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@402 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -25,10 +25,6 @@ class StatementEntriesController extends AppController {
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function gridDataSetup(&$params) {
|
||||
parent::gridDataSetup($params);
|
||||
}
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
$link =
|
||||
array(// Models
|
||||
@@ -56,6 +52,12 @@ class StatementEntriesController extends AppController {
|
||||
$link['PaymentEntry'] = 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) { */
|
||||
/* $link['PaymentEntry'] = array(); */
|
||||
/* $link['ChargeEntry'] = array(); */
|
||||
@@ -69,26 +71,22 @@ class StatementEntriesController extends AppController {
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
extract($params['post']['custom']);
|
||||
|
||||
/* if (isset($params['post']['custom']['reconcile_id'])) { */
|
||||
/* $fields[] = array("IF(StatementEntry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* " AS 'applied'"); */
|
||||
/* $fields[] = array("StatementEntry.amount - (", */
|
||||
/* "IF(StatementEntry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* ") AS 'balance'"); */
|
||||
/* } */
|
||||
if (in_array('applied', $params['post']['fields'])) {
|
||||
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
" AS 'applied'");
|
||||
$fields[] = ("StatementEntry.amount - (" .
|
||||
"IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
") AS 'balance'");
|
||||
}
|
||||
|
||||
$fields = array_merge($fields,
|
||||
$this->StatementEntry->chargePaymentFields());
|
||||
|
||||
if ($params['action'] === 'collected')
|
||||
$fields[] = 'MAX(Receipt.stamp) AS last_paid';
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -106,11 +104,8 @@ class StatementEntriesController extends AppController {
|
||||
= array('Transaction.stamp <=' =>
|
||||
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
|
||||
|
||||
if (isset($payment_accounts))
|
||||
$conditions[] = array('PaymentEntry.account_id' => $payment_accounts);
|
||||
|
||||
if (isset($charge_accounts))
|
||||
$conditions[] = array('ChargeEntry.account_id' => $charge_accounts);
|
||||
if (isset($account_id))
|
||||
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
||||
|
||||
if (isset($statement_entry_id)) {
|
||||
$conditions[] = array('OR' =>
|
||||
@@ -145,28 +140,34 @@ class StatementEntriesController extends AppController {
|
||||
return $order;
|
||||
}
|
||||
|
||||
function gridDataRecords(&$params, &$model, $query) {
|
||||
if ($params['action'] === 'collected') {
|
||||
$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',",
|
||||
" SUM(COALESCE(PaymentEntry.amount,0)),",
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))",
|
||||
function gridDataRecordsExecute(&$params, &$model, $query) {
|
||||
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(ChargeEntry.amount,0)))" .
|
||||
" AS 'applied'",
|
||||
|
||||
"StatementEntry.amount - (",
|
||||
"IF(StatementEntry.type = 'CHARGE',",
|
||||
" SUM(COALESCE(PaymentEntry.amount,0)),",
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))",
|
||||
"StatementEntry.amount - (" .
|
||||
"IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
") AS 'balance'",
|
||||
);
|
||||
|
||||
//pr(compact('tquery'));
|
||||
$total = $model->find('first', $tquery);
|
||||
$params['userdata']['total'] = $total[0]['applied'];
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user