[freeside-commits] freeside/httemplate/search report_svc_phone.html, NONE, 1.1 svc_phone.cgi, 1.5, 1.6

Ivan,,, ivan at wavetail.420.am
Wed Aug 26 04:22:03 PDT 2009


Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory wavetail.420.am:/tmp/cvs-serv16403

Modified Files:
	svc_phone.cgi 
Added Files:
	report_svc_phone.html 
Log Message:
first pass at balance reporting, RT#5496

--- NEW FILE: report_svc_phone.html ---
<% include('/elements/header.html', 'Phone number total usage' ) %>

<FORM ACTION="svc_phone.cgi" METHOD="GET">

<INPUT TYPE="hidden" NAME="magic"       VALUE="all">
<INPUT TYPE="hidden" NAME="usage_total" VALUE="1">

<TABLE BGCOLOR="#cccccc" CELLSPACING=0>

%#  <TR>
%#    <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left">
%#     <FONT SIZE="+1">Search options</FONT>
%#    </TH>
%#  </TR>

  <% include ( '/elements/tr-input-beginning_ending.html', prefix=>'usage' ) %>

</TABLE>

<BR>
<INPUT TYPE="submit" VALUE="Search phone numbers">

</FORM>

<% include('/elements/footer.html') %>
<%init>

#? 'List services' ?  something new?
die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('List rating data');

</%init>

Index: svc_phone.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/svc_phone.cgi,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- svc_phone.cgi	1 Aug 2007 22:26:46 -0000	1.5
+++ svc_phone.cgi	26 Aug 2009 11:22:01 -0000	1.6
@@ -3,33 +3,39 @@
                  'name'              => 'phone numbers',
                  'query'             => $sql_query,
                  'count_query'       => $count_query,
-                 'redirect'          => $link,
+                 'redirect'          => $redirect,
                  'header'            => [ '#',
                                           'Service',
                                           'Country code',
                                           'Phone number',
+                                          @header,
                                           FS::UI::Web::cust_header(),
                                         ],
                  'fields'            => [ 'svcnum',
                                           'svc',
                                           'countrycode',
                                           'phonenum',
+                                          @fields,
                                           \&FS::UI::Web::cust_fields,
                                         ],
                  'links'             => [ $link,
                                           $link,
                                           $link,
                                           $link,
+                                          ( map '', @header ),
                                           ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                                                 FS::UI::Web::cust_header()
                                           ),
                                         ],
-                 'align' => 'rlrr'. FS::UI::Web::cust_aligns(),
+                 'align' => 'rlrr'.
+                            join('', map 'r', @header).
+                            FS::UI::Web::cust_aligns(),
                  'color' => [ 
                               '',
                               '',
                               '',
                               '',
+                              ( map '', @header ),
                               FS::UI::Web::cust_colors(),
                             ],
                  'style' => [ 
@@ -37,6 +43,7 @@
                               '',
                               '',
                               '',
+                              ( map '', @header ),
                               FS::UI::Web::cust_styles(),
                             ],
               )
@@ -48,9 +55,16 @@
 
 my $conf = new FS::Conf;
 
-my $orderby = 'ORDER BY svcnum';
+my @select = ();
 my %svc_phone = ();
 my @extra_sql = ();
+my $orderby = 'ORDER BY svcnum';
+
+my @header = ();
+my @fields = ();
+my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
+my $redirect = $link;
+
 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
 
   push @extra_sql, 'pkgnum IS NULL'
@@ -61,6 +75,50 @@
     $orderby = "ORDER BY $sortby";
   }
 
+  if ( $cgi->param('usage_total') ) {
+
+    my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi, 'usage');
+
+    $redirect = '';
+
+    my $and_date = " AND startdate >= $beginning ".
+                   " AND startdate <= $ending ";
+
+    my $fromwhere = " FROM cdr WHERE cdr.svcnum = svc_phone.svcnum $and_date";
+
+    #more efficient to join against cdr just once... this will do for now
+    push @select, map { " ( SELECT SUM($_) $fromwhere ) AS $_ " }
+                      qw( billsec rated_price );
+
+    my $money_char = $conf->config('money_char') || '$';
+
+    push @header, 'Minutes', 'Billed';
+    push @fields, 
+      sub { sprintf('%.3f', shift->get('billsec') / 60 ); },
+      sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
+
+    #XXX and termination... (this needs a config to turn on, not by default)
+    if ( 1 ) { # $conf->exists('cdr-termination_hack') { #}
+
+      my $f_w =
+        " FROM cdr_termination LEFT JOIN cdr USING ( acctid ) ".
+        " WHERE cdr.acctid = svc_phone.phonenum ". # XXX connectone-specific
+        $and_date;
+
+      push @select,
+        " ( SELECT SUM(billsec) $f_w ) AS term_billsec ".
+        " ( SELECT SUM(cdr_termination.rated_price) $f_w ) AS term_rated_price";
+
+      push @header, 'Term Min', 'Term Billed',
+      push @fields,
+        sub { sprintf('%.3f', shift->get('term_billsec') / 60 ); },
+        sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
+
+    }
+                 
+
+  }
+
 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
   push @extra_sql, "svcpart = $1";
 } else {
@@ -106,8 +164,6 @@
   'addl_from' => $addl_from,
 };
 
-my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
-
 #smaller false laziness w/svc_*.cgi here
 my $link_cust = sub {
   my $svc_x = shift;



More information about the freeside-commits mailing list