Took some of the new learnings from invoice generation and put into receipt generations. Also moved some shared functions to pmgr.js, and renamed things for consistency.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@239 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
460
site/views/customers/receipt.ctp
Normal file
460
site/views/customers/receipt.ctp
Normal file
@@ -0,0 +1,460 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<div class="receipt input">
|
||||
<?php
|
||||
; // Editor alignment
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* Grid Setup / Javascript
|
||||
*/
|
||||
|
||||
$grid_setup = array();
|
||||
|
||||
if (isset($customer['id']))
|
||||
$grid_setup['hiddengrid'] = true;
|
||||
|
||||
$grid_setup['onSelectRow'] = array
|
||||
('--special' =>
|
||||
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
|
||||
);
|
||||
|
||||
$grid_setup['onHeaderClick'] = array
|
||||
('--special' =>
|
||||
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
|
||||
);
|
||||
|
||||
// Customer
|
||||
// Outstanding balance
|
||||
// Balance on each lease
|
||||
// Balance on personal account
|
||||
// Multiple fields for payments (cash, check, charge, etc)
|
||||
// How to apply (even split, oldest charges first, etc)
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
|
||||
// prepare the form when the DOM is ready
|
||||
$(document).ready(function() {
|
||||
var options = {
|
||||
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: 'get', // '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,
|
||||
};
|
||||
|
||||
// bind form using 'ajaxForm'
|
||||
$('#receipt-form').ajaxForm(options);
|
||||
});
|
||||
|
||||
// pre-submit callback
|
||||
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);
|
||||
//$('#request-debug').html('<PRE>'+dump(formData)+'</PRE>');
|
||||
$('#request-debug').html('Ommitted');
|
||||
//return false;
|
||||
|
||||
$('#response-debug').html('Loading <BLINK>...</BLINK>');
|
||||
$('#output-debug').html('Loading <BLINK>...</BLINK>');
|
||||
|
||||
// here we could return false to prevent the form from being submitted;
|
||||
// returning anything other than false will allow the form submit to continue
|
||||
return true;
|
||||
}
|
||||
|
||||
// post-submit callback
|
||||
function showResponse(responseText, statusText) {
|
||||
// for normal html responses, the first argument to the success callback
|
||||
// is the XMLHttpRequest object's responseText property
|
||||
|
||||
// if the ajaxForm method was passed an Options Object with the dataType
|
||||
// property set to 'xml' then the first argument to the success callback
|
||||
// is the XMLHttpRequest object's responseXML property
|
||||
|
||||
// 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
|
||||
|
||||
if (statusText == 'success') {
|
||||
// get a clean slate
|
||||
//resetForm();
|
||||
}
|
||||
else {
|
||||
alert('not successful??');
|
||||
}
|
||||
|
||||
|
||||
$('#response-debug').html('<PRE>'+dump(statusText)+'</PRE>');
|
||||
}
|
||||
|
||||
// Reset the form
|
||||
function resetForm() {
|
||||
$('#payment-entry-id').val(0);
|
||||
$('#payments').html('');
|
||||
|
||||
$("#receipt-customer-id").html("INTERNAL ERROR");
|
||||
$("#receipt-customer-name").html("INTERNAL ERROR");
|
||||
|
||||
addPaymentSource(false);
|
||||
datepickerNow('TransactionStamp');
|
||||
}
|
||||
|
||||
function addPaymentSource(flash) {
|
||||
addDiv('payment-entry-id', 'payment', 'payments', flash,
|
||||
// HTML section
|
||||
'<FIELDSET CLASS="payment subset">' +
|
||||
'<LEGEND>Payment #%{id} (%{remove})</LEGEND>' +
|
||||
|
||||
'<DIV ID="payment-type-div-%{id}">' +
|
||||
<?php
|
||||
|
||||
$types = array();
|
||||
foreach(array('Cash', 'Check', 'Money Order', /*'ACH', 'Credit Card'*/) AS $name)
|
||||
$types[preg_replace("/ /", "", strtolower($name))] = $name;
|
||||
|
||||
foreach ($types AS $type => $name) {
|
||||
$div = '<DIV>';
|
||||
$div .= '<INPUT TYPE="radio" NAME="data[LedgerEntry][%{id}][monetary_type_name]"';
|
||||
$div .= ' ONCLICK="switchPaymentType(%{id}, \\\''.$type.'\\\')"';
|
||||
$div .= ' CLASS="payment-type-%{id}" ID="payment-type-'.$type.'-%{id}"';
|
||||
$div .= ' VALUE="'.$name.'" ' . ($name == 'Cash' ? 'CHECKED ' : '') . '/>';
|
||||
$div .= ' <LABEL FOR="payment-type-'.$type.'-%{id}">'.$name.'</LABEL>';
|
||||
$div .= '</DIV>';
|
||||
echo "'$div' +\n";
|
||||
}
|
||||
?>
|
||||
'</DIV>' +
|
||||
|
||||
'<DIV ID="payment-amount-div-%{id}" CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-amount-%{id}">Amount</LABEL>' +
|
||||
' <INPUT TYPE="text" SIZE="20"' +
|
||||
' NAME="data[LedgerEntry][%{id}][amount]"' +
|
||||
' ID="payment-amount-%{id}" />' +
|
||||
'</DIV>' +
|
||||
|
||||
<?php
|
||||
foreach ($types AS $type => $name) {
|
||||
if ($type == 'cash')
|
||||
continue;
|
||||
|
||||
$div = '<DIV';
|
||||
$div .= ' ID="payment-'.$type.'-div-%{id}"';
|
||||
$div .= ' CLASS="payment-type-div-%{id}"';
|
||||
$div .= ' STYLE="display:none;">';
|
||||
$div .= '</DIV>';
|
||||
echo "'$div' +\n";
|
||||
}
|
||||
?>
|
||||
|
||||
'</FIELDSET>'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function switchPaymentType(paymentid, type) {
|
||||
$(".payment-type-div-"+paymentid).slideUp();
|
||||
$(".payment-type-div-"+paymentid).html('');
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 'cash':
|
||||
break;
|
||||
|
||||
case 'check':
|
||||
html =
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-check-number-'+paymentid+'">Check Number</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="6" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data1]"' +
|
||||
' ID="payment-check-number-'+paymentid+'" />' +
|
||||
'</DIV>';
|
||||
break;
|
||||
|
||||
case 'moneyorder':
|
||||
html =
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-moneyorder-number-'+paymentid+'">Money Order Number</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="6" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data1]"' +
|
||||
' ID="payment-moneyorder-number-'+paymentid+'" />' +
|
||||
'</DIV>';
|
||||
break;
|
||||
|
||||
case 'ach':
|
||||
html =
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-ach-routing-'+paymentid+'">Routing Number</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="9" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data1]"' +
|
||||
' ID="payment-ach-routing-'+paymentid+'" />' +
|
||||
'</DIV>' +
|
||||
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-ach-account-'+paymentid+'">Account Number</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="17" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data2]"' +
|
||||
' ID="payment-ach-account-'+paymentid+'" />' +
|
||||
'</DIV>';
|
||||
break;
|
||||
|
||||
case 'creditcard':
|
||||
html =
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-creditcard-account-'+paymentid+'">Account Number</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="16" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data1]' +
|
||||
' ID="payment-creditcard-account-'+paymentid+'" />' +
|
||||
'</DIV>' +
|
||||
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-creditcard-expiration-'+paymentid+'">Expiration Date</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="10" NAME="data[LedgerEntry]['+paymentid+'][MonetarySource][data2]' +
|
||||
' ID="payment-creditcard-expiration-'+paymentid+'" />' +
|
||||
' </DIV>' +
|
||||
|
||||
'<DIV CLASS="input text required">' +
|
||||
' <LABEL FOR="payment-creditcard-cvv2-'+paymentid+'">CVV2 Code</LABEL>' +
|
||||
// REVISIT <AP>: 20090617: Use comment field for now.
|
||||
' <INPUT TYPE="text" SIZE="10" NAME=data[LedgerEntry]['+paymentid+'][MonetarySource][data3]' +
|
||||
' ID="payment-creditcard-cvv2-'+paymentid+'" />' +
|
||||
'</DIV>';
|
||||
break;
|
||||
|
||||
default:
|
||||
html = '<DIV><H2>INVALID TYPE ('+type+')</H2></DIV>';
|
||||
break;
|
||||
}
|
||||
|
||||
$("#payment-"+type+"-div-"+paymentid).html(html);
|
||||
$("#payment-"+type+"-div-"+paymentid).slideDown();
|
||||
}
|
||||
|
||||
|
||||
function updateChargesCaption(customer_name, balance) {
|
||||
$('#charge-entries-jqGrid').setCaption('Outstanding Charges for ' +
|
||||
customer_name + ': ' +
|
||||
fmtCurrency(balance));
|
||||
}
|
||||
|
||||
function updateChargesGrid(idlist, balance) {
|
||||
updateChargesCaption($("#payment_customer").html(), balance);
|
||||
|
||||
$('#charge-entries-jqGrid').setPostDataItem('idlist', serialize(idlist));
|
||||
$('#charge-entries-jqGrid')
|
||||
.setGridParam({ page: 1 })
|
||||
.trigger("reloadGrid");
|
||||
}
|
||||
|
||||
function updateCharges(id) {
|
||||
var url = '<?php echo ($html->url(array("controller" => $this->params["controller"],
|
||||
"action" => "unreconciled"))); ?>';
|
||||
url += '/'+id;
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
dataType: "xml",
|
||||
success: function(xml) {
|
||||
var ids = new Array();
|
||||
$('#update-target ol').html('<A HREF="'+url+'">Data URL</A>');
|
||||
$('entry',xml).each(function(i){
|
||||
ids.push($(this).attr('id'));
|
||||
$('#update-target').append("Push: len=" + ids.length + '<BR>');
|
||||
});
|
||||
updateChargesGrid(ids, $('entries',xml).attr('balance'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onRowSelect(grid_id, customer_id) {
|
||||
// Set the customer id that will be returned with the form
|
||||
$("#customer-id").val(customer_id);
|
||||
|
||||
// Get the item names from the grid
|
||||
$("#receipt-customer-id").html($(grid_id).getCell(customer_id, 'Customer-id'));
|
||||
$("#receipt-customer-name").html($(grid_id).getCell(customer_id, 'Customer-name'));
|
||||
|
||||
// Make sure the redirect is up to date, if necessary
|
||||
if ($("#redirectController").val() == 'customers')
|
||||
$("#redirect0").val(customer_id);
|
||||
|
||||
// Hide the "no customer" message and show the current customer
|
||||
$("#no-customer").hide();
|
||||
$("#current-customer").show();
|
||||
|
||||
// Update the charges grid to reflect this customer
|
||||
updateCharges(customer_id);
|
||||
|
||||
// Collapse the grid now that the user has selected
|
||||
$("#customers-list .HeaderButton").click();
|
||||
}
|
||||
|
||||
function onGridState(grid_id, state) {
|
||||
if (state == 'visible') {
|
||||
$("#no-customer").hide();
|
||||
$("#current-customer").hide();
|
||||
}
|
||||
else {
|
||||
if ($("#customer-id").val() > 0) {
|
||||
$("#current-customer").show();
|
||||
$("#no-customer").hide();
|
||||
} else {
|
||||
$("#current-customer").hide();
|
||||
$("#no-customer").show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--></script>
|
||||
|
||||
<?php
|
||||
; // align
|
||||
//echo '<DIV ID="dialog">' . "\n";
|
||||
|
||||
echo $this->element('customers',
|
||||
array('grid_div_id' => 'customers-list',
|
||||
'grid_div_class' => 'text-below',
|
||||
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
|
||||
' return false;">Select Customer</A>'),
|
||||
'grid_setup' => $grid_setup,
|
||||
'nolinks' => true,
|
||||
'limit' => 10,
|
||||
));
|
||||
|
||||
echo ('<H2>' .
|
||||
'<SPAN id="current-customer" style="display:none">' .
|
||||
'Customer <SPAN id="receipt-customer-id"></SPAN>' .
|
||||
': <SPAN id="receipt-customer-name"></SPAN>' .
|
||||
'</SPAN>' .
|
||||
'<SPAN id="no-customer" style="display:none">' .
|
||||
'Please select customer' .
|
||||
'</SPAN>' .
|
||||
'</H2>' . "\n");
|
||||
|
||||
echo $this->element('ledger_entries',
|
||||
array('grid_div_id' => 'charge-entries',
|
||||
'caption' => 'Outstanding Charges',
|
||||
'account_ftype' => 'credit',
|
||||
'ledger_entries' => $charges['entry'],
|
||||
'limit' => 8,
|
||||
));
|
||||
|
||||
echo $form->create(null, array('id' => 'receipt-form',
|
||||
'url' => array('controller' => 'transactions',
|
||||
'action' => 'postReceipt')));
|
||||
|
||||
|
||||
echo $form->input("id",
|
||||
array('id' => 'customer-id',
|
||||
'type' => 'hidden',
|
||||
'value' => 0));
|
||||
|
||||
echo $this->element('form_table',
|
||||
array('class' => "item receipt transaction entry",
|
||||
//'with_name_after' => ':',
|
||||
'field_prefix' => 'Transaction',
|
||||
'fields' => array
|
||||
("stamp" => array('opts' => array('type' => 'text'),
|
||||
'between' => '<A HREF="#" ONCLICK="datepickerNow(\'TransactionStamp\'); return false;">Now</A>',
|
||||
),
|
||||
"comment" => array('opts' => array('size' => 50),
|
||||
),
|
||||
)));
|
||||
|
||||
echo $form->submit('Generate Receipt') . "\n";
|
||||
?>
|
||||
|
||||
<fieldset CLASS="payment superset">
|
||||
<legend>Payments</legend>
|
||||
<input type="hidden" id="payment-entry-id" value="0">
|
||||
<div id="payments"></div>
|
||||
<fieldset> <legend>
|
||||
<a href="#" onClick="addPaymentSource(true); return false;">Add Another Payment</a>
|
||||
</legend> </fieldset>
|
||||
</fieldset>
|
||||
|
||||
<?php echo $form->end('Generate Receipt'); ?>
|
||||
|
||||
<?php /* echo '</DIV>' . "\n"; // End of the dialog DIV */ ?>
|
||||
|
||||
<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>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#TransactionStamp")
|
||||
.attr('autocomplete', 'off')
|
||||
.datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' });
|
||||
|
||||
resetForm();
|
||||
|
||||
<?php if (isset($customer['id'])): ?>
|
||||
$("#customer-id").val(<?php echo $customer['id']; ?>);
|
||||
$("#receipt-customer-id").html("<?php echo '#'.$customer['id']; ?>");
|
||||
$("#receipt-customer-name").html("<?php echo $customer['name']; ?>");
|
||||
updateChargesCaption("<?php echo $customer['name']; ?>",
|
||||
<?php echo $charges['balance']; ?>
|
||||
);
|
||||
onGridState(null, 'hidden');
|
||||
<?php else: ?>
|
||||
onGridState(null, 'visible');
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
/* $("#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>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="#" onClick="$('#debug').html(''); return false;">Clear Debug Output</a>
|
||||
Reference in New Issue
Block a user