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

@@ -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'));

View File

@@ -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();

View File

@@ -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)