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@609 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-17 23:55:51 +00:00
parent 4b8dc3da02
commit d141f61055
5 changed files with 64 additions and 86 deletions

View File

@@ -878,7 +878,7 @@ INSERT INTO `pmgr_accounts` (`type`, `name`)
VALUES
('ASSET', 'A/R' ),
('LIABILITY', 'A/P' ),
('LIABILITY', 'Customer Credit' );
('LIABILITY', 'Credit' );
INSERT INTO `pmgr_accounts` (`type`, `name`, `receipts`)
VALUES
('ASSET', 'Cash', 1),
@@ -971,6 +971,7 @@ CREATE TABLE `pmgr_transactions` (
'CREDIT_NOTE', -- Inverse of Sales Invoice
'PAYMENT', -- Actual payment
'DEPOSIT',
'AUTO_DEPOSIT', -- Fundamentally same as DEPOSIT
'WITHDRAWAL',
'CLOSE', -- Essentially an internal (not accounting) transaction
-- 'CREDIT',
@@ -1227,6 +1228,8 @@ CREATE TABLE `pmgr_tenders` (
`ledger_entry_id` INT(10) UNSIGNED NOT NULL,
-- The ledger entry if this tender is marked NSF
`nsf_ledger_entry_id` INT(10) UNSIGNED DEFAULT NULL,
-- The ledger entry if this actual deposit transaction
`deposit_ledger_entry_id` INT(10) UNSIGNED DEFAULT NULL,
-- The deposit transaction that included these monies
`deposit_transaction_id` INT(10) UNSIGNED DEFAULT NULL,
-- The NSF transaction coming back from the bank.

View File

@@ -493,4 +493,19 @@ class TransactionsController extends AppController {
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);
}
}
}

View File

@@ -8,6 +8,9 @@ class Tender extends AppModel {
'DepositTransaction' => array(
'className' => 'Transaction',
),
'DepositLedgerEntry' => array(
'className' => 'LedgerEntry',
),
'NsfTransaction' => array(
'className' => 'Transaction',
'dependent' => true,
@@ -131,6 +134,7 @@ class Tender extends AppModel {
('contain' =>
array('LedgerEntry',
'DepositTransaction',
'DepositLedgerEntry',
'NsfTransaction'),
));
$this->pr(20, compact('tender'));

View File

@@ -159,6 +159,14 @@ class Transaction extends AppModel {
$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
('all', array('contain' => array('TenderType' => array('fields' => array()),
'LedgerEntry' => array('fields' => array()),
@@ -211,90 +219,20 @@ class Transaction extends AppModel {
if (!empty($deposit_ids['error']))
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
(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)
);
}
}
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,
'include_ledger_entry' => true,
'include_statement_entry' => false,
'update_tender' => true,
);
// 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
$group = array();
foreach ($data['Entry'] AS &$entry) {
$tender_groups = array();
foreach ($data['Entry'] AS $entry) {
if (!isset($group[$entry['account_id']]))
$group[$entry['account_id']] =
array('account_id' => $entry['account_id'],
'amount' => 0);
$group[$entry['account_id']]['amount'] += $entry['amount'];
$tender_groups[$entry['account_id']][] = $entry['tender_id'];
}
$data['Entry'] = $group;
@@ -409,11 +350,16 @@ class Transaction extends AppModel {
if (isset($ids['transaction_id']))
$ids['deposit_id'] = $ids['transaction_id'];
if (!empty($ids['deposit_id'])) {
$this->LedgerEntry->Tender->updateAll
(array('Tender.deposit_transaction_id' => $ids['deposit_id']),
array('Tender.id' => $tender_ids)
);
if (!empty($ids['deposit_id']) && !empty($control['update_tender'])) {
foreach ($tender_groups AS $group => $tender_ids) {
$entry_id = $ids['entries'][$group]['DoubleEntry']['Entry2']['ledger_entry_id'];
$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);
@@ -712,7 +658,9 @@ class Transaction extends AppModel {
$ret['error'] = true;
}
$this->Customer->update($transaction['customer_id']);
if (!empty($transaction['customer_id'])) {
$this->Customer->update($transaction['customer_id']);
}
return $this->prReturn($ret);
}
@@ -978,7 +926,13 @@ class Transaction extends AppModel {
// and recording it in the NSF account. It has nothing to do
// with the customer statement (charges, disbursements, credits, etc).
$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,
'type' => 'WITHDRAWAL',
'crdr' => 'CREDIT'),
@@ -988,7 +942,7 @@ class Transaction extends AppModel {
'account_id' => $this->Account->nsfAccountID(),
'amount' => $tender['LedgerEntry']['amount'],
))),
$tender['Transaction']['account_id']);
$tender['DepositLedgerEntry']['account_id']);
$this->pr(20, compact('bounce_result'));
$ret['bounce'] = $bounce_result;

View File

@@ -5,6 +5,8 @@ transaction.
Add NSF Fee to the NSF entry page (It's hardcoded right now
in Transaction to $35).
NSF of an item with customer credit is broken.
Sub-Total is broken, since it will only subtotal the current
page of the grid. It needs to be implemented in SQL as it
was in early (VERY early) implementations. At that time, I