diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index 68ca275f..0a0f2bbc 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -51,19 +51,8 @@ class EnquiriesController extends AppController { function add() { - - /* - * These were depreciated by the move to only add enquiries from the Customer View page. - * if(empty($this->data)) { - $this->set('step', 1); - } - - elseif( (!empty($this->data)) && ($this->data['Enquiry']['step'] == 1) ) { - $customer = $this->Enquiry->Customer->findByName($this->data['Customer']['name']); - } */ - - if(empty($this->data)) { + if(empty($this->data)) { if(isset($this->params['named']['customerid'])) { $customer = $this->Enquiry->Customer->findById($this->params['named']['customerid']); } @@ -71,7 +60,7 @@ class EnquiriesController extends AppController { $this->Session->setFlash(__('The customer must already exist in the database. Please add Enquiries to an existing Customer', true)); $this->redirect(array('action'=>'index')); } - } + } if(isset($customer)) { /* Check if the customer exists in the database - otherwise send the user back to step 1*/ @@ -85,38 +74,49 @@ class EnquiriesController extends AppController { } - if ( (!empty($this->data)) && ($this->data['Enquiry']['finished'] == 'true') ) { - - $this->Enquiry->create(); - $enquiryno = $this->__generateEnquiryNumber($this->data); - $this->data['Enquiry']['title'] = $enquiryno; - $principle = $this->Enquiry->Principle->findById($this->data['Enquiry']['principle_id']); - $this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to. - Sanitize::clean($this->data); + if (!empty($this->data)) { + $customer = $this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id']); + $principle = $this->Enquiry->Principle->findById($this->data['Enquiry']['principle_id']); + $this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to. + Sanitize::clean($this->data); if(isset($this->data['Contact']['new'])) { if($this->data['Contact']['new']) { $this->Enquiry->Contact->save($this->data); $this->data['Enquiry']['contact_id'] = $this->Enquiry->Contact->id; } } - - - if ($this->Enquiry->save($this->data)) { - $id = $this->Enquiry->id; - if($this->data['Enquiry']['send_enquiry_email'] == 1) { - $this->__sendNewEnquiryEmail($id); - } - else { - $this->Session->setFlash(__('The Enquiry has been saved but the Contact has NOT been emailed, as you requested.', true)); - $this->redirect(array('action'=>'view/'.$id), null, false); + $this->Enquiry->set($this->data); + if($this->Enquiry->validates()) { + + $enquiryno = $this->__generateEnquiryNumber($this->data); + $this->data['Enquiry']['title'] = $enquiryno; + $this->Enquiry->create(); + if ($this->Enquiry->save($this->data)) { + $id = $this->Enquiry->id; + if($this->data['Enquiry']['send_enquiry_email'] == 1) { + $this->__sendNewEnquiryEmail($id); + } + else { + $this->Session->setFlash(__('The Enquiry has been saved but the Contact has NOT been emailed, as you requested.', true)); + $this->redirect(array('action'=>'view/'.$id), null, false); + } } - } - else { - $this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true)); - $this->__showPage2($this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id'])); + else { + $this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true)); + $this->__showPage2($this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id'])); + } } + else { + + $this->set('errors', $this->Enquiry->invalidFields()); + $this->__showPage2($customer); + $this->render(); + + + } + } - } + } /* Internal function to display page 2 of the Add Enquiry Form Wizard * to help make the flow-control logic of the add function clearer. @@ -132,7 +132,6 @@ class EnquiriesController extends AppController { $statuses = $this->Enquiry->Status->find('list'); $users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username'))); $this->set(compact('users', 'customers', 'states', 'countries', 'principles', 'statuses', 'contacts', 'customer')); - $this->set('step',2); $customerAddresses = $this->Enquiry->BillingAddress->find('all', array('conditions'=>array('BillingAddress.customer_id' => $customer['Customer']['id']))); $this->set('billing_addresses', $customerAddresses); $this->set('shipping_addresses', $customerAddresses); diff --git a/models/enquiry.php b/models/enquiry.php index e70de04d..b3ef19a5 100755 --- a/models/enquiry.php +++ b/models/enquiry.php @@ -9,12 +9,7 @@ class Enquiry extends AppModel { 'required' => true, 'message' => 'User ID must be selected', 'on' => 'create' - ), - 'title' => array( - 'rule' => 'notEmpty', - 'required' => true, - 'on' => 'create' - ), + ), 'customer_id' => array( 'rule' => 'numeric', 'required' => true, diff --git a/views/enquiries/add.ctp b/views/enquiries/add.ctp index eaba3f98..2f241de5 100755 --- a/views/enquiries/add.ctp +++ b/views/enquiries/add.ctp @@ -3,25 +3,12 @@ doesn't appear in the drop down list, click 'New Contact'")); ?>
-create('Enquiry');?> +create('Enquiry', array('action' => 'add/customerid:'.$customer['Customer']['id']));?>
- + '; - echo 'Start typing the Company name and it should appear in a list below. It must already exist in the database'; - echo $form->label('Customer.name', 'Company Name'); - echo $ajax->autoComplete('Customer.name', '/enquiries/completeCustomer'); - echo '
'; - echo $form->input('step', array('type'=>'hidden', 'value' => $step)); - echo $form->input('finished', array('type' => 'hidden', 'value' => 'false')); - echo $form->end('Proceed to Step 2'); - } - else { - //echo $form->select('Contact.id', array(), null, array('id'=>'contacts')); + echo $form->input('Customer.name', array('readonly'=>'readonly', 'value'=>$customer['Customer']['name'])); - echo $form->input('user_id', array('label' =>'Assigned to User'), $users); echo '
'; echo $form->input('contact_id', array('div' => false)); @@ -30,24 +17,19 @@ doesn't appear in the drop down list, click 'New Contact'")); ?> echo $html->image('contact-new.png'); echo '
'; echo 'The Contact will be emailed informing them of the new Enquiry'; - echo $form->input('state_id'); + echo $form->input('state_id', array('label'=>'State', 'empty' => 'Please Choose A State')); echo $form->input('country_id'); echo $form->input('gst', array('label' => 'Is GST Applicable', 'options' => array('1' => 'Yes', '0' => 'No'))); - echo $form->input('principle_id'); + echo $form->input('principle_id', array('label'=>'Principle', 'empty'=>'Please Choose the Principle')); echo $form->input('status_id'); echo $form->input('comments', array('maxlength' => '250000')); echo $form->input('customer_id', array('type'=>'hidden', 'value' => $customer['Customer']['id'])); - echo $form->input('finished', array('type' => 'hidden', 'value' => 'true')); - - echo $form->input('step', array('type'=>'hidden', 'value' => $step)); echo $form->input('billing_address_id', array('div' => 'addressradio', 'legend' => 'Billing Address', 'options' => $billing_addresses_list, 'type' => 'radio')); echo $form->input('shipping_address_id', array('div' => 'addressradio','legend' => 'Shipping Address', 'options' => $shipping_addresses_list, 'type' => 'radio')); echo $form->input('send_enquiry_email', array('label' => 'Send the Contact an Enquiry Confirmation Email', 'type' => 'select', 'selected' => 1, 'options' => array(1 => 'Yes', 0 => 'No'))); echo $form->end('Add Enquiry'); echo 'After submitting it will take a moment to email the customer, if you selected the checkbox above, before you are redirected to the new Enquiry.'; - - } ?> @@ -58,3 +40,4 @@ doesn't appear in the drop down list, click 'New Contact'")); ?>
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • +