I'm still in the middle of moving onto a ledger based system. However, I'm am now changing how transactions and entries relate back to the customer. I'll be using a ledger for each lease (for rent, late charges, security deposits, etc), and a ledger for each customer (for POS, non-specific deposits such as reservations or covering mulitple units, bad debt writeoff, and possibly customer credits, when not obviously lease specific). This coming change might not be in the right direction, so I want to capture the work as is right now. This change set is not fully functional. Many operations do work, but there are obviously transaction problems with units and customers.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@71 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
177
controllers/customers_controller.php
Normal file
177
controllers/customers_controller.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
class CustomersController extends AppController {
|
||||
var $paginate = array('limit' => 100,
|
||||
'group' => 'Customer.id',
|
||||
'order' => array('Customer.name' => 'ASC'));
|
||||
|
||||
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')),
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* override: sideMenuLinks
|
||||
* - Generates controller specific links for the side menu
|
||||
*/
|
||||
function sideMenuLinks() {
|
||||
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: index
|
||||
* - Lists all current tenants
|
||||
*/
|
||||
|
||||
function index() {
|
||||
$this->current();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: current
|
||||
* - Lists all current tenants
|
||||
*/
|
||||
|
||||
function current() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NULL')
|
||||
));
|
||||
|
||||
$title = 'Current Tenants';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('customers', $this->paginate());
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: past
|
||||
* - Lists all past tenants
|
||||
*/
|
||||
|
||||
function past() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'Lease' =>
|
||||
array('fields' => array(),
|
||||
'type' => 'INNER',
|
||||
),
|
||||
),
|
||||
'conditions' => array('Lease.close_date IS NOT NULL')
|
||||
));
|
||||
|
||||
$title = 'Past Tenants';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('customers', $this->paginate());
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: all
|
||||
* - Lists all customers, including non-tenants
|
||||
*/
|
||||
|
||||
function all() {
|
||||
$title = 'All Customers';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('customers', $this->paginate());
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* 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'));
|
||||
}
|
||||
|
||||
$this->Customer->Behaviors->attach('Containable');
|
||||
$this->Customer->contain
|
||||
(array(// Models
|
||||
'Contact' =>
|
||||
array(// Models
|
||||
'ContactPhone',
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
),
|
||||
'Transaction' =>
|
||||
array('order' => array('stamp'),
|
||||
// Models
|
||||
'Entry' =>
|
||||
array(// Models
|
||||
'DebitAccount',
|
||||
'CreditAccount'),
|
||||
),
|
||||
'Lease' =>
|
||||
array('order' => 'movein_date',
|
||||
'conditions' => array('Lease.lease_date IS NOT NULL'),
|
||||
// Models
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$customer = $this->Customer->read(null, $id);
|
||||
//pr($customer);
|
||||
|
||||
$outstanding_deposit = 0;
|
||||
$outstanding_balance = 0;
|
||||
foreach($customer['Transaction'] AS $transaction) {
|
||||
foreach($transaction['Entry'] AS $entry) {
|
||||
if ($entry['DebitAccount']['name'] === 'A/R')
|
||||
$outstanding_balance += $entry['amount'];
|
||||
if ($entry['CreditAccount']['name'] === 'A/R')
|
||||
$outstanding_balance -= $entry['amount'];
|
||||
|
||||
if ($entry['DebitAccount']['name'] === 'Security Deposit')
|
||||
$outstanding_deposit -= $entry['amount'];
|
||||
if ($entry['CreditAccount']['name'] === 'Security Deposit')
|
||||
$outstanding_deposit += $entry['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
||||
|
||||
$title = $customer['Customer']['name'];
|
||||
$this->set(compact('customer', 'title',
|
||||
'outstanding_balance',
|
||||
'outstanding_deposit'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user