TRUE, 'ajaxjson_traffic'=>TRUE, 'adslstat'=>TRUE, 'list'=>TRUE, 'listbycheckout'=>TRUE, 'listadslbilling'=>TRUE, 'listadslservices'=>TRUE, 'listexpiring'=>TRUE, 'listdomainservices'=>TRUE, 'listdomainservicesbysupplier'=>TRUE, 'listdomainservicesbydnshost'=>TRUE, 'listhostservices'=>TRUE, 'listhostservicesbysupplier'=>TRUE, 'listhspaservices'=>TRUE, 'listwebservices'=>TRUE, 'listinvoicesoon'=>TRUE, 'update'=>TRUE, 'view'=>TRUE, ); public function action_ajaxlist() { $return = array(); $return += ORM::factory('service')->list_autocomplete( isset($_REQUEST['term']) ? $_REQUEST['term'] : '', 'id', isset($_REQUEST['aid']) ? array(array('account_id','=',$_REQUEST['aid'])) : array()); $this->auto_render = FALSE; $this->response->headers('Content-Type','application/json'); $this->response->body(json_encode(array_values($return))); } public function action_ajaxjson_traffic() { $return = array(); $svs = ORM::factory('service')->list_bylistgroup('ADSL'); $data = $this->consoltraffic($svs,time()); $google = GoogleChart::factory('ComboChart'); foreach ($data['data'] as $key => $values) $google->data(array('yl'=>$key),array($key=>$values)); $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); $this->auto_render = FALSE; $this->response->headers('Content-Type','application/json'); $this->response->body($google->json()); } /** * Show a list of services */ public function action_list() { Block::add(array( 'title'=>_('Customer Services'), 'body'=>Table::display( ORM::factory('service')->find_all(), 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'recur_schedule'=>array('label'=>'Billing'), 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), 'status'=>array('label'=>'Active'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), ), array( 'page'=>TRUE, 'type'=>'select', 'form'=>'user/service/view', )), )); } /** * List all services by their default checkout method */ public function action_listbycheckout() { $svs = array(); // @todo This needs to be configurable $go = ORM::factory('group',array('name'=>'Personal')); foreach (ORM::factory('account')->list_active() as $ao) if ($ao->has_any('group',array($go))) foreach ($ao->service->list_active() as $so) if (! $so->service_billing->checkout_plugin_id) array_push($svs,$so); if ($svs) Block::add(array( 'title'=>'Services that should be auto-billed', 'body'=>Table::display( $svs, 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'recur_schedule'=>array('label'=>'Billing'), 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), 'status'=>array('label'=>'Active'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), 'date_next_invoice'=>array('label'=>'Next Invoice'), 'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'), ), array( 'page'=>TRUE, 'type'=>'select', 'form'=>'user/service/view', )), )); foreach (ORM::factory('checkout')->list_active() as $co) { $svs = array(); foreach ($co->account->find_all() as $ao) foreach ($ao->service->list_active() as $so) if ($so->service_billing->checkout_plugin_id == $co->id) array_push($svs,$so); if ($svs) Block::add(array( 'title'=>$co->name, 'body'=>Table::display( $svs, 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'recur_schedule'=>array('label'=>'Billing'), 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), 'status'=>array('label'=>'Active'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), 'date_next_invoice'=>array('label'=>'Next Invoice'), 'account->invoices_due_total(NULL,TRUE)'=>array('label'=>'Due Invoices'), ), array( 'page'=>TRUE, 'type'=>'select', 'form'=>'user/service/view', )), )); } } 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; } public function action_listadslservices() { $svs = ORM::factory('service')->list_bylistgroup('ADSL'); $data = $this->consoltraffic($svs,time()); $google = GoogleChart::factory('ComboChart') ->title(sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday')))); foreach ($data['data'] as $key => $values) $google->data(array('yl'=>$key),array($key=>$values)); $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); Block::add(array('body'=>(string)$google)); Block::add(array( 'title'=>_('ADSL Services'), 'body'=>Table::display( $svs, NULL, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'name()'=>array('label'=>'Service'), 'plugin()->ipaddress()'=>array('label'=>'IP Address'), 'product->plugin()->speed'=>array('label'=>'Speed'), 'product->plugin()->allowance()'=>array('label'=>'Allowance'), 'plugin()->traffic_thismonth()'=>array('label'=>'This Month'), 'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'), 'recur_schedule'=>array('label'=>'Billing'), 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), 'date_next_invoice'=>array('label'=>'Next Invoice'), 'product->display("status")'=>array('label'=>'Current'), ), array( 'type'=>'select', 'form'=>'user/service/view', )), )); } /** * 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, NULL, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Service'), 'expire(TRUE)'=>array('label'=>'Expires'), 'due(TRUE)'=>array('label'=>'Due'), ), array( 'type'=>'select', 'form'=>'user/service/view', )), )); } public function action_listhspaservices() { $svs = ORM::factory('service')->list_bylistgroup('HSPA'); $data = $this->consoltraffic($svs,time()); $google = GoogleChart::factory('Legacy') ->type('vertical_bar') ->title(sprintf('HSPA traffic as at %s',date('Y-m-d',strtotime('yesterday')))); foreach ($data['data'] as $key => $values) $google->data(array('yl'=>$key),array($key=>$values)); $google->data(array('yr'=>'services'),array('services'=>$data['svs'])); Block::add(array('body'=>(string)$google)); Block::add(array( 'title'=>_('HSPA Services'), 'body'=>Table::display( $svs, NULL, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'name()'=>array('label'=>'Service'), 'plugin()->ipaddress()'=>array('label'=>'IP Address'), 'product->plugin()->speed'=>array('label'=>'Speed'), 'product->plugin()->allowance()'=>array('label'=>'Allowance'), 'plugin()->traffic_thismonth()'=>array('label'=>'This Month'), 'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'), 'recur_schedule'=>array('label'=>'Billing'), 'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'), 'account->accnum()'=>array('label'=>'Cust ID'), 'account->name()'=>array('label'=>'Customer'), 'date_next_invoice'=>array('label'=>'Next Invoice'), ), array( 'type'=>'select', 'form'=>'user/service/view', )), )); } public function action_listdomainservices() { $svs = ORM::factory('service')->list_bylistgroup('DOMAIN'); Sort::MAsort($svs,'name()'); Block::add(array( 'title'=>_('Domain Names'), 'body'=>Table::display( $svs, 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'plugin()->display("domain_expire")'=>array('label'=>'Expire'), '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'=>'user/service/view', )), )); } public function action_listdomainservicesbysupplier() { $svs = ORM::factory('service')->list_bylistgroup('DOMAIN'); Sort::MAsort($svs,'plugin()->domain_registrar_id,name()'); $list = array(); foreach ($svs as $so) $list[$so->plugin()->domain_registrar_id][] = $so; foreach (array_keys($list) as $sid) Block::add(array( 'title'=>sprintf(_('Domain Names by Supplier %s'),$sid), 'body'=>Table::display( $list[$sid], 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'plugin()->display("domain_expire")'=>array('label'=>'Expire'), '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'=>'user/service/view', )), )); } public function action_listdomainservicesbydnshost() { $svs = ORM::factory('service')->list_bylistgroup('DOMAIN'); Sort::MAsort($svs,'plugin()->service_plugin_host,name()'); $list = array(); foreach ($svs as $so) $list[$so->plugin()->service_plugin_host->host_server_id][] = $so; foreach (array_keys($list) as $sid) Block::add(array( 'title'=>sprintf(_('Domain Names by DNS Host [%s]'),$sid), 'body'=>Table::display( $list[$sid], 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'plugin()->domain_registrar->id'=>array('label'=>'SID'), 'plugin()->domain_registrar->name'=>array('label'=>'Supplier'), 'display("date_next_invoice")'=>array('label'=>'Next Invoice'), ), array( 'page'=>TRUE, 'type'=>'select', 'form'=>'user/service/view', )), )); } public function action_listhostservices() { $svs = ORM::factory('service')->list_bylistgroup('HOST'); Sort::MAsort($svs,'name()'); Block::add(array( 'title'=>_('Hosting Services'), 'body'=>Table::display( $svs, 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'plugin()->display("host_expire")'=>array('label'=>'Expire'), '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'=>'user/service/view', )), )); } public function action_listhostservicesbysupplier() { $svs = ORM::factory('service')->list_bylistgroup('HOST'); Sort::MAsort($svs,'plugin()->host_server,name()'); $list = array(); foreach ($svs as $so) $list[$so->plugin()->host_server_id][] = $so; foreach (array_keys($list) as $sid) Block::add(array( 'title'=>sprintf(_('Hosting by Supplier %s'),$sid), 'body'=>Table::display( $list[$sid], 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'service_name()'=>array('label'=>'Details'), 'plugin()->display("host_expire")'=>array('label'=>'Expire'), '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'=>'user/service/view', )), )); } 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'=>'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'=>'user/service/view', )), )); } /** * Reconcile billing for an ADSL supplier * * @todo this should really be in a different class, since adsl wont be part of the main app */ public function action_listadslbilling($id) { $aso = ORM::factory('adsl_supplier',$id); // Process upload // @todo This should be separated out by supplier in case each supplier has a different format if ($_FILES) { $files = Validation::factory($_FILES) ->rule('csv','Upload::valid') ->rule('csv','Upload::not_empty') ->rule('csv','Upload::type',array(':value',array('csv'))) ->rule('csv','Upload::size',array(':value','10M')); if ($files->check()) foreach ($files as $file) $csv = $this->process($file); } // @todo add a display if there are no items $i = $j = 0; $total = 0; $summary = ''; $output = View::factory($this->viewpath().'/head'); $output .= '