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

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