[freeside-commits] freeside/FS/FS/part_pkg torrus_bw_percentile.pm, NONE, 1.1 torrus_bw_usage.pm, NONE, 1.1 torrus_Common.pm, NONE, 1.1
Ivan,,,
ivan at wavetail.420.am
Fri Jan 7 16:54:58 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv18773/FS/FS/part_pkg
Added Files:
torrus_bw_percentile.pm torrus_bw_usage.pm torrus_Common.pm
Log Message:
torrus, RT#10574
--- NEW FILE: torrus_bw_usage.pm ---
package FS::part_pkg::torrus_bw_usage;
use strict;
use base qw( FS::part_pkg::torrus_Common );
use List::Util qw(max);
our %info = (
'name' => 'Volume billing based on the integrated Torrus NMS',
'shortname' => 'Bandwidth (volume)',
'weight' => 54.7, #:/
'inherit_fields' => [ 'flat', 'global_Mixin' ],
'fields' => {
#'recur_temporality' => { 'hidden' => 1, 'value' => 'preceding' }, #XXX do
'recur_temporality' => { 'disabled' => 1 },
'sync_bill_date' => { 'disabled' => 1 },
'cutoff_day' => { 'disabled' => 1 },
'base_gb' => { 'name' => 'Included gigabytes',
'default' => 0,
},
'gb_rate' => { 'name' => 'Charge per gigabyte',
'default' => 0,
},
},
'fieldorder' => [ qw( base_gb gb_rate ) ],
'freq' => 'm',
);
sub _torrus_name { 'VOLUME'; }
sub _torrus_base { 'base_gb'; }
sub _torrus_rate { 'gb_rate'; }
1;
--- NEW FILE: torrus_Common.pm ---
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;
--- NEW FILE: torrus_bw_percentile.pm ---
package FS::part_pkg::torrus_bw_percentile;
use strict;
use base qw( FS::part_pkg::torrus_Common );
use List::Util qw(max);
our %info = (
'name' => '95th percentile billing based on the integrated Torrus NMS',
'shortname' => 'Bandwidth (95th percentile)',
'weight' => 54.5, #:/
'inherit_fields' => [ 'flat', 'global_Mixin' ],
'fields' => {
#'recur_temporality' => { 'hidden' => 1, 'value' => 'preceding' }, #XXX do
'recur_temporality' => { 'disabled' => 1 },
'sync_bill_date' => { 'disabled' => 1 },
'cutoff_day' => { 'disabled' => 1 },
'base_mbps' => { 'name' => 'Included megabytes/sec (95th percentile)',
'default' => 0,
},
'mbps_rate' => { 'name' => 'Charge per megabyte/sec (95th percentile)',
'default' => 0,
},
},
'fieldorder' => [ qw( base_mbps mbps_rate ) ],
'freq' => 'm',
);
sub _torrus_name { '95TH_PERCENTILE'; }
sub _torrus_base { 'base_mbps'; }
sub _torrus_rate { 'mbps_rate'; }
1;
More information about the freeside-commits
mailing list