Added a flag to accounts, indicating whether they can be used for charges and/or payments. Invoice has already switch to this mechanism, but we're keeping receipt the same for now since I have bigger fish to fry.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@247 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -357,16 +357,6 @@ class CustomersController extends AppController {
|
||||
*/
|
||||
|
||||
function receipt($id = null) {
|
||||
/* if (!$id) { */
|
||||
/* $this->Session->setFlash(__('Invalid Item.', true)); */
|
||||
/* $this->redirect(array('action'=>'index')); */
|
||||
/* } */
|
||||
|
||||
/* if ($this->RequestHandler->isPost()) { */
|
||||
/* pr($this->data); */
|
||||
/* //$this->redirect(array('action'=>'index')); */
|
||||
/* $customer = $this->data; */
|
||||
/* } */
|
||||
if (isset($id)) {
|
||||
$this->Customer->recursive = -1;
|
||||
$customer = $this->Customer->read(null, $id);
|
||||
@@ -379,6 +369,11 @@ class CustomersController extends AppController {
|
||||
$charges = array('balance' => 0, 'entry' => array());
|
||||
}
|
||||
|
||||
$A = new Account();
|
||||
$payment_accounts = $A->paymentAccounts();
|
||||
$default_account = $A->cashAccountID();
|
||||
$this->set(compact('payment_accounts', 'default_account'));
|
||||
|
||||
$title = ($customer['name'] . ': Payment Entry');
|
||||
$this->set(compact('customer', 'charges', 'title'));
|
||||
}
|
||||
|
||||
@@ -97,6 +97,8 @@ class Account extends AppModel {
|
||||
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
||||
function taxAccountID() { return $this->nameToID('Tax'); }
|
||||
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||
function cashAccountID() { return $this->nameToID('Cash'); }
|
||||
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }
|
||||
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
||||
|
||||
@@ -128,13 +130,14 @@ class Account extends AppModel {
|
||||
* - Returns an array of accounts related by similar attributes
|
||||
*/
|
||||
|
||||
function relatedAccounts($attribute) {
|
||||
function relatedAccounts($attribute, $extra = null) {
|
||||
$this->cacheQueries = true;
|
||||
$account = $this->find('all', array
|
||||
('contain' => array('CurrentLedger'),
|
||||
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||
'conditions' => array('Account.'.$attribute => true)
|
||||
));
|
||||
) + (isset($extra) ? $extra : array())
|
||||
);
|
||||
$this->cacheQueries = false;
|
||||
|
||||
return $account;
|
||||
@@ -149,37 +152,8 @@ class Account extends AppModel {
|
||||
*/
|
||||
|
||||
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'),
|
||||
));
|
||||
// Get all accounts that support charges
|
||||
$accounts = $this->relatedAccounts('chargeable', array('order' => 'name'));
|
||||
|
||||
// Rearrange to be of the form (id => name)
|
||||
$charge_accounts = array();
|
||||
@@ -189,6 +163,29 @@ class Account extends AppModel {
|
||||
|
||||
return $charge_accounts;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: paymentAccounts
|
||||
* - Returns an array of accounts suitable for payments
|
||||
*/
|
||||
|
||||
function paymentAccounts() {
|
||||
// Get all accounts that support payments
|
||||
$accounts = $this->relatedAccounts('payable', array('order' => 'name'));
|
||||
|
||||
// Rearrange to be of the form (id => name)
|
||||
$payment_accounts = array();
|
||||
foreach ($accounts AS $acct) {
|
||||
$payment_accounts[$acct['Account']['id']] = $acct['Account']['name'];
|
||||
}
|
||||
|
||||
return $payment_accounts;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -122,10 +122,6 @@ function onRowSelect(grid_id, customer_id) {
|
||||
$("#receipt-customer-id").html($(grid_id).getCell(customer_id, 'Customer-id'));
|
||||
$("#receipt-customer-name").html($(grid_id).getCell(customer_id, 'Customer-name'));
|
||||
|
||||
// Make sure the redirect is up to date, if necessary
|
||||
if ($("#redirectController").val() == 'customers')
|
||||
$("#redirect0").val(customer_id);
|
||||
|
||||
// Hide the "no customer" message and show the current customer
|
||||
$("#no-customer").hide();
|
||||
$("#current-customer").show();
|
||||
|
||||
Reference in New Issue
Block a user