Updated charge, Invoice improvements and other minor fixes
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* Column Definitions:
|
||||
* + item_type: 0=MAIN Service Item,2=?,3=?,4=Connection/Setup,5=Excess Service Item,6=Change Service,126=Payment Fee,127=Late Fee
|
||||
*/
|
||||
class Model_Invoice_Item extends ORM_OSB implements Invoicable {
|
||||
class Model_Invoice_Item extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
@@ -38,11 +38,21 @@ class Model_Invoice_Item extends ORM_OSB implements Invoicable {
|
||||
),
|
||||
);
|
||||
|
||||
// Items belonging to an invoice
|
||||
private $subitems = array();
|
||||
private $subitems_loaded = FALSE;
|
||||
// Items belonging to an invoice item
|
||||
protected $_sub_items_load = array(
|
||||
'invoice_item_tax'=>FALSE,
|
||||
);
|
||||
|
||||
/**
|
||||
* The title for invoice items
|
||||
*/
|
||||
public function title() {
|
||||
if ($this->product_id AND $this->service_id)
|
||||
return $this->product_id ? sprintf('%s: %s',$this->product->title(),$this->service->name()) : $this->service->name;
|
||||
else
|
||||
return 'Unknown Item';
|
||||
}
|
||||
|
||||
/** INTERFACE REQUIREMENTS **/
|
||||
public function invoice_line() {
|
||||
if ($this->charge_id)
|
||||
return $this->charge->description.' '.$this->period();
|
||||
@@ -52,23 +62,6 @@ class Model_Invoice_Item extends ORM_OSB implements Invoicable {
|
||||
throw HTTP_Exception::factory(501,'Unable to render invoice item :id',array(':id'=>$this->id));
|
||||
}
|
||||
|
||||
public function __construct($id = NULL) {
|
||||
// Load our model.
|
||||
parent::__construct($id);
|
||||
|
||||
return $this->load_sub_items();
|
||||
}
|
||||
|
||||
private function load_sub_items() {
|
||||
// Load our sub items
|
||||
if (! $this->subitems_loaded AND $this->loaded()) {
|
||||
$this->subitems['tax'] = $this->invoice_item_tax->find_all()->as_array();
|
||||
$this->subitems_loaded = TRUE;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Display a transaction number
|
||||
public function trannum() {
|
||||
return sprintf('%03s-%06s',$this->item_type,$this->id);
|
||||
@@ -125,7 +118,7 @@ class Model_Invoice_Item extends ORM_OSB implements Invoicable {
|
||||
}
|
||||
|
||||
public function total($format=FALSE) {
|
||||
$result = Currency::round($this->subtotal()+$this->tax()-$this->discount());
|
||||
$result = $this->void ? 0 : Currency::round($this->subtotal()+$this->tax()-$this->discount());
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
@@ -205,9 +198,9 @@ class Model_Invoice_Item extends ORM_OSB implements Invoicable {
|
||||
if ($this->saved()) {
|
||||
$iito = ORM::factory('Invoice_Item_Tax');
|
||||
|
||||
if ($this->subitems_loaded) {
|
||||
if ($this->_sub_items) {
|
||||
foreach (array('tax') as $i)
|
||||
foreach ($this->subitems[$i] as $io)
|
||||
foreach ($this->_sub_items[$i] as $io)
|
||||
if ($io->changed())
|
||||
$io->save();
|
||||
|
||||
|
Reference in New Issue
Block a user