Fixed the bank deposit, which was not reconciling the income received with the actual deposit. Thus, there was no way to determine when a particular check, for example, was actually deposited in the bank... the trail was broken. This seems to work. I would like to move some of the logic in Transaction to simply use the Account::postLedgerEntry function, but I'll not do it just yet... other fish and all.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@303 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -164,7 +164,7 @@ class AccountsController extends AppController {
|
|||||||
array('fields' => array('name')),
|
array('fields' => array('name')),
|
||||||
|
|
||||||
'LedgerEntry' =>
|
'LedgerEntry' =>
|
||||||
array('fields' => array('amount'),
|
array('fields' => array('id', 'amount'),
|
||||||
|
|
||||||
'MonetarySource' =>
|
'MonetarySource' =>
|
||||||
array('fields' => array('name')),
|
array('fields' => array('name')),
|
||||||
@@ -183,23 +183,15 @@ class AccountsController extends AppController {
|
|||||||
));
|
));
|
||||||
|
|
||||||
$deposit['total'] += $ledger['amount'];
|
$deposit['total'] += $ledger['amount'];
|
||||||
$deposit['ledgers'][] = array('name' => $ledger['account_name'],
|
$deposit['ledgers'][] = array('id' => $ledger_id,
|
||||||
|
'name' => $ledger['account_name'],
|
||||||
'total' => $ledger['amount'],
|
'total' => $ledger['amount'],
|
||||||
'entries' => $ledger_entries);
|
'entries' => $ledger_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estabish a set of ledgers to close
|
|
||||||
$set = array();
|
|
||||||
foreach ($this->data['Tillable']['Ledger'] AS $ledger_id => $ledger) {
|
|
||||||
if (!$ledger['checked'] || $ledger['amount'] == 0)
|
|
||||||
continue;
|
|
||||||
$set[] = array('ledger_id' => $ledger_id, 'amount' => $ledger['amount']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the accounting work necessary to close the
|
// Perform the accounting work necessary to close the
|
||||||
// monetary ledgers and deposit into the bank account.
|
// monetary ledgers and deposit into the bank account.
|
||||||
if (count($set) > 0)
|
$this->Account->closeAndDeposit($deposit['ledgers'], $this->data['Deposit']['Account']['id']);
|
||||||
$this->Account->closeAndDeposit($set, $this->data['Deposit']['Account']['id']);
|
|
||||||
|
|
||||||
$title = 'Account: Deposit Slip';
|
$title = 'Account: Deposit Slip';
|
||||||
$this->set(compact('title', 'deposit'));
|
$this->set(compact('title', 'deposit'));
|
||||||
|
|||||||
@@ -155,7 +155,8 @@ class Account extends AppModel {
|
|||||||
$account = $this->find('all', array
|
$account = $this->find('all', array
|
||||||
('contain' => array('CurrentLedger'),
|
('contain' => array('CurrentLedger'),
|
||||||
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||||
'conditions' => array('Account.'.$attribute => true)
|
'conditions' => array('Account.'.$attribute => true),
|
||||||
|
'order' => array('Account.name'),
|
||||||
) + (isset($extra) ? $extra : array())
|
) + (isset($extra) ? $extra : array())
|
||||||
);
|
);
|
||||||
$this->cacheQueries = false;
|
$this->cacheQueries = false;
|
||||||
@@ -490,7 +491,8 @@ class Account extends AppModel {
|
|||||||
|
|
||||||
function postLedgerEntry($transaction_data,
|
function postLedgerEntry($transaction_data,
|
||||||
$monetary_data,
|
$monetary_data,
|
||||||
$entry_data) {
|
$entry_data,
|
||||||
|
$reconcile = null) {
|
||||||
|
|
||||||
/* if (!isset($entry_data) || */
|
/* if (!isset($entry_data) || */
|
||||||
/* !isset($entry_data['amount']) || */
|
/* !isset($entry_data['amount']) || */
|
||||||
@@ -608,18 +610,69 @@ class Account extends AppModel {
|
|||||||
|
|
||||||
//pr(array('pre-save', compact('entry_data')));
|
//pr(array('pre-save', compact('entry_data')));
|
||||||
// Create it!
|
// Create it!
|
||||||
$entry = new LedgerEntry();
|
$new_entry = new LedgerEntry();
|
||||||
$entry->create();
|
$new_entry->create();
|
||||||
if (!$entry->saveAll($entry_data, array('validate'=>false))) {
|
if (!$new_entry->saveAll($entry_data, array('validate'=>false))) {
|
||||||
return false;
|
return array('error' => true);
|
||||||
}
|
}
|
||||||
$entry->recursive = -1;
|
|
||||||
$entry->read();
|
// See if the user has entered some sort of non-array
|
||||||
|
// for the reconcile parameter.
|
||||||
|
if (isset($reconcile) && is_bool($reconcile) && $reconcile) {
|
||||||
|
$reconcile = array('debit' => true, 'credit' => true);
|
||||||
|
}
|
||||||
|
elseif (!isset($reconcile) || !is_array($reconcile)) {
|
||||||
|
$reconcile = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reconcile the new entry... assume we'll have success
|
||||||
|
$err = false;
|
||||||
|
foreach (array_intersect_key($reconcile, array('credit'=>1,'debit'=>1))
|
||||||
|
AS $dr => $reconcile_set) {
|
||||||
|
if (!isset($reconcile_set) || (is_bool($reconcile_set) && !$reconcile_set))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (is_bool($reconcile_set) && $reconcile_set) {
|
||||||
|
// REVISIT <AP>: 20090710
|
||||||
|
// Take the reconcile code from the Transaction model,
|
||||||
|
// which utilizes reconcileNewLedgerEntry, and insert
|
||||||
|
// it here so that we can migrate the bulk of the
|
||||||
|
// functions addReceipt and addInvoice
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($reconcile_set)) {
|
||||||
|
foreach ($reconcile_set AS $reconcile_entry) {
|
||||||
|
$amount = $reconcile_entry['LedgerEntry']['amount'];
|
||||||
|
if (!$amount)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ($dr == 'debit') {
|
||||||
|
$debit_ledger_entry_id = $new_entry->id;
|
||||||
|
$credit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$debit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
|
||||||
|
$credit_ledger_entry_id = $new_entry->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$R = new Reconciliation();
|
||||||
|
$R->create();
|
||||||
|
if (!$R->save(compact('amount',
|
||||||
|
'debit_ledger_entry_id',
|
||||||
|
'credit_ledger_entry_id'), false))
|
||||||
|
$err = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_entry->recursive = -1;
|
||||||
|
$new_entry->read();
|
||||||
//pr(array('post-save', $entry->data));
|
//pr(array('post-save', $entry->data));
|
||||||
|
|
||||||
return array('transaction_id' => $entry->data['LedgerEntry']['transaction_id'],
|
return array('error' => $err,
|
||||||
'monetary_source_id' => $entry->data['LedgerEntry']['monetary_source_id'],
|
'id' => $new_entry->data['LedgerEntry']['id'],
|
||||||
'id' => $entry->data['LedgerEntry']['id']);
|
'transaction_id' => $new_entry->data['LedgerEntry']['transaction_id'],
|
||||||
|
'monetary_source_id' => $new_entry->data['LedgerEntry']['monetary_source_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -640,14 +693,28 @@ class Account extends AppModel {
|
|||||||
|
|
||||||
$transaction = array();
|
$transaction = array();
|
||||||
foreach ($set AS $ledger) {
|
foreach ($set AS $ledger) {
|
||||||
|
// REVISIT <AP>: 20090710
|
||||||
|
// If the user said to include a ledger in the
|
||||||
|
// set, should we really be excluding it?
|
||||||
|
if ($ledger['total'] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
$ids = $this->postLedgerEntry
|
$ids = $this->postLedgerEntry
|
||||||
($transaction,
|
($transaction,
|
||||||
null,
|
null,
|
||||||
array('debit_account_id' => $deposit_account_id,
|
array('debit_account_id' => $deposit_account_id,
|
||||||
'credit_ledger_id' => $ledger['ledger_id'],
|
'credit_ledger_id' => $ledger['id'],
|
||||||
'amount' => $ledger['amount']));
|
'amount' => $ledger['total']),
|
||||||
|
// Reconcile the account for cash/check/etc,
|
||||||
|
// which is the credit side of this entry.
|
||||||
|
array('credit' => $ledger['entries']));
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
die("closeAndDeposit : postLedgerEntry returned error!");
|
||||||
|
|
||||||
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
|
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
|
||||||
$this->Ledger->closeLedger($ledger['ledger_id'], $close->id);
|
|
||||||
|
$this->Ledger->closeLedger($ledger['id'], $close->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user