Update to statements and other minor items

This commit is contained in:
Deon George 2014-02-06 11:03:25 +11:00
parent ae98efa84e
commit 06cbec3a94
16 changed files with 134 additions and 189 deletions

View File

@ -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()

View File

@ -40,6 +40,8 @@ class Model_Account extends Model_Auth_UserDefault {
),
);
protected $_form = array('id'=>'id','value'=>'name(TRUE)');
protected $_save_message = TRUE;
/**

View File

@ -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
*/

View File

@ -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;
}
}
?>

View File

@ -1,9 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $l = substr(I18n::$lang, 0, 2) ?>" lang="<?php echo $l ?>">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php echo $title ?> | Kohana <?php echo __('User Guide'); ?></title>
<title><?php echo $title ?> | Kohana User Guide</title>
<?php foreach ($styles as $style => $media) echo HTML::style($style, array('media' => $media), NULL, TRUE), "\n" ?>
@ -17,17 +17,17 @@
<div id="kodoc-header">
<div class="container">
<a href="http://phpTSMadmin.sf.net/" id="kodoc-logo">
<a href="http://dev.leenooks.vpn/" id="kodoc-logo">
<img src="<?php echo Route::url('docs/media', array('file' => 'img/logo-small.png')) ?>" />
</a>
<div id="kodoc-menu">
<ul>
<li class="guide first">
<a href="<?php echo Route::url('docs/guide') ?>"><?php echo __('User Guide') ?></a>
<a href="<?php echo Route::url('docs/guide') ?>">User Guide</a>
</li>
<?php if (Kohana::$config->load('userguide.api_browser')): ?>
<li class="api">
<a href="<?php echo Route::url('docs/api') ?>"><?php echo __('API Browser') ?></a>
<a href="<?php echo Route::url('docs/api') ?>">API Browser</a>
</li>
<?php endif ?>
</ul>
@ -67,7 +67,7 @@
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript><?php echo __('Please enable JavaScript to view the :anchor_open comments powered by Disqus.:anchor_close', array(':anchor_open' => '<a href="http://disqus.com/?ref_noscript=kohana">', ':anchor_close' => '</a>')); ?></noscript>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=kohana">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">Documentation comments powered by <span class="logo-disqus">Disqus</span></a>
<?php endif ?>
</div>

View File

@ -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);
}

View File

@ -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',

View File

@ -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

View File

@ -36,7 +36,7 @@
</div> <!-- /row -->
<div class="row">
<?php echo Form::select('product_id',ORM::factory('Product')->where_active()->list_select(TRUE),NULL,array('label'=>'Product','class'=>'span4','sort'=>TRUE)); ?>
<?php echo Form::select('product_id',ORM::factory('Product')->list_select(TRUE),NULL,array('label'=>'Product','class'=>'span4','sort'=>TRUE)); ?>
</div> <!-- /row -->
</fieldset>

View File

@ -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(

View File

@ -1,87 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User Statement functions
*
* @package Statement
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Statement extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'show'=>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,
));
}
}
?>

View File

@ -0,0 +1,76 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Reseller Statement functions
*
* @package Statement
* @category Controllers/Reseller
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Reseller_Statement extends Controller_Statement {
protected $secure_actions = array(
'index'=>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));
}
}
?>

View File

@ -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));
}
}
?>

View File

@ -1,14 +0,0 @@
<tr class="<?php echo $trc; ?>">
<?php if (isset($o['invoice'])) { ?>
<td><?php echo $o['invoice']->display('date_orig'); ?></td>
<td>Invoice</td>
<td><?php echo HTML::anchor(URL::link('user','invoice/view/'.$o['invoice']->id),$o['invoice']->id()); ?></td>
<td class="right"><?php echo $o['invoice']->total(TRUE); ?></td>
<?php } elseif (isset($o['payment'])) { ?>
<td><?php echo $o['payment']->display('date_payment'); ?></td>
<td>Payment</td>
<td><?php printf('%s - %s',$o['payment']->id,$o['payment']->checkout->display('name')); ?></td>
<td class="right"><?php echo $o['payment']->total(TRUE); ?></td>
<?php } ?>
<td class="right"><?php echo Currency::display($o['total']); ?></td>
</tr>

View File

@ -1 +0,0 @@
</table>

View File

@ -1,7 +0,0 @@
<table class="box-left" border="0" id="list-table">
<tr>
<td class="head">Date</td>
<td class="head" colspan="2">Type</td>
<td class="head">Amt</td>
<td class="head">Total</td>
</tr>