Modified the charges list on the receipt page to have the query performed directly as part of returning the grid data, instead of an intermediary call to get the unreconciled entries first. This not only ensures consistent data, but is quicker, cleaner, and fixes the customer balance bug that seems to have been introduced as part of the change to how customer surplus is handled (although it could have been resolved using the old technique just as well).
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@570 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -453,51 +453,4 @@ class CustomersController extends AppController {
|
|||||||
$this->render('/transactions/bad_debt');
|
$this->render('/transactions/bad_debt');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: unreconciled
|
|
||||||
* - returns the list of unreconciled entries
|
|
||||||
*/
|
|
||||||
|
|
||||||
function unreconciled($id) {
|
|
||||||
|
|
||||||
//$this->layout = 'ajax';
|
|
||||||
$this->layout = null;
|
|
||||||
$this->autoLayout = false;
|
|
||||||
$this->autoRender = false;
|
|
||||||
Configure::write('debug', '0');
|
|
||||||
header("Content-type: text/xml;charset=utf-8");
|
|
||||||
|
|
||||||
App::import('Helper', 'Xml');
|
|
||||||
$xml = new XmlHelper();
|
|
||||||
|
|
||||||
// Find the unreconciled entries, then manipulate the structure
|
|
||||||
// slightly to accomodate the format necessary for XML Helper.
|
|
||||||
$unreconciled = $this->Customer->unreconciledCharges($id);
|
|
||||||
|
|
||||||
foreach ($unreconciled['entries'] AS &$entry)
|
|
||||||
$entry = array_intersect_key($entry['StatementEntry'],
|
|
||||||
array('id'=>1));
|
|
||||||
|
|
||||||
$unreconciled = array('entries' =>
|
|
||||||
array('entry' => $unreconciled['entries'],
|
|
||||||
'balance' => $unreconciled['summary']['balance']));
|
|
||||||
|
|
||||||
// XML Helper will dump an empty tag if the array is empty
|
|
||||||
if (empty($unreconciled['entries']['entry']))
|
|
||||||
unset($unreconciled['entries']['entry']);
|
|
||||||
|
|
||||||
/* pr(compact('unreconciled')); */
|
|
||||||
/* echo htmlspecialchars($xml->serialize($unreconciled)); */
|
|
||||||
/* $this->render('/empty'); */
|
|
||||||
/* return; */
|
|
||||||
|
|
||||||
$opts = array();
|
|
||||||
//$opts['format'] = 'tags';
|
|
||||||
echo $xml->header();
|
|
||||||
echo $xml->serialize($unreconciled, $opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,12 +118,27 @@ class StatementEntriesController extends AppController {
|
|||||||
if (isset($account_id))
|
if (isset($account_id))
|
||||||
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
||||||
|
|
||||||
|
if (isset($customer_id))
|
||||||
|
$conditions[] = array('StatementEntry.customer_id' => $customer_id);
|
||||||
|
|
||||||
if (isset($statement_entry_id)) {
|
if (isset($statement_entry_id)) {
|
||||||
$conditions[] = array('OR' =>
|
$conditions[] = array('OR' =>
|
||||||
array(array('ChargeEntry.id' => $statement_entry_id),
|
array(array('ChargeEntry.id' => $statement_entry_id),
|
||||||
array('DisbursementEntry.id' => $statement_entry_id)));
|
array('DisbursementEntry.id' => $statement_entry_id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($params['action'] === 'unreconciled') {
|
||||||
|
$query = array('conditions' => $conditions);
|
||||||
|
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, true);
|
||||||
|
|
||||||
|
$entries = array();
|
||||||
|
foreach ($set['entries'] AS $entry)
|
||||||
|
$entries[] = $entry['StatementEntry']['id'];
|
||||||
|
|
||||||
|
$conditions[] = array('StatementEntry.id' => $entries);
|
||||||
|
$params['userdata']['balance'] = $set['summary']['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
return $conditions;
|
return $conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,26 +167,26 @@ class StatementEntriesController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gridDataRecordsExecute(&$params, &$model, $query) {
|
function gridDataRecordsExecute(&$params, &$model, $query) {
|
||||||
if (in_array('applied', $params['post']['fields'])) {
|
/* if ($params['action'] === '???') { */
|
||||||
$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['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
|
/* $tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," . */
|
||||||
" SUM(COALESCE(DisbursementEntry.amount,0))," .
|
/* " SUM(COALESCE(DisbursementEntry.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(DisbursementEntry.amount,0))," .
|
/* " SUM(COALESCE(DisbursementEntry.amount,0))," . */
|
||||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
/* " SUM(COALESCE(ChargeEntry.amount,0)))" . */
|
||||||
") AS 'balance'",
|
/* ") AS 'balance'", */
|
||||||
);
|
/* ); */
|
||||||
|
|
||||||
//pr(compact('tquery'));
|
/* //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 {
|
if ($params['action'] === 'collected') {
|
||||||
$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['fields'] = array("SUM(COALESCE(StatementEntry.amount,0)) AS 'total'");
|
$tquery['fields'] = array("SUM(COALESCE(StatementEntry.amount,0)) AS 'total'");
|
||||||
$total = $model->find('first', $tquery);
|
$total = $model->find('first', $tquery);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function updateEntriesGrid() {
|
|||||||
|
|
||||||
$('#collected-total').html('Calculating...');
|
$('#collected-total').html('Calculating...');
|
||||||
$('#collected-entries-jqGrid').clearGridData();
|
$('#collected-entries-jqGrid').clearGridData();
|
||||||
$('#collected-entries-jqGrid').setPostDataItem('dynamic_post', serialize(dynamic_post));
|
$('#collected-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
||||||
$('#collected-entries-jqGrid')
|
$('#collected-entries-jqGrid')
|
||||||
.setGridParam({ page: 1 })
|
.setGridParam({ page: 1 })
|
||||||
.trigger("reloadGrid");
|
.trigger("reloadGrid");
|
||||||
@@ -168,6 +168,7 @@ echo $this->element('statement_entries', array
|
|||||||
'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']),
|
||||||
|
'action' => 'collected',
|
||||||
'filter' => array(//'StatementEntry.type' => 'DISBURSEMENT',
|
'filter' => array(//'StatementEntry.type' => 'DISBURSEMENT',
|
||||||
'ChargeEntry.account_id' => $account['id']),
|
'ChargeEntry.account_id' => $account['id']),
|
||||||
'exclude' => array('Account', 'Charge', 'Type'),
|
'exclude' => array('Account', 'Charge', 'Type'),
|
||||||
|
|||||||
@@ -81,6 +81,33 @@ function resetForm() {
|
|||||||
updateCharges($("#customer-id").val());
|
updateCharges($("#customer-id").val());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCharges(id) {
|
||||||
|
$('#charge-entries-jqGrid').clearGridData();
|
||||||
|
$("#receipt-balance").html("Calculating...");
|
||||||
|
$("#receipt-charges-caption").html("Please Wait...");
|
||||||
|
|
||||||
|
var custom = new Array();
|
||||||
|
custom['customer_id'] = id;
|
||||||
|
|
||||||
|
var dynamic_post = new Array();
|
||||||
|
dynamic_post['custom'] = custom;
|
||||||
|
|
||||||
|
$('#charge-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
||||||
|
$('#charge-entries-jqGrid')
|
||||||
|
.setGridParam({ page: 1 })
|
||||||
|
.trigger("reloadGrid");
|
||||||
|
|
||||||
|
var gridstate = $('#charge-entries-jqGrid').getGridParam('gridstate');
|
||||||
|
if (gridstate == 'hidden')
|
||||||
|
$('#charge-entries .HeaderButton').click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onGridLoadComplete() {
|
||||||
|
var userdata = $('#charge-entries-jqGrid').getGridParam('userData');
|
||||||
|
$('#receipt-balance').html(fmtCurrency(userdata['balance']));
|
||||||
|
$("#receipt-charges-caption").html("Outstanding Charges");
|
||||||
|
}
|
||||||
|
|
||||||
function onRowSelect(grid_id, customer_id) {
|
function onRowSelect(grid_id, customer_id) {
|
||||||
// Set the customer id that will be returned with the form
|
// Set the customer id that will be returned with the form
|
||||||
$("#customer-id").val(customer_id);
|
$("#customer-id").val(customer_id);
|
||||||
@@ -217,52 +244,6 @@ function switchPaymentType(paymentid_base, paymentid, radioid) {
|
|||||||
$("#"+paymentid_base+"-"+paymentid+"-"+type_id).slideDown();
|
$("#"+paymentid_base+"-"+paymentid+"-"+type_id).slideDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateChargesGrid(idlist) {
|
|
||||||
var dynamic_post = new Array();
|
|
||||||
dynamic_post['idlist'] = idlist;
|
|
||||||
|
|
||||||
$('#charge-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
|
||||||
$('#charge-entries-jqGrid')
|
|
||||||
.setGridParam({ page: 1 })
|
|
||||||
.trigger("reloadGrid");
|
|
||||||
|
|
||||||
var gridstate = $('#charge-entries-jqGrid').getGridParam('gridstate');
|
|
||||||
if (gridstate == 'hidden')
|
|
||||||
$('#charge-entries .HeaderButton').click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCharges(id) {
|
|
||||||
var url = '<?php echo ($html->url(array("controller" => $this->params["controller"],
|
|
||||||
"action" => "unreconciled"))); ?>';
|
|
||||||
url += '/'+id;
|
|
||||||
|
|
||||||
$('#charge-entries-jqGrid').clearGridData();
|
|
||||||
$("#receipt-balance").html("Calculating...");
|
|
||||||
$("#receipt-charges-caption").html("Please Wait...");
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
url: url,
|
|
||||||
dataType: "xml",
|
|
||||||
success: function(xml) {
|
|
||||||
var ids = new Array();
|
|
||||||
$('entry',xml).each(function(i){
|
|
||||||
ids.push($(this).attr('id'));
|
|
||||||
});
|
|
||||||
$('#receipt-balance').html(fmtCurrency($('entries',xml).attr('balance')));
|
|
||||||
$("#receipt-charges-caption").html("Outstanding Charges");
|
|
||||||
updateChargesGrid(ids);
|
|
||||||
},
|
|
||||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
||||||
/* alert('ERROR'); */
|
|
||||||
/* $('#debug').html('<P>request<BR>'+escape(XMLHttpRequest)); */
|
|
||||||
/* $('#debug').append('<P>status<BR>'+escape(textStatus)); */
|
|
||||||
/* $('#debug').append('<P>error<BR>'+escape(errorThrown)); */
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
--></script>
|
--></script>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@@ -315,9 +296,10 @@ echo $this->element('statement_entries', array
|
|||||||
(
|
(
|
||||||
'grid_div_id' => 'charge-entries',
|
'grid_div_id' => 'charge-entries',
|
||||||
'grid_div_class' => 'text-below',
|
'grid_div_class' => 'text-below',
|
||||||
|
'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>',
|
||||||
'action' => 'idlist',
|
'action' => 'unreconciled',
|
||||||
'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
|
'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
|
||||||
'include' => array('Applied', 'Balance'),
|
'include' => array('Applied', 'Balance'),
|
||||||
'remap' => array('Applied' => 'Paid'),
|
'remap' => array('Applied' => 'Paid'),
|
||||||
|
|||||||
Reference in New Issue
Block a user