Files
pmgr/controllers/customers_controller.php

153 lines
5.4 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 jqGridSetup($action, $title) {
$this->set('title', $title); $this->set('heading', $title);
// The resulting page will contain a jqGrid, which will
// use ajax to obtain the actual data for this action
$this->set('action', $action);
$this->render('/elements/customers');
}
function index() { $this->current(); }
function current() { $this->jqGridSetup('current', 'Current Tenants'); }
function past() { $this->jqGridSetup('past', 'Past Tenants'); }
function all() { $this->jqGridSetup('all', 'All Tenants'); }
/**************************************************************************
**************************************************************************
**************************************************************************
* action: jqGridData
* - Fetches the actual data requested by jqGrid as XML
*/
function jqGridData() {
$action = 'all';
if (isset($this->params['url']['action']))
$action = $this->params['url']['action'];
// Set up the basic query
$query = array
('link' =>
array(// Models
'PrimaryContact',
'CurrentLease' => array('fields' => array()),
),
'fields' => 'Customer.*, COUNT(CurrentLease.id) AS lease_count',
);
// Calculate the number of rows for the query, and figure out
// any special query conditions that will be necessary
$records = $this->Customer->find('count', array('contain'=>false));
if ($action != 'all') {
$records_past = $this->Customer->find('count',
array('link' => array('CurrentLease' => array('fields' => array())),
'conditions' => 'CurrentLease.id IS NULL'));
if ($action == 'current') {
$records = $records - $records_past;
$query['conditions'][] = 'CurrentLease.id IS NOT NULL';
}
elseif ($action == 'past') {
$records = $records_past;
$query['conditions'][] = 'CurrentLease.id IS NULL';
}
}
parent::jqGridData($this->Customer, $records, $query);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* 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' => '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;
}
elseif (isset($id)) {
$customer = $this->Customer->details($id);
unset($customer['deposits']['Entries']);
}
else {
$customer = null;
}
$title = 'Payment Entry';
$this->set(compact('customer', 'title'));
}
}