Added logic to prevent a double entry where the credit and debit record in the exact same ledger. There is no known reason why we would need to record such an entry, even though it would not be incorrect to do so.
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@591 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -53,12 +53,27 @@ class DoubleEntry extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function addDoubleEntry($entry1, $entry2, $entry1_tender = null) {
|
function addDoubleEntry($entry1, $entry2, $entry1_tender = null) {
|
||||||
/* pr(array('DoubleEntry::addDoubleEntry' => */
|
$this->prFunctionLevel(16);
|
||||||
/* compact('entry1', 'entry2', 'entry1_tender'))); */
|
$this->prEnter(compact('entry1', 'entry2', 'entry1_tender'));
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if (!$this->verifyDoubleEntry($entry1, $entry2, $entry1_tender))
|
if (!$this->verifyDoubleEntry($entry1, $entry2, $entry1_tender))
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
|
// Handle the case where a double entry involves the same
|
||||||
|
// exact ledger. This would not serve any useful purpose.
|
||||||
|
// It is not, however, an error. It is semantically correct
|
||||||
|
// just not really logically correct. To make this easier,
|
||||||
|
// just ensure ledger_id is set for each entry, even though
|
||||||
|
// it would be handled later by the LedgerEntry model.
|
||||||
|
//array($entry1, $entry2) AS &$entry) {
|
||||||
|
for ($i=1; $i <= 2; ++$i) {
|
||||||
|
if (empty(${'entry'.$i}['ledger_id']))
|
||||||
|
${'entry'.$i}['ledger_id'] =
|
||||||
|
$this->DebitEntry->Account->currentLedgerID(${'entry'.$i}['account_id']);
|
||||||
|
}
|
||||||
|
if ($entry1['ledger_id'] == $entry2['ledger_id'])
|
||||||
|
return $this->prReturn(array('error' => false));
|
||||||
|
|
||||||
// Since this model only relates to DebitEntry and CreditEntry...
|
// Since this model only relates to DebitEntry and CreditEntry...
|
||||||
$LE = new LedgerEntry();
|
$LE = new LedgerEntry();
|
||||||
@@ -67,13 +82,13 @@ class DoubleEntry extends AppModel {
|
|||||||
$result = $LE->addLedgerEntry($entry1, $entry1_tender);
|
$result = $LE->addLedgerEntry($entry1, $entry1_tender);
|
||||||
$ret['Entry1'] = $result;
|
$ret['Entry1'] = $result;
|
||||||
if ($result['error'])
|
if ($result['error'])
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
// Add the second ledger entry to the database
|
// Add the second ledger entry to the database
|
||||||
$result = $LE->addLedgerEntry($entry2);
|
$result = $LE->addLedgerEntry($entry2);
|
||||||
$ret['Entry2'] = $result;
|
$ret['Entry2'] = $result;
|
||||||
if ($result['error'])
|
if ($result['error'])
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
// Now link them as a double entry
|
// Now link them as a double entry
|
||||||
$double_entry = array();
|
$double_entry = array();
|
||||||
@@ -86,9 +101,9 @@ class DoubleEntry extends AppModel {
|
|||||||
|
|
||||||
$this->create();
|
$this->create();
|
||||||
if (!$this->save($double_entry))
|
if (!$this->save($double_entry))
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
$ret['double_entry_id'] = $this->id;
|
$ret['double_entry_id'] = $this->id;
|
||||||
return $ret + array('error' => false);
|
return $this->prReturn($ret + array('error' => false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ class LedgerEntry extends AppModel {
|
|||||||
* - Inserts new Ledger Entry into the database
|
* - Inserts new Ledger Entry into the database
|
||||||
*/
|
*/
|
||||||
function addLedgerEntry($entry, $tender = null) {
|
function addLedgerEntry($entry, $tender = null) {
|
||||||
/* pr(array('LedgerEntry::addLedgerEntry' => */
|
$this->prFunctionLevel(16);
|
||||||
/* compact('entry', 'tender'))); */
|
$this->prEnter(compact('entry', 'tender'));
|
||||||
|
|
||||||
$ret = array('data' => $entry);
|
$ret = array('data' => $entry);
|
||||||
if (!$this->verifyLedgerEntry($entry, $tender))
|
if (!$this->verifyLedgerEntry($entry, $tender))
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
if (empty($entry['ledger_id']))
|
if (empty($entry['ledger_id']))
|
||||||
$entry['ledger_id'] =
|
$entry['ledger_id'] =
|
||||||
@@ -140,7 +140,7 @@ class LedgerEntry extends AppModel {
|
|||||||
|
|
||||||
$this->create();
|
$this->create();
|
||||||
if (!$this->save($entry))
|
if (!$this->save($entry))
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
|
||||||
$ret['ledger_entry_id'] = $this->id;
|
$ret['ledger_entry_id'] = $this->id;
|
||||||
|
|
||||||
@@ -150,10 +150,10 @@ class LedgerEntry extends AppModel {
|
|||||||
$result = $this->Tender->addTender($tender);
|
$result = $this->Tender->addTender($tender);
|
||||||
$ret['Tender'] = $result;
|
$ret['Tender'] = $result;
|
||||||
if ($result['error'])
|
if ($result['error'])
|
||||||
return array('error' => true) + $ret;
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret + array('error' => false);
|
return $this->prReturn($ret + array('error' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user