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@247 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-07 07:52:41 +00:00
parent 40264d3c39
commit 06b8ff2ae9
4 changed files with 54 additions and 64 deletions

View File

@@ -842,6 +842,8 @@ CREATE TABLE `pmgr_accounts` (
`trackable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
`tillable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Does manager collect by hand?
`depositable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Does this account receive deposits?
`chargeable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for charges?
`payable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for payments?
-- Security Level
`level` INT UNSIGNED DEFAULT 1,
@@ -856,24 +858,24 @@ CREATE TABLE `pmgr_accounts` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
LOCK TABLES `pmgr_accounts` WRITE;
INSERT INTO `pmgr_accounts` (`type`, `name`, `tillable`, `depositable`)
INSERT INTO `pmgr_accounts` (`type`, `name`, `tillable`, `depositable`, `chargeable`, `payable`)
VALUES
('ASSET', 'A/R', 0, 0),
('ASSET', 'Invoice', 0, 0),
('ASSET', 'Receipt', 0, 0),
('LIABILITY', 'A/P', 0, 0),
('LIABILITY', 'Tax', 0, 0),
('LIABILITY', 'Customer Credit', 0, 0),
('ASSET', 'Petty Cash', 0, 0),
('ASSET', 'Bank', 0, 1),
('ASSET', 'Cash', 1, 0),
('ASSET', 'Check', 1, 0),
('ASSET', 'Money Order', 1, 0),
('LIABILITY', 'Security Deposit', 0, 0),
('INCOME', 'Rent', 0, 0),
('INCOME', 'Late Charge', 0, 0),
('EXPENSE', 'Concession', 0, 0),
('EXPENSE', 'Bad Debt', 0, 0);
('ASSET', 'A/R', 0, 0, 0, 0),
('ASSET', 'Invoice', 0, 0, 0, 0),
('ASSET', 'Receipt', 0, 0, 0, 0),
('LIABILITY', 'A/P', 0, 0, 0, 0),
('LIABILITY', 'Tax', 0, 0, 1, 0),
('LIABILITY', 'Customer Credit', 0, 0, 1, 1),
('ASSET', 'Petty Cash', 0, 0, 0, 0),
('ASSET', 'Bank', 0, 1, 0, 0),
('ASSET', 'Cash', 1, 0, 0, 0),
('ASSET', 'Check', 1, 0, 0, 0),
('ASSET', 'Money Order', 1, 0, 0, 0),
('LIABILITY', 'Security Deposit', 0, 0, 1, 1),
('INCOME', 'Rent', 0, 0, 1, 0),
('INCOME', 'Late Charge', 0, 0, 1, 0),
('EXPENSE', 'Concession', 0, 0, 0, 1),
('EXPENSE', 'Bad Debt', 0, 0, 0, 1);
UNLOCK TABLES;

View File

@@ -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'));
}

View File

@@ -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;
}
/**************************************************************************
**************************************************************************
**************************************************************************

View File

@@ -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();