Merge in from surplus_account_20090815 r592
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@593 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -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'));
|
||||
|
||||
@@ -402,6 +402,10 @@ class AppModel extends Model {
|
||||
}
|
||||
|
||||
|
||||
function filter_null($array) {
|
||||
return array_diff_key($array, array_filter($array, 'is_null'));
|
||||
}
|
||||
|
||||
function recursive_array_replace($find, $replace, &$data) {
|
||||
if (!isset($data))
|
||||
return;
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -453,51 +453,4 @@ class CustomersController extends AppController {
|
||||
$this->render('/transactions/bad_debt');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: unreconciled
|
||||
* - returns the list of unreconciled entries
|
||||
*/
|
||||
|
||||
function unreconciled($id) {
|
||||
|
||||
//$this->layout = 'ajax';
|
||||
$this->layout = null;
|
||||
$this->autoLayout = false;
|
||||
$this->autoRender = false;
|
||||
Configure::write('debug', '0');
|
||||
header("Content-type: text/xml;charset=utf-8");
|
||||
|
||||
App::import('Helper', 'Xml');
|
||||
$xml = new XmlHelper();
|
||||
|
||||
// Find the unreconciled entries, then manipulate the structure
|
||||
// slightly to accomodate the format necessary for XML Helper.
|
||||
$unreconciled = $this->Customer->unreconciledCharges($id);
|
||||
|
||||
foreach ($unreconciled['entries'] AS &$entry)
|
||||
$entry = array_intersect_key($entry['StatementEntry'],
|
||||
array('id'=>1));
|
||||
|
||||
$unreconciled = array('entries' =>
|
||||
array('entry' => $unreconciled['entries'],
|
||||
'balance' => $unreconciled['summary']['balance']));
|
||||
|
||||
// XML Helper will dump an empty tag if the array is empty
|
||||
if (empty($unreconciled['entries']['entry']))
|
||||
unset($unreconciled['entries']['entry']);
|
||||
|
||||
/* pr(compact('unreconciled')); */
|
||||
/* echo htmlspecialchars($xml->serialize($unreconciled)); */
|
||||
/* $this->render('/empty'); */
|
||||
/* return; */
|
||||
|
||||
$opts = array();
|
||||
//$opts['format'] = 'tags';
|
||||
echo $xml->header();
|
||||
echo $xml->serialize($unreconciled, $opts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,28 @@ class DoubleEntriesController extends AppController {
|
||||
'conditions' => array('DoubleEntry.id' => $id),
|
||||
));
|
||||
|
||||
$entry += $this->DoubleEntry->DebitEntry->Transaction->find
|
||||
('first',
|
||||
array('contain' => false,
|
||||
'conditions' => array('id' => $entry['DebitEntry']['transaction_id']),
|
||||
));
|
||||
|
||||
$entry += $this->DoubleEntry->DebitEntry->find
|
||||
('first',
|
||||
array('contain' => array('Ledger' => array('Account')),
|
||||
'conditions' => array('DebitEntry.id' => $entry['DebitEntry']['id']),
|
||||
));
|
||||
$entry['DebitLedger'] = $entry['Ledger'];
|
||||
unset($entry['Ledger']);
|
||||
|
||||
$entry += $this->DoubleEntry->CreditEntry->find
|
||||
('first',
|
||||
array('contain' => array('Ledger' => array('Account')),
|
||||
'conditions' => array('CreditEntry.id' => $entry['CreditEntry']['id']),
|
||||
));
|
||||
$entry['CreditLedger'] = $entry['Ledger'];
|
||||
unset($entry['Ledger']);
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Double Ledger Entry #{$entry['DoubleEntry']['id']}";
|
||||
$this->set(compact('entry', 'title'));
|
||||
|
||||
@@ -168,6 +168,9 @@ class LedgerEntriesController extends AppController {
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
|
||||
'DebitDoubleEntry' => array('id'),
|
||||
'CreditDoubleEntry' => array('id'),
|
||||
|
||||
'DebitEntry' => array('fields' => array('id', 'crdr')),
|
||||
'CreditEntry' => array('fields' => array('id', 'crdr')),
|
||||
),
|
||||
@@ -194,6 +197,11 @@ class LedgerEntriesController extends AppController {
|
||||
else
|
||||
$entry['MatchingEntry'] = $entry['DebitEntry'][0];
|
||||
|
||||
if (empty($entry['DebitDoubleEntry']['id']))
|
||||
$entry['DoubleEntry'] = $entry['CreditDoubleEntry'];
|
||||
else
|
||||
$entry['DoubleEntry'] = $entry['DebitDoubleEntry'];
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
|
||||
$this->set(compact('entry', 'title'));
|
||||
|
||||
@@ -118,12 +118,27 @@ class StatementEntriesController extends AppController {
|
||||
if (isset($account_id))
|
||||
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
||||
|
||||
if (isset($customer_id))
|
||||
$conditions[] = array('StatementEntry.customer_id' => $customer_id);
|
||||
|
||||
if (isset($statement_entry_id)) {
|
||||
$conditions[] = array('OR' =>
|
||||
array(array('ChargeEntry.id' => $statement_entry_id),
|
||||
array('DisbursementEntry.id' => $statement_entry_id)));
|
||||
}
|
||||
|
||||
if ($params['action'] === 'unreconciled') {
|
||||
$query = array('conditions' => $conditions);
|
||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, true);
|
||||
|
||||
$entries = array();
|
||||
foreach ($set['entries'] AS $entry)
|
||||
$entries[] = $entry['StatementEntry']['id'];
|
||||
|
||||
$conditions[] = array('StatementEntry.id' => $entries);
|
||||
$params['userdata']['balance'] = $set['summary']['balance'];
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
@@ -152,26 +167,26 @@ class StatementEntriesController extends AppController {
|
||||
}
|
||||
|
||||
function gridDataRecordsExecute(&$params, &$model, $query) {
|
||||
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(DisbursementEntry.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
" AS 'applied'",
|
||||
/* if ($params['action'] === '???') { */
|
||||
/* $tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1)); */
|
||||
/* $tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," . */
|
||||
/* " SUM(COALESCE(DisbursementEntry.amount,0))," . */
|
||||
/* " SUM(COALESCE(ChargeEntry.amount,0)))" . */
|
||||
/* " AS 'applied'", */
|
||||
|
||||
"StatementEntry.amount - (" .
|
||||
"IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(DisbursementEntry.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
") AS 'balance'",
|
||||
);
|
||||
/* "StatementEntry.amount - (" . */
|
||||
/* "IF(StatementEntry.type = 'CHARGE'," . */
|
||||
/* " SUM(COALESCE(DisbursementEntry.amount,0))," . */
|
||||
/* " SUM(COALESCE(ChargeEntry.amount,0)))" . */
|
||||
/* ") AS 'balance'", */
|
||||
/* ); */
|
||||
|
||||
//pr(compact('tquery'));
|
||||
$total = $model->find('first', $tquery);
|
||||
$params['userdata']['total'] = $total[0]['applied'];
|
||||
$params['userdata']['balance'] = $total[0]['balance'];
|
||||
}
|
||||
else {
|
||||
/* //pr(compact('tquery')); */
|
||||
/* $total = $model->find('first', $tquery); */
|
||||
/* $params['userdata']['total'] = $total[0]['applied']; */
|
||||
/* $params['userdata']['balance'] = $total[0]['balance']; */
|
||||
/* } */
|
||||
if ($params['action'] === 'collected') {
|
||||
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
|
||||
$tquery['fields'] = array("SUM(COALESCE(StatementEntry.amount,0)) AS 'total'");
|
||||
$total = $model->find('first', $tquery);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -388,15 +388,9 @@ class TransactionsController extends AppController {
|
||||
('first',
|
||||
array('contain' =>
|
||||
array(// Models
|
||||
'Account' =>
|
||||
array('fields' => array('Account.id',
|
||||
'Account.name'),
|
||||
),
|
||||
|
||||
'Ledger' =>
|
||||
array('fields' => array('Ledger.id',
|
||||
'Ledger.name'),
|
||||
),
|
||||
'Account(id,name)',
|
||||
'Ledger(id,name)',
|
||||
'NsfTender(id,name)',
|
||||
),
|
||||
'conditions' => array(array('Transaction.id' => $id),
|
||||
// REVISIT <AP>: 20090811
|
||||
@@ -407,6 +401,10 @@ class TransactionsController extends AppController {
|
||||
),
|
||||
));
|
||||
|
||||
// REVISIT <AP>: 20090815
|
||||
// for debug purposes only (pr output)
|
||||
$this->Transaction->stats($id);
|
||||
|
||||
if (empty($transaction)) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -139,7 +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(
|
||||
// REVISIT <AP>: 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'
|
||||
); }
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -223,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;
|
||||
}
|
||||
|
||||
@@ -345,6 +370,7 @@ class Account extends AppModel {
|
||||
$this->queryInit($query);
|
||||
$query['link'] = array('Account' => $query['link']);
|
||||
|
||||
$stats = array();
|
||||
foreach ($this->ledgers($id, $all) AS $ledger)
|
||||
$this->statsMerge($stats['Ledger'],
|
||||
$this->Ledger->stats($ledger, $query));
|
||||
|
||||
@@ -53,12 +53,27 @@ class DoubleEntry extends AppModel {
|
||||
*/
|
||||
|
||||
function addDoubleEntry($entry1, $entry2, $entry1_tender = null) {
|
||||
/* pr(array('DoubleEntry::addDoubleEntry' => */
|
||||
/* compact('entry1', 'entry2', 'entry1_tender'))); */
|
||||
$this->prFunctionLevel(16);
|
||||
$this->prEnter(compact('entry1', 'entry2', 'entry1_tender'));
|
||||
|
||||
$ret = array();
|
||||
if (!$this->verifyDoubleEntry($entry1, $entry2, $entry1_tender))
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
// Handle the case where a double entry involves the same
|
||||
// exact ledger. This would not serve any useful purpose.
|
||||
// It is not, however, an error. It is semantically correct
|
||||
// just not really logically correct. To make this easier,
|
||||
// just ensure ledger_id is set for each entry, even though
|
||||
// it would be handled later by the LedgerEntry model.
|
||||
//array($entry1, $entry2) AS &$entry) {
|
||||
for ($i=1; $i <= 2; ++$i) {
|
||||
if (empty(${'entry'.$i}['ledger_id']))
|
||||
${'entry'.$i}['ledger_id'] =
|
||||
$this->DebitEntry->Account->currentLedgerID(${'entry'.$i}['account_id']);
|
||||
}
|
||||
if ($entry1['ledger_id'] == $entry2['ledger_id'])
|
||||
return $this->prReturn(array('error' => false));
|
||||
|
||||
// Since this model only relates to DebitEntry and CreditEntry...
|
||||
$LE = new LedgerEntry();
|
||||
@@ -67,13 +82,13 @@ class DoubleEntry extends AppModel {
|
||||
$result = $LE->addLedgerEntry($entry1, $entry1_tender);
|
||||
$ret['Entry1'] = $result;
|
||||
if ($result['error'])
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
// Add the second ledger entry to the database
|
||||
$result = $LE->addLedgerEntry($entry2);
|
||||
$ret['Entry2'] = $result;
|
||||
if ($result['error'])
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
// Now link them as a double entry
|
||||
$double_entry = array();
|
||||
@@ -82,15 +97,13 @@ class DoubleEntry extends AppModel {
|
||||
$double_entry['credit_entry_id'] =
|
||||
($entry1['crdr'] === 'CREDIT') ? $ret['Entry1']['ledger_entry_id'] : $ret['Entry2']['ledger_entry_id'];
|
||||
|
||||
/* pr(array('DoubleEntry::addDoubleEntry' => */
|
||||
/* array('checkpoint' => 'Pre-Save') */
|
||||
/* + compact('double_entry'))); */
|
||||
$ret['data'] = $double_entry;
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($double_entry))
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
$ret['double_entry_id'] = $this->id;
|
||||
return $ret + array('error' => false);
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class LedgerEntry extends AppModel {
|
||||
),
|
||||
'DebitDoubleEntry' => array(
|
||||
'className' => 'DoubleEntry',
|
||||
'foreignKey' => 'credit_entry_id',
|
||||
'foreignKey' => 'debit_entry_id',
|
||||
'dependent' => true,
|
||||
),
|
||||
'CreditDoubleEntry' => array(
|
||||
@@ -127,24 +127,20 @@ class LedgerEntry extends AppModel {
|
||||
* - Inserts new Ledger Entry into the database
|
||||
*/
|
||||
function addLedgerEntry($entry, $tender = null) {
|
||||
/* pr(array('LedgerEntry::addLedgerEntry' => */
|
||||
/* compact('entry', 'tender'))); */
|
||||
$this->prFunctionLevel(16);
|
||||
$this->prEnter(compact('entry', 'tender'));
|
||||
|
||||
$ret = array();
|
||||
$ret = array('data' => $entry);
|
||||
if (!$this->verifyLedgerEntry($entry, $tender))
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
if (empty($entry['ledger_id']))
|
||||
$entry['ledger_id'] =
|
||||
$this->Account->currentLedgerID($entry['account_id']);
|
||||
|
||||
/* pr(array('LedgerEntry::addLedgerEntry' => */
|
||||
/* array('checkpoint' => 'Pre-Save') */
|
||||
/* + compact('entry'))); */
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($entry))
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
$ret['ledger_entry_id'] = $this->id;
|
||||
|
||||
@@ -154,10 +150,10 @@ class LedgerEntry extends AppModel {
|
||||
$result = $this->Tender->addTender($tender);
|
||||
$ret['Tender'] = $result;
|
||||
if ($result['error'])
|
||||
return array('error' => true) + $ret;
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
}
|
||||
|
||||
return $ret + array('error' => false);
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class StatementEntry extends AppModel {
|
||||
);
|
||||
|
||||
var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
var $max_log_level = 19;
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -124,13 +125,10 @@ class StatementEntry extends AppModel {
|
||||
function addStatementEntry($entry) {
|
||||
$this->prEnter(compact('entry'));
|
||||
|
||||
$ret = array();
|
||||
$ret = array('data' => $entry);
|
||||
if (!$this->verifyStatementEntry($entry))
|
||||
return $this->prReturn(array('error' => true, 'verify_data' => $entry) + $ret);
|
||||
|
||||
$this->pr(20, array('checkpoint' => 'Pre-Save')
|
||||
+ compact('entry'));
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($entry))
|
||||
return $this->prReturn(array('error' => true, 'save_data' => $entry) + $ret);
|
||||
@@ -226,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);
|
||||
}
|
||||
@@ -258,7 +258,7 @@ class StatementEntry extends AppModel {
|
||||
}
|
||||
|
||||
function reconciledSet($set, $query = null, $unrec = false, $if_rec_include_partial = false) {
|
||||
//$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prEnter(compact('set', 'query', 'unrec', 'if_rec_include_partial'));
|
||||
$lquery = $this->reconciledSetQuery($set, $query);
|
||||
$result = $this->find('all', $lquery);
|
||||
@@ -395,14 +395,13 @@ class StatementEntry extends AppModel {
|
||||
"Credits Established");
|
||||
}
|
||||
else {
|
||||
// Next, establish credit from the newly added receipt
|
||||
// Establish credit from the (newly added) receipt
|
||||
$lquery =
|
||||
array('link' =>
|
||||
array('StatementEntry',
|
||||
'LedgerEntry' =>
|
||||
array('conditions' =>
|
||||
array('LedgerEntry.account_id <> Transaction.account_id')
|
||||
//$this->Account->accountReceivableAccountID()),
|
||||
),
|
||||
),
|
||||
'conditions' => array('Transaction.id' => $receipt_id),
|
||||
@@ -413,8 +412,7 @@ class StatementEntry extends AppModel {
|
||||
$this->INTERNAL_ERROR("Unable to locate receipt.");
|
||||
|
||||
$stats = $this->Transaction->stats($receipt_id);
|
||||
$receipt_credit['balance'] =
|
||||
$receipt_credit['Transaction']['amount'] - $stats['StatementEntry']['disbursements'];
|
||||
$receipt_credit['balance'] = $stats['undisbursed'];
|
||||
|
||||
$receipt_credit['receipt'] = true;
|
||||
$credits = array($receipt_credit);
|
||||
@@ -455,21 +453,8 @@ class StatementEntry extends AppModel {
|
||||
if ($charge['balance'] < 0)
|
||||
$this->INTERNAL_ERROR("Negative Charge Balance");
|
||||
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
$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'];
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
$disbursement_date = $credit['Transaction']['stamp'];
|
||||
$disbursement_transaction_id = $credit['Transaction']['id'];
|
||||
$disbursement_account_id = $credit['LedgerEntry']['account_id'];
|
||||
}
|
||||
if (!isset($credit['balance']))
|
||||
$credit['balance'] = $credit['StatementEntry']['amount'];
|
||||
|
||||
if (empty($credit['balance']))
|
||||
continue;
|
||||
@@ -479,6 +464,11 @@ class StatementEntry extends AppModel {
|
||||
$this->pr(20, compact('charge'),
|
||||
'Attempt Charge Reconciliation');
|
||||
|
||||
if (empty($credit['receipt']))
|
||||
$disbursement_account_id = $credit['StatementEntry']['account_id'];
|
||||
else
|
||||
$disbursement_account_id = $credit['LedgerEntry']['account_id'];
|
||||
|
||||
// REVISIT <AP>: 20090811
|
||||
// Need to come up with a better strategy for handling
|
||||
// concessions. For now, just restricting concessions
|
||||
@@ -501,25 +491,65 @@ class StatementEntry extends AppModel {
|
||||
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
|
||||
(empty($credit['receipt']) ? ' Credit' : ' Receipt'));
|
||||
|
||||
// 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,
|
||||
);
|
||||
if (strtotime($charge['StatementEntry']['effective_date']) >
|
||||
strtotime($credit['StatementEntry']['effective_date']))
|
||||
$disbursement_edate = $charge['StatementEntry']['effective_date'];
|
||||
else
|
||||
$disbursement_edate = $credit['StatementEntry']['effective_date'];
|
||||
|
||||
$this->pr(20, compact('disbursement'),
|
||||
'New Disbursement Entry');
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
$result = $this->Transaction->addTransactionEntries
|
||||
(array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => true),
|
||||
array('type' => 'INVOICE',
|
||||
'id' => $credit['StatementEntry']['transaction_id'],
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'crdr' => 'CREDIT',
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
),
|
||||
array
|
||||
(array('type' => $disbursement_type,
|
||||
'effective_date' => $disbursement_edate,
|
||||
'account_id' => $credit['StatementEntry']['account_id'],
|
||||
'amount' => $disbursement_amount,
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
),
|
||||
));
|
||||
|
||||
$result = $this->addStatementEntry($disbursement);
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
|
||||
if (strtotime($charge['StatementEntry']['effective_date']) >
|
||||
strtotime($credit['Transaction']['stamp']))
|
||||
$disbursement_edate = $charge['StatementEntry']['effective_date'];
|
||||
else
|
||||
$disbursement_edate = $credit['Transaction']['stamp'];
|
||||
|
||||
// Add a disbursement that uses the available credit to pay the charge
|
||||
$disbursement =
|
||||
array('type' => $disbursement_type,
|
||||
'effective_date' => $disbursement_edate,
|
||||
'amount' => $disbursement_amount,
|
||||
'account_id' => $credit['LedgerEntry']['account_id'],
|
||||
'transaction_id' => $credit['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('disbursement'), 'New Disbursement Entry');
|
||||
$result = $this->addStatementEntry($disbursement);
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
// Adjust the charge balance to reflect the new disbursement
|
||||
$charge['balance'] -= $disbursement_amount;
|
||||
@@ -538,65 +568,72 @@ class StatementEntry extends AppModel {
|
||||
|
||||
// Clean up any explicit credits that have been used
|
||||
foreach ($credits AS $credit) {
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
if (empty($credit['applied']))
|
||||
continue;
|
||||
if (!empty($credit['receipt']))
|
||||
continue;
|
||||
|
||||
if ($credit['balance'] > 0) {
|
||||
$this->pr(20, compact('credit'),
|
||||
'Update Credit Entry');
|
||||
if (empty($credit['applied']))
|
||||
continue;
|
||||
|
||||
$this->id = $credit['StatementEntry']['id'];
|
||||
$this->saveField('amount', $credit['balance']);
|
||||
}
|
||||
else {
|
||||
$this->pr(20, compact('credit'),
|
||||
'Delete Exhausted Credit Entry');
|
||||
if ($credit['balance'] > 0) {
|
||||
$this->pr(20, compact('credit'),
|
||||
'Update Credit Entry');
|
||||
|
||||
$this->delete($credit['StatementEntry']['id'], false);
|
||||
}
|
||||
$this->id = $credit['StatementEntry']['id'];
|
||||
$this->saveField('amount', $credit['balance']);
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
if (empty($credit['balance']))
|
||||
continue;
|
||||
$this->pr(20, compact('credit'),
|
||||
'Delete Exhausted Credit Entry');
|
||||
|
||||
// Convert non-exhausted receipt credit to an explicit one
|
||||
$explicit_credit = $this->find
|
||||
('first', array('contain' => false,
|
||||
'conditions' =>
|
||||
array(array('transaction_id' => $credit['Transaction']['id']),
|
||||
array('type' => 'SURPLUS')),
|
||||
));
|
||||
|
||||
if (empty($explicit_credit)) {
|
||||
$this->pr(18, compact('credit'),
|
||||
'Create Explicit Credit');
|
||||
|
||||
$result = $this->addStatementEntry
|
||||
(array('type' => 'SURPLUS',
|
||||
'account_id' => $credit['LedgerEntry']['account_id'],
|
||||
'amount' => $credit['balance'],
|
||||
'effective_date' => $credit['Transaction']['stamp'],
|
||||
'transaction_id' => $credit['Transaction']['id'],
|
||||
'customer_id' => $customer_id,
|
||||
'lease_id' => $lease_id,
|
||||
));
|
||||
$ret['Credit'] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
else {
|
||||
$this->pr(18, compact('explicit_credit', 'credit'),
|
||||
'Update Explicit Credit');
|
||||
$EC = new StatementEntry();
|
||||
$EC->id = $explicit_credit['StatementEntry']['id'];
|
||||
$EC->saveField('amount', $credit['balance']);
|
||||
}
|
||||
$this->delete($credit['StatementEntry']['id'], false);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for any implicit receipt credits, converting
|
||||
// into explicit credits if there is a remaining balance.
|
||||
foreach ($credits AS $credit) {
|
||||
if (empty($credit['receipt']))
|
||||
continue;
|
||||
|
||||
if (empty($credit['balance']))
|
||||
continue;
|
||||
|
||||
// See if there is an existing explicit credit
|
||||
// for this transaction.
|
||||
$explicit_credit = $this->find
|
||||
('first', array('contain' => false,
|
||||
'conditions' =>
|
||||
array(array('transaction_id' => $credit['Transaction']['id']),
|
||||
array('type' => 'SURPLUS')),
|
||||
));
|
||||
|
||||
if (!empty($explicit_credit)) {
|
||||
// REVISIT <AP>: 20090815
|
||||
// Testing whether or not this case occurs
|
||||
$this->INTERNAL_ERROR('Existing explicit credit unexpected');
|
||||
|
||||
// Since there IS an existing explicit credit, we must update
|
||||
// its balance instead of creating a new one, since it has
|
||||
// already been incorporated in the overall credit balance.
|
||||
// If we were to create a new one, we would erroneously create
|
||||
// an excess of credit available.
|
||||
$this->pr(18, compact('explicit_credit', 'credit'),
|
||||
'Update existing explicit credit');
|
||||
$EC = new StatementEntry();
|
||||
$EC->id = $explicit_credit['StatementEntry']['id'];
|
||||
$EC->saveField('amount', $credit['balance']);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($ret['receipt_balance']))
|
||||
$this->INTERNAL_ERROR('Only one receipt expected in assignCredits');
|
||||
|
||||
// Give caller the information necessary to create an explicit
|
||||
// credit from the passed receipt, which we've not exhausted.
|
||||
$this->pr(18, compact('credit'), 'Convert to explicit credit');
|
||||
$ret['receipt_balance'] = $credit['balance'];
|
||||
}
|
||||
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
|
||||
@@ -608,7 +645,7 @@ class StatementEntry extends AppModel {
|
||||
* - Returns summary data from the requested statement entry
|
||||
*/
|
||||
function stats($id = null, $query = null) {
|
||||
//$this->prFunctionLevel(array('log' => 19, 'show' => 10));
|
||||
$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prEnter(compact('id', 'query'));
|
||||
|
||||
$this->queryInit($query);
|
||||
|
||||
@@ -101,7 +101,7 @@ class Tender extends AppModel {
|
||||
function addTender($tender) {
|
||||
$this->prEnter(compact('tender'));
|
||||
|
||||
$ret = array();
|
||||
$ret = array('data' => $tender);
|
||||
if (!$this->verifyTender($tender))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
|
||||
@@ -7,6 +7,13 @@ class Transaction extends AppModel {
|
||||
'Ledger',
|
||||
);
|
||||
|
||||
var $hasOne = array(
|
||||
'NsfTender' => array(
|
||||
'className' => 'Tender',
|
||||
'foreignKey' => 'nsf_transaction_id',
|
||||
),
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'LedgerEntry' => array(
|
||||
'dependent' => true,
|
||||
@@ -44,6 +51,7 @@ class Transaction extends AppModel {
|
||||
|
||||
|
||||
var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
//var $max_log_level = 10;
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -75,7 +83,6 @@ class Transaction extends AppModel {
|
||||
// Go through the statement entries and flag as charges
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'CHARGE',
|
||||
'crdr' => 'CREDIT',
|
||||
);
|
||||
|
||||
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
|
||||
@@ -117,7 +124,6 @@ class Transaction extends AppModel {
|
||||
// Go through the statement entries and flag as disbursements
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'DISBURSEMENT', // not used
|
||||
'crdr' => 'DEBIT',
|
||||
'account_id' =>
|
||||
(isset($entry['Tender']['tender_type_id'])
|
||||
? ($this->LedgerEntry->Tender->TenderType->
|
||||
@@ -237,7 +243,6 @@ class Transaction extends AppModel {
|
||||
if (!isset($group[$entry['account_id']]))
|
||||
$group[$entry['account_id']] =
|
||||
array('account_id' => $entry['account_id'],
|
||||
'crdr' => strtoupper($this->Account->fundamentalOpposite($data['Transaction']['crdr'])),
|
||||
'amount' => 0);
|
||||
$group[$entry['account_id']]['amount'] += $entry['amount'];
|
||||
}
|
||||
@@ -392,7 +397,6 @@ class Transaction extends AppModel {
|
||||
// Go through the statement entries and flag as payments
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'PAYMENT',
|
||||
'crdr' => 'CREDIT',
|
||||
);
|
||||
|
||||
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
|
||||
@@ -453,59 +457,203 @@ class Transaction extends AppModel {
|
||||
* entries, as layed out in the $data['Entry'] array. The array is
|
||||
* overloaded, since it is used to create both ledger _and_ statement
|
||||
* entries.
|
||||
*
|
||||
* $data
|
||||
* - Transaction
|
||||
* - [MANDATORY]
|
||||
* - type (INVOICE, RECEIPT)
|
||||
* - account_id
|
||||
* - crdr
|
||||
* - [OPTIONAL]
|
||||
* - stamp
|
||||
* (default: NOW)
|
||||
* - comment
|
||||
* - [AUTOMATICALLY SET] (if set, these items will be overwritten)
|
||||
* - id
|
||||
* - amount
|
||||
* - customer_id
|
||||
* - ledger_id
|
||||
*
|
||||
* - Entry (array)
|
||||
* - [MANDATORY]
|
||||
* - type (CHARGE, DISBURSEMENT)
|
||||
* - account_id
|
||||
* - crdr
|
||||
* - amount
|
||||
* - [OPTIONAL]
|
||||
* - effective_date
|
||||
* - through_date
|
||||
* - due_date
|
||||
* - comment (used for statement or ledger entry, based on context)
|
||||
* - ledger_entry_comment
|
||||
* - statement_entry_comment
|
||||
* - Tender
|
||||
* - [MANDATORY]
|
||||
* - tender_type_id
|
||||
* - [OPTIONAL]
|
||||
* - name
|
||||
* (default: Entry Account Name & data1)
|
||||
* - data1, data2, data3, data4
|
||||
* - comment
|
||||
* - [AUTOMATICALLY SET] (if set, these items will be overwritten)
|
||||
* - id
|
||||
* - ledger_entry_id
|
||||
* - deposit_transaction_id
|
||||
* - nsf_transaction_id
|
||||
* - [AUTOMATICALLY SET] (if set, these items will be overwritten)
|
||||
* - id
|
||||
* - transaction_id
|
||||
* - ledger_id
|
||||
*
|
||||
*/
|
||||
|
||||
function addTransaction($control, $transaction, $entries) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries'));
|
||||
|
||||
$result = $this->_splitEntries($control, $transaction, $entries);
|
||||
if (!empty($result['error']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// Make use of the work done by splitEntries
|
||||
$transaction = $this->filter_null($transaction) + $result['transaction'];
|
||||
$entries = $result['entries'];
|
||||
extract($result['vars']);
|
||||
|
||||
$this->pr(20, compact('transaction', 'entries'));
|
||||
|
||||
// Move forward, verifying and saving everything.
|
||||
$ret = array('data' => $transaction);
|
||||
if (!$this->verifyTransaction($transaction, $entries))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
// Save transaction to the database
|
||||
$this->create();
|
||||
if (!$this->save($transaction))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
$ret['transaction_id'] = $transaction['id'] = $this->id;
|
||||
|
||||
// Add the entries
|
||||
$ret += $this->addTransactionEntries($control, $transaction, $entries, false);
|
||||
|
||||
// If the caller requests 'assign'=>true, they really
|
||||
// want to do a credit assignment, and _then_ create
|
||||
// an explicit credit with any leftover. If an array
|
||||
// is specified, they get full control of the order.
|
||||
if (empty($control['assign']))
|
||||
$assign_ops = array();
|
||||
elseif (is_array($control['assign']))
|
||||
$assign_ops = $control['assign'];
|
||||
elseif (is_bool($control['assign']))
|
||||
$assign_ops = (empty($control['assign_receipt'])
|
||||
? array('assign')
|
||||
: array('assign', 'create'));
|
||||
else
|
||||
$this->INTERNAL_ERROR('Invalid control[assign] parameter');
|
||||
|
||||
$this->pr(17, compact('assign_ops'), 'Credit operations');
|
||||
|
||||
// Go through the requested assignment mechanisms
|
||||
foreach ($assign_ops AS $method) {
|
||||
if (!empty($ret['error']))
|
||||
break;
|
||||
|
||||
$this->pr(17, compact('method'), 'Handling credits');
|
||||
|
||||
if ($method === 'assign') {
|
||||
$result = $this->StatementEntry->assignCredits
|
||||
(null,
|
||||
(empty($control['assign_receipt']) ? null
|
||||
: $ret['transaction_id']),
|
||||
null,
|
||||
$assign_disbursement_type,
|
||||
$transaction['customer_id'],
|
||||
$transaction['lease_id']
|
||||
);
|
||||
}
|
||||
elseif ($method === 'create' || is_numeric($method)) {
|
||||
if (is_numeric($method))
|
||||
$credit_amount = $method;
|
||||
else {
|
||||
$stats = $this->stats($transaction['id']);
|
||||
$credit_amount = $stats['undisbursed'];
|
||||
}
|
||||
|
||||
if ($credit_amount < 0)
|
||||
$this->INTERNAL_ERROR('Receipt has negative undisbursed balance');
|
||||
|
||||
if (empty($credit_amount))
|
||||
continue;
|
||||
|
||||
$result = $this->addTransactionEntries
|
||||
(array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => true),
|
||||
array('crdr' => 'DEBIT') + $transaction,
|
||||
array(array('type' => 'SURPLUS',
|
||||
'account_id' => $this->Account->customerCreditAccountID(),
|
||||
'amount' => $credit_amount,
|
||||
),
|
||||
));
|
||||
}
|
||||
else
|
||||
$this->INTERNAL_ERROR('Invalid assign method');
|
||||
|
||||
$ret['credit'][$method] = $result;
|
||||
if (!empty($result['error']))
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
$this->Customer->update($transaction['customer_id']);
|
||||
return $this->prReturn($ret);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: addTransactionEntries
|
||||
* - Largely a helper function to addTransaction, this function is
|
||||
* responsible for adding ledger/statement entries to an existing
|
||||
* transaction. If needed, this function can also be called outside
|
||||
* of addTransaction, although it's not clear where that would be
|
||||
* appropriate, since transactions are really snapshots of some
|
||||
* event, and shouldn't be mucked with after creation.
|
||||
*/
|
||||
|
||||
function addTransactionEntries($control, $transaction, $entries, $split = true) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries', 'split'));
|
||||
|
||||
// Verify that we have a transaction
|
||||
if (empty($transaction['id']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// If the entries are not already split, do so now.
|
||||
if ($split) {
|
||||
$result = $this->_splitEntries($control, $transaction, $entries);
|
||||
if (!empty($result['error']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// Make use of the work done by splitEntries
|
||||
$transaction = $this->filter_null($transaction) + $result['transaction'];
|
||||
$entries = $result['entries'];
|
||||
extract($result['vars']);
|
||||
|
||||
/* // Verify the entries */
|
||||
/* $ret = array(); */
|
||||
/* if (!$this->verifyTransaction($transaction, $entries)) */
|
||||
/* return $this->prReturn(array('error' => true) + $ret); */
|
||||
}
|
||||
|
||||
$this->id = $transaction['id'];
|
||||
$transaction['stamp'] = $this->field('stamp');
|
||||
$transaction['customer_id'] = $this->field('customer_id');
|
||||
|
||||
// Set up our return array
|
||||
$ret = array();
|
||||
$ret['entries'] = array();
|
||||
$ret['error'] = false;
|
||||
|
||||
// Go through the entries
|
||||
foreach ($entries AS $e_index => &$entry) {
|
||||
// Ensure these items are null'ed out so we don't
|
||||
// accidentally pick up stale data.
|
||||
$le1 = $le1_tender = $le2 = $se = null;
|
||||
extract($entry);
|
||||
|
||||
if (!empty($le1) && !empty($le2)) {
|
||||
$le1['transaction_id'] = $le2['transaction_id'] = $transaction['id'];
|
||||
if (isset($le1_tender))
|
||||
$le1_tender['customer_id'] = $transaction['customer_id'];
|
||||
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
|
||||
$ret['entries'][$e_index]['DoubleEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
$ret['error'] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($se)) {
|
||||
$se['transaction_id'] = $transaction['id'];
|
||||
if (empty($se['effective_date']))
|
||||
$se['effective_date'] = $transaction['stamp'];
|
||||
$result = $this->StatementEntry->addStatementEntry($se);
|
||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
$ret['error'] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->prReturn($ret);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: _splitEntries
|
||||
* - An internal helper function capable of splitting an array of
|
||||
* combined ledger/statement entries into their indivdual entry
|
||||
* components (2 ledger entries, and a statement entry), based
|
||||
* on the typical requirements. Any custom split will have to
|
||||
* be done outside of this function.
|
||||
*/
|
||||
|
||||
function _splitEntries($control, $transaction, $entries) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries'));
|
||||
|
||||
// Verify that we have a transaction and entries
|
||||
if (empty($transaction) ||
|
||||
($transaction['type'] !== 'CLOSE' && empty($entries)))
|
||||
@@ -523,8 +671,18 @@ class Transaction extends AppModel {
|
||||
$transaction['customer_id'] = $L->field('customer_id');
|
||||
}
|
||||
|
||||
if (!empty($transaction['account_id'])) {
|
||||
if (empty($transaction['ledger_id']))
|
||||
$transaction['ledger_id'] =
|
||||
$this->Account->currentLedgerID($transaction['account_id']);
|
||||
|
||||
if (empty($transaction['crdr']))
|
||||
$transaction['crdr'] = strtoupper($this->Account->fundamentalType
|
||||
($transaction['account_id']));
|
||||
}
|
||||
|
||||
// Some transactions do not have their statement entries
|
||||
// generated from this function, but they are instead
|
||||
// generated directly as part of the transaction, but are
|
||||
// created in the final steps during the reconciliation
|
||||
// phase by the assignCredits function. Keep track of
|
||||
// what type the statement entries _would_ have been, so
|
||||
@@ -534,7 +692,7 @@ class Transaction extends AppModel {
|
||||
// Break each entry out of the combined statement/ledger entry
|
||||
// and into individual entries appropriate for saving. While
|
||||
// we're at it, calculate the transaction total as well.
|
||||
$transaction_amount = 0;
|
||||
$transaction['amount'] = 0;
|
||||
foreach ($entries AS &$entry) {
|
||||
// Ensure these items are null'ed out so we don't
|
||||
// accidentally pick up stale data.
|
||||
@@ -558,6 +716,10 @@ class Transaction extends AppModel {
|
||||
$entry['statement_entry_comment'] = null;
|
||||
}
|
||||
|
||||
if (empty($entry['crdr']) && !empty($transaction['crdr']))
|
||||
$entry['crdr'] = strtoupper($this->Account->fundamentalOpposite
|
||||
($transaction['crdr']));
|
||||
|
||||
// Priority goes to settings defined in $entry, but
|
||||
// use the control information as defaults.
|
||||
$entry += $control;
|
||||
@@ -576,7 +738,7 @@ class Transaction extends AppModel {
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('account_id', 'amount')));
|
||||
$le2['ledger_id'] = $entry['new_ledger_id'];
|
||||
$le2['crdr'] = strtoupper($this->Account->fundamentalOpposite($le1['crdr']));
|
||||
$le2['crdr'] = strtoupper($this->Account->fundamentalType($le2['account_id']));
|
||||
$le2['comment'] = "Ledger Balance Forward (b/f)";
|
||||
}
|
||||
else {
|
||||
@@ -586,6 +748,15 @@ class Transaction extends AppModel {
|
||||
array_intersect_key($transaction,
|
||||
array_flip(array('ledger_id', 'account_id', 'crdr')));
|
||||
}
|
||||
|
||||
if ($entry['amount'] < 0 && !empty($entry['force_positive'])) {
|
||||
$le1['amount'] *= -1;
|
||||
$le2['amount'] *= -1;
|
||||
$entry += array('swap_crdr' => true);
|
||||
}
|
||||
|
||||
if (!empty($entry['swap_crdr']))
|
||||
list($le1['crdr'], $le2['crdr']) = array($le2['crdr'], $le1['crdr']);
|
||||
}
|
||||
else
|
||||
$le1 = $le1_tender = $le2 = null;
|
||||
@@ -620,84 +791,15 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
// Add entry amount into the transaction total
|
||||
$transaction_amount += $entry['amount'];
|
||||
$transaction['amount'] += $entry['amount'];
|
||||
|
||||
// Replace combined entry with our new individual entries
|
||||
$entry = compact('le1', 'le1_tender', 'le2', 'se');
|
||||
}
|
||||
|
||||
// If transaction amount is not already set, use the
|
||||
// sum of the entry amounts.
|
||||
$transaction += array('amount' => $transaction_amount);
|
||||
|
||||
$this->pr(20, compact('transaction', 'entries'));
|
||||
|
||||
// Move forward, verifying and saving everything.
|
||||
$ret = array();
|
||||
if (!$this->verifyTransaction($transaction, $entries))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
// Save transaction to the database
|
||||
$this->create();
|
||||
if (!$this->save($transaction))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
$transaction_stamp = $this->field('stamp');
|
||||
|
||||
// Set up our return ids array
|
||||
$ret['transaction_id'] = $this->id;
|
||||
$ret['entries'] = array();
|
||||
$ret['error'] = false;
|
||||
|
||||
// Go through the entries
|
||||
foreach ($entries AS $e_index => &$entry) {
|
||||
// Ensure these items are null'ed out so we don't
|
||||
// accidentally pick up stale data.
|
||||
$le1 = $le1_tender = $le2 = $se = null;
|
||||
extract($entry);
|
||||
|
||||
if (!empty($le1) && !empty($le2)) {
|
||||
$le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id'];
|
||||
if (isset($le1_tender))
|
||||
$le1_tender['customer_id'] = $transaction['customer_id'];
|
||||
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
|
||||
$ret['entries'][$e_index]['DoubleEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
$ret['error'] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($se)) {
|
||||
$se['transaction_id'] = $ret['transaction_id'];
|
||||
if (empty($se['effective_date']))
|
||||
$se['effective_date'] = $transaction_stamp;
|
||||
$result = $this->StatementEntry->addStatementEntry($se);
|
||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
$ret['error'] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($control['assign']) && !$ret['error']) {
|
||||
$result = $this->StatementEntry->assignCredits
|
||||
(null,
|
||||
(empty($control['assign_receipt']) ? null
|
||||
: $ret['transaction_id']),
|
||||
null,
|
||||
$assign_disbursement_type,
|
||||
$transaction['customer_id'],
|
||||
$transaction['lease_id']
|
||||
);
|
||||
|
||||
$ret['assigned'] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
$this->Customer->update($transaction['customer_id']);
|
||||
return $this->prReturn($ret);
|
||||
return $this->prReturn(compact('transaction', 'entries')
|
||||
+ array('vars' => compact('assign_disbursement_type'))
|
||||
+ array('error' => false));
|
||||
}
|
||||
|
||||
|
||||
@@ -726,7 +828,6 @@ class Transaction extends AppModel {
|
||||
'Entry' =>
|
||||
array(array('tender_id' => null,
|
||||
'account_id' => $this->Account->nsfAccountID(),
|
||||
'crdr' => 'DEBIT',
|
||||
'amount' => $tender['LedgerEntry']['amount'],
|
||||
))),
|
||||
$tender['Transaction']['account_id']);
|
||||
@@ -807,7 +908,6 @@ class Transaction extends AppModel {
|
||||
'include_statement_entry' => false,
|
||||
'amount' => $rollback['Transaction']['amount'],
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'crdr' => 'DEBIT',
|
||||
);
|
||||
|
||||
// Set the transaction amount to be negative
|
||||
@@ -848,9 +948,28 @@ class Transaction extends AppModel {
|
||||
if ($charge_result['error'])
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
if (!empty($ret['rollback'])) {
|
||||
foreach ($ret['rollback']['entries'] AS $rentry) {
|
||||
if (!empty($rentry['DoubleEntry'])) {
|
||||
if (!empty($rentry['DoubleEntry']['error']))
|
||||
continue;
|
||||
|
||||
foreach (array('Entry1', 'Entry2') AS $n) {
|
||||
$entry = $rentry['DoubleEntry'][$n];
|
||||
if ($entry['data']['account_id'] == $this->Account->nsfAccountID()) {
|
||||
if (!empty($ret['nsf_ledger_entry_id']))
|
||||
$this->INTERNAL_ERROR("More than one NSF LE ID");
|
||||
|
||||
$ret['nsf_ledger_entry_id'] = $entry['ledger_entry_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($ret['rollback']['error']) && empty($ret['nsf_ledger_entry_id']))
|
||||
$this->INTERNAL_ERROR("NSF LE ID not found under rollback entries");
|
||||
|
||||
$ret['nsf_transaction_id'] = $ret['bounce']['transaction_id'];
|
||||
if (!empty($ret['rollback']))
|
||||
$ret['nsf_ledger_entry_id'] = $ret['rollback']['entries'][0]['DoubleEntry']['Entry1']['ledger_entry_id'];
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
|
||||
@@ -885,18 +1004,16 @@ class Transaction extends AppModel {
|
||||
// These are all disbursements against the charge we're reversing
|
||||
$rollback =
|
||||
array('control' =>
|
||||
array('assign' => true,
|
||||
'assign_receipt' => true,
|
||||
'include_ledger_entry' => false,
|
||||
array('include_ledger_entry' => false,
|
||||
'include_statement_entry' => true,
|
||||
),
|
||||
|
||||
'Transaction' =>
|
||||
array('stamp' => $stamp,
|
||||
'type' => 'CREDIT_NOTE',
|
||||
'crdr' => 'DEBIT',
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'amount' => $charge['StatementEntry']['amount'],
|
||||
'account_id' => $charge['StatementEntry']['account_id'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => null,
|
||||
'comment' => $comment,
|
||||
@@ -904,32 +1021,49 @@ class Transaction extends AppModel {
|
||||
|
||||
'Entry' => array());
|
||||
|
||||
foreach ($disb_entries['DisbursementEntry'] AS $disbursement) {
|
||||
$rollback['Entry'][] =
|
||||
array(
|
||||
'type' => $disbursement['type'],
|
||||
//'type' => 'REVERSAL',
|
||||
'amount' => -1 * $disbursement['amount'],
|
||||
'account_id' => $disbursement['account_id'],
|
||||
'customer_id' => $disbursement['customer_id'],
|
||||
'lease_id' => $disbursement['lease_id'],
|
||||
'charge_entry_id' => $disbursement['charge_entry_id'],
|
||||
);
|
||||
}
|
||||
|
||||
// Add the sole ledger entry for this transaction
|
||||
// Reverse the charge
|
||||
$rollback['Entry'][] =
|
||||
array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => true,
|
||||
'type' => 'REVERSAL',
|
||||
'crdr' => 'CREDIT',
|
||||
'amount' => $rollback['Transaction']['amount'],
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'account_id' => $charge['StatementEntry']['account_id'],
|
||||
'amount' => $charge['StatementEntry']['amount'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
);
|
||||
|
||||
$customer_credit = 0;
|
||||
foreach ($disb_entries['DisbursementEntry'] AS $disbursement) {
|
||||
$rollback['Entry'][] =
|
||||
array(
|
||||
'include_ledger_entry' =>
|
||||
($disbursement['type'] !== 'DISBURSEMENT'),
|
||||
|
||||
'force_positive' => true,
|
||||
'type' => $disbursement['type'],
|
||||
'amount' => -1 * $disbursement['amount'],
|
||||
'account_id' =>
|
||||
($disbursement['type'] === 'DISBURSEMENT'
|
||||
? $this->Account->customerCreditAccountID()
|
||||
: $disbursement['account_id']),
|
||||
'customer_id' => $disbursement['customer_id'],
|
||||
'lease_id' => $disbursement['lease_id'],
|
||||
'charge_entry_id' => $disbursement['charge_entry_id'],
|
||||
);
|
||||
|
||||
if ($disbursement['type'] === 'DISBURSEMENT')
|
||||
$customer_credit += $disbursement['amount'];
|
||||
}
|
||||
|
||||
// Create an explicit surplus entry for the customer credit.
|
||||
// Do it BEFORE assigning credits to outstanding charges to
|
||||
// ensure that those charges are paid from the customer surplus
|
||||
// account thus and we don't end up with bizarre disbursements,
|
||||
// like having Rent paid from Damage (or whatever account the
|
||||
// reversed charge came from).
|
||||
$rollback['control']['assign'] = array($customer_credit, 'assign');
|
||||
|
||||
// Record the transaction, which will un-disburse previously
|
||||
// disbursed payments, and other similar work.
|
||||
if (count($rollback['Entry'])) {
|
||||
@@ -1030,7 +1164,17 @@ class Transaction extends AppModel {
|
||||
if (empty($query['fields']))
|
||||
$query['fields'] = array();
|
||||
|
||||
$stats = array();
|
||||
// Get the overall total
|
||||
$squery = $query;
|
||||
$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) &&
|
||||
@@ -1069,6 +1213,11 @@ class Transaction extends AppModel {
|
||||
unset($stats[$table][0]);
|
||||
}
|
||||
|
||||
// Add summary data, which may or may not be useful
|
||||
// or even meaningful, depending on what the caller
|
||||
// has queried (it's up to them to make that decision).
|
||||
$stats['undisbursed'] = $stats['total'] - $stats['StatementEntry']['disbursements'];
|
||||
|
||||
return $this->prReturn($stats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ function updateEntriesGrid() {
|
||||
|
||||
$('#collected-total').html('Calculating...');
|
||||
$('#collected-entries-jqGrid').clearGridData();
|
||||
$('#collected-entries-jqGrid').setPostDataItem('dynamic_post', serialize(dynamic_post));
|
||||
$('#collected-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
||||
$('#collected-entries-jqGrid')
|
||||
.setGridParam({ page: 1 })
|
||||
.trigger("reloadGrid");
|
||||
@@ -166,11 +166,11 @@ echo $this->element('statement_entries', array
|
||||
'grid_div_class' => 'text-below',
|
||||
'grid_events' => array('loadComplete' => 'onGridLoadComplete()'),
|
||||
'grid_setup' => array('hiddengrid' => true),
|
||||
//'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
|
||||
'caption' => 'Collected ' . Inflector::pluralize($account['name']),
|
||||
'filter' => array(//'StatementEntry.type' => 'DISBURSEMENT',
|
||||
'ChargeEntry.account_id' => $account['id']),
|
||||
'exclude' => array('Account', 'Charge', 'Type'),
|
||||
'action' => 'collected',
|
||||
'filter' => array('ChargeEntry.account_id' => $account['id']),
|
||||
'include' => array('Amount'),
|
||||
'exclude' => array(/*'Type',*/ 'Debit', 'Credit'),
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
@@ -81,6 +81,33 @@ function resetForm() {
|
||||
updateCharges($("#customer-id").val());
|
||||
}
|
||||
|
||||
function updateCharges(id) {
|
||||
$('#charge-entries-jqGrid').clearGridData();
|
||||
$("#receipt-balance").html("Calculating...");
|
||||
$("#receipt-charges-caption").html("Please Wait...");
|
||||
|
||||
var custom = new Array();
|
||||
custom['customer_id'] = id;
|
||||
|
||||
var dynamic_post = new Array();
|
||||
dynamic_post['custom'] = custom;
|
||||
|
||||
$('#charge-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
||||
$('#charge-entries-jqGrid')
|
||||
.setGridParam({ page: 1 })
|
||||
.trigger("reloadGrid");
|
||||
|
||||
var gridstate = $('#charge-entries-jqGrid').getGridParam('gridstate');
|
||||
if (gridstate == 'hidden')
|
||||
$('#charge-entries .HeaderButton').click();
|
||||
}
|
||||
|
||||
function onGridLoadComplete() {
|
||||
var userdata = $('#charge-entries-jqGrid').getGridParam('userData');
|
||||
$('#receipt-balance').html(fmtCurrency(userdata['balance']));
|
||||
$("#receipt-charges-caption").html("Outstanding Charges");
|
||||
}
|
||||
|
||||
function onRowSelect(grid_id, customer_id) {
|
||||
// Set the customer id that will be returned with the form
|
||||
$("#customer-id").val(customer_id);
|
||||
@@ -217,52 +244,6 @@ function switchPaymentType(paymentid_base, paymentid, radioid) {
|
||||
$("#"+paymentid_base+"-"+paymentid+"-"+type_id).slideDown();
|
||||
}
|
||||
|
||||
function updateChargesGrid(idlist) {
|
||||
var dynamic_post = new Array();
|
||||
dynamic_post['idlist'] = idlist;
|
||||
|
||||
$('#charge-entries-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
||||
$('#charge-entries-jqGrid')
|
||||
.setGridParam({ page: 1 })
|
||||
.trigger("reloadGrid");
|
||||
|
||||
var gridstate = $('#charge-entries-jqGrid').getGridParam('gridstate');
|
||||
if (gridstate == 'hidden')
|
||||
$('#charge-entries .HeaderButton').click();
|
||||
}
|
||||
|
||||
function updateCharges(id) {
|
||||
var url = '<?php echo ($html->url(array("controller" => $this->params["controller"],
|
||||
"action" => "unreconciled"))); ?>';
|
||||
url += '/'+id;
|
||||
|
||||
$('#charge-entries-jqGrid').clearGridData();
|
||||
$("#receipt-balance").html("Calculating...");
|
||||
$("#receipt-charges-caption").html("Please Wait...");
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
dataType: "xml",
|
||||
success: function(xml) {
|
||||
var ids = new Array();
|
||||
$('entry',xml).each(function(i){
|
||||
ids.push($(this).attr('id'));
|
||||
});
|
||||
$('#receipt-balance').html(fmtCurrency($('entries',xml).attr('balance')));
|
||||
$("#receipt-charges-caption").html("Outstanding Charges");
|
||||
updateChargesGrid(ids);
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
/* alert('ERROR'); */
|
||||
/* $('#debug').html('<P>request<BR>'+escape(XMLHttpRequest)); */
|
||||
/* $('#debug').append('<P>status<BR>'+escape(textStatus)); */
|
||||
/* $('#debug').append('<P>error<BR>'+escape(errorThrown)); */
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
--></script>
|
||||
|
||||
<?php
|
||||
@@ -315,9 +296,10 @@ echo $this->element('statement_entries', array
|
||||
(
|
||||
'grid_div_id' => 'charge-entries',
|
||||
'grid_div_class' => 'text-below',
|
||||
'grid_events' => array('loadComplete' => 'onGridLoadComplete()'),
|
||||
'grid_setup' => array('hiddengrid' => true),
|
||||
'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
|
||||
'action' => 'idlist',
|
||||
'action' => 'unreconciled',
|
||||
'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
|
||||
'include' => array('Applied', 'Balance'),
|
||||
'remap' => array('Applied' => 'Paid'),
|
||||
|
||||
@@ -52,8 +52,6 @@ $ledgers = array('debit' => $entry['DebitLedger'],
|
||||
'credit' => $entry['CreditLedger']);
|
||||
$entries = array('debit' => $entry['DebitEntry'],
|
||||
'credit' => $entry['CreditEntry']);
|
||||
$customer = $entry['Customer'];
|
||||
$lease = $entry['Lease'];
|
||||
$entry = $entry['DoubleEntry'];
|
||||
|
||||
$rows = array();
|
||||
@@ -63,21 +61,7 @@ $rows[] = array('Transaction', $html->link('#'.$transaction['id'],
|
||||
'action' => 'view',
|
||||
$transaction['id'])));
|
||||
$rows[] = array('Timestamp', FormatHelper::datetime($transaction['stamp']));
|
||||
$rows[] = array('Effective', FormatHelper::date($entry['effective_date']));
|
||||
//$rows[] = array('Through', FormatHelper::date($entry['through_date']));
|
||||
$rows[] = array('Customer', (isset($customer['name'])
|
||||
? $html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id']))
|
||||
: null));
|
||||
$rows[] = array('Lease', (isset($lease['id'])
|
||||
? $html->link('#'.$lease['id'],
|
||||
array('controller' => 'leases',
|
||||
'action' => 'view',
|
||||
$lease['id']))
|
||||
: null));
|
||||
$rows[] = array('Comment', $entry['comment']);
|
||||
$rows[] = array('Comment', $entry['comment']);
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger-entry detail',
|
||||
@@ -132,8 +116,8 @@ foreach ($ledgers AS $type => $ledger) {
|
||||
array('controller' => 'ledgers',
|
||||
'action' => 'view',
|
||||
$ledger['id'])));
|
||||
$rows[] = array('Amount', FormatHelper::currency($entry['amount']));
|
||||
$rows[] = array('Effect', $ledger['Account']['ftype'] == $type ? 'INCREASE' : 'DECREASE');
|
||||
$rows[] = array('Amount', FormatHelper::currency($entries[$type]['amount']));
|
||||
//$rows[] = array('Effect', $ledger['Account']['ftype'] == $type ? 'INCREASE' : 'DECREASE');
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => array('item', $type, 'detail'),
|
||||
|
||||
@@ -14,6 +14,7 @@ $ledger = $entry['Ledger'];
|
||||
$account = $ledger['Account'];
|
||||
$tender = $entry['Tender'];
|
||||
$matching = $entry['MatchingEntry'];
|
||||
$double = $entry['DoubleEntry'];
|
||||
$entry = $entry['LedgerEntry'];
|
||||
|
||||
$rows = array();
|
||||
@@ -43,6 +44,10 @@ $rows[] = array('Cr/Dr', ($entry['crdr'] .
|
||||
'action' => 'view',
|
||||
$matching['id'])) .
|
||||
')'));
|
||||
$rows[] = array('Double Entry', $html->link('#'.$double['id'],
|
||||
array('controller' => 'double_entries',
|
||||
'action' => 'view',
|
||||
$double['id'])));
|
||||
$rows[] = array('Comment', $entry['comment']);
|
||||
|
||||
echo $this->element('table',
|
||||
|
||||
@@ -15,7 +15,7 @@ $customer = $entry['Customer'];
|
||||
$lease = $entry['Lease'];
|
||||
$entry = $entry['StatementEntry'];
|
||||
|
||||
$Ttype = ucfirst(strtolower($transaction['type']));
|
||||
$Ttype = ucwords(strtolower(str_replace('_', ' ', $transaction['type'])));
|
||||
|
||||
$rows = array();
|
||||
$rows[] = array('ID', $entry['id']);
|
||||
|
||||
@@ -11,13 +11,14 @@ echo '<div class="transaction view">' . "\n";
|
||||
|
||||
$account = $transaction['Account'];
|
||||
$ledger = $transaction['Ledger'];
|
||||
$nsf_tender = $transaction['NsfTender'];
|
||||
|
||||
if (isset($transaction['Transaction']))
|
||||
$transaction = $transaction['Transaction'];
|
||||
|
||||
$rows = array();
|
||||
$rows[] = array('ID', $transaction['id']);
|
||||
$rows[] = array('Type', $transaction['type']);
|
||||
$rows[] = array('Type', str_replace('_', ' ', $transaction['type']));
|
||||
$rows[] = array('Timestamp', FormatHelper::datetime($transaction['stamp']));
|
||||
$rows[] = array('Amount', FormatHelper::currency($transaction['amount']));
|
||||
$rows[] = array('Account', $html->link($account['name'],
|
||||
@@ -28,7 +29,11 @@ $rows[] = array('Ledger', $html->link($ledger['name'],
|
||||
array('controller' => 'ledgers',
|
||||
'action' => 'view',
|
||||
$ledger['id'])));
|
||||
$rows[] = array('Comment', $transaction['comment']);
|
||||
if (!empty($nsf_tender['id']))
|
||||
$rows[] = array('NSF Tender', $html->link($nsf_tender['name'],
|
||||
array('controller' => 'tenders',
|
||||
'action' => 'view',
|
||||
$nsf_tender['id'])));
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item transaction detail',
|
||||
@@ -79,7 +84,8 @@ if ($transaction['type'] === 'INVOICE' ||
|
||||
'caption' => 'Statement Entries',
|
||||
'filter' => array('Transaction.id' => $transaction['id'],
|
||||
'type !=' => 'VOID'),
|
||||
'exclude' => array('Transaction', 'Account'),
|
||||
'exclude' => array('Transaction', 'Debit', 'Credit'),
|
||||
'include' => array('Amount'),
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user