From a6df3bedc91aba52e5010241f1b94a780d478b5c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Sep 2011 15:50:03 +0000 Subject: [PATCH] add invoice_pdf to selfservice, RT#13656 --- FS/FS/ClientAPI/MyAccount.pm | 46 ++++++++++++++++++++++++---- FS/FS/ClientAPI_XMLRPC.pm | 1 + fs_selfservice/FS-SelfService/SelfService.pm | 1 + 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index a1fd4b36e..fa667c0c0 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -936,6 +936,28 @@ sub invoice { } +sub invoice_pdf { + my $p = shift; + my $session = _cache->get($p->{'session_id'}) + or return { 'error' => "Can't resume session" }; #better error message + + my $custnum = $session->{'custnum'}; + + my $invnum = $p->{'invnum'}; + + my $cust_bill = qsearchs('cust_bill', { 'invnum' => $invnum, + 'custnum' => $custnum } ) + or return { 'error' => "Can't find invnum" }; + + #my %return; + + return { 'error' => '', + 'invnum' => $invnum, + 'invoice_pdf' => $cust_bill->print_pdf( { unsquelch_cdr => 1 } ), + }; + +} + sub invoice_logo { my $p = shift; @@ -981,13 +1003,25 @@ sub list_invoices { my @cust_bill = $cust_main->cust_bill; + my $balance = 0; + return { 'error' => '', - 'invoices' => [ map { { 'invnum' => $_->invnum, - '_date' => $_->_date, - 'date' => time2str("%b %o, %Y", $_->_date), - } - } @cust_bill - ] + 'invoices' => [ + map { + my $owed = $_->owed; + $balance += $owed; + +{ 'invnum' => $_->invnum, + '_date' => $_->_date, + 'date' => time2str("%b %o, %Y", $_->_date), + 'date_short' => time2str("%m-%d-%Y", $_->_date), + 'previous' => sprintf('%.2f', ($_->previous)[0]), + 'charged' => sprintf('%.2f', $_->charged), + 'owed' => sprintf('%.2f', $owed), + 'balance' => sprintf('%.2f', $balance), + } + } + @cust_bill + ] }; } diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm index 5cfb7d15c..33638f840 100644 --- a/FS/FS/ClientAPI_XMLRPC.pm +++ b/FS/FS/ClientAPI_XMLRPC.pm @@ -69,6 +69,7 @@ sub ss2clientapi { 'customer_info' => 'MyAccount/customer_info', 'edit_info' => 'MyAccount/edit_info', #add to ss cgi! 'invoice' => 'MyAccount/invoice', + 'invoice_pdf' => 'MyAccount/invoice_pdf', 'invoice_logo' => 'MyAccount/invoice_logo', 'list_invoices' => 'MyAccount/list_invoices', #? 'cancel' => 'MyAccount/cancel', #add to ss cgi! diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 5b215f10b..b45cf16a7 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -31,6 +31,7 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'customer_info' => 'MyAccount/customer_info', 'edit_info' => 'MyAccount/edit_info', #add to ss cgi! 'invoice' => 'MyAccount/invoice', + 'invoice_pdf' => 'MyAccount/invoice_pdf', 'invoice_logo' => 'MyAccount/invoice_logo', 'list_invoices' => 'MyAccount/list_invoices', #? 'cancel' => 'MyAccount/cancel', #add to ss cgi! -- 2.11.0