Overhaul ADSL traffic reporting/graphing

This commit is contained in:
Deon George
2013-11-14 22:50:35 +11:00
parent 158a4f9e47
commit e01d37244c
33 changed files with 891 additions and 471 deletions

View File

@@ -15,12 +15,50 @@ class Task_Adsl_Trafficcharge extends Task_Adsl_Trafficget {
);
protected function _execute(array $params) {
foreach ($this->_traffic_suppliers(TRUE) as $aso) {
if ($params['verbose'])
echo $aso->name."\n";
$date = strtotime('last month');
$c = array();
Service_Traffic_Adsl::instance($aso->name)->charge_excess_traffic();
// @todo Pick up services that are no longer active, but were inactive < 30 days ago.
foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) {
if ($params['verbose'])
echo $so->service_name()."\n";
if ($x=$so->plugin()->traffic_excess($date)) {
$po = $so->plugin()->plan();
$cost = $po->cost_extra();
$allowance = $po->allowance(array(),FALSE,TRUE,1000);
$used = $so->plugin()->traffic_month($date,FALSE,1000);
foreach ($x as $k=>$v) {
$co = ORM::factory('Charge');
// @todo This needs to be calculated.
$co->type = 5;
$co->sweep_type = 6;
$co->account_id = $so->account_id;
$co->service_id = $so->id;
$co->amount = $cost[$k];
$co->taxable = $so->product->taxable;
$co->quantity = $v;
$co->date_charge = time();
$co->description = sprintf('Excess Traffic %s',date('Y-m',$date));
$co->attributes = array(
'Allowance'=>$allowance[$k],
'Used'=>$used[$k],
'Metric'=>$so->plugin()->traffic->friendly($k),
'Month'=>date('Y-m',$date),
);
$co->save();
}
array_push($c,$so->id);
}
}
return sprintf('%s excess charges created (%s)',count($c),join('|',$c));
}
}
?>