More tweaks to the addTransaction algorithm, working on a solid plan for customer surplus
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@574 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -258,7 +258,7 @@ class StatementEntry extends AppModel {
|
||||
}
|
||||
|
||||
function reconciledSet($set, $query = null, $unrec = false, $if_rec_include_partial = false) {
|
||||
//$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prEnter(compact('set', 'query', 'unrec', 'if_rec_include_partial'));
|
||||
$lquery = $this->reconciledSetQuery($set, $query);
|
||||
$result = $this->find('all', $lquery);
|
||||
@@ -395,7 +395,7 @@ class StatementEntry extends AppModel {
|
||||
"Credits Established");
|
||||
}
|
||||
else {
|
||||
// Next, establish credit from the newly added receipt
|
||||
// Establish credit from the (newly added) receipt
|
||||
$lquery =
|
||||
array('link' =>
|
||||
array('StatementEntry',
|
||||
@@ -455,21 +455,8 @@ class StatementEntry extends AppModel {
|
||||
if ($charge['balance'] < 0)
|
||||
$this->INTERNAL_ERROR("Negative Charge Balance");
|
||||
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
$disbursement_date = $credit['StatementEntry']['effective_date'];
|
||||
$disbursement_transaction_id = $credit['StatementEntry']['transaction_id'];
|
||||
$disbursement_account_id = $credit['StatementEntry']['account_id'];
|
||||
|
||||
if (!isset($credit['balance']))
|
||||
$credit['balance'] = $credit['StatementEntry']['amount'];
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
$disbursement_date = $credit['Transaction']['stamp'];
|
||||
$disbursement_transaction_id = $credit['Transaction']['id'];
|
||||
$disbursement_account_id = $credit['LedgerEntry']['account_id'];
|
||||
}
|
||||
if (!isset($credit['balance']))
|
||||
$credit['balance'] = $credit['StatementEntry']['amount'];
|
||||
|
||||
if (empty($credit['balance']))
|
||||
continue;
|
||||
@@ -479,6 +466,11 @@ class StatementEntry extends AppModel {
|
||||
$this->pr(20, compact('charge'),
|
||||
'Attempt Charge Reconciliation');
|
||||
|
||||
if (empty($credit['receipt']))
|
||||
$disbursement_account_id = $credit['StatementEntry']['account_id'];
|
||||
else
|
||||
$disbursement_account_id = $credit['LedgerEntry']['account_id'];
|
||||
|
||||
// REVISIT <AP>: 20090811
|
||||
// Need to come up with a better strategy for handling
|
||||
// concessions. For now, just restricting concessions
|
||||
@@ -501,25 +493,71 @@ class StatementEntry extends AppModel {
|
||||
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
|
||||
(empty($credit['receipt']) ? ' Credit' : ' Receipt'));
|
||||
|
||||
// Add a disbursement that uses the available credit to pay the charge
|
||||
$disbursement = array('type' => $disbursement_type,
|
||||
'account_id' => $disbursement_account_id,
|
||||
'amount' => $disbursement_amount,
|
||||
'effective_date' => $disbursement_date,
|
||||
'transaction_id' => $disbursement_transaction_id,
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
'comment' => null,
|
||||
);
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
$result = $this->Transaction->addTransactionEntries
|
||||
(array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => true),
|
||||
array('type' => 'INVOICE',
|
||||
'id' => $credit['StatementEntry']['transaction_id'],
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'crdr' => 'CREDIT',
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
),
|
||||
array
|
||||
(array('type' => $disbursement_type,
|
||||
//$credit['StatementEntry']['effective_date'];
|
||||
'effective_date' => $credit['StatementEntry']['effective_date'],
|
||||
'account_id' => $credit['StatementEntry']['account_id'],
|
||||
'amount' => $disbursement_amount,
|
||||
/* 'customer_id' => $charge['StatementEntry']['customer_id'], */
|
||||
/* 'lease_id' => $charge['StatementEntry']['lease_id'], */
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
),
|
||||
));
|
||||
/* $result = $this->Transaction->addReceipt */
|
||||
/* (array('control' => */
|
||||
/* array('include_ledger_entry' => true, */
|
||||
/* 'include_statement_entry' => false), */
|
||||
|
||||
$this->pr(20, compact('disbursement'),
|
||||
'New Disbursement Entry');
|
||||
/* 'Transaction' => */
|
||||
/* array('id' => $credit['StatementEntry']['transaction_id'], */
|
||||
/* 'account_id' => $credit['StatementEntry']['account_id'], */
|
||||
/* 'crdr' => 'DEBIT'), */
|
||||
/* array(array('type' => $disbursement_type, */
|
||||
/* //$credit['StatementEntry']['effective_date']; */
|
||||
/* 'effective_date' => $charge['StatementEntry']['effective_date'], */
|
||||
/* 'account_id' => $charge['StatementEntry']['account_id'], */
|
||||
/* 'amount' => $disbursement_amount, */
|
||||
/* ), */
|
||||
/* )); */
|
||||
|
||||
$result = $this->addStatementEntry($disbursement);
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
// Add a disbursement that uses the available credit to pay the charge
|
||||
$disbursement =
|
||||
array('type' => $disbursement_type,
|
||||
'amount' => $disbursement_amount,
|
||||
'account_id' => $credit['LedgerEntry']['account_id'],
|
||||
'effective_date' => $credit['Transaction']['stamp'],
|
||||
'transaction_id' => $credit['Transaction']['id'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
'comment' => null,
|
||||
);
|
||||
|
||||
$this->pr(20, compact('disbursement'), 'New Disbursement Entry');
|
||||
$result = $this->addStatementEntry($disbursement);
|
||||
$ret['Disbursement'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
// Adjust the charge balance to reflect the new disbursement
|
||||
$charge['balance'] -= $disbursement_amount;
|
||||
@@ -594,7 +632,7 @@ class StatementEntry extends AppModel {
|
||||
* - Returns summary data from the requested statement entry
|
||||
*/
|
||||
function stats($id = null, $query = null) {
|
||||
//$this->prFunctionLevel(array('log' => 19, 'show' => 10));
|
||||
$this->prFunctionLevel(array('log' => 16, 'show' => 10));
|
||||
$this->prEnter(compact('id', 'query'));
|
||||
|
||||
$this->queryInit($query);
|
||||
|
||||
Reference in New Issue
Block a user