X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=d364ac527785e77c45d67f3c32106c2a34f7374f;hp=3e7109ec9ea276efd47fd2661026dc1d0aa5396c;hb=74a3083375ccc3a0dc8b74f9b39392989d088656;hpb=1ec723c2b944c08c32362d05cefe8b332c80276d diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 3e7109ec9..d364ac527 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -162,6 +162,45 @@ sub cust_unlinked_msg { Adds this invoice to the database ("Posts" the invoice). If there is an error, returns the error, otherwise returns false. +=cut + +sub insert { + my $self = shift; + warn "$me insert called\n" if $DEBUG; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->SUPER::insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + if ( $self->get('cust_bill_pkg') ) { + foreach my $cust_bill_pkg ( @{$self->get('cust_bill_pkg')} ) { + $cust_bill_pkg->invnum($self->invnum); + my $error = $cust_bill_pkg->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "can't create invoice line item: $error"; + } + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + =item delete This method now works but you probably shouldn't use it. Instead, apply a @@ -2386,7 +2425,8 @@ sub print_generic { qsearchs('pkg_class', { classnum => $conf->config('finance_pkgclass') }); $invoice_data{finance_section} = $pkg_class->categoryname; } - $invoice_data{finance_amount} = '0.00'; + $invoice_data{finance_amount} = '0.00'; + $invoice_data{finance_section} ||= 'Finance Charges'; #avoid config confusion my $countrydefault = $conf->config('countrydefault') || 'US'; my $prefix = $cust_main->has_ship_address ? 'ship_' : ''; @@ -2657,6 +2697,7 @@ sub print_generic { $options{'skip_usage'} = scalar(@$extra_sections) && !grep{$section == $_} @$extra_sections; $options{'multilocation'} = $multilocation; + $options{'multisection'} = $multisection; foreach my $line_item ( $self->_items_pkg(%options) ) { my $detail = { @@ -3358,6 +3399,7 @@ sub _items_sections { if ( $summarypage ) { @sections = grep { exists($subtotal{$_}) || ! _pkg_category($_)->disabled } map { $_->categoryname } qsearch('pkg_category', {}); + push @sections, '' if exists($subtotal{''}); } else { @sections = keys %subtotal; } @@ -3749,6 +3791,7 @@ sub _items_svc_phone_sections { my %lines = (); my %usage_class = map { $_->classnum => $_ } qsearch( 'usage_class', {} ); + $usage_class{''} ||= new FS::usage_class { 'classname' => '', 'weight' => 0 }; foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) { next unless $cust_bill_pkg->pkgnum > 0; @@ -3991,6 +4034,7 @@ sub _items_cust_bill_pkg { my $section = $opt{section}->{description} if $opt{section}; my $summary_page = $opt{summary_page} || ''; my $multilocation = $opt{multilocation} || ''; + my $multisection = $opt{multisection} || ''; my @b = (); my ($s, $r, $u) = ( undef, undef, undef ); @@ -4012,7 +4056,8 @@ sub _items_cust_bill_pkg { ? $_->section eq $section : 1 } - grep { !$_->summary || !$summary_page } + #grep { !$_->summary || !$summary_page } # bunk! + grep { !$_->summary || $multisection } $cust_bill_pkg->cust_bill_pkg_display ) { @@ -4071,7 +4116,7 @@ sub _items_cust_bill_pkg { } - if ( $cust_bill_pkg->recur != 0 && + if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 ) && ( !$type || $type eq 'R' || $type eq 'U' ) ) { @@ -4141,7 +4186,7 @@ sub _items_cust_bill_pkg { }; } - } elsif ( $amount ) { # && $type eq 'U' + } else { # $type eq 'U' if ( $cust_bill_pkg->hidden ) { $u->{amount} += $amount; @@ -4456,6 +4501,25 @@ sub credited_sql { WHERE cust_bill.invnum = cust_credit_bill.invnum $start $end )"; } +=item due_date_sql + +Returns an SQL fragment to retrieve the due date of an invoice. +Currently only supported on PostgreSQL. + +=cut + +sub due_date_sql { +'COALESCE( + SUBSTRING( + COALESCE( + cust_bill.invoice_terms, + cust_main.invoice_terms, + \''.($conf->config('invoice_default_terms') || '').'\' + ), E\'Net (\\\\d+)\' + )::INTEGER, 0 +) * 86400 + cust_bill._date' +} + =item search_sql_where HASHREF Class method which returns an SQL WHERE fragment to search for parameters