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:
@@ -454,33 +454,14 @@ class Transaction extends AppModel {
|
||||
function addTransaction($control, $transaction, $entries) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries'));
|
||||
|
||||
// Verify that we have a transaction and entries
|
||||
if (empty($transaction) ||
|
||||
($transaction['type'] !== 'CLOSE' && empty($entries)))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// set ledger ID as the current ledger of the specified account
|
||||
if (empty($transaction['ledger_id']))
|
||||
$transaction['ledger_id'] =
|
||||
$this->Account->currentLedgerID($transaction['account_id']);
|
||||
|
||||
// Automatically figure out the customer if we have the lease
|
||||
if (!empty($transaction['lease_id']) && empty($transaction['customer_id'])) {
|
||||
$L = new Lease();
|
||||
$L->id = $transaction['lease_id'];
|
||||
$transaction['customer_id'] = $L->field('customer_id');
|
||||
}
|
||||
|
||||
$result = $this->_splitEntries($control, $transaction, $entries);
|
||||
if (!empty($result['error']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// Extract each item from result and make local variables
|
||||
extract($result);
|
||||
|
||||
// If transaction amount is not already set, use the
|
||||
// sum of the entry amounts.
|
||||
$transaction += array('amount' => $transaction_amount);
|
||||
// Make use of the work done by splitEntries
|
||||
$transaction = array_filter($transaction) + $result['transaction'];
|
||||
$entries = $result['entries'];
|
||||
extract($result['vars']);
|
||||
|
||||
$this->pr(20, compact('transaction', 'entries'));
|
||||
|
||||
@@ -525,6 +506,34 @@ class Transaction extends AppModel {
|
||||
'amount' => $result['receipt_balance'],
|
||||
),
|
||||
));
|
||||
|
||||
/* $result = $this->addInvoice */
|
||||
/* (array('control' => array('assign' => false), */
|
||||
/* 'Transaction' => */
|
||||
/* array_intersect_key($transaction, array('stamp'=>1)) */
|
||||
/* + array('type' => 'CREDIT_NOTE'), */
|
||||
/* 'Entry' => array */
|
||||
/* (array('type' => 'SURPLUS', */
|
||||
/* 'account_id' => $this->Account->accountPayableAccountID(), */
|
||||
/* 'amount' => $result['receipt_balance'], */
|
||||
/* ), */
|
||||
/* ), */
|
||||
/* ), */
|
||||
/* $transaction['customer_id'], */
|
||||
/* $transaction['lease_id'] */
|
||||
/* ); */
|
||||
|
||||
/* $result2 = $this->StatementEntry->assignCredits */
|
||||
/* (null, */
|
||||
/* $ret['transaction_id'], */
|
||||
/* null, */
|
||||
/* null, */
|
||||
/* $transaction['customer_id'], */
|
||||
/* $transaction['lease_id'] */
|
||||
/* ); */
|
||||
|
||||
/* if (!empty($result2['receipt_balance'])) */
|
||||
/* $this->INTERNAL_ERROR('Surplus invoice did not resolve receipt balance'); */
|
||||
}
|
||||
|
||||
}
|
||||
@@ -549,9 +558,8 @@ class Transaction extends AppModel {
|
||||
function addTransactionEntries($control, $transaction, $entries, $split = true) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries', 'split'));
|
||||
|
||||
// Verify that we have a transaction and entries
|
||||
if (empty($transaction['id']) ||
|
||||
($transaction['type'] !== 'CLOSE' && empty($entries)))
|
||||
// Verify that we have a transaction
|
||||
if (empty($transaction['id']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// If the entries are not already split, do so now.
|
||||
@@ -559,13 +567,17 @@ class Transaction extends AppModel {
|
||||
$result = $this->_splitEntries($control, $transaction, $entries);
|
||||
if (!empty($result['error']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
$entries = $result['entries'];
|
||||
}
|
||||
|
||||
/* // Verify the entries */
|
||||
/* $ret = array(); */
|
||||
/* if (!$this->verifyTransaction($transaction, $entries)) */
|
||||
/* return $this->prReturn(array('error' => true) + $ret); */
|
||||
// Make use of the work done by splitEntries
|
||||
$transaction = array_filter($transaction) + $result['transaction'];
|
||||
$entries = $result['entries'];
|
||||
extract($result['vars']);
|
||||
|
||||
/* // Verify the entries */
|
||||
/* $ret = array(); */
|
||||
/* if (!$this->verifyTransaction($transaction, $entries)) */
|
||||
/* return $this->prReturn(array('error' => true) + $ret); */
|
||||
}
|
||||
|
||||
$this->id = $transaction['id'];
|
||||
$transaction['stamp'] = $this->field('stamp');
|
||||
@@ -632,6 +644,28 @@ class Transaction extends AppModel {
|
||||
($transaction['type'] !== 'CLOSE' && empty($entries)))
|
||||
return $this->prReturn(array('error' => true));
|
||||
|
||||
// set ledger ID as the current ledger of the specified account
|
||||
if (empty($transaction['ledger_id']))
|
||||
$transaction['ledger_id'] =
|
||||
$this->Account->currentLedgerID($transaction['account_id']);
|
||||
|
||||
// Automatically figure out the customer if we have the lease
|
||||
if (!empty($transaction['lease_id']) && empty($transaction['customer_id'])) {
|
||||
$L = new Lease();
|
||||
$L->id = $transaction['lease_id'];
|
||||
$transaction['customer_id'] = $L->field('customer_id');
|
||||
}
|
||||
|
||||
if (!empty($transaction['account_id'])) {
|
||||
if (empty($transaction['ledger_id']))
|
||||
$transaction['ledger_id'] =
|
||||
$this->Account->currentLedgerID($transaction['account_id']);
|
||||
|
||||
if (empty($transaction['crdr']))
|
||||
$transaction['crdr'] = strtoupper($this->Account->fundamentalType
|
||||
($transaction['account_id']));
|
||||
}
|
||||
|
||||
// Some transactions do not have their statement entries
|
||||
// generated directly as part of the transaction, but are
|
||||
// created in the final steps during the reconciliation
|
||||
@@ -643,7 +677,7 @@ class Transaction extends AppModel {
|
||||
// Break each entry out of the combined statement/ledger entry
|
||||
// and into individual entries appropriate for saving. While
|
||||
// we're at it, calculate the transaction total as well.
|
||||
$transaction_amount = 0;
|
||||
$transaction['amount'] = 0;
|
||||
foreach ($entries AS &$entry) {
|
||||
// Ensure these items are null'ed out so we don't
|
||||
// accidentally pick up stale data.
|
||||
@@ -667,10 +701,6 @@ class Transaction extends AppModel {
|
||||
$entry['statement_entry_comment'] = null;
|
||||
}
|
||||
|
||||
if (empty($transaction['crdr']) && !empty($transaction['account_id']))
|
||||
$transaction['crdr'] = strtoupper($this->Account->fundamentalType
|
||||
($transaction['account_id']));
|
||||
|
||||
if (empty($entry['crdr']) && !empty($transaction['crdr']))
|
||||
$entry['crdr'] = strtoupper($this->Account->fundamentalOpposite
|
||||
($transaction['crdr']));
|
||||
@@ -737,15 +767,15 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
// Add entry amount into the transaction total
|
||||
$transaction_amount += $entry['amount'];
|
||||
$transaction['amount'] += $entry['amount'];
|
||||
|
||||
// Replace combined entry with our new individual entries
|
||||
$entry = compact('le1', 'le1_tender', 'le2', 'se');
|
||||
}
|
||||
|
||||
return $this->prReturn(compact('transaction_amount',
|
||||
'assign_disbursement_type',
|
||||
'entries') + array('error' => false));
|
||||
return $this->prReturn(compact('transaction', 'entries')
|
||||
+ array('vars' => compact('assign_disbursement_type'))
|
||||
+ array('error' => false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user