Added support for deleting (destroying) a transaction. This is strictly development/super-admin type functionality.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@553 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-14 20:58:50 +00:00
parent c31c3a3cdc
commit e42c83c585
5 changed files with 151 additions and 38 deletions

View File

@@ -2,13 +2,19 @@
class Transaction extends AppModel {
var $belongsTo = array(
'Customer',
'Account',
'Ledger',
);
var $hasMany = array(
'LedgerEntry',
'StatementEntry',
'LedgerEntry' => array(
'dependent' => true,
),
'StatementEntry' => array(
'dependent' => true,
),
'DepositTender' => array(
'className' => 'Tender',
'foreignKey' => 'deposit_transaction_id',
@@ -525,25 +531,25 @@ class Transaction extends AppModel {
// Create one half of the Double Ledger Entry (and the Tender)
$le1 =
array_intersect_key($entry,
array_flip(array('ledger_id', 'account_id', 'crdr', 'amount')));
$le1['comment'] = $entry['ledger_entry_comment'];
$le1_tender = isset($entry['Tender']) ? $entry['Tender'] : null;
array_flip(array('ledger_id', 'account_id', 'crdr', 'amount')));
$le1['comment'] = $entry['ledger_entry_comment'];
$le1_tender = isset($entry['Tender']) ? $entry['Tender'] : null;
// Create the second half of the Double Ledger Entry
if ($transaction['type'] == 'CLOSE') {
$le2 =
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['comment'] = "Ledger Balance Forward (b/f)";
}
else {
$le2 =
array_intersect_key($entry,
array_flip(array('amount'))) +
array_intersect_key($transaction,
array_flip(array('ledger_id', 'account_id', 'crdr')));
// Create the second half of the Double Ledger Entry
if ($transaction['type'] == 'CLOSE') {
$le2 =
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['comment'] = "Ledger Balance Forward (b/f)";
}
else {
$le2 =
array_intersect_key($entry,
array_flip(array('amount'))) +
array_intersect_key($transaction,
array_flip(array('ledger_id', 'account_id', 'crdr')));
}
// Create the statement entry
@@ -795,6 +801,55 @@ class Transaction extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: destroy
* - Deletes a transaction and associated entries
* - !!WARNING!! This should be used with EXTREME caution, as it
* irreversibly destroys the data. It is not for normal use,
* and can leave the database in an inconsistent state. Expected
* scenario is to remove a bad transaction directly after creation,
* before it gets tied to anything else in the system (such as
* a late charge invoice for a customer that isn't actually late).
*/
function destroy($id) {
$this->prFunctionLevel(30);
$this->prEnter(compact('id'));
$this->id = $id;
$customer_id = $this->field('customer_id');
$result = $this->delete($id);
if (!empty($customer_id)) {
$this->StatementEntry->assignCredits
(null, null, null, null, $customer_id, null);
}
return $this->prReturn($result);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: update
* - Update any cached or calculated fields
*/
function update($id) {
INTERNAL_ERROR("Transaction::update not yet implemented");
$result = $this->find
('first',
array('link' => array('StatementEntry'),
'fields' => array("SUM(LedgerEntry.amount) AS total"),
'conditions' => array(array('LedgerEntry.account_id = Transaction.account_id'),
),
));
}
/**************************************************************************
**************************************************************************
**************************************************************************