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/site@244 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -194,13 +194,16 @@ class LeasesController extends AppController {
|
|||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$charge['type'] = $type;
|
$A = new Account();
|
||||||
if ($type == 'rent')
|
$charge_accounts = $A->chargeAccounts();
|
||||||
$charge['amount'] = $lease['Lease']['rent'];
|
$default_account = $A->rentAccountID();
|
||||||
elseif ($type == 'late')
|
$this->set(compact('charge_accounts', 'default_account'));
|
||||||
// REVISIT <AP> 20090705:
|
|
||||||
// Of course, the late charge should come from the late_schedule
|
// REVISIT <AP> 20090705:
|
||||||
$charge['amount'] = 10.00;
|
// Of course, the late charge should come from the late_schedule
|
||||||
|
$default_rent = $lease['Lease']['rent'];
|
||||||
|
$default_late = 10;
|
||||||
|
$this->set(compact('default_rent', 'default_late'));
|
||||||
|
|
||||||
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||||
$lease['Unit']['name'] . ': ' .
|
$lease['Unit']['name'] . ': ' .
|
||||||
|
|||||||
@@ -95,10 +95,32 @@ class Account extends AppModel {
|
|||||||
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
|
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
|
||||||
function rentAccountID() { return $this->nameToID('Rent'); }
|
function rentAccountID() { return $this->nameToID('Rent'); }
|
||||||
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
||||||
|
function taxAccountID() { return $this->nameToID('Tax'); }
|
||||||
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||||
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||||
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
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());
|
= $A->currentLedgerID($A->invoiceAccountID());
|
||||||
|
|
||||||
// ...and credit the charge ledger
|
// ...and credit the charge ledger
|
||||||
// REVISIT <AP> 20090706
|
$entry['credit_ledger_id']
|
||||||
// The charge page should have a list of all income types
|
= $A->currentLedgerID($entry['account_id']);
|
||||||
// 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['customer_id'] = $customer_id;
|
$entry['customer_id'] = $customer_id;
|
||||||
$entry['lease_id'] = $lease_id;
|
$entry['lease_id'] = $lease_id;
|
||||||
|
|||||||
@@ -154,29 +154,13 @@ function addChargeSource(flash) {
|
|||||||
//'with_name_after' => ':',
|
//'with_name_after' => ':',
|
||||||
'field_prefix' => 'LedgerEntry.%{id}',
|
'field_prefix' => 'LedgerEntry.%{id}',
|
||||||
'fields' => array
|
'fields' => array
|
||||||
("charge_type" => array('opts' =>
|
("account_id" => array('name' => 'Account',
|
||||||
array('options' =>
|
'opts' =>
|
||||||
array('rent' => 'Rent',
|
array('options' => $chargeAccounts,
|
||||||
'late' => 'Late Charge',
|
'value' => $defaultAccount,
|
||||||
'secd' => 'Security Deposit'),
|
),
|
||||||
'separator' => ' ',
|
),
|
||||||
'type' => 'radio',
|
"amount" => null,
|
||||||
'label' => false,
|
|
||||||
'div' => false,
|
|
||||||
'legend' => false,
|
|
||||||
'value' =>
|
|
||||||
(isset($charge['type'])
|
|
||||||
? $charge['type']
|
|
||||||
: null)
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"amount" => array('opts' =>
|
|
||||||
array('value' =>
|
|
||||||
(isset($charge['amount'])
|
|
||||||
? $charge['amount']
|
|
||||||
: null)
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"comment" => array('opts' => array('size' => 50)),
|
"comment" => array('opts' => array('size' => 50)),
|
||||||
),
|
),
|
||||||
))) . "+\n";
|
))) . "+\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user