summaryrefslogtreecommitdiff
path: root/FS/FS/part_pkg
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-09-20 11:39:37 -0700
committerMark Wells <mark@freeside.biz>2016-09-20 13:00:45 -0700
commit08de3ec51a1539162fe17e35a3cb04effd3dbcfb (patch)
tree6bda414e95c9af7c6bfe78183bbc8940d7cf1fff /FS/FS/part_pkg
parent3da4ea03e466c33f18640f5065951e77cca3f75b (diff)
when crediting unused time on packages, also credit any tax that was charged, #42729
Diffstat (limited to 'FS/FS/part_pkg')
-rw-r--r--FS/FS/part_pkg/flat.pm33
1 files changed, 24 insertions, 9 deletions
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index 84599ea..f23717b 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -235,6 +235,8 @@ sub calc_remain {
$time = time;
}
+ my $sources = $options{'cust_credit_source_bill_pkg'};
+
my $next_bill = $cust_pkg->getfield('bill') || 0;
return 0 if ! $self->base_recur($cust_pkg, \$time)
@@ -270,17 +272,30 @@ sub calc_remain {
$amount = $amount * ($edate - $time) / ($edate - $cust_bill_pkg->sdate);
}
+ # calculate tax adjustment. we're not doing full credit_lineitems here
+ # (e.g. not applying the credit to the past billing of this package)
+ # so just include the adjustment in the source record with the rest
+ # of the credit
+ my %tax_adjust = FS::cust_credit->calculate_tax_adjustment(
+ 'custnum' => $cust_pkg->custnum,
+ 'billpkgnums' => [ $cust_bill_pkg->billpkgnum ],
+ 'setuprecurs' => [ 'recur' ],
+ 'amounts' => [ $amount ],
+ );
+ $amount += $tax_adjust{taxtotal};
+
+ $amount = sprintf('%.2f', $amount); # ensure that amounts add up right
$credit += $amount;
- push @{ $options{'cust_credit_source_bill_pkg'} },
- new FS::cust_credit_source_bill_pkg {
- 'billpkgnum' => $cust_bill_pkg->billpkgnum,
- 'amount' => sprintf('%.2f', $amount),
- 'currency' => $cust_bill_pkg->cust_bill->currency,
- }
- if $options{'cust_credit_source_bill_pkg'};
-
- }
+ if ( $sources ) {
+ push @$sources,
+ FS::cust_credit_source_bill_pkg->new( {
+ 'billpkgnum' => $cust_bill_pkg->billpkgnum,
+ 'amount' => $amount,
+ 'currency' => $cust_bill_pkg->cust_bill->currency,
+ } );
+ }
+ } # foreach $cust_bill_pkg
sprintf('%.2f', $credit);