diff --git a/application/classes/lnapp/table.php b/application/classes/lnapp/table.php index eac4afa3..924014d8 100644 --- a/application/classes/lnapp/table.php +++ b/application/classes/lnapp/table.php @@ -146,6 +146,12 @@ $(document).ready(function() { }); } }); + + // Double click to select a row + $("#select-table tr:not(.head)") + .dblclick(function(e) { + window.location = $("a", this).attr("href"); + }); }); ')); diff --git a/modules/product/classes/model/product/plugin/adsl.php b/modules/adsl/classes/model/product/plugin/adsl.php similarity index 100% rename from modules/product/classes/model/product/plugin/adsl.php rename to modules/adsl/classes/model/product/plugin/adsl.php diff --git a/modules/product/views/product/plugin/adsl/feature_summary.php b/modules/adsl/views/product/plugin/adsl/feature_summary.php similarity index 100% rename from modules/product/views/product/plugin/adsl/feature_summary.php rename to modules/adsl/views/product/plugin/adsl/feature_summary.php diff --git a/modules/product/classes/model/product/plugin/domain.php b/modules/domain/classes/model/product/plugin/domain.php similarity index 100% rename from modules/product/classes/model/product/plugin/domain.php rename to modules/domain/classes/model/product/plugin/domain.php diff --git a/modules/product/classes/model/product/plugin/host.php b/modules/host/classes/model/product/plugin/host.php similarity index 100% rename from modules/product/classes/model/product/plugin/host.php rename to modules/host/classes/model/product/plugin/host.php diff --git a/modules/invoice/classes/controller/admin/invoice.php b/modules/invoice/classes/controller/admin/invoice.php index 2100cc72..e1342772 100644 --- a/modules/invoice/classes/controller/admin/invoice.php +++ b/modules/invoice/classes/controller/admin/invoice.php @@ -19,12 +19,10 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin { * Show a list of invoices */ public function action_list() { - $io = ORM::factory('invoice'); - Block::add(array( 'title'=>_('System Customer Invoices'), 'body'=>Table::display( - $io->find_all(), + ORM::factory('invoice')->find_all(), 25, array( 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), @@ -43,12 +41,5 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin { )), )); } - - public function action_convert() { - if (Config::sitemode() != KOHANA::DEVELOPMENT) - throw new Kohana_Exception(__METHOD__.' can only be run in development'); - else - throw new Kohana_Exception(__METHOD__.' can be run in development'); - } } ?> diff --git a/modules/invoice/classes/model/invoice.php b/modules/invoice/classes/model/invoice.php index fd23a7ab..f588400f 100644 --- a/modules/invoice/classes/model/invoice.php +++ b/modules/invoice/classes/model/invoice.php @@ -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; } diff --git a/modules/invoice/classes/model/invoice/item.php b/modules/invoice/classes/model/invoice/item.php index a6aa87b5..55cd8a32 100644 --- a/modules/invoice/classes/model/invoice/item.php +++ b/modules/invoice/classes/model/invoice/item.php @@ -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 diff --git a/modules/invoice/views/invoice/user/view.php b/modules/invoice/views/invoice/user/view.php index 2b4b0914..b4126e3b 100644 --- a/modules/invoice/views/invoice/user/view.php +++ b/modules/invoice/views/invoice/user/view.php @@ -70,7 +70,7 @@