Got the ledger closings to work again. This seems to work ok, although I notice closing the ledger after deposit results in a balance forward entry of $0.00 . I'll work on it next
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@421 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -148,6 +148,60 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: addClose
|
||||
* - Adds a new transaction for closing ledgers
|
||||
*/
|
||||
|
||||
function addClose($data) {
|
||||
// Establish the transaction as a close
|
||||
$close =& $data['Transaction'];
|
||||
$close['type'] = 'CLOSE';
|
||||
$close['account_id'] = null;
|
||||
$close['customer_id'] = null;
|
||||
$close['lease_id'] = null;
|
||||
|
||||
$ledger_ids = array();
|
||||
foreach ($data['Ledger'] AS $ledger) {
|
||||
$ledger_id = $ledger['old_ledger_id'];
|
||||
$new_ledger_id = $ledger['new_ledger_id'];
|
||||
$amount = $ledger['amount'];
|
||||
$account_id = $this->Account->Ledger->accountID($ledger_id);
|
||||
$crdr = strtoupper($this->Account->fundamentalOpposite($account_id));
|
||||
$comment = "Ledger Carry Forward (c/f)";
|
||||
|
||||
// Save the ledger ID for later, to mark it as closed
|
||||
$ledger_ids[] = $ledger_id;
|
||||
|
||||
// No need to generate ledger entries if there is no balance
|
||||
if (empty($ledger['amount']))
|
||||
continue;
|
||||
|
||||
// Add an entry to carry the ledger balance forward
|
||||
$data['Entry'][] = compact('account_id', 'ledger_id', 'new_ledger_id',
|
||||
'crdr', 'amount', 'comment');
|
||||
}
|
||||
unset($data['Ledger']);
|
||||
|
||||
// Add the transaction and carry forward balances
|
||||
$ids = $this->addTransaction($data);
|
||||
if (isset($ids['transaction_id']))
|
||||
$ids['close_id'] = $ids['transaction_id'];
|
||||
|
||||
// Mark the older ledgers as closed
|
||||
if (!empty($ids['close_id'])) {
|
||||
$this->LedgerEntry->Ledger->updateAll
|
||||
(array('Ledger.close_transaction_id' => $ids['close_id']),
|
||||
array('Ledger.id' => $ledger_ids)
|
||||
);
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -157,12 +211,13 @@ class Transaction extends AppModel {
|
||||
*/
|
||||
function verifyTransaction($transaction, $entries) {
|
||||
/* pr(array("Transaction::verifyTransaction()" */
|
||||
/* => compact('transaction', 'entries', 'customer_id', 'lease_id'))); */
|
||||
/* => compact('transaction', 'entries'))); */
|
||||
|
||||
// Verify required Transaction data is present
|
||||
if (empty($transaction['type']) ||
|
||||
empty($transaction['account_id']) ||
|
||||
empty($transaction['crdr']) ||
|
||||
($transaction['type'] != 'CLOSE'
|
||||
&& (empty($transaction['account_id']) ||
|
||||
empty($transaction['crdr']))) ||
|
||||
(in_array($transaction['type'], array('INVOICE', 'RECEIPT'))
|
||||
&& empty($transaction['customer_id'])) ||
|
||||
(in_array($transaction['type'], array('INVOICE'))
|
||||
@@ -304,16 +359,26 @@ class Transaction extends AppModel {
|
||||
// Create one half of the Double Ledger Entry (and the Tender)
|
||||
$le1 =
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('account_id', 'crdr', 'amount')));
|
||||
array_flip(array('ledger_id', 'account_id', 'crdr', 'amount')));
|
||||
$le1['comment'] = $entry['ledger_entry_comment'];
|
||||
$le1_tender = isset($entry['Tender']) ? $entry['Tender'] : null;
|
||||
|
||||
// Create the second half of the Double Ledger Entry
|
||||
$le2 =
|
||||
array_intersect_key($transaction,
|
||||
array_flip(array('account_id', 'crdr'))) +
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('amount')));
|
||||
if ($transaction['type'] == 'CLOSE') {
|
||||
$le2 =
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('account_id', 'amount')));
|
||||
$le2['ledger_id'] = $entry['new_ledger_id'];
|
||||
$le2['crdr'] = strtoupper($this->Account->fundamentalOpposite($le1['crdr']));
|
||||
$le2['comment'] = "Ledger Balance Forward (b/f)";
|
||||
}
|
||||
else {
|
||||
$le2 =
|
||||
array_intersect_key($transaction,
|
||||
array_flip(array('ledger_id', 'account_id', 'crdr'))) +
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('amount')));
|
||||
}
|
||||
|
||||
if ($transaction['type'] == 'INVOICE') {
|
||||
// Create a statement entry
|
||||
|
||||
Reference in New Issue
Block a user