sub previous {
my $self = shift;
- my $total = 0;
- my @cust_bill = sort { $a->_date <=> $b->_date }
- grep { $_->owed != 0 }
- qsearch( 'cust_bill', { 'custnum' => $self->custnum,
- #'_date' => { op=>'<', value=>$self->_date },
- 'invnum' => { op=>'<', value=>$self->invnum },
- } )
- ;
- foreach ( @cust_bill ) { $total += $_->owed; }
- $total, @cust_bill;
+ # simple memoize; we use this a lot
+ if (!$self->get('previous')) {
+ my $total = 0;
+ my @cust_bill = sort { $a->_date <=> $b->_date }
+ grep { $_->owed != 0 }
+ qsearch( 'cust_bill', { 'custnum' => $self->custnum,
+ #'_date' => { op=>'<', value=>$self->_date },
+ 'invnum' => { op=>'<', value=>$self->invnum },
+ } )
+ ;
+ foreach ( @cust_bill ) { $total += $_->owed; }
+ $self->set('previous', [$total, @cust_bill]);
+ }
+ return @{ $self->get('previous') };
}
=item enable_previous
my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } )
or die "invalid invoice number: " . $opt{invnum};
+ if ( $opt{mode} ) {
+ $self->set('mode', $opt{mode});
+ }
+
my %args = map {$_ => $opt{$_}}
grep { $opt{$_} }
qw( from notice_name no_coupon template );
my %classnums = ();
my %lines = ();
- my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 50;
+ my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 40;
my %usage_class = map { $_->classnum => $_ } qsearch( 'usage_class', {} );
foreach my $cust_bill_pkg ( $self->cust_bill_pkg ) {
my %classnums = ();
my %lines = ();
- my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 50;
+ my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 40;
my %usage_class = map { $_->classnum => $_ } qsearch( 'usage_class', {} );
$usage_class{''} ||= new FS::usage_class { 'classname' => '', 'weight' => 0 };
sub _items_credits {
my( $self, %opt ) = @_;
- my $trim_len = $opt{'trim_len'} || 60;
+ my $trim_len = $opt{'trim_len'} || 40;
my @b;
#credits
}
+sub _items_total {
+ my $self = shift;
+ my $conf = $self->conf;
+
+ my @items;
+ my ($pr_total) = $self->previous;
+ my ($new_charges_desc, $new_charges_amount);
+
+ if ( $conf->exists('previous_balance-exclude_from_total') ) {
+ # then return separate lines for previous balance and total new charges
+ if ( $pr_total ) {
+ push @items,
+ { total_item => $self->mt('Previous Balance'),
+ total_amount => sprintf('%.2f',$pr_total)
+ };
+ }
+ $new_charges_desc = $self->mt(
+ $conf->config('previous_balance-exclude_from_total')
+ || 'Total New Charges'
+ ); # localize 'Total New Charges' or whatever's in the config
+
+ $new_charges_amount = $self->charged;
+
+ } else {
+
+ $new_charges_desc = $self->mt('Total Charges');
+ $new_charges_amount = sprintf('%.2f',$self->charged + $pr_total);
+
+ }
+
+ if ( $conf->exists('invoice_show_prior_due_date') ) {
+ # then the due date should be shown with Total New Charges,
+ # and should NOT be shown with the Balance Due message.
+ if ( $self->due_date ) {
+ # localize the "Please pay by" message and the date itself
+ # (grammar issues with this, yeah)
+ $new_charges_desc .= ' - ' . $self->mt('Please pay by') . ' ' .
+ $self->due_date2str('short');
+ } elsif ( $self->terms ) {
+ # phrases like "due on receipt" should be localized
+ $new_charges_desc .= ' - ' . $self->mt($self->terms);
+ }
+ }
+
+ push @items,
+ { total_item => $new_charges_desc,
+ total_amount => $new_charges_amount,
+ };
+
+ @items;
+}
+
+
+
=item call_details [ OPTION => VALUE ... ]
Returns an array of CSV strings representing the call details for this invoice