Consistent use of return , payment refund handling

This commit is contained in:
Deon George
2013-04-05 23:50:08 +11:00
parent 43dfd88bce
commit 52d9005b64
30 changed files with 255 additions and 210 deletions

View File

@@ -20,16 +20,16 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
);
public function action_ajaxlist() {
$return = array();
$result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$return += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
$result += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$result += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
}
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
$this->response->body(json_encode(array_values($result)));
}
public function action_autoitemlist() {

View File

@@ -46,29 +46,39 @@ class Model_Payment extends ORM_OSB {
}
/**
* Return a list of invoice items for this payment.
* Add an item to this payment
*
* @param $inv number, to allocate payment to an invoice
*/
public function items() {
return $this->payment_items;
}
public function add_item($invnum) {
if ($this->loaded() and ! $this->payment_items)
throw new Kohana_Exception('Need to load payment_items?');
/**
* Add an item to an invoice
*/
public function add_item($iid) {
// Find our id, if it exists
foreach ($this->payment_items as $pio)
if ($pio->invoice_id == $iid)
if ($pio->invoice_id == $invnum)
return $pio;
// New Item
$c = count($this->payment_items);
$this->payment_items[$c] = ORM::factory('Payment_Item');
$this->payment_items[$c]->invoice_id = $iid;
$this->payment_items[$c]->invoice_id = $invnum;
return $this->payment_items[$c];
}
/**
* Calculate the remaining balance available for this payment
*/
public function balance($format=FALSE) {
$result = $this->total();
foreach ($this->items('ALLOC') as $pio)
$result -= $pio->alloc_amt;
return $format ? Currency::display($result) : $result;
}
/**
* Find all items that are exportable.
*
@@ -80,34 +90,69 @@ class Model_Payment extends ORM_OSB {
->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();
$result = array();
foreach ($this->payment_item->find_all() as $pio)
array_push($invoices,$pio->invoice);
foreach ($this->payment_items as $pio)
array_push($result,$pio->invoice);
return $invoices;
return $result;
}
public function invoicelist() {
return join(',',$this->invoices());
}
/**
* Return a list of payment items for this payment.
* @param type [ALLOC|CREDIT|ALL]
* @see payment_items
*/
public function items($type='ALL') {
$result = array();
foreach ($this->payment_items as $pio) {
$return = FALSE;
switch ($type) {
case 'ALLOC':
if ($pio->alloc_amt > 0)
$return = TRUE;
break;
case 'CREDIT':
if ($pio->alloc_amt < 0)
$return = TRUE;
break;
case 'ALL':
default:
$return = TRUE;
break;
}
if ($return)
array_push($result,$pio);
}
return $result;
}
/**
* Show the total amount of a payment.
*/
public function total($format=FALSE) {
$result = $this->total_amt;
foreach ($this->items('CREDIT') as $pio)
$result += $pio->alloc_amt;
return $format ? Currency::display($result) : Currency::round($result);
}
/** LIST FUNCTIONS **/
public function list_unapplied() {

View File

@@ -11,15 +11,15 @@
*/
class Payment_Bulk_Ezypay {
public function form() {
$return = '';
$result = '';
$return .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
$return .= Form::hidden('payer',$_POST['payer']);
$return .= View::factory('payment/admin/addbulk/ezypay');
$return .= Form::submit('submit','submit',array('class'=>'form_button'));
$return .= Form::close();
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
$result .= Form::hidden('payer',$_POST['payer']);
$result .= View::factory('payment/admin/addbulk/ezypay');
$result .= Form::submit('submit','submit',array('class'=>'form_button'));
$result .= Form::close();
return $return;
return $result;
}
public function process() {
@@ -83,8 +83,8 @@ class Payment_Bulk_Ezypay {
$payments[$array[3]]->checkout_plugin_id = 4;
}
$return = '';
$return .= View::Factory('payment/admin/addbulk/ezypay/head');
$result = '';
$result .= View::Factory('payment/admin/addbulk/ezypay/head');
$total = $fees = 0;
foreach ($payments as $po) {
@@ -93,15 +93,15 @@ class Payment_Bulk_Ezypay {
$total += $po->total_amt;
$fees += $po->fees_amt;
$return .= View::Factory('payment/admin/addbulk/ezypay/body')
$result .= View::Factory('payment/admin/addbulk/ezypay/body')
->set('o',$po);
}
$return .= View::Factory('payment/admin/addbulk/ezypay/foot')
$result .= View::Factory('payment/admin/addbulk/ezypay/foot')
->set('total',$total)
->set('fees',$fees);;
return $return;
return $result;
}
}
?>

View File

@@ -16,7 +16,7 @@
</tr>
<tr>
<td>Amount</td>
<td><?php echo Form::input('total_amt',$po->total_amt); ?></td>
<td><?php echo Form::input('total_amt',$po->total()); ?></td>
</tr>
<tr>
<td>Fees</td>