Several changes in an effort to support charge reversals. I can't imagine this is all working flawlessly, as I'm not quite sure how it even _should_ work.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@490 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-05 07:54:57 +00:00
parent 5247bb8db6
commit cca698d437
6 changed files with 236 additions and 220 deletions

View File

@@ -139,6 +139,69 @@ class Transaction extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addReversal
* - Adds a new charge reversal
*/
function addReversal($data, $charge_id, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'charge_id', 'customer_id', 'lease_id'));
if (count($data['Entry']) != 1)
die("INTERNAL ERROR: Should be one Entry for addWaiver");
$data['Transaction']['type'] = 'CREDIT_NOTE';
$data['Transaction']['charge_entry_id'] = $charge_id;
//$data['Entry'][0]['amount'] *= -1;
//$data['Entry'][0]['type'] = 'DISBURSEMENT';
$ids = $this->addReceipt($data, $customer_id, $lease_id);
if (isset($ids['transaction_id']))
$ids['reversal_id'] = $ids['transaction_id'];
/* $new_charge_id = $ids['entries'][0]['StatementEntry']['statement_entry_id']; */
/* $this->StatementEntry->id = $new_charge_id; */
/* $this->StatementEntry->saveField('charge_entry_id', $charge_id); */
return $this->prReturn($ids);
// Just make sure the transaction is marked as an INVOICE
// and that it goes to cover the specific charge.
//$data['Transaction']['type'] = 'INVOICE';
$data['Transaction']['charge_entry_id'] = $charge_id;
// In all other respects this works just like a receipt.
$ids = $this->addReceipt($data, $customer_id, $lease_id);
if (isset($ids['transaction_id']))
$ids['reversal_id'] = $ids['transaction_id'];
return $this->prReturn($ids);
// Establish the transaction as an Invoice Reversal
$reversal =& $data['Transaction'];
$reversal +=
array('type' => 'INVOICE', //'CREDIT_NOTE',
'crdr' => 'CREDIT',
'account_id' => $this->Account->accountReceivableAccountID(),
'customer_id' => $customer_id,
'lease_id' => $lease_id,
);
// Go through the statement entries and flag as reversals
foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'CHARGE', //'REVERSAL',
'crdr' => 'DEBIT',
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['reversal_id'] = $ids['transaction_id'];
return $this->prReturn($ids);
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -251,49 +314,11 @@ 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);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addRefund
* - Adds a new refund transaction
* - Adds a new refund
*/
function addRefund($data, $customer_id, $lease_id = null) {
@@ -303,20 +328,21 @@ class Transaction extends AppModel {
// NOT IMPLEMENTED AT ALL. Just cut and paste so far
return array('error' => true);
// Establish the transaction as an refund
// Establish the transaction as a Refund
$refund =& $data['Transaction'];
$refund +=
array('type' => 'VOUCHER',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountReceivableAccountID(),
array('type' => 'CREDIT_NOTE',
'crdr' => 'CREDIT',
'account_id' => $this->Account->accountPayableAccountID(),
'customer_id' => $customer_id,
'lease_id' => $lease_id,
);
// Go through the statement entries and flag as charges
// Go through the statement entries and flag as vouchers
foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'CHARGE',
'crdr' => 'CREDIT',
$entry += array('type' => 'VOUCHER',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountReceivableAccountID(),
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
@@ -327,6 +353,44 @@ class Transaction extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addPayment
* - Adds a new payment transaction, which is money outflow
*/
function addPayment($data, $customer_id, $lease_id = null) {
$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 payment
$payment =& $data['Transaction'];
$payment +=
array('type' => 'PAYMENT',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountPayableAccountID(),
'customer_id' => $customer_id,
'lease_id' => $lease_id,
);
// Go through the statement entries and flag as payments
foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'PAYMENT',
'crdr' => 'CREDIT',
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['payment_id'] = $ids['transaction_id'];
return $this->prReturn($ids);
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -511,7 +575,9 @@ class Transaction extends AppModel {
// (DISBURSEMENTS will have statement entries created below, when
// assigning credits, and DEPOSITS don't have statement entries)
if ($transaction['type'] != 'INVOICE' && $subtype !== 'NSF')
if (($transaction['account_id'] != $this->Account->accountReceivableAccountID() &&
$transaction['account_id'] != $this->Account->nsfAccountID()) ||
$transaction['crdr'] != 'DEBIT')
$se = null;
// NSF transactions don't use LedgerEntries
@@ -588,15 +654,14 @@ class Transaction extends AppModel {
}
}
if (($transaction['type'] == 'INVOICE' ||
$transaction['type'] == 'RECEIPT') &&
$subtype !== 'NSF' && !$ret['error']) {
if ($transaction['account_id'] == $this->Account->accountReceivableAccountID()
&& !$ret['error']) {
$result = $this->StatementEntry->assignCredits
(null,
($transaction['type'] == 'RECEIPT'
($transaction['crdr'] == 'CREDIT'
? $ret['transaction_id']
: null),
($transaction['type'] == 'RECEIPT' && !empty($transaction['charge_entry_id'])
($transaction['crdr'] == 'CREDIT' && !empty($transaction['charge_entry_id'])
? $transaction['charge_entry_id']
: null),
(!empty($transaction['disbursement_type'])