diff --git a/controllers/tenders_controller.php b/controllers/tenders_controller.php index 37c2717..3e2eb47 100644 --- a/controllers/tenders_controller.php +++ b/controllers/tenders_controller.php @@ -115,15 +115,33 @@ class TendersController extends AppController { */ function nsf($id = null) { + if ($this->data) { + $result = $this->Tender->nsf + ($this->data['Tender']['id'], + $this->data['Transaction']['stamp'], + $this->data['Transaction']['comment']); + $this->redirect(array('controller' => 'tenders', + 'action' => 'view', + $this->data['Tender']['id'])); + } + if (!$id) { $this->Session->setFlash(__('Invalid Item.', true)); $this->redirect(array('action'=>'index')); } - $this->Tender->nsf($id); - $this->redirect(array('action'=>'view', $id)); + $this->Tender->id = $id; + $tender = $this->Tender->find + ('first', array + ('contain' => array('Customer', 'LedgerEntry' => array('Transaction')), + )); + + // Prepare to render. + $title = "Tender #{$tender['Tender']['id']} : {$tender['Tender']['name']} : NSF"; + $this->set(compact('tender', 'title')); } + /************************************************************************** ************************************************************************** ************************************************************************** @@ -138,6 +156,7 @@ class TendersController extends AppController { } // Get the Tender and related fields + $this->Tender->id = $id; $tender = $this->Tender->find ('first', array ('contain' => array('TenderType', 'Customer', 'LedgerEntry' => array('Transaction')), @@ -161,7 +180,7 @@ class TendersController extends AppController { } // Prepare to render. - $title = "Tender #{$tender['Tender']['id']}"; + $title = "Tender #{$tender['Tender']['id']} : {$tender['Tender']['name']}"; $this->set(compact('tender', 'title')); } } diff --git a/models/tender.php b/models/tender.php index c27dcde..2a500e7 100644 --- a/models/tender.php +++ b/models/tender.php @@ -80,31 +80,10 @@ class Tender extends AppModel { ************************************************************************** * function: nsf * - Flags the ledger entry as having insufficient funds - * - * Steps: - * - Get information from Check (C1); for amount $A - * - Find Bank Deposit matching to Tender - * - New Transaction (T1) - * - New Bank Deposit (D1) - * - New Tender (N1); NSF; D1, - * - Add new LedgerEntry (L1a); T1; debit:bank; -$A - * - Add new LedgerEntry (L1b); T1; credit:NSF; -$A - * - Add new LedgerEntry (L2a); T1; debit:NSF; -$A; N1 - * - Add new LedgerEntry (L2b); T1; credit:A/R; -$A - * - For Tx associated with LE associated with C1: - * - For each Disbursement SE of Tx: - * - Add new StatementEntry (S1n); T1; DISBURSEMENT; -1*S1n.amount - * - New Transaction (T2) (?????) - * - Add new StatementEntry (S2); T2; CHARGE; NSF; $35 - * - Add new LedgerEntry (L3a); T2; credit:NSF-Fee; $35 - * - Add new LedgerEntry (L3b); T2; debit:A/R; $35 - * - Set C1.nsf_tx = T1 - * - Re-Reconcile (customer may have running credit) */ - function nsf($id, $stamp = null) { - $this->prFunctionLevel(30); - $this->prEnter(compact('id')); + function nsf($id, $stamp = null, $comment = null) { + $this->prEnter(compact('id', 'stamp', 'comment')); // Get information about this NSF item. $this->id = $id; @@ -128,16 +107,15 @@ class Tender extends AppModel { unset($tender['NsfTransaction']); $T = new Transaction(); - $result = $T->addNsf($tender, $stamp); - if ($result['error']) - return $this->prReturn(false); + $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']); + } - // 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(true); + return $this->prReturn($result); } diff --git a/models/transaction.php b/models/transaction.php index ffed796..33fc004 100644 --- a/models/transaction.php +++ b/models/transaction.php @@ -673,8 +673,8 @@ class Transaction extends AppModel { * - Adds NSF transaction */ - function addNsf($tender, $stamp) { - $this->prEnter(compact('tender', 'stamp')); + function addNsf($tender, $stamp = null, $comment = null) { + $this->prEnter(compact('tender', 'stamp', 'comment')); $ret = array(); @@ -683,7 +683,8 @@ class Transaction extends AppModel { // and recording it in the NSF account. It has nothing to do // with the customer statement (charges, disbursements, credits, etc). $bounce_result = $this->addDeposit - (array('Transaction' => array('crdr' => 'CREDIT'), + (array('Transaction' => array('stamp' => $stamp, + 'crdr' => 'CREDIT'), 'Entry' => array(array('tender_id' => null, 'account_id' => $this->Account->nsfAccountID(), 'crdr' => 'DEBIT', @@ -731,6 +732,7 @@ class Transaction extends AppModel { $rollback['Transaction']['crdr'] = 'CREDIT'; // Unused... keeps verifyTx happy $rollback['Transaction']['account_id'] = $this->Account->nsfAccountID(); $rollback['Transaction']['customer_id'] = $tender['Tender']['customer_id']; + $rollback['Transaction']['comment'] = $comment; foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $disbursement) { if ($disbursement['type'] === 'SURPLUS') { @@ -746,7 +748,6 @@ class Transaction extends AppModel { 'customer_id' => $disbursement['customer_id'], 'lease_id' => $disbursement['lease_id'], 'charge_entry_id' => $disbursement['charge_entry_id'], - 'effective_date' => $stamp, ); } } diff --git a/views/tenders/nsf.ctp b/views/tenders/nsf.ctp new file mode 100644 index 0000000..a5e5af3 --- /dev/null +++ b/views/tenders/nsf.ctp @@ -0,0 +1,74 @@ +' . "\n"; + +$customer = $tender['Customer']; +$entry = $tender['LedgerEntry']; +$transaction = $entry['Transaction']; + +if (isset($tender['Tender'])) + $tender = $tender['Tender']; + +// We're not actually using a grid to select the customer, +// but selection-text makes for reasonable formatting +echo ('
' . + '' . "\n"); + +echo ('' . + ' ' . + '' . "\n"); + +echo ('' . + ' ' . + '' . "\n"); + +echo ('' . + ' ' . + '' . "\n"); + +echo ('
' . $customer['name'] . '' . '(Customer #' . $customer['id'] . ')' . '
' . $tender['name'] . '' . '(Tender #' . $tender['id'] . ')' . '
Amount:' . FormatHelper::currency($entry['amount']) . '
' . + '
' . "\n"); + + +echo $form->create(null, array('id' => 'nsf-form', + 'url' => array('action' => 'nsf'))) . "\n"; + +echo $form->input("Tender.id", + array('type' => 'hidden', + 'value' => $tender['id'])) . "\n"; + +echo $this->element('form_table', + array('class' => "item receipt transaction entry", + //'with_name_after' => ':', + 'field_prefix' => 'Transaction', + 'fields' => array + ("stamp" => array('opts' => array('type' => 'text'), + 'between' => 'Now', + ), + "comment" => array('opts' => array('size' => 50), + ), + ))) . "\n"; + +echo $form->end('Record Item as NSF'); +?> + + + +