diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 4994824..59ceb4d 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -399,12 +399,27 @@ class CustomersController extends AppController { */ function receipt($id = null) { +/* $deposits = $this->Customer->findSecurityDeposits($id); */ +/* pr($deposits); */ +/* $this->autoRender = false; */ +/* return; */ + if (isset($id)) { $this->Customer->recursive = -1; $customer = $this->Customer->read(null, $id); $customer = $customer['Customer']; $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id); $charges = $unreconciled['debit']; + $leases = $this->Customer->find('first', array('contain' => array('CurrentLease'), + 'conditions' => array('Customer.id' => $id))); + $deposits = array(); + foreach ($leases['CurrentLease'] AS $lease) { + $lease_deposits = $this->Customer->Lease->findSecurityDeposits($lease['id']); + $deposits[] = array('lease_id' => $lease['id'], + 'balance' => $lease_deposits['summary']['balance']); + } + pr($deposits); + $this->set(compact('deposits')); } else { $customer = null; @@ -445,12 +460,23 @@ class CustomersController extends AppController { $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id); $unreconciled = array('entries' => array_intersect_key($unreconciled['debit'], - array('entry'=>1, 'balance'=>1))); + array('entry'=>1, 'balance'=>1)), + 'deposit' => array(), + ); // XML Helper will dump an empty tag if the array is empty if (!count($unreconciled['entries']['entry'])) unset($unreconciled['entries']['entry']); + $leases = $this->Customer->find('first', array('contain' => array('CurrentLease'), + 'conditions' => array('Customer.id' => $id))); + foreach ($leases['CurrentLease'] AS $lease) { + $lease_deposits = $this->Customer->Lease->findSecurityDeposits($lease['id']); + $unreconciled['deposit'][] + = array('lease_id' => $lease['id'], + 'balance' => $lease_deposits['summary']['balance']); + } + pr($unreconciled); //$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount); diff --git a/controllers/transactions_controller.php b/controllers/transactions_controller.php index c73ddd5..5d1a68b 100644 --- a/controllers/transactions_controller.php +++ b/controllers/transactions_controller.php @@ -137,6 +137,14 @@ class TransactionsController extends AppController { return; } + foreach($this->data['LedgerEntry'] AS &$entry) { + if (!isset($entry['acct'][$entry['account_id']])) + continue; + + $entry['MonetarySource'] = $entry['acct'][$entry['account_id']]; + } + + pr($this->data); if (!$this->Transaction->addReceipt($this->data, $this->data['Customer']['id'])) { $this->Session->setFlash("RECEIPT FAILED", true); diff --git a/models/customer.php b/models/customer.php index 4da68dc..e399b0d 100644 --- a/models/customer.php +++ b/models/customer.php @@ -86,8 +86,8 @@ class Customer extends AppModel { $A = new Account(); $entries = $A->findLedgerEntriesRelatedToAccount - ($A->invoiceAccountID(), - $A->securityDepositAccountID(), + ($A->securityDepositAccountID(), + array($A->invoiceAccountID(), $A->receiptAccountID()), true, array('LedgerEntry.customer_id' => $id), $link); /* pr(array('function' => 'Customer::findSecurityDeposits', */ diff --git a/models/lease.php b/models/lease.php index c64422b..f1fc24a 100644 --- a/models/lease.php +++ b/models/lease.php @@ -88,8 +88,8 @@ class Lease extends AppModel { $A = new Account(); $entries = $A->findLedgerEntriesRelatedToAccount - ($this->accountId($id), - $A->securityDepositAccountID(), + ($A->securityDepositAccountID(), + array($A->invoiceAccountID(), $A->receiptAccountID()), true, array('LedgerEntry.lease_id' => $id), $link); /* pr(array('function' => 'Lease::findSecurityDeposits', */ diff --git a/models/ledger_entry.php b/models/ledger_entry.php index bfce372..8fc8bad 100644 --- a/models/ledger_entry.php +++ b/models/ledger_entry.php @@ -91,7 +91,8 @@ class LedgerEntry extends AppModel { * query the ledger/account to find it out. */ function ledgerContextFields($ledger_id = null, $account_type = null) { - $fields = array('id', 'effective_date', 'through_date', 'comment', 'amount'); + $fields = array('id', 'effective_date', 'through_date', + 'lease_id', 'customer_id', 'comment', 'amount'); if (isset($ledger_id)) { $fields[] = ("IF(LedgerEntry.debit_ledger_id = $ledger_id," . diff --git a/views/customers/receipt.ctp b/views/customers/receipt.ctp index c36f2f3..65dba59 100644 --- a/views/customers/receipt.ctp +++ b/views/customers/receipt.ctp @@ -201,6 +201,57 @@ function addPaymentSource(flash) { $div .= ' ID="payment-type-div-%{id}-'.$account_id.'"'; $div .= ' CLASS="payment-type-div-%{id}"'; $div .= ' STYLE="display:none;">'; + + if ($name == 'Check') { + $div .= '
'; + $div .= ' '; + $div .= ' ' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
'; - break; - - case 'Money Order': - html = - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
'; - break; - - case 'ACH': - html = - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
' + - - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
'; - break; - - case 'Credit Card': - html = - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
' + - - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
' + - - '
' + - ' ' + - // REVISIT : 20090617: Use comment field for now. - ' ' + - '
'; - break; - - default: - return; - } - - $("#"+paymentid_base+"-"+paymentid+"-"+account_id).html(html); $("#"+paymentid_base+"-"+paymentid+"-"+account_id).slideDown(); } @@ -311,11 +288,22 @@ function updateCharges(id) { dataType: "xml", success: function(xml) { var ids = new Array(); - //$('#update-target ol').html('Data URL'); $('entry',xml).each(function(i){ ids.push($(this).attr('id')); - //$('#update-target').append("Push: len=" + ids.length + '
'); }); + var html = ''; + $('deposit',xml).each(function(i){ + html += 'Lease #' + $(this).attr('lease_id') + ' Deposit:' + + fmtCurrency($(this).attr('balance')) + ''; + }); + + var html = ''; + $('.security-deposit-info').html(html); $('#receipt-balance').html(fmtCurrency($('entries',xml).attr('balance'))); $("#receipt-charges-caption").html("Outstanding Charges"); updateChargesGrid(ids); @@ -381,7 +369,7 @@ echo('
' . '