Improvements to traffic collection, zero record ignore, some fixes to order_by
This commit is contained in:
parent
335e8e65bd
commit
c347032497
@ -37,7 +37,7 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
|||||||
->type('success')
|
->type('success')
|
||||||
->body(_('Method record has been added.'));
|
->body(_('Method record has been added.'));
|
||||||
|
|
||||||
HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
|
HTTP::redirect(URL::link('admin','module/edit/'.$mo->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::factory()
|
Block::factory()
|
||||||
@ -98,6 +98,8 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
|||||||
->body(sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name));
|
->body(sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTTP::redirect(URL::link('admin','module/edit/'.$mmo->module_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::factory()
|
Block::factory()
|
||||||
|
@ -21,6 +21,15 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
|||||||
'plan'=>array('model'=>'Service_Plugin_Adsl','foreign_key'=>'service_username','far_key'=>'service'),
|
'plan'=>array('model'=>'Service_Plugin_Adsl','foreign_key'=>'service_username','far_key'=>'service'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private $metrics = array(
|
||||||
|
'up_peak',
|
||||||
|
'up_offpeak',
|
||||||
|
'down_peak',
|
||||||
|
'down_offpeak',
|
||||||
|
'peer',
|
||||||
|
'internal',
|
||||||
|
);
|
||||||
|
|
||||||
public function rules() {
|
public function rules() {
|
||||||
$result = parent::rules();
|
$result = parent::rules();
|
||||||
|
|
||||||
@ -30,6 +39,37 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save(Validation $validation = NULL) {
|
||||||
|
// If all our values are zero/NULL, we'll ignore if our previous one was.
|
||||||
|
if ($this->total() !== 0)
|
||||||
|
return parent::save($validation);
|
||||||
|
|
||||||
|
$l = ORM::factory($this->_object_name)->where('service','=',$this->service)->where('supplier_id','=',$this->supplier_id)->list_last();
|
||||||
|
|
||||||
|
if ($l->total() !== 0)
|
||||||
|
return parent::save($validation);
|
||||||
|
|
||||||
|
// Fake our save, since the previous value is 0.
|
||||||
|
$this->_loaded = $this->_saved = TRUE;
|
||||||
|
$this->_changed = array();
|
||||||
|
$this->_original_values = $this->_object;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function total() {
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
foreach ($this->metrics as $metric) {
|
||||||
|
if (is_null($this->$metric))
|
||||||
|
$this->$metric = 0;
|
||||||
|
|
||||||
|
$result += $this->$metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function traffic(Model_Product_Plugin_Adsl $plan) {
|
public function traffic(Model_Product_Plugin_Adsl $plan) {
|
||||||
// Roll up the charges according to the product plan configuration
|
// Roll up the charges according to the product plan configuration
|
||||||
return ADSL::allowance(array(
|
return ADSL::allowance(array(
|
||||||
@ -43,5 +83,9 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
|||||||
'extra_up_offpeak'=>$plan->extra_up_offpeak,
|
'extra_up_offpeak'=>$plan->extra_up_offpeak,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function list_last() {
|
||||||
|
return $this->order_by('date','DESC')->order_by('time','DESC')->find();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
44
modules/adsl/classes/Task/Adsl/Traffictrim.php
Normal file
44
modules/adsl/classes/Task/Adsl/Traffictrim.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trim ADSL Traffic Records, truncating any zeros
|
||||||
|
*
|
||||||
|
* @package ADSL
|
||||||
|
* @category Tasks
|
||||||
|
* @author Deon George
|
||||||
|
* @copyright (c) 2009-2013 Open Source Billing
|
||||||
|
* @license http://dev.osbill.net/license.html
|
||||||
|
*/
|
||||||
|
class Task_Adsl_Traffictrim extends Task_Adsl_Trafficget {
|
||||||
|
protected function _execute(array $params) {
|
||||||
|
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
||||||
|
->select('service,supplier_id')
|
||||||
|
->group_by('service,supplier_id');
|
||||||
|
|
||||||
|
foreach ($t->find_all() as $group) {
|
||||||
|
|
||||||
|
$zerorow = FALSE;
|
||||||
|
foreach (ORM::factory('Service_Plugin_Adsl_Traffic')->where('service','=',$group->service)->where('supplier_id','=',$group->supplier_id)->order_by('date')->order_by('time')->find_all() as $spato)
|
||||||
|
if ($spato->total() === 0) {
|
||||||
|
if ($zerorow) {
|
||||||
|
// Cant use delete(), as our primary key is not used in this table.
|
||||||
|
$db = DB::query(Database::DELETE,DB::delete($spato->table_name())
|
||||||
|
->where('service','=',$group->service)
|
||||||
|
->where('supplier_id','=',$group->supplier_id)
|
||||||
|
->where('date','=',$spato->date)
|
||||||
|
->where('time','=',$spato->time));
|
||||||
|
|
||||||
|
$db->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
$zerorow = TRUE;
|
||||||
|
|
||||||
|
} else
|
||||||
|
$zerorow = FALSE;
|
||||||
|
|
||||||
|
// An attempt to free some memory.
|
||||||
|
$spato = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -148,7 +148,7 @@ $(document).ready(function() {
|
|||||||
->title_icon('icon-th-list')
|
->title_icon('icon-th-list')
|
||||||
->body(Table::factory()
|
->body(Table::factory()
|
||||||
->page_items(50)
|
->page_items(50)
|
||||||
->data(ORM::factory('Charge')->where_authorised($this->ao)->where('void','is',NULL)->order_by('id DESC')->find_all())
|
->data(ORM::factory('Charge')->where_authorised($this->ao)->where('void','is',NULL)->order_by('id','DESC')->find_all())
|
||||||
->columns(array(
|
->columns(array(
|
||||||
'id'=>'ID',
|
'id'=>'ID',
|
||||||
'date_charge'=>'Date',
|
'date_charge'=>'Date',
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
class Task_Invoice_Listoverdue extends Minion_Task {
|
class Task_Invoice_Listoverdue extends Minion_Task {
|
||||||
protected function _execute(array $params) {
|
protected function _execute(array $params) {
|
||||||
$overdue = ORM::factory('Invoice')->list_overdue();
|
$overdue = ORM::factory('Invoice')->list_overdue(NULL,FALSE);
|
||||||
|
|
||||||
$rtms = $invoices = array();
|
$rtms = $invoices = array();
|
||||||
foreach ($overdue as $io)
|
foreach ($overdue as $io)
|
||||||
|
@ -156,7 +156,7 @@ $(document).ready(function() {
|
|||||||
* Show a list of products
|
* Show a list of products
|
||||||
*/
|
*/
|
||||||
public function action_list() {
|
public function action_list() {
|
||||||
$products = ($x=$this->request->param('id')) ? ORM::factory('Product_Category',$x)->products() : ORM::factory('Product')->order_by('status DESC,prod_plugin_file')->find_all();
|
$products = ($x=$this->request->param('id')) ? ORM::factory('Product_Category',$x)->products() : ORM::factory('Product')->order_by('status','DESC')->order_by('prod_plugin_file')->find_all();
|
||||||
|
|
||||||
Block::factory()
|
Block::factory()
|
||||||
->title(_('Products'))
|
->title(_('Products'))
|
||||||
|
Reference in New Issue
Block a user