Added initial support for ledger entry reconciliation (e.g. matching payments to charges).

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@152 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-16 21:40:46 +00:00
parent a83edef049
commit fae90c3fa9
5 changed files with 141 additions and 22 deletions

View File

@@ -26,9 +26,8 @@ class LedgerEntriesController extends AppController {
*/
function jqGridDataTables(&$params, &$model) {
return array
('link' =>
array(// Models
$link =
array(// Models
'Transaction' =>
array('fields' => array('id', 'stamp'),
),
@@ -52,8 +51,16 @@ class LedgerEntriesController extends AppController {
'MonetarySource' =>
array('fields' => array('id', 'name'),
),
),
);
);
if ($params['action'] === 'reconcile') {
$type = $params['custom']['reconcile'];
$link[$type.'ReconciliationLedgerEntry'] =
array('fields' => array('Reconciliation.amount'));
}
return array('link' => $link);
}
function jqGridDataFields(&$params, &$model) {
@@ -63,8 +70,17 @@ class LedgerEntriesController extends AppController {
function jqGridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model);
$conditions[] = $model->ledgerContextConditions($params['custom']['ledger_id'],
$params['custom']['account_type']);
if ($params['action'] === 'ledger') {
$conditions[] = $model->ledgerContextConditions($params['custom']['ledger_id'],
$params['custom']['account_type']);
}
if ($params['action'] === 'reconcile') {
$type = $params['custom']['reconcile'];
$other = ($type === 'Credit' ? 'debit' : 'credit');
$conditions[] = array('Reconciliation.'.$other.'_ledger_entry_id' => $params['custom']['reconcile_id']);
}
return $conditions;
}
@@ -118,25 +134,31 @@ class LedgerEntriesController extends AppController {
// seems). We'll have to break out each Account separately.
// Get the Account from DebitLedger
$account = $this->LedgerEntry->DebitLedger->Account->find
$entry['DebitLedger'] += $this->LedgerEntry->DebitLedger->Account->find
('first',
array('contain' => true,
'fields' => array('Account.id', 'Account.name', 'Account.type'),
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']),
));
$entry['DebitLedger'] = array_merge($entry['DebitLedger'], $account);
// Get the Account from CreditLedger
$account = $this->LedgerEntry->CreditLedger->Account->find
$entry['CreditLedger'] += $this->LedgerEntry->CreditLedger->Account->find
('first',
array('contain' => true,
'fields' => array('Account.id', 'Account.name', 'Account.type'),
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']),
));
$entry['CreditLedger'] = array_merge($entry['CreditLedger'], $account);
// Get the reconciliation balances for this ledger entry
$stats = $this->LedgerEntry->stats($id);
if ($entry['DebitLedger']['Account']['trackable'])
$stats['debit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['debit_amount_reconciled'];
if ($entry['CreditLedger']['Account']['trackable'])
$stats['credit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['credit_amount_reconciled'];
//pr($stats);
// Prepare to render.
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
$this->set(compact('entry', 'title'));
$this->set(compact('entry', 'title', 'stats'));
}
}