Added lease and ledger_entry controllers/views. Minor bugfixes as well.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@85 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-10 08:53:22 +00:00
parent 4277962e3b
commit f8eb45a0b9
10 changed files with 427 additions and 38 deletions

View File

@@ -35,13 +35,14 @@
* @subpackage cake.app
*/
class AppController extends Controller {
var $helpers = array('Html', 'Format');
var $helpers = array('Html', 'Format', 'Time');
function sideMenuLinks() {
return array(
array('name' => 'Common', 'header' => true),
array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)),
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')),
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')),

View File

@@ -0,0 +1,152 @@
<?php
class LeasesController extends AppController {
var $paginate = array
('limit' => 100,
'group' => 'Lease.id',
'order' => array('Lease.movein_date' => 'DESC'));
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
* - Lists current leases
*/
function index() {
$this->active();
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: active
* - Lists all active leases
*/
function active() {
$leases = $this->paginate(array('Lease.close_date IS NULL'));
// Get the balance on each lease.
foreach ($leases AS &$lease) {
$stats = $this->Lease->stats($lease['Lease']['id']);
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'Active Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: closed
* - Lists all closed (inactive) leases
*/
function closed() {
$leases = $this->paginate(array('Lease.close_date IS NOT NULL'));
// Get the balance on each lease.
foreach ($leases AS &$lease) {
$stats = $this->Lease->stats($lease['Lease']['id']);
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'Past Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: all
* - Lists all leases
*/
function all() {
$leases = $this->paginate();
// Get the balance on each lease.
foreach ($leases AS &$lease) {
$stats = $this->Lease->stats($lease['Lease']['id']);
$lease['Lease']['balance'] = $stats['Account']['Ledger']['balance'];
}
$title = 'All Leases';
$this->set('title', $title); $this->set('heading', $title);
$this->set('leases', $leases);
$this->render('index');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* 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)
$this->Lease->Behaviors->attach('Containable');
$lease = $this->Lease->find
('first',
array('contain' =>
array(// Models
'LeaseType',
'Unit',
'Account' => array('Ledger'),
'Customer',
),
'conditions' => array(array('Lease.id' => $id)),
'limit' => 2
)
);
$this->Lease->Behaviors->detach('Containable');
// Summarize each ledger
$this->Lease->statsMerge($lease,
$this->Lease->stats($lease['Lease']['id']));
// Obtain the overall lease balance
$this->Lease->statsMerge($lease['Lease'],
array('stats' => $this->Lease->stats($id)));
$balance = $lease['Lease']['stats']['Account']['Ledger']['balance'];
// Prepare to render
$title = 'Lease: #' . $lease['Lease']['id'];
$this->set(compact('lease', 'title', 'balance'));
}
}

View File

@@ -5,11 +5,7 @@ class LedgerEntriesController extends AppController {
'group' => 'Entry.id',
'order' => array('Entry.stamp' => 'ASC'));
var $sidemenu_links =
array(array('name' => 'Entries', 'header' => true),
array('name' => 'Cleared', 'url' => array('controller' => 'ledger_entries', 'action' => 'cleared')),
array('name' => 'Unresolved', 'url' => array('controller' => 'ledger_entries', 'action' => 'unresolved')),
);
var $sidemenu_links = array();
/**************************************************************************
@@ -36,22 +32,56 @@ class LedgerEntriesController extends AppController {
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
}
// Get the LedgerEntry and related fields
$this->LedgerEntry->Behaviors->attach('Containable');
$this->LedgerEntry->contain
(array(// Models
'MonetarySource' => array('MonetaryType'),
'Transaction',
'DebitLedger',
'CreditLedger',
)
);
$entry = $this->LedgerEntry->read(null, $id);
$entry = $this->LedgerEntry->find
('first',
array('contain' => array('MonetarySource.id',
'MonetarySource.MonetaryType.id',
'Transaction.id',
'Transaction.stamp',
'DebitLedger.id',
'DebitLedger.sequence',
'DebitLedger.account_id',
'CreditLedger.id',
'CreditLedger.sequence',
'CreditLedger.account_id',
),
'fields' => array('LedgerEntry.id',
'LedgerEntry.amount',
'LedgerEntry.comment'),
));
$this->LedgerEntry->Behaviors->detach('Containable');
$title = "Entry #{$entry['LedgerEntry']['id']} ({$entry['LedgerEntry']['name']})";
$this->set(compact('entry', 'title'));
// Because 'DebitLedger' and 'CreditLedger' both relate to 'Account',
// CakePHP will not include them in the LedgerEntry->find (or so it
// seems). We'll have to break out each Account separately.
pr($entry);
$this->autoRender = false;
// Get the Account from DebitLedger
$this->LedgerEntry->DebitLedger->Account->Behaviors->attach('Containable');
$account = $this->LedgerEntry->DebitLedger->Account->find
('first',
array('contain' => true,
'fields' => array('Account.id', 'Account.name', 'Account.type'),
'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']),
));
$entry['DebitLedger'] = array_merge($entry['DebitLedger'], $account);
$this->LedgerEntry->DebitLedger->Account->Behaviors->detach('Containable');
// Get the Account from CreditLedger
$this->LedgerEntry->CreditLedger->Account->Behaviors->attach('Containable');
$account = $this->LedgerEntry->CreditLedger->Account->find
('first',
array('contain' => true,
'fields' => array('Account.id', 'Account.name', 'Account.type'),
'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']),
));
$entry['CreditLedger'] = array_merge($entry['CreditLedger'], $account);
$this->LedgerEntry->CreditLedger->Account->Behaviors->detach('Containable');
// Prepare to render.
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
$this->set(compact('entry', 'title'));
}
}

View File

@@ -100,9 +100,22 @@ class TransactionsController extends AppController {
$this->Transaction->Behaviors->attach('Containable');
$this->Transaction->contain
(array(// Models
'LedgerEntry' => array(//Models
'DebitLedger',
'CreditLedger',
'LedgerEntry' => array('fields' => array('LedgerEntry.id',
'LedgerEntry.amount',
'LedgerEntry.comment'),
//Models
'DebitLedger' => array
('fields' => array('DebitLedger.id', 'DebitLedger.sequence'),
'Account' => array
('fields' => array('Account.id', 'Account.name')),
),
'CreditLedger' => array
('fields' => array('CreditLedger.id', 'CreditLedger.sequence'),
'Account' => array
('fields' => array('Account.id', 'Account.name')),
),
),
)
);

View File

@@ -9,10 +9,10 @@ class Lease extends AppModel {
'unit_id' => array('numeric'),
'late_schedule_id' => array('numeric'),
'lease_date' => array('date'),
'movein_planed_date' => array('date'),
'movein_planned_date' => array('date'),
'movein_date' => array('date'),
'moveout_date' => array('date'),
'moveout_planed_date' => array('date'),
'moveout_planned_date' => array('date'),
'notice_given_date' => array('date'),
'notice_received_date' => array('date'),
'close_date' => array('date'),

View File

@@ -17,14 +17,17 @@ foreach (array_intersect($headers, array('Lease', 'Unit')) AS $k => $v) {
foreach (array_intersect($headers, array('Balance')) AS $k => $v) {
$column_class[$k] = 'currency';
}
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
$column_class[$k] = 'slack';
}
if (isset($paginator)) {
echo $paginator->counter(array('format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$headers = array_merge(array($paginator->sort('Lease')),
isset($leases[0]['Unit'])
? $paginator->sort('Unit', 'Unit.id')
: $paginator->sort('Customer.id'),
? array($paginator->sort('Unit', 'Unit.id'))
: array($paginator->sort('Customer.id')),
array($paginator->sort('Signed', 'lease_date'),
$paginator->sort('Move-In', 'movein_date'),
$paginator->sort('Move-Out', 'moveout_date'),

View File

@@ -0,0 +1,3 @@
<div class="leases index">
<?php echo $this->element('leases', array('heading' => '<h2>'.$heading.'</h2>')) ?>
</div>

View File

@@ -0,0 +1,94 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="lease view">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Lease Detail Main Section
*/
$lease_type = $lease['LeaseType'];
$customer = $lease['Customer'];
$account = $lease['Account'];
$unit = $lease['Unit'];
if (isset($lease['Lease']))
$lease = $lease['Lease'];
$rows = array(array('ID', $lease['id']),
array('Number', $lease['number']),
array('Lease Type', $lease_type['name']),
array('Unit', $html->link($unit['id'],
array('controller' => 'units',
'action' => 'view',
$unit['id']))),
array('Customer', $html->link($customer['name'],
array('controller' => 'customers',
'action' => 'view',
$customer['id']))),
array('Lease_Date', FormatHelper::date($lease['lease_date'])),
array('Move-in Planned', FormatHelper::date($lease['movein_planned_date'])),
array('Move-in', (FormatHelper::date($lease['movein_date'])
. ' ('
. $time->timeAgoInWords($lease['movein_date'],
array('end' => '+99 years'))
. ')')),
array('Move-out', (FormatHelper::date($lease['moveout_date'])
. ' ('
. $time->timeAgoInWords($lease['moveout_date'],
array('end' => '+99 years'))
. ')')),
array('Move-out Planned', FormatHelper::date($lease['moveout_planned_date'])),
array('Notice Given', FormatHelper::date($lease['notice_given_date'])),
array('Notice Received', FormatHelper::date($lease['notice_received_date'])),
array('Closed', FormatHelper::date($lease['close_date'])),
array('Account', $html->link($account['name'],
array('controller' => 'accounts',
'action' => 'view',
$account['id']))),
array('Deposit', (FormatHelper::currency($lease['deposit']))),
array('Rent', (FormatHelper::currency($lease['amount']))),
array('Comment', $lease['comment']));
echo $this->element('table',
array('class' => 'item account detail',
'caption' => 'Account Detail',
'rows' => $rows,
'column_class' => array('field', 'value')));
/**********************************************************************
* Account Info Box
*/
?>
<DIV CLASS="infobox">
<DIV CLASS="summary balance">
Account Balance: <?php echo FormatHelper::currency($balance); ?>
</DIV>
</DIV>
<DIV CLASS="detail supporting">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Supporting Elements Section
*/
/* End "detail supporting" DIV */ ?>
</DIV>
</div>

View File

@@ -0,0 +1,77 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="ledger-entry view">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* LedgerEntry Detail Main Section
*/
$rows = array(array('ID', $entry['LedgerEntry']['id']),
array('Transaction', $html->link('#'.$entry['Transaction']['id'],
array('controller' => 'transactions',
'action' => 'view',
$entry['Transaction']['id']))),
array('Timestamp', FormatHelper::datetime($entry['Transaction']['stamp'])),
array('Source', $entry['MonetarySource']['id']),
array('Amount', FormatHelper::currency($entry['LedgerEntry']['amount'])),
array('Debit', ($html->link($entry['DebitLedger']['Account']['name'],
array('controller' => 'accounts',
'action' => 'view',
$entry['DebitLedger']['Account']['id']))
. ' ('
. $html->link('#' . $entry['DebitLedger']['Account']['id']
. '-' . $entry['DebitLedger']['sequence'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['DebitLedger']['id']))
. ')')),
array('Credit', ($html->link($entry['CreditLedger']['Account']['name'],
array('controller' => 'accounts',
'action' => 'view',
$entry['CreditLedger']['Account']['id']))
. ' ('
. $html->link('#' . $entry['CreditLedger']['Account']['id']
. '-' . $entry['CreditLedger']['sequence'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['CreditLedger']['id']))
. ')')),
array('Comment', $entry['LedgerEntry']['comment']));
echo $this->element('table',
array('class' => 'item ledger-entry detail',
'caption' => 'Ledger Entry Detail',
'rows' => $rows,
'column_class' => array('field', 'value')));
/**********************************************************************
* LedgerEntry Info Box
*/
?>
<DIV CLASS="infobox">
</DIV>
<DIV CLASS="detail supporting">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Supporting Elements Section
*/
/* End "detail supporting" DIV */ ?>
</DIV>
</div>

View File

@@ -14,11 +14,13 @@
$rows = array(array('ID', $transaction['Transaction']['id']),
array('Timestamp', FormatHelper::datetime($transaction['Transaction']['stamp'])),
array('Through', FormatHelper::date($transaction['Transaction']['through_date'])),
array('Due', FormatHelper::date($transaction['Transaction']['due_date'])),
array('Comment', $transaction['Transaction']['comment']));
echo $this->element('table',
array('class' => 'item transaction detail',
'caption' => 'Transaction Info',
'caption' => 'Transaction Detail',
'rows' => $rows,
'column_class' => array('field', 'value')));
@@ -50,7 +52,7 @@ echo $this->element('table',
* Entries
*/
$headers = array('Entry', 'Debit', 'Credit', 'Comment', 'Amount', 'Total');
$headers = array('Entry', 'Debit', 'Credit', 'Amount', 'Comment',/* 'Total'*/);
$column_class = array();
foreach (array_intersect($headers, array('Entry')) AS $k => $v) {
$column_class[$k] = 'id';
@@ -71,17 +73,31 @@ foreach($transaction['LedgerEntry'] AS $entry) {
array('controller' => 'ledger_entries',
'action' => 'view',
$entry['id'])),
$html->link($entry['DebitLedger']['name'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['DebitLedger']['id'])),
$html->link($entry['CreditLedger']['name'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['CreditLedger']['id'])),
$entry['comment'],
($html->link($entry['DebitLedger']['Account']['name'],
array('controller' => 'accounts',
'action' => 'view',
$entry['DebitLedger']['Account']['id']))
. ' ('
. $html->link('#' . $entry['DebitLedger']['Account']['id']
. '-' . $entry['DebitLedger']['sequence'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['DebitLedger']['id']))
. ')'),
($html->link($entry['CreditLedger']['Account']['name'],
array('controller' => 'accounts',
'action' => 'view',
$entry['CreditLedger']['Account']['id']))
. ' ('
. $html->link('#' . $entry['CreditLedger']['Account']['id']
. '-' . $entry['CreditLedger']['sequence'],
array('controller' => 'ledgers',
'action' => 'view',
$entry['CreditLedger']['id']))
. ')'),
FormatHelper::currency($entry['amount']),
FormatHelper::currency($running_total)
$entry['comment'],
//FormatHelper::currency($running_total),
);
}