[freeside-commits] freeside/FS/FS/part_pkg torrus_bw_percentile.pm, 1.1, 1.2 torrus_Common.pm, 1.2, 1.3

Ivan,,, ivan at wavetail.420.am
Sun Jan 23 16:10:41 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv10939

Modified Files:
	torrus_bw_percentile.pm torrus_Common.pm 
Log Message:
torrus, RT#10574

Index: torrus_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/torrus_Common.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- torrus_Common.pm	8 Jan 2011 00:56:06 -0000	1.2
+++ torrus_Common.pm	24 Jan 2011 00:10:39 -0000	1.3
@@ -3,7 +3,7 @@
 use base qw( FS::part_pkg::prorate );
 use List::Util qw(max);
 
-our %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
+our %info = ( 'disabled' => 1 ); #torrus_Common not a usable price plan directly
 
 sub calc_recur {
   my $self = shift;
@@ -28,12 +28,18 @@
   my $self = shift;
   my($cust_pkg, $sdate, $details, $param ) = @_;
 
-  my $rep_id = 2; #XXX find the one matching the timeframe
-  #SELECT id FROM WHERE reportname = 'MonthlyUsage' AND rep_date = ''
+  my @sdate = localtime($$sdate);
+  my $rep_date = ($sdate[5]+1900). '-'. ($sdate[4]+1). '-01';
+  my $rep_sql = "
+    SELECT id FROM reports WHERE rep_date = ?
+                             AND reportname = 'MonthlyUsage' and iscomplete = 1
+  ";
+  my $rep_id = $self->scalar_sql($rep_sql, $rep_date) or return 0;
 
-  #XXX abort if ! iscomplete?
+  #abort if ! iscomplete instead?
 
-  my $serviceid = 'TESTING_1'; #XXX from svc_port (loop?)
+  my $conf = new FS::Conf;
+  my $money_char = $conf->config('money_char') || '$';
 
   my $sql = "
     SELECT value FROM reportfields
@@ -42,19 +48,37 @@
         AND servciceid = ?
   ";
   
+  my $total = 0;
+  foreach my $svc_port (
+    grep $_->table('svc_port'), map $_->svc_x, $cust_pkg->cust_svc
+  ) {
+
+    my $serviceid = $svc_port->serviceid;
+
   my $in  = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_IN');
   my $out = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_OUT');
 
   my $max = max($in,$out);
 
-  $max -= $self->option($self->_torrus_base);
-  return 0 if $max < 0;
+    my $inc = $self->option($self->_torrus_base);#aggregate instead of per-port?
+    $max -= $inc;
+    next if $max < 0;
 
-  #XXX add usage details
+    my $amount = sprintf('%.2f', $self->option($self->_torrus_rate) * $max );
+    $total += $amount;
 
-  return sprintf('%.2f', $self->option($self->_torrus_rate) * $max );
+    #add usage details to invoice
+    my $l = $self->_torrus_label;
+    my $d = "Last month's usage for $serviceid: $max$l";
+    $d .= " (". ($max+$inc). "$l - $inc$l included)" if $inc;
+    $d .= ": $money_char$amount";
+
+    push @$details, $d;
 
 }
 
+  return sprintf('%.2f', $total );
+
+}
 
 1;

Index: torrus_bw_percentile.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/torrus_bw_percentile.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- torrus_bw_percentile.pm	8 Jan 2011 00:54:56 -0000	1.1
+++ torrus_bw_percentile.pm	24 Jan 2011 00:10:39 -0000	1.2
@@ -28,5 +28,6 @@
 sub _torrus_name { '95TH_PERCENTILE'; }
 sub _torrus_base { 'base_mbps'; }
 sub _torrus_rate { 'mbps_rate'; }
+sub _torrus_label { 'mbps'; };
 
 1;



More information about the freeside-commits mailing list