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:
@@ -961,10 +961,15 @@ DROP TABLE IF EXISTS `pmgr_transactions`;
|
|||||||
CREATE TABLE `pmgr_transactions` (
|
CREATE TABLE `pmgr_transactions` (
|
||||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
|
||||||
`type` ENUM('INVOICE',
|
-- REVISIT <AP>: 20090804
|
||||||
'RECEIPT',
|
-- I'm not sure about most of these terms.
|
||||||
'VOUCHER',
|
-- Just as long as they're distinct though... I can rename them later
|
||||||
'DEPOSIT', -- Probably should use VOUCHER for DEPOSIT
|
`type` ENUM('INVOICE', -- Sales Invoice
|
||||||
|
'RECEIPT', -- Actual receipt of monies
|
||||||
|
'PURCHASE_INVOICE', -- Committment to pay
|
||||||
|
'CREDIT_NOTE', -- Inverse of Sales Invoice
|
||||||
|
'PAYMENT', -- Actual payment
|
||||||
|
'DEPOSIT',
|
||||||
'CLOSE', -- Essentially an internal (not accounting) transaction
|
'CLOSE', -- Essentially an internal (not accounting) transaction
|
||||||
-- 'CREDIT',
|
-- 'CREDIT',
|
||||||
-- 'REFUND',
|
-- 'REFUND',
|
||||||
@@ -1066,11 +1071,16 @@ DROP TABLE IF EXISTS `pmgr_statement_entries`;
|
|||||||
CREATE TABLE `pmgr_statement_entries` (
|
CREATE TABLE `pmgr_statement_entries` (
|
||||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
|
||||||
`type` ENUM('CHARGE',
|
-- REVISIT <AP>: 20090804
|
||||||
'DISBURSEMENT',
|
-- I'm not sure about most of these terms.
|
||||||
'VOUCHER-PAYMENT', -- REVISIT: Make PAYMENT
|
-- Just as long as they're distinct though... I can rename them later
|
||||||
'SURPLUS',
|
`type` ENUM('CHARGE', -- Invoiced Charge to Customer
|
||||||
'WAIVER',
|
'DISBURSEMENT', -- Disbursement of Receipt Funds
|
||||||
|
'REVERSAL', -- Reversal of a charge
|
||||||
|
'VOUCHER', -- Agreement to pay
|
||||||
|
'PAYMENT', -- Payment of a Voucher
|
||||||
|
'SURPLUS', -- Surplus Receipt Funds
|
||||||
|
'WAIVER', -- Waived Charge
|
||||||
-- REVISIT <AP>: 20090730
|
-- REVISIT <AP>: 20090730
|
||||||
-- VOID is used for handling NSF and perhaps charge reversals.
|
-- VOID is used for handling NSF and perhaps charge reversals.
|
||||||
-- It's not clear this is the best way to handle these things.
|
-- It's not clear this is the best way to handle these things.
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class StatementEntriesController extends AppController {
|
|||||||
|
|
||||||
function waive($id) {
|
function waive($id) {
|
||||||
$this->StatementEntry->waive($id);
|
$this->StatementEntry->waive($id);
|
||||||
//$this->redirect(array('action'=>'view', $id));
|
$this->redirect(array('action'=>'view', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -223,44 +223,6 @@ class StatementEntriesController extends AppController {
|
|||||||
|
|
||||||
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
||||||
|
|
||||||
|
|
||||||
/* // REVISIT <AP>: 20090711 */
|
|
||||||
/* // It's not clear whether we should be able to reverse charges that have */
|
|
||||||
/* // already been paid/cleared/reconciled. Certainly, that will be the */
|
|
||||||
/* // case when someone has pre-paid and then moves out early. However, this */
|
|
||||||
/* // will work well for items accidentally charged but not yet paid for. */
|
|
||||||
/* if ((!$entry['DebitLedger']['Account']['trackable'] || */
|
|
||||||
/* $stats['debit']['amount_reconciled'] == 0) && */
|
|
||||||
/* (!$entry['CreditLedger']['Account']['trackable'] || */
|
|
||||||
/* $stats['credit']['amount_reconciled'] == 0) */
|
|
||||||
|
|
||||||
/* && 0 */
|
|
||||||
|
|
||||||
/* ) */
|
|
||||||
/* { */
|
|
||||||
/* // Set up dynamic menu items */
|
|
||||||
/* $this->sidemenu_links[] = */
|
|
||||||
/* array('name' => 'Operations', 'header' => true); */
|
|
||||||
|
|
||||||
/* $this->sidemenu_links[] = */
|
|
||||||
/* array('name' => 'Undo', */
|
|
||||||
/* 'url' => array('action' => 'reverse', */
|
|
||||||
/* $id)); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* if ($this->StatementEntry->Ledger->Account->type */
|
|
||||||
/* ($entry['CreditLedger']['Account']['id']) == 'INCOME') */
|
|
||||||
/* { */
|
|
||||||
/* // Set up dynamic menu items */
|
|
||||||
/* $this->sidemenu_links[] = */
|
|
||||||
/* array('name' => 'Operations', 'header' => true); */
|
|
||||||
|
|
||||||
/* $this->sidemenu_links[] = */
|
|
||||||
/* array('name' => 'Reverse', */
|
|
||||||
/* 'url' => array('action' => 'reverse', */
|
|
||||||
/* $id)); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
$stats = $this->StatementEntry->stats($id);
|
$stats = $this->StatementEntry->stats($id);
|
||||||
|
|
||||||
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE')
|
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE')
|
||||||
@@ -269,16 +231,21 @@ class StatementEntriesController extends AppController {
|
|||||||
$stats = $stats['Disbursement'];
|
$stats = $stats['Disbursement'];
|
||||||
|
|
||||||
|
|
||||||
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE' &&
|
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE') {
|
||||||
$stats['balance'] > 0) {
|
|
||||||
// Set up dynamic menu items
|
// Set up dynamic menu items
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Operations', 'header' => true);
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Waive Balance',
|
array('name' => 'Reverse',
|
||||||
'url' => array('action' => 'waive',
|
'url' => array('action' => 'reverse',
|
||||||
$id));
|
$id));
|
||||||
|
|
||||||
|
if ($stats['balance'] > 0)
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Waive Balance',
|
||||||
|
'url' => array('action' => 'waive',
|
||||||
|
$id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare to render.
|
// Prepare to render.
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class StatementEntry extends AppModel {
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $default_log_level = array('log' => 30, 'show' => 15);
|
//var $default_log_level = array('log' => 30, 'show' => 15);
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -40,15 +40,12 @@ class StatementEntry extends AppModel {
|
|||||||
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
|
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
|
||||||
|
|
||||||
($sum ? 'SUM(' : '') .
|
($sum ? 'SUM(' : '') .
|
||||||
//"IF({$entry_name}.type IN('DISBURSEMENT', 'SURPLUS', 'WAIVER')," .
|
"IF({$entry_name}.type NOT IN('CHARGE', 'PAYMENT', 'VOID')," .
|
||||||
"IF({$entry_name}.type NOT IN('CHARGE', 'VOID')," .
|
|
||||||
" {$entry_name}.amount, NULL)" .
|
" {$entry_name}.amount, NULL)" .
|
||||||
($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''),
|
($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''),
|
||||||
|
|
||||||
($sum ? 'SUM(' : '') .
|
($sum ? 'SUM(' : '') .
|
||||||
//"IF({$entry_name}.type = 'CHARGE', 1," .
|
"IF({$entry_name}.type IN ('VOID', 'PAYMENT'), 0," .
|
||||||
//" IF({$entry_name}.type IN('DISBURSEMENT', 'SURPLUS', 'WAIVER'), -1, 0))" .
|
|
||||||
"IF({$entry_name}.type = 'VOID', 0," .
|
|
||||||
" IF({$entry_name}.type = 'CHARGE', 1, -1))" .
|
" IF({$entry_name}.type = 'CHARGE', 1, -1))" .
|
||||||
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
|
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
|
||||||
($sum ? ')' : '') . ' AS balance',
|
($sum ? ')' : '') . ' AS balance',
|
||||||
@@ -154,110 +151,80 @@ class StatementEntry extends AppModel {
|
|||||||
* function: reverse
|
* function: reverse
|
||||||
* - Reverses the charges
|
* - Reverses the charges
|
||||||
*
|
*
|
||||||
* SAMPLE MOVE IN w/ PRE DISBURSEMENT
|
|
||||||
* DEPOSIT RENT A/R RECEIPT CHECK PETTY BANK
|
|
||||||
* ------- ------- ------- ------- ------- ------- -------
|
|
||||||
* |25 | 25| | | | |
|
|
||||||
* | |20 20| | | | |
|
|
||||||
* | |20 20| | | | |
|
|
||||||
* | |20 20| | | | |
|
|
||||||
* | | |25 25| | | |
|
|
||||||
* | | |20 20| | | |
|
|
||||||
* | | |20 20| | | |
|
|
||||||
* | | |20 20| | | |
|
|
||||||
* | | | |85 85| | |
|
|
||||||
* | | | | |85 | 85|
|
|
||||||
|
|
||||||
* MOVE OUT and REFUND FINAL MONTH
|
|
||||||
* DEPOSIT RENT C/P RECEIPT CHECK PETTY BANK
|
|
||||||
* ------- ------- ------- ------- ------- ------- -------
|
|
||||||
* 25| | |25 | | | | t20 e20a
|
|
||||||
* | 20| |20 | | | | t20 e20b
|
|
||||||
|
|
||||||
* -ONE REFUND CHECK-
|
|
||||||
* | | 25| |25 | | | t30 e30a
|
|
||||||
* | | 20| |20 | | | t30 e30b
|
|
||||||
* | | | 45| | | |45 t40 e40
|
|
||||||
* -OR MULTIPLE-
|
|
||||||
* | | 15| |15 | | | t50a e50a
|
|
||||||
* | | | 15| | |15 | t60a e60a
|
|
||||||
* | | 30| |30 | | | t50b e50b
|
|
||||||
* | | | 30| | | |30 t60b e60b
|
|
||||||
* | | | | | | |
|
|
||||||
|
|
||||||
|
|
||||||
OPTION 1
|
|
||||||
* |-25 | -25| | | | |
|
|
||||||
* | |-20 -20| | | | |
|
|
||||||
* | | |-25 -25| | | |
|
|
||||||
* | | |-20 -20| | | |
|
|
||||||
|
|
||||||
OPTION 2
|
|
||||||
* |-25 | | -25| | | |
|
|
||||||
* | |-20 | -20| | | |
|
|
||||||
* | | | |-15 | -15| |
|
|
||||||
* | | | |-30 | | -30|
|
|
||||||
* | | | | | | |
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
function reverse($ledger_entries, $stamp = null) {
|
function reverse($id, $stamp = null) {
|
||||||
$this->prEnter(compact('ledger_entries', 'stamp'));
|
$this->prEnter(compact('id', 'stamp'));
|
||||||
|
|
||||||
// If the user only wants to reverse one ID, we'll allow it
|
$ret = array();
|
||||||
if (!is_array($ledger_entries))
|
|
||||||
$ledger_entries = $this->find
|
|
||||||
('all', array
|
|
||||||
('contain' => false,
|
|
||||||
'conditions' => array('Entry.id' => $ledger_entries)));
|
|
||||||
|
|
||||||
$A = new Account();
|
// Get the basic information about the entry to be reversed.
|
||||||
|
$this->recursive = -1;
|
||||||
|
$charge = $this->read(null, $id);
|
||||||
|
$charge = $charge['StatementEntry'];
|
||||||
|
|
||||||
$ar_account_id = $A->accountReceivableAccountID();
|
$voided_entry_transactions = array();
|
||||||
$receipt_account_id = $A->receiptAccountID();
|
$reconciled = $this->reconciledEntries($id);
|
||||||
|
$this->pr(21, compact('reconciled'));
|
||||||
|
|
||||||
$transaction_id = null;
|
if ($reconciled) {
|
||||||
foreach ($ledger_entries AS $entry) {
|
foreach ($reconciled['entries'] AS $entry) {
|
||||||
$entry = $entry['Entry'];
|
$voided_entry_transactions[$entry['DisbursementEntry']['transaction_id']]
|
||||||
$amount = -1*$entry['amount'];
|
= array_intersect_key($entry['DisbursementEntry'],
|
||||||
|
array('customer_id'=>1, 'lease_id'=>1));
|
||||||
|
|
||||||
if (isset($entry['credit_account_id']))
|
$this->del($entry['DisbursementEntry']['id']);
|
||||||
$refund_account_id = $entry['credit_account_id'];
|
continue;
|
||||||
elseif (isset($entry['CreditLedger']['Account']['id']))
|
|
||||||
$refund_account_id = $entry['CreditLedger']['Account']['id'];
|
|
||||||
elseif (isset($entry['credit_ledger_id']))
|
|
||||||
$refund_account_id = $this->Ledger->accountID($entry['credit_ledger_id']);
|
|
||||||
else
|
|
||||||
return $this->prReturn(null);
|
|
||||||
|
|
||||||
// post new refund in the income account
|
$DE = new StatementEntry();
|
||||||
$ids = $A->postEntry
|
$DE->id = $entry['DisbursementEntry']['id'];
|
||||||
(array('transaction_id' => $transaction_id),
|
$DE->saveField('type', 'VOID');
|
||||||
null,
|
$DE->saveField('charge_entry_id', null);
|
||||||
array('debit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
}
|
||||||
'credit_ledger_id' => $A->currentLedgerID($refund_account_id),
|
$this->pr(17, compact('voided_entry_transactions'));
|
||||||
'effective_date' => $entry['effective_date'],
|
|
||||||
'through_date' => $entry['through_date'],
|
|
||||||
'amount' => $amount,
|
|
||||||
'lease_id' => $entry['lease_id'],
|
|
||||||
'customer_id' => $entry['customer_id'],
|
|
||||||
'comment' => "Refund; Entry #{$entry['id']}",
|
|
||||||
),
|
|
||||||
array('debit' => array
|
|
||||||
(array('Entry' =>
|
|
||||||
array('id' => $entry['id'],
|
|
||||||
'amount' => $amount))),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($ids['error'])
|
|
||||||
return $this->prReturn(null);
|
|
||||||
$transaction_id = $ids['transaction_id'];
|
|
||||||
|
|
||||||
$this->pr(15, compact('ids', 'amount', 'refund_account_id', 'ar_account_id'),
|
|
||||||
'Posted Refund Ledger Entry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->prReturn(true);
|
// Query the stats to get the remaining balance
|
||||||
|
$stats = $this->stats($id);
|
||||||
|
|
||||||
|
// Build a transaction
|
||||||
|
$reversal = array('Transaction' => array(), 'Entry' => array());
|
||||||
|
$reversal['Transaction']['stamp'] = $stamp;
|
||||||
|
$reversal['Transaction']['comment'] = "Credit Note: Charge Reversal";
|
||||||
|
|
||||||
|
if ($charge['type'] !== 'CHARGE')
|
||||||
|
die("INTERNAL ERROR: REVERSAL ITEM IS NOT CHARGE");
|
||||||
|
|
||||||
|
// Add the charge reversal
|
||||||
|
$reversal['Entry'][] =
|
||||||
|
array('amount' => $stats['Charge']['total'],
|
||||||
|
'account_id' => $charge['account_id'],
|
||||||
|
'comment' => 'Charge Reversal',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Record the reversal transaction
|
||||||
|
$result = $this->Transaction->addReversal
|
||||||
|
($reversal, $id, $charge['customer_id'], $charge['lease_id']);
|
||||||
|
$this->pr(21, compact('result'));
|
||||||
|
$ret['reversal'] = $result;
|
||||||
|
if ($result['error'])
|
||||||
|
$ret['error'] = true;
|
||||||
|
|
||||||
|
foreach ($voided_entry_transactions AS $transaction_id => $tx) {
|
||||||
|
$result = $this->assignCredits
|
||||||
|
(null,
|
||||||
|
$transaction_id,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$tx['customer_id'],
|
||||||
|
$tx['lease_id']
|
||||||
|
);
|
||||||
|
$this->pr(21, compact('result'));
|
||||||
|
$ret['assigned'][] = $result;
|
||||||
|
if ($result['error'])
|
||||||
|
$ret['error'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->prReturn($ret + array('error' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -421,23 +388,27 @@ OPTION 2
|
|||||||
// Next, establish credit from the newly added receipt
|
// Next, establish credit from the newly added receipt
|
||||||
$receipt_credit = null;
|
$receipt_credit = null;
|
||||||
if (!empty($receipt_id)) {
|
if (!empty($receipt_id)) {
|
||||||
$lquery = $query;
|
$lquery =
|
||||||
$lquery['link'] = array('StatementEntry' => $lquery['link']);
|
array('link' =>
|
||||||
$lquery['link'] += array('LedgerEntry' =>
|
array('StatementEntry',
|
||||||
array('conditions' =>
|
'LedgerEntry' =>
|
||||||
//array(LedgerEntry.'crdr'=>'DEBIT'),
|
array('conditions' =>
|
||||||
array('LedgerEntry.account_id !=' => $this->Account->accountReceivableAccountID()),
|
array('LedgerEntry.account_id !=' =>
|
||||||
));
|
$this->Account->accountReceivableAccountID()),
|
||||||
$lquery['fields'] = array('Transaction.id', 'Transaction.stamp', 'Transaction.amount',
|
),
|
||||||
'LedgerEntry.account_id');
|
),
|
||||||
// Very specific case here... no extra conditions
|
'conditions' => array('Transaction.id' => $receipt_id),
|
||||||
unset($lquery['conditions']);
|
'fields' => array('Transaction.id', 'Transaction.stamp', 'Transaction.amount'),
|
||||||
$this->Transaction->id = $receipt_id;
|
);
|
||||||
$receipt_credit = $this->Transaction->find('first', $lquery);
|
$receipt_credit = $this->Transaction->find('first', $lquery);
|
||||||
if (!$receipt_credit)
|
if (!$receipt_credit)
|
||||||
die("INTERNAL ERROR: UNABLE TO LOCATE RECEIPT");
|
die("INTERNAL ERROR: UNABLE TO LOCATE RECEIPT");
|
||||||
|
|
||||||
$receipt_credit['balance'] = $receipt_credit['Transaction']['amount'];
|
//$reconciled = $this->reconciledEntries($id);
|
||||||
|
|
||||||
|
$stats = $this->Transaction->stats($receipt_id);
|
||||||
|
$receipt_credit['balance'] =
|
||||||
|
$receipt_credit['Transaction']['amount'] - $stats['Disbursement']['total'];
|
||||||
|
|
||||||
$this->pr(18, compact('receipt_credit'),
|
$this->pr(18, compact('receipt_credit'),
|
||||||
"Receipt Credit Added");
|
"Receipt Credit Added");
|
||||||
|
|||||||
@@ -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
|
* function: addRefund
|
||||||
* - Adds a new refund transaction
|
* - Adds a new refund
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function addRefund($data, $customer_id, $lease_id = null) {
|
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
|
// NOT IMPLEMENTED AT ALL. Just cut and paste so far
|
||||||
return array('error' => true);
|
return array('error' => true);
|
||||||
|
|
||||||
// Establish the transaction as an refund
|
// Establish the transaction as a Refund
|
||||||
$refund =& $data['Transaction'];
|
$refund =& $data['Transaction'];
|
||||||
$refund +=
|
$refund +=
|
||||||
array('type' => 'VOUCHER',
|
array('type' => 'CREDIT_NOTE',
|
||||||
'crdr' => 'DEBIT',
|
'crdr' => 'CREDIT',
|
||||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
'account_id' => $this->Account->accountPayableAccountID(),
|
||||||
'customer_id' => $customer_id,
|
'customer_id' => $customer_id,
|
||||||
'lease_id' => $lease_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)
|
foreach ($data['Entry'] AS &$entry)
|
||||||
$entry += array('type' => 'CHARGE',
|
$entry += array('type' => 'VOUCHER',
|
||||||
'crdr' => 'CREDIT',
|
'crdr' => 'DEBIT',
|
||||||
|
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
$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
|
// (DISBURSEMENTS will have statement entries created below, when
|
||||||
// assigning credits, and DEPOSITS don't have statement entries)
|
// 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;
|
$se = null;
|
||||||
|
|
||||||
// NSF transactions don't use LedgerEntries
|
// NSF transactions don't use LedgerEntries
|
||||||
@@ -588,15 +654,14 @@ class Transaction extends AppModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($transaction['type'] == 'INVOICE' ||
|
if ($transaction['account_id'] == $this->Account->accountReceivableAccountID()
|
||||||
$transaction['type'] == 'RECEIPT') &&
|
&& !$ret['error']) {
|
||||||
$subtype !== 'NSF' && !$ret['error']) {
|
|
||||||
$result = $this->StatementEntry->assignCredits
|
$result = $this->StatementEntry->assignCredits
|
||||||
(null,
|
(null,
|
||||||
($transaction['type'] == 'RECEIPT'
|
($transaction['crdr'] == 'CREDIT'
|
||||||
? $ret['transaction_id']
|
? $ret['transaction_id']
|
||||||
: null),
|
: null),
|
||||||
($transaction['type'] == 'RECEIPT' && !empty($transaction['charge_entry_id'])
|
($transaction['crdr'] == 'CREDIT' && !empty($transaction['charge_entry_id'])
|
||||||
? $transaction['charge_entry_id']
|
? $transaction['charge_entry_id']
|
||||||
: null),
|
: null),
|
||||||
(!empty($transaction['disbursement_type'])
|
(!empty($transaction['disbursement_type'])
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ $rows[] = array($Ttype, $html->link('#'.$transaction['id'],
|
|||||||
$transaction['id'])));
|
$transaction['id'])));
|
||||||
$rows[] = array('Timestamp', FormatHelper::datetime($transaction['stamp']));
|
$rows[] = array('Timestamp', FormatHelper::datetime($transaction['stamp']));
|
||||||
$rows[] = array('Effective', FormatHelper::date($entry['effective_date']));
|
$rows[] = array('Effective', FormatHelper::date($entry['effective_date']));
|
||||||
if (in_array($entry['type'], array('CHARGE', /*REVISIT 'VOUCHER-PAYMENT'*/)))
|
if (in_array($entry['type'], array('CHARGE', 'PAYMENT')))
|
||||||
$rows[] = array('Through', FormatHelper::date($entry['through_date']));
|
$rows[] = array('Through', FormatHelper::date($entry['through_date']));
|
||||||
$rows[] = array('Type', $entry['type']);
|
$rows[] = array('Type', $entry['type']);
|
||||||
$rows[] = array('Amount', FormatHelper::currency($entry['amount']));
|
$rows[] = array('Amount', FormatHelper::currency($entry['amount']));
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ echo '<div CLASS="detail supporting">' . "\n";
|
|||||||
* Statement Entries
|
* Statement Entries
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($transaction['type'] === 'INVOICE' || $transaction['type'] === 'RECEIPT') {
|
if ($transaction['type'] === 'INVOICE' ||
|
||||||
|
$transaction['type'] === 'RECEIPT' ||
|
||||||
|
$transaction['type'] === 'CREDIT_NOTE'
|
||||||
|
) {
|
||||||
echo $this->element('statement_entries', array
|
echo $this->element('statement_entries', array
|
||||||
(// Grid configuration
|
(// Grid configuration
|
||||||
'config' => array
|
'config' => array
|
||||||
|
|||||||
Reference in New Issue
Block a user