diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 4212d804..7086736e 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -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); diff --git a/models/address.php b/models/address.php index 342e85a4..54795a37 100755 --- a/models/address.php +++ b/models/address.php @@ -30,11 +30,18 @@ class Address extends AppModel { 'allowEmpty' => false ), 'country_id' => array( - 'rule' => array('notEmpty'), - 'message' => 'Please select the Country', - 'required' => true, - 'allowEmpty' => false - ), + 'numeric' => array( + 'rule' => 'numeric', + 'required' => true, + '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', @@ -66,8 +73,34 @@ class Address extends AppModel { 'fields' => '', 'order' => '' - + )); + + /*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; + } + } + } + } ?> diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index ca67f6c4..b80176b5 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -27,7 +27,7 @@ echo $form->input('Document.id');