X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=dd8fab231fb58e63e3b0ce7f457cb10b2f18f3d9;hp=4b8c3f37accb5af9537a9d5f3dbdd25bf8ad631c;hb=a1cde9ea31bf9f019ecf706efb158c2baa11efa7;hpb=3b0da26ea81169a7693d8bbc8719e8a9aa500734 diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 4b8c3f37a..dd8fab231 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -5,6 +5,7 @@ use vars qw( @ISA $DEBUG $me $conf $money_char $date_format $rdate_format $date_format_long ); use vars qw( $invoice_lines @buf ); #yuck use Fcntl qw(:flock); #for spool_csv +use Cwd; use List::Util qw(min max); use Date::Format; use Text::Template 1.20; @@ -38,7 +39,8 @@ use FS::part_bill_event; use FS::payby; use FS::bill_batch; use FS::cust_bill_batch; -use Cwd; +use FS::cust_bill_pay_pkg; +use FS::cust_credit_bill_pkg; @ISA = qw( FS::cust_main_Mixin FS::Record ); @@ -649,44 +651,86 @@ sub cust_credit_bill { shift->cust_credited(@_); } -=item cust_bill_pay_pkgnum PKGNUM +#=item cust_bill_pay_pkgnum PKGNUM +# +#Returns all payment applications (see L) for this invoice +#with matching pkgnum. +# +#=cut +# +#sub cust_bill_pay_pkgnum { +# my( $self, $pkgnum ) = @_; +# map { $_ } #return $self->num_cust_bill_pay_pkgnum($pkgnum) unless wantarray; +# sort { $a->_date <=> $b->_date } +# qsearch( 'cust_bill_pay', { 'invnum' => $self->invnum, +# 'pkgnum' => $pkgnum, +# } +# ); +#} + +=item cust_bill_pay_pkg PKGNUM Returns all payment applications (see L) for this invoice -with matching pkgnum. +applied against the matching pkgnum. =cut -sub cust_bill_pay_pkgnum { +sub cust_bill_pay_pkg { my( $self, $pkgnum ) = @_; - map { $_ } #return $self->num_cust_bill_pay_pkgnum($pkgnum) unless wantarray; - sort { $a->_date <=> $b->_date } - qsearch( 'cust_bill_pay', { 'invnum' => $self->invnum, - 'pkgnum' => $pkgnum, - } - ); + + qsearch({ + 'select' => 'cust_bill_pay_pkg.*', + 'table' => 'cust_bill_pay_pkg', + 'addl_from' => ' LEFT JOIN cust_bill_pay USING ( billpaynum ) '. + ' LEFT JOIN cust_bill_pkg USING ( billpkgnum ) ', + 'extra_sql' => ' WHERE invnum = '. $self->invnum. + " AND pkgnum = $pkgnum", + }); + } -=item cust_credited_pkgnum PKGNUM +#=item cust_credited_pkgnum PKGNUM +# +#=item cust_credit_bill_pkgnum PKGNUM +# +#Returns all applied credits (see L) for this invoice +#with matching pkgnum. +# +#=cut +# +#sub cust_credited_pkgnum { +# my( $self, $pkgnum ) = @_; +# map { $_ } #return $self->num_cust_credit_bill_pkgnum($pkgnum) unless wantarray; +# sort { $a->_date <=> $b->_date } +# qsearch( 'cust_credit_bill', { 'invnum' => $self->invnum, +# 'pkgnum' => $pkgnum, +# } +# ); +#} +# +#sub cust_credit_bill_pkgnum { +# shift->cust_credited_pkgnum(@_); +#} -=item cust_credit_bill_pkgnum PKGNUM +=item cust_credit_bill_pkg PKGNUM -Returns all applied credits (see L) for this invoice -with matching pkgnum. +Returns all credit applications (see L) for this invoice +applied against the matching pkgnum. =cut -sub cust_credited_pkgnum { +sub cust_credit_bill_pkg { my( $self, $pkgnum ) = @_; - map { $_ } #return $self->num_cust_credit_bill_pkgnum($pkgnum) unless wantarray; - sort { $a->_date <=> $b->_date } - qsearch( 'cust_credit_bill', { 'invnum' => $self->invnum, - 'pkgnum' => $pkgnum, - } - ); -} -sub cust_credit_bill_pkgnum { - shift->cust_credited_pkgnum(@_); + qsearch({ + 'select' => 'cust_credit_bill_pkg.*', + 'table' => 'cust_credit_bill_pkg', + 'addl_from' => ' LEFT JOIN cust_credit_bill USING ( creditbillnum ) '. + ' LEFT JOIN cust_bill_pkg USING ( billpkgnum ) ', + 'extra_sql' => ' WHERE invnum = '. $self->invnum. + " AND pkgnum = $pkgnum", + }); + } =item tax @@ -729,8 +773,8 @@ sub owed_pkgnum { my $balance = 0; $balance += $_->setup + $_->recur for $self->cust_bill_pkg_pkgnum($pkgnum); - $balance -= $_->amount for $self->cust_bill_pay_pkgnum($pkgnum); - $balance -= $_->amount for $self->cust_credited_pkgnum($pkgnum); + $balance -= $_->amount for $self->cust_bill_pay_pkg($pkgnum); + $balance -= $_->amount for $self->cust_credit_bill_pkg($pkgnum); $balance = sprintf( "%.2f", $balance); $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp @@ -911,6 +955,7 @@ sub generate_email { 'unsquelch_cdr' => $conf->exists('voip-cdr_email'), 'template' => $args{'template'}, 'notice_name' => ( $args{'notice_name'} || 'Invoice' ), + 'no_coupon' => $args{'no_coupon'}, ); my $cust_main = $self->cust_main; @@ -1259,11 +1304,12 @@ sub queueable_email { my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } ) or die "invalid invoice number: " . $opt{invnum}; - my @args = ( $opt{template} ); - push @args, $opt{invoice_from} - if exists($opt{invoice_from}) && $opt{invoice_from}; + my %args = ( 'template' => $opt{template} ); + $args{$_} = $opt{$_} + foreach grep { exists($opt{$_}) && $opt{$_} } + qw( invoice_from notice_name no_coupon ); - my $error = $self->email( @args ); + my $error = $self->email( \%args ); die $error if $error; } @@ -1272,16 +1318,18 @@ sub queueable_email { sub email { my $self = shift; - my( $template, $invoice_from, $notice_name ); + my( $template, $invoice_from, $notice_name, $no_coupon ); if ( ref($_[0]) ) { my $opt = shift; $template = $opt->{'template'} || ''; $invoice_from = $opt->{'invoice_from'}; $notice_name = $opt->{'notice_name'} || 'Invoice'; + $no_coupon = $opt->{'no_coupon'} || 0; } else { $template = scalar(@_) ? shift : ''; $invoice_from = shift if scalar(@_); $notice_name = 'Invoice'; + $no_coupon = 0; } $invoice_from ||= $self->_agent_invoice_from || #XXX should go away @@ -1308,6 +1356,7 @@ sub email { 'subject' => $subject, 'template' => $template, 'notice_name' => $notice_name, + 'no_coupon' => $no_coupon, ) ); die "can't email invoice: $error\n" if $error; @@ -2295,7 +2344,7 @@ sub print_generic { my $template = $params{template} ? $params{template} : $self->_agent_template; my $templatefile = "invoice_$format"; $templatefile .= "_$template" - if length($template); + if length($template) && $conf->exists($templatefile."_$template"); my @invoice_template = map "$_\n", $conf->config($templatefile) or die "cannot load config data $templatefile"; @@ -2643,7 +2692,9 @@ sub print_generic { warn "$me substituting variables in notes, footer, smallfooter\n" if $DEBUG > 1; - foreach my $include (qw( notes footer smallfooter coupon )) { + my @include = (qw( notes footer smallfooter )); + push @include, 'coupon' unless $params{'no_coupon'}; + foreach my $include (@include) { my $inc_file = $conf->key_orbase("invoice_${format}$include", $template); my @inc_src; @@ -2721,7 +2772,7 @@ sub print_generic { sprintf('%.2f', $pr_total), 'summarized' => $summarypage ? 'Y' : '', }; - $previous_section->{posttotal} = '0 / 30 / 60/ 90 days overdue '. + $previous_section->{posttotal} = '0 / 30 / 60 / 90 days overdue '. join(' / ', map { $cust_main->balance_date_range(@$_) } $self->_prior_month30s )