More progress on posting payments. Customer selection now works as well as the date picker. At this point, we need to figure out how to insert this data into the database. Of course, significant cleanup is still required, as is beautification.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@155 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-17 05:17:59 +00:00
parent d6c7fbb735
commit b8de98917a
5 changed files with 181 additions and 68 deletions

View File

@@ -148,6 +148,8 @@ class CustomersController extends AppController {
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('action' => 'payment', $id));
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
@@ -172,12 +174,12 @@ class CustomersController extends AppController {
/* $this->redirect(array('action'=>'index')); */
/* } */
if ($this->RequestHandler->isPost()) {
pr($this->data);
//$this->redirect(array('action'=>'index'));
$customer = $this->data;
}
elseif (isset($id)) {
/* if ($this->RequestHandler->isPost()) { */
/* pr($this->data); */
/* //$this->redirect(array('action'=>'index')); */
/* $customer = $this->data; */
/* } */
if (isset($id)) {
$customer = $this->Customer->details($id);
unset($customer['deposits']['Entries']);
}

View File

@@ -52,8 +52,38 @@
*
*/
$grid_setup = array();
if (isset($customer['Customer']['id']))
$grid_setup['hiddengrid'] = true;
$grid_setup['onSelectRow'] = array
('--special' =>
'function(ids) { if (ids != null)' .
' {' .
// Set the customer id that will be returned with the form
' $("#customer-id").val(ids);' .
// Get the customer name from the grid
' $("#payment_customer").html($("#"+$(this).attr("id"))' .
' .getCell(ids, "Customer-name"));' .
// Replace that with just the text portion of the hyperlink
' $("#payment_customer").html("Receipt for "+ $("#payment_customer a").html());' .
' } }'
);
/* $grid_setup['loadComplete'] = array */
/* ('--special' => */
/* 'function() { ' . */
/* //' $("#"+$(this).attr("id")).setSelection($("#customer-id").val());' . */
/* ' $(\'#customers-list-jqGrid\').setSelection($(\'#customer-id\').val());' . */
/* ' $("#"+$(this).attr("id")).setCaption("Hello");' . */
/* ' alert("Loaded");' . */
/* ' }' */
/* ); */
//pr($customer);
echo ("<H3>" . $customer['Customer']['name'] . "</H3>\n");
//echo ('<A HREF="#" ONCLICK="$(\'#debug\').append(htmlEncode($(\'#customers-list\').html())); return false">Get grid code</A><BR>');
// Customer
// Outstanding balance
@@ -63,8 +93,6 @@ echo ("<H3>" . $customer['Customer']['name'] . "</H3>\n");
// How to apply (even split, oldest charges first, etc)
echo $form->create(null, array('id' => 'payment-form', 'action' => 'payment'));
?>
<script type="text/javascript"><!--
@@ -72,37 +100,35 @@ echo $form->create(null, array('id' => 'payment-form', 'action' => 'payment'));
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#debug', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
target: '#output-debug', // target element(s) to be updated with server response
beforeSubmit: verifyRequest, // pre-submit callback
success: showResponse, // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
//url: url, // override for form's 'action' attribute
//type: type, // 'get' or 'post', override for form's 'method' attribute
//dataType: null, // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true, // clear all form fields after successful submit
resetForm: true, // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
//timeout: 3000,
};
// Get a clean slate for our payments
$('#payments').html('');
$('#payment-id').val(1);
addPaymentSource(false);
// get a clean slate
resetPaymentForm();
// bind form using 'ajaxForm'
$('#payment-form').ajaxForm(options);
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
function verifyRequest(formData, jqForm, options) {
// formData is an array; here we use $.param to convert it to a string to display it
// but the form plugin does this for you automatically when it submits the data
//var_dump(formData);
$('#debug').append('<PRE>'+dump(formData)+'</PRE>');
return false;
$('#request-debug').html('<PRE>'+dump(formData)+'</PRE>');
//return false;
// here we could return false to prevent the form from being submitted;
// returning anything other than false will allow the form submit to continue
@@ -121,10 +147,26 @@ echo $form->create(null, array('id' => 'payment-form', 'action' => 'payment'));
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
if (statusText == 'success') {
// get a clean slate
resetPaymentForm();
}
else {
alert('not successful??');
}
$('#response-debug').html('<PRE>'+dump(statusText)+'</PRE>');
}
// Reset payment fields
function resetPaymentForm() {
// Get a clean slate for our payments
$('#payments').html('');
$('#payment-id').val(1);
addPaymentSource(false);
}
function addPaymentSource(flash) {
addDiv('payment-id', 'payment', 'payments', flash,
@@ -140,7 +182,7 @@ echo $form->create(null, array('id' => 'payment-form', 'action' => 'payment'));
foreach ($types AS $type => $name) {
$div = '<DIV>';
$div .= '<INPUT TYPE="radio" NAME="data[Customer][payment][%{id}][type]"';
$div .= '<INPUT TYPE="radio" NAME="data[Source][%{id}][type]"';
$div .= ' ONCLICK="switchPaymentType(%{id}, \\\''.$type.'\\\')"';
$div .= ' CLASS="payment-type-%{id}" ID="payment-type-'.$type.'-%{id}"';
$div .= ' VALUE="'.$type.'" ' . ($type == 'cash' ? 'CHECKED ' : '') . '/>';
@@ -154,7 +196,7 @@ echo $form->create(null, array('id' => 'payment-form', 'action' => 'payment'));
'<DIV ID="payment-amount-div-%{id}" CLASS="input text required">' +
' <LABEL FOR="payment-amount-%{id}">Amount</LABEL>' +
' <INPUT TYPE="text" SIZE="20"' +
' NAME="data[Customer][payment][%{id}][amount]"' +
' NAME="data[Source][%{id}][amount]"' +
' ID="payment-amount-%{id}" />' +
'</DIV>' +
@@ -191,7 +233,7 @@ function switchPaymentType(paymentid, type) {
html =
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-check-number-'+paymentid+'">Check Number</LABEL>' +
' <INPUT TYPE="text" SIZE="6" NAME="data[Customer][payment]['+paymentid+'][check][number]"' +
' <INPUT TYPE="text" SIZE="6" NAME="data[Source]['+paymentid+'][check][number]"' +
' ID="payment-check-number-'+paymentid+'" />' +
'</DIV>';
break;
@@ -200,7 +242,7 @@ function switchPaymentType(paymentid, type) {
html =
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-moneyorder-number-'+paymentid+'">Money Order Number</LABEL>' +
' <INPUT TYPE="text" SIZE="6" NAME="data[Customer][payment]['+paymentid+'][moneyorder][number]"' +
' <INPUT TYPE="text" SIZE="6" NAME="data[Source]['+paymentid+'][moneyorder][number]"' +
' ID="payment-moneyorder-number-'+paymentid+'" />' +
'</DIV>';
break;
@@ -209,13 +251,13 @@ function switchPaymentType(paymentid, type) {
html =
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-ach-routing-'+paymentid+'">Routing Number</LABEL>' +
' <INPUT TYPE="text" SIZE="9" NAME="data[Customer][payment]['+paymentid+'][ach][routing]"' +
' <INPUT TYPE="text" SIZE="9" NAME="data[Source]['+paymentid+'][ach][routing]"' +
' ID="payment-ach-routing-'+paymentid+'" />' +
'</DIV>' +
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-ach-account-'+paymentid+'">Account Number</LABEL>' +
' <INPUT TYPE="text" SIZE="17" NAME="data[Customer][payment]['+paymentid+'][ach][account]"' +
' <INPUT TYPE="text" SIZE="17" NAME="data[Source]['+paymentid+'][ach][account]"' +
' ID="payment-ach-account-'+paymentid+'" />' +
'</DIV>';
break;
@@ -224,19 +266,19 @@ function switchPaymentType(paymentid, type) {
html =
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-creditcard-account-'+paymentid+'">Account Number</LABEL>' +
' <INPUT TYPE="text" SIZE="16" NAME="data[Customer][payment]['+paymentid+'][creditcard][account]"' +
' <INPUT TYPE="text" SIZE="16" NAME="data[Source]['+paymentid+'][creditcard][account]"' +
' ID="payment-creditcard-account-'+paymentid+'" />' +
'</DIV>' +
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-creditcard-expiration-'+paymentid+'">Expiration Date</LABEL>' +
' <INPUT TYPE="text" SIZE="10" NAME="data[Customer][payment]['+paymentid+'][creditcard][expiration]"' +
' <INPUT TYPE="text" SIZE="10" NAME="data[Source]['+paymentid+'][creditcard][expiration]"' +
' ID="payment-creditcard-expiration-'+paymentid+'" />' +
' </DIV>' +
'<DIV CLASS="input text required">' +
' <LABEL FOR="payment-creditcard-cvv2-'+paymentid+'">CVV2 Code</LABEL>' +
' <INPUT TYPE="text" SIZE="10" NAME="data[Customer][payment]['+paymentid+'][creditcard][cvv2]"' +
' <INPUT TYPE="text" SIZE="10" NAME="data[Source]['+paymentid+'][creditcard][cvv2]"' +
' ID="payment-creditcard-cvv2-'+paymentid+'" />' +
'</DIV>';
break;
@@ -253,6 +295,27 @@ function switchPaymentType(paymentid, type) {
--></script>
<?php
; // align
//echo '<DIV ID="dialog">' . "\n";
echo $this->element('customers',
array('caption' => '<A HREF="#" ONCLICK="$(\\\'.HeaderButton\\\').click(); return false;">Select Customer</A>',
'limit' => 7,
'grid_setup' => $grid_setup,
));
echo ('<H2><SPAN id="payment_customer">' .
(isset($customer['Customer']['id'])
? 'Receipt for ' . $customer['Customer']['name']
: 'Please select customer') .
'</SPAN></H2>' . "\n");
//echo $form->create(null, array('id' => 'payment-form', 'action' => 'other'));
echo $form->create(null, array('id' => 'payment-form', 'url' => 'http://localhost/vars.php'));
?>
<input type="hidden" id="customer-id" name="data[Customer][id]" value="<?php echo $customer['Customer']['id']; ?>">
<fieldset CLASS="payment superset">
<legend>Payments</legend>
<input type="hidden" id="payment-id" value="1">
@@ -264,13 +327,22 @@ function switchPaymentType(paymentid, type) {
<?php
//echo $form->inputs();
echo '<div type="text" id="datepicker"></div>' . "\n";
echo $form->end('Send');
echo 'Date: <input id="datepicker" name="data[Date]" type="text" /><BR>' . "\n";
echo 'Comment: <input id="comment" name="data[Comment]" type="text" SIZE=80 /><BR>' . "\n";
echo $form->end('Post Payment');
//echo '</DIV>' . "\n"; // End of the dialog DIV
?>
<a href="#" onClick="$('#debug').html(''); return false;">Clear Debug Output</a>
<div id="debug"></div>
<?php
/* <button id="post-payment" class="ui-button ui-state-default ui-corner-all">Create Payment</button> */
?>
<div><H4>Request</H4><div id="request-debug"></div></div>
<div><H4>Response</H4><div id="response-debug"></div></div>
<div><H4>Output</H4><div id="output-debug"></div></div>
<?php
?>
@@ -278,7 +350,35 @@ echo $form->end('Send');
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker();
$("#datepicker").datepicker()
.datepicker('setDate', '+0');
/* $("#dialog").dialog({ */
/* bgiframe: true, */
/* autoOpen: false, */
/* height: 500, */
/* width: 600, */
/* modal: true, */
/* buttons: { */
/* 'Post a Payment': function() { */
/* var bValid = true; */
/* if (bValid) { */
/* $('#debug').append('<H2>POSTED!</H2>'); */
/* $(this).dialog('close'); */
/* } */
/* }, */
/* Cancel: function() { */
/* $(this).dialog('close'); */
/* } */
/* }, */
/* close: function() { */
/* } */
/* }); */
/* $('#post-payment').click(function() { */
/* $('#dialog').dialog('open'); */
/* }); */
});
</script>

View File

@@ -12,8 +12,10 @@ $cols['Leases'] = array('index' => 'lease_count', 'width' =>
$cols['Comment'] = array('index' => 'Customer.comment', 'formatter' => 'comment');
$jqGrid_options = array('jqGridColumns' => $cols,
'controller' => 'customers',
'caption' => isset($caption) ? $caption : null);
'controller' => 'customers');
// User requested options have priority
$jqGrid_options += compact('caption', 'grid_setup', 'limit');
if (isset($customers)) {
$jqGrid_options += array('custom_ids' =>
@@ -22,7 +24,9 @@ if (isset($customers)) {
$customers),
'limit' => 5);
}
else {
// Not the long term solution here... just for testing
if (isset($searchfields)) {
$jqGrid_options += array('search_fields' => array('Last Name', 'First Name'));
}

View File

@@ -39,6 +39,8 @@ if (!isset($grid_id))
if (!isset($search_fields))
$search_fields = array();
if (!isset($grid_setup))
$grid_setup = array();
// Do some prework to bring in the appropriate libraries
$imgpath = '/pmgr/site/css/jqGrid/basic/images';
@@ -139,10 +141,35 @@ foreach ($jqGridColumns AS &$col) {
$col = array_merge($default, $col);
}
// Set the default sort column
reset($jqGridColumns);
$sortname = current($jqGridColumns);
$sortname = $sortname['index'];
// Configure the grid setup, giving priority to user defined parameters
$jqGrid_setup = array_merge
(array('mtype' => 'GET',
'datatype' => 'xml',
'url' => $url,
'postData' => $postData,
'colNames' => array_keys($jqGridColumns),
'colModel' => array('--special' => $jqGridColumns),
'height' => $height,
'rowNum' => $limit,
'rowList' => $limitOptions,
'sortname' => $sortname,
'caption' => $caption,
'imgpath' => $imgpath,
'viewrecords' => true,
'pager' => $grid_id.'-pager',
'loadComplete' => array('--special' => "function() {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>');}"),
'loadError' => array('--special' => "function(xhr,st,err) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Error Query</A><BR>');}"),
),
$grid_setup
);
//pr(compact('grid_setup', 'jqGrid_setup'));
// OK, now that everything is in place, get out of PHP mode,
// and add the javascript code (along with a touch of HTML)
@@ -165,27 +192,7 @@ jQuery(document).ready(function(){
}
jQuery('#<?php echo $grid_id; ?>').jqGrid(
<?php
echo FormatHelper::phpVarToJavascript
(array('mtype' => 'GET',
'datatype' => 'xml',
'url' => $url,
'postData' => $postData,
'colNames' => array_keys($jqGridColumns),
'colModel' => array('--special' => $jqGridColumns),
'height' => $height,
'rowNum' => $limit,
'rowList' => $limitOptions,
'sortname' => $sortname,
'caption' => $caption,
'imgpath' => $imgpath,
'viewrecords' => true,
'pager' => $grid_id.'-pager',
'loadComplete' => array('--special' => "function() {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>');}"),
'loadError' => array('--special' => "function(xhr,st,err) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Error Query</A><BR>');}"),
//'toolbar' => array(true,"bottom"),
)); ?>
<?php echo FormatHelper::phpVarToJavascript($jqGrid_setup); ?>
).navGrid('#<?php echo $grid_id; ?>-pager',
{ view:false,
edit:false,

View File

@@ -212,7 +212,7 @@ form div.submit {
border: 0;
clear: both;
margin-top: 10px;
margin-left: 140px;
/* margin-left: 140px; */
}
/************************************************************