git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@525 97e9348a-65ac-dc4b-aefc-98561f571b83
407 lines
14 KiB
PHP
407 lines
14 KiB
PHP
<?php /* -*- mode:PHP -*- */ ?>
|
|
|
|
<div class="invoice input">
|
|
<?php
|
|
; // Editor alignment
|
|
|
|
$unit = $lease['Unit'];
|
|
$customer = $lease['Customer'];
|
|
|
|
if (isset($lease['Lease']))
|
|
$lease = $lease['Lease'];
|
|
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* 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'
|
|
$('#invoice-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.invoice.amount").each(function(i) {
|
|
amount += (+ $(this).val().replace(/\$/,''));
|
|
});
|
|
|
|
$('#results').html('<H3>Invoice Saved<BR>' +
|
|
$("#invoice-customer").html() +
|
|
' : ' + fmtCurrency(amount) +
|
|
'</H3>');
|
|
|
|
if (!$("#repeat").attr("checked")) {
|
|
window.location.href =
|
|
"<?php echo $html->url(array('controller' => 'leases',
|
|
'action' => 'view')); ?>"
|
|
+ "/" + $("#lease-id").val();
|
|
return;
|
|
}
|
|
|
|
// get a clean slate
|
|
//resetForm();
|
|
}
|
|
else {
|
|
$('#results').html('<H2>Failed to save invoice!</H2>');
|
|
alert('Failed to save invoice.');
|
|
}
|
|
}
|
|
|
|
// Reset the form
|
|
function resetForm(nocharge) {
|
|
$('#charge-entry-id').val(1);
|
|
$('#charges').html('');
|
|
|
|
if (!nocharge)
|
|
addChargeSource(false);
|
|
}
|
|
|
|
|
|
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'));
|
|
// 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.
|
|
$("#invoice-lease").html('<A HREF="/pmgr/site/leases/view/' +
|
|
$(grid_id).getCell(lease_id, 'Lease-id').replace(/^#/,'') +
|
|
'">' +
|
|
$(grid_id).getCell(lease_id, 'Lease-number') +
|
|
'</A>');
|
|
$("#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
|
|
$(".lease-selection-invalid").hide();
|
|
$(".lease-selection-valid").show();
|
|
|
|
// Collapse the grid now that the user has selected
|
|
$("#leases-list .HeaderButton").click();
|
|
}
|
|
|
|
function onGridState(grid_id, state) {
|
|
if (state == 'visible') {
|
|
$(".lease-selection-invalid").hide();
|
|
$(".lease-selection-valid").hide();
|
|
}
|
|
else {
|
|
if ($("#lease-id").val() > 0) {
|
|
$(".lease-selection-valid").show();
|
|
$(".lease-selection-invalid").hide();
|
|
} else {
|
|
$(".lease-selection-valid").hide();
|
|
$(".lease-selection-invalid").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('id' => 'Entry%{id}Form',
|
|
'class' => "item invoice ledger-entry entry",
|
|
//'with_name_after' => ':',
|
|
'field_prefix' => 'Entry.%{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\',\'Entry%{id}EffectiveDate\'); return false;">BOM</A>',
|
|
),
|
|
"through_date" => array('opts' =>
|
|
array('type' => 'text'),
|
|
'between' => '<A HREF="#" ONCLICK="datepickerEOM(\'Entry%{id}EffectiveDate\',\'Entry%{id}ThroughDate\'); return false;">EOM</A>',
|
|
),
|
|
"amount" => array('opts' => array('class' => 'invoice amount')),
|
|
"comment" => array('opts' => array('size' => 50)),
|
|
),
|
|
))) . "+\n";
|
|
?>
|
|
|
|
'</FIELDSET>'
|
|
);
|
|
|
|
$("#Entry"+id+"EffectiveDate")
|
|
.attr('autocomplete', 'off')
|
|
.datepicker({ constrainInput: true,
|
|
numberOfMonths: [1, 1],
|
|
showCurrentAtPos: 0,
|
|
dateFormat: 'mm/dd/yy' });
|
|
|
|
$("#Entry"+id+"ThroughDate")
|
|
.attr('autocomplete', 'off')
|
|
.datepicker({ constrainInput: true,
|
|
numberOfMonths: [1, 1],
|
|
showCurrentAtPos: 0,
|
|
dateFormat: 'mm/dd/yy' });
|
|
|
|
return id;
|
|
}
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // align
|
|
// Re-Enable warnings
|
|
Configure::write('debug', $saved_debug_state);
|
|
|
|
echo $this->element('leases', array
|
|
('config' => 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' => array('hiddengrid' => isset($lease['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="invoice grid-selection-text">' .
|
|
|
|
'<DIV CLASS="lease-selection-valid" style="display:none">' .
|
|
'Lease <SPAN id="invoice-lease"></SPAN>' . ' / ' .
|
|
'Unit: <SPAN id="invoice-unit"></SPAN>' . ' / ' .
|
|
'Customer: <SPAN id="invoice-customer"></SPAN>' .
|
|
|
|
'<DIV CLASS="supporting">' .
|
|
'<TABLE>' .
|
|
'<TR><TD CLASS="field">Rent:</TD><TD CLASS="value"><SPAN id="invoice-rent"></SPAN></TD></TR>' .
|
|
'<TR><TD CLASS="field">Late Fee:</TD><TD CLASS="value"><SPAN id="invoice-late"></SPAN></TD></TR>' .
|
|
'<TR><TD CLASS="field">Deposit:</TD><TD CLASS="value"><SPAN id="invoice-deposit"></SPAN></TD></TR>' .
|
|
'</TABLE>' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="lease-selection-invalid" style="display:none">' .
|
|
'Please select lease' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' . "\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 "<BR>\n";
|
|
echo $form->input('repeat', array('type' => 'checkbox',
|
|
'id' => 'repeat',
|
|
'label' => 'Enter Multiple Invoices')) . "\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 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"><!--
|
|
$.fn.removeCol = function(col){
|
|
if(!col){ col = 1; }
|
|
$('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).remove();
|
|
};
|
|
|
|
$(document).ready(function(){
|
|
$("#TransactionStamp")
|
|
.attr('autocomplete', 'off')
|
|
.datepicker({ constrainInput: true,
|
|
numberOfMonths: [1, 1],
|
|
showCurrentAtPos: 0,
|
|
dateFormat: 'mm/dd/yy' });
|
|
|
|
$("#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");
|
|
|
|
<?php if (empty($movein)): ?>
|
|
|
|
resetForm();
|
|
datepickerNow('TransactionStamp');
|
|
|
|
<?php else: ?>
|
|
|
|
var id;
|
|
resetForm(true);
|
|
|
|
$("#TransactionStamp").datepicker('disable');
|
|
$("#TransactionStamp").val("<?php echo date('m/d/Y', $movein['time']); ?>");
|
|
$('#TransactionStamp').after
|
|
('<input type="hidden"' +
|
|
' name="data[Transaction][stamp]"' +
|
|
' value="<?php echo date('m/d/Y', $movein['time']); ?>">');
|
|
$("#TransactionComment").val('Move-In Charges');
|
|
|
|
id = addChargeSource(false);
|
|
$('#Entry'+id+'Form').removeCol(2);
|
|
$('#Entry'+id+'Form input, #Entry'+id+'Form select').attr('disabled', true);
|
|
$('#Entry'+id+'EffectiveDate').val("<?php echo date('m/d/Y', $movein['effective_time']); ?>");
|
|
$('#Entry'+id+'EffectiveDate').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][effective_date]"' +
|
|
' value="<?php echo date('m/d/Y', $movein['effective_time']); ?>">');
|
|
$('#Entry'+id+'AccountId').val(<?php echo $securityDepositAccount; ?>);
|
|
$('#Entry'+id+'AccountId').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][account_id]"' +
|
|
' value="<?php echo $securityDepositAccount; ?>">');
|
|
$('#Entry'+id+'Amount').val("<?php echo FormatHelper::currency($movein['deposit']); ?>");
|
|
$('#Entry'+id+'Amount').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][amount]"' +
|
|
' value="<?php echo FormatHelper::currency($movein['deposit']); ?>">');
|
|
//$('#Entry'+id+'Comment').val('Move-In Security Deposit');
|
|
$('#Entry'+id+'Comment').removeAttr('disabled');
|
|
|
|
|
|
id = addChargeSource(false);
|
|
$('#Entry'+id+'Form').removeCol(2);
|
|
$('#Entry'+id+'Form input, #Entry'+id+'Form select').attr('disabled', true);
|
|
$('#Entry'+id+'EffectiveDate').val("<?php echo date('m/d/Y', $movein['effective_time']); ?>");
|
|
$('#Entry'+id+'EffectiveDate').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][effective_date]"' +
|
|
' value="<?php echo date('m/d/Y', $movein['effective_time']); ?>">');
|
|
$('#Entry'+id+'ThroughDate').val("<?php echo date('m/d/Y', $movein['through_time']); ?>");
|
|
$('#Entry'+id+'ThroughDate').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][through_date]"' +
|
|
' value="<?php echo date('m/d/Y', $movein['through_time']); ?>">');
|
|
$('#Entry'+id+'AccountId').val(<?php echo $rentAccount; ?>);
|
|
$('#Entry'+id+'AccountId').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][account_id]"' +
|
|
' value="<?php echo $rentAccount; ?>">');
|
|
$('#Entry'+id+'Amount').val("<?php echo FormatHelper::currency($movein['prorated_rent']); ?>");
|
|
$('#Entry'+id+'Amount').after
|
|
('<input type="hidden"' +
|
|
' name="data[Entry]['+id+'][amount]"' +
|
|
' value="<?php echo FormatHelper::currency($movein['prorated_rent']); ?>">');
|
|
$('#Entry'+id+'Comment').val('Move-In Rent'
|
|
<?php if ($movein['prorated']) echo "+ ' (Prorated)'" ?>);
|
|
$('#Entry'+id+'Comment').removeAttr('disabled');
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if (isset($lease['id'])): ?>
|
|
$("#lease-id").val(<?php echo $lease['id']; ?>);
|
|
//$("#invoice-lease").html("<?php echo '#'.$lease['number']; ?>");
|
|
$("#invoice-lease").html('<A HREF="/pmgr/site/leases/view/' +
|
|
"<?php echo $lease['id']; ?>" +
|
|
'">#' +
|
|
"<?php echo $lease['number']; ?>" +
|
|
'</A>');
|
|
$("#invoice-unit").html("<?php echo $unit['name']; ?>");
|
|
$("#invoice-customer").html("<?php echo $customer['name']; ?>");
|
|
$("#invoice-rent").html("<?php echo FormatHelper::currency($lease['rent']); ?>");
|
|
$("#invoice-late").html("<?php echo FormatHelper::currency($defaultLate); ?>");
|
|
$("#invoice-deposit").html("<?php echo FormatHelper::currency($lease['deposit']); ?>");
|
|
onGridState(null, 'hidden');
|
|
<?php else: ?>
|
|
onGridState(null, 'visible');
|
|
<?php endif; ?>
|
|
});
|
|
--></script>
|
|
|
|
</div>
|