Minor work on ADSL/Domain/Hosting and other minor fixes
This commit is contained in:
@@ -18,7 +18,7 @@ class Model_Invoice extends ORMOSB {
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'invoice_item'=>array('far_key'=>'id'),
|
||||
'invoice_item_tax'=>array(),
|
||||
'invoice_item_tax'=>array('through'=>'invoice_item'),
|
||||
'service'=>array('through'=>'invoice_item'),
|
||||
'payment'=>array('through'=>'payment_item'),
|
||||
'payment_item'=>array('far_key'=>'id'),
|
||||
@@ -112,7 +112,11 @@ class Model_Invoice extends ORMOSB {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->items() as $ito)
|
||||
$result += $ito->tax_amt;
|
||||
$result += $ito->tax();
|
||||
|
||||
// @todo This should eventually be removed.
|
||||
if (! $result AND $this->tax_amt)
|
||||
$result = $this->tax_amt;
|
||||
|
||||
return $format ? Currency::display($result) : $result;
|
||||
}
|
||||
@@ -188,7 +192,7 @@ class Model_Invoice extends ORMOSB {
|
||||
*
|
||||
* @param int Service ID
|
||||
*/
|
||||
private function items_service($sid) {
|
||||
private function list_items_service($sid) {
|
||||
return $this->invoice_item->where('service_id','=',$sid)->find_all();
|
||||
}
|
||||
|
||||
@@ -198,7 +202,7 @@ class Model_Invoice extends ORMOSB {
|
||||
public function items_service_total($sid) {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->items_service($sid) as $ito)
|
||||
foreach ($this->list_items_service($sid) as $ito)
|
||||
$total += $ito->total();
|
||||
|
||||
return $total;
|
||||
@@ -206,16 +210,19 @@ class Model_Invoice extends ORMOSB {
|
||||
|
||||
/**
|
||||
* Calculate the tax of items for a service
|
||||
* @todo This can be optimised
|
||||
*/
|
||||
public function items_service_tax($sid) {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->items_service($sid) as $ito)
|
||||
foreach ($this->list_items_service($sid) as $ito)
|
||||
$total += $ito->tax_amt;
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
// @todo Add discounts
|
||||
|
||||
/**
|
||||
* Return a list of items based on a sort criteria
|
||||
*/
|
||||
@@ -242,6 +249,7 @@ class Model_Invoice extends ORMOSB {
|
||||
|
||||
/**
|
||||
* Return a list of taxes used on this invoice
|
||||
* @todo Move some of this to invoice_item_tax.
|
||||
*/
|
||||
public function tax_summary() {
|
||||
$summary = array();
|
||||
@@ -255,6 +263,10 @@ class Model_Invoice extends ORMOSB {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo This should be removed eventually
|
||||
if (! $summary AND $this->tax_amt)
|
||||
$summary[1] = $this->tax_amt;
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,9 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice_Item extends ORMOSB {
|
||||
protected $_updated_column = FALSE; // @todo No update columns
|
||||
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
'invoice'=>array(),
|
||||
@@ -19,7 +22,16 @@ class Model_Invoice_Item extends ORMOSB {
|
||||
protected $_has_many = array(
|
||||
'invoice_item_tax'=>array('far_key'=>'id')
|
||||
);
|
||||
protected $_updated_column = FALSE; // @todo No update columns
|
||||
|
||||
protected $_display_filters = array(
|
||||
'date_start'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'date_stop'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// Display a transaction number
|
||||
public function trannum() {
|
||||
@@ -35,6 +47,31 @@ class Model_Invoice_Item extends ORMOSB {
|
||||
return sprintf('%s -> %s',Config::date($this->date_start),Config::date($this->date_stop));
|
||||
}
|
||||
|
||||
// Sum up the tax that applies to this invoice item
|
||||
public function tax() {
|
||||
$amount = 0;
|
||||
|
||||
foreach ($this->invoice_item_tax->find_all() as $iit)
|
||||
$amount += $iit->amount;
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
// This total of this item before discounts and taxes
|
||||
public function subtotal() {
|
||||
return ($this->price_base)*$this->quantity;
|
||||
}
|
||||
|
||||
// The total of all discounts
|
||||
public function discount() {
|
||||
return $this->discount_amt;
|
||||
}
|
||||
|
||||
public function total() {
|
||||
// @todo This rounding should be a system config
|
||||
return round($this->subtotal()+$this->tax()-$this->discount(),2);
|
||||
}
|
||||
|
||||
public function invoice_detail_items() {
|
||||
if ($this->item_type != 0)
|
||||
return;
|
||||
@@ -42,14 +79,6 @@ class Model_Invoice_Item extends ORMOSB {
|
||||
return $this->service->details('invoice_detail_items');
|
||||
}
|
||||
|
||||
public function subtotal() {
|
||||
return ($this->price_base+$this->price_setup)*$this->quantity;
|
||||
}
|
||||
|
||||
public function total() {
|
||||
return ($this->price_base+$this->price_setup)*$this->quantity+$this->tax_amt-$this->discount_amt;
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Save the invoice item
|
||||
parent::save();
|
||||
@@ -80,8 +109,6 @@ class Model_Invoice_Item extends ORMOSB {
|
||||
// Save DISCOUNT details
|
||||
// @todo calculate discounts
|
||||
|
||||
$this->tax_amt = $tax_total;
|
||||
$this->total_amt = $this->total();
|
||||
parent::save();
|
||||
|
||||
} else
|
||||
|
Reference in New Issue
Block a user