-sub _items_pkg {
- my $self = shift;
- my @cust_bill_pkg = grep { $_->pkgnum } $self->cust_bill_pkg;
- $self->_items_cust_bill_pkg(\@cust_bill_pkg, @_);
-}
-
-sub _taxsort {
- return 0 unless $a cmp $b;
- return -1 if $b eq 'Tax';
- return 1 if $a eq 'Tax';
- return -1 if $b eq 'Other surcharges';
- return 1 if $a eq 'Other surcharges';
- $a cmp $b;
-}
-
-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, @_);
-}
-
-sub _items_cust_bill_pkg {
- my $self = shift;
- my $cust_bill_pkg = shift;
- my %opt = @_;
-
- my $format = $opt{format} || '';
- my $escape_function = $opt{escape_function} || sub { shift };
- my $format_function = $opt{format_function} || '';
- my $unsquelched = $opt{unsquelched} || '';
- my $section = $opt{section}->{description} if $opt{section};
-
- my @b = ();
- my ($s, $r, $u) = ( undef, undef, undef );
- foreach my $cust_bill_pkg ( @$cust_bill_pkg )
- {
-
- foreach ( $s, $r, $u ) {
- if ( $_ && !$cust_bill_pkg->hidden ) {
- $_->{amount} = sprintf( "%.2f", $_->{amount} ),
- $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
- push @b, { %$_ };
- $_ = undef;
- }
- }
-
- foreach my $display ( grep { defined($section)
- ? $_->section eq $section
- : 1
- }
- $cust_bill_pkg->cust_bill_pkg_display
- )
- {
-
- my $type = $display->type;
-
- my $cust_pkg = $cust_bill_pkg->cust_pkg;
-
- my $desc = $cust_bill_pkg->desc;
- $desc = substr($desc, 0, 50). '...'
- if $format eq 'latex' && length($desc) > 50;
-
- my %details_opt = ( 'format' => $format,
- 'escape_function' => $escape_function,
- 'format_function' => $format_function,
- );
-
- if ( $cust_bill_pkg->pkgnum > 0 ) {
-
- if ( $cust_bill_pkg->setup != 0 && (!$type || $type eq 'S') ) {
-
- my $description = $desc;
- $description .= ' Setup' if $cust_bill_pkg->recur != 0;
-
- my @d = ();
- push @d, map &{$escape_function}($_),
- $cust_pkg->h_labels_short($self->_date)
- unless $cust_pkg->part_pkg->hide_svc_detail
- || $cust_bill_pkg->hidden;
- push @d, $cust_bill_pkg->details(%details_opt)
- if $cust_bill_pkg->recur == 0;
-
- if ( $cust_bill_pkg->hidden ) {
- $s->{amount} += $cust_bill_pkg->setup;
- $s->{unit_amount} += $cust_bill_pkg->unitsetup;
- push @{ $s->{ext_description} }, @d;
- } else {
- $s = {
- description => $description,
- #pkgpart => $part_pkg->pkgpart,
- pkgnum => $cust_bill_pkg->pkgnum,
- amount => $cust_bill_pkg->setup,
- unit_amount => $cust_bill_pkg->unitsetup,
- quantity => $cust_bill_pkg->quantity,
- ext_description => \@d,
- };
- };
-
- }
-
- if ( $cust_bill_pkg->recur != 0 &&
- ( !$type || $type eq 'R' || $type eq 'U' )
- )
- {
-
- my $is_summary = $display->summary;
- my $description = $is_summary ? "Usage charges" : $desc;
-
- unless ( $conf->exists('disable_line_item_date_ranges') ) {
- $description .= " (" . time2str("%x", $cust_bill_pkg->sdate).
- " - ". time2str("%x", $cust_bill_pkg->edate). ")";
- }
-
- my @d = ();
-
- #at least until cust_bill_pkg has "past" ranges in addition to
- #the "future" sdate/edate ones... see #3032
- my @dates = ( $self->_date );
- my $prev = $cust_bill_pkg->previous_cust_bill_pkg;
- push @dates, $prev->sdate if $prev;
-
- push @d, map &{$escape_function}($_),
- $cust_pkg->h_labels_short(@dates)
- #$cust_bill_pkg->edate,
- #$cust_bill_pkg->sdate)
- unless $cust_pkg->part_pkg->hide_svc_detail
- || $cust_bill_pkg->itemdesc
- || $cust_bill_pkg->hidden
- || $is_summary;
-
- push @d, $cust_bill_pkg->details(%details_opt)
- unless ($is_summary || $type && $type eq 'R');
-
- my $amount = 0;
- if (!$type) {
- $amount = $cust_bill_pkg->recur;
- }elsif($type eq 'R') {
- $amount = $cust_bill_pkg->recur - $cust_bill_pkg->usage;
- }elsif($type eq 'U') {
- $amount = $cust_bill_pkg->usage;
- }
-
- if ( !$type || $type eq 'R' ) {
-
- if ( $cust_bill_pkg->hidden ) {
- $r->{amount} += $amount;
- $r->{unit_amount} += $cust_bill_pkg->unitrecur;
- push @{ $r->{ext_description} }, @d;
- } else {
- $r = {
- description => $description,
- #pkgpart => $part_pkg->pkgpart,
- pkgnum => $cust_bill_pkg->pkgnum,
- amount => $amount,
- unit_amount => $cust_bill_pkg->unitrecur,
- quantity => $cust_bill_pkg->quantity,
- ext_description => \@d,
- };
- }
-
- } elsif ( $amount ) { # && $type eq 'U'
-
- if ( $cust_bill_pkg->hidden ) {
- $u->{amount} += $amount;
- $u->{unit_amount} += $cust_bill_pkg->unitrecur;
- push @{ $u->{ext_description} }, @d;
- } else {
- $u = {
- description => $description,
- #pkgpart => $part_pkg->pkgpart,
- pkgnum => $cust_bill_pkg->pkgnum,
- amount => $amount,
- unit_amount => $cust_bill_pkg->unitrecur,
- quantity => $cust_bill_pkg->quantity,
- ext_description => \@d,
- };
- }
-
- }
-
- } # recurring or usage with recurring charge
-
- } else { #pkgnum tax or one-shot line item (??)
-
- if ( $cust_bill_pkg->setup != 0 ) {
- push @b, {
- 'description' => $desc,
- 'amount' => sprintf("%.2f", $cust_bill_pkg->setup),
- };
- }
- if ( $cust_bill_pkg->recur != 0 ) {
- push @b, {
- 'description' => "$desc (".
- time2str("%x", $cust_bill_pkg->sdate). ' - '.
- time2str("%x", $cust_bill_pkg->edate). ')',
- 'amount' => sprintf("%.2f", $cust_bill_pkg->recur),
- };
- }
-
- }
-
- }
-
- }
-
- foreach ( $s, $r, $u ) {
- if ( $_ ) {
- $_->{amount} = sprintf( "%.2f", $_->{amount} ),
- $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ),
- push @b, { %$_ };
- }
- }
-
- @b;
-
-}
-