Discovered that the use of the term 'Payment' has been a misnomer. A company uses the term payment to indicate the monies it pays to _others_. Changing this leaves us without a good replacement term, but disbursement really seems to fit the bill. As comfortable as the term payment was, it was odd in many respects and disbursement does seem more appropriate. I'm sure there are several lingering bugs from this massive search/replace exercise, but this is a decent baseline for the change.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@488 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-05 01:00:09 +00:00
parent 094e15ddf9
commit cb969ba340
21 changed files with 211 additions and 197 deletions

View File

@@ -855,8 +855,8 @@ CREATE TABLE `pmgr_accounts` (
-- normal circumstances, when a debit occurs.
-- `trackable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
`deposits` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for deposits?
`charges` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for charges?
`payments` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for payments?
`invoices` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for invoices?
`receipts` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for receipts?
`refunds` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for refunds?
-- Security Level
@@ -884,7 +884,7 @@ INSERT INTO `pmgr_accounts` (`type`, `name`)
-- us identify how serious the NSF situation is.
('ASSET', 'NSF' ),
('LIABILITY', 'A/P' );
INSERT INTO `pmgr_accounts` (`type`, `name`, `payments`, `refunds`)
INSERT INTO `pmgr_accounts` (`type`, `name`, `receipts`, `refunds`)
VALUES
('ASSET', 'Cash', 1, 1),
('ASSET', 'Check', 1, 0),
@@ -898,7 +898,7 @@ INSERT INTO `pmgr_accounts` (`type`, `name`, `refunds`, `deposits`)
-- REVISIT <AP>: 20090710 : We probably don't really want petty cash depositable.
-- This is just for testing our deposit code
('ASSET', 'Petty Cash', 1, 1);
INSERT INTO `pmgr_accounts` (`type`, `name`, `charges`)
INSERT INTO `pmgr_accounts` (`type`, `name`, `invoices`)
VALUES
('LIABILITY', 'Tax', 1),
('LIABILITY', 'Security Deposit', 1),
@@ -963,11 +963,12 @@ CREATE TABLE `pmgr_transactions` (
`type` ENUM('INVOICE',
'RECEIPT',
'DEPOSIT',
'CLOSE',
'VOUCHER',
'DEPOSIT', -- Probably should use VOUCHER for DEPOSIT
'CLOSE', -- Essentially an internal (not accounting) transaction
-- 'CREDIT',
-- 'REFUND',
'TRANSFER')
'TRANSFER') -- Unsure of TRANSFERs use
NOT NULL,
`stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -992,10 +993,6 @@ CREATE TABLE `pmgr_transactions` (
-- (e.g. A/R, Bank, etc)
`account_id` INT(10) UNSIGNED DEFAULT NULL,
`ledger_id` INT(10) UNSIGNED DEFAULT NULL,
-- For convenience. Actually, INVOICE will always set crdr
-- to DEBIT, RECEIPT will use CREDIT, and DEPOSIT will use
-- DEBIT
`crdr` ENUM('DEBIT',
'CREDIT')
DEFAULT NULL,
@@ -1024,9 +1021,6 @@ CREATE TABLE `pmgr_ledger_entries` (
-- The account/ledger of the entry
`account_id` INT(10) UNSIGNED NOT NULL,
`ledger_id` INT(10) UNSIGNED NOT NULL,
-- For convenience. Actually, CHARGE will always set crdr
-- to CREDIT and PAYMENT will use DEBIT.
`crdr` ENUM('DEBIT',
'CREDIT')
NOT NULL,
@@ -1073,7 +1067,8 @@ CREATE TABLE `pmgr_statement_entries` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('CHARGE',
'PAYMENT',
'DISBURSEMENT',
'VOUCHER-PAYMENT', -- REVISIT: Make PAYMENT
'SURPLUS',
'WAIVER',
-- REVISIT <AP>: 20090730
@@ -1084,7 +1079,7 @@ CREATE TABLE `pmgr_statement_entries` (
`transaction_id` INT(10) UNSIGNED NOT NULL,
-- Effective date is when the charge/payment/transfer actually
-- Effective date is when the charge/disbursement/transfer actually
-- takes effect (since it may not be at the time of the transaction).
-- Through date is used if/when a charge covers a certain time period,
-- like rent. A security deposit, for example, would not use the
@@ -1109,7 +1104,7 @@ CREATE TABLE `pmgr_statement_entries` (
-- in the statement. Keeping it for now...
`account_id` INT(10) UNSIGNED DEFAULT NULL,
-- Allow the payment to reconcile against the charge
-- Allow the disbursement to reconcile against the charge
`charge_entry_id` INT(10) UNSIGNED DEFAULT NULL,
`comment` VARCHAR(255) DEFAULT NULL,

View File

@@ -1308,18 +1308,13 @@ foreach $row (@{query($sdbh, $query)})
# 'effective_date' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'effective_date'},
# 'effective_date' => $effective_date;
# 'through_date' => $through_date;
'lease_id' => ($row->{'entry_type'} eq 'CREDIT'
? 0
: $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}),
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'amount' => $reconcile_amount,
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'},
};
$row->{'ChargeID'} = undef
if $row->{'entry_type'} eq 'CREDIT';
# Update the receipt & tender customer_id, now that we have payment info
$newdb{'tables'}{'transactions'}{'rows'}[
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'}
@@ -1336,7 +1331,7 @@ foreach $row (@{query($sdbh, $query)})
# Add the Payment Statement Entry
addRow('statement_entries', {
'transaction_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'},
'type' => $row->{'entry_type'} || 'PAYMENT',
'type' => 'DISBURSEMENT',
# 'effective_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'effective_date'},
# 'through_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'through_date'},
'effective_date' => $effective_date,

View File

@@ -141,7 +141,7 @@ class AccountsController extends AppController {
$payment_accounts = $this->Account->collectableAccounts();
//$payment_accounts[$this->Account->nameToID('Closing')] = 'Closing';
//$payment_accounts[$this->Account->nameToID('Equity')] = 'Equity';
$default_accounts = array_diff_key($this->Account->paymentAccounts(),
$default_accounts = array_diff_key($this->Account->receiptAccounts(),
array($this->Account->concessionAccountID() => 1));
$this->set(compact('payment_accounts', 'default_accounts'));

View File

@@ -64,7 +64,7 @@ class CustomersController extends AppController {
function gridDataFields(&$params, &$model) {
$fields = parent::gridDataFields($params, $model);
return array_merge($fields,
$this->Customer->StatementEntry->chargePaymentFields(true));
$this->Customer->StatementEntry->chargeDisbursementFields(true));
}
function gridDataConditions(&$params, &$model) {
@@ -384,7 +384,7 @@ class CustomersController extends AppController {
$default_type = $TT->defaultPaymentType();
$this->set(compact('payment_types', 'default_type'));
$title = ($customer['name'] . ': Payment Entry');
$title = ($customer['name'] . ': Receipt Entry');
$this->set(compact('customer', 'charges', 'stats', 'title'));
}

View File

@@ -64,7 +64,7 @@ class LeasesController extends AppController {
function gridDataFields(&$params, &$model) {
$fields = parent::gridDataFields($params, $model);
return array_merge($fields,
$this->Lease->StatementEntry->chargePaymentFields(true));
$this->Lease->StatementEntry->chargeDisbursementFields(true));
}
function gridDataConditions(&$params, &$model) {
@@ -332,7 +332,7 @@ class LeasesController extends AppController {
));
$A = new Account();
$charge_accounts = $A->chargeAccounts();
$charge_accounts = $A->invoiceAccounts();
$default_account = $A->rentAccountID();
$this->set(compact('charge_accounts', 'default_account'));

View File

@@ -49,21 +49,21 @@ class StatementEntriesController extends AppController {
);
if (isset($params['post']['custom']['statement_entry_id'])) {
$link['PaymentEntry'] = array();
$link['DisbursementEntry'] = array();
$link['ChargeEntry'] = array();
}
/* if ($params['action'] === 'collected') { */
/* $link['PaymentEntry'] = array('Receipt' => array('class' => 'Transaction')); */
/* $link['DisbursementEntry'] = array('Receipt' => array('class' => 'Transaction')); */
/* $link['ChargeEntry'] = array('Invoice' => array('class' => 'Transaction')); */
/* } */
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
/* $link['PaymentEntry'] = array(); */
/* $link['DisbursementEntry'] = array(); */
/* $link['ChargeEntry'] = array(); */
/* } */
/* elseif (isset($params['post']['custom']['customer_id']) || isset($params['post']['custom']['lease_id'])) { */
/* $link['PaymentEntry'] = array(); */
/* $link['DisbursementEntry'] = array(); */
/* } */
return array('link' => $link);
@@ -74,18 +74,18 @@ class StatementEntriesController extends AppController {
if (in_array('applied', $params['post']['fields'])) {
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(DisbursementEntry.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))" .
" AS 'applied'");
$fields[] = ("StatementEntry.amount - (" .
"IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(DisbursementEntry.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))" .
") AS 'balance'");
}
$fields = array_merge($fields,
$this->StatementEntry->chargePaymentFields());
$this->StatementEntry->chargeDisbursementFields());
return $fields;
}
@@ -110,7 +110,7 @@ class StatementEntriesController extends AppController {
if (isset($statement_entry_id)) {
$conditions[] = array('OR' =>
array(array('ChargeEntry.id' => $statement_entry_id),
array('PaymentEntry.id' => $statement_entry_id)));
array('DisbursementEntry.id' => $statement_entry_id)));
}
return $conditions;
@@ -144,13 +144,13 @@ class StatementEntriesController extends AppController {
if (in_array('applied', $params['post']['fields'])) {
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(DisbursementEntry.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))" .
" AS 'applied'",
"StatementEntry.amount - (" .
"IF(StatementEntry.type = 'CHARGE'," .
" SUM(COALESCE(PaymentEntry.amount,0))," .
" SUM(COALESCE(DisbursementEntry.amount,0))," .
" SUM(COALESCE(ChargeEntry.amount,0)))" .
") AS 'balance'",
);
@@ -266,7 +266,7 @@ class StatementEntriesController extends AppController {
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE')
$stats = $stats['Charge'];
else
$stats = $stats['Payment'];
$stats = $stats['Disbursement'];
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE' &&

View File

@@ -114,7 +114,7 @@ class TransactionsController extends AppController {
**************************************************************************
**************************************************************************
* action: postReceipt
* - handles the creation of a payment receipt
* - handles the creation of a receipt
*/
function postReceipt() {

View File

@@ -82,7 +82,7 @@ class UnitsController extends AppController {
$fields = parent::gridDataFields($params, $model);
return array_merge($fields,
$this->Unit->Lease->StatementEntry->chargePaymentFields(true));
$this->Unit->Lease->StatementEntry->chargeDisbursementFields(true));
}
function gridDataConditions(&$params, &$model) {

View File

@@ -194,12 +194,12 @@ class Account extends AppModel {
* - Returns an array of accounts suitable for activity xxx
*/
function chargeAccounts() {
return $this->relatedAccounts('charges', array('order' => 'name'));
function invoiceAccounts() {
return $this->relatedAccounts('invoices', array('order' => 'name'));
}
function paymentAccounts() {
return $this->relatedAccounts('payments', array('order' => 'name'));
function receiptAccounts() {
return $this->relatedAccounts('receipts', array('order' => 'name'));
}
function depositAccounts() {
@@ -215,7 +215,7 @@ class Account extends AppModel {
*/
function collectableAccounts() {
$accounts = $this->paymentAccounts();
$accounts = $this->receiptAccounts();
foreach(array($this->nsfAccountID(),
$this->securityDepositAccountID())

View File

@@ -127,23 +127,6 @@ class Customer extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: excessPayments
* - Returns payments which have not yet been fully utilized
*/
function excessPayments($id, $query = null) {
$this->prEnter(compact('id', 'query'));
$this->queryInit($query);
$query['conditions'][] = array('StatementEntry.customer_id' => $id);
$set = $this->StatementEntry->reconciledSet('PAYMENT', $query, true);
return $this->prReturn($set);
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -314,14 +297,14 @@ class Customer extends AppModel {
/* $stats = $this->StatementEntry->find */
/* ('first', array */
/* ('contain' => false, */
/* 'fields' => $this->StatementEntry->chargePaymentFields(true), */
/* 'fields' => $this->StatementEntry->chargeDisbursementFields(true), */
/* 'conditions' => array('StatementEntry.customer_id' => $id), */
/* )); */
$find_stats = $this->StatementEntry->find
('first', array
('contain' => false,
'fields' => $this->StatementEntry->chargePaymentFields(true),
'fields' => $this->StatementEntry->chargeDisbursementFields(true),
'conditions' => array('StatementEntry.customer_id' => $id),
));
$find_stats = $find_stats[0];

View File

@@ -72,7 +72,7 @@ class Lease extends AppModel {
**************************************************************************
* function: releaseSecurityDeposits
* - Releases all security deposits associated with this lease.
* That simply makes a payment out of them, which can be used
* That simply makes a disbursement out of them, which can be used
* to pay outstanding customer charges, or simply to become
* a customer surplus (customer credit).
*/

View File

@@ -170,7 +170,7 @@ class LedgerEntry extends AppModel {
//pr(array('stats()', compact('id', 'query', 'set')));
$rtypes = array('charge', 'payment',
$rtypes = array('charge', 'disbursement',
// 'debit', 'credit',
);
@@ -178,10 +178,8 @@ class LedgerEntry extends AppModel {
foreach($rtypes AS $rtype) {
$Rtype = ucfirst($rtype);
if (($rtype == 'charge' && (!isset($set) || $set == 'PAYMENT')) ||
($rtype == 'payment' && (!isset($set) || $set == 'CHARGE'))
/* ($rtype == 'debit' && (!isset($set) || $set == 'CREDIT')) || */
/* ($rtype == 'credit' && (!isset($set) || $set == 'DEBIT')) */
if (($rtype == 'charge' && (!isset($set) || $set == 'DISBURSEMENT')) ||
($rtype == 'disbursement' && (!isset($set) || $set == 'CHARGE'))
) {
$rquery = $query;

View File

@@ -7,15 +7,15 @@ class StatementEntry extends AppModel {
'Lease',
'Account',
// The charge to which this payment applies (if it is one)
// The charge to which this disbursement applies (if it is one)
'ChargeEntry' => array(
'className' => 'StatementEntry',
),
);
var $hasMany = array(
// The payments that apply to this charge (if it is one)
'PaymentEntry' => array(
// The disbursements that apply to this charge (if it is one)
'DisbursementEntry' => array(
'className' => 'StatementEntry',
'foreignKey' => 'charge_entry_id',
),
@@ -27,11 +27,11 @@ class StatementEntry extends AppModel {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: chargePaymentFields
* function: chargeDisbursementFields
*/
function chargePaymentFields($sum = false, $entry_name = 'StatementEntry') {
function chargeDisbursementFields($sum = false, $entry_name = 'StatementEntry') {
$fields = array
(
($sum ? 'SUM(' : '') .
@@ -40,14 +40,14 @@ class StatementEntry extends AppModel {
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
//"IF({$entry_name}.type IN('PAYMENT', 'SURPLUS', 'WAIVER')," .
//"IF({$entry_name}.type IN('DISBURSEMENT', 'SURPLUS', 'WAIVER')," .
"IF({$entry_name}.type NOT IN('CHARGE', 'VOID')," .
" {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS payment' . ($sum ? 's' : ''),
($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
//"IF({$entry_name}.type = 'CHARGE', 1," .
//" IF({$entry_name}.type IN('PAYMENT', 'SURPLUS', 'WAIVER'), -1, 0))" .
//" IF({$entry_name}.type IN('DISBURSEMENT', 'SURPLUS', 'WAIVER'), -1, 0))" .
"IF({$entry_name}.type = 'VOID', 0," .
" IF({$entry_name}.type = 'CHARGE', 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
@@ -154,7 +154,7 @@ class StatementEntry extends AppModel {
* function: reverse
* - Reverses the charges
*
* SAMPLE MOVE IN w/ PRE PAYMENT
* SAMPLE MOVE IN w/ PRE DISBURSEMENT
* DEPOSIT RENT A/R RECEIPT CHECK PETTY BANK
* ------- ------- ------- ------- ------- ------- -------
* |25 | 25| | | | |
@@ -271,20 +271,20 @@ OPTION 2
function reconciledSetQuery($set, $query) {
$this->queryInit($query);
if ($set == 'CHARGE' || $set == 'PAYMENT')
if ($set == 'CHARGE' || $set == 'DISBURSEMENT')
$query['conditions'][] = array('StatementEntry.type' => $set);
else
die("INVALID RECONCILE SET");
if ($set == 'CHARGE')
$query['link']['PaymentEntry'] = array('fields' => array("SUM(PaymentEntry.amount) AS reconciled"));
if ($set == 'PAYMENT')
$query['link']['DisbursementEntry'] = array('fields' => array("SUM(DisbursementEntry.amount) AS reconciled"));
if ($set == 'DISBURSEMENT')
$query['link']['ChargeEntry'] = array('fields' => array("SUM(ChargeEntry.amount) AS reconciled"));
$query['group'] = 'StatementEntry.id';
// REVISIT: TESTING
//$query['link']['PaymentEntry'] = array('fields' => array("(`PaymentEntry.amount`+0) AS reconciled"));
//$query['link']['DisbursementEntry'] = array('fields' => array("(`DisbursementEntry.amount`+0) AS reconciled"));
//$query['group'] = null;
// END REVISIT
@@ -316,7 +316,7 @@ OPTION 2
$reconciled = true;
elseif ($entry['StatementEntry']['reconciled'] == 0)
$reconciled = false;
else // Partial payment; depends on unrec
else // Partial disbursement; depends on unrec
$reconciled = (!$unrec && $if_rec_include_partial);
// Add to the set, if it's been requested
@@ -334,7 +334,7 @@ OPTION 2
**************************************************************************
* function: reconciledEntries
* - Returns a list of entries that reconcile against the given entry.
* (such as payments towards a charge).
* (such as disbursements towards a charge).
*/
function reconciledEntriesQuery($id, $query = null) {
$this->queryInit($query, false);
@@ -346,8 +346,8 @@ OPTION 2
$query['conditions'][] = array('StatementEntry.id' => $id);
if ($this->data['StatementEntry']['type'] == 'CHARGE')
$query['link']['PaymentEntry'] = array();
if ($this->data['StatementEntry']['type'] == 'PAYMENT')
$query['link']['DisbursementEntry'] = array();
if ($this->data['StatementEntry']['type'] == 'DISBURSEMENT')
$query['link']['ChargeEntry'] = array();
return $query;
@@ -373,24 +373,24 @@ OPTION 2
*
* REVISIT <AP>: 20090726
* This algorithm shouldn't be hardcoded. We need to allow
* the user to specify how payments should be applied.
* the user to specify how disbursements should be applied.
*
*/
function assignCredits($query = null, $receipt_id = null,
$charge_ids = null, $payment_type = null,
$charge_ids = null, $disbursement_type = null,
$customer_id = null, $lease_id = null)
{
$this->prFunctionLevel(25);
$this->prEnter(compact('query', 'receipt_id',
'charge_ids', 'payment_type',
'charge_ids', 'disbursement_type',
'customer_id', 'lease_id'));
$this->queryInit($query);
if (!empty($customer_id))
$query['conditions'][] = array('StatementEntry.customer_id' => $customer_id);
if (empty($payment_type))
$payment_type = 'PAYMENT';
if (empty($disbursement_type))
$disbursement_type = 'DISBURSEMENT';
$ret = array();
@@ -461,7 +461,7 @@ OPTION 2
// Initialize our list of used credits
$used_credits = array();
// Work through all unpaid charges, applying payments as we go
// Work through all unpaid charges, applying disbursements as we go
foreach ($charges['entries'] AS $charge) {
$this->pr(20, compact('charge'),
@@ -489,9 +489,9 @@ OPTION 2
if (count($credits)) {
// Peel off the first credit available
$credit =& $credits[0];
$payment_date = $credit['StatementEntry']['effective_date'];
$payment_transaction_id = $credit['StatementEntry']['transaction_id'];
$payment_account_id = $credit['StatementEntry']['account_id'];
$disbursement_date = $credit['StatementEntry']['effective_date'];
$disbursement_transaction_id = $credit['StatementEntry']['transaction_id'];
$disbursement_account_id = $credit['StatementEntry']['account_id'];
if (!isset($credit['balance']))
$credit['balance'] = $credit['StatementEntry']['amount'];
@@ -499,22 +499,22 @@ OPTION 2
elseif (!empty($receipt_credit['balance'])) {
// Use our only receipt credit
$credit =& $receipt_credit;
$payment_date = $credit['Transaction']['stamp'];
$payment_transaction_id = $credit['Transaction']['id'];
$payment_account_id = $credit['LedgerEntry']['account_id'];
$disbursement_date = $credit['Transaction']['stamp'];
$disbursement_transaction_id = $credit['Transaction']['id'];
$disbursement_account_id = $credit['LedgerEntry']['account_id'];
}
else {
die("HOW DID WE GET HERE WITH NO SURPLUS?");
}
// Set the payment amount to the maximum amount
// Set the disbursement amount to the maximum amount
// possible without exceeding the charge or credit balance
$payment_amount = min($charge['balance'], $credit['balance']);
$disbursement_amount = min($charge['balance'], $credit['balance']);
if (!isset($credit['applied']))
$credit['applied'] = 0;
$credit['applied'] += $payment_amount;
$credit['balance'] -= $payment_amount;
$credit['applied'] += $disbursement_amount;
$credit['balance'] -= $disbursement_amount;
$this->pr(20, compact('credit'),
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
@@ -528,28 +528,28 @@ OPTION 2
if ($credit['balance'] <= 0 && count($credits))
$used_credits[] = array_shift($credits);
// Add a payment that uses the available credit to pay the charge
$payment = array('type' => $payment_type,
'account_id' => $payment_account_id,
'amount' => $payment_amount,
'effective_date' => $payment_date,
'transaction_id' => $payment_transaction_id,
// Add a disbursement that uses the available credit to pay the charge
$disbursement = array('type' => $disbursement_type,
'account_id' => $disbursement_account_id,
'amount' => $disbursement_amount,
'effective_date' => $disbursement_date,
'transaction_id' => $disbursement_transaction_id,
'customer_id' => $charge['StatementEntry']['customer_id'],
'lease_id' => $charge['StatementEntry']['lease_id'],
'charge_entry_id' => $charge['StatementEntry']['id'],
'comment' => null,
);
$this->pr(20, compact('payment'),
'New Payment Entry');
$this->pr(20, compact('disbursement'),
'New Disbursement Entry');
$result = $this->addStatementEntry($payment);
$ret['Payment'][] = $result;
$result = $this->addStatementEntry($disbursement);
$ret['Disbursement'][] = $result;
if ($result['error'])
$ret['error'] = true;
// Adjust the charge balance to reflect the new payment
$charge['balance'] -= $payment_amount;
// Adjust the charge balance to reflect the new disbursement
$charge['balance'] -= $disbursement_amount;
if ($charge['balance'] < 0)
die("HOW DID WE GET A NEGATIVE CHARGE AMOUNT?");
@@ -564,7 +564,7 @@ OPTION 2
$used_credits[] = array_shift($credits);
$this->pr(18, compact('credits', 'used_credits', 'receipt_credit'),
'Payments added');
'Disbursements added');
// Clean up any explicit credits that have been used
foreach ($used_credits AS $credit) {
@@ -627,7 +627,7 @@ OPTION 2
// Determine the total in charges
$charge_query = $query;
unset($charge_query['link']['ChargeEntry']);
unset($charge_query['link']['PaymentEntry']);
unset($charge_query['link']['DisbursementEntry']);
$charge_query['fields'] = array();
$charge_query['fields'][] = "SUM(StatementEntry.amount) AS total";
@@ -639,23 +639,23 @@ OPTION 2
'Charges');
// Tally the amount actually _paid_ to those charges
$charge_payment_query = $charge_query;
$charge_payment_query['link']['PaymentEntry'] = array('fields' => array());
$charge_payment_query['fields'] = array();
$charge_payment_query['fields'][] = "COALESCE(SUM(PaymentEntry.amount),0) AS paid";
$charge_payment_query['conditions'][] = array('PaymentEntry.type' => 'PAYMENT');
$result = $this->find('first', $charge_payment_query);
$charge_disbursement_query = $charge_query;
$charge_disbursement_query['link']['DisbursementEntry'] = array('fields' => array());
$charge_disbursement_query['fields'] = array();
$charge_disbursement_query['fields'][] = "COALESCE(SUM(DisbursementEntry.amount),0) AS paid";
$charge_disbursement_query['conditions'][] = array('DisbursementEntry.type' => 'DISBURSEMENT');
$result = $this->find('first', $charge_disbursement_query);
$stats['Charge'] += $result[0];
$this->pr(17, compact('charge_payment_query', 'result'),
'Charge Payments');
$this->pr(17, compact('charge_disbursement_query', 'result'),
'Charge Disbursements');
// Tally the amount of charges that have been waived
$charge_waiver_query = $charge_query;
$charge_waiver_query['link']['PaymentEntry'] = array('fields' => array());
$charge_waiver_query['link']['DisbursementEntry'] = array('fields' => array());
$charge_waiver_query['fields'] = array();
$charge_waiver_query['fields'][] = "COALESCE(SUM(PaymentEntry.amount),0) AS waived";
$charge_waiver_query['conditions'][] = array('PaymentEntry.type' => 'WAIVER');
$charge_waiver_query['fields'][] = "COALESCE(SUM(DisbursementEntry.amount),0) AS waived";
$charge_waiver_query['conditions'][] = array('DisbursementEntry.type' => 'WAIVER');
$result = $this->find('first', $charge_waiver_query);
$stats['Charge'] += $result[0];
@@ -671,46 +671,46 @@ OPTION 2
$stats['Charge']['balance'] = 0;
// Determine the total in payments, including those which
// Determine the total in disbursements, including those which
// are charge waivers and those that do not even reconcile
// to charges (i.e. they are surplus payments).
$payment_query = $query;
unset($payment_query['link']['PaymentEntry']);
$payment_query['link']['ChargeEntry'] = array('fields' => array());
// to charges (i.e. they are surplus disbursements).
$disbursement_query = $query;
unset($disbursement_query['link']['DisbursementEntry']);
$disbursement_query['link']['ChargeEntry'] = array('fields' => array());
$payment_query['fields'] = array();
$payment_query['fields'][] = "SUM(StatementEntry.amount) AS total";
$payment_query['fields'][] = "COALESCE(SUM(IF(ChargeEntry.id IS NULL, 0, StatementEntry.amount)), 0) AS charged";
$payment_query['fields'][] = "COALESCE(SUM(IF(ChargeEntry.id IS NULL, StatementEntry.amount, 0)), 0) AS surplus";
$disbursement_query['fields'] = array();
$disbursement_query['fields'][] = "SUM(StatementEntry.amount) AS total";
$disbursement_query['fields'][] = "COALESCE(SUM(IF(ChargeEntry.id IS NULL, 0, StatementEntry.amount)), 0) AS charged";
$disbursement_query['fields'][] = "COALESCE(SUM(IF(ChargeEntry.id IS NULL, StatementEntry.amount, 0)), 0) AS surplus";
$payment_query['conditions'][] = array('StatementEntry.type' => array('PAYMENT', 'WAIVER', 'SURPLUS'));
$result = $this->find('first', $payment_query);
$stats['Payment'] = $result[0];
$disbursement_query['conditions'][] = array('StatementEntry.type' => array('DISBURSEMENT', 'WAIVER', 'SURPLUS'));
$result = $this->find('first', $disbursement_query);
$stats['Disbursement'] = $result[0];
$this->pr(17, compact('payment_query', 'result'),
'Payments');
$this->pr(17, compact('disbursement_query', 'result'),
'Disbursements');
// Compute some summary information for payments.
// Compute some summary information for disbursements.
// Add a reconciled field just for consistency with Charge.
$stats['Payment']['reconciled'] =
$stats['Payment']['charged'];
$stats['Payment']['balance'] =
$stats['Payment']['total'] - $stats['Payment']['reconciled'];
if (!isset($stats['Payment']['balance']))
$stats['Payment']['balance'] = 0;
$stats['Disbursement']['reconciled'] =
$stats['Disbursement']['charged'];
$stats['Disbursement']['balance'] =
$stats['Disbursement']['total'] - $stats['Disbursement']['reconciled'];
if (!isset($stats['Disbursement']['balance']))
$stats['Disbursement']['balance'] = 0;
// 'balance' is simply the difference between
// the balances of charges and payments
$stats['balance'] = $stats['Charge']['balance'] - $stats['Payment']['balance'];
// the balances of charges and disbursements
$stats['balance'] = $stats['Charge']['balance'] - $stats['Disbursement']['balance'];
if (!isset($stats['balance']))
$stats['balance'] = 0;
// 'account_balance' is really only relevant to
// callers that have requested charge and payment
// callers that have requested charge and disbursement
// stats with respect to a particular account.
// It represents the difference between inflow
// and outflow from that account.
$stats['account_balance'] = $stats['Charge']['paid'] - $stats['Payment']['total'];
$stats['account_balance'] = $stats['Charge']['paid'] - $stats['Disbursement']['total'];
if (!isset($stats['account_balance']))
$stats['account_balance'] = 0;

View File

@@ -92,8 +92,8 @@ class Tender extends AppModel {
* - Add new LedgerEntry (L2a); T1; debit:NSF; -$A; N1
* - Add new LedgerEntry (L2b); T1; credit:A/R; -$A
* - For Tx associated with LE associated with C1:
* - For each Payment SE of Tx:
* - Add new StatementEntry (S1n); T1; PAYMENT; -1*S1n.amount
* - For each Disbursement SE of Tx:
* - Add new StatementEntry (S1n); T1; DISBURSEMENT; -1*S1n.amount
* - New Transaction (T2) (?????)
* - Add new StatementEntry (S2); T2; CHARGE; NSF; $35
* - Add new LedgerEntry (L3a); T2; credit:NSF-Fee; $35

View File

@@ -19,9 +19,9 @@ class Transaction extends AppModel {
'conditions' => array('Charge.type' => 'CHARGE')
),
'Payment' => array(
'Disbursement' => array(
'className' => 'StatementEntry',
'conditions' => array('Payment.type' => 'PAYMENT')
'conditions' => array('Disbursement.type' => 'DISBURSEMENT')
),
'Debit' => array(
@@ -93,9 +93,9 @@ class Transaction extends AppModel {
'lease_id' => $lease_id,
);
// Go through the statement entries and flag as payments
// Go through the statement entries and flag as disbursements
foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'PAYMENT', // not used
$entry += array('type' => 'DISBURSEMENT', // not used
'crdr' => 'DEBIT',
'account_id' =>
(isset($entry['Tender']['tender_type_id'])
@@ -125,9 +125,9 @@ class Transaction extends AppModel {
if (count($data['Entry']) != 1)
die("INTERNAL ERROR: Should be one Entry for addWaiver");
// Just make sure the payment(s) are marked as waivers
// Just make sure the disbursement(s) are marked as waivers
// and that they go to cover the specific charge.
$data['Transaction']['payment_type'] = 'WAIVER';
$data['Transaction']['disbursement_type'] = 'WAIVER';
$data['Transaction']['charge_entry_id'] = $charge_id;
// In all other respects this is just a receipt.
@@ -151,11 +151,13 @@ class Transaction extends AppModel {
// Establish the transaction as a deposit
$deposit =& $data['Transaction'];
$deposit['type'] = 'DEPOSIT';
$deposit['crdr'] = 'DEBIT';
$deposit['account_id'] = $account_id;
$deposit['customer_id'] = null;
$deposit['lease_id'] = null;
$deposit +=
array('type' => 'DEPOSIT',
'crdr' => 'DEBIT',
'account_id' => $account_id,
'customer_id' => null,
'lease_id' => null,
);
// Save the list of IDs, so that we can mark their
// deposit transaction after it has been created.
@@ -201,10 +203,13 @@ class Transaction extends AppModel {
// Establish the transaction as a close
$close =& $data['Transaction'];
$close['type'] = 'CLOSE';
$close['account_id'] = null;
$close['customer_id'] = null;
$close['lease_id'] = null;
$close +=
array('type' => 'CLOSE',
'crdr' => null,
'account_id' => null,
'customer_id' => null,
'lease_id' => null,
);
$ledger_ids = array();
$data['Entry'] = array();
@@ -246,6 +251,44 @@ class Transaction extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addVoucher
* - Adds a new voucher transaction, which is money outflow
*/
function addVoucher($data) {
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
// REVISIT <AP>: 20090804
// NOT IMPLEMENTED AT ALL. Just cut and paste so far
return array('error' => true);
// Establish the transaction as an voucher
$voucher =& $data['Transaction'];
$voucher +=
array('type' => 'VOUCHER',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountPayableAccountID(),
'customer_id' => null,
'lease_id' => null,
);
// Go through the statement entries and flag as charges
foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'CHARGE',
'crdr' => 'CREDIT',
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['voucher_id'] = $ids['transaction_id'];
return $this->prReturn($ids);
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -353,7 +396,7 @@ class Transaction extends AppModel {
*
* - Entry (array)
* - [MANDATORY]
* - type (CHARGE, PAYMENT)
* - type (CHARGE, DISBURSEMENT)
* - account_id
* - crdr
* - amount
@@ -466,7 +509,7 @@ class Transaction extends AppModel {
array_flip(array('customer_id', 'lease_id')));
$se['comment'] = $entry['statement_entry_comment'];
// (PAYMENTS will have statement entries created below, when
// (DISBURSEMENTS will have statement entries created below, when
// assigning credits, and DEPOSITS don't have statement entries)
if ($transaction['type'] != 'INVOICE' && $subtype !== 'NSF')
$se = null;
@@ -556,8 +599,8 @@ class Transaction extends AppModel {
($transaction['type'] == 'RECEIPT' && !empty($transaction['charge_entry_id'])
? $transaction['charge_entry_id']
: null),
(!empty($transaction['payment_type'])
? $transaction['payment_type']
(!empty($transaction['disbursement_type'])
? $transaction['disbursement_type']
: null),
$transaction['customer_id'],
$transaction['lease_id']
@@ -587,7 +630,7 @@ class Transaction extends AppModel {
// Enter the NSF
// This is the transaction pulling money from the bank account
// and recording it in the NSF account. It has nothing to do
// with the customer statement (charges, payments, credits, etc).
// with the customer statement (charges, disbursements, credits, etc).
$bounce_result = $this->addDeposit
(array('Transaction' => array(),
'Entry' => array(array('tender_id' => null,
@@ -637,20 +680,20 @@ class Transaction extends AppModel {
$rollback['Transaction']['customer_id'] = $tender['Tender']['customer_id'];
$rollback['Transaction']['amount'] = -1 * $tender['LedgerEntry']['amount'];
foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $payment) {
if ($payment['type'] === 'SURPLUS') {
$payment['type'] = 'VOID';
$this->StatementEntry->id = $payment['id'];
$this->StatementEntry->saveField('type', $payment['type']);
foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $disbursement) {
if ($disbursement['type'] === 'SURPLUS') {
$disbursement['type'] = 'VOID';
$this->StatementEntry->id = $disbursement['id'];
$this->StatementEntry->saveField('type', $disbursement['type']);
}
else {
$rollback['Entry'][] =
array('type' => $payment['type'],
'amount' => -1 * $payment['amount'],
array('type' => $disbursement['type'],
'amount' => -1 * $disbursement['amount'],
'account_id' => $this->Account->nsfAccountID(),
'customer_id' => $payment['customer_id'],
'lease_id' => $payment['lease_id'],
'charge_entry_id' => $payment['charge_entry_id'],
'customer_id' => $disbursement['customer_id'],
'lease_id' => $disbursement['lease_id'],
'charge_entry_id' => $disbursement['charge_entry_id'],
'effective_date' => $stamp,
);
}
@@ -742,7 +785,7 @@ class Transaction extends AppModel {
}
elseif ($table == 'StatementEntry') {
$squery['fields'] = array_merge($squery['fields'],
$this->StatementEntry->chargePaymentFields(true));
$this->StatementEntry->chargeDisbursementFields(true));
}
else {
$squery['fields'][] = "SUM({$table}.amount) AS total";

View File

@@ -164,7 +164,7 @@ echo $this->element('statement_entries', array
//'grid_setup' => array('hiddengrid' => true),
//'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'caption' => 'Collected ' . Inflector::pluralize($account['name']),
'filter' => array('StatementEntry.type' => 'PAYMENT',
'filter' => array('StatementEntry.type' => 'DISBURSEMENT',
'ChargeEntry.account_id' => $account['id']),
'exclude' => array('Account', 'Charge'),
),

View File

@@ -82,7 +82,7 @@ echo $this->element('ledger_entries', array
"(". $current_ledger['name'] .")"),
'filter' => array('Ledger.id' => $current_ledger['id']),
'exclude' => array('Account', 'Amount', 'Cr/Dr', 'Balance',
empty($account['payments']) ? 'Tender' : null),
empty($account['receipts']) ? 'Tender' : null),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));
@@ -100,7 +100,7 @@ echo $this->element('ledger_entries', array
'caption' => "Entire Ledger",
'filter' => array('Account.id' => $account['id']),
'exclude' => array('Account', 'Amount', 'Cr/Dr', 'Balance',
empty($account['payments']) ? 'Tender' : null),
empty($account['receipts']) ? 'Tender' : null),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));

View File

@@ -18,7 +18,7 @@ $cols['Unit'] = array('index' => 'Unit.name', 'formatter' =>
$cols['Comment'] = array('index' => 'StatementEntry.comment', 'formatter' => 'comment', 'width'=>150);
$cols['Charge'] = array('index' => 'charge', 'formatter' => 'currency');
$cols['Payment'] = array('index' => 'payment', 'formatter' => 'currency');
$cols['Payment'] = array('index' => 'disbursement', 'formatter' => 'currency');
$cols['Applied'] = array('index' => "applied", 'formatter' => 'currency');
$cols['Sub-Total'] = array('index' => 'subtotal-balance', 'formatter' => 'currency', 'sortable' => false);

View File

@@ -72,7 +72,7 @@ echo $this->element('ledger_entries', array
'filter' => array('Ledger.id' => $ledger['id']),
'exclude' => array('Ledger', 'Account',
'Amount', 'Cr/Dr', 'Balance',
empty($account['payments']) ? 'Tender' : null),
empty($account['receipts']) ? 'Tender' : null),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));

View File

@@ -59,12 +59,12 @@ echo $this->element('table',
*/
if (strtoupper($entry['type']) === 'CHARGE') {
$applied_caption = "Payments Applied";
$applied_caption = "Disbursements Applied";
//$remaining_caption = "Charge Balance";
}
else {
$applied_caption = "Applied to Charges";
//$remaining_caption = "Payment Balance";
$applied_caption = "Dispursed to Charges";
//$remaining_caption = "Disbursement Balance";
}
$remaining_caption = "Remaining Balance";