From: mark Date: Wed, 1 Feb 2012 05:30:16 +0000 (+0000) Subject: print customer statements on the fly, #15864 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=33631ac48cd91bf9bee1cd7f25f2f23fc640cb65 print customer statements on the fly, #15864 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 2899de3ee..8e48dc20d 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -4673,6 +4673,13 @@ and customer address. Include units.', 'select_enum' => [ 'Classic', 'Recurring' ], }, + { + 'key' => 'cust_main-print_statement_link', + 'section' => 'UI', + 'description' => 'Show a link to download a current statement for the customer.', + 'type' => 'checkbox', + }, + { 'key' => 'username-pound', 'section' => 'username', diff --git a/FS/FS/cust_statement.pm b/FS/FS/cust_statement.pm index 83dd5c1be..45fae1ccf 100644 --- a/FS/FS/cust_statement.pm +++ b/FS/FS/cust_statement.pm @@ -60,6 +60,10 @@ Creates a new record. To add the record to the database, see L<"insert">. Note that this stores the hash reference, not a distinct copy of the hash it points to. You can ask the object for a copy with the I method. +Pass "statementnum => 'ALL'" to create a temporary statement that includes +all of the customer's invoices. This statement can't be inserted and won't +set the statementnum field on any invoices. + =cut sub new { FS::Record::new(@_); } @@ -165,7 +169,16 @@ Returns the associated invoices (cust_bill records) for this statement. sub cust_bill { my $self = shift; - qsearch('cust_bill', { 'statementnum' => $self->statementnum } ); + # we use it about a thousand times, let's cache it + $self->{Hash}->{cust_bill} ||= [ + qsearch('cust_bill', { + $self->statementnum eq 'ALL' ? + ('custnum' => $self->custnum) : + ('statementnum' => $self->statementnum) + } ) + ]; + + @{ $self->{Hash}->{cust_bill} } } sub _aggregate { diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html index 63708e63c..b5b716199 100644 --- a/httemplate/view/cust_main/payment_history.html +++ b/httemplate/view/cust_main/payment_history.html @@ -123,8 +123,14 @@ -%# invoice reports +%# invoice reports, combined statement % if ( $curuser->access_right('List invoices') ) { +% if ( $conf->exists('cust_main-print_statement_link') +% and $num_cust_bill > 0 ) { + <% + mt('Print a current statement') |h %> +
+% } <% mt('Invoice reports') |h %> % }
@@ -410,12 +416,14 @@ foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) { } #invoices +my $num_cust_bill = 0; foreach my $cust_bill ($cust_main->cust_bill) { push @history, { 'date' => $cust_bill->_date, 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ), 'charge' => $cust_bill->charged, }; + $num_cust_bill++; } #statements diff --git a/httemplate/view/cust_main_statement-pdf.cgi b/httemplate/view/cust_main_statement-pdf.cgi new file mode 100755 index 000000000..7a0e19838 --- /dev/null +++ b/httemplate/view/cust_main_statement-pdf.cgi @@ -0,0 +1,39 @@ +<%doc> +Like view/cust_statement-pdf.cgi, but for viewing/printing the implicit +statement containing all of a customer's invoices. Slightly redundant. +I don't see the need to create an equivalent to view/cust_statement.html +for this case, but one can be added if necessary. + +<% $pdf %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('View invoices'); + +#untaint statement +my($query) = $cgi->keywords; +$query =~ /^((.+)-)?(\d+)$/; +my $templatename = $2 || 'statement'; #XXX configure... via event?? eh.. +my $custnum = $3; + +my $cust_main = qsearchs({ + 'select' => 'cust_main.*', + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, +}); +die "Customer #$custnum not found!" unless $cust_main; + +my $cust_statement = FS::cust_statement->new({ + 'custnum' => $custnum, + 'statementnum' => 'ALL', #magic + '_date' => time, +}); + +my $pdf = $cust_statement->print_pdf( '', $templatename ); + +http_header('Content-Type' => 'application/pdf' ); +http_header('Content-Length' => length($pdf) ); +http_header('Cache-control' => 'max-age=60' ); + +