Significant changes to work with the new account/ledger structure. Removed much of the auto-generated model association code. Added helper functions into the models to perform model related work, such as model 'stats' (a bad name for a function to return a summary of pertinent financial information from a given model instance). There is a ton of cleanup to do, but first I want to get it all captured.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@81 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -41,7 +41,6 @@ class AppController extends Controller {
|
|||||||
return array(
|
return array(
|
||||||
array('name' => 'Common', 'header' => true),
|
array('name' => 'Common', 'header' => true),
|
||||||
array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)),
|
array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)),
|
||||||
array('name' => 'Tenants', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
|
||||||
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
|
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
|
||||||
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
|
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
|
||||||
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
||||||
|
|||||||
@@ -78,6 +78,39 @@ class AppModel extends Model {
|
|||||||
} //end getEnumValues
|
} //end getEnumValues
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: statMerge
|
||||||
|
* - Merges summary data from $b into $a
|
||||||
|
*/
|
||||||
|
|
||||||
|
function statsMerge (&$a, $b) {
|
||||||
|
if (!isset($b))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!isset($a)) {
|
||||||
|
$a = $b;
|
||||||
|
}
|
||||||
|
elseif (!is_array($a) && !is_array($b)) {
|
||||||
|
$a += $b;
|
||||||
|
}
|
||||||
|
elseif (is_array($a) && is_array($b)) {
|
||||||
|
foreach (array_intersect_key($a, $b) AS $k => $v)
|
||||||
|
{
|
||||||
|
if (preg_match("/^sp\./", $k))
|
||||||
|
$a[$k] .= '; ' . $b[$k];
|
||||||
|
else
|
||||||
|
$this->statsMerge($a[$k], $b[$k]);
|
||||||
|
}
|
||||||
|
$a = array_merge($a, array_diff_key($b, $a));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die ("Can't yet merge array and non-array stats");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Overriding pagination, since the stupid count mechanism blows.
|
// Overriding pagination, since the stupid count mechanism blows.
|
||||||
// This is also a crappy solution, especially if the query returns
|
// This is also a crappy solution, especially if the query returns
|
||||||
// a really large number of rows. However, trying to untagle this
|
// a really large number of rows. However, trying to untagle this
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ class AccountsController extends AppController {
|
|||||||
(// Models
|
(// Models
|
||||||
'LedgerEntry' =>
|
'LedgerEntry' =>
|
||||||
array('fields' =>
|
array('fields' =>
|
||||||
array('SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, LedgerEntry.amount, 0)) AS debits',
|
array('SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, LedgerEntry.amount, NULL)) AS debits',
|
||||||
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, LedgerEntry.amount, 0)) AS credits',
|
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, LedgerEntry.amount, NULL)) AS credits',
|
||||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
||||||
IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, 1, -1),
|
IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, 1, -1),
|
||||||
IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, 1, -1)
|
IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, 1, -1)
|
||||||
)* LedgerEntry.amount) AS balance",
|
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
|
||||||
|
) AS balance",
|
||||||
'COUNT(LedgerEntry.id) AS entries'),
|
'COUNT(LedgerEntry.id) AS entries'),
|
||||||
'conditions' =>
|
'conditions' =>
|
||||||
array('OR' =>
|
array('OR' =>
|
||||||
@@ -166,99 +167,51 @@ class AccountsController extends AppController {
|
|||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $this->Account->bindModel(array('hasMany' => array */
|
// Get details about the account and its ledgers (no ledger entries yet)
|
||||||
/* ('LedgerEntry' => array */
|
$this->Account->Behaviors->attach('Containable');
|
||||||
/* ('className' => 'LedgerEntry', */
|
$account = $this->Account->find
|
||||||
/* 'foreignKey' => false, */
|
('first',
|
||||||
/* 'finderQuery' => 'SELECT `LedgerEntry`.* */
|
array('contain' =>
|
||||||
/* FROM pmgr_entries AS `LedgerEntry` */
|
array(// Models
|
||||||
/* LEFT JOIN pmgr_transactions AS `Transaction` */
|
'CurrentLedger' =>
|
||||||
/* ON `Transaction`.id = `LedgerEntry`.transaction_id */
|
array('fields' => array('id', 'sequence')),
|
||||||
/* WHERE LedgerEntry.debit_ledger_id = ({$__cakeID__$}) */
|
|
||||||
/* OR LedgerEntry.credit_ledger_id = ({$__cakeID__$}) */
|
|
||||||
/* ORDER BY Transaction.stamp', */
|
|
||||||
/* )))); */
|
|
||||||
|
|
||||||
/* $this->Account->Behaviors->attach('Containable'); */
|
'Ledger' =>
|
||||||
/* $this->Account->Contain(array('LedgerEntry' => array */
|
array('order' => array('Ledger.open_stamp' => 'DESC')),
|
||||||
/* ( */
|
|
||||||
/* // Models */
|
|
||||||
/* 'Transaction' => array */
|
|
||||||
/* ( */
|
|
||||||
/* // Models */
|
|
||||||
/* 'Customer', */
|
|
||||||
/* )), */
|
|
||||||
|
|
||||||
/* )); */
|
|
||||||
/* } */
|
|
||||||
/* $account = $this->Account->read(null, $id); */
|
|
||||||
|
|
||||||
|
|
||||||
$this->Account->recursive = -1;
|
|
||||||
$account = $this->Account->read(null, $id);
|
|
||||||
|
|
||||||
$account['Ledger'] = $this->Account->find
|
|
||||||
('all', array
|
|
||||||
('link' => array
|
|
||||||
(// Models
|
|
||||||
'Ledger' => array
|
|
||||||
(// Models
|
|
||||||
'LedgerEntry' =>
|
|
||||||
array('fields' =>
|
|
||||||
array('SUM(IF(LedgerEntry.debit_ledger_id = Ledger.id, LedgerEntry.amount, 0)) AS debits',
|
|
||||||
'SUM(IF(LedgerEntry.credit_ledger_id = Ledger.id, LedgerEntry.amount, 0)) AS credits',
|
|
||||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
|
||||||
IF(LedgerEntry.debit_ledger_id = Ledger.id, 1, -1),
|
|
||||||
IF(LedgerEntry.credit_ledger_id = Ledger.id, 1, -1)
|
|
||||||
) * LedgerEntry.amount) AS balance",
|
|
||||||
'COUNT(LedgerEntry.id) AS entries'),
|
|
||||||
'conditions' =>
|
|
||||||
array('OR' =>
|
|
||||||
array('LedgerEntry.debit_ledger_id = Ledger.id',
|
|
||||||
'LedgerEntry.credit_ledger_id = Ledger.id'),
|
|
||||||
),
|
),
|
||||||
),
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
),
|
)
|
||||||
),
|
);
|
||||||
'fields' => array(),
|
$this->Account->Behaviors->detach('Containable');
|
||||||
'conditions' => array('Account.id' => $id),
|
|
||||||
'order' => 'Ledger.name',
|
|
||||||
'group' => 'Ledger.id',
|
|
||||||
'limit' => 4,
|
|
||||||
));
|
|
||||||
|
|
||||||
|
// Simply debug stuff... testing.
|
||||||
|
$cond = null;
|
||||||
|
//$cond = array('Transaction.stamp >' => '2009-05-16');
|
||||||
|
|
||||||
$account['CurrentLedger'] = array_shift($this->Account->Ledger->find
|
// Get all ledger entries of the CURRENT ledger
|
||||||
('first', array
|
//$crap = $this->Account->findSecurityDeposits($id);
|
||||||
('link' => array
|
//$crap = $this->Account->findAccountRelatedEntries($id, 8);
|
||||||
(// Models
|
//pr(array('crap', $crap));
|
||||||
'Account' => array('fields' => array()),
|
/* $this->autoRender = false; */
|
||||||
'LedgerEntry' =>
|
/* return; */
|
||||||
array('fields' =>
|
|
||||||
array("SUM(IF(LedgerEntry.debit_ledger_id = Ledger.id, LedgerEntry.amount, 0)) AS debits",
|
|
||||||
"SUM(IF(LedgerEntry.credit_ledger_id = Ledger.id, LedgerEntry.amount, 0)) AS credits",
|
|
||||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
|
||||||
IF(LedgerEntry.debit_ledger_id = Ledger.id, 1, -1),
|
|
||||||
IF(LedgerEntry.credit_ledger_id = Ledger.id, 1, -1)
|
|
||||||
) * LedgerEntry.amount) AS balance",
|
|
||||||
'COUNT(LedgerEntry.id) AS entries'),
|
|
||||||
'conditions' =>
|
|
||||||
array('OR' =>
|
|
||||||
array("LedgerEntry.debit_ledger_id = Ledger.id",
|
|
||||||
"LedgerEntry.credit_ledger_id = Ledger.id"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'fields' => array(),
|
|
||||||
'conditions' => array(array('Ledger.account_id' => $id),
|
|
||||||
'NOT' => array('Ledger.closed')),
|
|
||||||
//'order' => 'Ledger.name',
|
|
||||||
'group' => 'Ledger.id',
|
|
||||||
//'limit' => 4,
|
|
||||||
)));
|
|
||||||
//pr($account);
|
|
||||||
|
|
||||||
$balance = $account['CurrentLedger']['balance'];
|
// Get all ledger entries of the CURRENT ledger
|
||||||
|
$account['CurrentLedger']['LedgerEntry']
|
||||||
|
= $this->Account->findCurrentLedgerEntries($id, $cond);
|
||||||
|
//pr(array('Account summary', $account));
|
||||||
|
|
||||||
|
// Summarize each ledger
|
||||||
|
foreach($account['Ledger'] AS &$ledger)
|
||||||
|
$ledger = array_merge($ledger,
|
||||||
|
$this->Account->Ledger->stats($ledger['id']));
|
||||||
|
|
||||||
|
// Obtain the overall account balance
|
||||||
|
$account['Account'] =
|
||||||
|
array_merge($account['Account'],
|
||||||
|
array('stats' => $this->Account->stats($id)));
|
||||||
|
$balance = $account['Account']['stats']['Ledger']['balance'];
|
||||||
|
|
||||||
|
// Prepare to render
|
||||||
$title = 'Account: ' . $account['Account']['name'];
|
$title = 'Account: ' . $account['Account']['name'];
|
||||||
$this->set(compact('account', 'title', 'balance'));
|
$this->set(compact('account', 'title', 'balance'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,94 +29,11 @@ class ContactsController extends AppController {
|
|||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* action: index
|
* action: index
|
||||||
* - Lists all current tenants
|
* - Lists all contacts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function index() {
|
function index() {
|
||||||
$this->current();
|
$this->all();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: past
|
|
||||||
* - Lists all tenants, past and present
|
|
||||||
*/
|
|
||||||
|
|
||||||
function tenants() {
|
|
||||||
$this->paginate = array_merge
|
|
||||||
($this->paginate,
|
|
||||||
array('link' =>
|
|
||||||
array(// Models
|
|
||||||
'Lease' =>
|
|
||||||
array('fields' => array(),
|
|
||||||
'type' => 'INNER',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'conditions' => array('ContactsLease.type !=' => 'ALTERNATE')
|
|
||||||
));
|
|
||||||
|
|
||||||
$title = 'All Tenants';
|
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
|
||||||
$this->set('contacts', $this->paginate());
|
|
||||||
$this->render('index');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* 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('ContactsLease.type !=' => 'ALTERNATE',
|
|
||||||
'Lease.close_date IS NULL')
|
|
||||||
));
|
|
||||||
|
|
||||||
$title = 'Current Tenants';
|
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
|
||||||
$this->set('contacts', $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('ContactsLease.type !=' => 'ALTERNATE',
|
|
||||||
'Lease.close_date IS NOT NULL')
|
|
||||||
));
|
|
||||||
|
|
||||||
$title = 'Past Tenants';
|
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
|
||||||
$this->set('contacts', $this->paginate());
|
|
||||||
$this->render('index');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,7 +41,7 @@ class ContactsController extends AppController {
|
|||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* action: all
|
* action: all
|
||||||
* - Lists all contacts, including non-tenants
|
* - Lists all contacts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function all() {
|
function all() {
|
||||||
|
|||||||
@@ -126,18 +126,12 @@ class CustomersController extends AppController {
|
|||||||
'ContactEmail',
|
'ContactEmail',
|
||||||
'ContactAddress',
|
'ContactAddress',
|
||||||
),
|
),
|
||||||
'Transaction' =>
|
'Account',
|
||||||
array('order' => array('stamp'),
|
|
||||||
// Models
|
|
||||||
'Entry' =>
|
|
||||||
array(// Models
|
|
||||||
'DebitAccount',
|
|
||||||
'CreditAccount'),
|
|
||||||
),
|
|
||||||
'Lease' =>
|
'Lease' =>
|
||||||
array('order' => 'movein_date',
|
array(//'order' => 'movein_date',
|
||||||
'conditions' => array('Lease.lease_date IS NOT NULL'),
|
//'conditions' => array('Lease.lease_date IS NOT NULL'),
|
||||||
// Models
|
// Models
|
||||||
|
//'Account',
|
||||||
'Unit' =>
|
'Unit' =>
|
||||||
array('order' => array('sort_order'),
|
array('order' => array('sort_order'),
|
||||||
'fields' => array('id', 'name'),
|
'fields' => array('id', 'name'),
|
||||||
@@ -146,29 +140,38 @@ class CustomersController extends AppController {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$customer = $this->Customer->read(null, $id);
|
$customer = $this->Customer->read(null, $id);
|
||||||
|
$this->Customer->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
foreach ($customer['Lease'] AS &$lease) {
|
||||||
|
$stats = $this->Customer->Lease->stats($lease['id']);
|
||||||
|
//pr($stats);
|
||||||
|
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
//pr($customer);
|
//pr($customer);
|
||||||
|
|
||||||
$outstanding_deposit = 0;
|
$stats = $this->Customer->stats($id);
|
||||||
$outstanding_balance = 0;
|
$deposits = $this->Customer->findSecurityDeposits($id);
|
||||||
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_balance = $stats['balance'];
|
||||||
$outstanding_deposit -= $entry['amount'];
|
$outstanding_deposit = $deposits['summary']['balance'];
|
||||||
if ($entry['CreditAccount']['name'] === 'Security Deposit')
|
|
||||||
$outstanding_deposit += $entry['amount'];
|
/* pr(array('Customer Stats', $stats)); */
|
||||||
}
|
/* pr(array('Security Deposits', $deposits)); */
|
||||||
}
|
|
||||||
|
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Operations', 'header' => true);
|
array('name' => 'Operations', 'header' => true);
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
||||||
|
|
||||||
|
|
||||||
|
$customer['Account'] = array_merge($customer['Account'], $stats['Account']['Ledger']);
|
||||||
|
//pr($stats);
|
||||||
|
//unset($stats['Lease'], $stats['Account']);
|
||||||
|
/* $customer['Account']['debits'] = 10; */
|
||||||
|
/* $customer['Account']['credits'] = 20; */
|
||||||
|
/* $customer['Account']['balance'] = 55; */
|
||||||
|
|
||||||
$title = $customer['Customer']['name'];
|
$title = $customer['Customer']['name'];
|
||||||
$this->set(compact('customer', 'title',
|
$this->set(compact('customer', 'title',
|
||||||
'outstanding_balance',
|
'outstanding_balance',
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ class LedgersController extends AppController {
|
|||||||
'group' => 'Ledger.id',
|
'group' => 'Ledger.id',
|
||||||
'order' => array('Ledger.name' => 'ASC'));
|
'order' => array('Ledger.name' => 'ASC'));
|
||||||
|
|
||||||
var $uses = array('Ledger', 'LedgerEntry');
|
|
||||||
|
|
||||||
var $sidemenu_links =
|
var $sidemenu_links =
|
||||||
array(array('name' => 'Ledgers', 'header' => true),
|
array(array('name' => 'Ledgers', 'header' => true),
|
||||||
array('name' => 'Current', 'url' => array('controller' => 'ledgers', 'action' => 'current')),
|
array('name' => 'Current', 'url' => array('controller' => 'ledgers', 'action' => 'current')),
|
||||||
@@ -115,73 +113,37 @@ class LedgersController extends AppController {
|
|||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $this->Ledger->bindModel(array('hasMany' => array */
|
// Get details about the ledger itself (no entries yet)
|
||||||
/* ('LedgerEntry' => array */
|
|
||||||
/* ('className' => 'LedgerEntry', */
|
|
||||||
/* 'foreignKey' => false, */
|
|
||||||
/* 'finderQuery' => 'SELECT `LedgerEntry`.* */
|
|
||||||
/* FROM pmgr_entries AS `LedgerEntry` */
|
|
||||||
/* LEFT JOIN pmgr_transactions AS `Transaction` */
|
|
||||||
/* ON `Transaction`.id = `LedgerEntry`.transaction_id */
|
|
||||||
/* WHERE LedgerEntry.debit_ledger_id = ({$__cakeID__$}) */
|
|
||||||
/* OR LedgerEntry.credit_ledger_id = ({$__cakeID__$}) */
|
|
||||||
/* ORDER BY Transaction.stamp', */
|
|
||||||
/* )))); */
|
|
||||||
|
|
||||||
/* $this->Ledger->Behaviors->attach('Containable'); */
|
|
||||||
/* $this->Ledger->Contain(array('LedgerEntry' => array */
|
|
||||||
/* ( */
|
|
||||||
/* // Models */
|
|
||||||
/* 'Transaction' => array */
|
|
||||||
/* ( */
|
|
||||||
/* // Models */
|
|
||||||
/* 'Customer', */
|
|
||||||
/* )), */
|
|
||||||
|
|
||||||
/* )); */
|
|
||||||
/* } */
|
|
||||||
/* $ledger = $this->Ledger->read(null, $id); */
|
|
||||||
|
|
||||||
$this->Ledger->Behaviors->attach('Containable');
|
$this->Ledger->Behaviors->attach('Containable');
|
||||||
$this->Ledger->Contain(array('Account'));
|
$ledger = $this->Ledger->find
|
||||||
$ledger = $this->Ledger->read(null, $id);
|
('first',
|
||||||
//pr($ledger);
|
array('contain' =>
|
||||||
|
|
||||||
if (in_array($ledger['Account']['type'], array('ASSET', 'EXPENSE')))
|
|
||||||
$ledger_type = 'debit';
|
|
||||||
else
|
|
||||||
$ledger_type = 'credit';
|
|
||||||
|
|
||||||
$ledger['LedgerEntry'] = $this->LedgerEntry->find
|
|
||||||
('all',
|
|
||||||
array('link' => array
|
|
||||||
(// Models
|
|
||||||
'Transaction' =>
|
|
||||||
array(// Models
|
array(// Models
|
||||||
'Customer',
|
'Account',
|
||||||
)),
|
),
|
||||||
'fields' =>
|
'conditions' => array(array('Ledger.id' => $id)),
|
||||||
array('id', 'name', 'comment',
|
)
|
||||||
"IF(LedgerEntry.debit_ledger_id = $id, LedgerEntry.amount, NULL) AS debit",
|
);
|
||||||
"IF(LedgerEntry.credit_ledger_id = $id, LedgerEntry.amount, NULL) AS credit",
|
$this->Ledger->Behaviors->detach('Containable');
|
||||||
"(IF(LedgerEntry.{$ledger_type}_ledger_id = $id, 1, -1) * LedgerEntry.amount) AS balance"),
|
|
||||||
'conditions' => array('OR' =>
|
|
||||||
array("LedgerEntry.debit_ledger_id = $id",
|
|
||||||
"LedgerEntry.credit_ledger_id = $id")),
|
|
||||||
'order' => array('Transaction.stamp'),
|
|
||||||
//'limit' => 15,
|
|
||||||
//'limit' => 2,
|
|
||||||
));
|
|
||||||
//pr($ledger);
|
|
||||||
|
|
||||||
$balance = 0;
|
// Get all ledger entries of this ledger
|
||||||
foreach($ledger['LedgerEntry'] AS &$entry) {
|
$ledger['LedgerEntry'] = $this->Ledger->findLedgerEntries
|
||||||
if (isset($entry[0]))
|
($id, $ledger['Account']['type']);
|
||||||
$entry = array_merge($entry[0], array_diff_key($entry, array(0)));
|
|
||||||
|
|
||||||
$balance += $entry['balance'];
|
/* $ledger['LedgerEntry'] = $this->Ledger->LedgerEntry->findInLedgerContext */
|
||||||
}
|
/* ($id,
|
||||||
|
/* $ledger['LedgerEntry'] = $this->Ledger->findLedgerEntries */
|
||||||
|
/* ($id); */
|
||||||
|
//($id, $ledger['Account']['type']);
|
||||||
|
|
||||||
|
|
||||||
|
// Summarize the entries, and obtain the ledger balance
|
||||||
|
$ledger['Ledger'] =
|
||||||
|
array_merge($ledger['Ledger'],
|
||||||
|
array('stats' => $this->Ledger->stats($id)));
|
||||||
|
$balance = $ledger['Ledger']['stats']['balance'];
|
||||||
|
|
||||||
|
// OK, set our view variables and render!
|
||||||
$title = 'Ledger: ' . $ledger['Ledger']['name'];
|
$title = 'Ledger: ' . $ledger['Ledger']['name'];
|
||||||
$this->set(compact('ledger', 'title', 'balance'));
|
$this->set(compact('ledger', 'title', 'balance'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,74 +156,27 @@ class UnitsController extends AppController {
|
|||||||
$this->Unit->contain
|
$this->Unit->contain
|
||||||
(array(// Models
|
(array(// Models
|
||||||
'UnitSize',
|
'UnitSize',
|
||||||
//'CurrentLease' =>
|
'Lease' => array('Customer'),
|
||||||
'Lease' =>
|
'CurrentLease' => array('Customer')
|
||||||
array(//'order' => 'movein_date',
|
|
||||||
//'conditions' => array('Lease.lease_date IS NOT NULL',
|
|
||||||
//),
|
|
||||||
// Models
|
|
||||||
//'Contact' => array('alias' => 'PrimaryContact'),
|
|
||||||
// 'PrimaryContact',
|
|
||||||
'Customer' => array('fields' => array('id', 'name'),
|
|
||||||
// Models
|
|
||||||
'Transaction' =>
|
|
||||||
array('order' => array('stamp'),
|
|
||||||
// Models
|
|
||||||
'LedgerEntry' => array('DebitLedger' => array('Account'),
|
|
||||||
'CreditLedger' => array('Account'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
/* array(//'order' => array('sort_order'), */
|
|
||||||
/* 'fields' => array('id', 'display_name'), */
|
|
||||||
/* ), */
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$unit = $this->Unit->read(null, $id);
|
||||||
|
$this->Unit->Behaviors->detach('Containable');
|
||||||
|
|
||||||
//$unit = $this->Unit->read(null, $id);
|
pr($unit);
|
||||||
//pr($unit);
|
|
||||||
|
|
||||||
$this->Unit->Lease->Customer->Transaction->LedgerEntry->Behaviors->attach('Containable');
|
foreach ($unit['Lease'] AS &$lease) {
|
||||||
$entries = $this->Unit->Lease->Customer->Transaction->LedgerEntry->find
|
$stats = $this->Unit->Lease->stats($lease['id']);
|
||||||
('all',
|
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||||
array
|
|
||||||
(
|
|
||||||
'contain' =>
|
|
||||||
array('Transaction' =>
|
|
||||||
array('Customer' =>
|
|
||||||
array('Lease' =>
|
|
||||||
array('Unit' =>
|
|
||||||
array('conditions' => array('Unit.id' => $id)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
//'conditions' => 'xyz',
|
|
||||||
'limit' => 2,
|
|
||||||
));
|
|
||||||
pr($entries);
|
|
||||||
$this->autoRender = false;
|
|
||||||
|
|
||||||
|
|
||||||
$outstanding_deposit = 0;
|
|
||||||
$outstanding_balance = 0;
|
|
||||||
foreach($unit['Lease'] AS $lease) {
|
|
||||||
foreach($lease['Customer']['Transaction'] AS $transaction) {
|
|
||||||
foreach($transaction['LedgerEntry'] AS $entry) {
|
|
||||||
if ($entry['DebitLedger']['Account']['name'] === 'A/R')
|
|
||||||
$outstanding_balance += $entry['amount'];
|
|
||||||
if ($entry['CreditLedger']['Account']['name'] === 'A/R')
|
|
||||||
$outstanding_balance -= $entry['amount'];
|
|
||||||
|
|
||||||
if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit')
|
|
||||||
$outstanding_deposit -= $entry['amount'];
|
|
||||||
if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit')
|
|
||||||
$outstanding_deposit += $entry['amount'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stats = $this->Unit->stats($id);
|
||||||
|
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
|
||||||
|
|
||||||
|
//pr($stats);
|
||||||
|
$outstanding_balance = $stats['CurrentLease']['Account']['Ledger']['balance'];
|
||||||
|
$outstanding_deposit = $deposits['summary']['balance'];
|
||||||
|
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Operations', 'header' => true);
|
array('name' => 'Operations', 'header' => true);
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
|
|||||||
@@ -11,34 +11,428 @@ class Account extends AppModel {
|
|||||||
var $hasOne = array(
|
var $hasOne = array(
|
||||||
'CurrentLedger' => array(
|
'CurrentLedger' => array(
|
||||||
'className' => 'Ledger',
|
'className' => 'Ledger',
|
||||||
'foreignKey' => 'account_id',
|
//'foreignKey' => 'account_id',
|
||||||
'dependent' => false,
|
'conditions' => array('NOT' => array('CurrentLedger.closed'))
|
||||||
'conditions' => array(array('CurrentLedger.closed' => 0)),
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'Ledger' => array(
|
'Ledger',
|
||||||
'className' => 'Ledger',
|
|
||||||
'foreignKey' => 'account_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var $cache;
|
||||||
|
/* var $instantiated; */
|
||||||
|
|
||||||
|
|
||||||
|
/* /\************************************************************************** */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* * function: constructor */
|
||||||
|
/* *\/ */
|
||||||
|
/* function __constructor($id = null) { */
|
||||||
|
/* parent::__contstructor(); */
|
||||||
|
/* $this->id = $id; */
|
||||||
|
/* $this->instantiated = true; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: securityDepositAccountID
|
||||||
|
* - Returns the ID of the Security Deposit Account
|
||||||
|
*/
|
||||||
|
function securityDepositAccountID() {
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'conditions' => array(array('name' => 'Security Deposit')),
|
||||||
|
));
|
||||||
|
return $account['Account']['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function:rentAccountID
|
||||||
|
* - Returns the ID of the Rent Account
|
||||||
|
*/
|
||||||
|
function rentAccountID() {
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'conditions' => array(array('name' => 'Rent')),
|
||||||
|
));
|
||||||
|
return $account['Account']['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: type
|
||||||
|
* - Returns the type of this array of ledger ids from the given account
|
||||||
|
*/
|
||||||
|
function type($id) {
|
||||||
|
if (isset($this->cache[$id]['type'])) {
|
||||||
|
/* pr(array('function' => 'Account::type', */
|
||||||
|
/* 'args' => compact('id'), */
|
||||||
|
/* 'cache_hit' => true, */
|
||||||
|
/* 'return' => $this->cache[$id]['type'])); */
|
||||||
|
return $this->cache[$id]['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('type'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->cache[$id]['type'] = $account['Account']['type'];
|
||||||
|
/* pr(array('function' => 'Account::type', */
|
||||||
|
/* 'args' => compact('id'), */
|
||||||
|
/* 'return' => $this->cache[$id]['type'])); */
|
||||||
|
|
||||||
|
return $this->cache[$id]['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: ledgers
|
||||||
|
* - Returns an array of ledger ids from the given account
|
||||||
|
*/
|
||||||
|
function ledgers($id, $all = false) {
|
||||||
|
$cachekey = $all ? 'all' : 'current';
|
||||||
|
if (isset($this->cache[$id]['ledgers'][$cachekey])) {
|
||||||
|
/* pr(array('function' => 'Account::ledgers', */
|
||||||
|
/* 'args' => compact('id', 'all'), */
|
||||||
|
/* 'cache_hit' => true, */
|
||||||
|
/* 'return' => $this->cache[$id]['ledgers'][$cachekey])); */
|
||||||
|
return $this->cache[$id]['ledgers'][$cachekey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($all) {
|
||||||
|
$contain = array('Ledger' => array('fields' => array('Ledger.id')));
|
||||||
|
} else {
|
||||||
|
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('contain' => $contain,
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
if ($all) {
|
||||||
|
$ledger_ids = array();
|
||||||
|
foreach ($account['Ledger'] AS $ledger)
|
||||||
|
array_push($ledger_ids, $ledger['id']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ledger_ids = array($account['CurrentLedger']['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cache[$id]['ledgers'][$cachekey] = $ledger_ids;
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::ledgers', */
|
||||||
|
/* 'args' => compact('id', 'all'), */
|
||||||
|
/* 'return' => $this->cache[$id]['ledgers'][$cachekey])); */
|
||||||
|
|
||||||
|
return $this->cache[$id]['ledgers'][$cachekey];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerEntries
|
||||||
|
* - Returns an array of ledger entries that belong to the given
|
||||||
|
* account, either just from the current ledger, or from all ledgers.
|
||||||
|
*/
|
||||||
|
function findLedgerEntries($id, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$entries = array();
|
||||||
|
foreach ($this->ledgers($id, $all) AS $ledger_id) {
|
||||||
|
$ledger_entries = $this->Ledger->findLedgerEntries($ledger_id, $this->type($id), $cond, $link);
|
||||||
|
$entries = array_merge($entries, $ledger_entries);
|
||||||
|
//$entries = array_merge($entries, array_diff_key($ledger_entries, array('summary'=>1)));
|
||||||
|
//$this->statsMerge($entries['summary'], $ledger_entries['summary']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$stats = $this->stats($id, $all, $cond);
|
||||||
|
return array('Entries' => $entries, 'summary' => $stats['Ledger']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerEntriesRelatedToAccount
|
||||||
|
* - Returns an array of ledger entries that belong to the given
|
||||||
|
* account, and are related to a specific account, either just from
|
||||||
|
* the current ledger, or from all ledgers.
|
||||||
|
*/
|
||||||
|
function findLedgerEntriesRelatedToAccount($id, $rel_ids, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntriesRelatedToAccount', */
|
||||||
|
/* 'args' => compact('id', 'rel_ids', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
if (!isset($cond))
|
||||||
|
$cond = array();
|
||||||
|
|
||||||
|
if (!is_array($rel_ids))
|
||||||
|
$rel_ids = array($rel_ids);
|
||||||
|
|
||||||
|
$ledger_ids = array();
|
||||||
|
foreach ($rel_ids AS $rel_id)
|
||||||
|
$ledger_ids = array_merge($ledger_ids, $this->ledgers($rel_id));
|
||||||
|
|
||||||
|
array_push($cond, $this->Ledger->LedgerEntry->conditionEntryAsCreditOrDebit($ledger_ids));
|
||||||
|
$entries = $this->findLedgerEntries($id, $all, $cond, $link);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntriesRelatedToAccount', */
|
||||||
|
/* 'args' => compact('id', 'relid', 'all', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('ledger_ids'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findCurrentLedgerEntries
|
||||||
|
* - Returns an array of ledger entries that belong to the current
|
||||||
|
* ledger of the given account. There is extra work done... see the
|
||||||
|
* LedgerEntry model.
|
||||||
|
*/
|
||||||
|
function findCurrentLedgerEntries($id, $cond = null, $link = null) {
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('contain' => array('CurrentLedger'),
|
||||||
|
'fields' => array('Account.type', 'CurrentLedger.id'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$ledger_id = $account['CurrentLedger']['id'];
|
||||||
|
$account_type = $account['Account']['type'];
|
||||||
|
|
||||||
|
return $this->Ledger->findLedgerEntries($ledger_id, $account_type, $cond, $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerRelatedEntries
|
||||||
|
* - Returns an array of ledger entries from this account that are
|
||||||
|
* related to one of the given ledgers.
|
||||||
|
*/
|
||||||
|
function findLedgerRelatedEntries($id, $ledgers, $link = null) {
|
||||||
|
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||||
|
'checkpoint' => 'begin'),
|
||||||
|
compact('id', 'ledgers', 'link')));
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('contain' => array
|
||||||
|
('Ledger' => array('fields' => array('Ledger.id')),
|
||||||
|
),
|
||||||
|
'fields' => array('Account.type'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$cond = array('OR' =>
|
||||||
|
array(array('debit_ledger_id' => $ledgers),
|
||||||
|
array('credit_ledger_id' => $ledgers)));
|
||||||
|
|
||||||
|
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||||
|
'checkpoint' => 'get-account-ledgers'),
|
||||||
|
compact('account', 'cond')));
|
||||||
|
|
||||||
|
$entries = array();
|
||||||
|
foreach($account['Ledger'] AS $ledger) {
|
||||||
|
//pr(array('find', $ledger, $account, $cond, $link));
|
||||||
|
$entries = array_merge
|
||||||
|
($entries,
|
||||||
|
$this->Ledger->findLedgerEntries($ledger['id'],
|
||||||
|
$account['Account']['type'],
|
||||||
|
$cond, $link));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($entries AS $entry)
|
||||||
|
$this->statsMerge($entries['summary'], $entry[0]);
|
||||||
|
|
||||||
|
//$entries['summary']
|
||||||
|
|
||||||
|
pr(array_merge(array('function' => 'Account::findLedgerRelatedEntries',
|
||||||
|
'checkpoint' => 'return'),
|
||||||
|
compact('entries')));
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findAccountRelatedEntries
|
||||||
|
* - Returns an array of ledger entries from this account that are
|
||||||
|
* related to the given account.
|
||||||
|
*/
|
||||||
|
function findAccountRelatedEntries($id, $relid, $link = null) {
|
||||||
|
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||||
|
'checkpoint' => 'begin'),
|
||||||
|
compact('id', 'relid', 'link')));
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$related = $this->find('first', array
|
||||||
|
('contain' => array
|
||||||
|
('Ledger' => array('fields' => array('Ledger.id')),
|
||||||
|
),
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Account.id' => $relid)),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$ledger_ids = array();
|
||||||
|
foreach ($related['Ledger'] AS $ledger)
|
||||||
|
array_push($ledger_ids, $ledger['id']);
|
||||||
|
|
||||||
|
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||||
|
'checkpoint' => 'get-related'),
|
||||||
|
compact('related', 'ledger_ids')));
|
||||||
|
|
||||||
|
$entries = $this->findLedgerRelatedEntries($id, $ledger_ids, $link);
|
||||||
|
pr(array_merge(array('function' => 'Account::findAccountRelatedEntries',
|
||||||
|
'checkpoint' => 'return'),
|
||||||
|
compact('entries')));
|
||||||
|
return $entries;
|
||||||
|
//return $this->findLedgerRelatedEntries($id, $ledger_ids, $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* /\************************************************************************** */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* * function: findSecurityDeposits */
|
||||||
|
/* * - Returns an array of security deposit entries */
|
||||||
|
/* *\/ */
|
||||||
|
/* function findSecurityDeposits($id, $link = null) { */
|
||||||
|
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||||
|
/* 'checkpoint' => 'begin'), */
|
||||||
|
/* compact('id', 'link'))); */
|
||||||
|
/* $sd_account = $this->find('first', array */
|
||||||
|
/* ('recursive' => -1, */
|
||||||
|
/* 'conditions' => array(array('name' => 'Security Deposit')), */
|
||||||
|
/* )); */
|
||||||
|
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||||
|
/* 'checkpoint' => 'get-security-deposit-account'), */
|
||||||
|
/* compact('sd_account'))); */
|
||||||
|
|
||||||
|
/* $deposits = $this->findAccountRelatedEntries($id, $sd_account['Account']['id'], $link); */
|
||||||
|
/* pr(array_merge(array('function' => 'Account::findSecurityDeposits', */
|
||||||
|
/* 'checkpoint' => 'return'), */
|
||||||
|
/* compact('deposits'))); */
|
||||||
|
/* return $deposits; */
|
||||||
|
/* //return $this->findAccountRelatedEntries($id, $sd_account['Account']['id'], $link); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function zzfindSecurityDeposits($id, $cond = array(), $link = null) {
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('contain' => array
|
||||||
|
('Ledger' => array('fields' => array('Ledger.id')),
|
||||||
|
),
|
||||||
|
'fields' => array('Account.type'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
|
||||||
|
$sd_account = $this->find('first', array
|
||||||
|
('contain' => array
|
||||||
|
('Ledger' => array('fields' => array('Ledger.id')),
|
||||||
|
),
|
||||||
|
'conditions' => array(array('name' => 'Security Deposit')),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
pr(array('sd_account', $sd_account));
|
||||||
|
$sd_ledger_ids = array();
|
||||||
|
foreach ($sd_account['Ledger'] AS $ledger)
|
||||||
|
array_push($sd_ledger_ids, $ledger['id']);
|
||||||
|
|
||||||
|
pr(array('sd_ledger_ids', $sd_ledger_ids));
|
||||||
|
array_push($cond,
|
||||||
|
array('OR' =>
|
||||||
|
array(array('debit_ledger_id' => $sd_ledger_ids),
|
||||||
|
array('credit_ledger_id' => $sd_ledger_ids))));
|
||||||
|
|
||||||
|
$sd_entries = array();
|
||||||
|
foreach($account['Ledger'] AS $ledger) {
|
||||||
|
pr(array('find', $ledger, $account, $cond, $link));
|
||||||
|
$add = $this->Ledger->findLedgerEntries($ledger['id'],
|
||||||
|
$account['Account']['type'],
|
||||||
|
$cond, $link);
|
||||||
|
$sd_entries = array_merge($sd_entries, $add);
|
||||||
|
}
|
||||||
|
|
||||||
|
pr(array('sd_entries', $sd_entries));
|
||||||
|
|
||||||
|
//return $this->Ledger->findLedgerEntries($ledger_id, $account_type, $cond, $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested account.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null, $all = false, $cond = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// All old, closed ledgers MUST balance to 0.
|
||||||
|
// However, the user may want the ENTIRE running totals.
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$account = $this->find('first',
|
||||||
|
array('contain' =>
|
||||||
|
($all
|
||||||
|
? array('Ledger' => array('fields' => array('id')))
|
||||||
|
: array('CurrentLedger' => array('fields' => array('id')))
|
||||||
|
),
|
||||||
|
'conditions' => array(array('Account.id' => $id))));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
if ($all)
|
||||||
|
$ledgers = $account['Ledger'];
|
||||||
|
else
|
||||||
|
$ledgers = array($account['CurrentLedger']);
|
||||||
|
|
||||||
|
foreach ($ledgers AS $ledger) {
|
||||||
|
$this->statsMerge($stats['Ledger'], $this->Ledger->stats($ledger['id'], $cond));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -10,21 +10,7 @@ class Contact extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Customer' => array(
|
'Customer',
|
||||||
'className' => 'Customer',
|
|
||||||
'joinTable' => 'contacts_customers',
|
|
||||||
'foreignKey' => 'contact_id',
|
|
||||||
'associationForeignKey' => 'customer_id',
|
|
||||||
'unique' => true,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
),
|
|
||||||
'ContactAddress' => array(
|
'ContactAddress' => array(
|
||||||
'className' => 'ContactAddress',
|
'className' => 'ContactAddress',
|
||||||
'joinTable' => 'contacts_methods',
|
'joinTable' => 'contacts_methods',
|
||||||
@@ -32,13 +18,6 @@ class Contact extends AppModel {
|
|||||||
'associationForeignKey' => 'method_id',
|
'associationForeignKey' => 'method_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'POST'",
|
'conditions' => "method = 'POST'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
),
|
),
|
||||||
'ContactPhone' => array(
|
'ContactPhone' => array(
|
||||||
'className' => 'ContactPhone',
|
'className' => 'ContactPhone',
|
||||||
@@ -47,13 +26,6 @@ class Contact extends AppModel {
|
|||||||
'associationForeignKey' => 'method_id',
|
'associationForeignKey' => 'method_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'PHONE'",
|
'conditions' => "method = 'PHONE'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
),
|
),
|
||||||
'ContactEmail' => array(
|
'ContactEmail' => array(
|
||||||
'className' => 'ContactEmail',
|
'className' => 'ContactEmail',
|
||||||
@@ -62,13 +34,6 @@ class Contact extends AppModel {
|
|||||||
'associationForeignKey' => 'method_id',
|
'associationForeignKey' => 'method_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'EMAIL'",
|
'conditions' => "method = 'EMAIL'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ class ContactAddress extends AppModel {
|
|||||||
'associationForeignKey' => 'contact_id',
|
'associationForeignKey' => 'contact_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'POST'",
|
'conditions' => "method = 'POST'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ class ContactEmail extends AppModel {
|
|||||||
'associationForeignKey' => 'contact_id',
|
'associationForeignKey' => 'contact_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'EMAIL'",
|
'conditions' => "method = 'EMAIL'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,6 @@ class ContactPhone extends AppModel {
|
|||||||
'associationForeignKey' => 'contact_id',
|
'associationForeignKey' => 'contact_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'PHONE'",
|
'conditions' => "method = 'PHONE'",
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,52 +7,194 @@ class Customer extends AppModel {
|
|||||||
'name' => array('notempty'),
|
'name' => array('notempty'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'Account',
|
||||||
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'Lease' => array(
|
'CurrentLease' => array(
|
||||||
'className' => 'Lease',
|
'className' => 'Lease',
|
||||||
'foreignKey' => 'customer_id',
|
'conditions' => 'CurrentLease.close_date IS NULL',
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
),
|
||||||
'Transaction' => array(
|
'Lease',
|
||||||
'className' => 'Transaction',
|
'Transaction',
|
||||||
'foreignKey' => 'customer_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Contact' => array(
|
'Contact',
|
||||||
'className' => 'Contact',
|
|
||||||
'joinTable' => 'contacts_customers',
|
|
||||||
'foreignKey' => 'customer_id',
|
|
||||||
'associationForeignKey' => 'contact_id',
|
|
||||||
'unique' => true,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findAccountEntries
|
||||||
|
* - Returns an array of ledger entries that belong to the current
|
||||||
|
* ledger of the account for the given customer. There is extra work
|
||||||
|
* done... see the LedgerEntry model.
|
||||||
|
*/
|
||||||
|
/* function findAccountEntries($id, $date = null, $link = null) { */
|
||||||
|
/* $result = $this->find('first', array */
|
||||||
|
/* ('recursive' => -1, */
|
||||||
|
/* 'fields' => array('account_id'), */
|
||||||
|
/* 'conditions' => array(array('id' => $id)), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
/* return $this->Account->findCurrentLedgerEntries($result['account_id'], */
|
||||||
|
/* $date, $link); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function zfindSecurityDeposits($id, $link = null) {
|
||||||
|
pr(array('function' => 'Customer::findSecurityDeposits',
|
||||||
|
'args' => compact('id', 'link'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$customer = $this->find('first',
|
||||||
|
array('contain' =>
|
||||||
|
array('Lease' => array
|
||||||
|
('fields' => array('Lease.account_id')),
|
||||||
|
),
|
||||||
|
'fields' => array('Customer.account_id'),
|
||||||
|
'conditions' => array(array('Customer.id' => $id))));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$account_ids = array($customer['Customer']['account_id']);
|
||||||
|
foreach ($customer['Lease'] AS $lease)
|
||||||
|
array_push($account_ids, $lease['account_id']);
|
||||||
|
|
||||||
|
$acct = new Account();
|
||||||
|
$entries = $acct->findLedgerEntriesRelatedToAccount
|
||||||
|
($acct->securityDepositAccountID(),
|
||||||
|
$account_ids,
|
||||||
|
//$acct->rentAccountID(),
|
||||||
|
//6,
|
||||||
|
//array_merge(array(1), $account_ids),
|
||||||
|
true, null, $link);
|
||||||
|
|
||||||
|
// OK, we cheated by finding the entries of the security deposit account,
|
||||||
|
// and not by finding the security deposit entries of the customer
|
||||||
|
// account(s). Therefore, we have to invert the credit/debit business.
|
||||||
|
$entries['summary']['debits'] = $entries['summary']['credit'];
|
||||||
|
$entries['summary']['credits'] = $entries['summary']['debit'];
|
||||||
|
unset($entries['summary']['credit']);
|
||||||
|
unset($entries['summary']['debit']);
|
||||||
|
|
||||||
|
pr(array('function' => 'Customer::findSecurityDeposits',
|
||||||
|
'args' => compact('id', 'link'),
|
||||||
|
'vars' => compact('customer', 'account_ids'),
|
||||||
|
'return' => compact('entries'),
|
||||||
|
));
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function findSecurityDeposits($id, $link = null) {
|
||||||
|
/* pr(array_merge(array('function' => 'Customer::findSecurityDeposits', */
|
||||||
|
/* 'checkpoint' => 'begin'), */
|
||||||
|
/* compact('id', 'link'))); */
|
||||||
|
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$customer = $this->find('first',
|
||||||
|
array('contain' =>
|
||||||
|
array('Lease' => array('fields' => array('id'))),
|
||||||
|
'fields' => array('account_id'),
|
||||||
|
'conditions' => array(array('Customer.id' => $id))));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
||||||
|
($customer['Customer']['account_id'],
|
||||||
|
$this->Account->securityDepositAccountID(),
|
||||||
|
true, null, $link);
|
||||||
|
|
||||||
|
foreach ($customer['Lease'] AS $lease) {
|
||||||
|
$ledger_entries = $this->Lease->findSecurityDeposits($lease['id'], $link);
|
||||||
|
//$this->statsMerge($ledger_entries['summary'], $entries['summary']);
|
||||||
|
//unset($entries['summary']);
|
||||||
|
$this->statsMerge($entries['summary'], $ledger_entries['summary']);
|
||||||
|
$entries['Entries'] = array_merge($entries['Entries'], $ledger_entries['Entries']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
||||||
|
/* 'args' => compact('id', 'link'), */
|
||||||
|
/* 'vars' => compact('customer'), */
|
||||||
|
/* 'return' => compact('entries'))); */
|
||||||
|
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$customer = $this->find('first',
|
||||||
|
array('contain' =>
|
||||||
|
array('Account' => array('fields' => array('Account.id')),
|
||||||
|
'Lease' => array('fields' => array('Lease.id'))
|
||||||
|
),
|
||||||
|
/* array('Account' => array */
|
||||||
|
/* ('fields' => array('id'), */
|
||||||
|
/* /\* 'CurrentLedger' => array *\/ */
|
||||||
|
/* /\* ('fields => *\/ */
|
||||||
|
/* /\* 'Lease' => array('fields' => array('id') *\/ */
|
||||||
|
/* ), */
|
||||||
|
/* ), */
|
||||||
|
'conditions' => array(array('Customer.id' => $id))));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$stats['Account'] = $this->Account->stats($customer['Account']['id']);
|
||||||
|
foreach ($customer['Lease'] AS $lease) {
|
||||||
|
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* foreach($lease['Customer']['Transaction'] AS $transaction) { */
|
||||||
|
/* foreach($transaction['LedgerEntry'] AS $entry) { */
|
||||||
|
/* if ($entry['DebitLedger']['Account']['name'] === 'A/R') */
|
||||||
|
/* $outstanding_balance += $entry['amount']; */
|
||||||
|
/* if ($entry['CreditLedger']['Account']['name'] === 'A/R') */
|
||||||
|
/* $outstanding_balance -= $entry['amount']; */
|
||||||
|
|
||||||
|
/* if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit') */
|
||||||
|
/* $outstanding_deposit -= $entry['amount']; */
|
||||||
|
/* if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit') */
|
||||||
|
/* $outstanding_deposit += $entry['amount']; */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
/* if ($entry['DebitLedger']['Account']['name'] === 'Security Deposit') */
|
||||||
|
/* $outstanding_deposit -= $entry['amount']; */
|
||||||
|
/* if ($entry['CreditLedger']['Account']['name'] === 'Security Deposit') */
|
||||||
|
/* $outstanding_deposit += $entry['amount']; */
|
||||||
|
|
||||||
|
// Merge the stats from both the customer specific account, as
|
||||||
|
// well as the lease. This will provide current customer standing.
|
||||||
|
$this->statsMerge($stats, $stats['Account']['Ledger']);
|
||||||
|
$this->statsMerge($stats, $stats['Lease']['Account']['Ledger']);
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
177
models/lease.php
177
models/lease.php
@@ -23,36 +23,155 @@ class Lease extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'LeaseType' => array(
|
'LeaseType',
|
||||||
'className' => 'LeaseType',
|
'Unit',
|
||||||
'foreignKey' => 'lease_type_id',
|
'Account',
|
||||||
'conditions' => '',
|
'Customer',
|
||||||
'fields' => '',
|
'LateSchedule',
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'Unit' => array(
|
|
||||||
'className' => 'Unit',
|
|
||||||
'foreignKey' => 'unit_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'LateSchedule' => array(
|
|
||||||
'className' => 'LateSchedule',
|
|
||||||
'foreignKey' => 'late_schedule_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'Customer' => array(
|
|
||||||
'className' => 'Customer',
|
|
||||||
'foreignKey' => 'customer_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findAccountEntries
|
||||||
|
* - Returns an array of ledger entries from the account of the given
|
||||||
|
* lease.
|
||||||
|
*/
|
||||||
|
function findAccountEntries($id, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$lease = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('account_id'),
|
||||||
|
'conditions' => array(array('id' => $id)),
|
||||||
|
));
|
||||||
|
|
||||||
|
$entries = $this->Account->findLedgerEntries($lease['Lease']['account_id'],
|
||||||
|
$all, $cond, $link);
|
||||||
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('lease'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function findSecurityDeposits($id, $link = null) {
|
||||||
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
||||||
|
/* 'args' => compact('id', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$lease = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('account_id'),
|
||||||
|
'conditions' => array(array('id' => $id)),
|
||||||
|
));
|
||||||
|
|
||||||
|
/* $sd_account_id = $this->Account->securityDepositAccountID(); */
|
||||||
|
/* $sd_ledger_ids = $this->Account->ledgers($sd_account_id); */
|
||||||
|
/* $cond = conditionEntryAsCreditOrDebit($sd_ledger_ids); */
|
||||||
|
|
||||||
|
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
||||||
|
($lease['Lease']['account_id'],
|
||||||
|
$this->Account->securityDepositAccountID(),
|
||||||
|
true, null, $link);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
||||||
|
/* 'args' => compact('id', 'link'), */
|
||||||
|
/* 'vars' => compact('lease'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function findAccountDeposits($id, $link = null) {
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'begin'),
|
||||||
|
compact('id', 'link')));
|
||||||
|
$lease = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('account_id'),
|
||||||
|
'conditions' => array(array('id' => $id)),
|
||||||
|
));
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'get-lease'),
|
||||||
|
compact('lease')));
|
||||||
|
|
||||||
|
$deposits = $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'return'),
|
||||||
|
compact('deposits')));
|
||||||
|
return $deposits;
|
||||||
|
//return $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function qqfindSecurityDeposits($id, $link = null) {
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'begin'),
|
||||||
|
compact('id', 'link')));
|
||||||
|
$lease = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('account_id'),
|
||||||
|
'conditions' => array(array('id' => $id)),
|
||||||
|
));
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'get-lease'),
|
||||||
|
compact('lease')));
|
||||||
|
|
||||||
|
return $this->Account->findAccountRelatedEntries($id, $relaccount, $link);
|
||||||
|
$deposits = $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
||||||
|
pr(array_merge(array('function' => 'Lease::findSecurityDeposits',
|
||||||
|
'checkpoint' => 'return'),
|
||||||
|
compact('deposits')));
|
||||||
|
return $deposits;
|
||||||
|
//return $this->Account->findSecurityDeposits($lease['Lease']['account_id'], $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested lease.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Find the associated account.
|
||||||
|
$lease = $this->find('first',
|
||||||
|
array('recursive' => -1,
|
||||||
|
'conditions' => array(array('Lease.id' => $id))));
|
||||||
|
|
||||||
|
// Pull the stats from the account.
|
||||||
|
$stats['Account'] = $this->Account->stats($lease['Lease']['account_id']);
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -7,21 +7,8 @@ class LeaseType extends AppModel {
|
|||||||
'name' => array('notempty')
|
'name' => array('notempty')
|
||||||
);
|
);
|
||||||
|
|
||||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'Lease' => array(
|
'Lease',
|
||||||
'className' => 'Lease',
|
|
||||||
'foreignKey' => 'lease_type_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,58 +8,149 @@ class Ledger extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'Account' => array(
|
'Account',
|
||||||
'className' => 'Account',
|
|
||||||
'foreignKey' => 'account_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
/* 'LedgerEntry' => array( */
|
'LedgerEntry' => array(
|
||||||
/* 'className' => 'LedgerEntry', */
|
'className' => 'LedgerEntry',
|
||||||
/* 'foreignKey' => false, */
|
'foreignKey' => false,
|
||||||
/* 'dependent' => false, */
|
// conditions will be used when JOINing tables
|
||||||
/* 'conditions' => '', */
|
// (such as find with LinkableBehavior)
|
||||||
/* 'fields' => '', */
|
'conditions' => array('OR' =>
|
||||||
/* 'order' => '', */
|
array('LedgerEntry.debit_ledger_id = Ledger.id',
|
||||||
/* 'limit' => '', */
|
'LedgerEntry.credit_ledger_id = Ledger.id')),
|
||||||
/* 'offset' => '', */
|
// finderQuery will be used when tables are put
|
||||||
/* 'exclusive' => '', */
|
// together across several querys, not with JOIN.
|
||||||
/* 'finderQuery' => 'SELECT `Entry`.* FROM pmgr_entries AS `Entry` */
|
// (such as find with ContainableBehavior)
|
||||||
/* WHERE Entry.debit_ledger_id = ({$__cakeID__$}) */
|
'finderQuery' => 'SELECT `LedgerEntry`.*
|
||||||
/* OR Entry.credit_ledger_id = ({$__cakeID__$})', */
|
FROM pmgr_ledger_entries AS `LedgerEntry`
|
||||||
/* 'counterQuery' => '' */
|
WHERE LedgerEntry.debit_ledger_id = ({$__cakeID__$})
|
||||||
/* ), */
|
OR LedgerEntry.credit_ledger_id = ({$__cakeID__$})',
|
||||||
|
'counterQuery' => ''
|
||||||
|
),
|
||||||
'DebitLedgerEntry' => array(
|
'DebitLedgerEntry' => array(
|
||||||
'className' => 'LedgerEntry',
|
'className' => 'LedgerEntry',
|
||||||
'foreignKey' => 'debit_ledger_id',
|
'foreignKey' => 'debit_ledger_id',
|
||||||
'dependent' => false,
|
'dependent' => false,
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
),
|
||||||
'CreditLedgerEntry' => array(
|
'CreditLedgerEntry' => array(
|
||||||
'className' => 'LedgerEntry',
|
'className' => 'LedgerEntry',
|
||||||
'foreignKey' => 'credit_ledger_id',
|
'foreignKey' => 'credit_ledger_id',
|
||||||
'dependent' => false,
|
'dependent' => false,
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerEntries
|
||||||
|
* - Returns an array of ledger entries that belong to a given
|
||||||
|
* ledger. There is extra work done... see the LedgerEntry model.
|
||||||
|
*/
|
||||||
|
function findLedgerEntries($id, $account_type = null, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Ledger::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'account_type', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
if (!isset($account_type)) {
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$ledger = $this->find('first', array
|
||||||
|
('contain' => array
|
||||||
|
('Account' => array
|
||||||
|
('fields' => array('type'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Ledger.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
$account_type = $ledger['Account']['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the requested entries are limited by date, we must calculate
|
||||||
|
// a balance forward, or the resulting balance will be thrown off.
|
||||||
|
|
||||||
|
// REVISIT <AP>: This obviously is more general than date.
|
||||||
|
// As such, it will not work (or, only work if the
|
||||||
|
// condition only manages to exclude the first parts
|
||||||
|
// of the ledger, nothing in the middle or at the
|
||||||
|
// end. For now, I'll just create an 'other' entry,
|
||||||
|
// not necessarily a balance forward.
|
||||||
|
|
||||||
|
$bf = array();
|
||||||
|
if (0 && isset($cond)) {
|
||||||
|
//$date = '<NOT IMPLEMENTED>';
|
||||||
|
$stats = $this->stats($id, array('NOT' => array($cond)));
|
||||||
|
$bf = array(array(array('debit' => $stats['debits'],
|
||||||
|
'credit' => $stats['credits'],
|
||||||
|
'balance' => $stats['balance']),
|
||||||
|
|
||||||
|
'LedgerEntry' => array('id' => null,
|
||||||
|
//'comment' => "Balance Forward from $date"),
|
||||||
|
'comment' => "-- SUMMARY OF EXCLUDED ENTRIES --"),
|
||||||
|
|
||||||
|
'Transaction' => array('id' => null,
|
||||||
|
//'stamp' => $date,
|
||||||
|
'stamp' => null,
|
||||||
|
'comment' => null),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$entries = $this->LedgerEntry->findInLedgerContext($id, $account_type, $cond, $link);
|
||||||
|
/* pr(array('function' => 'Ledger::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'account_type', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('ledger'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
|
||||||
|
// Return entries from the ledger, along with our balance forward.
|
||||||
|
/* return array_merge($bf, */
|
||||||
|
/* $this->LedgerEntry->findInLedgerContext($id, $account_type, $cond, $link)); */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested ledger.
|
||||||
|
*/
|
||||||
|
function stats($id, $cond = null) {
|
||||||
|
|
||||||
|
$stats = $this->find
|
||||||
|
('first', array
|
||||||
|
('link' =>
|
||||||
|
array(// Models
|
||||||
|
'Account' => array('fields' => array()),
|
||||||
|
//'LedgerEntry' => array('fields' => array()),
|
||||||
|
'LedgerEntry' =>
|
||||||
|
array('fields' => array(),
|
||||||
|
'Transaction' => array('fields' => array('stamp')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'fields' =>
|
||||||
|
array("SUM(IF(LedgerEntry.debit_ledger_id = Ledger.id,
|
||||||
|
LedgerEntry.amount, NULL)) AS debits",
|
||||||
|
"SUM(IF(LedgerEntry.credit_ledger_id = Ledger.id,
|
||||||
|
LedgerEntry.amount, NULL)) AS credits",
|
||||||
|
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
||||||
|
IF(LedgerEntry.debit_ledger_id = Ledger.id, 1, -1),
|
||||||
|
IF(LedgerEntry.credit_ledger_id = Ledger.id, 1, -1)
|
||||||
|
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
|
||||||
|
) AS balance",
|
||||||
|
"COUNT(LedgerEntry.id) AS entries"),
|
||||||
|
'conditions' => array(isset($cond) ? $cond : array(),
|
||||||
|
array('Ledger.id' => $id)),
|
||||||
|
'group' => 'Ledger.id',
|
||||||
|
));
|
||||||
|
|
||||||
|
// The fields are all tucked into the [0] index,
|
||||||
|
// and the rest of the array is useless (empty).
|
||||||
|
return $stats[0];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -9,35 +9,89 @@ class LedgerEntry extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'MonetarySource' => array(
|
'MonetarySource',
|
||||||
'className' => 'MonetarySource',
|
'Transaction',
|
||||||
'foreignKey' => 'monetary_source_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'Transaction' => array(
|
|
||||||
'className' => 'Transaction',
|
|
||||||
'foreignKey' => 'transaction_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'DebitLedger' => array(
|
'DebitLedger' => array(
|
||||||
'className' => 'Ledger',
|
'className' => 'Ledger',
|
||||||
'foreignKey' => 'debit_ledger_id',
|
'foreignKey' => 'debit_ledger_id',
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
),
|
||||||
'CreditLedger' => array(
|
'CreditLedger' => array(
|
||||||
'className' => 'Ledger',
|
'className' => 'Ledger',
|
||||||
'foreignKey' => 'credit_ledger_id',
|
'foreignKey' => 'credit_ledger_id',
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function:
|
||||||
|
* -
|
||||||
|
*/
|
||||||
|
function conditionEntryAsCreditOrDebit($ledger_ids) {
|
||||||
|
return array('OR' =>
|
||||||
|
array(array('debit_ledger_id' => $ledger_ids),
|
||||||
|
array('credit_ledger_id' => $ledger_ids)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findInLedgerContext
|
||||||
|
* - Returns an array of ledger entries that belong to a given ledger.
|
||||||
|
* There is extra logic to also figure out whether the ledger_entry
|
||||||
|
* amount is either a credit, or a debit, depending on how it was
|
||||||
|
* written into the ledger, as well as whether the amount increases or
|
||||||
|
* decreases the balance depending on the particular account type of
|
||||||
|
* the ledger.
|
||||||
|
*/
|
||||||
|
function findInLedgerContext($ledger_id, $account_type, $cond = null, $link = null) {
|
||||||
|
if (!isset($link))
|
||||||
|
$link = array('Transaction');
|
||||||
|
|
||||||
|
if (in_array($account_type, array('ASSET', 'EXPENSE')))
|
||||||
|
$ledger_type = 'debit';
|
||||||
|
else
|
||||||
|
$ledger_type = 'credit';
|
||||||
|
|
||||||
|
$entries = $this->find
|
||||||
|
('all',
|
||||||
|
array('link' => $link,
|
||||||
|
|
||||||
|
'fields' =>
|
||||||
|
array('id', 'name', 'comment',
|
||||||
|
"IF(LedgerEntry.debit_ledger_id = $ledger_id," .
|
||||||
|
" LedgerEntry.amount, NULL) AS debit",
|
||||||
|
"IF(LedgerEntry.credit_ledger_id = $ledger_id," .
|
||||||
|
" LedgerEntry.amount, NULL) AS credit",
|
||||||
|
"(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id, 1, -1)" .
|
||||||
|
" * LedgerEntry.amount) AS balance"),
|
||||||
|
|
||||||
|
'conditions' =>
|
||||||
|
array(isset($cond) ? $cond : array(),
|
||||||
|
'OR' =>
|
||||||
|
array(array('LedgerEntry.debit_ledger_id' => $ledger_id),
|
||||||
|
array('LedgerEntry.credit_ledger_id' => $ledger_id))),
|
||||||
|
|
||||||
|
'order' =>
|
||||||
|
array('Transaction.stamp'),
|
||||||
|
));
|
||||||
|
|
||||||
|
/* $entries['summary'] = array('balance' => null, 'debit' => null, 'credit' => null); */
|
||||||
|
/* foreach($entries AS $entry) */
|
||||||
|
/* $this->statsMerge($entries['summary'], $entry[0]); */
|
||||||
|
|
||||||
|
/* //if (isset($entries['summary']['debit']) || isset($entries['summary']['credit'])) { */
|
||||||
|
/* $entries['summary']['debits'] = $entries['summary']['debit']; */
|
||||||
|
/* $entries['summary']['credits'] = $entries['summary']['credit']; */
|
||||||
|
/* unset($entries['summary']['debit']); */
|
||||||
|
/* unset($entries['summary']['credit']); */
|
||||||
|
/* //} */
|
||||||
|
|
||||||
|
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -11,33 +11,12 @@ class Map extends AppModel {
|
|||||||
'depth' => array('numeric')
|
'depth' => array('numeric')
|
||||||
);
|
);
|
||||||
|
|
||||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'SiteArea' => array(
|
'SiteArea',
|
||||||
'className' => 'SiteArea',
|
|
||||||
'foreignKey' => 'site_area_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Unit' => array(
|
'Unit',
|
||||||
'className' => 'Unit',
|
|
||||||
'joinTable' => 'maps_units',
|
|
||||||
'foreignKey' => 'map_id',
|
|
||||||
'associationForeignKey' => 'unit_id',
|
|
||||||
'unique' => true,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'deleteQuery' => '',
|
|
||||||
'insertQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,7 @@ class MonetarySource extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'MonetaryType' => array(
|
'MonetaryType',
|
||||||
'className' => 'MonetaryType',
|
|
||||||
'foreignKey' => 'monetary_type_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,7 @@ class MonetaryType extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'MonetarySource' => array(
|
'MonetarySource',
|
||||||
'className' => 'MonetarySource',
|
|
||||||
'foreignKey' => 'monetary_type_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,34 +7,9 @@ class Site extends AppModel {
|
|||||||
'name' => array('notempty')
|
'name' => array('notempty')
|
||||||
);
|
);
|
||||||
|
|
||||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'SiteArea' => array(
|
'SiteArea',
|
||||||
'className' => 'SiteArea',
|
'SiteOption',
|
||||||
'foreignKey' => 'site_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
),
|
|
||||||
'SiteOption' => array(
|
|
||||||
'className' => 'SiteOption',
|
|
||||||
'foreignKey' => 'site_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,26 +8,12 @@ class SiteArea extends AppModel {
|
|||||||
'name' => array('notempty')
|
'name' => array('notempty')
|
||||||
);
|
);
|
||||||
|
|
||||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'Site' => array(
|
'Site',
|
||||||
'className' => 'Site',
|
|
||||||
'foreignKey' => 'site_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasOne = array(
|
var $hasOne = array(
|
||||||
'Map' => array(
|
'Map',
|
||||||
'className' => 'Map',
|
|
||||||
'foreignKey' => 'site_area_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,29 +8,11 @@ class Transaction extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'Customer' => array(
|
'Customer',
|
||||||
'className' => 'Customer',
|
|
||||||
'foreignKey' => 'customer_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'LedgerEntry' => array(
|
'LedgerEntry',
|
||||||
'className' => 'LedgerEntry',
|
|
||||||
'foreignKey' => 'transaction_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,27 +13,15 @@ class Unit extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'UnitSize' => array(
|
'UnitSize',
|
||||||
'className' => 'UnitSize',
|
);
|
||||||
'foreignKey' => 'unit_size_id',
|
|
||||||
'conditions' => '',
|
var $hasOne = array(
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
|
||||||
'CurrentLease' => array(
|
'CurrentLease' => array(
|
||||||
'className' => 'Lease',
|
'className' => 'Lease',
|
||||||
'foreignKey' => 'current_lease_id',
|
//'foreignKey' => 'unit_id',
|
||||||
'conditions' => '',
|
'conditions' => 'CurrentLease.close_date IS NULL',
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
),
|
),
|
||||||
/* 'Map' => array( */
|
|
||||||
/* 'className' => 'MapsUnit', */
|
|
||||||
/* 'foreignKey' => 'unit_id', */
|
|
||||||
/* 'conditions' => '', */
|
|
||||||
/* 'fields' => '', */
|
|
||||||
/* 'order' => '' */
|
|
||||||
/* ) */
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
@@ -41,14 +29,6 @@ class Unit extends AppModel {
|
|||||||
'className' => 'Lease',
|
'className' => 'Lease',
|
||||||
'foreignKey' => 'unit_id',
|
'foreignKey' => 'unit_id',
|
||||||
'dependent' => false,
|
'dependent' => false,
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -83,4 +63,32 @@ class Unit extends AppModel {
|
|||||||
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
|
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$this->Behaviors->attach('Containable');
|
||||||
|
$unit = $this->find('first',
|
||||||
|
array('contain' => array
|
||||||
|
('Lease' => array('fields' => array('Lease.id')),
|
||||||
|
'CurrentLease' => array('fields' => array('CurrentLease.id'))),
|
||||||
|
'conditions' => array(array('Unit.id' => $id))));
|
||||||
|
$this->Behaviors->detach('Containable');
|
||||||
|
|
||||||
|
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);
|
||||||
|
|
||||||
|
foreach ($unit['Lease'] AS $lease) {
|
||||||
|
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,29 +14,11 @@ class UnitSize extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'UnitType' => array(
|
'UnitType',
|
||||||
'className' => 'UnitType',
|
|
||||||
'foreignKey' => 'unit_type_id',
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'Unit' => array(
|
'Unit',
|
||||||
'className' => 'Unit',
|
|
||||||
'foreignKey' => 'unit_size_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,7 @@ class UnitType extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
'UnitSize' => array(
|
'UnitSize',
|
||||||
'className' => 'UnitSize',
|
|
||||||
'foreignKey' => 'unit_type_id',
|
|
||||||
'dependent' => false,
|
|
||||||
'conditions' => '',
|
|
||||||
'fields' => '',
|
|
||||||
'order' => '',
|
|
||||||
'limit' => '',
|
|
||||||
'offset' => '',
|
|
||||||
'exclusive' => '',
|
|
||||||
'finderQuery' => '',
|
|
||||||
'counterQuery' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,22 @@ echo $this->element('table',
|
|||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Ledger
|
* Ledgers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
echo $this->element('ledgers',
|
echo $this->element('ledgers',
|
||||||
array('caption' => $account['Account']['name'] . " Ledgers",
|
array('caption' => $account['Account']['name'] . " Ledgers",
|
||||||
'ledgers' => $account['Ledger']));
|
'ledgers' => $account['Ledger']));
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* Current Ledger
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo $this->element('ledger_entries',
|
||||||
|
array('caption' => "Current Ledger: (#{$account['CurrentLedger']['sequence']})",
|
||||||
|
'ledger_entries' => $account['CurrentLedger']['LedgerEntry']));
|
||||||
|
|
||||||
/* End "detail supporting" DIV */ ?>
|
/* End "detail supporting" DIV */ ?>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
* Contact Detail Main Section
|
* Contact Detail Main Section
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$rows = array(array('Name', $contact['Contact']['display_name']),
|
$rows = array(array('First Name', $contact['Contact']['first_name']),
|
||||||
|
array('Middle Name', $contact['Contact']['middle_name']),
|
||||||
|
array('Last Name', $contact['Contact']['last_name']),
|
||||||
array('Company', $contact['Contact']['company_name']),
|
array('Company', $contact['Contact']['company_name']),
|
||||||
array('SSN', $contact['Contact']['id_federal']),
|
array('SSN', $contact['Contact']['id_federal']),
|
||||||
array('ID', ($contact['Contact']['id_local']
|
array('ID', ($contact['Contact']['id_local']
|
||||||
|
|||||||
@@ -31,17 +31,16 @@ if (isset($paginator)) {
|
|||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$extra = null;
|
//pr($account);
|
||||||
if (isset($account[0])) {
|
if (isset($account[0]))
|
||||||
$extra = $account[0];
|
$stats = $account[0];
|
||||||
unset($account[0]);
|
else
|
||||||
}
|
$stats = $account;
|
||||||
|
|
||||||
|
// Move our pointer to the meat
|
||||||
if (isset($account['Account']))
|
if (isset($account['Account']))
|
||||||
$account = $account['Account'];
|
$account = $account['Account'];
|
||||||
|
|
||||||
if (isset($extra))
|
|
||||||
$account = array_merge($account, $extra);
|
|
||||||
|
|
||||||
$rows[] = array($html->link($account['name'],
|
$rows[] = array($html->link($account['name'],
|
||||||
array('controller' => 'accounts',
|
array('controller' => 'accounts',
|
||||||
'action' => 'view',
|
'action' => 'view',
|
||||||
@@ -49,10 +48,10 @@ foreach ($accounts as $account) {
|
|||||||
$account['type'],
|
$account['type'],
|
||||||
$account['external_name'],
|
$account['external_name'],
|
||||||
$account['external_account'],
|
$account['external_account'],
|
||||||
$account['entries'],
|
$stats['entries'],
|
||||||
FormatHelper::currency($account['debits']),
|
FormatHelper::currency($stats['debits']),
|
||||||
FormatHelper::currency($account['credits']),
|
FormatHelper::currency($stats['credits']),
|
||||||
FormatHelper::currency($account['balance']),
|
FormatHelper::currency($stats['balance']),
|
||||||
$account['comment'],
|
$account['comment'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ foreach ($contacts as $contact) {
|
|||||||
$contact['company_name']),
|
$contact['company_name']),
|
||||||
(isset($contact['ContactsCustomer'])
|
(isset($contact['ContactsCustomer'])
|
||||||
? array($contact['ContactsCustomer']['type'],
|
? array($contact['ContactsCustomer']['type'],
|
||||||
$contact['ContactsCustomer']['active'],
|
$contact['ContactsCustomer']['active'] ? 'Yes' : 'No',
|
||||||
$contact['ContactsCustomer']['comment'])
|
$contact['ContactsCustomer']['comment'])
|
||||||
: array($contact['comment'])));
|
: array($contact['comment'])));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ if (isset($heading))
|
|||||||
elseif (!isset($caption))
|
elseif (!isset($caption))
|
||||||
echo '<h2>'.__('Customers',true).'</h2>';
|
echo '<h2>'.__('Customers',true).'</h2>';
|
||||||
|
|
||||||
$headers = array('ID', 'Name', 'Comment');
|
$headers = array_merge(array('Name'),
|
||||||
|
isset($customers[0]['ContactsCustomer'])
|
||||||
|
? array('Relationship')
|
||||||
|
: array(),
|
||||||
|
array('Comment'));
|
||||||
$column_class = array();
|
$column_class = array();
|
||||||
foreach (array_intersect($headers, array('ID')) AS $k => $v) {
|
|
||||||
$column_class[$k] = 'id';
|
|
||||||
}
|
|
||||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||||
$column_class[$k] = 'comment';
|
$column_class[$k] = 'comment';
|
||||||
}
|
}
|
||||||
@@ -18,25 +19,30 @@ if (isset($paginator)) {
|
|||||||
echo $paginator->counter(array(
|
echo $paginator->counter(array(
|
||||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||||
|
|
||||||
$headers = array($paginator->sort('id'),
|
$headers = array_merge(array($paginator->sort('name')),
|
||||||
$paginator->sort('name'),
|
isset($customers[0]['ContactsCustomer'])
|
||||||
$paginator->sort('comment'));
|
? array($paginator->sort('Relationship', 'type'))
|
||||||
|
: array(),
|
||||||
|
array($paginator->sort('comment')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($customers as $customer) {
|
foreach ($customers as $customer) {
|
||||||
|
$contacts_customer = null;
|
||||||
|
if (isset($customer['ContactsCustomer']))
|
||||||
|
$contacts_customer = $customer['ContactsCustomer'];
|
||||||
|
|
||||||
if (isset($customer['Customer']))
|
if (isset($customer['Customer']))
|
||||||
$customer = $customer['Customer'];
|
$customer = $customer['Customer'];
|
||||||
|
|
||||||
$rows[] = array($html->link($customer['id'],
|
$rows[] = array_merge(array($html->link($customer['name'],
|
||||||
array('controller' => 'customers',
|
array('controller' => 'customers',
|
||||||
'action' => 'view',
|
'action' => 'view',
|
||||||
$customer['id'])),
|
$customer['id']))),
|
||||||
$html->link($customer['name'],
|
isset($contacts_customer)
|
||||||
array('controller' => 'customers',
|
? array($contacts_customer['type'])
|
||||||
'action' => 'view',
|
: array(),
|
||||||
$customer['id'])),
|
array($customer['comment']));
|
||||||
$customer['comment']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $this->element('table',
|
echo $this->element('table',
|
||||||
|
|||||||
82
views/elements/leases.ctp
Normal file
82
views/elements/leases.ctp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
<?php /* -*- mode:PHP -*- */
|
||||||
|
|
||||||
|
if (isset($heading))
|
||||||
|
echo $heading;
|
||||||
|
elseif (!isset($caption))
|
||||||
|
echo '<h2>'.__('Leases',true).'</h2>';
|
||||||
|
|
||||||
|
$headers = array_merge(array('Lease'),
|
||||||
|
isset($leases[0]['Unit'])
|
||||||
|
? array('Unit')
|
||||||
|
: array('Customer'),
|
||||||
|
array('Signed', 'Move-In', 'Move-Out', 'Balance', 'Comment'));
|
||||||
|
$column_class = array();
|
||||||
|
foreach (array_intersect($headers, array('Lease', 'Unit')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'id';
|
||||||
|
}
|
||||||
|
foreach (array_intersect($headers, array('Balance')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'currency';
|
||||||
|
}
|
||||||
|
|
||||||
|
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('Signed', 'lease_date'),
|
||||||
|
$paginator->sort('Move-In', 'movein_date'),
|
||||||
|
$paginator->sort('Move-Out', 'moveout_date'),
|
||||||
|
$paginator->sort('balance'),
|
||||||
|
$paginator->sort('comment')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
foreach($leases AS $lease) {
|
||||||
|
$unit = $customer = null;
|
||||||
|
|
||||||
|
if (isset($lease['Unit']))
|
||||||
|
$unit = $lease['Unit'];
|
||||||
|
else
|
||||||
|
$customer = $lease['Customer'];
|
||||||
|
|
||||||
|
if (isset($lease['Lease']))
|
||||||
|
$lease = $lease['Lease'];
|
||||||
|
|
||||||
|
$rows[] = array_merge(array($html->link('#'.$lease['number'],
|
||||||
|
array('controller' => 'leases',
|
||||||
|
'action' => 'view',
|
||||||
|
$lease['id']))),
|
||||||
|
isset($unit)
|
||||||
|
? array($html->link($unit['name'],
|
||||||
|
array('controller' => 'units',
|
||||||
|
'action' => 'view',
|
||||||
|
$unit['id'])))
|
||||||
|
: array($html->link($customer['name'],
|
||||||
|
array('controller' => 'customers',
|
||||||
|
'action' => 'view',
|
||||||
|
$customer['id']))),
|
||||||
|
array(FormatHelper::date($lease['lease_date']),
|
||||||
|
FormatHelper::date($lease['movein_date']),
|
||||||
|
FormatHelper::date($lease['moveout_date']),
|
||||||
|
FormatHelper::currency($lease['balance']),
|
||||||
|
$lease['comment']));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $this->element('table',
|
||||||
|
array('class' => 'item lease list',
|
||||||
|
'caption' => isset($caption) ? $caption : null,
|
||||||
|
'headers' => $headers,
|
||||||
|
'rows' => $rows,
|
||||||
|
'column_class' => $column_class));
|
||||||
|
|
||||||
|
if (isset($paginator)) {
|
||||||
|
echo('<div class="paging">' . "\n");
|
||||||
|
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
|
||||||
|
echo(' | ');
|
||||||
|
echo $paginator->numbers();
|
||||||
|
echo(' | ');
|
||||||
|
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
|
||||||
|
echo('</div>' . "\n");
|
||||||
|
}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<?php /* -*- mode:PHP -*- */
|
|
||||||
|
|
||||||
if (isset($heading))
|
|
||||||
echo $heading;
|
|
||||||
elseif (!isset($caption))
|
|
||||||
echo '<h2>'.__('Ledger',true).'</h2>';
|
|
||||||
|
|
||||||
$headers = array('Transaction', 'Entry', 'Date', 'Customer', 'Comment', 'Debit', 'Credit', 'Total');
|
|
||||||
$column_class = array();
|
|
||||||
foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) {
|
|
||||||
$column_class[$k] = array($column_class[$k], 'id');
|
|
||||||
}
|
|
||||||
foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) {
|
|
||||||
$column_class[$k] = array($column_class[$k], 'currency');
|
|
||||||
}
|
|
||||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
|
||||||
$column_class[$k] = 'slack';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
$running_total = 0;
|
|
||||||
foreach($entries AS $entry) {
|
|
||||||
$transaction = $entry['Transaction'];
|
|
||||||
$customer = $entry['Customer'];
|
|
||||||
|
|
||||||
$credit = $debit = null;
|
|
||||||
$running_total += $entry['balance'];
|
|
||||||
|
|
||||||
if (isset($entry['debit']))
|
|
||||||
$debit = $entry['debit'];
|
|
||||||
if (isset($entry['credit']))
|
|
||||||
$credit = $entry['credit'];
|
|
||||||
|
|
||||||
// Now that we've extracted top level 'entry' data
|
|
||||||
// move our variable to the meat of 'LedgerEntry' for clarity
|
|
||||||
$entry = $entry['LedgerEntry'];
|
|
||||||
|
|
||||||
$rows[] = array($html->link('#'.$transaction['id'],
|
|
||||||
array('controller' => 'transactions',
|
|
||||||
'action' => 'view',
|
|
||||||
$transaction['id'])),
|
|
||||||
$html->link('#'.$entry['id'],
|
|
||||||
array('controller' => 'ledger_entries',
|
|
||||||
'action' => 'view',
|
|
||||||
$entry['id'])),
|
|
||||||
FormatHelper::date($transaction['stamp']),
|
|
||||||
$html->link($customer['name'],
|
|
||||||
array('controller' => 'customers',
|
|
||||||
'action' => 'view',
|
|
||||||
$customer['id'])),
|
|
||||||
FormatHelper::comment(array($transaction['comment'], $entry['comment'])),
|
|
||||||
FormatHelper::currency($debit),
|
|
||||||
FormatHelper::currency($credit),
|
|
||||||
FormatHelper::currency($running_total)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $this->element('table',
|
|
||||||
array('class' => 'item account ledger list',
|
|
||||||
'caption' => isset($caption) ? $caption : null,
|
|
||||||
'headers' => $headers,
|
|
||||||
'rows' => $rows,
|
|
||||||
'column_class' => $column_class));
|
|
||||||
|
|
||||||
?>
|
|
||||||
69
views/elements/ledger_entries.ctp
Normal file
69
views/elements/ledger_entries.ctp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php /* -*- mode:PHP -*- */
|
||||||
|
|
||||||
|
if (isset($heading))
|
||||||
|
echo $heading;
|
||||||
|
elseif (!isset($caption))
|
||||||
|
echo '<h2>'.__('Ledger Entries',true).'</h2>';
|
||||||
|
|
||||||
|
$headers = array('Transaction', 'Entry', 'Date', 'Comment', 'Debit', 'Credit', 'Total');
|
||||||
|
$column_class = array();
|
||||||
|
foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'id';
|
||||||
|
}
|
||||||
|
foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'currency';
|
||||||
|
}
|
||||||
|
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'slack';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
$running_total = 0;
|
||||||
|
foreach($ledger_entries AS $entry) {
|
||||||
|
$credit = $debit = null;
|
||||||
|
$running_total += $entry[0]['balance'];
|
||||||
|
|
||||||
|
if (isset($entry[0]['debit']))
|
||||||
|
$debit = $entry[0]['debit'];
|
||||||
|
if (isset($entry[0]['credit']))
|
||||||
|
$credit = $entry[0]['credit'];
|
||||||
|
|
||||||
|
// local references to linked tables
|
||||||
|
$transaction = $entry['Transaction'];
|
||||||
|
|
||||||
|
// Now that we've extracted top level 'LedgerEntry' data
|
||||||
|
// move our variable to the meat of 'LedgerEntry' for clarity
|
||||||
|
if (isset($entry['LedgerEntry']))
|
||||||
|
$entry = $entry['LedgerEntry'];
|
||||||
|
|
||||||
|
$rows[] = array(isset($transaction['id'])
|
||||||
|
? $html->link('#'.$transaction['id'],
|
||||||
|
array('controller' => 'transactions',
|
||||||
|
'action' => 'view',
|
||||||
|
$transaction['id']))
|
||||||
|
: null,
|
||||||
|
|
||||||
|
isset($entry['id'])
|
||||||
|
? $html->link('#'.$entry['id'],
|
||||||
|
array('controller' => 'ledger_entries',
|
||||||
|
'action' => 'view',
|
||||||
|
$entry['id']))
|
||||||
|
: null,
|
||||||
|
|
||||||
|
FormatHelper::date($transaction['stamp']),
|
||||||
|
FormatHelper::comment(array($transaction['comment'], $entry['comment'])),
|
||||||
|
FormatHelper::currency($debit),
|
||||||
|
FormatHelper::currency($credit),
|
||||||
|
FormatHelper::currency($running_total)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $this->element('table',
|
||||||
|
array('class' => 'item ledger-entries list',
|
||||||
|
'caption' => isset($caption) ? $caption : null,
|
||||||
|
'headers' => $headers,
|
||||||
|
'rows' => $rows,
|
||||||
|
'column_class' => $column_class));
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -5,12 +5,15 @@ if (isset($heading))
|
|||||||
elseif (!isset($caption))
|
elseif (!isset($caption))
|
||||||
echo '<h2>'.__('Ledgers',true).'</h2>';
|
echo '<h2>'.__('Ledgers',true).'</h2>';
|
||||||
|
|
||||||
$headers = array_merge(array('Name'),
|
$headers = array_merge(array('Sequence'), //array('Name'),
|
||||||
(isset($ledgers[0]['Account'])
|
(isset($ledgers[0]['Account'])
|
||||||
? array('Account')
|
? array('Account')
|
||||||
: array()),
|
: array()),
|
||||||
array('Entries', 'Debits', 'Credits', 'Balance', 'Closed', 'Comment'));
|
array('Entries', 'Debits', 'Credits', 'Balance', 'Close Date', 'Comment'));
|
||||||
$column_class = array();
|
$column_class = array();
|
||||||
|
foreach (array_intersect($headers, array('ID', 'Sequence')) AS $k => $v) {
|
||||||
|
$column_class[$k] = 'id';
|
||||||
|
}
|
||||||
foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
foreach (array_intersect($headers, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
||||||
$column_class[$k] = 'currency';
|
$column_class[$k] = 'currency';
|
||||||
}
|
}
|
||||||
@@ -22,7 +25,7 @@ if (isset($paginator)) {
|
|||||||
echo $paginator->counter(array(
|
echo $paginator->counter(array(
|
||||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||||
|
|
||||||
$headers = array_merge(array($paginator->sort('name')),
|
$headers = array_merge(array($paginator->sort('sequence')), //array($paginator->sort('name')),
|
||||||
(isset($ledgers[0]['Account'])
|
(isset($ledgers[0]['Account'])
|
||||||
? array($paginator->sort('Account', 'Account.name'))
|
? array($paginator->sort('Account', 'Account.name'))
|
||||||
: array()),
|
: array()),
|
||||||
@@ -30,35 +33,40 @@ if (isset($paginator)) {
|
|||||||
$paginator->sort('debits'),
|
$paginator->sort('debits'),
|
||||||
$paginator->sort('credits'),
|
$paginator->sort('credits'),
|
||||||
$paginator->sort('balance'),
|
$paginator->sort('balance'),
|
||||||
$paginator->sort('closed'),
|
$paginator->sort('Close Date', 'close_stamp'),
|
||||||
$paginator->sort('comment')));
|
$paginator->sort('comment')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($ledgers as $ledger) {
|
foreach ($ledgers as $ledger) {
|
||||||
|
$account = null;
|
||||||
|
$stats = null;
|
||||||
|
|
||||||
if (isset($ledger[0]))
|
if (isset($ledger[0]))
|
||||||
$ledger = array_merge($ledger[0], array_diff_key($ledger, array(0=>1)));
|
$stats = $ledger[0];
|
||||||
if (isset($ledger['Ledger']))
|
else
|
||||||
$ledger = array_merge($ledger['Ledger'], array_diff_key($ledger, array('Ledger'=>1)));
|
$stats = $ledger;
|
||||||
|
|
||||||
if (isset($ledger['Account']))
|
if (isset($ledger['Account']))
|
||||||
$account = $ledger['Account'];
|
$account = $ledger['Account'];
|
||||||
|
if (isset($ledger['Ledger']))
|
||||||
|
$ledger = $ledger['Ledger'];
|
||||||
|
|
||||||
$rows[] = array_merge(array($html->link($ledger['name'],
|
$rows[] = array_merge(array($html->link('#'.$ledger['sequence'],//$ledger['name'],
|
||||||
array('controller' => 'ledgers',
|
array('controller' => 'ledgers',
|
||||||
'action' => 'view',
|
'action' => 'view',
|
||||||
$ledger['id']))),
|
$ledger['id']))),
|
||||||
(isset($ledger['Account'])
|
(isset($account)
|
||||||
? array($html->link($account['name'],
|
? array($html->link($account['name'],
|
||||||
array('controller' => 'accounts',
|
array('controller' => 'accounts',
|
||||||
'action' => 'view',
|
'action' => 'view',
|
||||||
$account['id'])))
|
$account['id'])))
|
||||||
: array()),
|
: array()),
|
||||||
array($ledger['entries'],
|
array($stats['entries'],
|
||||||
FormatHelper::currency($ledger['debits']),
|
FormatHelper::currency($stats['debits']),
|
||||||
FormatHelper::currency($ledger['credits']),
|
FormatHelper::currency($stats['credits']),
|
||||||
FormatHelper::currency($ledger['balance']),
|
FormatHelper::currency($stats['balance']),
|
||||||
$ledger['closed'] ? 'Closed' : 'Open',
|
FormatHelper::datetime($ledger['close_stamp']),
|
||||||
$ledger['comment']));
|
$ledger['comment']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ class FormatHelper extends AppHelper {
|
|||||||
|
|
||||||
function currency($amount) {
|
function currency($amount) {
|
||||||
if (!isset($amount))
|
if (!isset($amount))
|
||||||
return null;
|
return '-';
|
||||||
|
//return null;
|
||||||
|
|
||||||
return (isset($amount)
|
return (isset($amount)
|
||||||
? self::$number->currency($amount)
|
? self::$number->currency($amount)
|
||||||
@@ -34,7 +35,7 @@ class FormatHelper extends AppHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function datetime($datetime) {
|
function datetime($datetime) {
|
||||||
if (!$date) return null;
|
if (!$datetime) return null;
|
||||||
return self::$time->nice($datetime);
|
return self::$time->nice($datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,11 +56,9 @@ echo $this->element('table',
|
|||||||
* Ledger
|
* Ledger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
echo $this->element('ledger',
|
echo $this->element('ledger_entries',
|
||||||
array('caption' => $ledger['Ledger']['name'],
|
array('caption' => $ledger['Ledger']['name'],
|
||||||
'ledger' => array('id' => $ledger['Ledger']['id'],
|
'ledger_entries' => $ledger['LedgerEntry']));
|
||||||
'type' => $ledger['Account']['type']),
|
|
||||||
'entries' => $ledger['LedgerEntry']));
|
|
||||||
|
|
||||||
/* End "detail supporting" DIV */ ?>
|
/* End "detail supporting" DIV */ ?>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|||||||
@@ -1,13 +1,3 @@
|
|||||||
<div class="transactions index">
|
<div class="transactions index">
|
||||||
|
|
||||||
<?php
|
|
||||||
function datefmt($date) {
|
|
||||||
$date_fmt = 'm/d/Y';
|
|
||||||
return ($date
|
|
||||||
? date_format(date_create($date), $date_fmt)
|
|
||||||
: null);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<?php echo $this->element('transactions', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
<?php echo $this->element('transactions', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$rows = array(array('ID', $transaction['Transaction']['id']),
|
$rows = array(array('ID', $transaction['Transaction']['id']),
|
||||||
array('Timestamp', datefmt($transaction['Transaction']['stamp'])),
|
array('Timestamp', FormatHelper::datetime($transaction['Transaction']['stamp'])),
|
||||||
array('Comment', $transaction['Transaction']['comment']));
|
array('Comment', $transaction['Transaction']['comment']));
|
||||||
|
|
||||||
echo $this->element('table',
|
echo $this->element('table',
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ echo $this->element('leases',
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Ledger History
|
* Ledger History
|
||||||
*/
|
*/
|
||||||
foreach($unit['Lease'] AS $lease) {
|
/* foreach($unit['Lease'] AS $lease) { */
|
||||||
pr($lease);
|
/* pr($lease); */
|
||||||
$caption = 'Lease #'.$lease['number'].' (Tenant: '.$lease['Customer']['name'].')';
|
/* $caption = 'Lease #'.$lease['number'].' (Tenant: '.$lease['Customer']['name'].')'; */
|
||||||
echo $this->element('ledger',
|
/* echo $this->element('lease', */
|
||||||
array('caption' => $caption,
|
/* array('caption' => $caption, */
|
||||||
'entries' => $lease['Customer']['Transaction'],
|
/* 'entries' => $lease['Customer']['Transaction'], */
|
||||||
'ledger' => array('mix'=>1)));
|
/* 'ledger' => array('mix'=>1))); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
/* End "detail supporting" DIV */ ?>
|
/* End "detail supporting" DIV */ ?>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ table.list td.currency { text-align: right; }
|
|||||||
/* White spacing exceptions */
|
/* White spacing exceptions */
|
||||||
td.comment { white-space: normal; }
|
td.comment { white-space: normal; }
|
||||||
|
|
||||||
|
/* Generic column to assign excess space */
|
||||||
|
table.list td.slack { width : 99%; }
|
||||||
|
|
||||||
|
/* Customers */
|
||||||
|
table.list.customer td.comment { width : 66%; }
|
||||||
|
|
||||||
/* Contacts */
|
/* Contacts */
|
||||||
table.list.contact td.comment { width : 66%; }
|
table.list.contact td.comment { width : 66%; }
|
||||||
|
|
||||||
@@ -124,16 +130,10 @@ table.list.phone td.comment ,
|
|||||||
table.list.email td.comment ,
|
table.list.email td.comment ,
|
||||||
table.list.address td.comment { width: auto; }
|
table.list.address td.comment { width: auto; }
|
||||||
|
|
||||||
/* Leases */
|
|
||||||
table.list.lease td.comment { width : 99%; }
|
|
||||||
|
|
||||||
/* Ledger Entries */
|
/* Ledger Entries */
|
||||||
table.list.ledger td { border-top : 1px dashed #ccc; }
|
table.list.ledger td { border-top : 1px dashed #ccc; }
|
||||||
table.list.ledger td.date.receipt { padding-left: 1em; }
|
table.list.ledger td.date.receipt { padding-left: 1em; }
|
||||||
table.list.ledger td.evnrow { background: #f4f4f4; }
|
table.list.ledger td.evnrow { background: #f4f4f4; }
|
||||||
table.list.ledger td.comment { width : 99%; }
|
|
||||||
|
|
||||||
/* Account Ledger Entries */
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user