1 package FS::part_pkg::torrus_Common;
3 use base qw( FS::part_pkg::prorate );
4 use List::Util qw(max);
6 our %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
10 my($cust_pkg, $sdate, $details, $param ) = @_;
14 $charges += $self->calc_usage(@_);
15 $charges += $self->calc_prorate(@_, 1);
16 #$charges -= $self->calc_discount(@_);
22 #sub calc_cancel { #somehow trigger an early report?
24 #have to look at getting the discounts to apply to the usage charges
25 sub can_discount { 0; }
29 my($cust_pkg, $sdate, $details, $param ) = @_;
31 my $rep_id = 2; #XXX find the one matching the timeframe
32 #SELECT id FROM WHERE reportname = 'MonthlyUsage' AND rep_date = ''
34 #XXX abort if ! iscomplete?
36 my $serviceid = 'TESTING_1'; #XXX from svc_port (loop?)
39 SELECT value FROM reportfields
40 WHERE rep_id = $rep_id
45 my $in = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_IN');
46 my $out = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_OUT');
48 my $max = max($in,$out);
50 $max -= $self->option($self->_torrus_base);
53 #XXX add usage details
55 return sprintf('%.2f', $self->option($self->_torrus_rate) * $max );