From 09589754a8926ef064ea1d3d474a0fc3a8590101 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Sun, 31 May 2015 18:17:28 -0500 Subject: [PATCH] RT#17828: Additional invoice fields on invoice view in selfservice portal --- FS/FS/ClientAPI/MyAccount.pm | 46 ++++++++++++++---------- fs_selfservice/FS-SelfService/cgi/invoices.html | 26 +++++++++----- fs_selfservice/FS-SelfService/cgi/myaccount.html | 28 +++++++++------ 3 files changed, 62 insertions(+), 38 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index c57584e6e..fa2b6ba8c 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -473,11 +473,13 @@ sub customer_info { if ( $session->{'pkgnum'} ) { #XXX open invoices in the pkg-balances case } else { + $return{'money_char'} = $conf->config("money_char") || '$'; my @open = map { { - invnum => $_->invnum, - date => time2str("%b %o, %Y", $_->_date), - owed => $_->owed, + invnum => $_->invnum, + date => time2str("%b %o, %Y", $_->_date), + owed => $_->owed, + charged => $_->charged, }; } $cust_main->open_cust_bill; $return{open_invoices} = \@open; @@ -1589,25 +1591,31 @@ sub list_invoices { my @cust_bill = grep ! $_->hide, $cust_main->cust_bill; my $balance = 0; + my $invoices = [ + map { + #not super efficient, we also run cust_bill_pay/cust_credited inside owed + my @payments_and_credits = sort {$b->_date <=> $a->_date} ($_->cust_bill_pay,$_->cust_credited); + 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), + 'lastpay' => @payments_and_credits + ? time2str("%b %o, %Y", $payments_and_credits[0]->_date) + : '', + } + } @cust_bill + ]; return { 'error' => '', 'balance' => $cust_main->balance, - '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 - ], + 'money_char' => $conf->config("money_char") || '$', + 'invoices' => $invoices, 'legacy_invoices' => [ map { +{ 'legacyinvnum' => $_->legacyinvnum, diff --git a/fs_selfservice/FS-SelfService/cgi/invoices.html b/fs_selfservice/FS-SelfService/cgi/invoices.html index 752805123..ffc44ec85 100644 --- a/fs_selfservice/FS-SelfService/cgi/invoices.html +++ b/fs_selfservice/FS-SelfService/cgi/invoices.html @@ -3,24 +3,34 @@ <%= if ( @invoices ) { - $OUT .= ''. - ''; - my $col1 = "ffffff"; - my $col2 = "dddddd"; + my $th = q!
All Invoices
!; + my $thr = q!!; + $OUT .= ''. + ''.$th.'Invoice #'.$th.'Date'.$thr.'Charges' + .$th.'Date Paid'.$thr.'Owed'; + my $col1 = "#ffffff"; + my $col2 = "#dddddd"; my $col = $col1; foreach my $invoice ( @invoices ) { - my $td = qq!$td${a}Invoice #". $invoice->{'invnum'}. "$td ". - "$td$a". $invoice->{'date'}. "$td". + "". + $td . $a . $invoice->{'invnum'}. "" . + $td . $a . $invoice->{'date'} . "" . + $tdr . $a . $money_char . $invoice->{'charged'} . "" . + $td . $a . $invoice->{'lastpay'} . "" . + $tdr . $a . $money_char . $invoice->{'owed'} . "" . ''; $col = $col eq $col1 ? $col2 : $col1; } + my $tht = ''.$tht.'BALANCE DUE'.$tht.$money_char.$balance.''; $OUT .= '
!; + my $td = qq!!; + my $tdr = qq!!; my $a=qq!'; $OUT .= - "
'; + $OUT .= '

'; } else { - $OUT .= 'You have no invoices.

'; + $OUT .= '

You have no invoices.

'; } %> diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount.html b/fs_selfservice/FS-SelfService/cgi/myaccount.html index 66e2c692e..309021a87 100644 --- a/fs_selfservice/FS-SelfService/cgi/myaccount.html +++ b/fs_selfservice/FS-SelfService/cgi/myaccount.html @@ -28,28 +28,34 @@ Hello <%= $name %>!

} %> <%= if ( @open_invoices ) { - $OUT .= ''. - ''; - my $link = qq!!; + my $thr = q!
Open Invoices
!; + $OUT .= ''. + ''. + ''.$th.'Invoice #'.$th.'Date'.$thr.'Charges' + .$thr.'Owed'; + my $col1 = "#ffffff"; + my $col2 = "#dddddd"; my $col = $col1; foreach my $invoice ( @open_invoices ) { - my $td = qq!$td${a}Invoice #". $invoice->{'invnum'}. "$td". - "$td$a". $invoice->{'date'}. "$td". - qq!'. + "". + $td . $a . $invoice->{'invnum'}. "" . + $td . $a . $invoice->{'date'} . "" . + $tdr . $a . $money_char . $invoice->{'charged'} . "" . + $tdr . $a . $money_char . $invoice->{'owed'} . "" . ''; $col = $col eq $col1 ? $col2 : $col1; } $OUT .= '
Open Invoices
!; + my $td = qq!!; + my $tdr = qq!!; my $a=qq!'; $OUT .= - "
$a\$!. $invoice->{'owed'}. - '

'; } else { - $OUT .= 'You have no outstanding invoices.

'; + $OUT .= '

You have no outstanding invoices.

'; } + %> <%= -- 2.11.0