X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_credit.pm;h=4860315e8b8920237ecefab6ed12065d00177d74;hp=e4b1fc07d013b5646fa3cc5ff2b28b1652e71cae;hb=d03ff57c2254deb9607c802db7454aa894e080fc;hpb=1f6659efd14865d7570ea84ac9ff83289876a713 diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index e4b1fc07d..4860315e8 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -783,7 +783,11 @@ sub calculate_tax_adjustment { ); } -=item credit_lineitems +=item credit_lineitems OPTIONS + +Creates a credit to a group of line items, with a specified amount applied +to each. This will also calculate the tax adjustments for those amounts and +credit the appropriate tax line items. Example: @@ -802,6 +806,16 @@ Example: ); +C, C, C are required and are parallel +arrays. Each one indicates an amount of credit to be applied to either the +setup or recur portion of a (non-tax) line item. + +C, C<_date>, C, and C will be set on the +credit before it's inserted. + +C is the total amount. If unspecified, the credit will be the sum +of the per-line-item amounts and their tax adjustments. + =cut #maybe i should just be an insert with extra args instead of a class method @@ -841,10 +855,18 @@ sub credit_lineitems { my $error = ''; + # first, determine the tax adjustments + my %tax_adjust = $class->calculate_tax_adjustment(%arg); + # and determine the amount automatically if it wasn't specified + if ( !exists( $arg{amount} ) ) { + $arg{amount} = sprintf('%.2f', $tax_adjust{subtotal} + $tax_adjust{taxtotal}); + } + + # create the credit my $cust_credit = new FS::cust_credit ( { map { $_ => $arg{$_} } #fields('cust_credit') - qw( custnum _date amount reasonnum addlinfo ), #pkgnum eventnum + qw( custnum _date amount reason reasonnum addlinfo ), #pkgnum eventnum } ); $error = $cust_credit->insert; if ( $error ) { @@ -864,9 +886,6 @@ sub credit_lineitems { my %cust_credit_bill_pkg = (); my %unapplied_payments = (); #invoice numbers, and then billpaynums - # determine the tax adjustments - my %tax_adjust = $class->calculate_tax_adjustment(%arg); - foreach my $billpkgnum ( @{$arg{billpkgnums}} ) { my $setuprecur = shift @{$arg{setuprecurs}}; my $amount = shift @{$arg{amounts}};