From 90ecbda5415e6090a6f1dfc10bd118283479a2f8 Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 17 Aug 2009 02:15:02 +0000 Subject: [PATCH] Several minor changes including a couple minor bugfixes. git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@592 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 1 + site/controllers/accounts_controller.php | 9 +++---- site/controllers/tenders_controller.php | 3 ++- site/controllers/units_controller.php | 1 - site/models/account.php | 32 +++++++++++++++++++++--- site/models/statement_entry.php | 8 +++--- site/models/transaction.php | 3 +++ site/views/accounts/collected.ctp | 7 +++--- 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index b62eedb..5ed9976 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -66,6 +66,7 @@ class AppController extends Controller { $menu[] = array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')); $menu[] = array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')); $menu[] = array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')); + $menu[] = array('name' => 'Tenders', 'url' => array('controller' => 'tenders', 'action' => 'index')); $menu[] = array('name' => 'Transactions', 'url' => array('controller' => 'transactions', 'action' => 'index')); $menu[] = array('name' => 'Ldgr Entries', 'url' => array('controller' => 'ledger_entries', 'action' => 'index')); $menu[] = array('name' => 'Stmt Entries', 'url' => array('controller' => 'statement_entries', 'action' => 'index')); diff --git a/site/controllers/accounts_controller.php b/site/controllers/accounts_controller.php index 2920e74..0554f26 100644 --- a/site/controllers/accounts_controller.php +++ b/site/controllers/accounts_controller.php @@ -143,12 +143,9 @@ class AccountsController extends AppController { $account = $this->Account->read(null, $id); $account = $account['Account']; - $payment_accounts = $this->Account->collectableAccounts(); - //$payment_accounts[$this->Account->nameToID('Closing')] = 'Closing'; - //$payment_accounts[$this->Account->nameToID('Equity')] = 'Equity'; - //$payment_accounts[$id] = 'Reversals'; - $default_accounts = array_diff_key($this->Account->receiptAccounts(), - array($this->Account->concessionAccountID() => 1)); + $accounts = $this->Account->collectableAccounts(); + $payment_accounts = $accounts['all']; + $default_accounts = $accounts['default']; $this->set(compact('payment_accounts', 'default_accounts')); $title = ($account['name'] . ': Collected Report'); diff --git a/site/controllers/tenders_controller.php b/site/controllers/tenders_controller.php index 71b0d04..8e8be18 100644 --- a/site/controllers/tenders_controller.php +++ b/site/controllers/tenders_controller.php @@ -178,7 +178,8 @@ class TendersController extends AppController { && empty($tender['Tender']['nsf_transaction_id']) // Hard to tell what types of items can come back as NSF. // For now, assume iff it is a named item, it can be NSF. - && !empty($tender['TenderType']['data1_name']) + // (or if we're in development mode) + && (!empty($tender['TenderType']['data1_name']) || !empty($this->params['dev'])) ) { $this->sidemenu_links[] = array('name' => 'NSF', diff --git a/site/controllers/units_controller.php b/site/controllers/units_controller.php index d04f7c7..50f15a0 100644 --- a/site/controllers/units_controller.php +++ b/site/controllers/units_controller.php @@ -212,7 +212,6 @@ class UnitsController extends AppController { ), 'conditions' => array('Unit.id' => $id), )); - $unit['Unit'] = $unit[0] + $unit['Unit']; // Get the balance on each lease. foreach ($unit['Lease'] AS &$lease) { diff --git a/site/models/account.php b/site/models/account.php index 490da80..e4c9f39 100644 --- a/site/models/account.php +++ b/site/models/account.php @@ -139,8 +139,17 @@ class Account extends AppModel { function invoiceAccountID() { return $this->nameToID('Invoice'); } function receiptAccountID() { return $this->nameToID('Receipt'); } function badDebtAccountID() { return $this->nameToID('Bad Debt'); } - function customerCreditAccountID() { return $this->nameToID('Credit'); } - + function customerCreditAccountID() { return $this->nameToID( + // REVISIT : 20090816 + // Use of A/R works, and saves an excess of accounts. + // However, a dedicated account is nice, since it can + // quickly be spotted how much is _really_ due, vs + // how much has been pre-paid. Customer credits in + // A/R is not as clear, although a report is an + // obvious solution. + //'A/R' + 'Credit' + ); } /************************************************************************** ************************************************************************** @@ -224,13 +233,28 @@ class Account extends AppModel { function collectableAccounts() { $accounts = $this->receiptAccounts(); - foreach(array($this->nsfAccountID(), + foreach(array($this->customerCreditAccountID(), + $this->securityDepositAccountID(), + $this->nsfAccountID(), + $this->waiverAccountID(), $this->badDebtAccountID(), - $this->securityDepositAccountID()) + //$this->nameToID('Closing'), + //$this->nameToID('Equity'), + ) AS $account_id) { $accounts[$account_id] = $this->name($account_id); } + $accounts['all'] = $accounts['default'] = $accounts; + + foreach(array($this->concessionAccountID(), + $this->waiverAccountID(), + $this->badDebtAccountID(), + ) + AS $account_id) { + unset($accounts['default'][$account_id]); + } + return $accounts; } diff --git a/site/models/statement_entry.php b/site/models/statement_entry.php index 4398012..a7f9e03 100644 --- a/site/models/statement_entry.php +++ b/site/models/statement_entry.php @@ -224,9 +224,11 @@ class StatementEntry extends AppModel { $result = $this->Transaction->addReversal ($charge, $stamp, 'Charge Reversal'); - // Mark the charge as reversed - $this->id = $id; - $this->saveField('reverse_transaction_id', $result['transaction_id']); + if (empty($result['error'])) { + // Mark the charge as reversed + $this->id = $id; + $this->saveField('reverse_transaction_id', $result['transaction_id']); + } return $this->prReturn($result); } diff --git a/site/models/transaction.php b/site/models/transaction.php index c0a89a5..1b2922d 100644 --- a/site/models/transaction.php +++ b/site/models/transaction.php @@ -1169,9 +1169,12 @@ class Transaction extends AppModel { $squery['fields'][] = "SUM(Transaction.amount) AS total"; $squery['fields'][] = "COUNT(Transaction.id) AS count"; $stats = $this->find('first', $squery); + if (empty($stats)) + return $this->prReturn(array()); $stats = $stats[0]; unset($stats[0]); + foreach ($this->hasMany AS $table => $association) { // Only calculate stats for *Entry types if (!preg_match("/Entry$/", $table) && diff --git a/site/views/accounts/collected.ctp b/site/views/accounts/collected.ctp index 7f7e862..0d0df56 100644 --- a/site/views/accounts/collected.ctp +++ b/site/views/accounts/collected.ctp @@ -166,12 +166,11 @@ echo $this->element('statement_entries', array 'grid_div_class' => 'text-below', 'grid_events' => array('loadComplete' => 'onGridLoadComplete()'), 'grid_setup' => array('hiddengrid' => true), - //'caption' => '', 'caption' => 'Collected ' . Inflector::pluralize($account['name']), 'action' => 'collected', - 'filter' => array(//'StatementEntry.type' => 'DISBURSEMENT', - 'ChargeEntry.account_id' => $account['id']), - 'exclude' => array('Account', 'Charge', 'Type'), + 'filter' => array('ChargeEntry.account_id' => $account['id']), + 'include' => array('Amount'), + 'exclude' => array(/*'Type',*/ 'Debit', 'Credit'), ), ));