From 5f84d2c14f07b6681410a7fb31b57f486a279cd3 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 3 Aug 2016 14:00:51 +1000 Subject: [PATCH] More Standardisation work. --- application/classes/Company.php | 2 +- application/classes/Controller/Login.php | 2 +- .../classes/Controller/User/Search.php | 8 +-- application/classes/Model/Account.php | 43 ++++++++++----- application/classes/ORM.php | 20 ++++++- application/classes/StaticList/ItemType.php | 16 +----- application/views/account/list.php | 2 +- .../adsl/classes/Model/ADSL/Supplier/Plan.php | 2 +- .../classes/Model/Service/Plugin/Adsl.php | 5 +- .../adsl/classes/Task/Adsl/Trafficalert.php | 2 +- .../adsl/classes/Task/Adsl/Trafficcharge.php | 2 +- .../classes/Controller/Reseller/Charge.php | 9 ++-- modules/charge/classes/Model/Charge.php | 7 +++ .../charge/views/charge/reseller/add_edit.php | 2 +- .../classes/Model/Service/Plugin/Domain.php | 5 +- .../email/classes/Controller/User/Email.php | 2 +- .../email/classes/Model/Email/Template.php | 2 +- .../classes/Model/Service/Plugin/Host.php | 5 +- .../classes/Controller/User/Invoice.php | 16 +++--- modules/invoice/classes/Model/Invoice.php | 2 +- .../invoice/classes/Model/Invoice/Item.php | 53 ++++++++++++++++--- modules/lnapp | 2 +- .../classes/Controller/Admin/Payment.php | 4 +- .../classes/Controller/User/Payment.php | 2 +- modules/product/classes/Model/Product.php | 49 ++++++++++++++++- .../classes/Model/Product/Category.php | 2 +- .../classes/Controller/Reseller/Service.php | 2 +- .../classes/Controller/User/Service.php | 2 +- modules/service/classes/Model/Service.php | 52 ++++++++++++------ modules/service/views/service/list.php | 19 +++++++ .../service/views/service/reseller/list.php | 2 +- modules/service/views/service/user/list.php | 15 ++++++ .../service/views/service/user/list/brief.php | 2 +- .../views/service/user/list/expiring.php | 5 +- .../views/service/user/list/inactive.php | 5 +- .../ssl/classes/Model/Service/Plugin/Ssl.php | 2 +- .../classes/Controller/Reseller/Statement.php | 2 +- .../classes/Controller/User/Statement.php | 2 +- 38 files changed, 276 insertions(+), 100 deletions(-) create mode 100644 modules/service/views/service/list.php create mode 100644 modules/service/views/service/user/list.php diff --git a/application/classes/Company.php b/application/classes/Company.php index 93de1d45..33c29f1c 100644 --- a/application/classes/Company.php +++ b/application/classes/Company.php @@ -83,7 +83,7 @@ class Company { return ($x=Kohana::find_file(sprintf('media/site/%s',$this->site()),$path,$suffix)) ? $x : Kohana::find_file('media',$path,$suffix); } - public function name() { + public function name($variable=NULL) { return $this->so->site_details('name'); } diff --git a/application/classes/Controller/Login.php b/application/classes/Controller/Login.php index 6f037340..4731e4f5 100644 --- a/application/classes/Controller/Login.php +++ b/application/classes/Controller/Login.php @@ -57,7 +57,7 @@ class Controller_Login extends lnApp_Controller_Login { 'SITE_NAME'=>Company::instance()->name(), 'TOKEN'=>$mmto->token, 'TOKEN_EXPIRE_MIN'=>$token_expire, - 'USER_NAME'=>sprintf('%s %s',$mmto->account->first_name,$mmto->account->last_name), + 'USER_NAME'=>$mmto->account->namesub(), ); $et->send(); diff --git a/application/classes/Controller/User/Search.php b/application/classes/Controller/User/Search.php index 3ef0e2d1..6fbf3dde 100644 --- a/application/classes/Controller/User/Search.php +++ b/application/classes/Controller/User/Search.php @@ -21,12 +21,12 @@ class Controller_User_Search extends Controller_Search { $result = array(); if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { - $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'url','id',array('ACC %s: %s'=>array('id','name(TRUE)')),array(),array('urlprefix'=>URL::link('reseller','account/view/')))); - $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'url','id',array('SVC %s: %s'=>array('id','service_name()')),array(),array('urlprefix'=>URL::link('user','service/view/')))); - $result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'url','id',array('INV %s: %s'=>array('id','account->name(TRUE)')),array(),array('urlprefix'=>URL::link('user','invoice/view/')))); + $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'url','id',array('ACC %s: %s'=>array('id','name()')),array(),array('urlprefix'=>URL::link('reseller','account/view/')))); + $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'url','id',array('SVC %s: %s'=>array('id','name()')),array(),array('urlprefix'=>URL::link('user','service/view/')))); + $result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'url','id',array('INV %s: %s'=>array('id','account->name()')),array(),array('urlprefix'=>URL::link('user','invoice/view/')))); foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o) - $result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service_name()')),array(),array('urlprefix'=>URL::link('user','service/view/')))); + $result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service->name()')),array(),array('urlprefix'=>URL::link('user','service/view/')))); } $this->response->headers('Content-Type','application/json'); diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index 002a893d..f20cfe18 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -21,12 +21,15 @@ class Model_Account extends lnApp_Model_Account { ); protected $_has_one = array( - 'country'=>array('foreign_key'=>'id'), - 'currency'=>array('foreign_key'=>'id'), - 'language'=>array('foreign_key'=>'id'), 'RTM'=>array('far_key'=>'id'), ); + protected $_belongs_to = array( + 'country'=>array(), + 'currency'=>array(), + 'language'=>array(), + ); + protected $_display_filters = array( 'date_orig'=>array( array('Site::Date',array(':value')), @@ -39,6 +42,22 @@ class Model_Account extends lnApp_Model_Account { ), ); + /** REQUIRED ABSTRACT METHODS **/ + + /** + * Returns the company name if it exists, otherwise the persons name + */ + public function name($variable=NULL) { + return $this->isCompany() ? $this->company : $this->namesub(); + } + + /* + * Returns the persons name + */ + public function namesub($variable=NULL) { + return trim(sprintf('%s %s',$this->first_name,$this->last_name)); + } + /** OTHER METHODS **/ public function activated() { @@ -85,15 +104,15 @@ class Model_Account extends lnApp_Model_Account { return ($this->RTM->loaded() AND is_null($this->RTM->parent_id)); } - public function isReseller() { - return $this->RTM->loaded(); + /** + * Is this account a company account + */ + public function isCompany() { + return strlen($this->company) > 0; } - /** - * Return an account name - */ - public function name($withcompany=FALSE) { - return trim(sprintf('%s %s',$this->first_name,$this->last_name).(($withcompany AND $this->company) ? sprintf(' (%s)',$this->company) : '')); + public function isReseller() { + return $this->RTM->loaded(); } /** @@ -111,7 +130,7 @@ class Model_Account extends lnApp_Model_Account { /** * Search for accounts matching a term */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { $ao = Auth::instance()->get_user(); $this->clear(); @@ -147,7 +166,7 @@ class Model_Account extends lnApp_Model_Account { // Restrict results to authorised accounts array_push($limit,array('id','IN',$ao->RTM->customers($ao->RTM))); - return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); + return parent::list_autocomplete($term,$index,$value,$label,$limit,array_merge($options,array('parentbypass'=>TRUE))); } } ?> diff --git a/application/classes/ORM.php b/application/classes/ORM.php index 3d41c167..2d8c9b61 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -148,11 +148,29 @@ abstract class ORM extends lnApp_ORM { /** * Name value return for the record + * + * @param $variable to enable further processing to determine name, eg: language */ - public function name() { + public function name($variable=NULL) { return sprintf('Unknown [%s]',$this->id); } + /** + * Sub-Name value return for the record + * + * @param $variable to enable further processing to determine name, eg: language + */ + public function namesub($variable=NULL) { + return sprintf('Unknown [%s]',$this->id); + } + + /** + * A reference number relating to the object + */ + public function refnum($short=FALSE) { + return ($short ? '' : 'x').sprintf('%06s',$this->id); + } + /** * Set the site ID attribute for each row update */ diff --git a/application/classes/StaticList/ItemType.php b/application/classes/StaticList/ItemType.php index 1c9a93d8..faff971f 100644 --- a/application/classes/StaticList/ItemType.php +++ b/application/classes/StaticList/ItemType.php @@ -11,21 +11,7 @@ */ class StaticList_ItemType extends StaticList { protected function _table() { - return array( - 0=>_('Product/Service Charge'), // Line Charge Topic on Invoice, eg: Service Name - 1=>_('Hardware'), - 2=>_('Service Relocation Fee'), - 3=>_('Service Change Fee'), - 4=>_('Service Connection Fee'), - 5=>_('Excess Usage'), // Excess Service Item, of item 0 - 6=>_('Service Cancellation Fee'), - 7=>_('Extra Product/Service Charge'), // Service Billing in advance - 8=>_('Product Addition'), // Additional Product Customisation - 124=>_('Late Payment Fee'), - 125=>_('Payment Fee'), // Payment processing fee - 126=>_('Other'), - 127=>_('Rounding'), - ); + return ORM::factory('Invoice_Item')->_types(); } public static function get($value) { diff --git a/application/views/account/list.php b/application/views/account/list.php index 33a2f0b2..0f5b5024 100644 --- a/application/views/account/list.php +++ b/application/views/account/list.php @@ -6,7 +6,7 @@ 'id'=>'ID', 'status'=>'Active', 'refnum()'=>'Num', - 'name(TRUE)'=>'Account', + 'name()'=>'Account', 'email'=>'Email', 'invoices_due_total(NULL,TRUE)'=>'Invoices', 'service->find_all()->count()'=>'Services', diff --git a/modules/adsl/classes/Model/ADSL/Supplier/Plan.php b/modules/adsl/classes/Model/ADSL/Supplier/Plan.php index 17ee7e22..4353c548 100644 --- a/modules/adsl/classes/Model/ADSL/Supplier/Plan.php +++ b/modules/adsl/classes/Model/ADSL/Supplier/Plan.php @@ -87,7 +87,7 @@ class Model_ADSL_Supplier_Plan extends ORM_OSB { /** * ADSL Plan Name */ - public function name() { + public function name($variable=NULL) { return sprintf('%s: %s',$this->product_id,$this->product_desc); } diff --git a/modules/adsl/classes/Model/Service/Plugin/Adsl.php b/modules/adsl/classes/Model/Service/Plugin/Adsl.php index 114ac475..4d60c7fb 100644 --- a/modules/adsl/classes/Model/Service/Plugin/Adsl.php +++ b/modules/adsl/classes/Model/Service/Plugin/Adsl.php @@ -41,7 +41,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin { return NULL; } - public function name() { + public function name($variable=NULL) { return $this->service_number; } @@ -435,7 +435,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin { /** * Search for services matching a term */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { $ao = Auth::instance()->get_user(); $options['key'] = 'id'; @@ -444,6 +444,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin { ->join('service') ->on('service.id','=',$this->_table_name.'.service_id') ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) + ->and_where('service.status','=',1) ->where_open() ->and_where($this->_table_name.'.service_number','like','%'.$term.'%') ->or_where($this->_table_name.'.service_address','like','%'.$term.'%') diff --git a/modules/adsl/classes/Task/Adsl/Trafficalert.php b/modules/adsl/classes/Task/Adsl/Trafficalert.php index 3c53ccc2..4dad8cc6 100644 --- a/modules/adsl/classes/Task/Adsl/Trafficalert.php +++ b/modules/adsl/classes/Task/Adsl/Trafficalert.php @@ -21,7 +21,7 @@ class Task_Adsl_Trafficalert extends Minion_Task { // @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 (Minion_CLI::options('verbose')) - echo $so->service_name()."\n"; + echo $so->name()."\n"; if (! $data=$so->plugin()->traffic_report()) continue; diff --git a/modules/adsl/classes/Task/Adsl/Trafficcharge.php b/modules/adsl/classes/Task/Adsl/Trafficcharge.php index 62b183c1..b8605c54 100644 --- a/modules/adsl/classes/Task/Adsl/Trafficcharge.php +++ b/modules/adsl/classes/Task/Adsl/Trafficcharge.php @@ -21,7 +21,7 @@ class Task_Adsl_Trafficcharge extends Minion_Task { // @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 (Minion_CLI::options('verbose')) - echo $so->service_name()."\n"; + echo $so->name()."\n"; if ($x=$so->plugin()->traffic_excess($date)) { $po = $so->plugin()->plan(); diff --git a/modules/charge/classes/Controller/Reseller/Charge.php b/modules/charge/classes/Controller/Reseller/Charge.php index c1a48087..a47f43d0 100644 --- a/modules/charge/classes/Controller/Reseller/Charge.php +++ b/modules/charge/classes/Controller/Reseller/Charge.php @@ -30,11 +30,11 @@ class Controller_Reseller_Charge extends Controller_Charge { $result = array(); if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { - $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'id','id',array('ACC %s: %s'=>array('id','name(TRUE)')))); - $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'account_id','id',array('ACC %s: %s (%s)'=>array('account_id','account->name()','name()')))); + $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'id','id',array('%s: %s'=>array('refnum()','name()')))); + $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'account_id','id',array('%s: %s (%s)'=>array('account->refnum()','account->name()','name()')))); foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o) - $result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'account_id','service->account_id',array('ACC %s: %s (%s)'=>array('service->account_id','service->account->name()','name()')))); + $result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'account_id','service->account_id',array('%s: %s (%s)'=>array('service->account->refnum()','service->account->name()','service->name()')))); } $this->response->headers('Content-Type','application/json'); @@ -45,7 +45,7 @@ class Controller_Reseller_Charge extends Controller_Charge { $result = array(); if (isset($_REQUEST['key']) AND trim($_REQUEST['key'])) - $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete('','id','id',array('SVC %s: %s'=>array('id','service_name()')),array(array('account_id','=',$_REQUEST['key'])))); + $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete('','id','id',array('%s: %s'=>array('refnum(TRUE)','name()')),array(array('account_id','=',$_REQUEST['key'])))); $this->response->headers('Content-Type','application/json'); $this->response->body(json_encode(array_values($result))); @@ -104,6 +104,7 @@ $(document).ready(function() { alert("Failed to submit"); }, success: function(data) { + $("select[name=service_id]").empty(); $.each(data, function(i, j){ var row = ""; $(row).appendTo("select[name=service_id]"); diff --git a/modules/charge/classes/Model/Charge.php b/modules/charge/classes/Model/Charge.php index 2b0c49e6..132bc0ca 100644 --- a/modules/charge/classes/Model/Charge.php +++ b/modules/charge/classes/Model/Charge.php @@ -79,6 +79,13 @@ class Model_Charge extends ORM_OSB implements Invoicable { } } + /** REQUIRED ABSTRACT METHODS **/ + public function namesub($variable=NULL) { + return sprintf('%d@%2.2f - %s (%s)',$this->quantity,$this->amount,($this->description ? ' '.$this->description : '').($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),$this->display('date_charge')); + } + + /** LOCAL METHODS **/ + /** * Return the Invoice Item object for this charge */ diff --git a/modules/charge/views/charge/reseller/add_edit.php b/modules/charge/views/charge/reseller/add_edit.php index 6382299d..f5ddd8de 100644 --- a/modules/charge/views/charge/reseller/add_edit.php +++ b/modules/charge/views/charge/reseller/add_edit.php @@ -23,7 +23,7 @@ description,array('label'=>'Description','placeholder'=>'Any notes about this charge?')); ?> - attributes as $key => $value) : + attributes) foreach ($o->attributes as $key => $value) : echo Form::input("attributes[$key]",$value,array('label'=>$key)); $i++; endforeach ?> diff --git a/modules/domain/classes/Model/Service/Plugin/Domain.php b/modules/domain/classes/Model/Service/Plugin/Domain.php index 4487b871..654abb14 100644 --- a/modules/domain/classes/Model/Service/Plugin/Domain.php +++ b/modules/domain/classes/Model/Service/Plugin/Domain.php @@ -41,7 +41,7 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin { return $this->domain_expire; } - public function name() { + public function name($variable=NULL) { return sprintf('%s.%s',$this->display('domain_name'),$this->tld->display('name')); } @@ -74,7 +74,7 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin { * Search for services matching a term * @todo This search doesnt pick up the TLD of domain names */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { // We only show domain names. if (is_numeric($term)) return array(); @@ -87,6 +87,7 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin { ->join('service') ->on('service.id','=',$this->_table_name.'.service_id') ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) + ->and_where('service.status','=',1) ->and_where($this->_table_name.'.domain_name','like','%'.$term.'%'); return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); diff --git a/modules/email/classes/Controller/User/Email.php b/modules/email/classes/Controller/User/Email.php index c41cde76..5fe911bf 100644 --- a/modules/email/classes/Controller/User/Email.php +++ b/modules/email/classes/Controller/User/Email.php @@ -22,7 +22,7 @@ class Controller_User_Email extends Controller_Email { $this->meta->title = 'Email List'; Block::factory() - ->title(sprintf(_('System Emails Sent for %s: %s'),$this->ao->refnum(),$this->ao->name(TRUE))) + ->title(sprintf(_('System Emails Sent for %s: %s'),$this->ao->refnum(),$this->ao->name())) ->title_icon($this->icon) ->body(View::factory('email/user/list')->set('o',$this->ao->email_log->find_all())); } diff --git a/modules/email/classes/Model/Email/Template.php b/modules/email/classes/Model/Email/Template.php index 18cd1a33..82e1661b 100644 --- a/modules/email/classes/Model/Email/Template.php +++ b/modules/email/classes/Model/Email/Template.php @@ -29,7 +29,7 @@ class Model_Email_Template extends ORM_OSB { protected $_save_message = TRUE; - public function name() { + public function name($variable=NULL) { return ! is_null($this->description) ? $this->description : $this->name; } diff --git a/modules/host/classes/Model/Service/Plugin/Host.php b/modules/host/classes/Model/Service/Plugin/Host.php index a170c9ea..373ec381 100644 --- a/modules/host/classes/Model/Service/Plugin/Host.php +++ b/modules/host/classes/Model/Service/Plugin/Host.php @@ -43,7 +43,7 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin { return $this->host_expire; } - public function name() { + public function name($variable=NULL) { return sprintf('%s.%s',$this->display('domain_name'),$this->tld->display('name')); } @@ -75,7 +75,7 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin { /** * Search for services matching a term */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { // We only show domain names. if (is_numeric($term)) return array(); @@ -88,6 +88,7 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin { ->join('service') ->on('service.id','=',$this->_table_name.'.service_id') ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) + ->and_where('service.status','=',1) ->and_where($this->_table_name.'.domain_name','like','%'.$term.'%'); return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); diff --git a/modules/invoice/classes/Controller/User/Invoice.php b/modules/invoice/classes/Controller/User/Invoice.php index b3bf549f..6b55cd32 100644 --- a/modules/invoice/classes/Controller/User/Invoice.php +++ b/modules/invoice/classes/Controller/User/Invoice.php @@ -26,13 +26,15 @@ class Controller_User_Invoice extends Controller_Invoice { if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); - // Log the download - $imo = $io->invoice_memo; - $imo->invoice_id = $io->id; - $imo->account_id = $this->ao->id; - $imo->type = 'download'; - $imo->memo = 'Invoice Downloaded.'; - $imo->save(); + if (! $this->ao->isAdmin()) { + // Log the download + $imo = $io->invoice_memo; + $imo->invoice_id = $io->id; + $imo->account_id = $this->ao->id; + $imo->type = 'download'; + $imo->memo = 'Invoice Downloaded.'; + $imo->save(); + } $this->response->body(Invoice::instance($io)->render('pdf','all',array('download'=>sprintf('%s.pdf',$io->refnum())))); $this->response->headers(array('Content-Type' => 'application/pdf')); diff --git a/modules/invoice/classes/Model/Invoice.php b/modules/invoice/classes/Model/Invoice.php index 136d80ad..a4fa3356 100644 --- a/modules/invoice/classes/Model/Invoice.php +++ b/modules/invoice/classes/Model/Invoice.php @@ -547,7 +547,7 @@ class Model_Invoice extends ORM_OSB implements Cartable { /** * Search for invoices matching a term */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { // We only show invoice numbers. if (! is_numeric($term)) return array(); diff --git a/modules/invoice/classes/Model/Invoice/Item.php b/modules/invoice/classes/Model/Invoice/Item.php index 9df2a2a2..2bedf46c 100644 --- a/modules/invoice/classes/Model/Invoice/Item.php +++ b/modules/invoice/classes/Model/Invoice/Item.php @@ -36,6 +36,46 @@ class Model_Invoice_Item extends ORM_OSB { 'tax'=>array(), ); + /** + * Invoice Item Types + */ + private $_item_type = array( + 0=>'Product/Service Charge', // Line Charge Topic on Invoice, eg: Service Name, must have corresponding SERVICE_ID + 1=>'Hardware', + 2=>'Service Relocation Fee', // Must have corresponding SERVICE_ID + 3=>'Service Change Fee', // Must have corresponding SERVICE_ID + 4=>'Service Connection Fee', // Must have corresponding SERVICE_ID + 5=>'Excess Usage', // Excess Service Item, of item 0, must have corresponding SERVICE_ID + 6=>'Service Cancellation Fee', // Must have corresponding SERVICE_ID + 7=>'Extra Product/Service Charge', // Service Billing in advance, Must have corresponding SERVICE_ID + 8=>'Product Addition', // Additional Product Customisation, Must have corresponding SERVICE_ID + 9=>'Module Charge', // Must have corresponding SERVICE_ID + 120=>'Credit/Debit Transfer', // SERVICE_ID is NULL, MODULE_ID is NULL, MODULE_REF is NULL : INVOICE_ID is NOT NULL + 124=>'Late Payment Fee', // SERVICE_ID is NULL, MODULE_ID = CHECKOUT MODULE, + 125=>'Payment Fee', // SERVICE_ID is NULL, MODULE_ID = CHECKOUT MODULE, MODULE_REF = CHECKOUT NAME + 126=>'Other', // MODEL_ID should be a module + 127=>'Rounding', // SERVICE_ID is NULL, MODULE_ID is NULL, MODULE_REF is NULL + ); + + /** REQUIRED ABSTRACT METHODS **/ + + public function name($variable=NULL) { + switch ($this->item_type) { + default: + return sprintf('Unknown [%s]',$this->id); + } + } + + public function titleline() { + return in_array($this->item_type,[0,120,124,125,126,127]); + } + + /** LOCAL METHODS **/ + + public function _types() { + return $this->_item_type; + } + /** * Add tax to our item * @@ -85,7 +125,7 @@ class Model_Invoice_Item extends ORM_OSB { switch ($this->item_type) { // Service Charges case 0: - return ((! $this->service_id OR $this->product_id OR $this->charge_id OR $this->product_name OR ! $this->recurring_schedule OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii.' '.$this->period(); + return ((! $this->service_id OR $this->product_id OR $this->product_name OR ! $this->recurring_schedule OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii.' '.$this->period(); case 1: // @todo return $this->product_name; @@ -95,10 +135,10 @@ class Model_Invoice_Item extends ORM_OSB { case 4: case 5: case 6: - return ((! $this->service_id OR $this->product_id OR $this->charge_id OR $this->product_name OR $this->recurring_schedule OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii; + return ((! $this->service_id OR $this->product_id OR $this->product_name OR $this->recurring_schedule OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii; case 7: - return ((! $this->service_id OR $this->product_id OR $this->charge_id OR $this->product_name OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii.' '.$this->period(); + return ((! $this->service_id OR $this->product_id OR $this->product_name OR ! $this->date_start OR ! $this->date_stop) ? '+ ' : '').$ii.' '.$this->period(); case 8: return $this->product_name; @@ -112,10 +152,7 @@ class Model_Invoice_Item extends ORM_OSB { // @todo DB records to fix. default: - if ($this->charge_id) - return '*'.($ii ? $ii : $this->charge->description).' '.$this->period(); - else - throw HTTP_Exception::factory(501,'Unable to render invoice item :id',array(':id'=>$this->id)); + throw HTTP_Exception::factory(501,'Unable to render invoice item :id',array(':id'=>$this->id)); } } @@ -202,7 +239,7 @@ class Model_Invoice_Item extends ORM_OSB { */ public function title() { if ($this->service_id AND $this->module_id AND method_exists($this->module(),'invoice_title')) - return $this->module_ref ? sprintf('%s: %s',$this->module()->invoice_title(),$this->service->name()) : $this->service->name(); + return $this->service->name(); #$this->module_ref ? sprintf('%s: %s',$this->module()->invoice_title(),$this->service->name()) : $this->service->name(); elseif ($x=$this->module() AND ($x instanceof Model_Charge) AND $x->product_id) return $x->product->title().' '.$this->service->name(); elseif ($this->product_id) diff --git a/modules/lnapp b/modules/lnapp index c57e1668..4bbf00a3 160000 --- a/modules/lnapp +++ b/modules/lnapp @@ -1 +1 @@ -Subproject commit c57e16683499491a56ff177a10896a531e4ae8d0 +Subproject commit 4bbf00a3d19198c28886877828e67816569aa0ec diff --git a/modules/payment/classes/Controller/Admin/Payment.php b/modules/payment/classes/Controller/Admin/Payment.php index 8d4c9114..f4476b22 100644 --- a/modules/payment/classes/Controller/Admin/Payment.php +++ b/modules/payment/classes/Controller/Admin/Payment.php @@ -74,8 +74,8 @@ class Controller_Admin_Payment extends Controller_Payment { $result = array(); if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { - $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'id','id',array('ACC %s: %s'=>array('id','name(TRUE)')))); - $result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'id','account_id',array('INV %s: %s'=>array('id','account->name(TRUE)')))); + $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'id','id',array('ACC %s: %s'=>array('id','name()')))); + $result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'id','account_id',array('INV %s: %s'=>array('id','account->name()')))); } $this->response->headers('Content-Type','application/json'); diff --git a/modules/payment/classes/Controller/User/Payment.php b/modules/payment/classes/Controller/User/Payment.php index 83ecbc5d..bbcb4f29 100644 --- a/modules/payment/classes/Controller/User/Payment.php +++ b/modules/payment/classes/Controller/User/Payment.php @@ -21,7 +21,7 @@ class Controller_User_Payment extends Controller_Payment { $this->meta->title = 'Payments Received'; Block::factory() - ->title(sprintf('%s: %s - %s',_('Payments Received For'),$this->ao->refnum(),$this->ao->name(TRUE))) + ->title(sprintf('%s: %s - %s',_('Payments Received For'),$this->ao->refnum(),$this->ao->name())) ->title_icon($this->icon) ->body(View::factory('payment/user/list')->set('o',$this->ao->payment->find_all())); } diff --git a/modules/product/classes/Model/Product.php b/modules/product/classes/Model/Product.php index ccc6cc8b..d3425826 100644 --- a/modules/product/classes/Model/Product.php +++ b/modules/product/classes/Model/Product.php @@ -13,6 +13,8 @@ * + price_type: 0=One Time, 1=Recurring, 2=Trial */ class Model_Product extends ORM_OSB implements Invoicable { + private $_pto = NULL; + protected $_has_many = array( 'invoice'=>array('through'=>'invoice_item'), 'service'=>array('far_key'=>'id'), @@ -55,7 +57,31 @@ class Model_Product extends ORM_OSB implements Invoicable { protected $_save_message = TRUE; - // Our required Interface Methods + /** REQUIRED ABSTRACT METHODS **/ + + public function name($variable=NULL) { + if (! $variable instanceof Model_Language) + throw HTTP_Exception::factory(500,'Call to :method incorrect',array(':method'=>__METHOD__)); + + $pto = $this->_pto($variable); + + return (! $pto->loaded() OR ! $pto->name) ? sprintf('Unknown: [%s]',$this->id) : $pto->name; + } + + public function namesub($variable=NULL) { + if (! $variable instanceof Model_Language) + throw HTTP::Exception(500,'Call to :method incorrect',array(':method'=>__METHOD__)); + + $pto = $this->_pto($variable); + + return (! $pto->loaded() OR ! $pto->description_short) ? sprintf('Unknown: [%s]',$this->id) : $pto->description_short; + } + + public function refnum($short=FALSE) { + return ($short ? '' : sprintf('%02s-',Site::id())).sprintf('%04s',$this->id); + } + + /** REQUIRED INTERFACE METHODS **/ public function invoice_item($item_type) { switch ($item_type) { @@ -73,7 +99,7 @@ class Model_Product extends ORM_OSB implements Invoicable { return $this->title(); } - // Our local methods + /** LOCAL METHODS **/ // Our database index for pricing values private $_price_options = array( @@ -81,6 +107,25 @@ class Model_Product extends ORM_OSB implements Invoicable { 'setup'=>'price_setup', ); + /** + * Return the translated langauge object + */ + private function _pto(Model_Language $lo) { + if (! $this->_pto) { + + // First try the called langauge. + $pto = $this->translate->where('language_id','=',$lo->id)->find(); + + // Second try the called langauge. + if (! $pto->loaded()) + $pto = $this->translate->where('language_id','=',Company::instance()->language()->id)->find(); + + $this->_pto = $pto; + } + + return $this->_pto; + } + public function cost($annual=FALSE) { return $this->plugin() ? $this->plugin()->cost($annual) : 0; } diff --git a/modules/product/classes/Model/Product/Category.php b/modules/product/classes/Model/Product/Category.php index 257601cb..ef13dbf6 100644 --- a/modules/product/classes/Model/Product/Category.php +++ b/modules/product/classes/Model/Product/Category.php @@ -39,7 +39,7 @@ class Model_Product_Category extends ORM_OSB { return $x->loaded() ? $x->display('description') : 'No Description'; } - public function name() { + public function name($variable=NULL) { $x = $this->translate(); return $x->loaded() ? $x->display('name') : 'No Name'; diff --git a/modules/service/classes/Controller/Reseller/Service.php b/modules/service/classes/Controller/Reseller/Service.php index 6030d661..a03cc719 100644 --- a/modules/service/classes/Controller/Reseller/Service.php +++ b/modules/service/classes/Controller/Reseller/Service.php @@ -64,7 +64,7 @@ class Controller_Reseller_Service extends Controller_Service { ->data($svs) ->columns(array( 'id'=>'ID', - 'service_name()'=>'Service', + 'name()'=>'Service', 'recur_schedule'=>'Billing', 'price(TRUE,TRUE)'=>'Price', 'account->refnum()'=>'Cust ID', diff --git a/modules/service/classes/Controller/User/Service.php b/modules/service/classes/Controller/User/Service.php index 1b0512b8..21ad6410 100644 --- a/modules/service/classes/Controller/User/Service.php +++ b/modules/service/classes/Controller/User/Service.php @@ -59,7 +59,7 @@ class Controller_User_Service extends Controller_Service { ->set('o',$so); Block::factory() - ->title(sprintf('%s: %s',$so->id(),$so->service_name())) + ->title(sprintf('%s: %s',$so->id(),$so->name())) ->title_icon('fa fa-server') ->body($output); } diff --git a/modules/service/classes/Model/Service.php b/modules/service/classes/Model/Service.php index 2abe972a..866acb04 100644 --- a/modules/service/classes/Model/Service.php +++ b/modules/service/classes/Model/Service.php @@ -13,6 +13,8 @@ * + queue: PROVISION (to be provisioned) */ class Model_Service extends ORM_OSB { + private $_plugin = NULL; + // Relationships protected $_has_one = array( 'service_billing'=>array('far_key'=>'account_billing_id','foreign_key'=>'id'), @@ -79,11 +81,41 @@ class Model_Service extends ORM_OSB { 'price_override', ); - protected $_form = array('id'=>'id','value'=>'service_name()'); + protected $_form = array('id'=>'id','value'=>'name()'); // Cache our calls to our plugins public static $plugin = array(); + /** REQUIRED ABSTRACT METHODS **/ + + /** + * Display the service product name + */ + public function name($variable=NULL) { + if (! $variable instanceOf Model_Language) + $variable = Company::instance()->language(); + + return $this->product->name($variable).(($x=$this->namesub($variable)) ? ': '.$x : ''); + } + + public function namesub($variable=NULL) { + return is_null($plugin=$this->_plugin()) ? '' : $plugin->name($variable); + } + + public function refnum($short=FALSE) { + return ($short ? '' : sprintf('%02s-',Site::id())).sprintf('%05s',$this->id); + } + + /** LOCAL METHODS **/ + + private function _plugin() { + if (! $this->_plugin AND $this->product->prod_plugin_file) { + $this->_plugin = ORM::factory(Kohana::classname(sprintf('Service_Plugin_%s',$this->product->prod_plugin_file)),array('service_id'=>$this->id)); + } + + return $this->_plugin; + } + /** * Get the additional charges associated with this service */ @@ -200,13 +232,6 @@ class Model_Service extends ORM_OSB { ->order_by('date_stop','DESC'); } - /** - * Display the service product name - */ - public function name() { - return is_null($plugin=$this->plugin()) ? $this->product->title() : $plugin->name(); - } - /** * Returns the date that an item has been paid to */ @@ -270,13 +295,6 @@ class Model_Service extends ORM_OSB { return $this->service_change->where_active()->where_open()->and_where('complete','!=',1)->or_where('complete','IS',null)->where_close()->find(); } - /** - * Return a descriptive name for this service - */ - public function service_name($chars=NULL) { - return HTML::abbr(is_null($x=$this->plugin()) ? $this->name() : $x->service_name(),$chars); - } - /** * Return the service charge */ @@ -323,7 +341,7 @@ class Model_Service extends ORM_OSB { /** * Search for services matching a term */ - public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) { + public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) { // We only show service numbers. if (! is_numeric($term) AND (! $limit)) return array(); @@ -364,7 +382,7 @@ class Model_Service extends ORM_OSB { if ($so->product->prod_plugin_file == $cat) array_push($result,$so); - Sort::MASort($result,'service_name()'); + Sort::MASort($result,array('name()')); return $result; } diff --git a/modules/service/views/service/list.php b/modules/service/views/service/list.php new file mode 100644 index 00000000..ae3212bb --- /dev/null +++ b/modules/service/views/service/list.php @@ -0,0 +1,19 @@ + +jssort('service') + ->data($o) + ->columns(array( + 'id'=>'ID', + 'name()'=>'Service', + 'plugin()->expire(TRUE)'=>'Expire', + 'recur_schedule'=>'Billing', + 'price(TRUE,TRUE)'=>'Price', + 'account->refnum()'=>'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/service/views/service/reseller/list.php b/modules/service/views/service/reseller/list.php index e6108fc5..9e61d5d5 100644 --- a/modules/service/views/service/reseller/list.php +++ b/modules/service/views/service/reseller/list.php @@ -4,7 +4,7 @@ ->data($o) ->columns(array( 'id'=>'ID', - 'service_name()'=>'Service', + 'name()'=>'Service', 'recur_schedule'=>'Billing', 'price(TRUE,TRUE)'=>'Price', 'charges(TRUE,TRUE)'=>'Charges', diff --git a/modules/service/views/service/user/list.php b/modules/service/views/service/user/list.php new file mode 100644 index 00000000..89c3f18e --- /dev/null +++ b/modules/service/views/service/user/list.php @@ -0,0 +1,15 @@ + +data($o) + ->columns(array( + 'id'=>'ID', + 'name()'=>'Service', + 'recur_schedule'=>'Billing', + 'price(TRUE,TRUE)'=>'Price', + 'status'=>'Active', + + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','service/view/')), + )); +?> diff --git a/modules/service/views/service/user/list/brief.php b/modules/service/views/service/user/list/brief.php index 2817a5ce..0fbf20e0 100644 --- a/modules/service/views/service/user/list/brief.php +++ b/modules/service/views/service/user/list/brief.php @@ -3,7 +3,7 @@ ->data($o) ->columns(array( 'id'=>'ID', - 'service_name()'=>'Service', + 'name()'=>'Service', )) ->prepend(array( 'id'=>array('url'=>URL::link('user','service/view/')), diff --git a/modules/service/views/service/user/list/expiring.php b/modules/service/views/service/user/list/expiring.php index d9528432..5a9234a2 100644 --- a/modules/service/views/service/user/list/expiring.php +++ b/modules/service/views/service/user/list/expiring.php @@ -3,10 +3,13 @@ ->data($o) ->columns(array( 'id'=>'ID', - 'service_name(59)'=>'Service', + 'name()'=>'Service', 'expire(TRUE)'=>'Date', )) ->prepend(array( 'id'=>array('url'=>URL::link('user','service/view/')), + )) + ->postproc(array( + 'name()'=>array('trim'=>60), )); ?> diff --git a/modules/service/views/service/user/list/inactive.php b/modules/service/views/service/user/list/inactive.php index a5b0b31e..bbd328ce 100644 --- a/modules/service/views/service/user/list/inactive.php +++ b/modules/service/views/service/user/list/inactive.php @@ -3,10 +3,13 @@ ->data($o) ->columns(array( 'id'=>'ID', - 'service_name(60)'=>'Service', + 'name()'=>'Service', 'date_end'=>'Date', )) ->prepend(array( 'id'=>array('url'=>URL::link('user','service/view/')), + )) + ->postproc(array( + 'name()'=>array('trim'=>60), )); ?> diff --git a/modules/ssl/classes/Model/Service/Plugin/Ssl.php b/modules/ssl/classes/Model/Service/Plugin/Ssl.php index e18d5f12..c0e46f67 100644 --- a/modules/ssl/classes/Model/Service/Plugin/Ssl.php +++ b/modules/ssl/classes/Model/Service/Plugin/Ssl.php @@ -39,7 +39,7 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin { return $this->_so->get_valid_to($format); } - public function name() { + public function name($variable=NULL) { return ($this->cert AND $this->ca->loaded()) ? sprintf('%s:%s',$this->ca->subject(),$this->display('cert')) : $this->display('csr'); } diff --git a/modules/statement/classes/Controller/Reseller/Statement.php b/modules/statement/classes/Controller/Reseller/Statement.php index 80dc23bb..fa9061dc 100644 --- a/modules/statement/classes/Controller/Reseller/Statement.php +++ b/modules/statement/classes/Controller/Reseller/Statement.php @@ -70,7 +70,7 @@ class Controller_Reseller_Statement extends Controller_Statement { krsort($result); Block::factory() - ->title(sprintf('%s: %s - %s',_('Transactions For'),$ao->refnum(),$ao->name(TRUE))) + ->title(sprintf('%s: %s - %s',_('Transactions For'),$ao->refnum(),$ao->name())) ->title_icon('icon-tasks') ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); } diff --git a/modules/statement/classes/Controller/User/Statement.php b/modules/statement/classes/Controller/User/Statement.php index 962a01b4..06407a80 100644 --- a/modules/statement/classes/Controller/User/Statement.php +++ b/modules/statement/classes/Controller/User/Statement.php @@ -48,7 +48,7 @@ class Controller_User_Statement extends Controller_Statement { krsort($result); Block::factory() - ->title(sprintf('%s: %s - %s',_('Transactions For'),$this->ao->refnum(),$this->ao->name(TRUE))) + ->title(sprintf('%s: %s - %s',_('Transactions For'),$this->ao->refnum(),$this->ao->name())) ->title_icon('icon-tasks') ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); }