Removed redundant functions, some Standardisation work
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice_Item extends ORM_OSB {
|
||||
class Model_Invoice_Item extends ORM {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'invoice'=>array(),
|
||||
@@ -66,51 +66,6 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
|
||||
/** REQUIRED ABSTRACT METHODS **/
|
||||
|
||||
public function name($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return sprintf('%s: %s',$this->product->name($variable),$this->service->namesub($variable));
|
||||
case 124:
|
||||
return StaticList_ItemType::get($this->item_type);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function namesub($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->period());
|
||||
case 2:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->_module() ? $this->_module()->display('date_charge') : $this->period());
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),($this->_module()->attributes ? $this->_module()->namesub($variable) : $this->_module()->display('date_charge')));
|
||||
case 5:
|
||||
return $this->_module()->namesub($variable);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Invoice Item Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return $short ? '' : sprintf('%03s-',$this->item_type).sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
/** LOCAL METHODS **/
|
||||
|
||||
/**
|
||||
@@ -185,6 +140,7 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 7:
|
||||
if (! $this->service_id OR ! $this->product_id OR ! $this->module_id OR ! $this->module_ref OR $this->product_name OR ! is_null($this->recurring_schedule))
|
||||
return FALSE;
|
||||
break;
|
||||
@@ -210,11 +166,57 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
return $this->_module();
|
||||
}
|
||||
|
||||
public function name($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return sprintf('%s: %s',$this->product->name($variable),$this->service->namesub($variable));
|
||||
case 124:
|
||||
return StaticList_ItemType::get($this->item_type);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function namesub($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->period());
|
||||
case 2:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->_module() ? $this->_module()->display('date_charge') : $this->period());
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),($this->_module()->attributes ? $this->_module()->namesub($variable) : $this->_module()->display('date_charge')));
|
||||
case 5:
|
||||
case 7:
|
||||
return $this->_module()->namesub($variable);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Display the period that a transaction applies
|
||||
public function period() {
|
||||
return ($this->date_start == $this->date_stop) ? Site::Date($this->date_start) : sprintf('%s -> %s',Site::Date($this->date_start),Site::Date($this->date_stop));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Invoice Item Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return $short ? '' : sprintf('%03s-',$this->item_type).sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Our items will be clobbered once we save the object, so we need to save it here.
|
||||
$subitems = $this->subitems();
|
||||
@@ -276,20 +278,6 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title for invoice items
|
||||
*/
|
||||
public function title() {
|
||||
if ($this->service_id AND $this->module_id AND method_exists($this->module(),'invoice_title'))
|
||||
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)
|
||||
return sprintf('* %s: %s',$this->product->invoice_title(),$this->service->name());
|
||||
else
|
||||
return 'Unknown Item';
|
||||
}
|
||||
|
||||
public function total($format=FALSE) {
|
||||
$result = $this->void ? 0 : $this->subtotal()+$this->tax()-$this->discount();
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice_Memo extends ORM_OSB {
|
||||
class Model_Invoice_Memo extends ORM {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'invoice'=>array(),
|
||||
|
Reference in New Issue
Block a user