Modified to dynamically determine eligible charge accounts, instead of the two that were hardcoded.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@244 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -95,10 +95,32 @@ class Account extends AppModel {
|
||||
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
|
||||
function rentAccountID() { return $this->nameToID('Rent'); }
|
||||
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
||||
function taxAccountID() { return $this->nameToID('Tax'); }
|
||||
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: fundamentalAccounts
|
||||
* - Returns an array of accounts by their fundamental type
|
||||
*/
|
||||
|
||||
function fundamentalAccounts($ftype) {
|
||||
$this->cacheQueries = true;
|
||||
$account = $this->find('all', array
|
||||
('contain' => array('CurrentLedger'),
|
||||
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||
'conditions' => array('Account.type' => strtoupper($ftype))
|
||||
));
|
||||
$this->cacheQueries = false;
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -119,6 +141,54 @@ class Account extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: chargeAccounts
|
||||
* - Returns an array of accounts suitable for charges
|
||||
*/
|
||||
|
||||
function chargeAccounts() {
|
||||
// REVISIT <AP>: 20090706
|
||||
// It's not clear how to authoritatively return accounts
|
||||
// that are suitable for entering charges. Clearly, INCOME
|
||||
// accounts are part of the list, but there must be others
|
||||
// as well. Security Deposit, for example, is clearly not
|
||||
// an INCOME account. In fact, it is a LIABILITY, yet not
|
||||
// all liability accounts should be part of this list
|
||||
// (consider a mortgage account, for example). At the
|
||||
// moment, I'll just specify the exceptions individually,
|
||||
// and we'll update the algorithm when we figure out how to
|
||||
// bettter genericize it.
|
||||
/* $accounts = array_merge($A->fundamentalAccounts('INCOME'), */
|
||||
/* $A->fundamentalAccounts('LIABILITY')); */
|
||||
/* usort($accounts, */
|
||||
/* create_function('$a, $b', */
|
||||
/* 'return strcasecmp($a["Account"]["name"], $b["Account"]["name"]);') */
|
||||
/* ); */
|
||||
|
||||
// Find the accounts suitable for invoicing
|
||||
$accounts = $this->find
|
||||
('all', array
|
||||
('contain' => false,
|
||||
'conditions' => array
|
||||
('OR' => array
|
||||
(array('type' => 'INCOME'),
|
||||
array('id' => $this->securityDepositAccountID()),
|
||||
array('id' => $this->taxAccountID()),
|
||||
),
|
||||
),
|
||||
'order' => array('name'),
|
||||
));
|
||||
|
||||
// Rearrange to be of the form (id => name)
|
||||
$charge_accounts = array();
|
||||
foreach ($accounts AS $acct) {
|
||||
$charge_accounts[$acct['Account']['id']] = $acct['Account']['name'];
|
||||
}
|
||||
|
||||
return $charge_accounts;
|
||||
}
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -97,22 +97,8 @@ class Transaction extends AppModel {
|
||||
= $A->currentLedgerID($A->invoiceAccountID());
|
||||
|
||||
// ...and credit the charge ledger
|
||||
// REVISIT <AP> 20090706
|
||||
// The charge page should have a list of all income types
|
||||
// and thus the field _should_ contain a valid account
|
||||
// name. At the moment, however, I'm still cobbling things
|
||||
// together, and only have two types.
|
||||
/* $entry['credit_ledger_id'] */
|
||||
/* = $A->currentLedgerID($A->nameToID($entry['charge_account'])); */
|
||||
if ($entry['charge_type'] === 'rent') {
|
||||
$entry['credit_ledger_id']
|
||||
= $A->currentLedgerID($A->rentAccountID());
|
||||
} elseif ($entry['charge_type'] === 'late') {
|
||||
$entry['credit_ledger_id']
|
||||
= $A->currentLedgerID($A->lateChargeAccountID());
|
||||
} else {
|
||||
die("Invalid charge account");
|
||||
}
|
||||
$entry['credit_ledger_id']
|
||||
= $A->currentLedgerID($entry['account_id']);
|
||||
|
||||
$entry['customer_id'] = $customer_id;
|
||||
$entry['lease_id'] = $lease_id;
|
||||
|
||||
Reference in New Issue
Block a user