X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=92a51af352b72d880bde80073151ce9f4c2292d1;hb=d5c36bbc9efd8dd9270a115c6d4ed376e8d91cff;hp=0b110f5931e59aa58a0f96f5fec826ea8c06ef0b;hpb=b9db0c84e15438e7be5cf5f34016d6829a796a39;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 0b110f593..92a51af35 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -334,6 +334,7 @@ line item to the FS::cust_bill_pkg_void table (and related tables). sub void { my $self = shift; my $reason = scalar(@_) ? shift : ''; + my $reprocess_cdrs = scalar(@_) ? shift : ''; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -365,6 +366,9 @@ sub void { cust_tax_exempt_pkg cust_bill_pkg_fee )) { + my %delete_args = (); + $delete_args{'reprocess_cdrs'} = $reprocess_cdrs + if $table eq 'cust_bill_pkg_detail'; foreach my $linked ( qsearch($table, { billpkgnum=>$self->billpkgnum }) ) { @@ -372,7 +376,7 @@ sub void { my $void = $vclass->new( { map { $_ => $linked->get($_) } $linked->fields }); - my $error = $void->insert || $linked->delete; + my $error = $void->insert || $linked->delete(%delete_args); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -382,7 +386,7 @@ sub void { } - $error = $self->delete; + $error = $self->delete( skip_update_cust_bill_charged=>1 ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -402,6 +406,7 @@ Not recommended. sub delete { my $self = shift; + my %opt = @_; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -447,6 +452,26 @@ sub delete { } } + unless ( $opt{skip_update_cust_bill_charged} ) { + + #fix the invoice amount + + my $cust_bill = $self->cust_bill; + my $charged = $cust_bill->charged - $self->setup - $self->recur; + $charged = sprintf('%.2f', $charged + 0.00000001 ); + $cust_bill->charged( $charged ); + + #not adding a cc surcharge, but this override lets us modify charged + $cust_bill->{'Hash'}{'cc_surcharge_replace_hack'} = 1; + + my $error = $cust_bill->replace; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + } + my $error = $self->SUPER::delete(@_); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -838,8 +863,7 @@ sub _item_discount { $d = { _is_discount => 1, description => $self->mt('Discount'), - setup_amount => 0, - recur_amount => 0, + amount => 0, ext_description => \@ext, pkgpart => $self->pkgpart, feepart => $self->feepart, @@ -847,15 +871,14 @@ sub _item_discount { }; foreach my $pkg_discount (@pkg_discounts) { push @ext, $pkg_discount->description; - my $setuprecur = $pkg_discount->cust_pkg_discount->setuprecur; - $d->{$setuprecur.'_amount'} -= $pkg_discount->amount; + $d->{'amount'} -= $pkg_discount->amount; } } # show introductory rate as a pseudo-discount if (!$d) { # this will conflict with showing real discounts my $part_pkg = $self->part_pkg; - if ( $part_pkg and $part_pkg->option('show_as_discount') ) { + if ( $part_pkg and $part_pkg->option('show_as_discount',1) ) { my $cust_pkg = $self->cust_pkg; my $intro_end = $part_pkg->intro_end($cust_pkg); my $_date = $self->cust_bill->_date; @@ -866,8 +889,7 @@ sub _item_discount { } if ( $d ) { - $d->{setup_amount} *= $self->quantity || 1; # ?? - $d->{recur_amount} *= $self->quantity || 1; # ?? + $d->{amount} *= $self->quantity || 1; } $d; @@ -1803,6 +1825,70 @@ sub upgrade_tax_location { ''; } +sub _pkg_tax_list { + # Return an array of hashrefs for each cust_bill_pkg_tax_location + # applied to this bill for this cust_bill_pkg.pkgnum. + # + # ! Important Note: + # In some situations, this list will contain more tax records than the + # ones directly related to $self->billpkgnum. The returned list contains + # all records, for this bill, charged against this billpkgnum's pkgnum. + # + # One must keep this in mind when using data returned by this method. + # + # An unaddressed deficiency in the cust_bill_pkg_tax_location model makes + # this necessary: When a linked-hidden package generates a tax/fee as a row + # in cust_bill_pkg_tax_location, there is not enough information to surmise + # with specificity which billpkgnum row represents the direct parent of the + # the linked-hidden package's tax row. The closest we can get to this + # backwards reassociation is to use the pkgnum. Therefore, when multiple + # billpkgnum's appear with the same pkgnum, this method is going to return + # the tax records for ALL of those billpkgnum's, not just $self->billpkgnum. + # + # This could be addressed with an update to the model, and to the billing + # routine that generates rows into cust_bill_pkg_tax_location. Perhaps a + # column, link_billpkgnum or parent_billpkgnum, recording the link. I'm not + # doing that now, because there would be no possible repair of data stored + # historically prior to such a fix. I need _pkg_tax_list() to not be + # broken for already-generated bills. + # + # Any code you write relying on _pkg_tax_list() MUST be aware of, and + # account for, the possible return of duplicated tax records returned + # when method is called on multiple cust_bill_pkg_tax_location rows. + # Duplicates can be identified by billpkgtaxlocationnum column. + + my $self = shift; + return unless $self->pkgnum; + + map +{ + billpkgtaxlocationnum => $_->billpkgtaxlocationnum, + billpkgnum => $_->billpkgnum, + taxnum => $_->taxnum, + amount => $_->amount, + taxname => $_->taxname, + }, + qsearch({ + table => 'cust_bill_pkg_tax_location', + addl_from => ' + LEFT JOIN cust_bill_pkg + ON cust_bill_pkg.billpkgnum + = cust_bill_pkg_tax_location.taxable_billpkgnum + ', + select => join( ', ', (qw| + cust_bill_pkg.billpkgnum + cust_bill_pkg_tax_location.billpkgtaxlocationnum + cust_bill_pkg_tax_location.taxnum + cust_bill_pkg_tax_location.amount + |)), + extra_sql => + ' WHERE '. + ' cust_bill_pkg.invnum = ' . dbh->quote( $self->invnum ) . + ' AND '. + ' cust_bill_pkg_tax_location.pkgnum = ' . dbh->quote( $self->pkgnum ), + }); + +} + sub _upgrade_data { # Create a queue job to run upgrade_tax_location from January 1, 2012 to # the present date. @@ -1861,4 +1947,3 @@ from the base documentation. =cut 1; -