Although I'm not too happy with the modifications, I do have a working version that minimizes the columns need to display ledger entries. The logic feels screwy to me, but I've beat my head on it long enough. I'll move on to something else and come back to it when my head clears.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@166 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-18 03:57:43 +00:00
parent 9b6830468e
commit 3e5ac64108
6 changed files with 189 additions and 80 deletions

View File

@@ -32,31 +32,56 @@ class LedgerEntriesController extends AppController {
array('fields' => array('id', 'stamp'),
),
'DebitLedger' =>
array('fields' => array('id', 'sequence'),
// Models
'DebitAccount' => array('class' => 'Account',
'fields' => array('id', 'name'),
),
),
'CreditLedger' =>
array('fields' => array('id', 'sequence'),
// Models
'CreditAccount' => array('class' => 'Account',
'fields' => array('id', 'name'),
),
),
'MonetarySource' =>
array('fields' => array('id', 'name'),
),
);
if ($params['action'] === 'reconcile') {
$type = $params['custom']['reconcile'];
$link[$type.'ReconciliationLedgerEntry'] =
if (isset($params['custom']['account_ftype'])) {
$ftype = $params['custom']['account_ftype'];
$ftype = ucfirst($ftype);
//$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
$link[$ftype . 'Ledger'] =
array('fields' => array('id', 'sequence'),
'Account' => array('class' => 'Account',
'fields' => array('id', 'name'),
),
);
}
elseif (isset($params['custom']['ledger_id'])) {
$ledger_id = $params['custom']['ledger_id'];
$link['Ledger'] =
array('fields' => array('id', 'sequence'),
'conditions' => ("Ledger.id = IF(LedgerEntry.debit_ledger_id = $ledger_id," .
" LedgerEntry.credit_ledger_id," .
" LedgerEntry.debit_ledger_id)"),
'Account' => array(
'fields' => array('id', 'name'),
),
);
}
else {
$link['DebitLedger'] =
array('fields' => array('id', 'sequence'),
'DebitAccount' => array('class' => 'Account',
'fields' => array('id', 'name'),
),
);
$link['CreditLedger'] =
array('fields' => array('id', 'sequence'),
'CreditAccount' => array('class' => 'Account',
'fields' => array('id', 'name'),
),
);
}
if (isset($params['custom']['reconcile_id'])) {
$ftype = $params['custom']['account_ftype'];
$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
$ftype = ucfirst($ftype);
$link[$ftype.'ReconciliationLedgerEntry'] =
array('fields' => array('Reconciliation.amount'));
}
@@ -64,21 +89,33 @@ class LedgerEntriesController extends AppController {
}
function jqGridDataFields(&$params, &$model) {
return $model->ledgerContextFields($params['custom']['ledger_id'],
$params['custom']['account_type']);
$ledger_id = (isset($params['custom']['ledger_id'])
? $params['custom']['ledger_id']
: null);
$account_type = (isset($params['custom']['account_type'])
? $params['custom']['account_type']
: null);
return $model->ledgerContextFields($ledger_id, $account_type);
}
function jqGridDataConditions(&$params, &$model) {
$ledger_id = (isset($params['custom']['ledger_id'])
? $params['custom']['ledger_id']
: null);
$account_type = (isset($params['custom']['account_type'])
? $params['custom']['account_type']
: null);
$conditions = parent::jqGridDataConditions($params, $model);
if ($params['action'] === 'ledger') {
$conditions[] = $model->ledgerContextConditions($params['custom']['ledger_id'],
$params['custom']['account_type']);
$conditions[] = $model->ledgerContextConditions($ledger_id, $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']);
if (isset($params['custom']['reconcile_id'])) {
$ftype = $params['custom']['account_ftype'];
//$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
$conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']);
}
return $conditions;
@@ -87,8 +124,13 @@ class LedgerEntriesController extends AppController {
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id');
$links['LedgerEntry'] = array('id');
$links['DebitAccount'] = array('controller' => 'accounts', 'name');
$links['CreditAccount'] = array('controller' => 'accounts', 'name');
if (isset($params['custom']['account_ftype']) || isset($params['custom']['ledger_id'])) {
$links['Account'] = array('controller' => 'accounts', 'name');
}
else {
$links['DebitAccount'] = array('controller' => 'accounts', 'name');
$links['CreditAccount'] = array('controller' => 'accounts', 'name');
}
$links['MonetarySource'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links);
}
@@ -157,8 +199,11 @@ class LedgerEntriesController extends AppController {
$stats['credit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['credit_amount_reconciled'];
//pr($stats);
$reconciled = $this->LedgerEntry->findReconciledLedgerEntries($id);
//pr($reconciled);
// Prepare to render.
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
$this->set(compact('entry', 'title', 'stats'));
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
}
}