summaryrefslogtreecommitdiff
path: root/FS/FS/part_pkg
diff options
context:
space:
mode:
authorivan <ivan>2011-01-08 00:54:56 +0000
committerivan <ivan>2011-01-08 00:54:56 +0000
commit8fad52859c516d8657653007f0fa602f7c857651 (patch)
tree722eb43618f6b8e21f9be49e7f638912fa0dabbb /FS/FS/part_pkg
parent262e07f22cd3f79e191456503cf6da2d34d00626 (diff)
torrus, RT#10574
Diffstat (limited to 'FS/FS/part_pkg')
-rw-r--r--FS/FS/part_pkg/torrus_Common.pm60
1 files changed, 60 insertions, 0 deletions
diff --git a/FS/FS/part_pkg/torrus_Common.pm b/FS/FS/part_pkg/torrus_Common.pm
new file mode 100644
index 000000000..229a0c32b
--- /dev/null
+++ b/FS/FS/part_pkg/torrus_Common.pm
@@ -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;