git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@155 97e9348a-65ac-dc4b-aefc-98561f571b83
195 lines
6.7 KiB
PHP
195 lines
6.7 KiB
PHP
<?php
|
|
|
|
class CustomersController extends AppController {
|
|
var $sidemenu_links =
|
|
array(array('name' => 'Tenants', 'header' => true),
|
|
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
|
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
|
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
|
);
|
|
|
|
//var $components = array('RequestHandler');
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* override: sideMenuLinks
|
|
* - Generates controller specific links for the side menu
|
|
*/
|
|
function sideMenuLinks() {
|
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: index / current / past / all
|
|
* - Creates a list of tenants
|
|
*/
|
|
|
|
function index() { $this->current(); }
|
|
function current() { $this->jqGridView('Current Tenants'); }
|
|
function past() { $this->jqGridView('Past Tenants'); }
|
|
function all() { $this->jqGridView('All Tenants', '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(// Models
|
|
'PrimaryContact',
|
|
'CurrentLease' => array('fields' => array()),
|
|
),
|
|
);
|
|
}
|
|
|
|
function jqGridDataFields(&$params, &$model) {
|
|
return array('Customer.*',
|
|
'COUNT(CurrentLease.id) AS lease_count');
|
|
}
|
|
|
|
function jqGridDataConditions(&$params, &$model) {
|
|
$conditions = parent::jqGridDataConditions($params, $model);
|
|
|
|
if ($params['action'] === 'current') {
|
|
$conditions[] = 'CurrentLease.id IS NOT NULL';
|
|
}
|
|
elseif ($params['action'] === 'past') {
|
|
$conditions[] = 'CurrentLease.id IS NULL';
|
|
}
|
|
|
|
return $conditions;
|
|
}
|
|
|
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
|
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
|
if ($index === 'PrimaryContact.last_name') {
|
|
$order[] = 'PrimaryContact.first_name ' . $direction;
|
|
}
|
|
if ($index === 'PrimaryContact.first_name') {
|
|
$order[] = 'PrimaryContact.last_name ' . $direction;
|
|
}
|
|
return $order;
|
|
}
|
|
|
|
function jqGridDataRecordCount(&$params, &$model, $query) {
|
|
|
|
// We don't have a good way to use the query to obtain
|
|
// our count. The problem is that we're relying on the
|
|
// group by for the query, which will destroy the count,
|
|
// whether we omit the group by or leave it in.
|
|
// So, build a fresh query for counting.
|
|
|
|
$query['conditions'] = parent::jqGridDataConditions($params, $model);
|
|
|
|
$count = $model->find('count',
|
|
array_merge(array('link' => array_diff_key($query['link'],
|
|
array('CurrentLease'=>1))),
|
|
array_diff_key($query, array('link'=>1))));
|
|
|
|
if ($params['action'] === 'all')
|
|
return $count;
|
|
|
|
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
|
$count_past = $model->find('count', $query);
|
|
|
|
// Since we can't easily count 'current' directly, we
|
|
// can quickly derive it since 'current' customers
|
|
// are mutually exclusive to 'past' customers.
|
|
if ($params['action'] == 'current')
|
|
$count = $count - $count_past;
|
|
elseif ($params['action'] == 'past') {
|
|
$count = $count_past;
|
|
}
|
|
|
|
return $count;
|
|
}
|
|
|
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
$links['Customer'] = array('name');
|
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: view
|
|
* - Displays information about a specific customer
|
|
*/
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
|
|
$customer = $this->Customer->details($id);
|
|
|
|
$outstanding_balance = $customer['stats']['balance'];
|
|
$outstanding_deposit = $customer['deposits']['summary']['balance'];
|
|
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Operations', 'header' => true);
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Payment', 'url' => array('action' => 'payment', $id));
|
|
$this->sidemenu_links[] =
|
|
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
|
|
|
// Prepare to render.
|
|
$title = $customer['Customer']['name'];
|
|
$this->set(compact('customer', 'title',
|
|
'outstanding_balance',
|
|
'outstanding_deposit'));
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* action: payment
|
|
* - Sets up the payment entry page for the given customer.
|
|
*/
|
|
|
|
function payment($id = null) {
|
|
/* if (!$id) { */
|
|
/* $this->Session->setFlash(__('Invalid Item.', true)); */
|
|
/* $this->redirect(array('action'=>'index')); */
|
|
/* } */
|
|
|
|
/* if ($this->RequestHandler->isPost()) { */
|
|
/* pr($this->data); */
|
|
/* //$this->redirect(array('action'=>'index')); */
|
|
/* $customer = $this->data; */
|
|
/* } */
|
|
if (isset($id)) {
|
|
$customer = $this->Customer->details($id);
|
|
unset($customer['deposits']['Entries']);
|
|
}
|
|
else {
|
|
$customer = null;
|
|
}
|
|
|
|
$title = 'Payment Entry';
|
|
$this->set(compact('customer', 'title'));
|
|
}
|
|
|
|
}
|