Captured some thoughts, some experiments on how to tie statement entry to ledger entry. It's not at all clear we want to go down this (or any other) path at the moment. This checkin will probably go nowhere, as I'm going to see if we can make do with the current implementation.

git-svn-id: file:///svn-source/pmgr/branches/statement_ledger_entry_tie_20090802@468 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-03 02:19:39 +00:00
parent 4ee9c99e30
commit ae09d160bb
10 changed files with 143 additions and 56 deletions

View File

@@ -25,7 +25,7 @@ class StatementEntriesController extends AppController {
* to jqGrid.
*/
function gridDataTables(&$params, &$model) {
function gridDataCountTables(&$params, &$model) {
$link =
array(// Models
'Transaction' =>
@@ -42,10 +42,6 @@ class StatementEntriesController extends AppController {
array('fields' => array('id', 'name'),
),
),
'Account' =>
array('fields' => array('id', 'name', 'type'),
),
);
if (isset($params['post']['custom']['statement_entry_id'])) {
@@ -53,25 +49,32 @@ class StatementEntriesController extends AppController {
$link['ChargeEntry'] = array();
}
/* if ($params['action'] === 'collected') { */
/* $link['PaymentEntry'] = array('Receipt' => array('class' => 'Transaction')); */
/* $link['ChargeEntry'] = array('Invoice' => array('class' => 'Transaction')); */
/* } */
if (isset($params['post']['custom']['account_id'])) {
$link['LedgerEntry'] = array('fields' => array('id'));
$link['LedgerEntry']['Account'] = array('fields' => array('id', 'name', 'type'));
}
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
/* $link['PaymentEntry'] = array(); */
/* $link['ChargeEntry'] = array(); */
/* } */
/* elseif (isset($params['post']['custom']['customer_id']) || isset($params['post']['custom']['lease_id'])) { */
/* $link['PaymentEntry'] = array(); */
/* } */
return array('link' => $link);
}
function gridDataTables(&$params, &$model) {
$tables = $this->gridDataCountTables($params, $model);
$tables['link']['LedgerEntry'] = array('fields' => array('id'));
$tables['link']['LedgerEntry']['Account'] = array('fields' => array('id', 'name', 'type'));
return $tables;
}
function gridDataFields(&$params, &$model) {
//foreach(
$fields = parent::gridDataFields($params, $model);
$fields[] = "COUNT(LedgerEntry.id) AS ledger_entry_count";
if (in_array('applied', $params['post']['fields'])) {
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
@@ -105,7 +108,7 @@ class StatementEntriesController extends AppController {
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
if (isset($account_id))
$conditions[] = array('StatementEntry.account_id' => $account_id);
$conditions[] = array('LedgerEntry.account_id' => $account_id);
if (isset($statement_entry_id)) {
$conditions[] = array('OR' =>
@@ -116,6 +119,14 @@ class StatementEntriesController extends AppController {
return $conditions;
}
function gridDataPostProcessCalculatedFields(&$params, &$model, &$records) {
parent::gridDataPostProcessCalculatedFields($params, $model, $records);
foreach ($records AS &$record) {
if ($record['StatementEntry']['ledger_entry_count'] > 1)
$record['Account']['name'] = 'Multiple';
}
}
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['StatementEntry'] = array('id');
$links['Transaction'] = array('id');
@@ -144,7 +155,7 @@ class StatementEntriesController extends AppController {
if (in_array('applied', $params['post']['fields'])) {
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(StatementFraction.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))" .
" AS 'applied'",
@@ -197,18 +208,22 @@ class StatementEntriesController extends AppController {
}
// Get the StatementEntry and related fields
$this->StatementEntry->prClassLevel(30, 'Model');
$entry = $this->StatementEntry->find
('first',
array('contain' => array
('Transaction' => array('fields' => array('id', 'stamp')),
'Account' => array('id', 'name', 'type'),
'Customer' => array('fields' => array('id', 'name')),
'Lease' => array('fields' => array('id')),
'LedgerEntry' => array('fields' => array('id'),
'Account' => array('id', 'name', 'type')),
),
'conditions' => array('StatementEntry.id' => $id),
));
pr($entry);
//die();
$reconciled = $this->StatementEntry->reconciledEntries($id);