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 .= '