X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_credit.pm;h=eaff6e8aa278960616d09a7de5c1a6f36a08e0a4;hb=f618014107741d159fb257f1a6726a92cb046dfb;hp=23b7aed3a6b8d9958d7f514926e049628c33e08c;hpb=ad78be45d49a6933879e07e7d6f7c53b883249a5;p=freeside.git diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 23b7aed3a..eaff6e8aa 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -797,6 +797,7 @@ Example: 'setuprecurs' => \@setuprecurs, 'amounts' => \@amounts, 'apply' => 1, #0 leaves the credit unapplied + 'set_source' => 1, #creates credit source records for the line items #the credit map { $_ => scalar($cgi->param($_)) } @@ -861,6 +862,8 @@ sub credit_lineitems { $arg{amount} = sprintf('%.2f', $tax_adjust{subtotal} + $tax_adjust{taxtotal}); } + my $set_source = $arg{set_source}; + # create the credit my $cust_credit = new FS::cust_credit ( { map { $_ => $arg{$_} } @@ -884,6 +887,7 @@ sub credit_lineitems { my %cust_bill_pkg = (); my %cust_credit_bill_pkg = (); my %unapplied_payments = (); #invoice numbers, and then billpaynums + my %currency; # little private function to unapply payments from a cust_bill_pkg until # there's a specified amount of unpaid balance on it. @@ -956,6 +960,17 @@ sub credit_lineitems { # unapply payments if necessary $error = &{$unapply_sub}($cust_bill_pkg, $setuprecur, $amount); + if ( $set_source ) { + $currency{$invnum} ||= $cust_bill_pkg->cust_bill->currency; + my $source = FS::cust_credit_source_bill_pkg->new({ + 'crednum' => $cust_credit->crednum, + 'billpkgnum' => $billpkgnum, + 'amount' => $amount, + 'currency' => $currency{invnum}, + }); + $error ||= $source->insert; + } + if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error unapplying payment: $error"; @@ -993,6 +1008,19 @@ sub credit_lineitems { }; $error = &{$unapply_sub}($cust_bill_pkg, 'setup', $amount); + + # I guess it's correct to do this for taxes also? + if ( $set_source ) { + $currency{$invnum} ||= $cust_bill_pkg->cust_bill->currency; + my $source = FS::cust_credit_source_bill_pkg->new({ + 'crednum' => $cust_credit->crednum, + 'billpkgnum' => $billpkgnum, + 'amount' => $amount, + 'currency' => $currency{invnum}, + }); + $error ||= $source->insert; + } + if ( $error ) { $dbh->rollback if $oldAutoCommit; return "Error unapplying payment: $error";