89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||
|
|
||
|
/**
|
||
|
* This class provides User Statement functions
|
||
|
*
|
||
|
* @package OSB
|
||
|
* @subpackage Statement
|
||
|
* @category Controllers/Admin
|
||
|
* @author Deon George
|
||
|
* @copyright (c) 2010 Deon George
|
||
|
* @license http://dev.leenooks.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 (round($o->total_amt-$o->refund_status,0) == 0)
|
||
|
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_amt-$v['payment']->refund_status;
|
||
|
|
||
|
$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,
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
?>
|