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:
abijah
2009-08-10 22:23:47 +00:00
parent 1ce71a3936
commit e100c9a88f
6 changed files with 152 additions and 29 deletions

View File

@@ -1155,6 +1155,12 @@ CREATE TABLE `pmgr_tender_types` (
`data3_name` VARCHAR(80) DEFAULT NULL, `data3_name` VARCHAR(80) DEFAULT NULL,
`data4_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 -- When we accept legal tender of this form, where does
-- it go? Each type of legal tender can specify an -- it go? Each type of legal tender can specify an
-- account, either distinct or non-distinct from others -- account, either distinct or non-distinct from others

View File

@@ -544,16 +544,19 @@ foreach my $tender_name ('Cash', 'Check', 'Money Order', 'ACH',
) { ) {
my ($tillable, $fields) = (0, 0); my ($tillable, $fields) = (0, 0);
my ($name1, $name2, $name3, $name4); my ($name1, $name2, $name3, $name4);
my ($name_field) = ('id');
$tillable = 1 $tillable = 1
if ($tender_name =~ /^Cash|Check|Money Order$/); if ($tender_name =~ /^Cash|Check|Money Order$/);
($name1) = ('Check Number') ($name1, $name_field) = ('Check Number', 'data1')
if ($tender_name eq 'Check'); if ($tender_name eq 'Check');
($name1) = ('Money Order Number') ($name1, $name_field) = ('Money Order Number', 'data1')
if ($tender_name eq 'Money Order'); if ($tender_name eq 'Money Order');
# REVISIT <AP>: 20090810
# Make data3 be the confirmation number?
($name1, $name2) = ('Routing Number', 'Account Number') ($name1, $name2) = ('Routing Number', 'Account Number')
if ($tender_name eq 'ACH'); if ($tender_name eq 'ACH');
@@ -571,6 +574,7 @@ foreach my $tender_name ('Cash', 'Check', 'Money Order', 'ACH',
'data2_name' => $name2, 'data2_name' => $name2,
'data3_name' => $name3, 'data3_name' => $name3,
'data4_name' => $name4, 'data4_name' => $name4,
'naming_field' => $name_field,
}); });
$newdb{'lookup'}{'tender_type'}{$tender_name} $newdb{'lookup'}{'tender_type'}{$tender_name}
@@ -1206,8 +1210,6 @@ foreach $row (@{query($sdbh, $query)}) {
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}; = $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
if ($SITELINK_ACCOUNT_TYPE{$row->{'PaymentType'}} eq 'Check') { 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'} $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'}
= $row->{'CheckNum'}; = $row->{'CheckNum'};
} }
@@ -1577,6 +1579,18 @@ $query = "UPDATE pmgr_transactions T, pmgr_ledger_entries E
query($db_handle, $query); 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 ## Invoice date fixes

View File

@@ -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']) if (!empty($tender['Tender']['deposit_transaction_id'])
&& empty($tender['Tender']['nsf_transaction_id']) && empty($tender['Tender']['nsf_transaction_id'])
// Hard to tell what types of items can come back as NSF. // 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. // For now, assume iff it is a named item, it can be NSF.
&& !empty($tender['TenderType']['data1_name']) && !empty($tender['TenderType']['data1_name'])
) { ) {
// Set up dynamic menu items
$this->sidemenu_links[] =
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] = $this->sidemenu_links[] =
array('name' => 'NSF', array('name' => 'NSF',
'url' => array('action' => 'nsf', 'url' => array('action' => 'nsf',
@@ -183,4 +190,73 @@ class TendersController extends AppController {
$title = "Tender #{$tender['Tender']['id']} : {$tender['Tender']['name']}"; $title = "Tender #{$tender['Tender']['id']} : {$tender['Tender']['name']}";
$this->set(compact('tender', 'title')); $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'));
}
} }

View File

@@ -132,6 +132,7 @@ class Account extends AppModel {
function cashAccountID() { return $this->nameToID('Cash'); } function cashAccountID() { return $this->nameToID('Cash'); }
function checkAccountID() { return $this->nameToID('Check'); } function checkAccountID() { return $this->nameToID('Check'); }
function moneyOrderAccountID() { return $this->nameToID('Money Order'); } function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
function achAccountID() { return $this->nameToID('ACH'); }
function concessionAccountID() { return $this->nameToID('Concession'); } function concessionAccountID() { return $this->nameToID('Concession'); }
function waiverAccountID() { return $this->nameToID('Waiver'); } function waiverAccountID() { return $this->nameToID('Waiver'); }
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); } function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }

View File

@@ -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)) if (!$this->verifyTender($tender))
return $this->prReturn(array('error' => true) + $ret); 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(); $this->create();
if (!$this->save($tender)) if (!$this->save($tender))
return $this->prReturn(array('error' => true) + $ret); return $this->prReturn(array('error' => true) + $ret);

View File

@@ -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; width: 10em;
} }
label.payment { label.payment {
@@ -208,6 +208,16 @@ label.payment {
/* display: block; */ /* display: block; */
} }
div.tender {
padding-bottom: 0.1em;
}
div.tender label {
float: left;
width: 12em;
padding-right: 0.5em;
}
/************************************************************ /************************************************************
************************************************************ ************************************************************