From e100c9a88fe81f82c2c13689d30bf3ef119e2927 Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 10 Aug 2009 22:23:47 +0000 Subject: [PATCH] Added the ability to edit a tender. I've locked this down to just editing the data1-4 fields at the moment, since there are accounting ramifications if we were to change the tender type. git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@519 97e9348a-65ac-dc4b-aefc-98561f571b83 --- db/schema.sql | 6 ++ scripts/sitelink2pmgr.pl | 22 +++++-- site/controllers/tenders_controller.php | 84 +++++++++++++++++++++++-- site/models/account.php | 1 + site/models/tender.php | 54 ++++++++++------ site/webroot/css/layout.css | 14 ++++- 6 files changed, 152 insertions(+), 29 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index 7800fba..9b0fcff 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1155,6 +1155,12 @@ CREATE TABLE `pmgr_tender_types` ( `data3_name` VARCHAR(80) DEFAULT NULL, `data4_name` VARCHAR(80) DEFAULT NULL, + -- The field from pmgr_tenders that is used for helping + -- to name the tender. For example, a Check tender type + -- might specify data1 as the field, so that tenders + -- would be named "Check #0000" + `naming_field` VARCHAR(80) DEFAULT 'id', + -- When we accept legal tender of this form, where does -- it go? Each type of legal tender can specify an -- account, either distinct or non-distinct from others diff --git a/scripts/sitelink2pmgr.pl b/scripts/sitelink2pmgr.pl index a4575ed..2b64568 100644 --- a/scripts/sitelink2pmgr.pl +++ b/scripts/sitelink2pmgr.pl @@ -544,16 +544,19 @@ foreach my $tender_name ('Cash', 'Check', 'Money Order', 'ACH', ) { my ($tillable, $fields) = (0, 0); my ($name1, $name2, $name3, $name4); + my ($name_field) = ('id'); $tillable = 1 if ($tender_name =~ /^Cash|Check|Money Order$/); - ($name1) = ('Check Number') + ($name1, $name_field) = ('Check Number', 'data1') if ($tender_name eq 'Check'); - ($name1) = ('Money Order Number') + ($name1, $name_field) = ('Money Order Number', 'data1') if ($tender_name eq 'Money Order'); + # REVISIT : 20090810 + # Make data3 be the confirmation number? ($name1, $name2) = ('Routing Number', 'Account Number') if ($tender_name eq 'ACH'); @@ -571,6 +574,7 @@ foreach my $tender_name ('Cash', 'Check', 'Money Order', 'ACH', 'data2_name' => $name2, 'data3_name' => $name3, 'data4_name' => $name4, + 'naming_field' => $name_field, }); $newdb{'lookup'}{'tender_type'}{$tender_name} @@ -1206,8 +1210,6 @@ foreach $row (@{query($sdbh, $query)}) { = $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}; if ($SITELINK_ACCOUNT_TYPE{$row->{'PaymentType'}} eq 'Check') { - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'} - = 'Check #' . $row->{'CheckNum'}; $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'} = $row->{'CheckNum'}; } @@ -1577,6 +1579,18 @@ $query = "UPDATE pmgr_transactions T, pmgr_ledger_entries E query($db_handle, $query); +###################################################################### +## Tender Names + +print("Set Tender Names...\n"); + +$query = "UPDATE pmgr_tenders T, pmgr_tender_types TT + SET T.`name` = CONCAT(T.`name`, ' #', + IF(T.tender_type_id IN (2,3), T.data1, T.id)) + WHERE T.tender_type_id IS NULL OR TT.id = T.tender_type_id"; +query($db_handle, $query); + + ###################################################################### ## Invoice date fixes diff --git a/site/controllers/tenders_controller.php b/site/controllers/tenders_controller.php index 3e2eb47..0f0a9fa 100644 --- a/site/controllers/tenders_controller.php +++ b/site/controllers/tenders_controller.php @@ -163,16 +163,23 @@ class TendersController extends AppController { )); + // Set up dynamic menu items + $this->sidemenu_links[] = + array('name' => 'Operations', 'header' => true); + + // Watch out for the special "Closing" entries + if (!empty($tender['TenderType']['id'])) + $this->sidemenu_links[] = + array('name' => 'Edit', + 'url' => array('action' => 'edit', + $id)); + if (!empty($tender['Tender']['deposit_transaction_id']) && empty($tender['Tender']['nsf_transaction_id']) // Hard to tell what types of items can come back as NSF. // For now, assume iff it is a named item, it can be NSF. && !empty($tender['TenderType']['data1_name']) ) { - // Set up dynamic menu items - $this->sidemenu_links[] = - array('name' => 'Operations', 'header' => true); - $this->sidemenu_links[] = array('name' => 'NSF', 'url' => array('action' => 'nsf', @@ -183,4 +190,73 @@ class TendersController extends AppController { $title = "Tender #{$tender['Tender']['id']} : {$tender['Tender']['name']}"; $this->set(compact('tender', 'title')); } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: edit + * - Edit tender information + */ + + function edit($id = null) { + if (isset($this->data)) { + // Check to see if the operation was cancelled. + if (isset($this->params['form']['cancel'])) { + if (empty($this->data['Tender']['id'])) + $this->redirect(array('action'=>'index')); + + $this->redirect(array('action'=>'view', $this->data['Tender']['id'])); + } + + // Make sure we have tender data + if (empty($this->data['Tender']) || empty($this->data['Tender']['id'])) + $this->redirect(array('action'=>'index')); + + // Figure out which tender type was chosen + // REVISIT : 20090810; Not ready to change tender type + // $tender_type_id = $this->data['Tender']['tender_type_id']; + $tender_type_id = $this->Tender->field('tender_type_id'); + if (empty($tender_type_id)) + $this->redirect(array('action'=>'view', $this->data['Tender']['id'])); + + // Get data fields from the selected tender type + $this->data['Tender'] += $this->data['type'][$tender_type_id]; + unset($this->data['type']); + + // Save the tender and all associated data + $this->Tender->create(); + $this->Tender->id = $this->data['Tender']['id']; + if (!$this->Tender->save($this->data, false)) { + $this->Session->setFlash("TENDER SAVE FAILED", true); + pr("TENDER SAVE FAILED"); + } + + $this->redirect(array('action'=>'view', $this->Tender->id)); + + // For debugging, only if the redirects above have been + // commented out, otherwise this section isn't reached. + $this->render('/fake'); + return; + } + + if ($id) { + $this->data = $this->Tender->findById($id); + } else { + $this->redirect(array('action'=>'index')); + } + + $tender_types = $this->Tender->TenderType->find + ('list', array('order' => array('name'))); + $this->set(compact('tender_types')); + + $types = $this->Tender->TenderType->find('all', array('contain' => false)); + $this->set(compact('types')); + + // Prepare to render. + $title = ('Tender #' . $this->data['Tender']['id'] . + ' : ' . $this->data['Tender']['name'] . + " : Edit"); + $this->set(compact('title')); + } } diff --git a/site/models/account.php b/site/models/account.php index a94baf5..60416d5 100644 --- a/site/models/account.php +++ b/site/models/account.php @@ -132,6 +132,7 @@ class Account extends AppModel { function cashAccountID() { return $this->nameToID('Cash'); } function checkAccountID() { return $this->nameToID('Check'); } function moneyOrderAccountID() { return $this->nameToID('Money Order'); } + function achAccountID() { return $this->nameToID('ACH'); } function concessionAccountID() { return $this->nameToID('Concession'); } function waiverAccountID() { return $this->nameToID('Waiver'); } function pettyCashAccountID() { return $this->nameToID('Petty Cash'); } diff --git a/site/models/tender.php b/site/models/tender.php index 2a500e7..405816e 100644 --- a/site/models/tender.php +++ b/site/models/tender.php @@ -14,6 +14,41 @@ class Tender extends AppModel { ); + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: beforeSave + * - Performs any work needed before the save occurs + */ + + function afterSave() { + // 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 tender type, and the tender ID + + // Determine our tender type, and set the ID of that model + $this->TenderType->id = $this->field('tender_type_id'); + + // REVISIT : 20090810 + // The only tender expected to have no tender type + // is our special "Closing" tender. + if (empty($this->TenderType->id)) + $newname = 'Closing'; + else { + $newname = $this->TenderType->field('name'); + $naming_field = $this->TenderType->field('naming_field'); + if (!empty($naming_field)) + $newname .= ' #' . $this->field($naming_field); + } + + if ($newname !== $this->field('name')) + $this->saveField('name', $newname); + + return parent::afterSave(); + } + + /************************************************************************** ************************************************************************** ************************************************************************** @@ -47,25 +82,6 @@ class Tender extends AppModel { 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); diff --git a/site/webroot/css/layout.css b/site/webroot/css/layout.css index 0699da8..644264a 100644 --- a/site/webroot/css/layout.css +++ b/site/webroot/css/layout.css @@ -195,10 +195,10 @@ table.list.ledger td.evnrow { background: #f4f4f4; } /************************************************************ ************************************************************ - * Receipt Entry + * Receipt Entry / Tender Edit */ -input.payment { +input.payment, div.tender input, div.tender select { width: 10em; } label.payment { @@ -208,6 +208,16 @@ label.payment { /* display: block; */ } +div.tender { + padding-bottom: 0.1em; +} + +div.tender label { + float: left; + width: 12em; + padding-right: 0.5em; + } + /************************************************************ ************************************************************