Merge in from pre_0.1 branch
git-svn-id: file:///svn-source/pmgr/trunk/site@847 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -1,28 +1,34 @@
|
||||
<?php
|
||||
|
||||
class CustomersController extends AppController {
|
||||
var $sidemenu_links =
|
||||
array(array('name' => 'Customers', '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')),
|
||||
array('name' => 'Add Customer', 'url' => array('controller' => 'customers', 'action' => 'add')),
|
||||
);
|
||||
|
||||
//var $components = array('RequestHandler');
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* override: sideMenuLinks
|
||||
* - Generates controller specific links for the side menu
|
||||
* override: addGridViewSideMenuLinks
|
||||
* - Adds grid view navigation side menu links
|
||||
*/
|
||||
function sideMenuLinks() {
|
||||
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||
|
||||
function addGridViewSideMenuLinks() {
|
||||
parent::addGridViewSideMenuLinks();
|
||||
|
||||
$this->addSideMenuLink('Current',
|
||||
array('controller' => 'customers', 'action' => 'current'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('Past',
|
||||
array('controller' => 'customers', 'action' => 'past'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('All',
|
||||
array('controller' => 'customers', 'action' => 'all'), null,
|
||||
'CONTROLLER');
|
||||
|
||||
/* $this->addSideMenuLink('New Customer', */
|
||||
/* array('controller' => 'customers', 'action' => 'add'), null, */
|
||||
/* 'CONTROLLER', $this->new_area); */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -81,19 +87,29 @@ class CustomersController extends AppController {
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function gridDataOrder(&$params, &$model, $index, $direction) {
|
||||
$order = array();
|
||||
$order[] = parent::gridDataOrder($params, $model, $index, $direction);
|
||||
function gridDataFilterTablesConfig(&$params, &$model, $table) {
|
||||
$config = parent::gridDataFilterTablesConfig($params, $model, $table);
|
||||
|
||||
if ($index !== 'PrimaryContact.last_name')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'PrimaryContact.last_name', $direction);
|
||||
if ($index !== 'PrimaryContact.first_name')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'PrimaryContact.first_name', $direction);
|
||||
if ($index !== 'Customer.id')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'Customer.id', $direction);
|
||||
// Special case for Contact; We need the Contact/Customer relationship
|
||||
if ($table == 'Contact')
|
||||
$config = array('fields' => array('ContactsCustomer.type',
|
||||
'ContactsCustomer.active'),
|
||||
'conditions' => array('ContactsCustomer.active' => true),
|
||||
);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
function gridDataOrder(&$params, &$model, $index, $direction) {
|
||||
$order = parent::gridDataOrder($params, $model, $index, $direction);
|
||||
|
||||
// After sorting by whatever the user wants, add these
|
||||
// defaults into the sort mechanism. If we're already
|
||||
// sorting by one of them, it will only be redundant,
|
||||
// and should cause no harm (possible a longer query?)
|
||||
$order[] = 'PrimaryContact.last_name ' . $direction;
|
||||
$order[] = 'PrimaryContact.first_name ' . $direction;
|
||||
$order[] = 'Customer.id ' . $direction;
|
||||
|
||||
return $order;
|
||||
}
|
||||
@@ -111,14 +127,18 @@ class CustomersController extends AppController {
|
||||
* - Sets up the move-in page for the given customer.
|
||||
*/
|
||||
|
||||
function move_in($id = null) {
|
||||
function move_in($id = null, $unit_id = null) {
|
||||
$customer = array();
|
||||
$unit = array();
|
||||
|
||||
if (isset($id)) {
|
||||
if (!empty($id)) {
|
||||
$this->Customer->recursive = -1;
|
||||
$customer = current($this->Customer->read(null, $id));
|
||||
}
|
||||
if (!empty($unit_id)) {
|
||||
$this->Customer->Lease->Unit->recursive = -1;
|
||||
$unit = current($this->Customer->Lease->Unit->read(null, $unit_id));
|
||||
}
|
||||
$this->set(compact('customer', 'unit'));
|
||||
|
||||
$title = 'Customer Move-In';
|
||||
@@ -219,52 +239,71 @@ class CustomersController extends AppController {
|
||||
$outstanding_deposit = $this->Customer->securityDepositBalance($id);
|
||||
|
||||
// Figure out if this customer has any non-closed leases
|
||||
$show_moveout = false;
|
||||
$show_payment = false;
|
||||
$show_moveout = false; $moveout_lease_id = null;
|
||||
$show_payment = false; $payment_lease_id = null;
|
||||
foreach ($customer['Lease'] AS $lease) {
|
||||
if (!isset($lease['close_date']))
|
||||
if (!isset($lease['close_date'])) {
|
||||
if ($show_payment)
|
||||
$payment_lease_id = null;
|
||||
else
|
||||
$payment_lease_id = $lease['id'];
|
||||
$show_payment = true;
|
||||
if (!isset($lease['moveout_date']))
|
||||
}
|
||||
if (!isset($lease['moveout_date'])) {
|
||||
if ($show_moveout)
|
||||
$moveout_lease_id = null;
|
||||
else
|
||||
$moveout_lease_id = $lease['id'];
|
||||
$show_moveout = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set up dynamic menu items
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Edit',
|
||||
'url' => array('action' => 'edit',
|
||||
$id));
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-In',
|
||||
'url' => array('action' => 'move_in',
|
||||
$id));
|
||||
|
||||
/* if ($show_moveout) { */
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Move-Out', */
|
||||
/* 'url' => array('action' => 'move_out', */
|
||||
/* $id)); */
|
||||
/* } */
|
||||
|
||||
if ($show_payment || $outstanding_balance > 0)
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'New Receipt',
|
||||
'url' => array('action' => 'receipt',
|
||||
$id));
|
||||
$this->addSideMenuLink('New Receipt',
|
||||
array('action' => 'receipt', $id), null,
|
||||
'ACTION');
|
||||
|
||||
if ($show_payment) {
|
||||
/* $ids = $this->Customer->leaseIds($id, true); */
|
||||
/* if (count($ids) == 1) */
|
||||
/* $lease_id = $ids[0]; */
|
||||
/* else */
|
||||
/* $lease_id = null; */
|
||||
|
||||
$this->addSideMenuLink('New Invoice',
|
||||
array('controller' => 'leases',
|
||||
'action' => 'invoice',
|
||||
$payment_lease_id), null,
|
||||
'ACTION');
|
||||
}
|
||||
|
||||
$this->addSideMenuLink('Move-In',
|
||||
array('action' => 'move_in', $id), null,
|
||||
'ACTION');
|
||||
|
||||
if ($show_moveout) {
|
||||
$this->addSideMenuLink('Move-Out',
|
||||
array('controller' => 'leases',
|
||||
'action' => 'move_out',
|
||||
$moveout_lease_id), null,
|
||||
'ACTION');
|
||||
}
|
||||
|
||||
if (!$show_moveout && $outstanding_balance > 0)
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Write-Off',
|
||||
'url' => array('action' => 'bad_debt',
|
||||
$id));
|
||||
$this->addSideMenuLink('Write-Off',
|
||||
array('action' => 'bad_debt', $id), null,
|
||||
'ACTION');
|
||||
|
||||
if ($outstanding_balance < 0)
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Issue Refund',
|
||||
'url' => array('action' => 'refund', $id));
|
||||
$this->addSideMenuLink('Issue Refund',
|
||||
array('action' => 'refund', $id), null,
|
||||
'ACTION');
|
||||
|
||||
$this->addSideMenuLink('Edit',
|
||||
array('action' => 'edit', $id), null,
|
||||
'ACTION');
|
||||
|
||||
// Prepare to render.
|
||||
$title = 'Customer: ' . $customer['Customer']['name'];
|
||||
@@ -322,7 +361,17 @@ class CustomersController extends AppController {
|
||||
$this->redirect(array('action'=>'view', $this->Customer->id));
|
||||
|
||||
// Since this is a new customer, go to the move in screen.
|
||||
$this->redirect(array('action'=>'move_in', $this->Customer->id));
|
||||
// First set the move-in unit id, if there is one, ...
|
||||
if (empty($this->data['movein']['Unit']['id']))
|
||||
$unit_id = null;
|
||||
else
|
||||
$unit_id = $this->data['movein']['Unit']['id'];
|
||||
|
||||
// ... then redirect
|
||||
$this->redirect(array('action'=>'move_in',
|
||||
$this->Customer->id,
|
||||
$unit_id,
|
||||
));
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
@@ -385,7 +434,8 @@ class CustomersController extends AppController {
|
||||
* - Add a new customer
|
||||
*/
|
||||
|
||||
function add() {
|
||||
function add($unit_id = null) {
|
||||
$this->set('movein', array('Unit' => array('id' => $unit_id)));
|
||||
$this->edit();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user