- $self->freq =~ /^(\d+)([hdwm]?)$/
- or die 'unparsable frequency: '. $self->freq;
- my $freq_sec = $1 * $sec{$2||'m'};
- return 0 unless $freq_sec;
+ # but if the cancellation happens during the interval, prorate it:
+ # (XXX obey prorate_round_day here?)
+ if ( $cust_bill_pkg->sdate < $time ) {
+ $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;
+
+ 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