From 06cbec3a94da5991bad0f58063a7c86af6313f92 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 6 Feb 2014 11:03:25 +1100 Subject: [PATCH] Update to statements and other minor items --- .../classes/Controller/Reseller/Account.php | 2 +- application/classes/Model/Account.php | 2 + application/classes/ORM.php | 17 ++++ application/classes/ORM/OSB.php | 17 ---- application/views/userguide/template.php | 12 +-- .../classes/Model/Checkout/Notify.php | 2 +- .../Controller/Admin/Service/Domain.php | 1 + modules/invoice/classes/Model/Invoice.php | 3 + modules/service/views/service/admin/add.php | 2 +- modules/service/views/service/user/view.php | 3 +- .../classes/Controller/Admin/Statement.php | 87 ------------------- .../classes/Controller/Reseller/Statement.php | 76 ++++++++++++++++ .../classes/Controller/User/Statement.php | 77 +++++----------- .../views/statement/user/show/body.php | 14 --- .../views/statement/user/show/foot.php | 1 - .../views/statement/user/show/head.php | 7 -- 16 files changed, 134 insertions(+), 189 deletions(-) delete mode 100644 modules/statement/classes/Controller/Admin/Statement.php create mode 100644 modules/statement/classes/Controller/Reseller/Statement.php delete mode 100644 modules/statement/views/statement/user/show/body.php delete mode 100644 modules/statement/views/statement/user/show/foot.php delete mode 100644 modules/statement/views/statement/user/show/head.php diff --git a/application/classes/Controller/Reseller/Account.php b/application/classes/Controller/Reseller/Account.php index 2fb1b48c..07a2638e 100644 --- a/application/classes/Controller/Reseller/Account.php +++ b/application/classes/Controller/Reseller/Account.php @@ -117,7 +117,7 @@ class Controller_Reseller_Account extends Controller_Account { $i = Invoice::instance(); foreach ($ao->service->list_active() as $io) - if (! $io->suspend_billing) + if (! $io->suspend_billing AND ! $io->external_billing) $i->add_service($io); Block::factory() diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index b102640b..ce81b72c 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -40,6 +40,8 @@ class Model_Account extends Model_Auth_UserDefault { ), ); + protected $_form = array('id'=>'id','value'=>'name(TRUE)'); + protected $_save_message = TRUE; /** diff --git a/application/classes/ORM.php b/application/classes/ORM.php index 42bfd483..36a0b8f5 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -209,6 +209,23 @@ abstract class ORM extends Kohana_ORM { return $result; } + /** + * Return an array of data that can be used in a SELECT statement. + * The ID and VALUE is defined in the model for the select. + */ + public function list_select($blank=FALSE) { + $result = array(); + + if ($blank) + $result[] = ''; + + if ($this->_form AND array_intersect(array('id','value'),$this->_form)) + foreach ($this->find_all() as $o) + $result[$o->{$this->_form['id']}] = $o->resolve($this->_form['value']); + + return $result; + } + /** * This function is used so that methods can be called via variables */ diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php index 1043951a..9e94ce45 100644 --- a/application/classes/ORM/OSB.php +++ b/application/classes/ORM/OSB.php @@ -283,22 +283,5 @@ abstract class ORM_OSB extends ORM { return $x->find_all()->count(); } - - /** - * Return an array of data that can be used in a SELECT statement. - * The ID and VALUE is defined in the model for the select. - */ - public function list_select($blank=FALSE) { - $result = array(); - - if ($blank) - $result[] = ''; - - if ($this->_form AND array_intersect(array('id','value'),$this->_form)) - foreach ($this->find_all() as $o) - $result[$o->{$this->_form['id']}] = $o->resolve($this->_form['value']); - - return $result; - } } ?> diff --git a/application/views/userguide/template.php b/application/views/userguide/template.php index 454a31a7..ea27ba48 100644 --- a/application/views/userguide/template.php +++ b/application/views/userguide/template.php @@ -1,9 +1,9 @@ - + -<?php echo $title ?> | Kohana <?php echo __('User Guide'); ?> +<?php echo $title ?> | Kohana User Guide $media) echo HTML::style($style, array('media' => $media), NULL, TRUE), "\n" ?> @@ -17,17 +17,17 @@
-
@@ -67,7 +67,7 @@ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); - + Documentation comments powered by Disqus
diff --git a/modules/checkout/classes/Model/Checkout/Notify.php b/modules/checkout/classes/Model/Checkout/Notify.php index ca8ec6a4..9d284d27 100644 --- a/modules/checkout/classes/Model/Checkout/Notify.php +++ b/modules/checkout/classes/Model/Checkout/Notify.php @@ -21,7 +21,7 @@ class Model_Checkout_Notify extends ORM_OSB implements Invoicable { ), ); - public function invoice_item() { + public function invoice_item($item_type) { return sprintf('Payment Fee: %s',$this->checkout->name); } diff --git a/modules/domain/classes/Controller/Admin/Service/Domain.php b/modules/domain/classes/Controller/Admin/Service/Domain.php index fed2bf27..cec24d64 100644 --- a/modules/domain/classes/Controller/Admin/Service/Domain.php +++ b/modules/domain/classes/Controller/Admin/Service/Domain.php @@ -26,6 +26,7 @@ class Controller_Admin_Service_Domain extends Controller_Domain { 'name()'=>'Domain', 'status'=>'Active', 'suspend_billing'=>'Not Bill', + 'external_billing'=>'Ext Bill', 'plugin()->display("domain_expire")'=>'Expire', 'recur_schedule'=>'Billing', 'price(TRUE,TRUE)'=>'Charge', diff --git a/modules/invoice/classes/Model/Invoice.php b/modules/invoice/classes/Model/Invoice.php index 362961eb..9dd18865 100644 --- a/modules/invoice/classes/Model/Invoice.php +++ b/modules/invoice/classes/Model/Invoice.php @@ -36,6 +36,9 @@ class Model_Invoice extends ORM_OSB implements Cartable { 'status'=>array( array('StaticList_YesNo::get',array(':value',TRUE)), ), + 'void'=>array( + array('StaticList_YesNo::get',array(':value',TRUE)), + ), ); // Items belonging to an invoice diff --git a/modules/service/views/service/admin/add.php b/modules/service/views/service/admin/add.php index acf31120..91de3203 100644 --- a/modules/service/views/service/admin/add.php +++ b/modules/service/views/service/admin/add.php @@ -36,7 +36,7 @@
- where_active()->list_select(TRUE),NULL,array('label'=>'Product','class'=>'span4','sort'=>TRUE)); ?> + list_select(TRUE),NULL,array('label'=>'Product','class'=>'span4','sort'=>TRUE)); ?>
diff --git a/modules/service/views/service/user/view.php b/modules/service/views/service/user/view.php index 7edde18b..3e33d91d 100644 --- a/modules/service/views/service/user/view.php +++ b/modules/service/views/service/user/view.php @@ -95,9 +95,10 @@ ->data($o->invoice_list()) ->columns(array( 'id'=>'ID', + 'void'=>'Void', 'date_orig'=>'Date', 'due_date'=>'Due', - 'total(TRUE)'=>'Amount', + 'total(TRUE)'=>'Amount', 'due(TRUE)'=>'Due', )) ->prepend(array( diff --git a/modules/statement/classes/Controller/Admin/Statement.php b/modules/statement/classes/Controller/Admin/Statement.php deleted file mode 100644 index ceedf8b2..00000000 --- a/modules/statement/classes/Controller/Admin/Statement.php +++ /dev/null @@ -1,87 +0,0 @@ -TRUE, - ); - - /** - * Show a payments received - */ - public function action_show() { - $ao = ORM::factory('account',$this->request->param('id')); - $ta = array(); - - foreach ($ao->payment->find_all() as $o) { - if ( ! $o->total()) - continue; - - $i = count($ta); - $ta[$i]['time'] = $o->date_payment; - $ta[$i]['payment'] = $o; - } - - foreach ($ao->invoice->list_active() as $o) { - $i = count($ta); - $ta[$i]['time'] = $o->date_orig; - $ta[$i]['invoice'] = $o; - } - - Sort::MAsort($ta,'time'); - - $t = 0; - $a = 0; - foreach ($ta as $k => $v) { - // If 2 metrics have the same time, we need to increment 1 by a small number so that it doesnt affect the next sorting - if ($a == $v['time']) { - $ta[$k]['time'] += 1; - } - - if (isset($v['invoice'])) - $t += $v['invoice']->total(); - elseif (isset($v['payment'])) - $t -= $v['payment']->total(); - - $ta[$k]['total'] = $t; - $a = $v['time']; - } - - Sort::MAsort($ta,'time',1); - - $pag = new Pagination(array( - 'total_items'=>count($ta), - )); - - $output = (string)$pag; - $output .= View::factory('statement/user/show'.'/head'); - - $i = 0; - foreach ($ta as $k => $v) { - if (++$i < $pag->current_first_item()) - continue; - elseif ($i > $pag->current_last_item()) - break; - - $output .= View::factory('statement/user/show/'.'/body') - ->set('o',$v) - ->set('trc',$i%2 ? 'odd' : 'even'); - } - - $output .= View::factory('statement/user/show/'.'/foot'); - - Block::add(array( - 'title'=>sprintf('%s: %s - %s',_('Transactions For'),$ao->accnum(),$ao->name(TRUE)), - 'body'=>$output, - )); - } -} -?> diff --git a/modules/statement/classes/Controller/Reseller/Statement.php b/modules/statement/classes/Controller/Reseller/Statement.php new file mode 100644 index 00000000..acfbeafe --- /dev/null +++ b/modules/statement/classes/Controller/Reseller/Statement.php @@ -0,0 +1,76 @@ +TRUE, + 'show'=>TRUE, + ); + + public function action_index() { + if ($x=$this->request->post('aid')) + HTTP::redirect(URL::link('reseller','statement/show/'.$x)); + + $output = Form::open(); + $output .= Form::select('aid',ORM::factory('Account')->where_authorised(Auth::instance()->get_user(),'id') + ->order_by('company','ASC')->order_by('last_name','ASC')->order_by('first_name','ASC')->list_select()); + $output .= Form::button('submit','Submit',array('class'=>'btn btn-primary')); + $output .= Form::close(); + + Block::factory() + ->title('Select Account') + ->title_icon('icon-share') + ->body($output); + } + + /** + * Show a payments received + */ + public function action_show() { + $ao = ORM::factory('account',$this->request->param('id')); + + if (! $ao->loaded() OR ! Auth::instance()->authorised($ao)) + throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); + + $result = array(); + $total = 0; + + foreach ($ao->payment->find_all() as $o) { + $key = $o->date_payment; + + while (isset($result[$key])) + $key += 1; + + $result[$key] = $o; + + $total += Currency::round($o->total()); + } + + foreach ($ao->invoice->list_active() as $o) { + $key = $o->date_orig; + + while (isset($result[$key])) + $key += 1; + + $result[$key] = $o; + + $total -= Currency::round($o->total()); + } + + krsort($result); + + Block::factory() + ->title(sprintf('%s: %s - %s',_('Transactions For'),$ao->accnum(),$ao->name(TRUE))) + ->title_icon('icon-tasks') + ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); + } +} +?> diff --git a/modules/statement/classes/Controller/User/Statement.php b/modules/statement/classes/Controller/User/Statement.php index 09d43e00..285600d6 100644 --- a/modules/statement/classes/Controller/User/Statement.php +++ b/modules/statement/classes/Controller/User/Statement.php @@ -9,7 +9,7 @@ * @copyright (c) 2009-2013 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Controller_User_Statement extends Controller_TemplateDefault_User { +class Controller_User_Statement extends Controller_Statement { protected $secure_actions = array( 'show'=>TRUE, ); @@ -18,66 +18,37 @@ class Controller_User_Statement extends Controller_TemplateDefault_User { * Show a payments received */ public function action_show() { - $ta = array(); + $result = array(); + $total = 0; foreach ($this->ao->payment->find_all() as $o) { - $i = count($ta); - $ta[$i]['time'] = $o->date_payment; - $ta[$i]['payment'] = $o; + $key = $o->date_payment; + + while (isset($result[$key])) + $key += 1; + + $result[$key] = $o; + + $total += Currency::round($o->total()); } foreach ($this->ao->invoice->list_active() as $o) { - $i = count($ta); - $ta[$i]['time'] = $o->date_orig; - $ta[$i]['invoice'] = $o; + $key = $o->date_orig; + + while (isset($result[$key])) + $key += 1; + + $result[$key] = $o; + + $total -= Currency::round($o->total()); } - Sort::MAsort($ta,'time'); + krsort($result); - $t = 0; - $a = 0; - foreach ($ta as $k => $v) { - // If 2 metrics have the same time, we need to increment 1 by a small number so that it doesnt affect the next sorting - if ($a == $v['time']) { - $ta[$k]['time'] += 1; - } - - if (isset($v['invoice'])) - $t += $v['invoice']->total(); - elseif (isset($v['payment'])) - $t -= $v['payment']->total(); - - $ta[$k]['total'] = $t; - $a = $v['time']; - } - - Sort::MAsort($ta,'time',1); - - $pag = new Pagination(array( - 'total_items'=>count($ta), - )); - - $output = (string)$pag; - $output .= View::factory($this->viewpath().'/head'); - - $i = 0; - foreach ($ta as $k => $v) { - if (++$i < $pag->current_first_item()) - continue; - elseif ($i > $pag->current_last_item()) - break; - - $output .= View::factory($this->viewpath().'/body') - ->set('o',$v) - ->set('trc',$i%2 ? 'odd' : 'even'); - } - - $output .= View::factory($this->viewpath().'/foot'); - - Block::add(array( - 'title'=>sprintf('%s: %s - %s',_('Transactions For'),$this->ao->accnum(),$this->ao->name(TRUE)), - 'body'=>$output, - )); + Block::factory() + ->title(sprintf('%s: %s - %s',_('Transactions For'),$this->ao->accnum(),$this->ao->name(TRUE))) + ->title_icon('icon-tasks') + ->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total)); } } ?> diff --git a/modules/statement/views/statement/user/show/body.php b/modules/statement/views/statement/user/show/body.php deleted file mode 100644 index 70b76908..00000000 --- a/modules/statement/views/statement/user/show/body.php +++ /dev/null @@ -1,14 +0,0 @@ - - - display('date_orig'); ?> - Invoice - id),$o['invoice']->id()); ?> - total(TRUE); ?> - - display('date_payment'); ?> - Payment - id,$o['payment']->checkout->display('name')); ?> - total(TRUE); ?> - - - diff --git a/modules/statement/views/statement/user/show/foot.php b/modules/statement/views/statement/user/show/foot.php deleted file mode 100644 index 000ca4b0..00000000 --- a/modules/statement/views/statement/user/show/foot.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/statement/views/statement/user/show/head.php b/modules/statement/views/statement/user/show/head.php deleted file mode 100644 index 8956570f..00000000 --- a/modules/statement/views/statement/user/show/head.php +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - -
DateTypeAmtTotal