From 50a096e22aab5383b3d058ef16202faabe528536 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 11 Oct 2011 10:38:21 +1100 Subject: [PATCH] Minor work on ADSL/Domain/Hosting and other minor fixes --- application/classes/lnapp/table.php | 6 +++ .../classes/model/product/plugin/adsl.php | 0 .../product/plugin/adsl/feature_summary.php | 0 .../classes/model/product/plugin/domain.php | 0 .../classes/model/product/plugin/host.php | 0 .../classes/controller/admin/invoice.php | 11 +---- modules/invoice/classes/model/invoice.php | 22 +++++++-- .../invoice/classes/model/invoice/item.php | 49 ++++++++++++++----- modules/invoice/views/invoice/user/view.php | 4 +- modules/product/classes/model/product.php | 4 ++ .../classes/controller/admin/service.php | 28 +++++++++++ modules/service/classes/model/service.php | 14 ++++++ 12 files changed, 110 insertions(+), 28 deletions(-) rename modules/{product => adsl}/classes/model/product/plugin/adsl.php (100%) rename modules/{product => adsl}/views/product/plugin/adsl/feature_summary.php (100%) rename modules/{product => domain}/classes/model/product/plugin/domain.php (100%) rename modules/{product => host}/classes/model/product/plugin/host.php (100%) 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 @@ service->id,$item->service->id()); ?> - product->product_translate->find()->name; ?> (product_id; ?>) + product_name ? $item->product_name : $item->product->product_translate->find()->name; ?> (product_id; ?>) items_service_total($item->service_id));?> @@ -109,7 +109,7 @@   - items_service_tax($item->service_id));?> + tax(TRUE);?> diff --git a/modules/product/classes/model/product.php b/modules/product/classes/model/product.php index 6490dfb0..0ba9c0aa 100644 --- a/modules/product/classes/model/product.php +++ b/modules/product/classes/model/product.php @@ -23,6 +23,9 @@ class Model_Product extends ORMOSB { ); protected $_display_filters = array( + 'active'=>array( + array('StaticList_YesNo::display',array(':value')), + ), 'price_type'=>array( array('StaticList_PriceType::display',array(':value')), ), @@ -43,6 +46,7 @@ class Model_Product extends ORMOSB { /** * Get the product name, after translating + * @todo This needs to be improved to find the right language item. */ public function name() { return $this->product_translate->find()->display('name'); diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php index 67adf01b..fe996b83 100644 --- a/modules/service/classes/controller/admin/service.php +++ b/modules/service/classes/controller/admin/service.php @@ -19,6 +19,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { 'listdomainservices'=>TRUE, 'listhostservices'=>TRUE, 'listhspaservices'=>TRUE, + 'listinvoicesoon'=>TRUE, 'update'=>TRUE, ); @@ -434,6 +435,33 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name return $return; } + /** + * List services that need to be invoiced. + */ + public function action_listinvoicesoon() { + Block::add(array( + 'title'=>_('Services to Invoice'), + 'body'=>Table::display( + ORM::factory('service')->list_invoicesoon(), + 25, + array( + 'id'=>array('label'=>'ID','url'=>'user/service/view/'), + 'service_name()'=>array('label'=>'Details'), + 'recur_schedule'=>array('label'=>'Billing'), + 'date_next_invoice'=>array('label'=>'Next Invoice'), + 'price'=>array('label'=>'Price','class'=>'right'), + 'active'=>array('label'=>'Active'), + 'account->accnum()'=>array('label'=>'Cust ID'), + 'account->name()'=>array('label'=>'Customer'), + ), + array( + 'page'=>TRUE, + 'type'=>'select', + 'form'=>'user/service/view', + )), + )); + } + public function action_update($id) { $so = ORM::factory('service',$id); diff --git a/modules/service/classes/model/service.php b/modules/service/classes/model/service.php index 11ee7e9f..216bf505 100644 --- a/modules/service/classes/model/service.php +++ b/modules/service/classes/model/service.php @@ -163,5 +163,19 @@ class Model_Service extends ORMOSB { return $result; } + + /** + * List services that need to be billed. + */ + public function list_invoicesoon() { + $result = array(); + + foreach ($this->list_active() as $so) + // @todo This should be configurable + if (! $so->suspend_billing AND $so->date_next_invoice < time()+35*86400) + array_push($result,$so); + + return $result; + } } ?>