summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-05-07 16:02:01 -0700
committerMark Wells <mark@freeside.biz>2013-05-07 16:02:01 -0700
commit85dc9f5c03d159e88d2af277749ec2c2707de3a1 (patch)
tree611932ef964cbde580af247ff967c30b839e185f /FS
parent0dfdc3e5dc012c1a2640ac2af22b1488cdfbd083 (diff)
changes to support new invoice features, #21293
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm10
-rw-r--r--FS/FS/Template_Mixin.pm70
-rw-r--r--FS/FS/cust_bill.pm6
3 files changed, 78 insertions, 8 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index db21563dc..d955f34ae 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1038,6 +1038,9 @@ sub reason_type_options {
'select_hash' => [
'%b %o, %Y' => 'Mon DDth, YYYY',
'%e %b %Y' => 'DD Mon YYYY',
+ '%m/%d/%Y' => 'MM/DD/YYYY',
+ '%d/%m/%Y' => 'DD/MM/YYYY',
+ '%Y/%m/%d' => 'YYYY/MM/DD',
],
},
@@ -4138,6 +4141,13 @@ and customer address. Include units.',
},
{
+ 'key' => 'always_show_tax',
+ 'section' => 'invoicing',
+ 'description' => 'Show a line for tax on the invoice even when the tax is zero. Optionally provide text for the tax name to show.',
+ 'type' => [ qw(checkbox text) ],
+ },
+
+ {
'key' => 'address_standardize_method',
'section' => 'UI', #???
'description' => 'Method for standardizing customer addresses.',
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 2e78f12f4..dd1796c7d 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -597,12 +597,54 @@ sub print_generic {
# info from customer's last invoice before this one, for some
# summary formats
$invoice_data{'last_bill'} = {};
- my $last_bill = $pr_cust_bill[-1];
+ # returns the last unpaid bill, not the last bill
+ #my $last_bill = $pr_cust_bill[-1];
+ # THIS returns the customer's last bill before this one
+ my $last_bill = qsearchs({
+ 'table' => 'cust_bill',
+ 'hashref' => { 'custnum' => $self->custnum,
+ 'invnum' => { op => '<', value => $self->invnum },
+ },
+ 'order_by' => ' ORDER BY invnum DESC LIMIT 1'
+ });
if ( $last_bill ) {
$invoice_data{'last_bill'} = {
'_date' => $last_bill->_date, #unformatted
# all we need for now
};
+ my (@payments, @credits);
+ # for formats that itemize previous payments
+ foreach my $cust_pay ( qsearch('cust_pay', {
+ 'custnum' => $self->custnum,
+ '_date' => { op => '>=',
+ value => $last_bill->_date }
+ } ) )
+ {
+ next if $cust_pay->_date > $self->_date;
+ push @payments, {
+ '_date' => $cust_pay->_date,
+ 'date' => time2str($date_format, $cust_pay->_date),
+ 'payinfo' => $cust_pay->payby_payinfo_pretty,
+ 'amount' => sprintf('%.2f', $cust_pay->paid),
+ };
+ # not concerned about applications
+ }
+ foreach my $cust_credit ( qsearch('cust_credit', {
+ 'custnum' => $self->custnum,
+ '_date' => { op => '>=',
+ value => $last_bill->_date }
+ } ) )
+ {
+ next if $cust_credit->_date > $self->_date;
+ push @credits, {
+ '_date' => $cust_credit->_date,
+ 'date' => time2str($date_format, $cust_credit->_date),
+ 'creditreason'=> $cust_credit->cust_credit->reason,
+ 'amount' => sprintf('%.2f', $cust_credit->amount),
+ };
+ }
+ $invoice_data{'previous_payments'} = \@payments;
+ $invoice_data{'previous_credits'} = \@credits;
}
my $summarypage = '';
@@ -687,6 +729,11 @@ sub print_generic {
my $other_money_char = $other_money_chars{$format};
$invoice_data{'dollar'} = $other_money_char;
+ my %minus_signs = ( 'latex' => '$-$',
+ 'html' => '&minus;',
+ 'template' => '- ' );
+ my $minus = $minus_signs{$format};
+
my @detail_items = ();
my @total_items = ();
my @buf = ();
@@ -971,7 +1018,8 @@ sub print_generic {
warn "$me adding taxes\n"
if $DEBUG > 1;
- foreach my $tax ( $self->_items_tax ) {
+ my @items_tax = $self->_items_tax;
+ foreach my $tax ( @items_tax ) {
$taxtotal += $tax->{'amount'};
@@ -1006,7 +1054,7 @@ sub print_generic {
}
- if ( $taxtotal ) {
+ if ( @items_tax ) {
my $total = {};
$total->{'total_item'} = $self->mt('Sub-total');
$total->{'total_amount'} =
@@ -1106,7 +1154,7 @@ sub print_generic {
my $total;
$total->{'total_item'} = &$escape_function($credit->{'description'});
$credittotal += $credit->{'amount'};
- $total->{'total_amount'} = '-'. $other_money_char. $credit->{'amount'};
+ $total->{'total_amount'} = $minus.$other_money_char.$credit->{'amount'};
$adjusttotal += $credit->{'amount'};
if ( $multisection ) {
my $money = $old_latex ? '' : $money_char;
@@ -1137,7 +1185,7 @@ sub print_generic {
my $total = {};
$total->{'total_item'} = &$escape_function($payment->{'description'});
$paymenttotal += $payment->{'amount'};
- $total->{'total_amount'} = '-'. $other_money_char. $payment->{'amount'};
+ $total->{'total_amount'} = $minus.$other_money_char.$payment->{'amount'};
$adjusttotal += $payment->{'amount'};
if ( $multisection ) {
my $money = $old_latex ? '' : $money_char;
@@ -2129,7 +2177,17 @@ sub _taxsort {
sub _items_tax {
my $self = shift;
my @cust_bill_pkg = sort _taxsort grep { ! $_->pkgnum } $self->cust_bill_pkg;
- $self->_items_cust_bill_pkg(\@cust_bill_pkg, @_);
+ my @items = $self->_items_cust_bill_pkg(\@cust_bill_pkg, @_);
+
+ if ( $self->conf->exists('always_show_tax') ) {
+ my $itemdesc = $self->conf->config('always_show_tax') || 'Tax';
+ if (0 == grep { $_->{description} eq $itemdesc } @items) {
+ push @items,
+ { 'description' => $itemdesc,
+ 'amount' => 0.00 };
+ }
+ }
+ @items;
}
=item _items_cust_bill_pkg CUST_BILL_PKGS OPTIONS
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index f85bca6af..fc6a7ddbe 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -110,9 +110,11 @@ Customer info at invoice generation time
=over 4
-=item previous_balance
+=item billing_balance - the customer's balance at the time the invoice was
+generated (not including charges on this invoice)
-=item billing_balance
+=item previous_balance - the billing_balance of this customer's previous
+invoice plus the charges on that invoice
=back