359 lines
11 KiB
PHP
359 lines
11 KiB
PHP
<?php /* -*- mode:PHP -*- */
|
|
|
|
$move_action = $this->action;
|
|
//$move_class = preg_replace("/_/", "-", $this->action);
|
|
//$move_date = preg_replace("/_/", "", $this->action) . "_date";
|
|
$move_type = preg_replace("/.*_/", "", $this->action);
|
|
|
|
?>
|
|
|
|
<div class="move-inout input">
|
|
|
|
<?php
|
|
; // Editor alignment
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Javascript
|
|
*/
|
|
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
|
|
// Reset the form
|
|
function resetForm() {
|
|
$("#customer-id").val(0);
|
|
$("#unit-id").val(0);
|
|
$("#lease-id").val(0);
|
|
$("#move-customer").html("INTERNAL ERROR");
|
|
$("#move-unit").html("INTERNAL ERROR");
|
|
$("#move-lease").html("INTERNAL ERROR");
|
|
datepickerNow('LeaseMoveDate', false);
|
|
}
|
|
|
|
// pre-submit callback
|
|
function verifyRequest() {
|
|
//$("#debug").html('');
|
|
<?php if ($move_type === 'out'): ?>
|
|
|
|
if (!($("#lease-id").val() > 0)) {
|
|
//$("#debug").append('<P>Missing Lease ID');
|
|
alert("Please select the lease");
|
|
return false;
|
|
}
|
|
|
|
<?php else: ?>
|
|
|
|
if (!($("#customer-id").val() > 0)) {
|
|
//$("#debug").append('<P>Missing Customer ID');
|
|
alert("Please select the customer");
|
|
return false;
|
|
}
|
|
|
|
if (!($("#unit-id").val() > 0)) {
|
|
//$("#debug").append('<P>Missing Unit ID');
|
|
alert("Please select the unit");
|
|
return false;
|
|
}
|
|
|
|
<?php endif; ?>
|
|
|
|
//$("#debug").append('OK');
|
|
//return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
function onRowSelect(grid_id, item_type, item_id) {
|
|
cell_name = item_type.charAt(0).toUpperCase() + item_type.substr(1);
|
|
if (item_type == 'lease')
|
|
cell_name += "-number";
|
|
else
|
|
cell_name += "-name";
|
|
|
|
// Set the item id that will be returned with the form
|
|
$("#"+item_type+"-id").val(item_id);
|
|
|
|
// Get the item name from the grid
|
|
$("#move-"+item_type).html($(grid_id).getCell(item_id, cell_name));
|
|
|
|
// If a unit was selected, update the rent and deposit
|
|
if (item_type == 'unit') {
|
|
$("#LeaseRent").val($(grid_id).getCell(item_id, 'Unit-rent'));
|
|
$("#LeaseDeposit").val($(grid_id).getCell(item_id, 'Unit-deposit'));
|
|
}
|
|
|
|
// If a unit was selected, update the "Create new customer" link
|
|
if (item_type == 'unit') {
|
|
$("#customer-selection-new-url").attr
|
|
('href',
|
|
"<?php echo
|
|
$html->url(array('controller' => 'customers',
|
|
'action' => 'add')); ?>"
|
|
+ '/' + $("#unit-id").val());
|
|
}
|
|
|
|
// If a lease was selected, update the customer and unit
|
|
if (item_type == 'lease') {
|
|
$("#move-unit").html($(grid_id).getCell(item_id, 'Unit-name'));
|
|
$("#move-customer").html($(grid_id).getCell(item_id, 'Customer-name'));
|
|
}
|
|
|
|
// Hide the "no customer" message and show the current customer
|
|
$("."+item_type+"-selection-invalid").hide();
|
|
$("."+item_type+"-selection-valid").show();
|
|
|
|
$("#"+item_type+"s-list .HeaderButton").click();
|
|
}
|
|
|
|
function onGridState(grid_id, item_type, state) {
|
|
if (state == 'visible') {
|
|
$("."+item_type+"-selection-new").show();
|
|
$("."+item_type+"-selection-invalid").hide();
|
|
$("."+item_type+"-selection-valid").hide();
|
|
}
|
|
else {
|
|
$("."+item_type+"-selection-new").hide();
|
|
if ($("#"+item_type+"-id").val() > 0) {
|
|
$("."+item_type+"-selection-invalid").hide();
|
|
$("."+item_type+"-selection-valid").show();
|
|
} else {
|
|
$("."+item_type+"-selection-invalid").show();
|
|
$("."+item_type+"-selection-valid").hide();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // align
|
|
|
|
if ($move_type === 'out') {
|
|
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"), "lease", ids);}'),
|
|
'onHeaderClick' =>
|
|
array('gridstate' =>
|
|
'onGridState("#"+$(this).attr("id"), "lease", gridstate)'),
|
|
),
|
|
'exclude' => array('Closed'),
|
|
'action' => 'active',
|
|
'nolinks' => true,
|
|
'limit' => 10,
|
|
)));
|
|
|
|
echo ('<DIV CLASS="move-inout grid-selection-text">' .
|
|
|
|
'<DIV CLASS="lease-selection-valid" style="display:none">' .
|
|
'Lease <SPAN id="move-lease"></SPAN>' . ' / ' .
|
|
'Unit: <SPAN id="move-unit"></SPAN>' . ' / ' .
|
|
'Customer: <SPAN id="move-customer"></SPAN>' .
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="lease-selection-invalid" style="display:none">' .
|
|
'Please select lease' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' . "\n");
|
|
}
|
|
else {
|
|
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"), "customer", ids);}'),
|
|
'onHeaderClick' =>
|
|
array('gridstate' =>
|
|
'onGridState("#"+$(this).attr("id"), "customer", gridstate)'),
|
|
),
|
|
'nolinks' => true,
|
|
'limit' => 10,
|
|
)));
|
|
|
|
echo ('<DIV CLASS="move-inout grid-selection-text">' .
|
|
|
|
'<DIV CLASS="customer-selection-new" style="display:none">' .
|
|
$html->link('Create a new Customer',
|
|
array('controller' => 'customers',
|
|
'action' => 'add',
|
|
(empty($unit['id']) ? null : $unit['id'])),
|
|
array('id' => 'customer-selection-new-url')) .
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="customer-selection-valid" style="display:none">' .
|
|
'Customer: <SPAN id="move-customer"></SPAN>' .
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
|
|
'Please select customer' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' . "\n");
|
|
|
|
echo $this->element('units', array
|
|
('config' => array
|
|
('grid_div_id' => 'units-list',
|
|
'grid_div_class' => 'text-below',
|
|
'caption' => ('<A HREF="#" ONCLICK="$(\'#units-list .HeaderButton\').click();'.
|
|
' return false;">Select Unit</A>'),
|
|
'grid_setup' => array('hiddengrid' => isset($unit['id'])),
|
|
'grid_events' => array('onSelectRow' =>
|
|
array('ids' =>
|
|
'if (ids != null){onRowSelect("#"+$(this).attr("id"), "unit", ids);}'),
|
|
'onHeaderClick' =>
|
|
array('gridstate' =>
|
|
'onGridState("#"+$(this).attr("id"), "unit", gridstate)'),
|
|
),
|
|
'include' => array('Deposit'),
|
|
'exclude' => array('Balance'),
|
|
'action' => 'vacant',
|
|
'nolinks' => true,
|
|
'limit' => 10,
|
|
)));
|
|
|
|
echo ('<DIV CLASS="move-inout grid-selection-text">' .
|
|
|
|
'<DIV CLASS="unit-selection-valid" style="display:none">' .
|
|
'Unit: <SPAN id="move-unit"></SPAN>' .
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="unit-selection-invalid" style="display:none">' .
|
|
'Please select unit' .
|
|
'</DIV>' .
|
|
|
|
'</DIV>' . "\n");
|
|
}
|
|
|
|
echo $form->create(null, array('id' => 'move-inout-form',
|
|
'onsubmit' => 'return verifyRequest();',
|
|
'url' => array('controller' => 'leases',
|
|
'action' => $move_action)));
|
|
|
|
if ($move_type === 'out') {
|
|
echo $form->input('Lease.id',
|
|
array('id' => 'lease-id',
|
|
'type' => 'hidden',
|
|
'value' => 0));
|
|
}
|
|
else {
|
|
echo $form->input("Lease.customer_id",
|
|
array('id' => 'customer-id',
|
|
'type' => 'hidden',
|
|
'value' => 0));
|
|
|
|
echo $form->input("Lease.unit_id",
|
|
array('id' => 'unit-id',
|
|
'type' => 'hidden',
|
|
'value' => 0));
|
|
}
|
|
|
|
echo $this->element('form_table',
|
|
array('class' => "item move-inout entry",
|
|
'field_prefix' => 'Lease',
|
|
'fields' => array
|
|
('move'.$move_type.'_date' =>
|
|
array('opts' =>
|
|
array('type' => 'text',
|
|
'id' => "LeaseMoveDate"),
|
|
'between' => '<A HREF="#" ONCLICK="datepickerNow(\'LeaseMoveDate\', false); return false;">Now</A>',
|
|
),
|
|
) +
|
|
($move_type === 'in' ? array
|
|
("deposit" =>
|
|
array('opts' => array
|
|
('value' => (!empty($unit)
|
|
? FormatHelper::currency($unit['deposit'])
|
|
: null))),
|
|
"rent" =>
|
|
array('opts' => array
|
|
('value' => (!empty($unit)
|
|
? FormatHelper::currency($unit['rent'])
|
|
: null))),
|
|
) : array()) + array
|
|
("comment" =>
|
|
($move_type !== 'out'
|
|
? array('opts' => array('size' => 50))
|
|
: null),
|
|
)));
|
|
|
|
if ($move_type === 'out') {
|
|
echo('<P><BR>Be sure that you really want to move this customer out of the unit,<BR>' .
|
|
'select the correct moveout date,' .
|
|
'and press the "Perform Move Out" button.' . "\n");
|
|
}
|
|
|
|
// Set up a redirect page. I use lower case 'redirect' here
|
|
// to avoid the model convention, which starts with upper-case.
|
|
if (isset($redirect)) {
|
|
foreach ($redirect AS $name => $value) {
|
|
echo $form->input("redirect.$name",
|
|
array('type' => 'hidden',
|
|
'value' => $value,
|
|
));
|
|
}
|
|
}
|
|
|
|
echo $form->end('Perform Move ' . ucfirst($move_type));
|
|
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
$(document).ready(function(){
|
|
datepicker('LeaseMoveDate');
|
|
resetForm();
|
|
|
|
<?php if ($move_type === 'out') { ?>
|
|
|
|
<?php if (isset($lease['id'])): ?>
|
|
$("#lease-id").val(<?php echo $lease['id']; ?>);
|
|
$("#move-lease").html("#<?php echo $lease['number']; ?>");
|
|
$("#move-customer").html("<?php echo $customer['name']; ?>");
|
|
$("#move-unit").html("<?php echo $unit['name']; ?>");
|
|
onGridState(null, 'lease', 'hidden');
|
|
<?php else: ?>
|
|
onGridState(null, 'lease', 'visible');
|
|
<?php endif; ?>
|
|
|
|
<?php } else { /* end (move_type === 'out') */ ?>
|
|
|
|
<?php if (isset($customer['id'])): ?>
|
|
$("#customer-id").val(<?php echo $customer['id']; ?>);
|
|
$("#move-customer").html("<?php echo $customer['name']; ?>");
|
|
onGridState(null, 'customer', 'hidden');
|
|
<?php else: ?>
|
|
onGridState(null, 'customer', 'visible');
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($unit['id'])): ?>
|
|
$("#unit-id").val(<?php echo $unit['id']; ?>);
|
|
$("#move-unit").html("<?php echo $unit['name']; ?>");
|
|
onGridState(null, 'unit', 'hidden');
|
|
<?php else: ?>
|
|
onGridState(null, 'unit', 'visible');
|
|
<?php endif; ?>
|
|
|
|
<?php } /* end (move_type === 'out') */ ?>
|
|
|
|
|
|
});
|
|
--></script>
|
|
|
|
</div>
|