Nowhere near done yet, but checking in a snapshot of semi-working code. There is some simultaneous support for both with and without use of the Invoice/Receipt account. I want to do away with them completely, but will need to change how sitelink payments are mapped (right now, they split a payment into multiple parts to match the charge).

git-svn-id: file:///svn-source/pmgr/branches/single_AR_20090622/site@181 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-23 19:04:41 +00:00
parent 7ea002850a
commit 009ea6b44d
16 changed files with 200 additions and 193 deletions

View File

@@ -305,7 +305,13 @@ class AppController extends Controller {
$id = 'id'; $id = 'id';
extract(array_intersect_key($fields, array_flip($special))); extract(array_intersect_key($fields, array_flip($special)));
foreach ($records AS &$record) { foreach ($records AS &$record) {
if (!isset($record[$table]))
continue;
foreach (array_diff_key($fields, array_flip($special)) AS $field) { foreach (array_diff_key($fields, array_flip($special)) AS $field) {
if (!isset($record[$table][$id]) || !isset($record[$table][$field]))
continue;
// DEBUG PURPOSES ONLY! // DEBUG PURPOSES ONLY!
//$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record'); //$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
$record[$table][$field] = $record[$table][$field] =

View File

@@ -71,6 +71,7 @@ class LeasesController extends AppController {
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Lease'] = array('number'); $links['Lease'] = array('number');
$links['Unit'] = array('name'); $links['Unit'] = array('name');
$links['Customer'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::jqGridRecordLinks($params, $model, $records, $links);
} }
@@ -107,7 +108,6 @@ class LeasesController extends AppController {
array(// Models array(// Models
'LeaseType', 'LeaseType',
'Unit', 'Unit',
'Account' => array('CurrentLedger'),
'Customer', 'Customer',
), ),
'conditions' => array(array('Lease.id' => $id)), 'conditions' => array(array('Lease.id' => $id)),
@@ -115,23 +115,15 @@ class LeasesController extends AppController {
) )
); );
// Summarize each ledger
$this->Lease->statsMerge($lease,
$this->Lease->stats($lease['Lease']['id']));
// Obtain the overall lease balance // Obtain the overall lease balance
$this->Lease->statsMerge($lease['Lease'], $this->Lease->statsMerge($lease['Lease'],
array('stats' => $this->Lease->stats($id))); array('stats' => $this->Lease->stats($id)));
$outstanding_balance = $lease['Lease']['stats']['Account']['Ledger']['balance']; $outstanding_balance = $lease['Lease']['stats']['balance'];
// Determine the lease security deposit // Determine the lease security deposit
$deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']); $deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
$outstanding_deposit = $deposits['summary']['balance']; $outstanding_deposit = $deposits['summary']['balance'];
// Move the Leder stats into our alias 'CurrentLedger'
$lease['Account']['CurrentLedger'] += $lease['Account']['Ledger'];
unset($lease['Account']['Ledger']);
// Prepare to render // Prepare to render
$title = 'Lease: #' . $lease['Lease']['id']; $title = 'Lease: #' . $lease['Lease']['id'];
$this->set(compact('lease', 'title', $this->set(compact('lease', 'title',

View File

@@ -36,6 +36,16 @@ class LedgerEntriesController extends AppController {
array('fields' => array('id', 'name'), array('fields' => array('id', 'name'),
), ),
'Customer' =>
array('fields' => array('id', 'name'),
),
'Lease' =>
array('fields' => array('id', 'number'),
'Unit' =>
array('fields' => array('id', 'name'),
),
),
); );
if (isset($params['custom']['account_ftype'])) { if (isset($params['custom']['account_ftype'])) {
@@ -118,20 +128,64 @@ class LedgerEntriesController extends AppController {
$conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']); $conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']);
} }
if (isset($params['custom']['customer_id'])) {
$conditions[] =
array('Customer.id' => $params['custom']['customer_id']);
/* $Account = new Account(); */
/* if (isset($params['custom']['account_ftype']) || */
/* isset($params['custom']['ledger_id'])) { */
/* $conditions[] = */
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
/* 'Account.id' => $Account->receiptAccountID())); */
/* } else { */
/* $conditions[] = */
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
/* )); */
/* } */
}
if (isset($params['custom']['lease_id'])) {
$conditions[] =
array('Lease.id' => $params['custom']['lease_id']);
/* $Account = new Account(); */
/* if (isset($params['custom']['account_ftype']) || */
/* isset($params['custom']['ledger_id'])) { */
/* $conditions[] = */
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
/* 'Account.id' => $Account->receiptAccountID())); */
/* } else { */
/* $conditions[] = */
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
/* )); */
/* } */
}
if (isset($params['custom']['transaction_id'])) {
$conditions[] =
array('Transaction.id' => $params['custom']['transaction_id']);
}
return $conditions; return $conditions;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id'); $links['Transaction'] = array('id');
$links['LedgerEntry'] = array('id'); $links['LedgerEntry'] = array('id');
if (isset($params['custom']['account_ftype']) || isset($params['custom']['ledger_id'])) { $links['Account'] = array('controller' => 'accounts', 'name');
$links['Account'] = array('controller' => 'accounts', 'name'); $links['DebitAccount'] = array('controller' => 'accounts', 'name');
} $links['CreditAccount'] = array('controller' => 'accounts', 'name');
else {
$links['DebitAccount'] = array('controller' => 'accounts', 'name');
$links['CreditAccount'] = array('controller' => 'accounts', 'name');
}
$links['MonetarySource'] = array('name'); $links['MonetarySource'] = array('name');
$links['Customer'] = array('name');
$links['Lease'] = array('number');
$links['Unit'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::jqGridRecordLinks($params, $model, $records, $links);
} }
@@ -145,8 +199,13 @@ class LedgerEntriesController extends AppController {
function jqGridDataOrder(&$params, &$model, $index, $direction) { function jqGridDataOrder(&$params, &$model, $index, $direction) {
/* if ($index === 'balance') */ /* if ($index === 'balance') */
/* return ($index .' '. $direction); */ /* return ($index .' '. $direction); */
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
return parent::jqGridDataOrder($params, $model, $index, $direction); if ($index === 'Transaction.stamp') {
$order[] = 'LedgerEntry.id ' . $direction;
}
return $order;
} }
@@ -167,6 +226,7 @@ class LedgerEntriesController extends AppController {
$entry = $this->LedgerEntry->find $entry = $this->LedgerEntry->find
('first', ('first',
array('contain' => array('MonetarySource.id', array('contain' => array('MonetarySource.id',
'MonetarySource.name',
'MonetarySource.MonetaryType.id', 'MonetarySource.MonetaryType.id',
'Transaction.id', 'Transaction.id',
'Transaction.stamp', 'Transaction.stamp',
@@ -176,6 +236,9 @@ class LedgerEntriesController extends AppController {
'CreditLedger.id', 'CreditLedger.id',
'CreditLedger.sequence', 'CreditLedger.sequence',
'CreditLedger.account_id', 'CreditLedger.account_id',
'Customer.id',
'Customer.name',
'Lease.id',
), ),
'fields' => array('LedgerEntry.id', 'fields' => array('LedgerEntry.id',

View File

@@ -121,7 +121,7 @@ class UnitsController extends AppController {
// Get the balance on each lease. // Get the balance on each lease.
foreach ($unit['Lease'] AS &$lease) { foreach ($unit['Lease'] AS &$lease) {
$stats = $this->Unit->Lease->stats($lease['id']); $stats = $this->Unit->Lease->stats($lease['id']);
$lease['balance'] = $stats['Account']['Ledger']['balance']; $lease['balance'] = $stats['balance'];
} }
$outstanding_balance = 0; $outstanding_balance = 0;
@@ -130,7 +130,7 @@ class UnitsController extends AppController {
// Figure out the outstanding balance of the current lease. // Figure out the outstanding balance of the current lease.
$stats = $this->Unit->stats($id); $stats = $this->Unit->stats($id);
$outstanding_balance = $outstanding_balance =
$stats['CurrentLease']['Account']['Ledger']['balance']; $stats['CurrentLease']['balance'];
// Figure out the total security deposit for the current lease. // Figure out the total security deposit for the current lease.
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']); $deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);

View File

@@ -82,37 +82,26 @@ class Account extends AppModel {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* function: securityDepositAccountID * function: accountNameToID
* - Returns the ID of the Security Deposit Account * - Returns the ID of the named account
*/ */
function securityDepositAccountID() { function accountNameToID($name) {
$this->cacheQueries = true; $this->cacheQueries = true;
$account = $this->find('first', array $account = $this->find('first', array
('recursive' => -1, ('recursive' => -1,
'conditions' => array 'conditions' => compact('name'),
(array('name' => 'Security Deposit')),
)); ));
$this->cacheQueries = false; $this->cacheQueries = false;
return $account['Account']['id']; return $account['Account']['id'];
} }
function securityDepositAccountID() { return $this->accountNameToID('Security Deposit'); }
/************************************************************************** function rentAccountID() { return $this->accountNameToID('Rent'); }
************************************************************************** function accountReceivableAccountID() { return $this->accountNameToID('A/R'); }
************************************************************************** function invoiceAccountID() { return $this->accountReceivableAccountID(); }
* function:rentAccountID function receiptAccountID() { return $this->accountReceivableAccountID(); }
* - Returns the ID of the Rent Account //function invoiceAccountID() { return $this->accountNameToID('Invoice'); }
*/ //function receiptAccountID() { return $this->accountNameToID('Receipt'); }
function rentAccountID() {
$this->cacheQueries = true;
$account = $this->find('first', array
('recursive' => -1,
'conditions' => array
(array('name' => 'Rent')),
));
$this->cacheQueries = false;
return $account['Account']['id'];
}
/************************************************************************** /**************************************************************************
@@ -122,22 +111,19 @@ class Account extends AppModel {
* - Returns an array of ledger ids from the given account * - Returns an array of ledger ids from the given account
*/ */
function ledgers($id, $all = false) { function ledgers($id, $all = false) {
$cachekey = $all ? 'all' : 'current';
if (isset($this->cache[$id]['ledgers'][$cachekey])) {
return $this->cache[$id]['ledgers'][$cachekey];
}
if ($all) { if ($all) {
$contain = array('Ledger' => array('fields' => array('Ledger.id'))); $contain = array('Ledger' => array('fields' => array('Ledger.id')));
} else { } else {
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id'))); $contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
} }
$this->cacheQueries = true;
$account = $this->find('first', array $account = $this->find('first', array
('contain' => $contain, ('contain' => $contain,
'fields' => array(), 'fields' => array(),
'conditions' => array(array('Account.id' => $id)), 'conditions' => array(array('Account.id' => $id)),
)); ));
$this->cacheQueries = false;
if ($all) { if ($all) {
$ledger_ids = array(); $ledger_ids = array();
@@ -148,14 +134,11 @@ class Account extends AppModel {
$ledger_ids = array($account['CurrentLedger']['id']); $ledger_ids = array($account['CurrentLedger']['id']);
} }
// Save the ledgers in our cache for future reference
$this->cache[$id]['ledgers'][$cachekey] = $ledger_ids;
/* pr(array('function' => 'Account::ledgers', */ /* pr(array('function' => 'Account::ledgers', */
/* 'args' => compact('id', 'all'), */ /* 'args' => compact('id', 'all'), */
/* 'return' => $this->cache[$id]['ledgers'][$cachekey])); */ /* 'return' => $ledger_ids)); */
return $this->cache[$id]['ledgers'][$cachekey]; return $ledger_ids;
} }
@@ -234,7 +217,11 @@ class Account extends AppModel {
* (such as charges not paid). * (such as charges not paid).
*/ */
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) { function findUnreconciledLedgerEntries($id = null, $fundamental_type = null, $cond = null) {
if (!isset($cond))
$cond = array();
$cond[] = array('Account.id' => $id);
foreach (($fundamental_type foreach (($fundamental_type
? array($fundamental_type) ? array($fundamental_type)
: array('debit', 'credit')) AS $fund) { : array('debit', 'credit')) AS $fund) {
@@ -260,7 +247,7 @@ class Account extends AppModel {
'group' => ("LedgerEntry.id" . 'group' => ("LedgerEntry.id" .
" HAVING LedgerEntry.amount" . " HAVING LedgerEntry.amount" .
" <> COALESCE(SUM(Reconciliation.amount),0)"), " <> COALESCE(SUM(Reconciliation.amount),0)"),
'conditions' => array('Account.id' => $id), 'conditions' => $cond,
'fields' => array(), 'fields' => array(),
)); ));
$balance = 0; $balance = 0;
@@ -290,7 +277,7 @@ class Account extends AppModel {
* whatever algorithm is simplest. * whatever algorithm is simplest.
*/ */
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) { function reconcileNewLedgerEntry($id, $fundamental_type, $amount, $cond = null) {
$ofund = $this->fundamentalOpposite($fundamental_type); $ofund = $this->fundamentalOpposite($fundamental_type);
$unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0)); $unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
$applied = 0; $applied = 0;
@@ -298,7 +285,7 @@ class Account extends AppModel {
// if there is no money in the entry, it can reconcile nothing // if there is no money in the entry, it can reconcile nothing
// don't bother wasting time sifting ledger entries. // don't bother wasting time sifting ledger entries.
if ($amount > 0) { if ($amount > 0) {
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund); $unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund, $cond);
foreach ($unreconciled[$ofund]['entry'] AS $i => &$entry) { foreach ($unreconciled[$ofund]['entry'] AS $i => &$entry) {
// Determine if amount is sufficient to cover the entry // Determine if amount is sufficient to cover the entry

View File

@@ -8,7 +8,6 @@ class Customer extends AppModel {
); );
var $belongsTo = array( var $belongsTo = array(
'Account',
'PrimaryContact' => array( 'PrimaryContact' => array(
'className' => 'Contact', 'className' => 'Contact',
), ),
@@ -20,11 +19,19 @@ class Customer extends AppModel {
'conditions' => 'CurrentLease.close_date IS NULL', 'conditions' => 'CurrentLease.close_date IS NULL',
), ),
'Lease', 'Lease',
'Transaction', 'LedgerEntry',
// Cheat to get Account set as part of this class
'Account',
); );
var $hasAndBelongsToMany = array( var $hasAndBelongsToMany = array(
'Contact', 'Contact',
'Transaction' => array(
'joinTable' => 'ledger_entries',
'foreignKey' => 'customer_id',
'associationForeignKey' => 'transaction_id',
),
); );
@@ -80,16 +87,9 @@ class Customer extends AppModel {
/* )); */ /* )); */
$entries = $this->Account->findLedgerEntriesRelatedToAccount $entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->accountId($id), ($this->Account->invoiceAccountID(),
$this->Account->securityDepositAccountID(), $this->Account->securityDepositAccountID(),
true, null, $link); true, array('LedgerEntry.customer_id' => $id), $link);
foreach ($this->leaseIds($id) AS $lease_id) {
$ledger_entries = $this->Lease->findSecurityDeposits($lease_id, $link);
$this->statsMerge($entries['summary'], $ledger_entries['summary']);
$entries['Entries'] = array_merge($entries['Entries'],
$ledger_entries['Entries']);
}
/* pr(array('function' => 'Customer::findSecurityDeposits', */ /* pr(array('function' => 'Customer::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */ /* 'args' => compact('id', 'link'), */
@@ -110,22 +110,10 @@ class Customer extends AppModel {
*/ */
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) { function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
$unreconciled = $this->Account->findUnreconciledLedgerEntries $unreconciled = $this->Account->findUnreconciledLedgerEntries
($this->accountId($id), $fundamental_type); ($this->Account->accountReceivableAccountID(),
$fundamental_type,
foreach ($this->leaseIds($id) AS $lease_id) { array('LedgerEntry.customer_id' => $id));
$unrec = $this->Lease->findUnreconciledLedgerEntries($lease_id,
$fundamental_type);
foreach (array_keys($unreconciled) AS $type) {
$left = &$unreconciled[$type];
$right = &$unrec[$type];
$left['entry'] = array_merge($left['entry'], $right['entry']);
$left['balance'] += $right['balance'];
}
}
return $unreconciled; return $unreconciled;
} }
@@ -146,25 +134,11 @@ class Customer extends AppModel {
*/ */
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) { function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
$reconciled = $this->Account->reconcileNewLedgerEntry $reconciled = $this->Account->reconcileNewLedgerEntry
($this->accountId($id), $fundamental_type, $amount); ($this->Account->accountReceivableAccountID(),
$fundamental_type,
foreach ($this->leaseIds($id) AS $lease_id) { $amount,
foreach (array_keys($reconciled) AS $type) { array('LedgerEntry.customer_id' => $id));
$rec = $this->Lease->reconcileNewLedgerEntry($lease_id,
$fundamental_type,
$reconciled[$type]['unapplied']);
$left = &$reconciled[$type];
$right = &$rec[$type];
$left['entry'] = array_merge($left['entry'], $right['entry']);
$left['balance'] += $right['balance'];
$left['applied'] += $right['applied'];
$left['unapplied'] = $right['unapplied'];
}
}
return $reconciled; return $reconciled;
} }
@@ -189,7 +163,6 @@ class Customer extends AppModel {
'ContactEmail', 'ContactEmail',
'ContactAddress', 'ContactAddress',
), ),
'Account',
'Lease' => 'Lease' =>
array('Unit' => array('Unit' =>
array('order' => array('sort_order'), array('order' => array('sort_order'),
@@ -201,22 +174,12 @@ class Customer extends AppModel {
'conditions' => array('Customer.id' => $id), 'conditions' => array('Customer.id' => $id),
)); ));
// Add the lease balance to each lease. // Figure out the outstanding balance for this customer
foreach ($customer['Lease'] AS &$lease) {
$stats = $this->Lease->stats($lease['id']);
$lease['balance'] = $stats['Account']['Ledger']['balance'];
}
// Figure out the outstanding balance of the current lease.
$customer['stats'] = $this->stats($id); $customer['stats'] = $this->stats($id);
// Figure out the total security deposit for the current lease. // Figure out the total security deposit for the current lease.
$customer['deposits'] = $this->findSecurityDeposits($id); $customer['deposits'] = $this->findSecurityDeposits($id);
// Add statistics into the customer account.
$customer['Account'] = array_merge($customer['Account'],
$customer['stats']['Account']['Ledger']);
return $customer; return $customer;
} }
@@ -232,29 +195,11 @@ class Customer extends AppModel {
if (!$id) if (!$id)
return null; return null;
// Get the basic information necessary $stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
$customer = $this->find('first', array('LedgerEntry.customer_id' => $id));
array('contain' =>
array('Account' => array
('fields' => array('Account.id')),
'Lease' => array
('fields' => array('Lease.id'))
),
'conditions' => array
(array('Customer.id' => $id))));
// Get stats from the customer account, and each lease
$stats['Account'] = $this->Account->stats($customer['Account']['id']);
foreach ($customer['Lease'] AS $lease) {
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
}
// Merge the stats from both the customer specific account, as
// well as the leases. This will provide current customer standing.
$this->statsMerge($stats, $stats['Account']['Ledger']);
$this->statsMerge($stats, $stats['Lease']['Account']['Ledger']);
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats; return $stats;
} }

View File

@@ -25,11 +25,18 @@ class Lease extends AppModel {
var $belongsTo = array( var $belongsTo = array(
'LeaseType', 'LeaseType',
'Unit', 'Unit',
'Account',
'Customer', 'Customer',
'LateSchedule', 'LateSchedule',
); );
var $hasMany = array(
'LedgerEntry',
// Cheat to get Account set as part of this class
'Account',
);
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -37,15 +44,7 @@ class Lease extends AppModel {
* - Returns the accountId of the given lease * - Returns the accountId of the given lease
*/ */
function accountId($id) { function accountId($id) {
$this->cacheQueries = true; return $this->Account->invoiceAccountID();
$lease = $this->find('first', array
('recursive' => -1,
'fields' => array('account_id'),
'conditions' => array(array('id' => $id)),
));
$this->cacheQueries = false;
return $lease['Lease']['account_id'];
} }
@@ -61,6 +60,10 @@ class Lease extends AppModel {
/* 'args' => compact('id', 'all', 'cond', 'link'), */ /* 'args' => compact('id', 'all', 'cond', 'link'), */
/* )); */ /* )); */
if (!isset($cond))
$cond = array();
$cond[] = array('LedgerEntry.lease_id' => $id);
$entries = $this->Account->findLedgerEntries($this->accountId($id), $entries = $this->Account->findLedgerEntries($this->accountId($id),
$all, $cond, $link); $all, $cond, $link);
@@ -87,7 +90,7 @@ class Lease extends AppModel {
$entries = $this->Account->findLedgerEntriesRelatedToAccount $entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->accountId($id), ($this->accountId($id),
$this->Account->securityDepositAccountID(), $this->Account->securityDepositAccountID(),
true, null, $link); true, array('LedgerEntry.lease_id' => $id), $link);
/* pr(array('function' => 'Lease::findSecurityDeposits', */ /* pr(array('function' => 'Lease::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */ /* 'args' => compact('id', 'link'), */
@@ -108,7 +111,7 @@ class Lease extends AppModel {
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) { function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
return $this->Account->findUnreconciledLedgerEntries return $this->Account->findUnreconciledLedgerEntries
($this->accountId($id), $fundamental_type); ($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id));
} }
@@ -128,7 +131,7 @@ class Lease extends AppModel {
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) { function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
return $this->Account->reconcileNewLedgerEntry return $this->Account->reconcileNewLedgerEntry
($this->accountId($id), $fundamental_type, $amount); ($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id));
} }
@@ -143,18 +146,11 @@ class Lease extends AppModel {
if (!$id) if (!$id)
return null; return null;
// Find the associated account. $stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
$lease = $this->find('first', array('LedgerEntry.lease_id' => $id));
array('recursive' => -1,
'conditions' => array(array('Lease.id' => $id))));
// Pull the stats from the account.
$stats['Account'] = $this->Account->stats($lease['Lease']['account_id']);
// Place a summary of the stats (one lease account in this case)
// at the top level for easy summarized access.
$this->statsMerge($stats, $stats['Account']['Ledger']);
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats; return $stats;
} }

View File

@@ -115,6 +115,9 @@ class Ledger extends AppModel {
* - Returns summary data from the requested ledger. * - Returns summary data from the requested ledger.
*/ */
function stats($id, $cond = null) { function stats($id, $cond = null) {
if (!isset($cond))
$cond = array();
$cond[] = array('Ledger.id' => $id);
$stats = $this->find $stats = $this->find
('first', array ('first', array
@@ -138,8 +141,7 @@ class Ledger extends AppModel {
) * IF(LedgerEntry.amount, LedgerEntry.amount, 0) ) * IF(LedgerEntry.amount, LedgerEntry.amount, 0)
) AS balance", ) AS balance",
"COUNT(LedgerEntry.id) AS entries"), "COUNT(LedgerEntry.id) AS entries"),
'conditions' => array(isset($cond) ? $cond : array(), 'conditions' => $cond,
array('Ledger.id' => $id)),
'group' => 'Ledger.id', 'group' => 'Ledger.id',
)); ));

View File

@@ -11,6 +11,8 @@ class LedgerEntry extends AppModel {
var $belongsTo = array( var $belongsTo = array(
'MonetarySource', 'MonetarySource',
'Transaction', 'Transaction',
'Customer',
'Lease',
'DebitLedger' => array( 'DebitLedger' => array(
'className' => 'Ledger', 'className' => 'Ledger',

View File

@@ -63,12 +63,13 @@ echo $this->element('leases',
/********************************************************************** /**********************************************************************
* Account * Customer Account History
*/ */
echo $this->element('accounts', echo $this->element('ledger_entries',
array('caption' => 'Account', array('caption' => 'Account',
'accounts' => array($customer['Account']))); 'customer_id' => $customer['Customer']['id'],
));
/* End "detail supporting" div */ /* End "detail supporting" div */

View File

@@ -143,8 +143,12 @@ foreach ($jqGridColumns AS &$col) {
} }
// Set the default sort column // Set the default sort column
reset($jqGridColumns); if (isset($sort_column)) {
$sortname = current($jqGridColumns); $sortname = $jqGridColumns[$sort_column];
} else {
reset($jqGridColumns);
$sortname = current($jqGridColumns);
}
$sortname = $sortname['index']; $sortname = $sortname['index'];
// Configure the grid setup, giving priority to user defined parameters // Configure the grid setup, giving priority to user defined parameters

View File

@@ -21,6 +21,9 @@ else {
$cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'longname'); $cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'longname');
$cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'longname'); $cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'longname');
} }
$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'name');
$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id');
$cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'name');
$cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name'); $cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name');
$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150); $cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150);
if (isset($ledger_id)) { if (isset($ledger_id)) {
@@ -34,7 +37,8 @@ if (isset($reconcile_id)) {
$cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency'); $cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency');
} }
$custom_post_data = compact('ledger_id', 'account_type', 'account_ftype', 'notxgroup'); $custom_post_data = compact('ledger_id', 'account_type', 'account_ftype',
'customer_id', 'lease_id', 'transaction_id', 'notxgroup');
$jqGrid_options = array('jqGridColumns' => $cols, $jqGrid_options = array('jqGridColumns' => $cols,
'controller' => 'ledger_entries', 'controller' => 'ledger_entries',
@@ -42,11 +46,6 @@ $jqGrid_options = array('jqGridColumns' => $cols,
$jqGrid_options += compact('grid_div_id', 'grid_id', 'caption', 'grid_setup', 'limit'); $jqGrid_options += compact('grid_div_id', 'grid_id', 'caption', 'grid_setup', 'limit');
if (isset($ledger_id)) {
$jqGrid_options += array('action' => 'ledger',
'limit' => 50);
}
if (isset($ledger_entries)) { if (isset($ledger_entries)) {
$jqGrid_options += array('custom_ids' => $jqGrid_options += array('custom_ids' =>
array_map(create_function('$data', array_map(create_function('$data',
@@ -54,6 +53,10 @@ if (isset($ledger_entries)) {
$ledger_entries), $ledger_entries),
'limit' => 10); 'limit' => 10);
} }
else {
$jqGrid_options += array('action' => 'ledger',
'limit' => 50);
}
if (isset($reconcile_id)) { if (isset($reconcile_id)) {
$custom_post_data += compact('reconcile_id'); $custom_post_data += compact('reconcile_id');
@@ -61,5 +64,6 @@ if (isset($reconcile_id)) {
} }
$jqGrid_options += compact('custom_post_data'); $jqGrid_options += compact('custom_post_data');
$jqGrid_options['sort_column'] = 'Date';
echo $this->element('jqGrid', $jqGrid_options); echo $this->element('jqGrid', $jqGrid_options);

View File

@@ -11,7 +11,6 @@ echo '<div class="lease view">' . "\n";
$lease_type = $lease['LeaseType']; $lease_type = $lease['LeaseType'];
$customer = $lease['Customer']; $customer = $lease['Customer'];
$account = $lease['Account'];
$unit = $lease['Unit']; $unit = $lease['Unit'];
if (isset($lease['Lease'])) if (isset($lease['Lease']))
@@ -36,10 +35,6 @@ $rows = array(array('ID', $lease['id']),
array('Notice Given', FormatHelper::date($lease['notice_given_date'], true)), array('Notice Given', FormatHelper::date($lease['notice_given_date'], true)),
array('Notice Received', FormatHelper::date($lease['notice_received_date'], true)), array('Notice Received', FormatHelper::date($lease['notice_received_date'], true)),
array('Closed', FormatHelper::date($lease['close_date'], true)), array('Closed', FormatHelper::date($lease['close_date'], true)),
array('Account', $html->link($account['name'],
array('controller' => 'accounts',
'action' => 'view',
$account['id']))),
array('Deposit', FormatHelper::currency($lease['deposit'])), array('Deposit', FormatHelper::currency($lease['deposit'])),
array('Rent', FormatHelper::currency($lease['amount'])), array('Rent', FormatHelper::currency($lease['amount'])),
array('Comment', $lease['comment'])); array('Comment', $lease['comment']));
@@ -53,7 +48,7 @@ echo $this->element('table',
/********************************************************************** /**********************************************************************
* Account Info Box * Lease Info Box
*/ */
echo '<div class="infobox">' . "\n"; echo '<div class="infobox">' . "\n";
@@ -80,15 +75,15 @@ echo '<div CLASS="detail supporting">' . "\n";
/********************************************************************** /**********************************************************************
* Current Ledger * Lease Account History
*/ */
echo $this->element('ledger_entries', echo $this->element('ledger_entries',
array('caption' => "Current Ledger: (#{$account['id']}-{$account['CurrentLedger']['sequence']})", array('caption' => 'Account',
'ledger_id' => $account['CurrentLedger']['id'], 'lease_id' => $lease['id'],
'account_type' => $account['type'],
)); ));
/* End "detail supporting" div */ /* End "detail supporting" div */
echo '</div>' . "\n"; echo '</div>' . "\n";

View File

@@ -13,6 +13,8 @@ $transaction = $entry['Transaction'];
$debit_ledger = $entry['DebitLedger']; $debit_ledger = $entry['DebitLedger'];
$credit_ledger = $entry['CreditLedger']; $credit_ledger = $entry['CreditLedger'];
$source = $entry['MonetarySource']; $source = $entry['MonetarySource'];
$customer = $entry['Customer'];
$lease = $entry['Lease'];
$entry = $entry['LedgerEntry']; $entry = $entry['LedgerEntry'];
$rows = array(array('ID', $entry['id']), $rows = array(array('ID', $entry['id']),
@@ -21,8 +23,16 @@ $rows = array(array('ID', $entry['id']),
'action' => 'view', 'action' => 'view',
$transaction['id']))), $transaction['id']))),
array('Timestamp', FormatHelper::datetime($transaction['stamp'])), array('Timestamp', FormatHelper::datetime($transaction['stamp'])),
array('Monetary Source', (isset($source['id']) array('Customer', $html->link($customer['name'],
? $html->link('#'.$source['id'], array('controller' => 'customers',
'action' => 'view',
$customer['id']))),
array('Lease', $html->link('#'.$lease['id'],
array('controller' => 'leases',
'action' => 'view',
$lease['id']))),
array('Monetary Source', (isset($source['name'])
? $html->link($source['name'],
array('controller' => 'monetary_sources', array('controller' => 'monetary_sources',
'action' => 'view', 'action' => 'view',
$source['id'])) $source['id']))

View File

@@ -54,7 +54,8 @@ echo '<div CLASS="detail supporting">' . "\n";
echo $this->element('ledger_entries', echo $this->element('ledger_entries',
array('caption' => 'Entries in Transaction', array('caption' => 'Entries in Transaction',
'ledger_entries' => $transaction['LedgerEntry'], //'ledger_entries' => $transaction['LedgerEntry'],
'transaction_id' => $transaction['Transaction']['id'],
'notxgroup' => true, 'notxgroup' => true,
)); ));

View File

@@ -57,16 +57,15 @@ echo $this->element('leases',
/********************************************************************** /**********************************************************************
* Ledger History * Current Tenant Lease Account History
*/ */
/* foreach($unit['Lease'] AS $lease) { */
/* pr($lease); */ echo $this->element('ledger_entries',
/* $caption = 'Lease #'.$lease['number'].' (Tenant: '.$lease['Customer']['name'].')'; */ array('caption' => ('Current Lease Account (' .
/* echo $this->element('lease', */ $unit['CurrentLease']['Customer']['name']
/* array('caption' => $caption, */ . ')'),
/* 'entries' => $lease['Customer']['Transaction'], */ 'lease_id' => $unit['CurrentLease']['id'],
/* 'ledger' => array('mix'=>1))); */ ));
/* } */
/* End "detail supporting" div */ /* End "detail supporting" div */