summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2009-10-10 00:00:32 +0000
committerivan <ivan>2009-10-10 00:00:32 +0000
commitbdf4497fd8d3778e9cc0f8b90dd8a742f3a84158 (patch)
treef721e2efecfea352e5fbde4177e2b9b026b161ee /FS
parentf04616ad2c32641c1b85820cb97bcb22edbbc9f5 (diff)
change invoice terms for one-time charges (& bill them immediately), RT#5891
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Schema.pm10
-rw-r--r--FS/FS/cust_bill.pm23
-rw-r--r--FS/FS/cust_main.pm25
3 files changed, 51 insertions, 7 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 70f32502b..6f53b2aa7 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -390,15 +390,23 @@ sub tables_hashref {
'cust_bill' => {
'columns' => [
+ #regular fields
'invnum', 'serial', '', '', '', '',
'custnum', 'int', '', '', '', '',
'_date', @date_type, '', '',
'charged', @money_type, '', '',
+ 'invoice_terms', 'varchar', 'NULL', $char_d, '', '',
+
+ #customer balance info at invoice generation time
'previous_balance', @money_typen, '', '', #eventually not nullable
'billing_balance', @money_typen, '', '', #eventually not nullable
+
+ #deprecated (unused by now, right?)
'printed', 'int', '', '', '', '',
+
+ #specific use cases
'closed', 'char', 'NULL', 1, '', '',
- 'statementnum', 'int', 'NULL', '', '', '',
+ 'statementnum', 'int', 'NULL', '', '', '', #invoice aggregate statements
],
'primary_key' => 'invnum',
'unique' => [],
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index ac1e450d8..493bc097b 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -96,6 +96,18 @@ L<Time::Local> and L<Date::Parse> for conversion functions.
=item charged - amount of this invoice
+=item invoice_terms - optional terms override for this specific invoice
+
+=back
+
+Customer info at invoice generation time
+
+=over 4
+
+=item previous_balance
+
+=item billing_balance
+
=back
Deprecated
@@ -2989,10 +3001,10 @@ sub _translate_old_latex_format {
$line_item_line =~ s/\$(\w+)/'. \$_tr_line->{$1}. '/g;
push @template, " \$OUT .= '$line_item_line';";
}
-
+
push @template, '}',
'--@]';
-
+ #' doh, gvim
} elsif ( $line =~ /^%%TotalDetails\s*$/ ) {
push @template, '[@--',
@@ -3026,11 +3038,12 @@ sub _translate_old_latex_format {
sub terms {
my $self = shift;
- #check for an invoice- specific override (eventually)
+ #check for an invoice-specific override
+ return $self->invoice_terms if $self->invoice_terms;
#check for a customer- specific override
- return $self->cust_main->invoice_terms
- if $self->cust_main->invoice_terms;
+ my $cust_main = $self->cust_main;
+ return $cust_main->invoice_terms if $cust_main->invoice_terms;
#use configured default
$conf->config('invoice_default_terms') || '';
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 9d40e7306..c83acc65e 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2475,6 +2475,11 @@ typically might mean not charging the normal recurring fee but only usage
fees since the last billing. Setup charges may be charged. Not all package
plans support this feature (they tend to charge 0).
+=item invoice_terms
+
+Options terms to be printed on this invocice. Otherwise, customer-specific
+terms or the default terms are used.
+
=back
=cut
@@ -2801,6 +2806,7 @@ sub bill {
'charged' => $charged,
'billing_balance' => $balance,
'previous_balance' => $previous_balance,
+ 'invoice_terms' => $options{'invoice_terms'},
} );
$error = $cust_bill->insert;
if ( $error ) {
@@ -7172,6 +7178,10 @@ New-style, with a hashref of options:
#will be filled in with the new object
'cust_pkg_ref' => \$cust_pkg,
+
+ #generate an invoice immediately
+ 'bill_now' => 0,
+ 'invoice_terms' => '', #with these terms
}
);
@@ -7188,6 +7198,7 @@ sub charge {
my ( $setuptax, $taxclass ); #internal taxes
my ( $taxproduct, $override ); #vendor (CCH) taxes
my $cust_pkg_ref = '';
+ my ( $bill_now, $invoice_terms ) = ( 0, '' );
if ( ref( $_[0] ) ) {
$amount = $_[0]->{amount};
$quantity = exists($_[0]->{quantity}) ? $_[0]->{quantity} : 1;
@@ -7202,6 +7213,8 @@ sub charge {
$taxproduct = $_[0]->{taxproductnum};
$override = { '' => $_[0]->{tax_override} };
$cust_pkg_ref = exists($_[0]->{cust_pkg_ref}) ? $_[0]->{cust_pkg_ref} : '';
+ $bill_now = exists($_[0]->{bill_now}) ? $_[0]->{bill_now} : '';
+ $invoice_terms = exists($_[0]->{invoice_terms}) ? $_[0]->{invoice_terms} : '';
} else {
$amount = shift;
$quantity = 1;
@@ -7277,8 +7290,18 @@ sub charge {
${$cust_pkg_ref} = $cust_pkg;
}
+ if ( $bill_now ) {
+ my $error = $self->bill( 'invoice_terms' => $invoice_terms,
+ 'pkg_list' => [ $cust_pkg ],
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
- '';
+ return '';
}