git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@270 97e9348a-65ac-dc4b-aefc-98561f571b83
497 lines
16 KiB
PHP
497 lines
16 KiB
PHP
<?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(1);
|
|
$('#payments').html('');
|
|
|
|
$("#receipt-customer-id").html("INTERNAL ERROR");
|
|
$("#receipt-customer-name").html("INTERNAL ERROR");
|
|
$("#receipt-balance").html("INTERNAL ERROR");
|
|
$("#receipt-charges-caption").html("Outstanding Charges");
|
|
|
|
addPaymentSource(false);
|
|
datepickerNow('TransactionStamp');
|
|
}
|
|
|
|
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'));
|
|
// REVISIT <AP>: 20090708
|
|
// This is not intended as a long term solution,
|
|
// but I need a way to enter data and then view
|
|
// the results. This link will help.
|
|
$("#receipt-customer-id").html('<A HREF="/pmgr/site/customers/view/' +
|
|
$(grid_id).getCell(customer_id, 'Customer-id').replace(/^#/,'') +
|
|
'">' +
|
|
$(grid_id).getCell(customer_id, 'Customer-id') +
|
|
'</A>');
|
|
$("#receipt-customer-name").html($(grid_id).getCell(customer_id, 'Customer-name'));
|
|
$("#receipt-balance").html("Calculating...");
|
|
$("#receipt-charges-caption").html("Please Wait...");
|
|
|
|
// Hide the "no customer" message and show the current customer
|
|
$(".customer-selection-invalid").hide();
|
|
$(".customer-selection-valid").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') {
|
|
$(".customer-selection-invalid").hide();
|
|
$(".customer-selection-valid").hide();
|
|
}
|
|
else {
|
|
if ($("#customer-id").val() > 0) {
|
|
$(".customer-selection-valid").show();
|
|
$(".customer-selection-invalid").hide();
|
|
} else {
|
|
$(".customer-selection-valid").hide();
|
|
$(".customer-selection-invalid").show();
|
|
}
|
|
}
|
|
}
|
|
|
|
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 updateChargesGrid(idlist) {
|
|
$('#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;
|
|
|
|
$('#charge-entries-jqGrid').clearGridData();
|
|
|
|
$.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>');
|
|
});
|
|
$('#receipt-balance').html(fmtCurrency($('entries',xml).attr('balance')));
|
|
$("#receipt-charges-caption").html("Outstanding Charges");
|
|
updateChargesGrid(ids);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // align
|
|
//echo '<DIV ID="dialog">' . "\n";
|
|
|
|
echo $this->element('customers', array
|
|
('config' => 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 ('<DIV CLASS="receipt grid-selection-text">' .
|
|
|
|
'<DIV CLASS="customer-selection-valid" style="display:none">' .
|
|
'Customer <SPAN id="receipt-customer-id"></SPAN>' .
|
|
': <SPAN id="receipt-customer-name"></SPAN>' .
|
|
|
|
/* '<DIV CLASS="supporting">' . */
|
|
/* '<TABLE>' . */
|
|
/* '<TR><TD CLASS="field">Balance:</TD><TD CLASS="value"><SPAN id="receipt-balance"></SPAN></TD></TR>' . */
|
|
/* '</TABLE>' . */
|
|
/* '</DIV>' . */
|
|
|
|
'</DIV>' . // END customer-selection-valid
|
|
|
|
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
|
|
'Please select customer' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' . "\n");
|
|
|
|
|
|
echo $this->element('ledger_entries', array
|
|
(// Element configuration
|
|
'account_ftype' => 'credit',
|
|
'limit' => 8,
|
|
|
|
// Grid configuration
|
|
'config' => array
|
|
(
|
|
'grid_div_id' => 'charge-entries',
|
|
'grid_div_class' => 'text-below',
|
|
'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
|
|
'rows' => $charges['entry'],
|
|
),
|
|
));
|
|
|
|
echo('<DIV CLASS="receipt grid-selection-text">' .
|
|
'<DIV CLASS="customer-selection-valid" style="display:none">' .
|
|
|
|
//'<DIV CLASS="supporting">' .
|
|
'<TABLE>' .
|
|
'<TR><TD CLASS="field">Balance:</TD><TD CLASS="value"><SPAN id="receipt-balance"></SPAN></TD></TR>' .
|
|
'</TABLE>' .
|
|
//'</DIV>' .
|
|
|
|
'</DIV>' . // END customer-selection-valid
|
|
'</DIV>' .
|
|
"\n");
|
|
|
|
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-id").html('<A HREF="/pmgr/site/customers/view/' +
|
|
"<?php echo $customer['id']; ?>" +
|
|
'">#' +
|
|
"<?php echo $customer['id']; ?>" +
|
|
'</A>');
|
|
$("#receipt-customer-name").html("<?php echo $customer['name']; ?>");
|
|
$("#receipt-balance").html(fmtCurrency("<?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>
|