Added a column to Tender that identifies the exact ledger entry which was used to deposit the tender. It was necessary due to the kludgy way that I've set ACH items to auto-deposit, which uses a ledger entry that has nothing to do with the transaction account. This would probably allow us to eliminate the deposit_transaction_id, but I'd like to break as little as possible at the moment. I'll come back and clean this up in the future. Also, fixed a stupid bug that was causing major database thrash whenever a transaction was entered without a customer id. I could have fixed the Customer::update() function, but it was designed to accept null so that we could update all the customers, something definitely useful while developing.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@609 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -493,4 +493,19 @@ class TransactionsController extends AppController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function foo() {
|
||||||
|
$all_tenders = $this->Transaction->LedgerEntry->Tender->find
|
||||||
|
('all', array('link' => array('TenderType',
|
||||||
|
'LedgerEntry' =>
|
||||||
|
array('Transaction')),
|
||||||
|
'conditions' => array(array('TenderType.auto_deposit' => true),
|
||||||
|
array('Tender.deposit_transaction_id' => null)),
|
||||||
|
));
|
||||||
|
|
||||||
|
foreach ($all_tenders AS $cur_tender) {
|
||||||
|
$tender_ids = array($cur_tender['Tender']['id']);
|
||||||
|
$ids = array('transaction_id' => $cur_tender['Transaction']['id']);
|
||||||
|
$this->Transaction->_autoDeposit($tender_ids, $ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ class Tender extends AppModel {
|
|||||||
'DepositTransaction' => array(
|
'DepositTransaction' => array(
|
||||||
'className' => 'Transaction',
|
'className' => 'Transaction',
|
||||||
),
|
),
|
||||||
|
'DepositLedgerEntry' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
),
|
||||||
'NsfTransaction' => array(
|
'NsfTransaction' => array(
|
||||||
'className' => 'Transaction',
|
'className' => 'Transaction',
|
||||||
'dependent' => true,
|
'dependent' => true,
|
||||||
@@ -131,6 +134,7 @@ class Tender extends AppModel {
|
|||||||
('contain' =>
|
('contain' =>
|
||||||
array('LedgerEntry',
|
array('LedgerEntry',
|
||||||
'DepositTransaction',
|
'DepositTransaction',
|
||||||
|
'DepositLedgerEntry',
|
||||||
'NsfTransaction'),
|
'NsfTransaction'),
|
||||||
));
|
));
|
||||||
$this->pr(20, compact('tender'));
|
$this->pr(20, compact('tender'));
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ class Transaction extends AppModel {
|
|||||||
$tender_ids[] = $entry1['Tender']['tender_id'];
|
$tender_ids[] = $entry1['Tender']['tender_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ids = $this->_autoDeposit($tender_ids, $ids);
|
||||||
|
|
||||||
|
return $this->prReturn($ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090817
|
||||||
|
// Delete after rolling up the old items
|
||||||
|
function _autoDeposit($tender_ids, $ids) {
|
||||||
$deposit_tenders = $this->LedgerEntry->Tender->find
|
$deposit_tenders = $this->LedgerEntry->Tender->find
|
||||||
('all', array('contain' => array('TenderType' => array('fields' => array()),
|
('all', array('contain' => array('TenderType' => array('fields' => array()),
|
||||||
'LedgerEntry' => array('fields' => array()),
|
'LedgerEntry' => array('fields' => array()),
|
||||||
@@ -211,90 +219,20 @@ class Transaction extends AppModel {
|
|||||||
if (!empty($deposit_ids['error']))
|
if (!empty($deposit_ids['error']))
|
||||||
return $this->prReturn(array('error' => true) + $ids);
|
return $this->prReturn(array('error' => true) + $ids);
|
||||||
|
|
||||||
if (!empty($tender_ids))
|
if (!empty($tender_ids)) {
|
||||||
|
$entry_id = $deposit_ids['entries'][0]['DoubleEntry']['Entry2']['ledger_entry_id'];
|
||||||
|
$this->pr(10, compact('tender_ids', 'entry_id'));
|
||||||
$this->LedgerEntry->Tender->updateAll
|
$this->LedgerEntry->Tender->updateAll
|
||||||
(array('Tender.deposit_transaction_id' => $ids['transaction_id']),
|
(array('Tender.deposit_transaction_id' => $ids['transaction_id'],
|
||||||
|
'Tender.deposit_ledger_entry_id' => $entry_id),
|
||||||
array('Tender.id' => $tender_ids)
|
array('Tender.id' => $tender_ids)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->prReturn($ids);
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REVISIT <AP>: 20090817
|
|
||||||
// Delete after rolling up the old items
|
|
||||||
function temp_auto_deposit_old_ach_items() {
|
|
||||||
$all_tenders = $this->LedgerEntry->Tender->find
|
|
||||||
('all', array('link' => array('TenderType',
|
|
||||||
'LedgerEntry' =>
|
|
||||||
array('Transaction')),
|
|
||||||
'conditions' => array(array('TenderType.auto_deposit' => true),
|
|
||||||
array('Tender.deposit_transaction_id' => null)),
|
|
||||||
));
|
|
||||||
|
|
||||||
//$this->pr(10, compact('all_tenders'));
|
|
||||||
|
|
||||||
foreach ($all_tenders AS $cur_tender) {
|
|
||||||
$tender_ids = array($cur_tender['Tender']['id']);
|
|
||||||
$ids = array('transaction_id' => $cur_tender['Transaction']['id']);
|
|
||||||
|
|
||||||
$tenders = $this->LedgerEntry->Tender->find
|
|
||||||
('all', array('contain' => array('TenderType' => array('fields' => array()),
|
|
||||||
'LedgerEntry' => array('fields' => array()),
|
|
||||||
),
|
|
||||||
'fields' => array('TenderType.deposit_account_id',
|
|
||||||
'TenderType.account_id',
|
|
||||||
'CONCAT("CREDIT") AS crdr',
|
|
||||||
'CONCAT("Auto Deposit") AS comment',
|
|
||||||
'SUM(LedgerEntry.amount) AS amount'),
|
|
||||||
'conditions' => array('Tender.id' => $tender_ids,
|
|
||||||
'TenderType.auto_deposit' => true,
|
|
||||||
),
|
|
||||||
'group' => 'TenderType.deposit_account_id',
|
|
||||||
));
|
|
||||||
|
|
||||||
foreach ($tenders AS &$tender)
|
|
||||||
$tender = $tender[0] + array_diff_key($tender['TenderType'], array('id'=>1));
|
|
||||||
|
|
||||||
$this->pr(10, compact('tender_ids', 'tenders'));
|
|
||||||
|
|
||||||
// REVISIT <AP>: 20090817
|
|
||||||
// Multiple tenders could result in deposits to more than one
|
|
||||||
// account. We're already mucking with things by having a
|
|
||||||
// ledger entry that's not involved with the account_id of the
|
|
||||||
// transaction. We could handle this by not using the helper
|
|
||||||
// _splitEntries function, and just building or individual
|
|
||||||
// entries right here (which we should probably do anyway).
|
|
||||||
// However, I'm ignoring the issue for now...
|
|
||||||
if (count($tenders) > 1)
|
|
||||||
$this->INTERNAL_ERROR("Only expecting one tender type");
|
|
||||||
|
|
||||||
$deposit_ids = $this->addTransactionEntries
|
|
||||||
(array('include_ledger_entry' => true,
|
|
||||||
'include_statement_entry' => false,
|
|
||||||
),
|
|
||||||
|
|
||||||
array('id' => $ids['transaction_id'],
|
|
||||||
// REVISIT <AP>: 20090817
|
|
||||||
// This is an awful cheat, and we're going to
|
|
||||||
// get burned from it someday.
|
|
||||||
'type' => 'DEPOSIT',
|
|
||||||
'crdr' => 'DEBIT',
|
|
||||||
'account_id' => $tenders[0]['deposit_account_id'],
|
|
||||||
),
|
|
||||||
|
|
||||||
$tenders);
|
|
||||||
|
|
||||||
if (empty($deposit_ids['error'])) {
|
|
||||||
if (!empty($tender_ids))
|
|
||||||
$this->LedgerEntry->Tender->updateAll
|
|
||||||
(array('Tender.deposit_transaction_id' => $ids['transaction_id']),
|
|
||||||
array('Tender.id' => $tender_ids)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -378,6 +316,7 @@ class Transaction extends AppModel {
|
|||||||
array('assign' => false,
|
array('assign' => false,
|
||||||
'include_ledger_entry' => true,
|
'include_ledger_entry' => true,
|
||||||
'include_statement_entry' => false,
|
'include_statement_entry' => false,
|
||||||
|
'update_tender' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Establish the transaction as a deposit
|
// Establish the transaction as a deposit
|
||||||
@@ -396,12 +335,14 @@ class Transaction extends AppModel {
|
|||||||
|
|
||||||
// Go through the statement entries and re-group by account id
|
// Go through the statement entries and re-group by account id
|
||||||
$group = array();
|
$group = array();
|
||||||
foreach ($data['Entry'] AS &$entry) {
|
$tender_groups = array();
|
||||||
|
foreach ($data['Entry'] AS $entry) {
|
||||||
if (!isset($group[$entry['account_id']]))
|
if (!isset($group[$entry['account_id']]))
|
||||||
$group[$entry['account_id']] =
|
$group[$entry['account_id']] =
|
||||||
array('account_id' => $entry['account_id'],
|
array('account_id' => $entry['account_id'],
|
||||||
'amount' => 0);
|
'amount' => 0);
|
||||||
$group[$entry['account_id']]['amount'] += $entry['amount'];
|
$group[$entry['account_id']]['amount'] += $entry['amount'];
|
||||||
|
$tender_groups[$entry['account_id']][] = $entry['tender_id'];
|
||||||
}
|
}
|
||||||
$data['Entry'] = $group;
|
$data['Entry'] = $group;
|
||||||
|
|
||||||
@@ -409,11 +350,16 @@ class Transaction extends AppModel {
|
|||||||
if (isset($ids['transaction_id']))
|
if (isset($ids['transaction_id']))
|
||||||
$ids['deposit_id'] = $ids['transaction_id'];
|
$ids['deposit_id'] = $ids['transaction_id'];
|
||||||
|
|
||||||
if (!empty($ids['deposit_id'])) {
|
if (!empty($ids['deposit_id']) && !empty($control['update_tender'])) {
|
||||||
$this->LedgerEntry->Tender->updateAll
|
foreach ($tender_groups AS $group => $tender_ids) {
|
||||||
(array('Tender.deposit_transaction_id' => $ids['deposit_id']),
|
$entry_id = $ids['entries'][$group]['DoubleEntry']['Entry2']['ledger_entry_id'];
|
||||||
array('Tender.id' => $tender_ids)
|
$this->pr(10, compact('group', 'tender_ids', 'entry_id'));
|
||||||
);
|
$this->LedgerEntry->Tender->updateAll
|
||||||
|
(array('Tender.deposit_transaction_id' => $ids['deposit_id'],
|
||||||
|
'Tender.deposit_ledger_entry_id' => $entry_id),
|
||||||
|
array('Tender.id' => $tender_ids)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->prReturn($ids);
|
return $this->prReturn($ids);
|
||||||
@@ -712,7 +658,9 @@ class Transaction extends AppModel {
|
|||||||
$ret['error'] = true;
|
$ret['error'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Customer->update($transaction['customer_id']);
|
if (!empty($transaction['customer_id'])) {
|
||||||
|
$this->Customer->update($transaction['customer_id']);
|
||||||
|
}
|
||||||
return $this->prReturn($ret);
|
return $this->prReturn($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,7 +926,13 @@ class Transaction extends AppModel {
|
|||||||
// and recording it in the NSF account. It has nothing to do
|
// and recording it in the NSF account. It has nothing to do
|
||||||
// with the customer statement (charges, disbursements, credits, etc).
|
// with the customer statement (charges, disbursements, credits, etc).
|
||||||
$bounce_result = $this->addDeposit
|
$bounce_result = $this->addDeposit
|
||||||
(array('Transaction' =>
|
(array('control' =>
|
||||||
|
// This is not a "normal" deposit, so we don't
|
||||||
|
// want to update the tender deposit transaction id
|
||||||
|
// (it already has the correct one).
|
||||||
|
array('update_tender' => false),
|
||||||
|
|
||||||
|
'Transaction' =>
|
||||||
array('stamp' => $stamp,
|
array('stamp' => $stamp,
|
||||||
'type' => 'WITHDRAWAL',
|
'type' => 'WITHDRAWAL',
|
||||||
'crdr' => 'CREDIT'),
|
'crdr' => 'CREDIT'),
|
||||||
@@ -988,7 +942,7 @@ class Transaction extends AppModel {
|
|||||||
'account_id' => $this->Account->nsfAccountID(),
|
'account_id' => $this->Account->nsfAccountID(),
|
||||||
'amount' => $tender['LedgerEntry']['amount'],
|
'amount' => $tender['LedgerEntry']['amount'],
|
||||||
))),
|
))),
|
||||||
$tender['Transaction']['account_id']);
|
$tender['DepositLedgerEntry']['account_id']);
|
||||||
|
|
||||||
$this->pr(20, compact('bounce_result'));
|
$this->pr(20, compact('bounce_result'));
|
||||||
$ret['bounce'] = $bounce_result;
|
$ret['bounce'] = $bounce_result;
|
||||||
|
|||||||
Reference in New Issue
Block a user