X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_credit.pm;h=fda10decf7454d90bb13add88830845ba5473e85;hb=40a7b3dc653e099f7bd0bd762b649b04c4432db2;hp=4336ea04180165f24e6fbd05dcc47637c4b44e41;hpb=674115921f5fba37fd9173a8bbe298233cbf4b31;p=freeside.git diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 4336ea041..fda10decf 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -8,6 +8,7 @@ use FS::Misc qw(send_email); use FS::Record qw( qsearch qsearchs dbdef ); use FS::cust_main_Mixin; use FS::cust_main; +use FS::cust_pkg; use FS::cust_refund; use FS::cust_credit_bill; use FS::part_pkg; @@ -58,22 +59,46 @@ FS::Record. The following fields are currently supported: =over 4 -=item crednum - primary key (assigned automatically for new credits) +=item crednum -=item custnum - customer (see L) +Primary key (assigned automatically for new credits) -=item amount - amount of the credit +=item custnum -=item _date - specified as a UNIX timestamp; see L. Also see +Customer (see L) + +=item amount + +Amount of the credit + +=item _date + +Specified as a UNIX timestamp; see L. Also see L and L for conversion functions. -=item otaker - order taker (assigned automatically, see L) +=item otaker + +Order taker (assigned automatically, see L) + +=item reason + +Text ( deprecated ) + +=item reasonnum + +Reason (see L) + +=item addlinfo + +Text + +=item closed -=item reason - text ( deprecated ) +Books closed flag, empty or `Y' -=item reasonum - int reason (see L) +=item pkgnum -=item closed - books closed flag, empty or `Y' +Desired pkgnum when using experimental package balances. =back @@ -209,7 +234,8 @@ sub delete { my $cust_main = $self->cust_main; my $error = send_email( - 'from' => $conf->config('invoice_from'), #??? well as good as any + 'from' => $conf->config('invoice_from', $self->cust_main->agentnum), + #invoice_from??? well as good as any 'to' => $conf->config('deletecredits'), 'subject' => 'FREESIDE NOTIFICATION: Credit deleted', 'body' => [ @@ -262,47 +288,35 @@ methods. sub check { my $self = shift; + $self->otaker(getotaker) unless ($self->otaker); + my $error = $self->ut_numbern('crednum') || $self->ut_number('custnum') || $self->ut_numbern('_date') || $self->ut_money('amount') + || $self->ut_alpha('otaker') || $self->ut_textn('reason') || $self->ut_foreign_key('reasonnum', 'reason', 'reasonnum') + || $self->ut_textn('addlinfo') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum') ; return $error if $error; return "amount must be > 0 " if $self->amount <= 0; + return "amount must be greater or equal to amount applied" + if $self->unapplied < 0; + return "Unknown customer" unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); $self->_date(time) unless $self->_date; - $self->otaker(getotaker) unless ($self->otaker); - $self->SUPER::check; } -=item cust_refund - -Depreciated. See the cust_credit_refund method. - -#Returns all refunds (see L) for this credit. - -=cut - -sub cust_refund { - use Carp; - croak "FS::cust_credit->cust_pay depreciated; see ". - "FS::cust_credit->cust_credit_refund"; - #my $self = shift; - #sort { $a->_date <=> $b->_date } - # qsearch( 'cust_refund', { 'crednum' => $self->crednum } ) - #; -} - =item cust_credit_refund Returns all refund applications (see L) for this credit. @@ -330,15 +344,15 @@ sub cust_credit_bill { ; } -=item credited +=item unapplied -Returns the amount of this credit that is still outstanding; which is +Returns the amount of this credit that is still unapplied/outstanding; amount minus all refund applications (see L) and applications to invoices (see L). =cut -sub credited { +sub unapplied { my $self = shift; my $amount = $self->amount; $amount -= $_->amount foreach ( $self->cust_credit_refund ); @@ -346,6 +360,18 @@ sub credited { sprintf( "%.2f", $amount ); } +=item credited + +Deprecated name for the unapplied method. + +=cut + +sub credited { + my $self = shift; + #carp "cust_credit->credited deprecated; use ->unapplied"; + $self->unapplied(@_); +} + =item cust_main Returns the customer (see L) for this credit. @@ -401,14 +427,13 @@ sub reason { $dbh->commit or die $dbh->errstr if $oldAutoCommit; - $reason ? $reason->reason : ''; + ( $reason ? $reason->reason : '' ). + ( $self->addlinfo ? ' '.$self->addlinfo : '' ); } # _upgrade_data # # Used by FS::Upgrade to migrate to a new database. -# -# sub _upgrade_data { # class method my ($class, %opts) = @_; @@ -419,9 +444,9 @@ sub _upgrade_data { # class method warn "$me Checking for unmigrated reasons\n" if $DEBUG; - my @cust_credits = qsearch({ 'table' => $class->table, - 'hashref' => {}, - 'extrasql' => 'WHERE reason IS NOT NULL', + my @cust_credits = qsearch({ 'table' => $class->table, + 'hashref' => {}, + 'extra_sql' => 'WHERE reason IS NOT NULL', }); if (scalar(grep { $_->getfield('reason') =~ /\S/ } @cust_credits)) { @@ -526,13 +551,13 @@ sub _upgrade_data { # class method =over 4 -=item credited_sql +=item unapplied_sql Returns an SQL fragment to retreive the unapplied amount. =cut -sub credited_sql { +sub unapplied_sql { #my $class = shift; "amount @@ -550,14 +575,29 @@ sub credited_sql { } +=item credited_sql + +Deprecated name for the unapplied_sql method. + +=cut + +sub credited_sql { + #my $class = shift; + + #carp "cust_credit->credited_sql deprecated; use ->unapplied_sql"; + + #$class->unapplied_sql(@_); + unapplied_sql(); +} + =back =head1 BUGS The delete method. The replace method. -B and B should probably be called B and -B. +B and B are now called B and +B. The old method names should start to give warnings. =head1 SEE ALSO