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
This commit is contained in:
@@ -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 <AP>: 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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'); }
|
||||
|
||||
@@ -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 <AP>: 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 <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'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->pr(20, array('Tender' => $tender),
|
||||
'Pre-Save');
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($tender))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************
|
||||
************************************************************
|
||||
|
||||
Reference in New Issue
Block a user