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 ); #torrus_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 @sdate = localtime($$sdate);
32 my $rep_date = ($sdate[5]+1900). '-'. ($sdate[4]+1). '-01';
34 SELECT id FROM reports WHERE rep_date = ?
35 AND reportname = 'MonthlyUsage' and iscomplete = 1
37 my $rep_id = $self->scalar_sql($rep_sql, $rep_date) or return 0;
39 #abort if ! iscomplete instead?
41 my $conf = new FS::Conf;
42 my $money_char = $conf->config('money_char') || '$';
45 SELECT value FROM reportfields
46 WHERE rep_id = $rep_id
52 foreach my $svc_port (
53 grep $_->table('svc_port'), map $_->svc_x, $cust_pkg->cust_svc
56 my $serviceid = $svc_port->serviceid;
58 my $in = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_IN');
59 my $out = $self->scalar_sql($sql, $self->_torrus_name, $serviceid.'_OUT');
61 my $max = max($in,$out);
63 my $inc = $self->option($self->_torrus_base);#aggregate instead of per-port?
67 my $amount = sprintf('%.2f', $self->option($self->_torrus_rate) * $max );
70 #add usage details to invoice
71 my $l = $self->_torrus_label;
72 my $d = "Last month's usage for $serviceid: $max$l";
73 $d .= " (". ($max+$inc). "$l - $inc$l included)" if $inc;
74 $d .= ": $money_char$amount";
80 return sprintf('%.2f', $total );