X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=aa25f8c4b137650591323ecd55855773aee52ff3;hb=92b6628c08e4478e48b6f250320a3e3e93262ec2;hp=78b8b0fb344ddf9108bbe7fa44bd6aaeda766a45;hpb=60dc4fe638eb9abc5a3ea92d43031dcbfeb71454;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 78b8b0fb3..aa25f8c4b 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -25,6 +25,7 @@ use FS::cust_bill_pkg_discount_void; use FS::cust_bill_pkg_tax_location_void; use FS::cust_bill_pkg_tax_rate_location_void; use FS::cust_tax_exempt_pkg_void; +use FS::cust_bill_pkg_fee_void; use FS::Cursor; @@ -294,13 +295,12 @@ sub insert { } # foreach my $link } - my $cust_event_fee = $self->get('cust_event_fee'); - if ( $cust_event_fee ) { - $cust_event_fee->set('billpkgnum' => $self->billpkgnum); - $error = $cust_event_fee->replace; + if ( my $fee_origin = $self->get('fee_origin') ) { + $fee_origin->set('billpkgnum' => $self->billpkgnum); + $error = $fee_origin->replace; if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "error updating cust_event_fee: $error"; + return "error updating fee origin record: $error"; } } @@ -358,6 +358,7 @@ sub void { cust_bill_pkg_tax_location cust_bill_pkg_tax_rate_location cust_tax_exempt_pkg + cust_bill_pkg_fee )) { foreach my $linked ( qsearch($table, { billpkgnum=>$self->billpkgnum }) ) { @@ -417,6 +418,7 @@ sub delete { cust_tax_exempt_pkg cust_bill_pay_pkg cust_credit_bill_pkg + cust_bill_pkg_fee )) { foreach my $linked ( qsearch($table, { billpkgnum=>$self->billpkgnum }) ) { @@ -668,6 +670,45 @@ sub units { $self->pkgnum ? $self->part_pkg->calc_units($self->cust_pkg) : 0; # 1? } +=item _item_discount + +If this item has any discounts, returns a hashref in the format used +by L to describe the discount(s) +on an invoice. This will contain the keys 'description', 'amount', +'ext_description' (an arrayref of text lines describing the discounts), +and '_is_discount' (a flag). + +The value for 'amount' will be negative, and will be scaled for the package +quantity. + +=cut + +sub _item_discount { + my $self = shift; + my @pkg_discounts = $self->pkg_discount; + return if @pkg_discounts == 0; + # special case: if there are old "discount details" on this line item, don't + # show discount line items + if ( FS::cust_bill_pkg_detail->count("detail LIKE 'Includes discount%' AND billpkgnum = ?", $self->billpkgnum || 0) > 0 ) { + return; + } + + my @ext; + my $d = { + _is_discount => 1, + description => $self->mt('Discount'), + amount => 0, + ext_description => \@ext, + # maybe should show quantity/unit discount? + }; + foreach my $pkg_discount (@pkg_discounts) { + push @ext, $pkg_discount->description; + $d->{amount} -= $pkg_discount->amount; + } + $d->{amount} *= $self->quantity || 1; + + return $d; +} =item set_display OPTION => VALUE ... @@ -860,7 +901,13 @@ sub usage { my $sql = 'SELECT SUM(COALESCE(amount,0)) FROM cust_bill_pkg_detail '. ' WHERE billpkgnum = '. $self->billpkgnum; - $sql .= " AND classnum = $classnum" if defined($classnum); + if (defined $classnum) { + if ($classnum =~ /^(\d+)$/) { + $sql .= " AND classnum = $1"; + } elsif ($classnum eq '') { + $sql .= " AND classnum IS NULL"; + } + } my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; @@ -981,26 +1028,6 @@ sub tax_location { } } -=item part_X - -Returns the L or L object that defines this -charge. If called on a tax line, returns nothing. - -=cut - -sub part_X { - my $self = shift; - if ( $self->pkgpart_override ) { - return FS::part_pkg->by_key($self->pkgpart_override); - } elsif ( $self->pkgnum ) { - return $self->cust_pkg->part_pkg; - } elsif ( $self->feepart ) { - return $self->part_fee; - } else { - return; - } -} - =back =head1 CLASS METHODS @@ -1204,6 +1231,7 @@ sub upgrade_tax_location { # It's either the bill or ship address of the customer as of the # invoice date-of-insertion. (Not necessarily the invoice date.) my $date = $h_cust_bill->history_date; + local($FS::Record::qsearch_qualify_columns) = 0; my $h_cust_main = qsearchs('h_cust_main', { custnum => $custnum }, FS::h_cust_main->sql_h_searchs($date) @@ -1257,6 +1285,7 @@ sub upgrade_tax_location { } else { # (pkgparts really shouldn't change, right?) + local($FS::Record::qsearch_qualify_columns) = 0; my $h_cust_pkg = qsearchs('h_cust_pkg', { pkgnum => $pkgnum }, FS::h_cust_pkg->sql_h_searchs($date) ); @@ -1276,6 +1305,7 @@ sub upgrade_tax_location { } if (!exists $pkgpart_taxclass{$pkgpart}) { + local($FS::Record::qsearch_qualify_columns) = 0; my $h_part_pkg = qsearchs('h_part_pkg', { pkgpart => $pkgpart }, FS::h_part_pkg->sql_h_searchs($date) ); @@ -1310,6 +1340,7 @@ sub upgrade_tax_location { # Get any per-customer taxname exemptions that were in effect. my %exempt_cust_taxname; foreach (keys %all_tax_names) { + local($FS::Record::qsearch_qualify_columns) = 0; my $h_exemption = qsearchs('h_cust_main_exemption', { 'custnum' => $custnum, 'taxname' => $_,