From 6f855fb32d3a5878ac70623cf0a9ccf4c265a64e Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 11 Oct 2013 00:08:02 +1100 Subject: [PATCH] Work on Service Reports --- .../classes/Controller/Reseller/Welcome.php | 2 +- application/config/debug.php | 2 +- .../classes/Controller/Admin/Service/Adsl.php | 60 ++++++ modules/adsl/views/service/admin/adslstat.php | 35 +++ .../service/admin/adslstat/body_data.php | 1 - .../views/service/admin/adslstat/body_end.php | 1 - .../service/admin/adslstat/body_head.php | 4 - .../views/service/admin/adslstat/foot.php | 1 - .../views/service/admin/adslstat/head.php | 3 - .../service/admin/adslstat/head_data.php | 1 - .../views/service/admin/adslstat/head_end.php | 1 - .../Controller/Reseller/Service/Domain.php | 2 +- .../Controller/Reseller/Service/Host.php | 2 +- modules/payment/classes/Model/Payment.php | 2 +- .../classes/Controller/Admin/Service.php | 204 ------------------ .../classes/Controller/Reseller/Service.php | 57 ++++- .../Controller/Reseller/Service/Ssl.php | 41 ++++ .../ssl/classes/Model/Service/Plugin/Ssl.php | 4 +- 18 files changed, 198 insertions(+), 225 deletions(-) create mode 100644 modules/adsl/classes/Controller/Admin/Service/Adsl.php create mode 100644 modules/adsl/views/service/admin/adslstat.php delete mode 100644 modules/adsl/views/service/admin/adslstat/body_data.php delete mode 100644 modules/adsl/views/service/admin/adslstat/body_end.php delete mode 100644 modules/adsl/views/service/admin/adslstat/body_head.php delete mode 100644 modules/adsl/views/service/admin/adslstat/foot.php delete mode 100644 modules/adsl/views/service/admin/adslstat/head.php delete mode 100644 modules/adsl/views/service/admin/adslstat/head_data.php delete mode 100644 modules/adsl/views/service/admin/adslstat/head_end.php create mode 100644 modules/ssl/classes/Controller/Reseller/Service/Ssl.php diff --git a/application/classes/Controller/Reseller/Welcome.php b/application/classes/Controller/Reseller/Welcome.php index 1dbc7b4e..4c29229e 100644 --- a/application/classes/Controller/Reseller/Welcome.php +++ b/application/classes/Controller/Reseller/Welcome.php @@ -93,7 +93,7 @@ class Controller_Reseller_Welcome extends Controller_Welcome { 'date_payment'=>'Pay Date', 'account->accnum()'=>'Num', 'account->name()'=>'Account', - 'account->display("status")'=>'Active', + 'account->status(TRUE)'=>'Active', 'total(TRUE)'=>'Total', 'balance(TRUE)'=>'Balance', )) diff --git a/application/config/debug.php b/application/config/debug.php index b881d6e1..f3e3a1e9 100644 --- a/application/config/debug.php +++ b/application/config/debug.php @@ -25,7 +25,7 @@ return array ), 'invoice'=>0, // Number of invoices to generate in a pass 'site'=>FALSE, // Glogal site debug - 'show_errors'=>TRUE, // Show errors instead of logging in the DB. + 'show_errors'=>FALSE, // Show errors instead of logging in the DB. 'show_inactive'=>FALSE, // Show Inactive Items 'task_sim'=>FALSE, // Simulate running tasks ); diff --git a/modules/adsl/classes/Controller/Admin/Service/Adsl.php b/modules/adsl/classes/Controller/Admin/Service/Adsl.php new file mode 100644 index 00000000..e9fbd9f1 --- /dev/null +++ b/modules/adsl/classes/Controller/Admin/Service/Adsl.php @@ -0,0 +1,60 @@ +TRUE, + ); + + public function action_stat() { + // @todo This needs to be configurable. + $traffic = array(1000,2000,5000,10000,25000,50000,75000,100000); + + $svs = ORM::factory('Service')->list_bylistgroup('ADSL'); + $stats = array(); + $output = ''; + $ts = 0; + + foreach ($svs as $a=>$so) { + // Number of services + if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'])) + $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'] = 0; + + $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']++; + $ts++; + + // Amount of traffic + $t = array_sum($so->plugin()->traffic_lastmonth(FALSE)); + $a = 0; + foreach (array_reverse($traffic) as $i) { + if ($i < $t) + break; + $a = $i; + } + + if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a])) + $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a] = 0; + + $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]++; + } + + Block::factory() + ->title('ADSL Traffic Summary Stats - Last Month') + ->title_icon('icon-list') + ->body( + View::factory('service/admin/adslstat') + ->set('stats',$stats) + ->set('traffic',$traffic) + ->set('ts',$ts) + ); + } +} +?> diff --git a/modules/adsl/views/service/admin/adslstat.php b/modules/adsl/views/service/admin/adslstat.php new file mode 100644 index 00000000..47e0d869 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat.php @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + $details) : ?> + + + + + + + + + + + + + + + + + +
Speed#%%Other%
diff --git a/modules/adsl/views/service/admin/adslstat/body_data.php b/modules/adsl/views/service/admin/adslstat/body_data.php deleted file mode 100644 index 41a521c9..00000000 --- a/modules/adsl/views/service/admin/adslstat/body_data.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/adsl/views/service/admin/adslstat/body_end.php b/modules/adsl/views/service/admin/adslstat/body_end.php deleted file mode 100644 index 23019526..00000000 --- a/modules/adsl/views/service/admin/adslstat/body_end.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/adsl/views/service/admin/adslstat/body_head.php b/modules/adsl/views/service/admin/adslstat/body_head.php deleted file mode 100644 index a36ffa79..00000000 --- a/modules/adsl/views/service/admin/adslstat/body_head.php +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/modules/adsl/views/service/admin/adslstat/foot.php b/modules/adsl/views/service/admin/adslstat/foot.php deleted file mode 100644 index 000ca4b0..00000000 --- a/modules/adsl/views/service/admin/adslstat/foot.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/adsl/views/service/admin/adslstat/head.php b/modules/adsl/views/service/admin/adslstat/head.php deleted file mode 100644 index baa32e3b..00000000 --- a/modules/adsl/views/service/admin/adslstat/head.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/modules/adsl/views/service/admin/adslstat/head_data.php b/modules/adsl/views/service/admin/adslstat/head_data.php deleted file mode 100644 index 96181072..00000000 --- a/modules/adsl/views/service/admin/adslstat/head_data.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/adsl/views/service/admin/adslstat/head_end.php b/modules/adsl/views/service/admin/adslstat/head_end.php deleted file mode 100644 index 23019526..00000000 --- a/modules/adsl/views/service/admin/adslstat/head_end.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/domain/classes/Controller/Reseller/Service/Domain.php b/modules/domain/classes/Controller/Reseller/Service/Domain.php index d57b0b36..0b267bf8 100644 --- a/modules/domain/classes/Controller/Reseller/Service/Domain.php +++ b/modules/domain/classes/Controller/Reseller/Service/Domain.php @@ -24,7 +24,7 @@ class Controller_Reseller_Service_Domain extends Controller_Service { ->columns(array( 'id'=>'ID', 'name()'=>'Service', - 'plugin()->display("domain_expire")'=>'Expire', + 'plugin()->display("domain_expire")'=>'Expire', 'recur_schedule'=>'Billing', 'price(TRUE,TRUE)'=>'Price', 'account->accnum()'=>'Cust ID', diff --git a/modules/host/classes/Controller/Reseller/Service/Host.php b/modules/host/classes/Controller/Reseller/Service/Host.php index 1f968bbf..55365e92 100644 --- a/modules/host/classes/Controller/Reseller/Service/Host.php +++ b/modules/host/classes/Controller/Reseller/Service/Host.php @@ -24,7 +24,7 @@ class Controller_Reseller_Service_Host extends Controller_Service { ->columns(array( 'id'=>'ID', 'name()'=>'Service', - 'plugin()->display("host_expire")'=>'Expire', + 'plugin()->display("host_expire")'=>'Expire', 'recur_schedule'=>'Billing', 'price(TRUE,TRUE)'=>'Price', 'account->accnum()'=>'Cust ID', diff --git a/modules/payment/classes/Model/Payment.php b/modules/payment/classes/Model/Payment.php index f809af4b..ca601698 100644 --- a/modules/payment/classes/Model/Payment.php +++ b/modules/payment/classes/Model/Payment.php @@ -222,7 +222,7 @@ class Model_Payment extends ORM_OSB { $sql = 'SELECT A.id as id, A.total_amt, ROUND(SUM(IF(IFNULL(B.alloc_amt,0)<0,IFNULL(B.alloc_amt,0)*-1,IFNULL(B.alloc_amt,0))),2) as ALLOC'; $sql .= ' FROM :prefix_payment A '; - $sql .= ' RIGHT JOIN :prefix_payment_item B ON (A.site_id=B.site_id AND A.id=B.payment_id)'; + $sql .= ' LEFT JOIN :prefix_payment_item B ON (A.site_id=B.site_id AND A.id=B.payment_id)'; $sql .= ' WHERE A.site_id=:site_id'; $sql .= ' GROUP BY A.id'; $sql .= ' HAVING round(A.total_amt-ALLOC,2) <> 0'; diff --git a/modules/service/classes/Controller/Admin/Service.php b/modules/service/classes/Controller/Admin/Service.php index ff48473d..0f4a13a5 100644 --- a/modules/service/classes/Controller/Admin/Service.php +++ b/modules/service/classes/Controller/Admin/Service.php @@ -11,93 +11,13 @@ */ class Controller_Admin_Service extends Controller_Service { protected $secure_actions = array( - 'ajaxjson_traffic'=>TRUE, - 'adslstat'=>TRUE, - 'listexpiring'=>TRUE, 'listdomainservicesbysupplier'=>TRUE, 'listdomainservicesbydnshost'=>TRUE, 'listhostservicesbysupplier'=>TRUE, - 'listwebservices'=>TRUE, - 'listinvoicesoon'=>TRUE, 'update'=>TRUE, 'view'=>TRUE, ); - public function action_ajaxjson_traffic() { - $result = array(); - $svs = ORM::factory('Service')->list_bylistgroup('ADSL'); - $data = $this->consoltraffic($svs,time()); - - $google = GoogleChart::factory('ComboChart') - ->stacked(TRUE); - - foreach ($data['data'] as $key => $values) - $google->sdata(array('yl'=>$key),array($key=>$values)); - - $google->sdata(array('yr'=>'services'),array('services'=>$data['svs'])); - - $this->response->headers('Content-Type','application/json'); - $this->response->body($google->json()); - } - - private function consoltraffic($svs,$date) { - $data = array(); - - foreach ($svs as $so) { - $c = array(); - foreach ($so->plugin()->get_traffic_data_monthly($date) as $metric => $ma) { - foreach ($ma as $month => $traffic) { - // Only count the service once, not for each metric. - if (! isset($c[$month])) { - if (isset($data['svs'][$month])) - $data['svs'][$month] += 1; - else - $data['svs'][$month] = 1; - - $c[$month] = 1; - } - - if (isset($data['data'][$metric][$month])) - $data['data'][$metric][$month] += (int)$traffic; - else - $data['data'][$metric][$month] = (int)$traffic; - } - } - } - - ksort($data['svs']); - foreach ($data['data'] as $metric => $details) - ksort($data['data'][$metric]); - - return $data; - } - - /** - * Show a list of services that are expiring or have expired - */ - public function action_listexpiring() { - $svs = ORM::factory('Service')->list_expiring(); - - Sort::MAsort($svs,'expire()'); - - Block::add(array( - 'title'=>_('ADSL Services'), - 'body'=>Table::display( - $svs, - 50, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')), - 'service_name()'=>array('label'=>'Service'), - 'expire(TRUE)'=>array('label'=>'Expires'), - 'due(TRUE)'=>array('label'=>'Due'), - ), - array( - 'type'=>'select', - 'form'=>URL::link('user','service/view'), - )), - )); - } - public function action_listdomainservicesbysupplier() { $svs = ORM::factory('Service')->list_bylistgroup('DOMAIN'); Sort::MAsort($svs,'plugin()->domain_registrar_id,name()'); @@ -194,60 +114,6 @@ class Controller_Admin_Service extends Controller_Service { )); } - public function action_listwebservices() { - $svs = ORM::factory('Service')->list_bylistgroup('WEB'); - Sort::MAsort($svs,'name()'); - - Block::add(array( - 'title'=>_('SSL Services'), - 'body'=>Table::display( - $svs, - 25, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')), - 'service_name()'=>array('label'=>'Details'), - 'recur_schedule'=>array('label'=>'Billing'), - 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), - 'account->accnum()'=>array('label'=>'Cust ID'), - 'account->name()'=>array('label'=>'Customer'), - 'display("date_next_invoice")'=>array('label'=>'Next Invoice'), - ), - array( - 'page'=>TRUE, - 'type'=>'select', - 'form'=>URL::link('user','service/view'), - )), - )); - } - - /** - * List services that need to be invoiced. - */ - public function action_listinvoicesoon() { - Block::add(array( - 'title'=>_('Services to Invoice'), - 'body'=>Table::display( - ORM::factory('Service')->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')), - 25, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('user','service/view/')), - 'service_name()'=>array('label'=>'Details'), - 'recur_schedule'=>array('label'=>'Billing'), - 'date_next_invoice'=>array('label'=>'Next Invoice'), - 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), - 'charges()'=>array('label'=>'Charges','class'=>'right'), - 'status'=>array('label'=>'Active'), - 'account->accnum()'=>array('label'=>'Cust ID'), - 'account->name()'=>array('label'=>'Customer'), - ), - array( - 'page'=>TRUE, - 'type'=>'select', - 'form'=>URL::link('user','service/view'), - )), - )); - } - public function action_update() { $id = $this->request->param('id'); $so = ORM::factory('Service',$id); @@ -382,75 +248,5 @@ class Controller_Admin_Service extends Controller_Service { 'body'=>$output, )); } - - public function action_adslstat() { - $output = ''; - $svs = ORM::factory('Service')->list_bylistgroup('ADSL'); - $stats = array(); - // @todo This needs to be configurable. - $traffic = array(1000,2000,5000,10000,25000,50000,75000,100000); - $ts = 0; - - foreach ($svs as $a=>$so) { - // Number of services - if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'])) - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'] = 0; - - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']++; - $ts++; - - // Amount of traffic - $t = array_sum($so->plugin()->traffic_lastmonth(FALSE)); - $a = 0; - foreach (array_reverse($traffic) as $i) { - if ($i < $t) - break; - $a = $i; - } - - if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a])) - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a] = 0; - - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]++; - } - - if (count($stats)) { - $output .= View::factory($this->viewpath().'/head') - ->set('name','SPEED'); - $output .= View::factory($this->viewpath().'/head_data') - ->set('name','#'); - foreach ($traffic as $i) - $output .= View::factory($this->viewpath().'/head_data') - ->set('name',$i); - $output .= View::factory($this->viewpath().'/head_data') - ->set('name','Other'); - $output .= View::factory($this->viewpath().'/head_end'); - - foreach ($stats as $speed => $details) { - $output .= View::factory($this->viewpath().'/body_head') - ->set('count',$details['c']) - ->set('percent',sprintf('%2.1f',$details['c']/$ts*100)) - ->set('speed',$speed); - - foreach ($traffic as $i) { - $output .= View::factory($this->viewpath().'/body_data') - ->set('count',$c=isset($details['d'][$i]) ? $details['d'][$i] : 0) - ->set('percent',sprintf('%2.1f',$c/$details['c']*100)); - } - - $output .= View::factory($this->viewpath().'/body_data') - ->set('count',$c=isset($details['d'][0]) ? $details['d'][0] : 0) - ->set('percent',sprintf('%2.1f',$c/$details['c']*100)); - $output .= View::factory($this->viewpath().'/body_end'); - } - - $output .= View::factory($this->viewpath().'/foot'); - } - - Block::add(array( - 'title'=>_('ADSL Traffic Summary Stats - Last Month'), - 'body'=>$output, - )); - } } ?> diff --git a/modules/service/classes/Controller/Reseller/Service.php b/modules/service/classes/Controller/Reseller/Service.php index 125f0789..2f885481 100644 --- a/modules/service/classes/Controller/Reseller/Service.php +++ b/modules/service/classes/Controller/Reseller/Service.php @@ -13,7 +13,8 @@ class Controller_Reseller_Service extends Controller_Service { protected $secure_actions = array( 'list'=>TRUE, 'listbycheckout'=>TRUE, - 'listhostservices'=>TRUE, + 'listexpiring'=>TRUE, + 'listinvoicesoon'=>TRUE, ); /** @@ -49,7 +50,7 @@ class Controller_Reseller_Service extends Controller_Service { // @todo This needs to be configurable $go = ORM::factory('Group',array('name'=>'Personal')); - foreach (ORM::factory('Account')->where_active()->where_authoised($this->ao,'id')->find_all() as $ao) + foreach (ORM::factory('Account')->where_active()->where_authorised($this->ao,'id')->find_all() as $ao) if ($ao->has_any('group',array($go))) foreach ($ao->service->list_active() as $so) if (! $so->service_billing->checkout_id) @@ -108,5 +109,57 @@ class Controller_Reseller_Service extends Controller_Service { ); } } + + /** + * Show a list of expring services + */ + public function action_listexpiring() { + Block::factory() + ->title('Customer Services Expiring') + ->title_icon('icon-th-list') + ->body(Table::factory() + ->jssort('services') + ->data(ORM::factory('Service')->where_authorised($this->ao)->list_expiring()) + ->columns(array( + 'id'=>'ID', + 'expire(TRUE)'=>'Expiry', + 'service_name()'=>'Service', + 'recur_schedule'=>'Billing', + 'price(TRUE,TRUE)'=>'Price', + 'account->accnum()'=>'Cust ID', + 'account->name()'=>'Customer', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )) + ); + } + + /** + * Show a list of expring services + */ + public function action_listinvoicesoon() { + Block::factory() + ->title('Customer Services soon to be Invoiced') + ->title_icon('icon-th-list') + ->body(Table::factory() + ->jssort('services') + ->data(ORM::factory('Service')->where_authorised($this->ao)->list_invoicesoon(ORM::factory('Invoice')->config('GEN_SOON_DAYS')+30)) + ->columns(array( + 'id'=>'ID', + 'expire(TRUE)'=>'Expiry', + 'service_name()'=>'Service', + 'recur_schedule'=>'Billing', + 'price(TRUE,TRUE)'=>'Price', + 'charges(TRUE,TRUE)'=>'Charges', + 'account->accnum()'=>'Cust ID', + 'account->name()'=>'Customer', + 'date_next_invoice'=>'Next Invoice', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )) + ); + } } ?> diff --git a/modules/ssl/classes/Controller/Reseller/Service/Ssl.php b/modules/ssl/classes/Controller/Reseller/Service/Ssl.php new file mode 100644 index 00000000..64da60a7 --- /dev/null +++ b/modules/ssl/classes/Controller/Reseller/Service/Ssl.php @@ -0,0 +1,41 @@ +TRUE, + ); + + public function action_list() { + Block::factory() + ->title('SSL Services') + ->title_icon('icon-th-list') + ->body(Table::factory() + ->jssort('host') + ->data(ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('SSL')) + ->columns(array( + 'id'=>'ID', + 'name()'=>'Service', + 'plugin()->expire(TRUE)'=>'Expire', + 'recur_schedule'=>'Billing', + 'price(TRUE,TRUE)'=>'Price', + 'account->accnum()'=>'Cust ID', + 'account->name()'=>'Customer', + 'date_next_invoice'=>'Next Invoice', + 'due(TRUE)'=>'Due Invoices', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )) + ); + } +} +?> diff --git a/modules/ssl/classes/Model/Service/Plugin/Ssl.php b/modules/ssl/classes/Model/Service/Plugin/Ssl.php index 44d1fd82..329dba40 100644 --- a/modules/ssl/classes/Model/Service/Plugin/Ssl.php +++ b/modules/ssl/classes/Model/Service/Plugin/Ssl.php @@ -68,8 +68,8 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin { return $this; } - public function expire() { - return $this->_so->get_valid_to(); + public function expire($format=FALSE) { + return $this->_so->get_valid_to($format); } public function name() {
%