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:
abijah
2009-08-25 01:09:47 +00:00
parent 241028603b
commit 20309fba39
2 changed files with 141 additions and 76 deletions

View File

@@ -186,42 +186,43 @@ class LeasesController extends AppController {
$this->data['Lease']['moveout_date'] $this->data['Lease']['moveout_date']
); );
$this->redirect($this->data['redirect']); $this->redirect(array('controller' => 'leases',
'action' => 'view',
$this->data['Lease']['id']));
} }
if (!isset($id)) if (isset($id)) {
die("Oh Nooooo!!"); $lease = $this->Lease->find
('first', array
('contain' => array
(// Models
'Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
$lease = $this->Lease->find 'Customer' =>
('first', array array('fields' => array('id', 'name'),
('contain' => array ),
(// Models ),
'Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
'Customer' => 'conditions' => array(array('Lease.id' => $id),
array('fields' => array('id', 'name'), 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), $title = ('Lease #' . $lease['Lease']['number'] . ': ' .
array('Lease.close_date' => null), $lease['Unit']['name'] . ': ' .
), $lease['Customer']['name'] . ': Move-Out');
)); }
$this->set('customer', $lease['Customer']); else {
$this->set('unit', $lease['Unit']); $title = 'Move-Out';
$this->set('lease', $lease['Lease']); }
$redirect = array('controller' => 'leases', $this->set(compact('title'));
'action' => 'view',
$id);
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
$lease['Unit']['name'] . ': ' .
$lease['Customer']['name'] . ': Prepare Move-Out');
$this->set(compact('title', 'redirect'));
$this->render('/leases/move'); $this->render('/leases/move');
} }

View File

@@ -26,14 +26,20 @@ $move_type = preg_replace("/.*_/", "", $this->action);
// Reset the form // Reset the form
function resetForm() { function resetForm() {
$("#customer-id").val(0); $("#customer-id").val(0);
$("#move-customer").html("INTERNAL ERROR");
$("#unit-id").val(0); $("#unit-id").val(0);
$("#lease-id").val(0);
$("#move-customer").html("INTERNAL ERROR");
$("#move-unit").html("INTERNAL ERROR"); $("#move-unit").html("INTERNAL ERROR");
$("#move-lease").html("INTERNAL ERROR");
datepickerNow('LeaseMoveDate', false); datepickerNow('LeaseMoveDate', false);
} }
function onRowSelect(grid_id, item_type, item_id) { 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 // Set the item id that will be returned with the form
$("#"+item_type+"-id").val(item_id); $("#"+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')); $("#LeaseDeposit").val($(grid_id).getCell(item_id, 'Unit-deposit'));
} }
// If a unit was selected, update the "Create new customer" link
if (item_type == 'unit') { if (item_type == 'unit') {
$("#customer-selection-new-url").attr $("#customer-selection-new-url").attr
('href', ('href',
@@ -56,6 +63,12 @@ function onRowSelect(grid_id, item_type, item_id) {
+ '/' + $("#unit-id").val()); + '/' + $("#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 // Hide the "no customer" message and show the current customer
$("."+item_type+"-selection-invalid").hide(); $("."+item_type+"-selection-invalid").hide();
$("."+item_type+"-selection-valid").show(); $("."+item_type+"-selection-valid").show();
@@ -87,7 +100,42 @@ function onGridState(grid_id, item_type, state) {
<?php <?php
; // align ; // 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 echo $this->element('customers', array
('config' => array ('config' => array
('grid_div_id' => 'customers-list', ('grid_div_id' => 'customers-list',
@@ -105,30 +153,27 @@ if ($move_type !== 'out') {
'nolinks' => true, 'nolinks' => true,
'limit' => 10, '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">' . '<DIV CLASS="customer-selection-new" style="display:none">' .
$html->link('Create a new Customer', $html->link('Create a new Customer',
array('controller' => 'customers', array('controller' => 'customers',
'action' => 'add', 'action' => 'add',
(empty($unit['id']) ? null : $unit['id'])), (empty($unit['id']) ? null : $unit['id'])),
array('id' => 'customer-selection-new-url')) . array('id' => 'customer-selection-new-url')) .
'</DIV>' . '</DIV>' .
'<DIV CLASS="customer-selection-valid" style="display:none">' . '<DIV CLASS="customer-selection-valid" style="display:none">' .
'Customer: <SPAN id="move-customer"></SPAN>' . 'Customer: <SPAN id="move-customer"></SPAN>' .
'</DIV>' . '</DIV>' .
'<DIV CLASS="customer-selection-invalid" style="display:none">' . '<DIV CLASS="customer-selection-invalid" style="display:none">' .
'Please select customer' . 'Please select customer' .
'</DIV>' . '</DIV>' .
'</DIV>' . "\n"); '</DIV>' . "\n");
if ($move_type !== 'out') {
echo $this->element('units', array echo $this->element('units', array
('config' => array ('config' => array
('grid_div_id' => 'units-list', ('grid_div_id' => 'units-list',
@@ -149,39 +194,40 @@ if ($move_type !== 'out') {
'nolinks' => true, 'nolinks' => true,
'limit' => 10, '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', echo $form->create(null, array('id' => 'move-inout-form',
'url' => array('controller' => 'leases', 'url' => array('controller' => 'leases',
'action' => $move_action))); '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') { if ($move_type === 'out') {
echo $form->input('Lease.id', echo $form->input('Lease.id',
array('type' => 'hidden', array('id' => 'lease-id',
'value' => $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', echo $this->element('form_table',
@@ -245,6 +291,20 @@ echo $form->end('Perform Move ' . ucfirst($move_type));
resetForm(); 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'])): ?> <?php if (isset($customer['id'])): ?>
$("#customer-id").val(<?php echo $customer['id']; ?>); $("#customer-id").val(<?php echo $customer['id']; ?>);
$("#move-customer").html("<?php echo $customer['name']; ?>"); $("#move-customer").html("<?php echo $customer['name']; ?>");
@@ -260,6 +320,10 @@ echo $form->end('Perform Move ' . ucfirst($move_type));
<?php else: ?> <?php else: ?>
onGridState(null, 'unit', 'visible'); onGridState(null, 'unit', 'visible');
<?php endif; ?> <?php endif; ?>
<?php } /* end (move_type === 'out') */ ?>
}); });
--></script> --></script>