X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=39a810c132b39fa48cb06bfdc041d834486c9c85;hb=0692ff47a2eac65616bf24104a51e558506f1b8f;hp=cdce7be47ecffcedff4ee8507df6430129a236f4;hpb=32072dbf59a054529f5304574c0f56f9567d14d0;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index cdce7be47..39a810c13 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -2,7 +2,7 @@ package FS::cust_bill; use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::Record ); use strict; -use vars qw( $DEBUG $me $date_format ); +use vars qw( $DEBUG $me ); # but NOT $conf use Fcntl qw(:flock); #for spool_csv use Cwd; @@ -44,7 +44,6 @@ $me = '[FS::cust_bill]'; #ask FS::UID to run this stuff for us later FS::UID->install_callback( sub { my $conf = new FS::Conf; #global - $date_format = $conf->config('date_format') || '%x'; #/YY } ); =head1 NAME @@ -158,7 +157,7 @@ sub notice_name { $self->conf->config('notice_name') || 'Invoice' } -sub cust_linked { $_[0]->cust_main_custnum; } +sub cust_linked { $_[0]->cust_main_custnum || $_[0]->custnum } sub cust_unlinked_msg { my $self = shift; "WARNING: can't find cust_main.custnum ". $self->custnum. @@ -1066,6 +1065,8 @@ sub generate_email { my %return = ( 'from' => $args{'from'}, 'subject' => ($args{'subject'} || $self->email_subject), + 'custnum' => $self->custnum, + 'msgtype' => 'invoice', ); $args{'unsquelch_cdr'} = $conf->exists('voip-cdr_email'); @@ -1118,6 +1119,7 @@ sub generate_email { $alternative->attach( 'Type' => 'text/plain', 'Encoding' => 'quoted-printable', + 'Charset' => 'UTF-8', #'Encoding' => '7bit', 'Data' => $data, 'Disposition' => 'inline', @@ -1396,7 +1398,7 @@ sub email { my $self = shift; return if $self->hide; my $conf = $self->conf; - my $opt = shift; + my $opt = shift || {}; if ($opt and !ref($opt)) { die "FS::cust_bill::email called with positional parameters"; } @@ -1471,7 +1473,7 @@ I, if specified, overrides "Invoice" as the name of the sent docume sub lpr_data { my $self = shift; my $conf = $self->conf; - my $opt = shift; + my $opt = shift || {}; if ($opt and !ref($opt)) { # nobody does this anyway die "FS::cust_bill::lpr_data called with positional parameters"; @@ -1497,7 +1499,7 @@ sub print { my $self = shift; return if $self->hide; my $conf = $self->conf; - my $opt = shift; + my $opt = shift || {}; if ($opt and !ref($opt)) { die "FS::cust_bill::print called with positional parameters"; } @@ -1532,7 +1534,7 @@ sub fax_invoice { my $self = shift; return if $self->hide; my $conf = $self->conf; - my $opt = shift; + my $opt = shift || {}; if ($opt and !ref($opt)) { die "FS::cust_bill::fax_invoice called with positional parameters"; } @@ -1659,6 +1661,7 @@ sub send_csv { my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/cust_bill"; mkdir $spooldir, 0700 unless -d $spooldir; + # don't localize dates here, they're a defined format my $tracctnum = $self->invnum. time2str('-%Y%m%d%H%M%S', time); my $file = "$spooldir/$tracctnum.csv"; @@ -1965,13 +1968,13 @@ sub print_csv { my $taxtotal = 0; $taxtotal += $_->{'amount'} foreach $self->_items_tax; - my $duedate = $self->due_date2str('%m/%d/%Y'); #date_format? + my $duedate = $self->due_date2str('%m/%d/%Y'); # hardcoded, NOT date_format my( $previous_balance, @unused ) = $self->previous; #previous balance my $pmt_cr_applied = 0; $pmt_cr_applied += $_->{'amount'} - foreach ( $self->_items_payments, $self->_items_credits ) ; + foreach ( $self->_items_payments(%opt), $self->_items_credits(%opt) ) ; my $totaldue = sprintf('%.2f', $self->owed + $previous_balance); @@ -2252,7 +2255,7 @@ sub print_csv { ? time2str("%x", $cust_bill_pkg->sdate) : '' ), ($cust_bill_pkg->edate - ?time2str("%x", $cust_bill_pkg->edate) + ? time2str("%x", $cust_bill_pkg->edate) : '' ), ); @@ -2965,8 +2968,8 @@ sub _items_previous { my @b = (); foreach ( @pr_cust_bill ) { my $date = $conf->exists('invoice_show_prior_due_date') - ? 'due '. $_->due_date2str($date_format) - : time2str($date_format, $_->_date); + ? 'due '. $_->due_date2str('short') + : $self->time2str_local('short', $_->_date); push @b, { 'description' => $self->mt('Previous Balance, Invoice #'). $_->invnum. " ($date)", #'pkgpart' => 'N/A', @@ -2998,14 +3001,22 @@ sub _items_credits { #credits my @objects; if ( $self->conf->exists('previous_balance-payments_since') ) { - my $date = 0; - $date = $self->previous_bill->_date if $self->previous_bill; - @objects = qsearch('cust_credit', { - 'custnum' => $self->custnum, - '_date' => {op => '>=', value => $date}, + if ( $opt{'template'} eq 'statement' ) { + # then the current bill is a "statement" (i.e. an invoice sent as + # a payment receipt) + # and in that case we want to see payments on or after THIS invoice + @objects = qsearch('cust_credit', { + 'custnum' => $self->custnum, + '_date' => {op => '>=', value => $self->_date}, }); - # hard to do this in the qsearch... - @objects = grep { $_->_date < $self->_date } @objects; + } else { + my $date = 0; + $date = $self->previous_bill->_date if $self->previous_bill; + @objects = qsearch('cust_credit', { + 'custnum' => $self->custnum, + '_date' => {op => '>=', value => $date}, + }); + } } else { @objects = $self->cust_credited; } @@ -3022,7 +3033,7 @@ sub _items_credits { # " (". time2str("%x",$_->cust_credit->_date) .")". # $reason, 'description' => $self->mt('Credit applied').' '. - time2str($date_format,$obj->_date). $reason, + $self->time2str_local('short', $obj->_date). $reason, 'amount' => sprintf("%.2f",$obj->amount), }; } @@ -3033,18 +3044,32 @@ sub _items_credits { sub _items_payments { my $self = shift; + my %opt = @_; my @b; my $detailed = $self->conf->exists('invoice_payment_details'); my @objects; if ( $self->conf->exists('previous_balance-payments_since') ) { - my $date = 0; - $date = $self->previous_bill->_date if $self->previous_bill; - @objects = qsearch('cust_pay', { + # then show payments dated on/after the previous bill... + if ( $opt{'template'} eq 'statement' ) { + # then the current bill is a "statement" (i.e. an invoice sent as + # a payment receipt) + # and in that case we want to see payments on or after THIS invoice + @objects = qsearch('cust_pay', { + 'custnum' => $self->custnum, + '_date' => {op => '>=', value => $self->_date}, + }); + } else { + # the normal case: payments on or after the previous invoice + my $date = 0; + $date = $self->previous_bill->_date if $self->previous_bill; + @objects = qsearch('cust_pay', { 'custnum' => $self->custnum, '_date' => {op => '>=', value => $date}, }); - @objects = grep { $_->_date < $self->_date } @objects; + # and before the current bill... + @objects = grep { $_->_date < $self->_date } @objects; + } } else { @objects = $self->cust_bill_pay; } @@ -3052,7 +3077,7 @@ sub _items_payments { foreach my $obj (@objects) { my $cust_pay = $obj->isa('FS::cust_pay') ? $obj : $obj->cust_pay; my $desc = $self->mt('Payment received').' '. - time2str($date_format, $cust_pay->_date ); + $self->time2str_local('short', $cust_pay->_date ); $desc .= $self->mt(' via ') . $cust_pay->payby_payinfo_pretty( $self->cust_main->locale ) if $detailed;