RT#17828: Additional invoice fields on invoice view in selfservice portal
authorJonathan Prykop <jonathan@freeside.biz>
Sun, 31 May 2015 23:17:28 +0000 (18:17 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Sun, 31 May 2015 23:17:28 +0000 (18:17 -0500)
FS/FS/ClientAPI/MyAccount.pm
fs_selfservice/FS-SelfService/cgi/invoices.html
fs_selfservice/FS-SelfService/cgi/myaccount.html

index c57584e..fa2b6ba 100644 (file)
@@ -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,
index 7528051..ffc44ec 100644 (file)
@@ -3,24 +3,34 @@
 
 <%=
   if ( @invoices ) {
-    $OUT .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR="#eeeeee">'.
-            '<TR><TH BGCOLOR="#ff6666" COLSPAN=4>All Invoices</TH></TR>';
-    my $col1 = "ffffff";
-    my $col2 = "dddddd";
+    my $th  = q!<TH STYLE="background: #ff9999; text-align: left; padding: .1em .5em;">!;
+    my $thr = q!<TH STYLE="background: #ff9999; text-align: right; padding: .1em .5em;">!;
+    $OUT .= '<TABLE STYLE="border: 0;" CELLSPACING="0">'.
+            '<TR>'.$th.'Invoice #</TH>'.$th.'Date</TH>'.$thr.'Charges</TH>'
+            .$th.'Date Paid</TH>'.$thr.'Owed</TH></TR>';
+    my $col1 = "#ffffff";
+    my $col2 = "#dddddd";
     my $col = $col1;
 
     foreach my $invoice ( @invoices ) {
-      my $td = qq!<TD BGCOLOR="#$col">!;
+      my $td  = qq!<TD STYLE="background: $col; padding: .1em .5em;">!;
+      my $tdr = qq!<TD STYLE="background: $col; padding: .1em .5em; text-align: right;">!;
       my $a=qq!<A HREF="${url}view_invoice;invnum=!. $invoice->{'invnum'}. '">';
       $OUT .=
-        "<TR>$td${a}Invoice #". $invoice->{'invnum'}. "</A></TD>$td&nbsp;</TD>".
-        "$td$a". $invoice->{'date'}. "</A></TD>$td</TD>".
+        "<TR>".
+        $td . $a . $invoice->{'invnum'}. "</A></TD>" .
+        $td . $a . $invoice->{'date'} . "</A></TD>" .
+        $tdr . $a . $money_char . $invoice->{'charged'} . "</A></TD>" .
+        $td . $a . $invoice->{'lastpay'} . "</A></TD>" .
+        $tdr . $a . $money_char . $invoice->{'owed'} . "</A></TD>" .
         '</TR>';
       $col = $col eq $col1 ? $col2 : $col1;
     }
+    my $tht = '<TH COLSPAN="4" STYLE="background: #ff9999; padding: .1em .5em; text-align: right;">';
+    $OUT .= '<TR>'.$tht.'BALANCE DUE</TH>'.$tht.$money_char.$balance.'</TH></TR>';
     $OUT .= '</TABLE><BR>';
   } else {
-    $OUT .= 'You have no invoices.<BR><BR>';
+    $OUT .= '<P>You have no invoices.</P>';
   }
 %>
 
index 66e2c69..309021a 100644 (file)
@@ -28,28 +28,34 @@ Hello <%= $name %>!<BR><BR>
 } %>
 <%=
   if ( @open_invoices ) {
-    $OUT .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR="#eeeeee">'.
-            '<TR><TH BGCOLOR="#ff6666" COLSPAN=5>Open Invoices</TH></TR>';
-    my $link = qq!<A HREF="<%= $url %>myaccount!;
-    my $col1 = $stripe1_bgcolor || '#ffffff';
-    my $col2 = $stripe2_bgcolor || '#dddddd';
+    my $th  = q!<TH STYLE="background: #ff9999; text-align: left; padding: .1em .5em;">!;
+    my $thr = q!<TH STYLE="background: #ff9999; text-align: right; padding: .1em .5em;">!;
+    $OUT .= '<TABLE STYLE="border: 0;" CELLSPACING="0">'.
+            '<TR><TH BGCOLOR="#ff6666" COLSPAN="4">Open Invoices</TH></TR>'.
+            '<TR>'.$th.'Invoice #</TH>'.$th.'Date</TH>'.$thr.'Charges</TH>'
+            .$thr.'Owed</TH></TR>';
+    my $col1 = "#ffffff";
+    my $col2 = "#dddddd";
     my $col = $col1;
 
     foreach my $invoice ( @open_invoices ) {
-      my $td = qq!<TD BGCOLOR="$col">!;
+      my $td  = qq!<TD STYLE="background: $col; padding: .1em .5em;">!;
+      my $tdr = qq!<TD STYLE="background: $col; padding: .1em .5em; text-align: right;">!;
       my $a=qq!<A HREF="${url}view_invoice;invnum=!. $invoice->{'invnum'}. '">';
       $OUT .=
-        "<TR>$td${a}Invoice #". $invoice->{'invnum'}. "</A></TD>$td</TD>".
-        "$td$a". $invoice->{'date'}. "</A></TD>$td</TD>".
-        qq!<TD BGCOLOR="$col" ALIGN="right">$a\$!. $invoice->{'owed'}.
-          '</A></TD>'.
+        "<TR>".
+        $td . $a . $invoice->{'invnum'}. "</A></TD>" .
+        $td . $a . $invoice->{'date'} . "</A></TD>" .
+        $tdr . $a . $money_char . $invoice->{'charged'} . "</A></TD>" .
+        $tdr . $a . $money_char . $invoice->{'owed'} . "</A></TD>" .
         '</TR>';
       $col = $col eq $col1 ? $col2 : $col1;
     }
     $OUT .= '</TABLE><BR>';
   } else {
-    $OUT .= 'You have no outstanding invoices.<BR><BR>';
+    $OUT .= '<P>You have no outstanding invoices.</P>';
   }
+
 %>
 
 <%=