Files
pmgr/views/customers/receipt.ctp
abijah 23cdd0e497 Merge in from surplus_account_20090815 r592
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@593 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-08-17 02:22:54 +00:00

421 lines
13 KiB
PHP

<?php /* -*- mode:PHP -*- */ ?>
<div class="receipt input">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Javascript
*/
// Warnings _really_ screw up javascript
$saved_debug_state = Configure::read('debug');
Configure::write('debug', '0');
?>
<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:
//clearForm: true, // clear all form fields after successful submit
//resetForm: true, // reset the form after successful submit
};
// bind form using 'ajaxForm'
$('#receipt-form').ajaxForm(options);
});
// pre-submit callback
function verifyRequest(formData, jqForm, options) {
$('#results').html('Working <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) {
if (statusText == 'success') {
var amount = 0;
$("input.payment.amount").each(function(i) {
amount += $(this).val();
});
$('#results').html('<H3>Receipt Saved<BR>' +
$("#receipt-customer-name").html() +
' : ' + fmtCurrency(amount) +
'</H3>');
if (!$("#repeat").attr("checked")) {
window.location.href =
"<?php echo $html->url(array('controller' => 'customers',
'action' => 'view')); ?>"
+ "/" + $("#customer-id").val();
return;
}
// get a clean slate
resetForm();
}
else {
$('#results').html('<H2>Failed to save receipt!</H2>');
alert('Failed to save receipt.');
}
}
// Reset the form
function resetForm() {
$('#payment-entry-id').val(1);
$('#payments').html('');
addPaymentSource(false);
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) {
// 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="' +
"<?php echo $html->url(array('controller' => 'customers',
'action' => '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'));
// 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">' +
<?php /* '<LEGEND>Payment #%{id} (%{remove})</LEGEND>' + */ ?>
'<LEGEND>Payment</LEGEND>' +
'<DIV ID="payment-div-%{id}">' +
<?php
// Rearrange to be of the form (id => name)
$radioOptions = array();
foreach ($paymentTypes AS $type)
$radioOptions[$type['TenderType']['id']] = $type['TenderType']['name'];
echo FormatHelper::phpVarToJavascript
($form->input('Entry.%{id}.tender_type_id',
array('type' => 'radio',
'separator' => '<BR>',
'onclick' => ('switchPaymentType(' .
'\\\'payment-type-div\\\', ' .
'%{id}, ' .
'$(this).attr("id")' .
')' .
//' return false;'
''
),
'legend' => false,
'value' => $defaultType,
'options' => $radioOptions))) . "+\n";
?>
'</DIV>' +
'<DIV ID="payment-amount-div-%{id}" CLASS="input text required">' +
' <INPUT TYPE="text" SIZE="20"' +
' NAME="data[Entry][%{id}][amount]"' +
' CLASS="payment amount"' +
' ID="payment-amount-%{id}" />' +
' <LABEL CLASS="payment" FOR="payment-amount-%{id}">Amount</LABEL>' +
'</DIV>' +
<?php
foreach ($paymentTypes AS $type) {
$type = $type['TenderType'];
$div = '<DIV';
$div .= ' ID="payment-type-div-%{id}-'.$type['id'].'"';
$div .= ' CLASS="payment-type-div-%{id}"';
if ($type['id'] != $defaultType)
$div .= ' STYLE="display:none;"';
$div .= '>';
$div .= ' <INPUT TYPE="hidden"';
$div .= ' NAME="data[Entry][%{id}][type]['.$type['id'].'][tender_type_id]"';
$div .= ' VALUE="'.$type['id'].'"';
$div .= '>';
for ($i=1; $i<=4; ++$i) {
if (!empty($type["data{$i}_name"])) {
$div .= '<DIV CLASS="input text required">';
$div .= ' <INPUT TYPE="text" SIZE="20"';
$div .= ' NAME="data[Entry][%{id}][type]['.$type['id'].'][data'.$i.']"';
$div .= ' CLASS="payment"';
$div .= ' ID="payment-data'.$i.'-%{id}" />';
$div .= ' <LABEL';
$div .= ' CLASS="payment"';
$div .= ' FOR="payment-data'.$i.'-%{id}">';
$div .= $type["data{$i}_name"];
$div .= ' </LABEL>';
$div .= '</DIV>';
}
}
$div .= '</DIV>';
echo "'$div' +\n";
}
?>
'</FIELDSET>'
);
}
function switchPaymentType(paymentid_base, paymentid, radioid) {
var type_id = $("#"+radioid).val();
$("."+paymentid_base+"-"+paymentid+
":not(" +
"#"+paymentid_base+"-"+paymentid+"-"+type_id +
")").slideUp();
$("#"+paymentid_base+"-"+paymentid+"-"+type_id).slideDown();
}
--></script>
<?php
; // align
// Re-Enable warnings
Configure::write('debug', $saved_debug_state);
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' => array('hiddengrid' => isset($customer['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'),
'onHeaderClick' =>
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), gridstate)'),
),
'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('statement_entries', array
(// Grid configuration
'config' => array
(
'grid_div_id' => 'charge-entries',
'grid_div_class' => 'text-below',
'grid_events' => array('loadComplete' => 'onGridLoadComplete()'),
'grid_setup' => array('hiddengrid' => true),
'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'action' => 'unreconciled',
'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
'include' => array('Applied', 'Balance'),
'remap' => array('Applied' => 'Paid'),
'limit' => 8,
),
));
echo('<DIV CLASS="receipt grid-selection-text">' .
'<DIV CLASS="customer-selection-valid" style="display:none">' .
//'<DIV CLASS="supporting">' .
'<TABLE ID="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 "<BR>\n";
echo $form->input('repeat', array('type' => 'checkbox',
'id' => 'repeat',
'label' => 'Enter Multiple Receipts')) . "\n";
echo $form->submit('Generate Receipt') . "\n";
?>
<?php /*
<fieldset CLASS="payment superset">
<legend>Payments</legend>
*/ ?>
<input type="hidden" id="payment-entry-id" value="0">
<div id="payments"></div>
<?php /*
<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 id="results"></div>
<div id="output-debug" style="display:none"></div>
<?php
// Warnings _really_ screw up javascript
Configure::write('debug', '0');
?>
<script type="text/javascript"><!--
$(document).ready(function(){
$("#TransactionStamp")
.attr('autocomplete', 'off')
.datepicker({ constrainInput: true,
numberOfMonths: [1, 1],
showCurrentAtPos: 0,
dateFormat: 'mm/dd/yy' });
$("#receipt-customer-id").html("INTERNAL ERROR");
$("#receipt-customer-name").html("INTERNAL ERROR");
$("#receipt-balance").html("INTERNAL ERROR");
$("#receipt-charges-caption").html("Outstanding Charges");
<?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="' +
"<?php echo $html->url(array('controller' => 'customers',
'action' => 'view')); ?>"
+ "/" +
"<?php echo $customer['id']; ?>" +
'">#' +
"<?php echo $customer['id']; ?>" +
'</A>');
$("#receipt-customer-name").html("<?php echo $customer['name']; ?>");
$("#receipt-balance").html(fmtCurrency("<?php echo $stats['balance']; ?>"));
onGridState(null, 'hidden');
<?php else: ?>
onGridState(null, 'visible');
<?php endif; ?>
resetForm();
datepickerNow('TransactionStamp');
<?php if ($this->params['dev']): ?>
$('#output-debug').html('Post Output');
$('#output-debug').show();
<?php endif; ?>
});
--></script>
</div>