Added some validation to Address model. Closes #29

This commit is contained in:
Karl Cordes 2011-10-24 14:20:07 +11:00
parent aa8414b68c
commit aa7a25e5c2
5 changed files with 115 additions and 53 deletions

View file

@ -6,11 +6,9 @@ class DocumentsController extends AppController {
var $paginate = array(
'contain' => false,
'limit' => 200,
'order'=>array('Document.id' => 'desc')
);
var $components = array('Email');
@ -28,7 +26,7 @@ class DocumentsController extends AppController {
$this->redirect(array('action'=>'index'));
}
$document = $this->Document->read(null,$id);
//$document = $this->Document->find('first',array('conditions'=>array('Document.id'=>$id), 'recursive'=>2));
$this->set('document', $document);
$this->data = $document;
@ -49,15 +47,12 @@ class DocumentsController extends AppController {
break;
case 'invoice':
$docTypeElement = 'document_invoice_view';
$this->set('currencies', $this->Document->Invoice->Currency->find('list'));
$this->set('invoice', $this->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id']))));
break;
case 'purchaseOrder':
$docTypeElement = 'document_purchase_order_view';
break;
case 'orderAck':
$this->set('currencies', $this->Document->OrderAcknowledgement->Currency->find('list'));
$this->set('job', $this->Document->OrderAcknowledgement->Job->find('first', array('conditions'=>array('Job.id'=>$document['OrderAcknowledgement']['job_id']))));
@ -170,6 +165,18 @@ class DocumentsController extends AppController {
break;
case "purchaseOrder":
$count = $this->Document->PurchaseOrder->findCount();
$count++;
$offset = 2060;
$count += $offset;
$newPOnumber = "CMCPO".$count;
$this->data['PurchaseOrder']['title'] = $newPOnumber;
$this->data['PurchaseOrder']['issue_date'] = date('Y-m-d');
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
$this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it!
$this->data['Document']['type'] = 'purchaseOrder';
break;
case "orderAck":
$enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid);

View file

@ -30,11 +30,18 @@ class Address extends AppModel {
'allowEmpty' => false
),
'country_id' => array(
'rule' => array('notEmpty'),
'message' => 'Please select the Country',
'numeric' => array(
'rule' => 'numeric',
'required' => true,
'allowEmpty' => false
'message' => 'Please choose a Country for this Address',
'on' => 'create'
),
'checkStates' => array(
'rule' => array('checkStates'),
'message' => ' Australian States can only be chosen if Australia is selected. Otherwise choose "Overseas" for other Countries ',
'on' => 'create')),
'type' => array(
'rule' => array('notEmpty'),
'message' => 'Please select the Type of Address',
@ -69,5 +76,31 @@ class Address extends AppModel {
));
/*Custom Validation Rule to Check that Address with Australian States are assigned to Australia.
* and that Overseas enquiries are NOT assigned to Australia.
* Not Portable at all. This code is only for CMC usage
* Should probably change this to use RegExes.
*/
function checkStates($data) {
if($this->data['Address']['country_id'] != 1) { //This Enquiry is not for Australia. State must be set to overseas.
if($this->data['Address']['state_id'] != 9) { //The State isn't set to Overseas. Return false
return FALSE;
}
else {
return TRUE;
}
}
if($this->data['Address']['country_id'] == 1) { //This enquiry is for Australia. State must be for an Australian State
if($this->data['Address']['state_id'] == 9) {
return FALSE;
}
else {
return TRUE;
}
}
}
}
?>

View file

@ -27,7 +27,7 @@ echo $form->input('Document.id');
<div class="docOperations">
<h3>Customer placed an order for this Quote?</h3>
<h3>Has <?=$html->link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?> placed an order for this Quote?</h3>
<? //$html->link('Convert this Enquiry to a new Job and Generate an Order Acknowledgement', '/documents/convert_to_oa/'.$document['Document']['id'], array('class'=>'actionLink'));?>
<button id="createJobAndOA">Create a New Job and Order Acknowledgement</button>
</div>

View file

@ -21,10 +21,7 @@
<input id="PurchaseOrderDateArrivedDisplay" type="text" value="" class="datePicker">
</div>
<?php
echo $form->input('issue_date', array('type'=>'hidden'));
echo $form->input('dispatch_date', array('type'=>'hidden'));
echo $form->input('date_arrived', array('type'=>'hidden'));

View file

@ -30,4 +30,29 @@ $(function() {
});
/**
* A more generic way of handling the HABTM <ul> <li>[REMOVE BUTTON] NAME [HIDDEN INPUT]</li> </ul>
*/
function addToList(modelName, id, value, ULelement) {
var thisLI = $('<li></li>');
var thisButton = $('<button>X</button>');
thisButton.addClass('removeFromList');
thisButton.button();
var thisHiddenInput = $('<input type="hidden">');
var modelString = '['+modelName+']';
thisHiddenInput.attr('name', 'data'+modelString+modelString+'[]');
thisHiddenInput.attr('value', id);
thisLI.attr('id', modelName+'ID_'+id);
thisLI.html(value);
thisLI.prepend(thisButton);
thisLI.append(thisHiddenInput);
ULelement.append(thisLI);
}
});