Primarly a cleanup checkin, although a couple minor bugfixes were included as well.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@82 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -9,8 +9,10 @@ class AccountsController extends AppController {
|
||||
(// Models
|
||||
'LedgerEntry' =>
|
||||
array('fields' =>
|
||||
array('SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, LedgerEntry.amount, NULL)) AS debits',
|
||||
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, LedgerEntry.amount, NULL)) AS credits',
|
||||
array('SUM(IF(LedgerEntry.debit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS debits',
|
||||
'SUM(IF(LedgerEntry.credit_ledger_id = CurrentLedger.id,
|
||||
LedgerEntry.amount, NULL)) AS credits',
|
||||
"SUM(IF(Account.type IN ('ASSET', 'EXPENSE'),
|
||||
IF(LedgerEntry.debit_ledger_id = CurrentLedger.id, 1, -1),
|
||||
IF(LedgerEntry.credit_ledger_id = CurrentLedger.id, 1, -1)
|
||||
@@ -184,21 +186,9 @@ class AccountsController extends AppController {
|
||||
);
|
||||
$this->Account->Behaviors->detach('Containable');
|
||||
|
||||
// Simply debug stuff... testing.
|
||||
$cond = null;
|
||||
//$cond = array('Transaction.stamp >' => '2009-05-16');
|
||||
|
||||
// Get all ledger entries of the CURRENT ledger
|
||||
//$crap = $this->Account->findSecurityDeposits($id);
|
||||
//$crap = $this->Account->findAccountRelatedEntries($id, 8);
|
||||
//pr(array('crap', $crap));
|
||||
/* $this->autoRender = false; */
|
||||
/* return; */
|
||||
|
||||
// Get all ledger entries of the CURRENT ledger
|
||||
$account['CurrentLedger']['LedgerEntry']
|
||||
= $this->Account->findCurrentLedgerEntries($id, $cond);
|
||||
//pr(array('Account summary', $account));
|
||||
$entries = $this->Account->findLedgerEntries($id);
|
||||
$account['CurrentLedger']['LedgerEntry'] = $entries['Entries'];
|
||||
|
||||
// Summarize each ledger
|
||||
foreach($account['Ledger'] AS &$ledger)
|
||||
|
||||
@@ -74,8 +74,9 @@ class ContactsController extends AppController {
|
||||
'Customer')
|
||||
);
|
||||
$contact = $this->Contact->read(null, $id);
|
||||
//pr($contact);
|
||||
$this->Contact->Behaviors->detach('Containable');
|
||||
|
||||
// Prepare to render.
|
||||
$title = $contact['Contact']['display_name'];
|
||||
$this->set(compact('contact', 'title'));
|
||||
}
|
||||
|
||||
@@ -128,11 +128,7 @@ class CustomersController extends AppController {
|
||||
),
|
||||
'Account',
|
||||
'Lease' =>
|
||||
array(//'order' => 'movein_date',
|
||||
//'conditions' => array('Lease.lease_date IS NOT NULL'),
|
||||
// Models
|
||||
//'Account',
|
||||
'Unit' =>
|
||||
array('Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
@@ -142,36 +138,30 @@ class CustomersController extends AppController {
|
||||
$customer = $this->Customer->read(null, $id);
|
||||
$this->Customer->Behaviors->detach('Containable');
|
||||
|
||||
// Add the lease balance to each lease.
|
||||
foreach ($customer['Lease'] AS &$lease) {
|
||||
$stats = $this->Customer->Lease->stats($lease['id']);
|
||||
//pr($stats);
|
||||
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||
}
|
||||
|
||||
//pr($customer);
|
||||
|
||||
// Figure out the outstanding balance of the current lease.
|
||||
$stats = $this->Customer->stats($id);
|
||||
$deposits = $this->Customer->findSecurityDeposits($id);
|
||||
|
||||
$outstanding_balance = $stats['balance'];
|
||||
|
||||
// Figure out the total security deposit for the current lease.
|
||||
$deposits = $this->Customer->findSecurityDeposits($id);
|
||||
$outstanding_deposit = $deposits['summary']['balance'];
|
||||
|
||||
/* pr(array('Customer Stats', $stats)); */
|
||||
/* pr(array('Security Deposits', $deposits)); */
|
||||
// Add statistics into the customer account.
|
||||
$customer['Account'] = array_merge($customer['Account'],
|
||||
$stats['Account']['Ledger']);
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
$this->sidemenu_links[] =
|
||||
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; */
|
||||
|
||||
// Prepare to render.
|
||||
$title = $customer['Customer']['name'];
|
||||
$this->set(compact('customer', 'title',
|
||||
'outstanding_balance',
|
||||
|
||||
@@ -46,10 +46,12 @@ class LedgerEntriesController extends AppController {
|
||||
)
|
||||
);
|
||||
$entry = $this->LedgerEntry->read(null, $id);
|
||||
pr($entry);
|
||||
$this->LedgerEntry->Behaviors->detach('Containable');
|
||||
|
||||
$title = "Entry #{$entry['LedgerEntry']['id']} ({$entry['LedgerEntry']['name']})";
|
||||
$this->set(compact('entry', 'title'));
|
||||
//$this->autoRender = false;
|
||||
|
||||
pr($entry);
|
||||
$this->autoRender = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ class LedgersController extends AppController {
|
||||
'Account',
|
||||
'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'),
|
||||
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('OR' =>
|
||||
array('LedgerEntry.debit_ledger_id = Ledger.id',
|
||||
@@ -23,7 +27,7 @@ class LedgersController extends AppController {
|
||||
),
|
||||
|
||||
'group' => 'Ledger.id',
|
||||
'order' => array('Ledger.name' => 'ASC'));
|
||||
'order' => array('Ledger.account_id', 'Ledger.sequence'));
|
||||
|
||||
var $sidemenu_links =
|
||||
array(array('name' => 'Ledgers', 'header' => true),
|
||||
@@ -130,13 +134,6 @@ class LedgersController extends AppController {
|
||||
$ledger['LedgerEntry'] = $this->Ledger->findLedgerEntries
|
||||
($id, $ledger['Account']['type']);
|
||||
|
||||
/* $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'],
|
||||
|
||||
@@ -107,23 +107,15 @@ class TransactionsController extends AppController {
|
||||
)
|
||||
);
|
||||
$transaction = $this->Transaction->read(null, $id);
|
||||
pr($transaction);
|
||||
$this->Transaction->Behaviors->detach('Containable');
|
||||
|
||||
$debit_amount = 0;
|
||||
$credit_amount = 0;
|
||||
foreach($transaction['LedgerEntry'] AS $entry) {
|
||||
$debit_amount += $entry['amount'];
|
||||
$credit_amount += $entry['amount'];
|
||||
}
|
||||
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Operations', 'header' => true); */
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Move-Out', 'url' => array('controller' => 'transactions', 'action' => 'move-out')); */
|
||||
// Figure out the transaction total
|
||||
$total = 0;
|
||||
foreach($transaction['LedgerEntry'] AS $entry)
|
||||
$total += $entry['amount'];
|
||||
|
||||
// OK, prepare to render.
|
||||
$title = 'Transaction #' . $transaction['Transaction']['id'];
|
||||
$this->set(compact('transaction', 'title',
|
||||
'debit_amount',
|
||||
'credit_amount'));
|
||||
$this->set(compact('transaction', 'title', 'total'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,18 +163,19 @@ class UnitsController extends AppController {
|
||||
$unit = $this->Unit->read(null, $id);
|
||||
$this->Unit->Behaviors->detach('Containable');
|
||||
|
||||
pr($unit);
|
||||
|
||||
// Get the balance on each lease.
|
||||
foreach ($unit['Lease'] AS &$lease) {
|
||||
$stats = $this->Unit->Lease->stats($lease['id']);
|
||||
$lease['balance'] = $stats['Account']['Ledger']['balance'];
|
||||
}
|
||||
|
||||
// Figure out the outstanding balance of the current lease.
|
||||
$stats = $this->Unit->stats($id);
|
||||
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
|
||||
$outstanding_balance =
|
||||
$stats['CurrentLease']['Account']['Ledger']['balance'];
|
||||
|
||||
//pr($stats);
|
||||
$outstanding_balance = $stats['CurrentLease']['Account']['Ledger']['balance'];
|
||||
// Figure out the total security deposit for the current lease.
|
||||
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
|
||||
$outstanding_deposit = $deposits['summary']['balance'];
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
@@ -182,6 +183,7 @@ class UnitsController extends AppController {
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
||||
|
||||
// Prepare to render.
|
||||
$title = 'Unit ' . $unit['Unit']['name'];
|
||||
$this->set(compact('unit', 'title',
|
||||
'outstanding_balance',
|
||||
|
||||
Reference in New Issue
Block a user