1 <%= $url = "$selfurl?action=";
2 %by_pkg_label = (); # not used yet, but I'm sure it will be...
6 @bytes_svcs = (); # contains svc_acct and svc_broadband
7 @bytes_cols = qw(seconds_used seconds upbytes_used upbytes downbytes_used downbytes totalbytes_used totalbytes);
8 %bytes_show = map { $_ => 0 } @bytes_cols;
10 foreach my $svc (@svcs) {
11 $by_pkg_label{ $svc->{pkg_label} } ||= [];
12 push @{ $by_pkg_label{ $svc->{pkg_label} } }, $svc;
14 if (( $svc->{svcdb} eq 'svc_acct' ) || ( $svc->{svcdb} eq 'svc_broadband' )) {
15 foreach my $field (@bytes_cols) {
16 $bytes_show{$field} = 1 if length($svc->{$field}) or (($field !~ /_used$/) && $svc->{'recharge_'.$field});
18 push @bytes_svcs, $svc;
19 } elsif ( $svc->{svcdb} eq 'svc_phone' ) {
20 push @svc_phone, $svc;
21 } elsif ( $svc->{svcdb} eq 'svc_port' ) {
23 } elsif ( $svc->{svcdb} eq 'svc_pbx' ) {
29 <%= include('header', 'Account usage') %>
32 $OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">$error</FONT><BR><BR>!;
35 <%= if ( @bytes_svcs ) {
36 $OUT .= '<TABLE BGCOLOR="#cccccc"><TR>';
37 $OUT .= '<TH ALIGN="left">Account</TH>';
38 $OUT .= '<TH ALIGN="right">Time used</TH>' if $bytes_show{'seconds_used'};
39 $OUT .= '<TH ALIGN="right">Time remaining</TH>' if $bytes_show{'seconds'};
40 $OUT .= '<TH ALIGN="right">Upload used</TH>' if $bytes_show{'upbytes_used'};
41 $OUT .= '<TH ALIGN="right">Upload remaining</TH>' if $bytes_show{'upbytes'};
42 $OUT .= '<TH ALIGN="right">Download used</TH>' if $bytes_show{'downbytes_used'};
43 $OUT .= '<TH ALIGN="right">Download remaining</TH>' if $bytes_show{'downbytes'};
44 $OUT .= '<TH ALIGN="right">Total used</TH>' if $bytes_show{'totalbytes_used'};
45 $OUT .= '<TH ALIGN="right">Total remaining</TH>' if $bytes_show{'totalbytes'};
50 <%= foreach my $svc ( @bytes_svcs ) {
51 my $link = "${url}view_usage_details;".
52 "svcnum=$svc->{'svcnum'};beginning=0;ending=0";
53 my $username = $svc->{'value'};
54 $username =~ s/@.*?$//g if $view_usage_nodomain;
56 $OUT .= '<TD>' . qq!<A HREF="$link">!. $svc->{'label'}. ': '. $username .'</A></TD>';
57 foreach my $field (@bytes_cols) {
58 $OUT .= '<TD ALIGN="right">' . $svc->{$field} . '</TD>' if $bytes_show{$field};
60 if ( $svc->{'recharge_amount'} ) {
61 my $link = "${url}process_order_recharge;".
62 "svcnum=$svc->{'svcnum'}";
63 $OUT .= '<TR><TD ALIGN="right">';
64 $OUT .= qq!<A HREF="$link">!.'Recharge for $';
65 $OUT .= $svc->{'recharge_amount'} . '</A> with';
67 foreach my $field ( qw(seconds upbytes downbytes totalbytes) ) {
68 $OUT .= '<TD></TD>' if $bytes_show{$field.'_used'};
69 if ($bytes_show{$field}) {
70 $OUT .= '<TD ALIGN="right">';
71 $OUT .= $svc->{'recharge_'.$field} if $svc->{'recharge_'.$field};
78 if ((@bytes_svcs > 1) and (grep { $bytes_show{$_.'_used'} } qw(seconds upbytes downbytes totalbytes) )) {
80 $OUT .= '<TH align="left">Total Used</TH>';
81 foreach my $field (@bytes_cols) {
82 if ($bytes_show{$field}) {
83 $OUT .= '<TD ALIGN="right">';
84 $OUT .= $bytes_used_total{$field} || '0' if $field =~ /_used$/;
92 <%= scalar(@bytes_svcs) ? '</TABLE><BR><BR>' : '' %>
94 <%= if ( @svc_phone or @svc_pbx ) {
96 for my $dir (qw(outbound inbound)) {
97 $any{$dir} = grep { $_->{$dir} } (@svc_phone, @svc_pbx);
99 $OUT.= '<FONT SIZE="4">Call usage</FONT><BR><BR>
100 <TABLE BGCOLOR="#cccccc" STYLE="display:inline-block">
102 <TH ALIGN="left">Number</TH>';
103 if ( $any{outbound} ) {
107 if ( $any{inbound} ) {
117 <%= foreach my $svc_x ( @svc_phone, @svc_pbx ) {
118 my $link = $url . 'view_cdr_details;' .
119 'svcnum='.$svc_x->{'svcnum'}.
120 ';beginning=0;ending=0';
121 $OUT .= '<TR><TD>'. $svc_x->{'label'}. ': '. $svc_x->{'value'};
123 # usage summary w/ links
124 for my $dir (qw(outbound inbound)) {
125 if ( $dir eq 'inbound' ) {
126 $link .= ';inbound=1';
128 if ( $svc_x->{$dir} ) {
129 $OUT .= '<TD ALIGN="right">'.qq!<A HREF="$link">! .
130 sprintf('%d calls (%.0f minutes)',
131 $svc_x->{$dir}->{'count'},
132 $svc_x->{$dir}->{'duration'} / 60
135 } elsif ( $any{$dir} ) {
144 <%= if ( @usage_pools ) {
146 <TABLE BGCOLOR="#cccccc" STYLE="display: inline-block">
147 <TR><TH COLSPAN=4>Remaining minutes</TH></TR>
150 foreach my $usage (@usage_pools) {
151 # false laziness with the back office side
152 my ($description, $remain, $total, $shared) = @$usage;
157 my $ratio = 255 * ($remain/$total);
158 $ratio = 255 if $color > 255;
160 sprintf('STYLE="font-weight: bold; color: #%02x%02x00"',
161 255 - $ratio, $ratio);
164 <TD ALIGN="right">$description</TD>
165 <TD $color ALIGN="right">$remain</TD>
167 <TD $color>$total</TD>
171 $OUT .= '<TR STYLE="font-size: 80%; font-style: italic">'.
172 '<TD COLSPAN=4>* shared among all your phone plans</TD></TR>';
175 if ( @svc_phone or @svc_pbx or @usage_pools ) {
176 $OUT .= '</TABLE><BR><BR>';
181 <%= if ( @svc_port ) {
182 $OUT.= '<FONT SIZE="4">Bandwidth Graphs</FONT><BR><BR>
183 <script type="text/javascript">
184 function preset_range(start,end,prefix){
185 document.getElementById(prefix+\'_start\').value = start;
186 document.getElementById(prefix+\'_end\').value = end;
189 <TABLE BGCOLOR="#cccccc">
191 <TH ALIGN="left">Service</TH>
202 my($start,$end,$label,$date_format,$prefix) = (shift,shift,shift,shift,shift);
203 $start = Date::Format::time2str($date_format,$start);
204 $end = Date::Format::time2str($date_format,$end);
205 return '<A HREF="javascript:void(0);" onclick="preset_range(\''
206 .$start.'\',\''.$end.'\',\''.$prefix.'\')">'.$label.'</A>';
209 foreach my $svc_port ( @svc_port ) {
210 $svcnum = $svc_port->{'svcnum'};
212 $default_start = $default_end-86400;
214 $OUT .= '<TR><TD>'. $svc_port->{'label'}. ': '. $svc_port->{'value'}.'</TD>';
215 $OUT .= qq! <TD><FORM ACTION="$url" METHOD="GET">
216 <INPUT TYPE="hidden" name="svcnum" value="$svcnum">
217 <INPUT TYPE="hidden" name="action" value="view_port_graph"> !;
218 $OUT .= preset_range($default_start,$default_end,'Last Day',$date_format,$svcnum)
219 .' | '.preset_range($default_end-86400*7,$default_end,'Last Week',$date_format,$svcnum)
220 .' | '.preset_range($default_end-86400*30,$default_end,'Last Month',$date_format,$svcnum)
221 .' | '.preset_range($default_end-86400*365,$default_end,'Last Year',$date_format,$svcnum);
224 Start Date <INPUT TYPE="TEXT" id="${svcnum}_start" name="${svcnum}_start" SIZE="10" MAXLENGTH="10">
225 End Date <INPUT TYPE="TEXT" id="${svcnum}_end" name="${svcnum}_end" SIZE="10" MAXLENGTH="10">
227 <INPUT TYPE="submit" value="Display"> !;
229 $OUT .= '</FORM></TD></TR>';
233 <%= scalar(@svc_port) ? '</TABLE><BR><BR>' : '' %>
237 <%= include('footer') %>