More Standardisation work.

This commit is contained in:
Deon George 2016-08-03 14:00:51 +10:00
parent 85f08bbb0a
commit 5f84d2c14f
38 changed files with 276 additions and 100 deletions

View File

@ -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); 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'); return $this->so->site_details('name');
} }

View File

@ -57,7 +57,7 @@ class Controller_Login extends lnApp_Controller_Login {
'SITE_NAME'=>Company::instance()->name(), 'SITE_NAME'=>Company::instance()->name(),
'TOKEN'=>$mmto->token, 'TOKEN'=>$mmto->token,
'TOKEN_EXPIRE_MIN'=>$token_expire, '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(); $et->send();

View File

@ -21,12 +21,12 @@ class Controller_User_Search extends Controller_Search {
$result = array(); $result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { 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('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','service_name()')),array(),array('urlprefix'=>URL::link('user','service/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(TRUE)')),array(),array('urlprefix'=>URL::link('user','invoice/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) 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'); $this->response->headers('Content-Type','application/json');

View File

@ -21,12 +21,15 @@ class Model_Account extends lnApp_Model_Account {
); );
protected $_has_one = array( protected $_has_one = array(
'country'=>array('foreign_key'=>'id'),
'currency'=>array('foreign_key'=>'id'),
'language'=>array('foreign_key'=>'id'),
'RTM'=>array('far_key'=>'id'), 'RTM'=>array('far_key'=>'id'),
); );
protected $_belongs_to = array(
'country'=>array(),
'currency'=>array(),
'language'=>array(),
);
protected $_display_filters = array( protected $_display_filters = array(
'date_orig'=>array( 'date_orig'=>array(
array('Site::Date',array(':value')), 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 **/ /** OTHER METHODS **/
public function activated() { 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)); 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;
} }
/** public function isReseller() {
* Return an account name return $this->RTM->loaded();
*/
public function name($withcompany=FALSE) {
return trim(sprintf('%s %s',$this->first_name,$this->last_name).(($withcompany AND $this->company) ? sprintf(' (%s)',$this->company) : ''));
} }
/** /**
@ -111,7 +130,7 @@ class Model_Account extends lnApp_Model_Account {
/** /**
* Search for accounts matching a term * 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(); $ao = Auth::instance()->get_user();
$this->clear(); $this->clear();
@ -147,7 +166,7 @@ class Model_Account extends lnApp_Model_Account {
// Restrict results to authorised accounts // Restrict results to authorised accounts
array_push($limit,array('id','IN',$ao->RTM->customers($ao->RTM))); 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)));
} }
} }
?> ?>

View File

@ -148,11 +148,29 @@ abstract class ORM extends lnApp_ORM {
/** /**
* Name value return for the record * 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); 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 * Set the site ID attribute for each row update
*/ */

View File

@ -11,21 +11,7 @@
*/ */
class StaticList_ItemType extends StaticList { class StaticList_ItemType extends StaticList {
protected function _table() { protected function _table() {
return array( return ORM::factory('Invoice_Item')->_types();
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'),
);
} }
public static function get($value) { public static function get($value) {

View File

@ -6,7 +6,7 @@
'id'=>'ID', 'id'=>'ID',
'status'=>'Active', 'status'=>'Active',
'refnum()'=>'Num', 'refnum()'=>'Num',
'name(TRUE)'=>'Account', 'name()'=>'Account',
'email'=>'Email', 'email'=>'Email',
'invoices_due_total(NULL,TRUE)'=>'Invoices', 'invoices_due_total(NULL,TRUE)'=>'Invoices',
'service->find_all()->count()'=>'Services', 'service->find_all()->count()'=>'Services',

View File

@ -87,7 +87,7 @@ class Model_ADSL_Supplier_Plan extends ORM_OSB {
/** /**
* ADSL Plan Name * ADSL Plan Name
*/ */
public function name() { public function name($variable=NULL) {
return sprintf('%s: %s',$this->product_id,$this->product_desc); return sprintf('%s: %s',$this->product_id,$this->product_desc);
} }

View File

@ -41,7 +41,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
return NULL; return NULL;
} }
public function name() { public function name($variable=NULL) {
return $this->service_number; return $this->service_number;
} }
@ -435,7 +435,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
/** /**
* Search for services matching a term * 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(); $ao = Auth::instance()->get_user();
$options['key'] = 'id'; $options['key'] = 'id';
@ -444,6 +444,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
->join('service') ->join('service')
->on('service.id','=',$this->_table_name.'.service_id') ->on('service.id','=',$this->_table_name.'.service_id')
->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM))
->and_where('service.status','=',1)
->where_open() ->where_open()
->and_where($this->_table_name.'.service_number','like','%'.$term.'%') ->and_where($this->_table_name.'.service_number','like','%'.$term.'%')
->or_where($this->_table_name.'.service_address','like','%'.$term.'%') ->or_where($this->_table_name.'.service_address','like','%'.$term.'%')

View File

@ -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. // @todo Pick up services that are no longer active, but were inactive < 30 days ago.
foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) { foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) {
if (Minion_CLI::options('verbose')) if (Minion_CLI::options('verbose'))
echo $so->service_name()."\n"; echo $so->name()."\n";
if (! $data=$so->plugin()->traffic_report()) if (! $data=$so->plugin()->traffic_report())
continue; continue;

View File

@ -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. // @todo Pick up services that are no longer active, but were inactive < 30 days ago.
foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) { foreach (ORM::factory('Service')->list_byplugin('ADSL') as $so) {
if (Minion_CLI::options('verbose')) if (Minion_CLI::options('verbose'))
echo $so->service_name()."\n"; echo $so->name()."\n";
if ($x=$so->plugin()->traffic_excess($date)) { if ($x=$so->plugin()->traffic_excess($date)) {
$po = $so->plugin()->plan(); $po = $so->plugin()->plan();

View File

@ -30,11 +30,11 @@ class Controller_Reseller_Charge extends Controller_Charge {
$result = array(); $result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { 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('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('ACC %s: %s (%s)'=>array('account_id','account->name()','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) 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'); $this->response->headers('Content-Type','application/json');
@ -45,7 +45,7 @@ class Controller_Reseller_Charge extends Controller_Charge {
$result = array(); $result = array();
if (isset($_REQUEST['key']) AND trim($_REQUEST['key'])) 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->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($result))); $this->response->body(json_encode(array_values($result)));
@ -104,6 +104,7 @@ $(document).ready(function() {
alert("Failed to submit"); alert("Failed to submit");
}, },
success: function(data) { success: function(data) {
$("select[name=service_id]").empty();
$.each(data, function(i, j){ $.each(data, function(i, j){
var row = "<option value=\"" + j.value + "\">" + j.label + "</option>"; var row = "<option value=\"" + j.value + "\">" + j.label + "</option>";
$(row).appendTo("select[name=service_id]"); $(row).appendTo("select[name=service_id]");

View File

@ -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 * Return the Invoice Item object for this charge
*/ */

View File

@ -23,7 +23,7 @@
<?php echo Form::input('description',$o->description,array('label'=>'Description','placeholder'=>'Any notes about this charge?')); ?> <?php echo Form::input('description',$o->description,array('label'=>'Description','placeholder'=>'Any notes about this charge?')); ?>
<!-- @todo Use JS to dynamically add more lines as required --> <!-- @todo Use JS to dynamically add more lines as required -->
<?php $i=0; foreach ($o->attributes as $key => $value) : <?php $i=0; if ($o->attributes) foreach ($o->attributes as $key => $value) :
echo Form::input("attributes[$key]",$value,array('label'=>$key)); echo Form::input("attributes[$key]",$value,array('label'=>$key));
$i++; $i++;
endforeach ?> endforeach ?>

View File

@ -41,7 +41,7 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
return $this->domain_expire; return $this->domain_expire;
} }
public function name() { public function name($variable=NULL) {
return sprintf('%s.%s',$this->display('domain_name'),$this->tld->display('name')); 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 * Search for services matching a term
* @todo This search doesnt pick up the TLD of domain names * @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. // We only show domain names.
if (is_numeric($term)) if (is_numeric($term))
return array(); return array();
@ -87,6 +87,7 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
->join('service') ->join('service')
->on('service.id','=',$this->_table_name.'.service_id') ->on('service.id','=',$this->_table_name.'.service_id')
->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM))
->and_where('service.status','=',1)
->and_where($this->_table_name.'.domain_name','like','%'.$term.'%'); ->and_where($this->_table_name.'.domain_name','like','%'.$term.'%');
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);

View File

@ -22,7 +22,7 @@ class Controller_User_Email extends Controller_Email {
$this->meta->title = 'Email List'; $this->meta->title = 'Email List';
Block::factory() 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) ->title_icon($this->icon)
->body(View::factory('email/user/list')->set('o',$this->ao->email_log->find_all())); ->body(View::factory('email/user/list')->set('o',$this->ao->email_log->find_all()));
} }

View File

@ -29,7 +29,7 @@ class Model_Email_Template extends ORM_OSB {
protected $_save_message = TRUE; protected $_save_message = TRUE;
public function name() { public function name($variable=NULL) {
return ! is_null($this->description) ? $this->description : $this->name; return ! is_null($this->description) ? $this->description : $this->name;
} }

View File

@ -43,7 +43,7 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
return $this->host_expire; return $this->host_expire;
} }
public function name() { public function name($variable=NULL) {
return sprintf('%s.%s',$this->display('domain_name'),$this->tld->display('name')); 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 * 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. // We only show domain names.
if (is_numeric($term)) if (is_numeric($term))
return array(); return array();
@ -88,6 +88,7 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
->join('service') ->join('service')
->on('service.id','=',$this->_table_name.'.service_id') ->on('service.id','=',$this->_table_name.'.service_id')
->where('service.account_id','IN',$ao->RTM->customers($ao->RTM)) ->where('service.account_id','IN',$ao->RTM->customers($ao->RTM))
->and_where('service.status','=',1)
->and_where($this->_table_name.'.domain_name','like','%'.$term.'%'); ->and_where($this->_table_name.'.domain_name','like','%'.$term.'%');
return parent::list_autocomplete($term,$index,$value,$label,$limit,$options); return parent::list_autocomplete($term,$index,$value,$label,$limit,$options);

View File

@ -26,13 +26,15 @@ class Controller_User_Invoice extends Controller_Invoice {
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account)) 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'); throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
// Log the download if (! $this->ao->isAdmin()) {
$imo = $io->invoice_memo; // Log the download
$imo->invoice_id = $io->id; $imo = $io->invoice_memo;
$imo->account_id = $this->ao->id; $imo->invoice_id = $io->id;
$imo->type = 'download'; $imo->account_id = $this->ao->id;
$imo->memo = 'Invoice Downloaded.'; $imo->type = 'download';
$imo->save(); $imo->memo = 'Invoice Downloaded.';
$imo->save();
}
$this->response->body(Invoice::instance($io)->render('pdf','all',array('download'=>sprintf('%s.pdf',$io->refnum())))); $this->response->body(Invoice::instance($io)->render('pdf','all',array('download'=>sprintf('%s.pdf',$io->refnum()))));
$this->response->headers(array('Content-Type' => 'application/pdf')); $this->response->headers(array('Content-Type' => 'application/pdf'));

View File

@ -547,7 +547,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
/** /**
* Search for invoices matching a term * 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. // We only show invoice numbers.
if (! is_numeric($term)) if (! is_numeric($term))
return array(); return array();

View File

@ -36,6 +36,46 @@ class Model_Invoice_Item extends ORM_OSB {
'tax'=>array(), '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 * Add tax to our item
* *
@ -85,7 +125,7 @@ class Model_Invoice_Item extends ORM_OSB {
switch ($this->item_type) { switch ($this->item_type) {
// Service Charges // Service Charges
case 0: 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: case 1:
// @todo // @todo
return $this->product_name; return $this->product_name;
@ -95,10 +135,10 @@ class Model_Invoice_Item extends ORM_OSB {
case 4: case 4:
case 5: case 5:
case 6: 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: 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: case 8:
return $this->product_name; return $this->product_name;
@ -112,10 +152,7 @@ class Model_Invoice_Item extends ORM_OSB {
// @todo DB records to fix. // @todo DB records to fix.
default: default:
if ($this->charge_id) throw HTTP_Exception::factory(501,'Unable to render invoice item :id',array(':id'=>$this->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));
} }
} }
@ -202,7 +239,7 @@ class Model_Invoice_Item extends ORM_OSB {
*/ */
public function title() { public function title() {
if ($this->service_id AND $this->module_id AND method_exists($this->module(),'invoice_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) elseif ($x=$this->module() AND ($x instanceof Model_Charge) AND $x->product_id)
return $x->product->title().' '.$this->service->name(); return $x->product->title().' '.$this->service->name();
elseif ($this->product_id) elseif ($this->product_id)

@ -1 +1 @@
Subproject commit c57e16683499491a56ff177a10896a531e4ae8d0 Subproject commit 4bbf00a3d19198c28886877828e67816569aa0ec

View File

@ -74,8 +74,8 @@ class Controller_Admin_Payment extends Controller_Payment {
$result = array(); $result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { 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('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(TRUE)')))); $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'); $this->response->headers('Content-Type','application/json');

View File

@ -21,7 +21,7 @@ class Controller_User_Payment extends Controller_Payment {
$this->meta->title = 'Payments Received'; $this->meta->title = 'Payments Received';
Block::factory() 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) ->title_icon($this->icon)
->body(View::factory('payment/user/list')->set('o',$this->ao->payment->find_all())); ->body(View::factory('payment/user/list')->set('o',$this->ao->payment->find_all()));
} }

View File

@ -13,6 +13,8 @@
* + price_type: 0=One Time, 1=Recurring, 2=Trial * + price_type: 0=One Time, 1=Recurring, 2=Trial
*/ */
class Model_Product extends ORM_OSB implements Invoicable { class Model_Product extends ORM_OSB implements Invoicable {
private $_pto = NULL;
protected $_has_many = array( protected $_has_many = array(
'invoice'=>array('through'=>'invoice_item'), 'invoice'=>array('through'=>'invoice_item'),
'service'=>array('far_key'=>'id'), 'service'=>array('far_key'=>'id'),
@ -55,7 +57,31 @@ class Model_Product extends ORM_OSB implements Invoicable {
protected $_save_message = TRUE; 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) { public function invoice_item($item_type) {
switch ($item_type) { switch ($item_type) {
@ -73,7 +99,7 @@ class Model_Product extends ORM_OSB implements Invoicable {
return $this->title(); return $this->title();
} }
// Our local methods /** LOCAL METHODS **/
// Our database index for pricing values // Our database index for pricing values
private $_price_options = array( private $_price_options = array(
@ -81,6 +107,25 @@ class Model_Product extends ORM_OSB implements Invoicable {
'setup'=>'price_setup', '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) { public function cost($annual=FALSE) {
return $this->plugin() ? $this->plugin()->cost($annual) : 0; return $this->plugin() ? $this->plugin()->cost($annual) : 0;
} }

View File

@ -39,7 +39,7 @@ class Model_Product_Category extends ORM_OSB {
return $x->loaded() ? $x->display('description') : 'No Description'; return $x->loaded() ? $x->display('description') : 'No Description';
} }
public function name() { public function name($variable=NULL) {
$x = $this->translate(); $x = $this->translate();
return $x->loaded() ? $x->display('name') : 'No Name'; return $x->loaded() ? $x->display('name') : 'No Name';

View File

@ -64,7 +64,7 @@ class Controller_Reseller_Service extends Controller_Service {
->data($svs) ->data($svs)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'service_name()'=>'Service', 'name()'=>'Service',
'recur_schedule'=>'Billing', 'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price', 'price(TRUE,TRUE)'=>'Price',
'account->refnum()'=>'Cust ID', 'account->refnum()'=>'Cust ID',

View File

@ -59,7 +59,7 @@ class Controller_User_Service extends Controller_Service {
->set('o',$so); ->set('o',$so);
Block::factory() Block::factory()
->title(sprintf('%s: %s',$so->id(),$so->service_name())) ->title(sprintf('%s: %s',$so->id(),$so->name()))
->title_icon('fa fa-server') ->title_icon('fa fa-server')
->body($output); ->body($output);
} }

View File

@ -13,6 +13,8 @@
* + queue: PROVISION (to be provisioned) * + queue: PROVISION (to be provisioned)
*/ */
class Model_Service extends ORM_OSB { class Model_Service extends ORM_OSB {
private $_plugin = NULL;
// Relationships // Relationships
protected $_has_one = array( protected $_has_one = array(
'service_billing'=>array('far_key'=>'account_billing_id','foreign_key'=>'id'), 'service_billing'=>array('far_key'=>'account_billing_id','foreign_key'=>'id'),
@ -79,11 +81,41 @@ class Model_Service extends ORM_OSB {
'price_override', 'price_override',
); );
protected $_form = array('id'=>'id','value'=>'service_name()'); protected $_form = array('id'=>'id','value'=>'name()');
// Cache our calls to our plugins // Cache our calls to our plugins
public static $plugin = array(); 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 * Get the additional charges associated with this service
*/ */
@ -200,13 +232,6 @@ class Model_Service extends ORM_OSB {
->order_by('date_stop','DESC'); ->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 * 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 $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 * Return the service charge
*/ */
@ -323,7 +341,7 @@ class Model_Service extends ORM_OSB {
/** /**
* Search for services matching a term * 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. // We only show service numbers.
if (! is_numeric($term) AND (! $limit)) if (! is_numeric($term) AND (! $limit))
return array(); return array();
@ -364,7 +382,7 @@ class Model_Service extends ORM_OSB {
if ($so->product->prod_plugin_file == $cat) if ($so->product->prod_plugin_file == $cat)
array_push($result,$so); array_push($result,$so);
Sort::MASort($result,'service_name()'); Sort::MASort($result,array('name()'));
return $result; return $result;
} }

View File

@ -0,0 +1,19 @@
<!-- o = Array of Model_Service -->
<?php echo Table::factory()
->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/')),
));
?>

View File

@ -4,7 +4,7 @@
->data($o) ->data($o)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'service_name()'=>'Service', 'name()'=>'Service',
'recur_schedule'=>'Billing', 'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price', 'price(TRUE,TRUE)'=>'Price',
'charges(TRUE,TRUE)'=>'Charges', 'charges(TRUE,TRUE)'=>'Charges',

View File

@ -0,0 +1,15 @@
<!-- o = Array of Model_Service -->
<?php echo Table::factory()
->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/')),
));
?>

View File

@ -3,7 +3,7 @@
->data($o) ->data($o)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'service_name()'=>'Service', 'name()'=>'Service',
)) ))
->prepend(array( ->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')), 'id'=>array('url'=>URL::link('user','service/view/')),

View File

@ -3,10 +3,13 @@
->data($o) ->data($o)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'service_name(59)'=>'Service', 'name()'=>'Service',
'expire(TRUE)'=>'Date', 'expire(TRUE)'=>'Date',
)) ))
->prepend(array( ->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')), 'id'=>array('url'=>URL::link('user','service/view/')),
))
->postproc(array(
'name()'=>array('trim'=>60),
)); ));
?> ?>

View File

@ -3,10 +3,13 @@
->data($o) ->data($o)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'service_name(60)'=>'Service', 'name()'=>'Service',
'date_end'=>'Date', 'date_end'=>'Date',
)) ))
->prepend(array( ->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')), 'id'=>array('url'=>URL::link('user','service/view/')),
))
->postproc(array(
'name()'=>array('trim'=>60),
)); ));
?> ?>

View File

@ -39,7 +39,7 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
return $this->_so->get_valid_to($format); 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'); return ($this->cert AND $this->ca->loaded()) ? sprintf('%s:%s',$this->ca->subject(),$this->display('cert')) : $this->display('csr');
} }

View File

@ -70,7 +70,7 @@ class Controller_Reseller_Statement extends Controller_Statement {
krsort($result); krsort($result);
Block::factory() 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') ->title_icon('icon-tasks')
->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total));
} }

View File

@ -48,7 +48,7 @@ class Controller_User_Statement extends Controller_Statement {
krsort($result); krsort($result);
Block::factory() 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') ->title_icon('icon-tasks')
->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total));
} }