[freeside-commits] branch FREESIDE_3_BRANCH updated. 02d95b3bb4f7beb0c4c52751c25bd6d37f8f9b59

Jonathan Prykop jonathan at 420.am
Wed Jun 1 17:23:33 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  02d95b3bb4f7beb0c4c52751c25bd6d37f8f9b59 (commit)
      from  5f473f3fbe2e8ad7450300608dd2b72797341d44 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 02d95b3bb4f7beb0c4c52751c25bd6d37f8f9b59
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue May 31 23:53:17 2016 -0500

    RT#42380: Show usage for broadband services in selfservice portal

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 9564e9c..9be7cc3 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -1772,6 +1772,20 @@ sub list_svcs {
 
     # would it make sense to put this in a svc_* method?
 
+    if (!$hide_usage and grep(/^$svcdb$/, qw(svc_acct svc_broadband)) and $part_svc->part_export_usage) {
+      my $last_bill = $cust_pkg->last_bill || 0;
+      my $now = time;
+      my $up_used = $cust_svc->attribute_since_sqlradacct($last_bill,$now,'AcctInputOctets');
+      my $down_used = $cust_svc->attribute_since_sqlradacct($last_bill,$now,'AcctOutputOctets');
+      %hash = (
+        %hash,
+        'seconds_used'    => $cust_svc->seconds_since_sqlradacct($last_bill,$now),
+        'upbytes_used'    => display_bytecount($up_used),
+        'downbytes_used'  => display_bytecount($down_used),
+        'totalbytes_used' => display_bytecount($up_used + $down_used)
+      );
+    }
+
     if ( $svcdb eq 'svc_acct' ) {
       foreach (qw(username email finger seconds)) {
         $hash{$_} = $svc_x->$_;
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 1f46cf1..ca09034 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -709,13 +709,12 @@ sub seconds_since { 'internal session db deprecated'; };
 
 =item seconds_since_sqlradacct TIMESTAMP_START TIMESTAMP_END
 
-See L<FS::svc_acct/seconds_since_sqlradacct>.  Equivalent to
-$cust_svc->svc_x->seconds_since_sqlradacct, but more efficient.  Meaningless
-for records where B<svcdb> is not "svc_acct".
+Equivalent to $cust_svc->svc_x->seconds_since_sqlradacct, but 
+more efficient.  Meaningless for records where B<svcdb> is not 
+svc_acct or svc_broadband.
 
 =cut
 
-#note: implementation here, POD in FS::svc_acct
 sub seconds_since_sqlradacct {
   my($self, $start, $end) = @_;
 
@@ -854,12 +853,11 @@ sub seconds_since_sqlradacct {
 =item attribute_since_sqlradacct TIMESTAMP_START TIMESTAMP_END ATTRIBUTE
 
 See L<FS::svc_acct/attribute_since_sqlradacct>.  Equivalent to
-$cust_svc->svc_x->attribute_since_sqlradacct, but more efficient.  Meaningless
-for records where B<svcdb> is not "svc_acct".
+$cust_svc->svc_x->attribute_since_sqlradacct, but more efficient.
+Meaningless for records where B<svcdb> is not svc_acct or svc_broadband.
 
 =cut
 
-#note: implementation here, POD in FS::svc_acct
 #(false laziness w/seconds_since_sqlradacct above)
 sub attribute_since_sqlradacct {
   my($self, $start, $end, $attrib) = @_;
diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
index b00ff4d..6aa5191 100755
--- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
+++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
@@ -984,7 +984,7 @@ sub delete_svc {
 sub view_usage {
   my $res = list_svcs(
     'session_id'  => $session_id,
-    'svcdb'       => [ 'svc_acct', 'svc_phone', 'svc_port', 'svc_pbx' ],
+    'svcdb'       => [ 'svc_acct', 'svc_broadband', 'svc_phone', 'svc_port', 'svc_pbx' ],
     'ncancelled'  => 1,
   );
   if ($res->{hide_usage}) {
diff --git a/fs_selfservice/FS-SelfService/cgi/view_usage.html b/fs_selfservice/FS-SelfService/cgi/view_usage.html
index 4099a57..07ccfed 100644
--- a/fs_selfservice/FS-SelfService/cgi/view_usage.html
+++ b/fs_selfservice/FS-SelfService/cgi/view_usage.html
@@ -1,21 +1,27 @@
 <%= $url = "$selfurl?action=";
     %by_pkg_label = (); # not used yet, but I'm sure it will be...
-    @svc_acct = ();
     @svc_phone = ();
     @svc_port = ();
     @svc_pbx = ();
-
-    foreach (@svcs) {
-      $by_pkg_label{ $_->{pkg_label} } ||= [];
-      push @{ $by_pkg_label{ $_->{pkg_label} } }, $_;
-      if ( $_->{svcdb} eq 'svc_acct' ) {
-        push @svc_acct, $_;
-      } elsif ( $_->{svcdb} eq 'svc_phone' ) {
-        push @svc_phone, $_;
-      } elsif ( $_->{svcdb} eq 'svc_port' ) {
-        push @svc_port, $_;
-      } elsif ( $_->{svcdb} eq 'svc_pbx' ) {
-        push @svc_pbx, $_;
+    @bytes_svcs = (); # contains svc_acct and svc_broadband
+    @bytes_cols = qw(seconds_used seconds upbytes_used upbytes downbytes_used downbytes totalbytes_used totalbytes);
+    %bytes_show = map { $_ => 0 } @bytes_cols;
+
+    foreach my $svc (@svcs) {
+      $by_pkg_label{ $svc->{pkg_label} } ||= [];
+      push @{ $by_pkg_label{ $svc->{pkg_label} } }, $svc;
+
+      if (( $svc->{svcdb} eq 'svc_acct' ) || ( $svc->{svcdb} eq 'svc_broadband' )) {
+        foreach my $field (@bytes_cols) {
+          $bytes_show{$field} = 1 if length($svc->{$field}) or (($field !~ /_used$/) && $svc->{'recharge_'.$field});
+        }
+        push @bytes_svcs, $svc;
+      } elsif ( $svc->{svcdb} eq 'svc_phone' ) {
+        push @svc_phone, $svc;
+      } elsif ( $svc->{svcdb} eq 'svc_port' ) {
+        push @svc_port, $svc;
+      } elsif ( $svc->{svcdb} eq 'svc_pbx' ) {
+        push @svc_pbx, $svc;
       }
     }
     '';
@@ -26,56 +32,52 @@
   $OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">$error</FONT><BR><BR>!;
 } ''; %>
 
-<%= if ( @svc_acct ) {
-      $OUT.= '<TABLE BGCOLOR="#cccccc">
-                <TR>
-                  <TH ALIGN="left">Account</TH>
-                  <TH ALIGN="right">Time remaining</TH>
-                  <TH ALIGN="right">Upload remaining</TH>
-                  <TH ALIGN="right">Download remaining</TH>
-                  <TH ALIGN="right">Total remaining</TH>
-                </TR>';
-    } else {
-      $OUT .= '';
+<%= if ( @bytes_svcs ) {
+      $OUT .= '<TABLE BGCOLOR="#cccccc"><TR>';
+      $OUT .= '<TH ALIGN="left">Account</TH>';
+      $OUT .= '<TH ALIGN="right">Time used</TH>' if $bytes_show{'seconds_used'};
+      $OUT .= '<TH ALIGN="right">Time remaining</TH>' if $bytes_show{'seconds'};
+      $OUT .= '<TH ALIGN="right">Upload used</TH>' if $bytes_show{'upbytes_used'};
+      $OUT .= '<TH ALIGN="right">Upload remaining</TH>' if $bytes_show{'upbytes'};
+      $OUT .= '<TH ALIGN="right">Download used</TH>' if $bytes_show{'downbytes_used'};
+      $OUT .= '<TH ALIGN="right">Download remaining</TH>' if $bytes_show{'downbytes'};
+      $OUT .= '<TH ALIGN="right">Total used</TH>' if $bytes_show{'totalbytes_used'};
+      $OUT .= '<TH ALIGN="right">Total remaining</TH>' if $bytes_show{'totalbytes'};
+      $OUT .= '</TR>';
     }
 %>
 
-<%= foreach my $svc ( @svc_acct ) {
-      my $link = "${url}view_usage_details;".
-        "svcnum=$svc->{'svcnum'};beginning=0;ending=0";
+<%= foreach my $svc ( @bytes_svcs ) {
+    my $link = "${url}view_usage_details;".
+      "svcnum=$svc->{'svcnum'};beginning=0;ending=0";
     my $username = $svc->{'value'};
     $username =~ s/@.*?$//g if $view_usage_nodomain;
-  $OUT .= '<TR><TD>';
-    $OUT .= qq!<A HREF="$link">!. $svc->{'label'}. ': '. $username .'</A>';
-    $OUT .= '</TD><TD ALIGN="right">';
-    $OUT .= $svc->{'seconds'};
-    $OUT .= '</TD><TD ALIGN="right">';
-    $OUT .=  $svc->{'upbytes'};
-    $OUT .= '</TD><TD ALIGN="right">';
-    $OUT .= $svc->{'downbytes'};
-    $OUT .= '</TD><TD ALIGN="right">';
-    $OUT .= $svc->{'totalbytes'};
-  $OUT .= '</TD></TR>';
+    $OUT .= '<TR>';
+    $OUT .= '<TD>' . qq!<A HREF="$link">!. $svc->{'label'}. ': '. $username .'</A></TD>';
+    foreach my $field (@bytes_cols) {
+      $OUT .= '<TD ALIGN="right">' . $svc->{$field} . '</TD>' if $bytes_show{$field};
+    }
     if ( $svc->{'recharge_amount'} ) {
       my $link = "${url}process_order_recharge;".
                  "svcnum=$svc->{'svcnum'}";
-    $OUT .= '<TR><TD ALIGN="right">';
+      $OUT .= '<TR><TD ALIGN="right">';
       $OUT .= qq!<A HREF="$link">!.'Recharge for $';
       $OUT .= $svc->{'recharge_amount'} . '</A> with';
-      $OUT .= '</TD><TD ALIGN="right">';
-      $OUT .= $svc->{'recharge_seconds'} if $svc->{'recharge_seconds'};
-      $OUT .= '</TD><TD ALIGN="right">';
-      $OUT .=  $svc->{'recharge_upbytes'} if $svc->{'recharge_upbytes'};
-      $OUT .= '</TD><TD ALIGN="right">';
-      $OUT .= $svc->{'recharge_downbytes'} if $svc->{'recharge_downbytes'};
-      $OUT .= '</TD><TD ALIGN="right">';
-      $OUT .= $svc->{'recharge_totalbytes'} if $svc->{'recharge_totalbytes'};
-    $OUT .= '</TD></TR>';
+      $OUT .= '</TD>';
+      foreach my $field ( qw(seconds upbytes downbytes totalbytes) ) {
+        $OUT .= '<TD></TD>' if $bytes_show{$field.'_used'};
+        if ($bytes_show{$field}) {
+          $OUT .= '<TD ALIGN="right">';
+          $OUT .= $svc->{'recharge_'.$field} if $svc->{'recharge_'.$field};
+          $OUT .= '</TD>';
+        }
+      }
+      $OUT .= '</TR>';
     }
   }
 %>
 
-<%= scalar(@svc_acct) ? '</TABLE><BR><BR>' : '' %>
+<%= scalar(@bytes_svcs) ? '</TABLE><BR><BR>' : '' %>
 
 <%= if ( @svc_phone or @svc_pbx ) {
       %any = ();

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/ClientAPI/MyAccount.pm                      |   14 +++
 FS/FS/cust_svc.pm                                 |   12 ++-
 fs_selfservice/FS-SelfService/cgi/selfservice.cgi |    2 +-
 fs_selfservice/FS-SelfService/cgi/view_usage.html |  100 +++++++++++----------
 4 files changed, 71 insertions(+), 57 deletions(-)




More information about the freeside-commits mailing list