array( 'className' => 'Transaction', ), 'NsfTransaction' => array( 'className' => 'Transaction', ), ); /************************************************************************** ************************************************************************** ************************************************************************** * function: verifyTender * - Verifies consistenty of new tender data * (not in a pre-existing tender) */ function verifyTender($tender) { $this->prFunctionLevel(10); $this->prEnter(compact('tender')); if (empty($tender['tender_type_id'])) { return $this->prReturn(false); } return $this->prReturn(true); } /************************************************************************** ************************************************************************** ************************************************************************** * function: addTender * - Inserts new Tender into the database */ function addTender($tender) { $this->prEnter(compact('tender')); $ret = array(); if (!$this->verifyTender($tender)) return $this->prReturn(array('error' => true) + $ret); // 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 : 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']; } } $this->pr(20, array('Tender' => $tender), 'Pre-Save'); $this->create(); if (!$this->save($tender)) return $this->prReturn(array('error' => true) + $ret); $ret['tender_id'] = $this->id; return $this->prReturn($ret + array('error' => false)); } /************************************************************************** ************************************************************************** ************************************************************************** * function: nsf * - Flags the ledger entry as having insufficient funds */ function nsf($id, $stamp = null, $comment = null) { $this->prEnter(compact('id', 'stamp', 'comment')); // Get information about this NSF item. $this->id = $id; $tender = $this->find ('first', array ('contain' => array('LedgerEntry', 'DepositTransaction', 'NsfTransaction'), )); $this->pr(20, compact('tender')); if (!empty($tender['NsfTransaction']['id'])) die("Item has already been set as NSF"); if (empty($tender['DepositTransaction']['id'])) die("Item has not been deposited yet"); $tender['Transaction'] = $tender['DepositTransaction']; unset($tender['DepositTransaction']); unset($tender['NsfTransaction']); $T = new Transaction(); $result = $T->addNsf($tender, $stamp, $comment); if (empty($result['error'])) { // Flag the tender as NSF, using the items created from addNsf $this->id = $id; $this->saveField('nsf_transaction_id', $result['nsf_transaction_id']); $this->saveField('nsf_ledger_entry_id', $result['nsf_ledger_entry_id']); } return $this->prReturn($result); } } ?>