Improvements to invoice

This commit is contained in:
Deon George
2013-06-13 23:35:19 +10:00
parent 25a47cac3a
commit 6875dc3693
15 changed files with 321 additions and 200 deletions

View File

@@ -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_OSB implements Invoicable {
// Relationships
protected $_belongs_to = array(
'product'=>array(),
@@ -39,6 +39,16 @@ class Model_Invoice_Item extends ORM_OSB {
private $subitems = array();
private $subitems_loaded = FALSE;
/** INTERFACE REQUIREMENTS **/
public function invoice_line() {
if ($this->charge_id)
return $this->charge->description.' '.$this->period();
elseif ($this->service_id)
return 'Service '.$this->period();
else
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);
@@ -71,7 +81,7 @@ class Model_Invoice_Item extends ORM_OSB {
}
// Sum up the tax that applies to this invoice item
public function tax() {
public function tax($format=FALSE) {
$result = 0;
foreach ($this->invoice_item_tax->find_all() as $iit)
@@ -81,7 +91,9 @@ class Model_Invoice_Item extends ORM_OSB {
if (! $result)
$result += round($this->price_base*$this->quantity*.1,2);
return Currency::round($result);
$result = Currency::round($result);
return $format ? Currency::display($result) : $result;
}
public function tax_items() {
@@ -98,8 +110,10 @@ class Model_Invoice_Item extends ORM_OSB {
}
// This total of this item before discounts and taxes
public function subtotal() {
return Currency::round($this->price_base*$this->quantity);
public function subtotal($format=FALSE) {
$result = Currency::round($this->price_base*$this->quantity);
return $format ? Currency::display($result) : $result;
}
// The total of all discounts
@@ -107,8 +121,10 @@ class Model_Invoice_Item extends ORM_OSB {
return Currency::round($this->discount_amt);
}
public function total() {
return Currency::round($this->subtotal()+$this->tax()-$this->discount());
public function total($format=FALSE) {
$result = Currency::round($this->subtotal()+$this->tax()-$this->discount());
return $format ? Currency::display($result) : $result;
}
/**