Modified move_out to present a grid of leases, so the user can make a selection just as with move-in, invoices, receipts, etc.
git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@771 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -186,42 +186,43 @@ class LeasesController extends AppController {
|
||||
$this->data['Lease']['moveout_date']
|
||||
);
|
||||
|
||||
$this->redirect($this->data['redirect']);
|
||||
$this->redirect(array('controller' => 'leases',
|
||||
'action' => 'view',
|
||||
$this->data['Lease']['id']));
|
||||
}
|
||||
|
||||
if (!isset($id))
|
||||
die("Oh Nooooo!!");
|
||||
if (isset($id)) {
|
||||
$lease = $this->Lease->find
|
||||
('first', array
|
||||
('contain' => array
|
||||
(// Models
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
|
||||
$lease = $this->Lease->find
|
||||
('first', array
|
||||
('contain' => array
|
||||
(// Models
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
'conditions' => array(array('Lease.id' => $id),
|
||||
array('Lease.close_date' => null),
|
||||
),
|
||||
));
|
||||
$this->set('customer', $lease['Customer']);
|
||||
$this->set('unit', $lease['Unit']);
|
||||
$this->set('lease', $lease['Lease']);
|
||||
|
||||
'conditions' => array(array('Lease.id' => $id),
|
||||
array('Lease.close_date' => null),
|
||||
),
|
||||
));
|
||||
$this->set('customer', $lease['Customer']);
|
||||
$this->set('unit', $lease['Unit']);
|
||||
$this->set('lease', $lease['Lease']);
|
||||
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||
$lease['Unit']['name'] . ': ' .
|
||||
$lease['Customer']['name'] . ': Move-Out');
|
||||
}
|
||||
else {
|
||||
$title = 'Move-Out';
|
||||
}
|
||||
|
||||
$redirect = array('controller' => 'leases',
|
||||
'action' => 'view',
|
||||
$id);
|
||||
|
||||
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||
$lease['Unit']['name'] . ': ' .
|
||||
$lease['Customer']['name'] . ': Prepare Move-Out');
|
||||
$this->set(compact('title', 'redirect'));
|
||||
$this->set(compact('title'));
|
||||
$this->render('/leases/move');
|
||||
}
|
||||
|
||||
|
||||
@@ -26,14 +26,20 @@ $move_type = preg_replace("/.*_/", "", $this->action);
|
||||
// Reset the form
|
||||
function resetForm() {
|
||||
$("#customer-id").val(0);
|
||||
$("#move-customer").html("INTERNAL ERROR");
|
||||
$("#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);
|
||||
}
|
||||
|
||||
function onRowSelect(grid_id, item_type, item_id) {
|
||||
cell_name = item_type.charAt(0).toUpperCase() + item_type.substr(1) + "-name";
|
||||
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);
|
||||
@@ -47,6 +53,7 @@ function onRowSelect(grid_id, item_type, item_id) {
|
||||
$("#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',
|
||||
@@ -56,6 +63,12 @@ function onRowSelect(grid_id, item_type, item_id) {
|
||||
+ '/' + $("#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();
|
||||
@@ -87,7 +100,42 @@ function onGridState(grid_id, item_type, state) {
|
||||
<?php
|
||||
; // align
|
||||
|
||||
if ($move_type !== 'out') {
|
||||
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',
|
||||
@@ -105,30 +153,27 @@ if ($move_type !== 'out') {
|
||||
'nolinks' => true,
|
||||
'limit' => 10,
|
||||
)));
|
||||
}
|
||||
|
||||
echo ('<DIV CLASS="move-inout grid-selection-text">' .
|
||||
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-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-valid" style="display:none">' .
|
||||
'Customer: <SPAN id="move-customer"></SPAN>' .
|
||||
'</DIV>' .
|
||||
|
||||
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
|
||||
'Please select customer' .
|
||||
'</DIV>' .
|
||||
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
|
||||
'Please select customer' .
|
||||
'</DIV>' .
|
||||
|
||||
'</DIV>' . "\n");
|
||||
'</DIV>' . "\n");
|
||||
|
||||
|
||||
if ($move_type !== 'out') {
|
||||
echo $this->element('units', array
|
||||
('config' => array
|
||||
('grid_div_id' => 'units-list',
|
||||
@@ -149,39 +194,40 @@ if ($move_type !== 'out') {
|
||||
'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 ('<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',
|
||||
'url' => array('controller' => 'leases',
|
||||
'action' => $move_action)));
|
||||
|
||||
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));
|
||||
|
||||
if ($move_type === 'out') {
|
||||
echo $form->input('Lease.id',
|
||||
array('type' => 'hidden',
|
||||
'value' => $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',
|
||||
@@ -245,6 +291,20 @@ echo $form->end('Perform Move ' . ucfirst($move_type));
|
||||
|
||||
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']; ?>");
|
||||
@@ -260,6 +320,10 @@ echo $form->end('Perform Move ' . ucfirst($move_type));
|
||||
<?php else: ?>
|
||||
onGridState(null, 'unit', 'visible');
|
||||
<?php endif; ?>
|
||||
|
||||
<?php } /* end (move_type === 'out') */ ?>
|
||||
|
||||
|
||||
});
|
||||
--></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user