Finished basic functionality for Move-Out. This still needs some work to handle the security deposit.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@202 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-02 20:00:50 +00:00
parent 591e1db81d
commit 504f1e7cc0
8 changed files with 352 additions and 57 deletions

View File

@@ -140,6 +140,42 @@ class CustomersController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: move_out
* - prepare to move a customer out of one of their units
*/
function move_out($id) {
$customer = $this->Customer->find
('first', array
('contain' => array
(// Models
'Lease' =>
array('conditions' => array('Lease.moveout_date' => null),
// Models
'Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
),
),
'conditions' => array('Customer.id' => $id),
));
$redirect = array('controller' => 'customers',
'action' => 'view',
$id);
$title = $customer['Customer']['name'] . ': Prepare Move-Out';
$this->set(compact('title', 'customer', 'redirect'));
$this->render('/leases/move_out');
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -158,12 +194,31 @@ class CustomersController extends AppController {
$outstanding_balance = $customer['stats']['balance'];
$outstanding_deposit = $customer['deposits']['summary']['balance'];
// Figure out if this customer has any non-closed leases
$show_moveout = false;
$show_payment = false;
foreach ($customer['Lease'] AS $lease) {
if (!isset($lease['close_date']))
$show_payment = true;
if (!isset($lease['moveout_date']))
$show_moveout = true;
}
// Set up dynamic menu items
if ($show_moveout || $show_payment) {
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
if ($show_moveout) {
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('action' => 'payment', $id));
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
$id));
}
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
array('name' => 'Payment', 'url' => array('action' => 'payment',
$id));
}
// Prepare to render.
$title = $customer['Customer']['name'];

View File

@@ -88,6 +88,57 @@ class LeasesController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: move_out
* - prepare or execute a move out on a specific lease
*/
function move_out($id = null) {
if ($this->data) {
// Handle the move out based on the data given
pr($this->data);
$this->Lease->moveOut($this->data['Lease']['id']);
$this->redirect($this->data['redirect']);
//$this->autoRender = false;
return;
}
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'),
),
'Customer' =>
array('fields' => array('id', 'name'),
),
),
'conditions' => array(array('Lease.id' => $id),
array('Lease.close_date' => null),
),
));
$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', 'lease', 'redirect'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -111,7 +162,6 @@ class LeasesController extends AppController {
'Customer',
),
'conditions' => array(array('Lease.id' => $id)),
'limit' => 2
)
);
@@ -124,6 +174,22 @@ class LeasesController extends AppController {
$deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
$outstanding_deposit = $deposits['summary']['balance'];
// Set up dynamic menu items
if (!isset($lease['Lease']['close_date'])) {
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
if (!isset($lease['Lease']['moveout_date'])) {
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
$id));
}
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('action' => 'payment',
$id));
}
// Prepare to render
$title = 'Lease: #' . $lease['Lease']['id'];
$this->set(compact('lease', 'title',

View File

@@ -53,6 +53,7 @@ class MapsController extends AppController {
$this->redirect(array('action'=>'index'));
}
$this->set('info', $this->mapInfo($id, $requested_width));
$this->set('title', "Site Map");
}

View File

@@ -94,6 +94,42 @@ class UnitsController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: move_out
* - prepare or execute a move out on a specific lease
*/
function move_out($id) {
$unit = $this->Unit->find
('first', array
('contain' => array
(// Models
'CurrentLease' =>
array(//'conditions' => array('Lease.moveout_date' => null),
// Models
'Customer' =>
array('fields' => array('id', 'name'),
),
),
),
'conditions' => array('Unit.id' => $id),
));
$redirect = array('controller' => 'units',
'action' => 'view',
$id);
$title = ('Lease' . $unit['CurrentLease']['number'] . ': ' .
$unit['Unit']['name'] . ': ' .
$unit['CurrentLease']['Customer']['name'] . ': Prepare Move-Out');
$this->set(compact('title', 'unit', 'redirect'));
$this->render('/leases/move_out');
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -137,10 +173,22 @@ class UnitsController extends AppController {
$outstanding_deposit = $deposits['summary']['balance'];
}
// Set up dynamic menu items
if (isset($unit['CurrentLease']['id']) &&
!isset($unit['CurrentLease']['close_date'])) {
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
if (!isset($unit['CurrentLease']['moveout_date'])) {
$this->sidemenu_links[] =
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
$id));
}
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('action' => 'payment',
$id));
}
// Prepare to render.
$title = 'Unit ' . $unit['Unit']['name'];

View File

@@ -31,9 +31,6 @@ class Lease extends AppModel {
var $hasMany = array(
'LedgerEntry',
// Cheat to get Account set as part of this class
'Account',
);
@@ -44,7 +41,8 @@ class Lease extends AppModel {
* - Returns the accountId of the given lease
*/
function accountId($id) {
return $this->Account->invoiceAccountID();
$A = new Account();
return $A->invoiceAccountID();
}
@@ -64,7 +62,8 @@ class Lease extends AppModel {
$cond = array();
$cond[] = array('LedgerEntry.lease_id' => $id);
$entries = $this->Account->findLedgerEntries($this->accountId($id),
$A = new Account();
$entries = $A->findLedgerEntries($this->accountId($id),
$all, $cond, $link);
/* pr(array('function' => 'Lease::findAccountEntries', */
@@ -87,9 +86,10 @@ class Lease extends AppModel {
/* 'args' => compact('id', 'link'), */
/* )); */
$entries = $this->Account->findLedgerEntriesRelatedToAccount
$A = new Account();
$entries = $A->findLedgerEntriesRelatedToAccount
($this->accountId($id),
$this->Account->securityDepositAccountID(),
$A->securityDepositAccountID(),
true, array('LedgerEntry.lease_id' => $id), $link);
/* pr(array('function' => 'Lease::findSecurityDeposits', */
@@ -110,7 +110,8 @@ class Lease extends AppModel {
*/
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
return $this->Account->findUnreconciledLedgerEntries
$A = new Account();
return $A->findUnreconciledLedgerEntries
($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id));
}
@@ -130,11 +131,42 @@ class Lease extends AppModel {
*/
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
return $this->Account->reconcileNewLedgerEntry
$A = new Account();
return $A->reconcileNewLedgerEntry
($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: moveOut
* - Moves the customer out of the specified lease
*/
function moveOut($id = null, $status = 'VACANT',
$stamp = null, $close = false) {
$this->create(false);
$this->id = $id;
// Use NOW if not given a moveout date
if (!isset($stamp))
$stamp = date('Y-m-d G:i:s');
// Move customer out of the lease, and possibly close it
$this->data['Lease']['moveout_date'] = $stamp;
if ($close)
$this->data['Lease']['close_date'] = $stamp;
// Save it!
$this->save($this->data, false);
// Finally, update the unit status
$this->recursive = -1;
$this->read();
$this->Unit->updateStatus($this->data['Lease']['unit_id'], $status);
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -146,7 +178,8 @@ class Lease extends AppModel {
if (!$id)
return null;
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
$A = new Account();
$stats = $A->stats($A->accountReceivableAccountID(), true,
array('LedgerEntry.lease_id' => $id));
// Pull to the top level and return

View File

@@ -19,7 +19,7 @@ class Unit extends AppModel {
var $hasOne = array(
'CurrentLease' => array(
'className' => 'Lease',
'conditions' => 'CurrentLease.close_date IS NULL',
'conditions' => 'CurrentLease.moveout_date IS NULL',
),
);
@@ -27,6 +27,12 @@ class Unit extends AppModel {
'Lease',
);
/**************************************************************************
**************************************************************************
**************************************************************************
* helpers: status enumerations
*/
function statusEnums() {
static $status_enums;
if (!isset($status_enums))
@@ -58,6 +64,18 @@ class Unit extends AppModel {
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: updateStatus
* - Update the given unit to the given status
*/
function updateStatus($id, $status) {
$this->id = $id;
pr(compact('id', 'status'));
$this->saveField('status', $status);
}
/**************************************************************************
**************************************************************************
**************************************************************************

View File

@@ -0,0 +1,72 @@
<?php /* -*- mode:PHP -*- */
$multiple = false;
$class = 'move-out';
if (isset($lease)) {
$class .= ' lease';
$data = $lease;
}
elseif (isset($customer) && count($customer['Lease']) == 1) {
$class .= ' customer';
$data = array_diff_key($customer, array('Lease'=>1));
$data['Lease'] = array_diff_key($customer['Lease'][0], array('Unit'=>1));
$data['Unit'] = $customer['Lease'][0]['Unit'];
}
elseif (isset($customer)) {
$class .= ' customer';
$data = $customer;
$multiple = true;
}
elseif (isset($unit)) {
$class .= ' unit';
$data = array_diff_key($unit, array('CurrentLease'=>1));
$data['Lease'] = array_diff_key($unit['CurrentLease'], array('Customer'=>1));
$data['Customer'] = $unit['CurrentLease']['Customer'];
}
else {
die("INTERNAL ERROR");
}
//pr(compact('customer', 'lease', 'unit', 'class', 'multiple', 'data', 'redirect'));
echo '<div class="'.$class.'">' . "\n";
echo('<H2>Move Out: '. $data['Customer']['name'] .
(!$multiple ? ': Unit ' . $data['Unit']['name'] : '') .
'</H2>' . "\n");
echo('<P>Be sure that you really want to move this customer out, ' .
($multiple ? 'select the correct unit to move out of, ' : '') .
'and press the "Perform Move Out" button.' . "\n");
echo '<P><BR>' . "\n";
echo $form->create(null, array('id' => 'move-out-form',
'url' => array('controller' => 'leases',
'action' => 'move_out')));
if ($multiple) {
$options = array();
foreach ($data['Lease'] AS $lease)
$options[$lease['id']] = $lease['Unit']['name'];
echo $form->input('Lease.id', array('label' => 'Move Out of Unit: ',
'options' => $options));
}
else {
echo $form->input('Lease.id',
array('type' => 'hidden',
'value' => $data['Lease']['id'],
));
}
// Set up a redirect page. I use lower case 'redirect' here
// to avoid the model convention, which starts with upper-case.
foreach ($redirect AS $name => $value) {
echo $form->input("redirect.$name",
array('type' => 'hidden',
'value' => $value,
));
}
echo $form->end('Perform Move Out');
// End page div
echo '</div>' . "\n";

View File

@@ -59,14 +59,16 @@ echo $this->element('leases',
/**********************************************************************
* Current Tenant Lease Account History
*/
echo $this->element('ledger_entries',
array('caption' => ('Current Lease Account (' .
$unit['CurrentLease']['Customer']['name']
if (isset($unit['CurrentLease']['id'])) {
echo $this->element('ledger_entries',
array('caption' =>
('Current Lease Account ('
. $unit['CurrentLease']['Customer']['name']
. ')'),
'ar_account' => true,
'lease_id' => $unit['CurrentLease']['id'],
));
}
/* End "detail supporting" div */