torrus, RT#10574
authorivan <ivan>
Sat, 8 Jan 2011 00:54:56 +0000 (00:54 +0000)
committerivan <ivan>
Sat, 8 Jan 2011 00:54:56 +0000 (00:54 +0000)
FS/FS/Schema.pm
FS/FS/h_svc_port.pm [new file with mode: 0644]
FS/FS/part_pkg/torrus_Common.pm [new file with mode: 0644]

index 26252a7..fe23e16 100644 (file)
@@ -3207,36 +3207,10 @@ sub tables_hashref {
       'index'  => [], #recnum
     },
 
-    'nms_device' => {
-      'columns' => [
-        'nms_devicenum', 'serial',     '',      '', '', '',
-        #'agentnum',         'int', 'NULL',      '', '', '',
-        'devicename',   'varchar',     '', $char_d, '', '',
-        'ip',           'varchar',     '',      15, '', '', 
-        'protocol',     'varchar',     '', $char_d, '', '',
-#        'last',     'int',     '',    '', '', '', 
-      ],
-      'primary_key' => 'nms_devicenum',
-      'unique' => [],
-      'index'  => [],
-    },
-   
-    'nms_deviceport' => {
-      'columns' => [
-        'portnum',       'serial',     '', '', '', '', 
-        'nms_devicenum',    'int',     '', '', '', '', 
-        'deviceport',       'int',     '', '', '', '', 
-        #'ip',       'varchar', 'NULL', 15, '', '', 
-        'svcnum',           'int', 'NULL', '', '', '',
-      ],
-      'primary_key' => 'portnum',
-      'unique'      => [ [ 'nms_devicenum', 'deviceport' ] ],
-      'index'       => [ [ 'svcnum' ] ],
-    },
-
     'svc_port' => {
       'columns' => [
         'svcnum',                'int',     '',      '', '', '', 
+        'serviceid', 'varchar', '', 64, '', '', #srvexport / reportfields
       ],
       'primary_key' => 'svcnum',
       'unique' => [],
diff --git a/FS/FS/h_svc_port.pm b/FS/FS/h_svc_port.pm
new file mode 100644 (file)
index 0000000..05d8475
--- /dev/null
@@ -0,0 +1,33 @@
+package FS::h_svc_port;
+
+use strict;
+use vars qw( @ISA );
+use FS::h_Common;
+use FS::svc_port;
+
+@ISA = qw( FS::h_Common FS::svc_port );
+
+sub table { 'h_svc_port' };
+
+=head1 NAME
+
+FS::h_svc_port - Historical port objects
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+An FS::h_svc_port object represents a historical customer port.  FS::h_svc_port
+inherits from FS::h_Common and FS::svc_port.
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::h_Common>, L<FS::svc_port>, L<FS::Record>, schema.html from the base
+documentation.
+
+=cut
+
+1;
+
diff --git a/FS/FS/part_pkg/torrus_Common.pm b/FS/FS/part_pkg/torrus_Common.pm
new file mode 100644 (file)
index 0000000..229a0c3
--- /dev/null
@@ -0,0 +1,60 @@
+package FS::part_pkg::torrus_Common;
+
+use base qw( FS::part_pkg::prorate );
+use List::Util qw(max);
+
+our %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
+
+sub calc_recur {
+  my $self = shift;
+  my($cust_pkg, $sdate, $details, $param ) = @_;
+
+  my $charges = 0;
+
+  $charges += $self->calc_usage(@_);
+  $charges += $self->calc_prorate(@_, 1);
+  #$charges -= $self->calc_discount(@_);
+
+  $charges;
+
+}
+
+#sub calc_cancel {  #somehow trigger an early report?
+
+#have to look at getting the discounts to apply to the usage charges
+sub can_discount { 0; }
+
+sub calc_usage {
+  my $self = shift;
+  my($cust_pkg, $sdate, $details, $param ) = @_;
+
+  my $serviceid = 'TESTING_1'; #XXX from svc_port (loop?)
+
+  my $rep_id = 2; #XXX find the one matching the timeframe
+  #SELECT id FROM WHERE reportname = 'MonthlyUsage' AND rep_date = ''
+
+  #XXX abort if ! iscomplete?
+
+  my $sql = "
+    SELECT value FROM reportfields
+      WHERE rep_id = $rep_id
+        AND name = ?
+        AND servciceid = ?
+  ";
+  
+  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;
+
+  #XXX add usage details
+
+  return sprintf('%.2f', $self->option($self->_torrus_rate) * $max );
+
+}
+
+
+1;