use File::Temp 0.14;
use HTML::Entities;
use Locale::Country;
+use Cwd;
use FS::UID;
use FS::Record qw( qsearch qsearchs );
use FS::Misc qw( generate_ps generate_pdf );
close $lh;
$params{'logo_file'} = $lh->filename;
- if( $conf->exists('invoice-barcode') && $self->can('invoice_barcode') ) {
+ if( $conf->exists('invoice-barcode')
+ && $self->can('invoice_barcode')
+ && $self->invnum ) { # don't try to barcode statements
my $png_file = $self->invoice_barcode($dir);
my $eps_file = $png_file;
$eps_file =~ s/\.png$/.eps/g;
warn "$me generating sections\n"
if $DEBUG > 1;
+ # Previous Charges section
+ # subtotal is the first return value from $self->previous
my $previous_section = { 'description' => $self->mt('Previous Charges'),
'subtotal' => $other_money_char.
sprintf('%.2f', $pr_total),
}
}
- unless ( $conf->exists('disable_previous_balance', $agentnum)
- || $conf->exists('previous_balance-summary_only')
- || ! $self->can('_items_previous')
- )
- {
+ # previous invoice balances in the Previous Charges section if there
+ # is one, otherwise in the main detail section
+ if ( $self->can('_items_previous') &&
+ $self->enable_previous &&
+ ! $conf->exists('previous_balance-summary_only') ) {
warn "$me adding previous balances\n"
if $DEBUG > 1;
}
}
-
- if ( @pr_cust_bill && !$conf->exists('disable_previous_balance', $agentnum) )
- {
+
+ if ( @pr_cust_bill && $self->enable_previous ) {
push @buf, ['','-----------'];
push @buf, [ $self->mt('Total Previous Balance'),
$money_char. sprintf("%10.2f", $pr_total) ];
warn "$me setting options\n"
if $DEBUG > 1;
- my $multilocation = scalar($cust_main->cust_location); #too expensive?
my %options = ();
$options{'section'} = $section if $multisection;
$options{'format'} = $format;
$options{'summary_page'} = $summarypage;
$options{'skip_usage'} =
scalar(@$extra_sections) && !grep{$section == $_} @$extra_sections;
- $options{'multilocation'} = $multilocation;
$options{'multisection'} = $multisection;
warn "$me searching for line items\n"
}
$detail->{'amount'} = ( $old_latex ? '' : $money_char ).
$line_item->{'amount'};
- $detail->{'unit_amount'} = ( $old_latex ? '' : $money_char ).
- $line_item->{'unit_amount'};
+ if ( exists $line_item->{'unit_amount'} ) {
+ $detail->{'unit_amount'} = ( $old_latex ? '' : $money_char ).
+ $line_item->{'unit_amount'};
+ }
$detail->{'product_code'} = $line_item->{'pkgpart'} || 'N/A';
$detail->{'sdate'} = $line_item->{'sdate'};
$invoice_data{current_less_finance} =
sprintf('%.2f', $self->charged - $invoice_data{finance_amount} );
- if ( $multisection && !$conf->exists('disable_previous_balance', $agentnum)
+ # create a major section for previous balance if we have major sections,
+ # or if previous_section is in summary form
+ if ( ( $multisection && $self->enable_previous )
|| $conf->exists('previous_balance-summary_only') )
{
unshift @sections, $previous_section if $pr_total;
push @buf,['','-----------'];
push @buf,[$self->mt(
- $conf->exists('disable_previous_balance', $agentnum)
+ (!$self->enable_previous)
? 'Total Charges'
: 'Total New Charges'
),
$money_char. sprintf("%10.2f",$self->charged) ];
push @buf,['',''];
+ # calculate total, possibly including total owed on previous
+ # invoices
{
my $total = {};
my $item = 'Total';
$item = $conf->config('previous_balance-exclude_from_total')
|| 'Total New Charges'
if $conf->exists('previous_balance-exclude_from_total');
- my $amount = $self->charged +
- ( $conf->exists('disable_previous_balance', $agentnum) ||
- $conf->exists('previous_balance-exclude_from_total')
- ? 0
- : $pr_total
- );
+ my $amount = $self->charged;
+ if ( $self->enable_previous and !$conf->exists('previous_balance-exclude_from_total') ) {
+ $amount += $pr_total;
+ }
+
$total->{'total_item'} = &$embolden_function($self->mt($item));
$total->{'total_amount'} =
&$embolden_function( $other_money_char. sprintf( '%.2f', $amount ) );
];
push @buf,['',''];
}
-
- unless ( $conf->exists('disable_previous_balance', $agentnum)
- || ! $self->can('_items_credits')
- || ! $self->can('_items_payments')
- )
- {
+
+ # if we're showing previous invoices, also show previous
+ # credits and payments
+ if ( $self->enable_previous
+ and $self->can('_items_credits')
+ and $self->can('_items_payments') )
+ {
#foreach my $thing ( sort { $a->_date <=> $b->_date } $self->_items_credits, $self->_items_payments
# credits
multisection: a flag indicating that this is a multisection invoice,
which does something complicated.
-multilocation: a flag to display the location label for the package.
-
Returns a list of hashrefs, each of which may contain:
pkgnum, description, amount, unit_amount, quantity, _is_setup, and
my $unsquelched = $opt{unsquelched} || ''; #unused
my $section = $opt{section}->{description} if $opt{section};
my $summary_page = $opt{summary_page} || ''; #unused
- my $multilocation = $opt{multilocation} || '';
my $multisection = $opt{multisection} || '';
my $discount_show_always = 0;
my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 50;
my $cust_main = $self->cust_main;#for per-agent cust_bill-line_item-ate_style
+ # and location labels
my @b = ();
my ($s, $r, $u) = ( undef, undef, undef );
$cust_pkg->h_labels_short($self->_date, undef, 'I')
unless $cust_bill_pkg->pkgpart_override; #don't redisplay services
- if ( $multilocation ) {
+ if ( ! $cust_pkg->locationnum or
+ $cust_pkg->locationnum != $cust_main->ship_locationnum ) {
my $loc = $cust_pkg->location_label;
$loc = substr($loc, 0, $maxlength). '...'
if $format eq 'latex' && length($loc) > $maxlength;
warn "$me _items_cust_bill_pkg done adding service details\n"
if $DEBUG > 1;
- if ( $multilocation ) {
+ if ( $cust_pkg->locationnum != $cust_main->ship_locationnum ) {
my $loc = $cust_pkg->location_label;
$loc = substr($loc, 0, $maxlength). '...'
if $format eq 'latex' && length($loc) > $maxlength;
$amount = $cust_bill_pkg->usage;
}
+ my $unit_amount =
+ ( $cust_bill_pkg->unitrecur > 0 ) ? $cust_bill_pkg->unitrecur
+ : $amount;
+
if ( !$type || $type eq 'R' ) {
warn "$me _items_cust_bill_pkg adding recur\n"
if ( $cust_bill_pkg->hidden ) {
$r->{amount} += $amount;
- $r->{unit_amount} += $cust_bill_pkg->unitrecur;
+ $r->{unit_amount} += $unit_amount;
push @{ $r->{ext_description} }, @d;
} else {
$r = {
pkgnum => $cust_bill_pkg->pkgnum,
amount => $amount,
recur_show_zero => $cust_bill_pkg->recur_show_zero,
- unit_amount => $cust_bill_pkg->unitrecur,
+ unit_amount => $unit_amount,
quantity => $cust_bill_pkg->quantity,
%item_dates,
ext_description => \@d,
if ( $cust_bill_pkg->hidden ) {
$u->{amount} += $amount;
- $u->{unit_amount} += $cust_bill_pkg->unitrecur;
+ $u->{unit_amount} += $unit_amount,
push @{ $u->{ext_description} }, @d;
} else {
$u = {
pkgnum => $cust_bill_pkg->pkgnum,
amount => $amount,
recur_show_zero => $cust_bill_pkg->recur_show_zero,
- unit_amount => $cust_bill_pkg->unitrecur,
+ unit_amount => $unit_amount,
quantity => $cust_bill_pkg->quantity,
%item_dates,
ext_description => \@d,