cust_pay_batch
cust_bill_pay_batch
cust_bill_pkg
+ cust_bill_batch
)) {
foreach my $linked ( $self->$table() ) {
}
+=item cust_bill_batch
+
+Returns all invoice batch records (L<FS::cust_bill_batch>) for this invoice.
+
+=cut
+
+sub cust_bill_batch {
+ my $self = shift;
+ qsearch('cust_bill_batch', { 'invnum' => $self->invnum });
+}
+
=item tax
Returns the tax amount (see L<FS::cust_bill_pkg>) for this invoice.
$params{'time'} = $today if $today;
$params{'template'} = $template if $template;
$params{$_} = $opt{$_}
- foreach grep $opt{$_}, qw( unsquealch_cdr notice_name );
+ foreach grep $opt{$_}, qw( unsquelch_cdr notice_name );
$self->print_generic( %params );
}
$params{'time'} = $today if $today;
$params{'template'} = $template if $template;
$params{$_} = $opt{$_}
- foreach grep $opt{$_}, qw( unsquealch_cdr notice_name );
+ foreach grep $opt{$_}, qw( unsquelch_cdr notice_name );
$template ||= $self->_agent_template;
#invoice from info
'company_name' => scalar( $conf->config('company_name', $agentnum) ),
'company_address' => join("\n", $conf->config('company_address', $agentnum) ). "\n",
+ 'company_phonenum'=> scalar( $conf->config('company_phonenum', $agentnum) ),
'returnaddress' => $returnaddress,
'agent' => &$escape_function($cust_main->agent->agent),
}
}
-
+
if ( @pr_cust_bill && !$conf->exists('disable_previous_balance') ) {
push @buf, ['','-----------'];
push @buf, [ 'Total Previous Balance',
if $DEBUG > 1;
my ($didsummary,$minutes) = $self->_did_summary;
- my $didsummary_desc = 'DID Activity Summary (Past 30 days)';
+ my $didsummary_desc = 'DID Activity Summary (since last invoice)';
push @detail_items,
{ 'description' => $didsummary_desc,
'ext_description' => [ $didsummary, $minutes ],
- }
- if !$multisection;
+ };
}
foreach my $section (@sections, @$late_sections) {
my ($file, $logofile, $barcodefile) = $self->print_latex(@_);
my $ps = generate_ps($file);
unlink($logofile);
- unlink($barcodefile);
+ unlink($barcodefile) if $barcodefile;
$ps;
}
my ($file, $logofile, $barcodefile) = $self->print_latex(@_);
my $pdf = generate_pdf($file);
unlink($logofile);
- unlink($barcodefile);
+ unlink($barcodefile) if $barcodefile;
$pdf;
}
}
} @sections;
push @early, @$extra_sections if $extra_sections;
-
+
sort { $a->{sort_weight} <=> $b->{sort_weight} } @early;
}
sub _did_summary {
my $self = shift;
my $end = $self->_date;
- my $start = $end - 2592000; # 30 days
+
+ # start at date of previous invoice + 1 second or 0 if no previous invoice
+ my $start = $self->scalar_sql("SELECT max(_date) FROM cust_bill WHERE custnum = ? and invnum != ?",$self->custnum,$self->invnum);
+ $start = 0 if !$start;
+ $start++;
+
my $cust_main = $self->cust_main;
my @pkgs = $cust_main->all_pkgs;
my($num_activated,$num_deactivated,$num_portedin,$num_portedout,$minutes)
my $inserted = $h_cust_svc->date_inserted;
my $deleted = $h_cust_svc->date_deleted;
- my $phone_inserted = $h_cust_svc->h_svc_x($inserted);
+ my $phone_inserted = $h_cust_svc->h_svc_x($inserted+5);
my $phone_deleted;
$phone_deleted = $h_cust_svc->h_svc_x($deleted) if $deleted;
}
# increment usage minutes
- my @cdrs = $phone_inserted->get_cdrs('begin'=>$start,'end'=>$end);
- foreach my $cdr ( @cdrs ) {
- $minutes += $cdr->billsec/60;
- }
+ if ( $phone_inserted ) {
+ my @cdrs = $phone_inserted->get_cdrs('begin'=>$start,'end'=>$end,'billsec_sum'=>1);
+ $minutes = $cdrs[0]->billsec_sum if scalar(@cdrs) == 1;
+ }
+ else {
+ warn "WARNING: no matching h_svc_phone insert record for insert time $inserted, svcnum " . $h_cust_svc->svcnum;
+ }
# don't look at this service again
push @seen, $h_cust_svc->svcnum;
foreach my $cust_bill_pkg ( @$cust_bill_pkgs )
{
- warn "$me _items_cust_bill_pkg considering cust_bill_pkg $cust_bill_pkg\n"
+ warn "$me _items_cust_bill_pkg considering cust_bill_pkg ".
+ $cust_bill_pkg->billpkgnum. ", pkgnum ". $cust_bill_pkg->pkgnum. "\n"
if $DEBUG > 1;
- $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount
- && $conf->exists('discount-show-always'));
-
- foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
- if ( $_ && !$cust_bill_pkg->hidden ) {
- $_->{amount} = sprintf( "%.2f", $_->{amount} ),
- $_->{amount} =~ s/^\-0\.00$/0.00/;
- $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
- push @b, { %$_ }
- unless ( $_->{amount} == 0 && !$discount_show_always );
- $_ = undef;
- }
- }
-
foreach my $display ( grep { defined($section)
? $_->section eq $section
: 1
my $cust_pkg = $cust_bill_pkg->cust_pkg;
- if ( $cust_bill_pkg->setup != 0 && (!$type || $type eq 'S') ) {
+ if ( (!$type || $type eq 'S')
+ && ( $cust_bill_pkg->setup != 0
+ || $cust_bill_pkg->setup_show_zero
+ )
+ )
+ {
warn "$me _items_cust_bill_pkg adding setup\n"
if $DEBUG > 1;
my $description = $desc;
- $description .= ' Setup' if $cust_bill_pkg->recur != 0;
+ $description .= ' Setup'
+ if $cust_bill_pkg->recur != 0
+ || $discount_show_always
+ || $cust_bill_pkg->recur_show_zero;
my @d = ();
unless ( $cust_pkg->part_pkg->hide_svc_detail
push @{ $s->{ext_description} }, @d;
} else {
$s = {
+ _is_setup => 1,
description => $description,
#pkgpart => $part_pkg->pkgpart,
pkgnum => $cust_bill_pkg->pkgnum,
}
- if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 ||
- ($discount_show_always && $cust_bill_pkg->recur == 0) ) &&
- ( !$type || $type eq 'R' || $type eq 'U' )
+ if ( ( !$type || $type eq 'R' || $type eq 'U' )
+ && (
+ $cust_bill_pkg->recur != 0
+ || $cust_bill_pkg->setup == 0
+ || $discount_show_always
+ || $cust_bill_pkg->recur_show_zero
+ )
)
{
$description .= " (" . time2str($date_format, $cust_bill_pkg->sdate).
" - ". time2str($date_format, $cust_bill_pkg->edate).
")"
- unless $conf->exists('disable_line_item_date_ranges');
+ unless $conf->exists('disable_line_item_date_ranges')
+ || $cust_pkg->part_pkg->option('disable_line_item_date_ranges',1);
my @d = ();
}
+ $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount
+ && $conf->exists('discount-show-always'));
+
+ foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
+ if ( $_ && !$cust_bill_pkg->hidden ) {
+ $_->{amount} = sprintf( "%.2f", $_->{amount} ),
+ $_->{amount} =~ s/^\-0\.00$/0.00/;
+ $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
+ push @b, { %$_ }
+ if $_->{amount} != 0
+ || $discount_show_always
+ || ( ! $_->{_is_setup} && $cust_bill_pkg->recur_show_zero )
+ || ( $_->{_is_setup} && $cust_bill_pkg->setup_show_zero )
+ ;
+ $_ = undef;
+ }
+ }
+
}
+ #foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
+ # if ( $_ ) {
+ # $_->{amount} = sprintf( "%.2f", $_->{amount} ),
+ # $_->{amount} =~ s/^\-0\.00$/0.00/;
+ # $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
+ # push @b, { %$_ }
+ # if $_->{amount} != 0
+ # || $discount_show_always
+ # }
+ #}
+
warn "$me _items_cust_bill_pkg done considering cust_bill_pkgs\n"
if $DEBUG > 1;
- foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) {
- if ( $_ ) {
- $_->{amount} = sprintf( "%.2f", $_->{amount} ),
- $_->{amount} =~ s/^\-0\.00$/0.00/;
- $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
- push @b, { %$_ }
- unless ( $_->{amount} == 0 && !$discount_show_always );
- }
- }
-
@b;
}