2013-07-06 14:00:10 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Charge ADSL Traffic to Customers
|
|
|
|
*
|
|
|
|
* @package ADSL
|
|
|
|
* @category Tasks
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-11-15 05:25:45 +00:00
|
|
|
class Task_Adsl_Trafficcharge extends Minion_Task {
|
2013-10-28 23:41:14 +00:00
|
|
|
protected $_options = array(
|
|
|
|
'verbose'=>FALSE,
|
|
|
|
);
|
|
|
|
|
2013-07-06 14:00:10 +00:00
|
|
|
protected function _execute(array $params) {
|
2013-12-31 06:18:49 +00:00
|
|
|
$date = strtotime('first day of last month');
|
2013-11-14 11:50:35 +00:00
|
|
|
$c = array();
|
|
|
|
|
|
|
|
// @todo Pick up services that are no longer active, but were inactive < 30 days ago.
|
|
|
|
foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) {
|
2013-12-02 04:16:28 +00:00
|
|
|
if (Minion_CLI::options('verbose'))
|
2016-08-03 04:00:51 +00:00
|
|
|
echo $so->name()."\n";
|
2013-11-14 11:50:35 +00:00
|
|
|
|
|
|
|
if ($x=$so->plugin()->traffic_excess($date)) {
|
|
|
|
$po = $so->plugin()->plan();
|
|
|
|
$cost = $po->cost_extra();
|
2013-11-18 04:18:50 +00:00
|
|
|
$allowance = $po->allowance(array(),FALSE,TRUE,TRUE);
|
|
|
|
$used = $so->plugin()->traffic_month($date,FALSE,TRUE);
|
2013-11-14 11:50:35 +00:00
|
|
|
|
|
|
|
foreach ($x as $k=>$v) {
|
|
|
|
$co = ORM::factory('Charge');
|
|
|
|
|
|
|
|
// @todo This needs to be calculated.
|
|
|
|
$co->type = 5;
|
|
|
|
$co->sweep_type = 6;
|
2013-07-06 14:00:10 +00:00
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
$co->account_id = $so->account_id;
|
2018-06-13 11:34:58 +00:00
|
|
|
$co->active = TRUE;
|
2013-11-14 11:50:35 +00:00
|
|
|
$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);
|
|
|
|
}
|
2013-07-06 14:00:10 +00:00
|
|
|
}
|
2013-11-14 11:50:35 +00:00
|
|
|
|
|
|
|
return sprintf('%s excess charges created (%s)',count($c),join('|',$c));
|
2013-07-06 14:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|