Got the collected reports working again. NSF hasn't been tested yet, because NSF entry is not yet working.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@402 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-28 16:08:15 +00:00
parent aa0a60ea2b
commit 1d6c7436d4
4 changed files with 73 additions and 62 deletions

View File

@@ -183,11 +183,21 @@ class AppController extends Controller {
'rows' => 20), 'rows' => 20),
$params); $params);
// Unserialize our complex structure of fields // Unserialize our complex structure of post data.
// This SHOULD always be set, except when debugging // This SHOULD always be set, except when debugging
if (isset($params['post'])) if (isset($params['post']))
$params['post'] = unserialize($params['post']); $params['post'] = unserialize($params['post']);
// Unserialize our complex structure of dynamic post data
if (isset($params['dynamic_post']))
$params['dynamic_post'] = unserialize($params['dynamic_post']);
// Merge the static and dynamic post data
if (empty($params['post']) && !empty($params['dynamic_post']))
$params['post'] = $params['dynamic_post'];
elseif (!empty($params['post']) && !empty($params['dynamic_post']))
//$params['post'] = array_merge($params['post'], $params['dynamic_post']);
$params['post'] = array_merge_recursive($params['post'], $params['dynamic_post']);
// This SHOULD always be set, except when debugging // This SHOULD always be set, except when debugging
if (!isset($params['post']['fields'])) if (!isset($params['post']['fields']))
@@ -321,11 +331,11 @@ class AppController extends Controller {
// If the table is already part of the query, append to it // If the table is already part of the query, append to it
if ($table == $model->alias) { if ($table == $model->alias) {
$query[$link] = $query[$link] =
array_merge_recursive($query[$link], $config); array_merge_recursive($config, $query[$link]);
} }
elseif (isset($query[$link][$table])) { elseif (isset($query[$link][$table])) {
$query[$link][$table] = $query[$link][$table] =
array_merge_recursive($query[$link][$table], $config); array_merge_recursive($config, $query[$link][$table]);
} }
elseif (in_array($table, $query[$link])) { elseif (in_array($table, $query[$link])) {
// REVISIT <AP>: 20090727 // REVISIT <AP>: 20090727
@@ -357,6 +367,10 @@ class AppController extends Controller {
} }
function gridDataFilterTablesTable(&$params, &$model, $table) { function gridDataFilterTablesTable(&$params, &$model, $table) {
// By default, don't add anything if the filter
// condition occurs on the actual model table
if ($table == $model->alias)
return null;
return $this->gridDataFilterTableName($params, $model, $table); return $this->gridDataFilterTableName($params, $model, $table);
} }

View File

@@ -25,10 +25,6 @@ class StatementEntriesController extends AppController {
* to jqGrid. * to jqGrid.
*/ */
function gridDataSetup(&$params) {
parent::gridDataSetup($params);
}
function gridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $link =
array(// Models array(// Models
@@ -56,6 +52,12 @@ class StatementEntriesController extends AppController {
$link['PaymentEntry'] = array(); $link['PaymentEntry'] = array();
$link['ChargeEntry'] = array(); $link['ChargeEntry'] = array();
} }
/* if ($params['action'] === 'collected') { */
/* $link['PaymentEntry'] = array('Receipt' => array('class' => 'Transaction')); */
/* $link['ChargeEntry'] = array('Invoice' => array('class' => 'Transaction')); */
/* } */
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */ /* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
/* $link['PaymentEntry'] = array(); */ /* $link['PaymentEntry'] = array(); */
/* $link['ChargeEntry'] = array(); */ /* $link['ChargeEntry'] = array(); */
@@ -69,26 +71,22 @@ class StatementEntriesController extends AppController {
function gridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$fields = parent::gridDataFields($params, $model); $fields = parent::gridDataFields($params, $model);
extract($params['post']['custom']);
/* if (isset($params['post']['custom']['reconcile_id'])) { */ if (in_array('applied', $params['post']['fields'])) {
/* $fields[] = array("IF(StatementEntry.type = 'CHARGE',", */ $fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
/* " COALESCE(AppliedCharge.amount,0),", */ " SUM(COALESCE(PaymentEntry.amount,0))," .
/* " COALESCE(AppliedPayment.amount,0))", */ " SUM(COALESCE(ChargeEntry.amount,0)))" .
/* " AS 'applied'"); */ " AS 'applied'");
/* $fields[] = array("StatementEntry.amount - (", */ $fields[] = ("StatementEntry.amount - (" .
/* "IF(StatementEntry.type = 'CHARGE',", */ "IF(StatementEntry.type = 'CHARGE'," .
/* " COALESCE(AppliedCharge.amount,0),", */ " SUM(COALESCE(PaymentEntry.amount,0))," .
/* " COALESCE(AppliedPayment.amount,0))", */ " SUM(COALESCE(ChargeEntry.amount,0)))" .
/* ") AS 'balance'"); */ ") AS 'balance'");
/* } */ }
$fields = array_merge($fields, $fields = array_merge($fields,
$this->StatementEntry->chargePaymentFields()); $this->StatementEntry->chargePaymentFields());
if ($params['action'] === 'collected')
$fields[] = 'MAX(Receipt.stamp) AS last_paid';
return $fields; return $fields;
} }
@@ -106,11 +104,8 @@ class StatementEntriesController extends AppController {
= array('Transaction.stamp <=' => = array('Transaction.stamp <=' =>
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59')); $this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
if (isset($payment_accounts)) if (isset($account_id))
$conditions[] = array('PaymentEntry.account_id' => $payment_accounts); $conditions[] = array('StatementEntry.account_id' => $account_id);
if (isset($charge_accounts))
$conditions[] = array('ChargeEntry.account_id' => $charge_accounts);
if (isset($statement_entry_id)) { if (isset($statement_entry_id)) {
$conditions[] = array('OR' => $conditions[] = array('OR' =>
@@ -145,28 +140,34 @@ class StatementEntriesController extends AppController {
return $order; return $order;
} }
function gridDataRecords(&$params, &$model, $query) { function gridDataRecordsExecute(&$params, &$model, $query) {
if ($params['action'] === 'collected') { if (in_array('applied', $params['post']['fields'])) {
$tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1)); $tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['group'] = array('AppliedPayment.id'); $tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE',", " SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(PaymentEntry.amount,0)),", " SUM(COALESCE(ChargeEntry.amount,0)))" .
" SUM(COALESCE(ChargeEntry.amount,0)))",
" AS 'applied'", " AS 'applied'",
"StatementEntry.amount - (", "StatementEntry.amount - (" .
"IF(StatementEntry.type = 'CHARGE',", "IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0)),", " SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))", " SUM(COALESCE(ChargeEntry.amount,0)))" .
") AS 'balance'", ") AS 'balance'",
); );
//pr(compact('tquery'));
$total = $model->find('first', $tquery); $total = $model->find('first', $tquery);
$params['userdata']['total'] = $total[0]['applied']; $params['userdata']['total'] = $total[0]['applied'];
$params['userdata']['balance'] = $total[0]['balance']; $params['userdata']['balance'] = $total[0]['balance'];
} }
else {
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['fields'] = array("SUM(COALESCE(StatementEntry.amount,0)) AS 'total'");
$total = $model->find('first', $tquery);
$params['userdata']['total'] = $total[0]['total'];
}
return parent::gridDataRecords($params, $model, $query); return parent::gridDataRecordsExecute($params, $model, $query);
} }

View File

@@ -24,21 +24,22 @@ function onGridLoadComplete() {
} }
function updateEntriesGrid() { function updateEntriesGrid() {
var cust = new Array();
var account_ids = new Array(); var account_ids = new Array();
$("INPUT[type='checkbox']:checked").each(function(i) { $("INPUT[type='checkbox']:checked").each(function(i) {
account_ids.push($(this).val()); account_ids.push($(this).val());
}); });
cust['account_id'] = <?php echo $account['id']; ?>; var cust = new Array();
cust['from_date'] = $('#TxFromDate').val(); cust['from_date'] = $('#TxFromDate').val();
cust['through_date'] = $('#TxThroughDate').val(); cust['through_date'] = $('#TxThroughDate').val();
cust['payment_accounts'] = account_ids; cust['account_id'] = account_ids;
var dynamic_post = new Array();
dynamic_post['custom'] = cust;
$('#collected-total').html('Calculating...'); $('#collected-total').html('Calculating...');
$('#collected-entries-jqGrid').clearGridData(); $('#collected-entries-jqGrid').clearGridData();
$('#collected-entries-jqGrid').setPostDataItem('custom', serialize(cust)); $('#collected-entries-jqGrid').setPostDataItem('dynamic_post', serialize(dynamic_post));
$('#collected-entries-jqGrid') $('#collected-entries-jqGrid')
.setGridParam({ page: 1 }) .setGridParam({ page: 1 })
.trigger("reloadGrid"); .trigger("reloadGrid");
@@ -153,11 +154,8 @@ echo '<div CLASS="detail supporting">' . "\n";
* Entries * Entries
*/ */
echo $this->element('ledger_entries', array echo $this->element('statement_entries', array
(// Element configuration (// Grid configuration
'account_id' => $account['id'],
// Grid configuration
'config' => array 'config' => array
( (
'grid_div_id' => 'collected-entries', 'grid_div_id' => 'collected-entries',
@@ -165,7 +163,10 @@ echo $this->element('ledger_entries', array
'grid_events' => array('loadComplete' => 'onGridLoadComplete()'), 'grid_events' => array('loadComplete' => 'onGridLoadComplete()'),
//'grid_setup' => array('hiddengrid' => true), //'grid_setup' => array('hiddengrid' => true),
//'caption' => '<SPAN id="receipt-charges-caption"></SPAN>', //'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'caption' => 'Collected ' . Inflector::pluralize($account['name']) 'caption' => 'Collected ' . Inflector::pluralize($account['name']),
'filter' => array('StatementEntry.type' => 'PAYMENT',
'ChargeEntry.account_id' => $account['id']),
'exclude' => array('Account', 'Charge'),
), ),
)); ));

View File

@@ -20,23 +20,16 @@ $cols['Comment'] = array('index' => 'StatementEntry.comment', 'formatter'
$cols['Charge'] = array('index' => 'charge', 'formatter' => 'currency'); $cols['Charge'] = array('index' => 'charge', 'formatter' => 'currency');
$cols['Payment'] = array('index' => 'payment', 'formatter' => 'currency'); $cols['Payment'] = array('index' => 'payment', 'formatter' => 'currency');
$cols['Last Payment'] = array('index' => 'last_paid', 'formatter' => 'date');
$cols['Applied'] = array('index' => "applied", 'formatter' => 'currency'); $cols['Applied'] = array('index' => "applied", 'formatter' => 'currency');
$cols['Sub-Total'] = array('index' => 'subtotal-balance', 'formatter' => 'currency', 'sortable' => false); $cols['Sub-Total'] = array('index' => 'subtotal-balance', 'formatter' => 'currency', 'sortable' => false);
/* if (!isset($statement_entry_id)) */ if (isset($subtotal_column))
/* $grid->invalidFields('Applied'); */ $cols['Sub-Total']['index'] =
/* else */ 'subtotal-' . $cols[$subtotal_column]['index'];
/* $cols['Sub-Total']['index'] = 'subtotal-applied'; */
// REVISIT <AP>: 20090722
// Disallowing this field until more of the rework is complete
$grid->invalidFields('Applied');
// Include custom data // Include custom data
$grid->customData(compact('statement_entry_id', 'from_date', 'through_date', $grid->customData(compact('statement_entry_id'));
'payment_accounts', 'charge_accounts'));
// Render the grid // Render the grid
$grid $grid
@@ -45,5 +38,7 @@ $grid
->defaultFields(array('Entry', 'Date', 'Charge', 'Payment')) ->defaultFields(array('Entry', 'Date', 'Charge', 'Payment'))
->searchFields(array('Customer', 'Unit')) ->searchFields(array('Customer', 'Unit'))
->render($this, isset($config) ? $config : null, ->render($this, isset($config) ? $config : null,
array_diff(array_keys($cols), array('Through', 'Lease', 'Last Payment', 'Comment'))); array_diff(array_keys($cols), array('Through', 'Lease',
'Applied', 'Sub-Total',
'Comment')));