X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=d364ac527785e77c45d67f3c32106c2a34f7374f;hb=343befcb41d5ab76173645ceb8ac235ca7b92d35;hp=e4215bf2b42b7e7ec17c83d87824441afeaba6d9;hpb=c8cd96b69c9c1ede44c06c04f2703079d1afdf2b;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index e4215bf2b..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 @@ -4462,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