Files
pmgr/site/views/customers/payment.ctp

504 lines
16 KiB
PHP

<?php /* -*- mode:PHP -*- */ ?>
<div class="payment input">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Transaction Detail Main Section
*/
/* $rows = array(array('ID', $transaction['Transaction']['id']), */
/* array('Timestamp', FormatHelper::datetime($transaction['Transaction']['stamp'])), */
/* array('Through', FormatHelper::date($transaction['Transaction']['through_date'])), */
/* array('Due', FormatHelper::date($transaction['Transaction']['due_date'])), */
/* array('Comment', $transaction['Transaction']['comment'])); */
/* echo $this->element('table', */
/* array('class' => 'item transaction detail', */
/* 'caption' => 'Transaction Detail', */
/* 'rows' => $rows, */
/* 'column_class' => array('field', 'value'))); */
/**********************************************************************
* Transaction Info Box
*/
?>
<!--
<DIV CLASS="infobox">
<DIV CLASS="summary grand total">
Total: <?php /*echo FormatHelper::currency($total);*/ ?>
</DIV>
</DIV>
-->
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
*
*/
$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); } }'
);
// 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,
};
// get a clean slate
resetPaymentForm();
// bind form using 'ajaxForm'
$('#payment-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
//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(0);
addPaymentSource(false);
}
function addPaymentSource(flash) {
addDiv('payment-id', 'payment', 'payments', flash,
// HTML section
'<FIELDSET CLASS="payment subset">' +
'<LEGEND>Payment #%{id} (%{remove})</LEGEND>' +
'<DIV ID="payment-type-div-%{id}">' +
<?php
/* REVISIT <AP> 20090616:
* MUST GET THIS FROM THE DATABASE!!
* HARDCODED VALUES BAD... VERY BAD...
*/
$monetary_type_ids = array('Cash' => 2,
'Check' => 3,
'Money Order' => 4,
'ACH' => 5,
'Credit Card' => 7,
);
$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="hidden" NAME="data[LedgerEntry][%{id}][bogus]" VALUE="1">';
$div .= '<INPUT TYPE="radio" NAME="data[LedgerEntry][%{id}][MonetarySource][monetary_type_id]"';
$div .= ' ONCLICK="switchPaymentType(%{id}, \\\''.$type.'\\\')"';
$div .= ' CLASS="payment-type-%{id}" ID="payment-type-'.$type.'-%{id}"';
$div .= ' VALUE="'.$monetary_type_ids[$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][comment]"' +
' 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][comment]"' +
' 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][comment]"' +
' 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][comment]"' +
' 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][comment]' +
' 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][comment]' +
' 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][comment]' +
' 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 += '/'+$("#customer-id").val();
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, cust_id) {
// Set the customer id that will be returned with the form
$("#customer-id").val(cust_id);
// Get the customer name from the grid
$("#payment_customer").html($(grid_id).getCell(cust_id, "Customer-name"));
// Replace that with just the text portion of the hyperlink
$("#payment_customer").html($("#payment_customer a").html());
// Hide the "no customer" message and show the current customer
$("#no_customer").hide();
$("#current_customer").show();
updateCharges(cust_id);
}
--></script>
<?php
; // align
//echo '<DIV ID="dialog">' . "\n";
echo $this->element('customers',
array('grid_div_id' => 'customers-list',
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
' return false;">Select Customer</A>'),
'grid_setup' => $grid_setup,
));
echo $this->element('ledger_entries',
array('grid_div_id' => 'charge-entries',
'caption' => 'Outstanding Charges',
'account_ftype' => 'credit',
'ledger_entries' => $charges['entry'],
'limit' => 8,
));
echo ('<H2>' .
'<SPAN id="current_customer" style="display:'.(isset($customer['id'])?"inline":"none").'">' .
'Enter new receipt for ' .
'<SPAN id="payment_customer">' . (isset($customer['name']) ? $customer['name'] : "") . '</SPAN>' .
'</SPAN>' .
'<SPAN id="no_customer" style="display:'.(isset($customer['id'])?"none":"inline").'">' .
'Please select customer' .
'</SPAN>' .
'</H2>' . "\n");
echo $form->create(null, array('id' => 'payment-form',
'url' => array('controller' => 'transactions',
'action' => 'postReceipt')));
/***************************************************
* Post data should look like this:
*
* data => Array
* (
* [Transaction] => Array
* (
* stamp => <Transaction Time Stamp>
* through_date => <Transaction Through Date, if any>
* due_date => <Transaction Due Date, if any>
* comment => <Transaction Comment>
* )
*
* [LedgerEntry] => Array
* (
* [0] => Array
* (
* name => <NOT TO INCLUDE??>
* amount => <Payment Amount>
* debit_ledger_id => <ID of the debit account's current ledger>
* credit_ledger_id => <ID of the debit account's current ledger>
* comment => <Ledger Entry Comment>
*
* [MonetarySource] => Array
* (
* name => <Name (may be useless parameter)>
* monetary_type_id => <Monetary Type ID>
* comment => <Monetary Source Comment>
* )
*
* REVISIT: Reconciliations will be tricker.
* )
*
* )
*
* )
*
***************************************************/
?>
<input type="hidden" id="customer-id" name="data[customer_id]" value="<?php echo $customer['id']; ?>">
<fieldset CLASS="payment superset">
<legend>Payments</legend>
<input type="hidden" id="payment-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 'Date: <input id="datepicker" name="data[Transaction][stamp]" type="text" /><BR>' . "\n";
echo 'Comment: <input id="comment" name="data[Transaction][comment]" type="text" SIZE=80 /><BR>' . "\n";
echo $form->end('Post Payment');
//echo '</DIV>' . "\n"; // End of the dialog 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
?>
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker()
.datepicker('setDate', '+0');
<?php if (isset($customer['id'])) { ?>
$("#customer-id").val(<?php echo $customer['id']; ?>);
updateChargesCaption("<?php echo $customer['name']; ?>",
<?php echo $charges['balance']; ?>);
<?php } ?>
/* $("#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>