Updates to invoice display

This commit is contained in:
Deon George
2011-08-02 16:20:11 +10:00
parent c8c4c5176d
commit 41eec89afa
11 changed files with 137 additions and 11 deletions

View File

@@ -0,0 +1,36 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User Payment functions
*
* @package OSB
* @subpackage Payment
* @category Controllers/User
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_User_Payment extends Controller_TemplateDefault {
public $secure_actions = array(
'list'=>TRUE,
'view'=>TRUE,
);
/**
* Show a payments received
*/
public function action_list() {
$id = Auth::instance()->get_user()->id;
$ao = ORM::factory('account',$id);
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$id));
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Payments For'),$ao->accnum(),$ao->name(TRUE)),
'body'=>View::factory('payment/user/list')
->set('payments',$ao->payment->find_all()),
));
}
}
?>

View File

@@ -21,7 +21,9 @@ class Model_Payment extends ORMOSB {
'checkout'=>array('foreign_key'=>'checkout_plugin_id'),
);
protected $_sorting = array('date_payment'=>'DESC');
protected $_sorting = array(
'date_payment'=>'DESC'
);
protected $_display_filters = array(
'date_payment'=>array(
@@ -42,4 +44,32 @@ class Model_Payment extends ORMOSB {
->where('date_payment','>=',time()-$start*86400)
->find_all();
}
/**
* Calculate the remaining balance available for this payment
*/
public function balance($format=FALSE) {
$t = 0;
foreach ($this->payment_item->find_all() as $pio)
$t += $pio->alloc_amt;
return $format ? Currency::display($this->total_amt-$t) : $this->total_amt-$t;
}
/**
* Return a list of invoices that this payment is applied to
*/
public function invoices() {
$invoices = array();
foreach ($this->payment_item->find_all() as $pio)
array_push($invoices,$pio->invoice);
return $invoices;
}
public function invoicelist() {
return join(',',$this->invoices());
}
}

View File

@@ -0,0 +1,21 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<table class="box-left">
<tr>
<td class="head">ID</td>
<td class="head">Date</td>
<td class="head">Method</td>
<td class="head">Total</td>
<td class="head">Unallocated</td>
<td class="head">Invoices</td>
</tr>
<?php $i = 0; foreach ($payments as $po) { ?>
<tr class="<?php echo ++$i%2 ? 'odd' : 'even'; ?>">
<td><?php echo $po->id; ?></td>
<td><?php echo $po->display('date_payment'); ?></td>
<td><?php echo $po->checkout->display('name'); ?></td>
<td class="number"><?php echo $po->display('total_amt'); ?></td>
<td class="number"><?php echo $po->balance() ? '<b>'.$po->balance(TRUE).'</b>' : $po->balance(TRUE); ?></td>
<td class="number"><?php echo $po->invoicelist(); ?></td>
</tr>
<?php } ?>
</table>