git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@250 97e9348a-65ac-dc4b-aefc-98561f571b83
282 lines
9.0 KiB
PHP
282 lines
9.0 KiB
PHP
<?php
|
|
|
|
class LeasesController extends AppController {
|
|
|
|
var $sidemenu_links =
|
|
array(array('name' => 'Leases', 'header' => true),
|
|
array('name' => 'Active', 'url' => array('controller' => 'leases', 'action' => 'active')),
|
|
array('name' => 'Closed', 'url' => array('controller' => 'leases', 'action' => 'closed')),
|
|
array('name' => 'All', 'url' => array('controller' => 'leases', 'action' => 'all')),
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / active / closed / all
|
|
* - Generate a listing of leases
|
|
*/
|
|
|
|
function index() { $this->all(); }
|
|
function active() { $this->jqGridView('Active Leases'); }
|
|
function closed() { $this->jqGridView('Closed Leases'); }
|
|
function all() { $this->jqGridView('All Leases', 'all'); }
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: jqGridData
|
|
* - With the application controller handling the jqGridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function jqGridDataSetup(&$params) {
|
|
parent::jqGridDataSetup($params);
|
|
if (!isset($params['action']))
|
|
$params['action'] = 'all';
|
|
}
|
|
|
|
function jqGridDataTables(&$params, &$model) {
|
|
return array
|
|
('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')),
|
|
'Customer' => array('fields' => array('Customer.id', 'Customer.name'))));
|
|
}
|
|
|
|
function jqGridDataConditions(&$params, &$model) {
|
|
$conditions = parent::jqGridDataConditions($params, $model);
|
|
|
|
if ($params['action'] === 'active') {
|
|
$conditions[] = 'Lease.close_date IS NULL';
|
|
}
|
|
elseif ($params['action'] === 'closed') {
|
|
$conditions[] = 'Lease.close_date IS NOT NULL';
|
|
}
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
$links['Lease'] = array('number');
|
|
$links['Unit'] = array('name');
|
|
$links['Customer'] = array('name');
|
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
function jqGridDataRecords(&$params, &$model, $query) {
|
|
$leases = parent::jqGridDataRecords($params, $model, $query);
|
|
|
|
// Get the balance on each lease.
|
|
foreach ($leases AS &$lease) {
|
|
$stats = $this->Lease->stats($lease['Lease']['id']);
|
|
$lease['Lease']['balance'] = $stats['balance'];
|
|
}
|
|
|
|
return $leases;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: move_in
|
|
* - execute a move in on a new lease
|
|
*/
|
|
|
|
function move_in() {
|
|
if (!$this->data)
|
|
die("Should have some data");
|
|
|
|
// Handle the move in based on the data given
|
|
//pr(array('Move-in data', $this->data));
|
|
|
|
$lid = $this->Lease->moveIn($this->data['Lease']['customer_id'],
|
|
$this->data['Lease']['unit_id'],
|
|
null, null,
|
|
$this->data['Lease']['movein_date'],
|
|
$this->data['Lease']['comment']
|
|
);
|
|
|
|
// Since this is a new lease, go to the invoice
|
|
// screen so we can start assessing charges.
|
|
$this->redirect(array('action'=>'invoice', $lid));
|
|
|
|
// For debugging, only if the redirect above have been
|
|
// commented out, otherwise this section isn't reached.
|
|
$this->render('/empty');
|
|
return;
|
|
}
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* 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'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: invoice
|
|
* - Sets up the invoice entry page for the given customer.
|
|
*/
|
|
|
|
function invoice($id = null, $type = null) {
|
|
|
|
$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),
|
|
),
|
|
));
|
|
|
|
$A = new Account();
|
|
$charge_accounts = $A->chargeAccounts();
|
|
$default_account = $A->rentAccountID();
|
|
$this->set(compact('charge_accounts', 'default_account'));
|
|
|
|
// REVISIT <AP> 20090705:
|
|
// Of course, the late charge should come from the late_schedule
|
|
$default_rent = $lease['Lease']['rent'];
|
|
$default_late = 10;
|
|
$this->set(compact('default_rent', 'default_late'));
|
|
|
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
|
$lease['Unit']['name'] . ': ' .
|
|
$lease['Customer']['name'] . ': Charge Entry');
|
|
$this->set(compact('title', 'lease', 'charge'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific lease
|
|
*/
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
// Get details about the lease and its ledgers (no ledger entries yet)
|
|
$lease = $this->Lease->find
|
|
('first',
|
|
array('contain' =>
|
|
array(// Models
|
|
'LeaseType',
|
|
'Unit',
|
|
'Customer',
|
|
),
|
|
'conditions' => array(array('Lease.id' => $id)),
|
|
)
|
|
);
|
|
|
|
// Obtain the overall lease balance
|
|
$this->Lease->statsMerge($lease['Lease'],
|
|
array('stats' => $this->Lease->stats($id)));
|
|
$outstanding_balance = $lease['Lease']['stats']['balance'];
|
|
|
|
// Determine the lease security deposit
|
|
$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' => 'Charges', 'url' => array('action' => 'invoice',
|
|
$id));
|
|
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Payments', 'url' => array('controller' => 'customers',
|
|
'action' => 'receipt',
|
|
$id));
|
|
}
|
|
|
|
// Prepare to render
|
|
$title = 'Lease: #' . $lease['Lease']['id'];
|
|
$this->set(compact('lease', 'title',
|
|
'outstanding_deposit',
|
|
'outstanding_balance'));
|
|
}
|
|
}
|