git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1046 97e9348a-65ac-dc4b-aefc-98561f571b83
441 lines
13 KiB
PHP
441 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
|
|
|
|
url: "<?php echo $html->url(array('controller' => 'transactions',
|
|
'action' => 'postReceipt', 0)); ?>"
|
|
};
|
|
|
|
// bind form using 'ajaxForm'
|
|
if ($('#receipt-form').ajaxForm != null)
|
|
$('#receipt-form').ajaxForm(options);
|
|
else
|
|
$('#repeat, label[for=repeat]').remove();
|
|
});
|
|
|
|
// pre-submit callback
|
|
function verifyRequest(formData, jqForm, options) {
|
|
//$("#debug").html('');
|
|
for (var i = 0; i < formData.length; ++i) {
|
|
//$("#debug").append(i + ') ' + dump(formData[i]) + '<BR>');
|
|
if (formData[i]['name'] == "data[Customer][id]" &&
|
|
!(formData[i]['value'] > 0)) {
|
|
//$("#debug").append('<P>Missing Customer ID');
|
|
alert("Please select a customer first.");
|
|
return false;
|
|
}
|
|
|
|
if (formData[i]['name'] == "data[Transaction][stamp]" &&
|
|
formData[i]['value'] == '') {
|
|
//$("#debug").append('<P>Bad Stamp');
|
|
if (formData[i]['value'] != '')
|
|
alert(formData[i]['value'] + " is not valid date stamp. Please correct it.");
|
|
else
|
|
alert("Please enter a valid date stamp first.");
|
|
return false;
|
|
}
|
|
|
|
// Terrible way to accomplish this...
|
|
for (var j = 0; j < 20; ++j) {
|
|
if (formData[i]['name'] == "data[Entry]["+j+"][amount]") {
|
|
var val = formData[i]['value'].replace(/\$/,'');
|
|
//$("#debug").append('<P>Bad Amount');
|
|
if (!(val > 0)) {
|
|
if (formData[i]['value'] == '')
|
|
alert("Please enter an amount first.");
|
|
else
|
|
alert('"'+formData[i]['value']+'"' + " is not valid amount. Please correct it.");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//$("#debug").append('OK');
|
|
//return false;
|
|
|
|
$('#results').html('Working <BLINK>...</BLINK>');
|
|
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 filter = new Array();
|
|
filter['StatementEntry.customer_id'] = id;
|
|
|
|
var dynamic_post = new Array();
|
|
dynamic_post['filter'] = filter;
|
|
|
|
$('#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);
|
|
|
|
// Set the customer name, so the user knows who the receipt is for
|
|
$("#receipt-customer-name")
|
|
.html('<A HREF="view/' + customer_id + '">'
|
|
+ $(grid_id).getCell(customer_id, 'Customer-name')
|
|
+ '</A>');
|
|
|
|
// 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)'),
|
|
),
|
|
'action' => 'current',
|
|
'nolinks' => true,
|
|
'limit' => 20,
|
|
)));
|
|
|
|
echo ('<DIV CLASS="receipt grid-selection-text">' .
|
|
|
|
'<DIV CLASS="customer-selection-valid" style="display:none">' .
|
|
'Customer: <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('Received' => '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(){
|
|
datepicker('TransactionStamp');
|
|
|
|
$("#customer-id").val(0);
|
|
$("#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-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>
|