-<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
-<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
-<%= $url = "$selfurl?session=$session_id;action="; ''; %>
-<%= include('myaccount_menu') %>
-<TD VALIGN="top">
+<%= $url = "$selfurl?action=";
+ %by_pkg_label = (); # not used yet, but I'm sure it will be...
+ @svc_phone = ();
+ @svc_port = ();
+ @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;
-<FONT SIZE=4>Service usage</FONT><BR><BR>
+ 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;
+ }
+ }
+ '';
+%>
+<%= include('header', 'Account usage') %>
<%= if ( $error ) {
$OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">$error</FONT><BR><BR>!;
} ''; %>
-<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>
-<%= foreach my $svc ( @svcs ) {
- $OUT .= '<TR><TD>';
- $OUT .= $svc->{'label'}. ': '. $svc->{'value'};
- $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>';
+<%= 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 ( @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>';
+ $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>';
+ }
+ }
+ if ((@bytes_svcs > 1) and (grep { $bytes_show{$_.'_used'} } qw(seconds upbytes downbytes totalbytes) )) {
+ $OUT .= '<TR>';
+ $OUT .= '<TH align="left">Total Used</TH>';
+ foreach my $field (@bytes_cols) {
+ if ($bytes_show{$field}) {
+ $OUT .= '<TD ALIGN="right">';
+ $OUT .= $bytes_used_total{$field} || '0' if $field =~ /_used$/;
+ $OUT .= '</TD>';
+ }
+ }
+ $OUT .= '</TR>';
+ }
+%>
+
+<%= scalar(@bytes_svcs) ? '</TABLE><BR><BR>' : '' %>
+
+<%= if ( @svc_phone or @svc_pbx ) {
+ %any = ();
+ for my $dir (qw(outbound inbound)) {
+ $any{$dir} = grep { $_->{$dir} } (@svc_phone, @svc_pbx);
+ }
+ $OUT.= '<FONT SIZE="4">Call usage</FONT><BR><BR>
+ <TABLE BGCOLOR="#cccccc" STYLE="display:inline-block">
+ <TR>
+ <TH ALIGN="left">Number</TH>';
+ if ( $any{outbound} ) {
+ $OUT .= '
+ <TH>Dialed</TH>';
+ }
+ if ( $any{inbound} ) {
+ $OUT .= '
+ <TH>Received</TH>';
+ }
+ $OUT .= '</TR>';
+ } else {
+ $OUT .= '';
+ }
+%>
+
+<%= foreach my $svc_x ( @svc_phone, @svc_pbx ) {
+ my $link = $url . 'view_cdr_details;' .
+ 'svcnum='.$svc_x->{'svcnum'}.
+ ';beginning=0;ending=0';
+ $OUT .= '<TR><TD>'. $svc_x->{'label'}. ': '. $svc_x->{'value'};
+ $OUT .= '</TD>';
+ # usage summary w/ links
+ for my $dir (qw(outbound inbound)) {
+ if ( $dir eq 'inbound' ) {
+ $link .= ';inbound=1';
}
- } %>
+ if ( $svc_x->{$dir} ) {
+ $OUT .= '<TD ALIGN="right">'.qq!<A HREF="$link">! .
+ sprintf('%d calls (%.0f minutes)',
+ $svc_x->{$dir}->{'count'},
+ $svc_x->{$dir}->{'duration'} / 60
+ ) .
+ '</A></TD>';
+ } elsif ( $any{$dir} ) {
+ $OUT .= '<TD></TD>';
+ }
+ }
+ $OUT .= '</TR>';
+}
+'';
+%>
+
+<%= if ( @usage_pools ) {
+ $OUT .= '</TABLE>
+ <TABLE BGCOLOR="#cccccc" STYLE="display: inline-block">
+ <TR><TH COLSPAN=4>Remaining minutes</TH></TR>
+ ';
+ my $any_shared = 0;
+ foreach my $usage (@usage_pools) {
+ # false laziness with the back office side
+ my ($description, $remain, $total, $shared) = @$usage;
+ if ( $shared ) {
+ $any_shared = 1;
+ $description .= '*';
+ }
+ my $ratio = 255 * ($remain/$total);
+ $ratio = 255 if $color > 255;
+ my $color =
+ sprintf('STYLE="font-weight: bold; color: #%02x%02x00"',
+ 255 - $ratio, $ratio);
+ $OUT .=
+ qq!<TR>
+ <TD ALIGN="right">$description</TD>
+ <TD $color ALIGN="right">$remain</TD>
+ <TD $color> / </TD>
+ <TD $color>$total</TD>
+ </TR>!;
+ }
+ if ( $any_shared ) {
+ $OUT .= '<TR STYLE="font-size: 80%; font-style: italic">'.
+ '<TD COLSPAN=4>* shared among all your phone plans</TD></TR>';
+ }
+}
+if ( @svc_phone or @svc_pbx or @usage_pools ) {
+ $OUT .= '</TABLE><BR><BR>';
+}
+'';
+%>
+
+<%= if ( @svc_port ) {
+ $OUT.= '<FONT SIZE="4">Bandwidth Graphs</FONT><BR><BR>
+ <script type="text/javascript">
+ function preset_range(start,end,prefix){
+ document.getElementById(prefix+\'_start\').value = start;
+ document.getElementById(prefix+\'_end\').value = end;
+ }
+ </script>
+ <TABLE BGCOLOR="#cccccc">
+ <TR>
+ <TH ALIGN="left">Service</TH>
+ <TH ALIGN="right">
+ </TH>
+ </TR>';
+ }
+ $OUT .= '';
+%>
+
+<%=
+
+sub preset_range {
+ my($start,$end,$label,$date_format,$prefix) = (shift,shift,shift,shift,shift);
+ $start = Date::Format::time2str($date_format,$start);
+ $end = Date::Format::time2str($date_format,$end);
+ return '<A HREF="javascript:void(0);" onclick="preset_range(\''
+ .$start.'\',\''.$end.'\',\''.$prefix.'\')">'.$label.'</A>';
+}
+
+foreach my $svc_port ( @svc_port ) {
+ $svcnum = $svc_port->{'svcnum'};
+ $default_end = time;
+ $default_start = $default_end-86400;
+
+ $OUT .= '<TR><TD>'. $svc_port->{'label'}. ': '. $svc_port->{'value'}.'</TD>';
+ $OUT .= qq! <TD><FORM ACTION="$url" METHOD="GET">
+ <INPUT TYPE="hidden" name="svcnum" value="$svcnum">
+ <INPUT TYPE="hidden" name="action" value="view_port_graph"> !;
+ $OUT .= preset_range($default_start,$default_end,'Last Day',$date_format,$svcnum)
+ .' | '.preset_range($default_end-86400*7,$default_end,'Last Week',$date_format,$svcnum)
+ .' | '.preset_range($default_end-86400*30,$default_end,'Last Month',$date_format,$svcnum)
+ .' | '.preset_range($default_end-86400*365,$default_end,'Last Year',$date_format,$svcnum);
+
+ $OUT .= qq! <BR>
+ Start Date <INPUT TYPE="TEXT" id="${svcnum}_start" name="${svcnum}_start" SIZE="10" MAXLENGTH="10">
+ End Date <INPUT TYPE="TEXT" id="${svcnum}_end" name="${svcnum}_end" SIZE="10" MAXLENGTH="10">
+ <BR>
+ <INPUT TYPE="submit" value="Display"> !;
+
+ $OUT .= '</FORM></TD></TR>';
+}
+%>
+
+<%= scalar(@svc_port) ? '</TABLE><BR><BR>' : '' %>
-</TABLE>
-<BR>
</TD></TR></TABLE>
-<HR>
-<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
-</BODY></HTML>
+<%= include('footer') %>
+