Updated charge, Invoice improvements and other minor fixes

This commit is contained in:
Deon George
2013-09-06 15:39:56 +10:00
parent 2322a802de
commit ab3735914b
52 changed files with 748 additions and 560 deletions

View File

@@ -131,7 +131,7 @@ $(document).ready(function() {
$("input[name=account_id_label]").typeahead({
minLength: 2,
source: function (query,process) {
search("a/payment/ajaxlist",query,process);
search("'.URL::link('admin','payment/ajaxlist').'",query,process);
},
matcher: function () { return true; },

View File

@@ -39,34 +39,23 @@ class Model_Payment extends ORM_OSB {
),
);
// Items belonging to an invoice
private $payment_items = array();
private $payment_items_unsorted = TRUE;
/**
* Intercept our object load, so that we can load our subitems
*/
protected function _load_values(array $values) {
parent::_load_values($values);
if ($this->_loaded)
$this->payment_items = $this->payment_item->find_all()->as_array();
return $this;
}
// Items belonging to a payment
protected $_sub_items_load = array(
'payment_item'=>FALSE,
);
/**
* Add an item to an payment
*/
public function add_item(Model_Payment_Item $p=NULL) {
$this->payment_items_unsorted = TRUE;
$this->_sub_items_sorted = FALSE;
// Make sure this payment item for an invoice is not already in the list
foreach ($this->payment_items as $pio)
foreach ($this->_sub_items as $pio)
if ($pio->invoice_id == $p->invoice_id)
return $pio;
array_push($this->payment_items,$p);
array_push($this->_sub_items,$p);
return $p;
}
@@ -101,7 +90,7 @@ class Model_Payment extends ORM_OSB {
public function invoices() {
$result = array();
foreach ($this->payment_items as $pio)
foreach ($this->_sub_items as $pio)
array_push($result,$pio->invoice);
return $result;
@@ -117,14 +106,14 @@ class Model_Payment extends ORM_OSB {
* @see payment_items
*/
public function items($type='ALL') {
if ($this->payment_items_unsorted) {
Sort::MAsort($this->payment_items,'invoice_id');
$this->payment_items_unsorted = FALSE;
if (! $this->_sub_items_sorted) {
Sort::MAsort($this->_sub_items,'invoice_id');
$this->_sub_items_sorted = TRUE;
}
$result = array();
foreach ($this->payment_items as $pio) {
foreach ($this->_sub_items as $pio) {
$return = FALSE;
switch ($type) {