summaryrefslogtreecommitdiff
path: root/FS/FS/cust_credit.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-09-21 14:30:01 -0700
committerMark Wells <mark@freeside.biz>2016-09-21 14:30:06 -0700
commitf618014107741d159fb257f1a6726a92cb046dfb (patch)
tree3aaac956dc585e25e7b32c916a0f84d5980f205c /FS/FS/cust_credit.pm
parentad78be45d49a6933879e07e7d6f7c53b883249a5 (diff)
and still create credit source records on 4.x+, #42729
Diffstat (limited to 'FS/FS/cust_credit.pm')
-rw-r--r--FS/FS/cust_credit.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 23b7aed..eaff6e8 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";