Further tweaked the code to add new transactions, primarily by creating separate verification and addition functions in each underlying model. There are logic changes as well, such as adding in the other half of the missing double entry (as well as the double entry itself). This checkin also introduces the creation of CREDIT statement entries, when the customer has overpayed. It's working fairly well, although undoubtedly will need more tweaking.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@394 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-28 01:16:42 +00:00
parent 4adf0dd2fc
commit 24ccb56e50
6 changed files with 447 additions and 374 deletions

View File

@@ -13,43 +13,68 @@ class Tender extends AppModel {
);
/**************************************************************************
**************************************************************************
**************************************************************************
* function: verifyTender
* - Verifies consistenty of new tender data
* (not in a pre-existing tender)
*/
function verifyTender($tender) {
pr(array("Tender::verifyTender()"
=> compact('tender')));
if (empty($tender['tender_type_id'])) {
pr(array("Tender::verifyTender()"
=> "Tender verification failed"));
return false;
}
return true;
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addTender
* - Adds a new tender
* - Inserts new Tender into the database
*/
function addTender($data, $customer_id, $lease_id = null, $reconcile = null) {
// Create some models for convenience
$A = new Account();
function addTender($tender) {
pr(array('Tender::addTender' =>
compact('tender')));
// Assume this will succeed
$ret = true;
$ret = array();
if (!$this->verifyTender($tender))
return array('error' => true) + $ret;
// Establish the key tender parameters
$tender = array_intersect_key($data, array('stamp'=>1, 'type'=>1, 'name'=>1, 'amount'=>1,
'data1'=>1, 'data2'=>1, 'data3'=>1, 'data4'=>1));
$tender['customer_id'] = $customer_id;
// Come up with a (not necessarily unique) name for the tender.
// For checks & money orders, this will be based on the check
// number. For other types of tender, we'll just use the
// generic name of the monetary account.
// REVISIT <AP>: 20090723
// I would like to have cash named "Cash #1234", where
// the number would correspond to either the Tender ID
// or the LedgerEntry ID.
if (empty($tender['name']) && !empty($tender['account_id'])) {
$tender['name'] = $this->LedgerEntry->Account->name($tender['account_id']);
if ($tender['account_id'] == $this->LedgerEntry->Account->checkAccountID() ||
$tender['account_id'] == $this->LedgerEntry->Account->moneyOrderAccountID()) {
$tender['name'] .= ' #' . $tender['data1'];
}
}
// Create the tender entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a tender.
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
($tender,
array('debit_ledger_id' => $A->currentLedgerID($entry['account_id']),
'credit_ledger_id' => $A->currentLedgerID($A->tenderAccountID())
) + $entry,
array('debit' => 'tender',
'credit' => $reconcile)
);
if ($ids['error'])
$ret = false;
pr(array('Tender::addTender' =>
array('checkpoint' => 'Pre-Save')
+ array('Tender' => $tender)));
$tender = array_intersect_key($ids,
array('tender_id'=>1,
'split_tender_id'=>1));
return $ret;
$this->create();
if (!$this->save($tender))
return array('error' => true) + $ret;
$ret['tender_id'] = $this->id;
return $ret + array('error' => false);
}