git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@256 97e9348a-65ac-dc4b-aefc-98561f571b83
334 lines
11 KiB
PHP
334 lines
11 KiB
PHP
<?php /* -*- mode:PHP -*- */ ?>
|
|
|
|
<div class="invoice input">
|
|
<?php
|
|
; // Editor alignment
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Grid Setup / Javascript
|
|
*/
|
|
|
|
$lease_grid_setup = array();
|
|
|
|
if (isset($lease['Lease']['id']))
|
|
$lease_grid_setup['hiddengrid'] = true;
|
|
|
|
$lease_grid_setup['onSelectRow'] = array
|
|
('--special' =>
|
|
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
|
|
);
|
|
|
|
$lease_grid_setup['onHeaderClick'] = array
|
|
('--special' =>
|
|
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
|
|
);
|
|
|
|
?>
|
|
|
|
<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'
|
|
$('#invoice-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() {
|
|
$("#charge-entry-id").val(1);
|
|
|
|
$("#invoice-lease").html("INTERNAL ERROR");
|
|
$("#invoice-unit").html("INTERNAL ERROR");
|
|
$("#invoice-customer").html("INTERNAL ERROR");
|
|
$("#invoice-rent").html("INTERNAL ERROR");
|
|
$("#invoice-late").html("INTERNAL ERROR");
|
|
$("#invoice-deposit").html("INTERNAL ERROR");
|
|
|
|
addChargeSource(false);
|
|
datepickerNow('TransactionStamp');
|
|
}
|
|
|
|
|
|
function onRowSelect(grid_id, lease_id) {
|
|
// Set the item id that will be returned with the form
|
|
$("#lease-id").val(lease_id);
|
|
|
|
// Get the item names from the grid
|
|
$("#invoice-lease").html($(grid_id).getCell(lease_id, 'Lease-number'));
|
|
$("#invoice-unit").html($(grid_id).getCell(lease_id, 'Unit-name'));
|
|
$("#invoice-customer").html($(grid_id).getCell(lease_id, 'Customer-name'));
|
|
$("#invoice-rent").html($(grid_id).getCell(lease_id, 'Lease-rent'));
|
|
$("#invoice-late").html('$10.00');
|
|
$("#invoice-deposit").html($(grid_id).getCell(lease_id, 'Lease-deposit')
|
|
? $(grid_id).getCell(lease_id, 'Lease-deposit')
|
|
: '-');
|
|
|
|
// Hide the "no lease" message and show the current lease
|
|
$("#no-lease").hide();
|
|
$("#current-lease").show();
|
|
|
|
// Collapse the grid now that the user has selected
|
|
$("#leases-list .HeaderButton").click();
|
|
}
|
|
|
|
function onGridState(grid_id, state) {
|
|
if (state == 'visible') {
|
|
$("#no-lease").hide();
|
|
$("#current-lease").hide();
|
|
}
|
|
else {
|
|
if ($("#lease-id").val() > 0) {
|
|
$("#current-lease").show();
|
|
$("#no-lease").hide();
|
|
} else {
|
|
$("#current-lease").hide();
|
|
$("#no-lease").show();
|
|
}
|
|
}
|
|
}
|
|
|
|
function addChargeSource(flash) {
|
|
var id = $("#charge-entry-id").val();
|
|
addDiv('charge-entry-id', 'charge', 'charges', flash,
|
|
// HTML section
|
|
'<FIELDSET CLASS="charge subset">' +
|
|
'<LEGEND>Charge #%{id} (%{remove})</LEGEND>' +
|
|
|
|
<?php
|
|
echo FormatHelper::phpVarToJavascript
|
|
($this->element('form_table',
|
|
array('class' => "item invoice ledger-entry entry",
|
|
//'with_name_after' => ':',
|
|
'field_prefix' => 'LedgerEntry.%{id}',
|
|
'fields' => array
|
|
("account_id" => array('name' => 'Account',
|
|
'opts' =>
|
|
array('options' => $chargeAccounts,
|
|
'value' => $defaultAccount,
|
|
),
|
|
),
|
|
"effective_date" => array('opts' =>
|
|
array('type' => 'text'),
|
|
'between' => '<A HREF="#" ONCLICK="datepickerBOM(\'TransactionStamp\',\'LedgerEntry%{id}EffectiveDate\'); return false;">BOM</A>',
|
|
),
|
|
"through_date" => array('opts' =>
|
|
array('type' => 'text'),
|
|
'between' => '<A HREF="#" ONCLICK="datepickerEOM(\'LedgerEntry%{id}EffectiveDate\',\'LedgerEntry%{id}ThroughDate\'); return false;">EOM</A>',
|
|
),
|
|
"amount" => null,
|
|
"comment" => array('opts' => array('size' => 50)),
|
|
),
|
|
))) . "+\n";
|
|
?>
|
|
|
|
'</FIELDSET>'
|
|
);
|
|
|
|
$("#LedgerEntry"+id+"EffectiveDate")
|
|
.attr('autocomplete', 'off')
|
|
.datepicker({ constrainInput: true,
|
|
numberOfMonths: [1, 1],
|
|
showCurrentAtPos: 0,
|
|
dateFormat: 'mm/dd/yy' });
|
|
|
|
$("#LedgerEntry"+id+"ThroughDate")
|
|
.attr('autocomplete', 'off')
|
|
.datepicker({ constrainInput: true,
|
|
numberOfMonths: [1, 1],
|
|
showCurrentAtPos: 0,
|
|
dateFormat: 'mm/dd/yy' });
|
|
}
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // align
|
|
|
|
echo $this->element('leases',
|
|
array('grid_div_id' => 'leases-list',
|
|
'grid_div_class' => 'text-below',
|
|
'caption' => ('<A HREF="#" ONCLICK="$(\'#leases-list .HeaderButton\').click();'.
|
|
' return false;">Select Lease</A>'),
|
|
'grid_setup' => $lease_grid_setup,
|
|
'nolinks' => true,
|
|
'limit' => 10,
|
|
));
|
|
|
|
echo ('<SPAN id="current-lease" style="display:none">' .
|
|
'<DIV>' .
|
|
'<H2>' .
|
|
'Lease <SPAN id="invoice-lease"></SPAN>' . ' / ' .
|
|
'Unit: <SPAN id="invoice-unit"></SPAN>' . ' / ' .
|
|
'Customer: <SPAN id="invoice-customer"></SPAN>' .
|
|
'</H2>' .
|
|
'</DIV>' .
|
|
'<DIV>' .
|
|
|
|
/* '<H3>' . */
|
|
/* 'Rent: <SPAN id="invoice-rent"></SPAN>' . */
|
|
/* '<BR>' . */
|
|
/* 'Late Fee: <SPAN id="invoice-late"></SPAN>' . */
|
|
/* '<BR>' . */
|
|
/* 'Deposit: <SPAN id="invoice-deposit"></SPAN>' . */
|
|
/* '</H3>' . */
|
|
|
|
/* '<H3>' . */
|
|
/* 'Rent: <SPAN id="invoice-rent"></SPAN>' . ' / ' . */
|
|
/* 'Late Fee: <SPAN id="invoice-late"></SPAN>' . ' / ' . */
|
|
/* 'Deposit: <SPAN id="invoice-deposit"></SPAN>' . */
|
|
/* '</H3>' . */
|
|
|
|
'<H3>' .
|
|
'<TABLE BORDER=0>' .
|
|
'<TR><TD style="width:5em;">Rent:</TD><TD><SPAN id="invoice-rent"></SPAN></TD></TR>' .
|
|
'<TR><TD>Late Fee:</TD><TD><SPAN id="invoice-late"></SPAN></TD></TR>' .
|
|
'<TR><TD>Deposit:</TD><TD><SPAN id="invoice-deposit"></SPAN></TD></TR>' .
|
|
'</TABLE>' .
|
|
'</H3>' .
|
|
'<BR />' .
|
|
|
|
'</DIV>' .
|
|
'</SPAN>' .
|
|
'<SPAN id="no-lease" style="display:none">' .
|
|
'<H2>' .
|
|
'Please select lease' .
|
|
'</H2>' .
|
|
'</SPAN>' .
|
|
"\n");
|
|
|
|
echo $form->create(null, array('id' => 'invoice-form',
|
|
'url' => array('controller' => 'transactions',
|
|
'action' => 'postInvoice')));
|
|
|
|
echo $form->input("Lease.id",
|
|
array('id' => 'lease-id',
|
|
'type' => 'hidden',
|
|
'value' => 0));
|
|
|
|
/* echo '<fieldset CLASS="invoice">' . "\n"; */
|
|
/* echo ' <legend>Invoice</legend>' . "\n"; */
|
|
|
|
echo $this->element('form_table',
|
|
array('class' => "item invoice 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 '</fieldset>' . "\n"; */
|
|
|
|
echo $form->submit('Generate Invoice') . "\n";
|
|
?>
|
|
|
|
<fieldset CLASS="charge superset">
|
|
<legend>Charges</legend>
|
|
<input type="hidden" id="charge-entry-id" value="0">
|
|
<div id="charges"></div>
|
|
<fieldset> <legend>
|
|
<a href="#" onClick="addChargeSource(true); return false;">Add Another Charge</a>
|
|
</legend> </fieldset>
|
|
</fieldset>
|
|
|
|
<?php echo $form->end('Generate Invoice'); ?>
|
|
|
|
<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($lease['Lease']['id'])): ?>
|
|
$("#lease-id").val(<?php echo $lease['Lease']['id']; ?>);
|
|
$("#invoice-lease").html("<?php echo '#'.$lease['Lease']['number']; ?>");
|
|
$("#invoice-unit").html("<?php echo $lease['Unit']['name']; ?>");
|
|
$("#invoice-customer").html("<?php echo $lease['Customer']['name']; ?>");
|
|
$("#invoice-rent").html("<?php echo FormatHelper::currency($lease['Lease']['rent']); ?>");
|
|
$("#invoice-late").html('$10.00');
|
|
$("#invoice-deposit").html("<?php echo FormatHelper::currency($lease['Lease']['deposit']); ?>");
|
|
onGridState(null, 'hidden');
|
|
<?php else: ?>
|
|
onGridState(null, 'visible');
|
|
<?php endif; ?>
|
|
});
|
|
--></script>
|
|
|
|
</div>
|
|
|
|
<a href="#" onClick="$('#debug').html(''); return false;">Clear Debug Output</a>
|