Changed Enquiry Adding. Cleaned up cruft left over from previous method of adding
This commit is contained in:
parent
ebfced738a
commit
eb556f9780
|
|
@ -51,19 +51,8 @@ class EnquiriesController extends AppController {
|
||||||
|
|
||||||
|
|
||||||
function add() {
|
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'])) {
|
if(isset($this->params['named']['customerid'])) {
|
||||||
$customer = $this->Enquiry->Customer->findById($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->Session->setFlash(__('The customer must already exist in the database. Please add Enquiries to an existing Customer', true));
|
||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($customer)) {
|
if(isset($customer)) {
|
||||||
/* Check if the customer exists in the database - otherwise send the user back to step 1*/
|
/* 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') ) {
|
if (!empty($this->data)) {
|
||||||
|
$customer = $this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id']);
|
||||||
$this->Enquiry->create();
|
$principle = $this->Enquiry->Principle->findById($this->data['Enquiry']['principle_id']);
|
||||||
$enquiryno = $this->__generateEnquiryNumber($this->data);
|
$this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to.
|
||||||
$this->data['Enquiry']['title'] = $enquiryno;
|
Sanitize::clean($this->data);
|
||||||
$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(isset($this->data['Contact']['new'])) {
|
||||||
if($this->data['Contact']['new']) {
|
if($this->data['Contact']['new']) {
|
||||||
$this->Enquiry->Contact->save($this->data);
|
$this->Enquiry->Contact->save($this->data);
|
||||||
$this->data['Enquiry']['contact_id'] = $this->Enquiry->Contact->id;
|
$this->data['Enquiry']['contact_id'] = $this->Enquiry->Contact->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->Enquiry->set($this->data);
|
||||||
|
if($this->Enquiry->validates()) {
|
||||||
if ($this->Enquiry->save($this->data)) {
|
|
||||||
$id = $this->Enquiry->id;
|
$enquiryno = $this->__generateEnquiryNumber($this->data);
|
||||||
if($this->data['Enquiry']['send_enquiry_email'] == 1) {
|
$this->data['Enquiry']['title'] = $enquiryno;
|
||||||
$this->__sendNewEnquiryEmail($id);
|
$this->Enquiry->create();
|
||||||
}
|
if ($this->Enquiry->save($this->data)) {
|
||||||
else {
|
$id = $this->Enquiry->id;
|
||||||
$this->Session->setFlash(__('The Enquiry has been saved but the Contact has NOT been emailed, as you requested.', true));
|
if($this->data['Enquiry']['send_enquiry_email'] == 1) {
|
||||||
$this->redirect(array('action'=>'view/'.$id), null, false);
|
$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 {
|
||||||
else {
|
$this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
|
||||||
$this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
|
$this->__showPage2($this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id']));
|
||||||
$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
|
/* Internal function to display page 2 of the Add Enquiry Form Wizard
|
||||||
* to help make the flow-control logic of the add function clearer.
|
* 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');
|
$statuses = $this->Enquiry->Status->find('list');
|
||||||
$users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username')));
|
$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(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'])));
|
$customerAddresses = $this->Enquiry->BillingAddress->find('all', array('conditions'=>array('BillingAddress.customer_id' => $customer['Customer']['id'])));
|
||||||
$this->set('billing_addresses', $customerAddresses);
|
$this->set('billing_addresses', $customerAddresses);
|
||||||
$this->set('shipping_addresses', $customerAddresses);
|
$this->set('shipping_addresses', $customerAddresses);
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,7 @@ class Enquiry extends AppModel {
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'message' => 'User ID must be selected',
|
'message' => 'User ID must be selected',
|
||||||
'on' => 'create'
|
'on' => 'create'
|
||||||
),
|
),
|
||||||
'title' => array(
|
|
||||||
'rule' => 'notEmpty',
|
|
||||||
'required' => true,
|
|
||||||
'on' => 'create'
|
|
||||||
),
|
|
||||||
'customer_id' => array(
|
'customer_id' => array(
|
||||||
'rule' => 'numeric',
|
'rule' => 'numeric',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,12 @@
|
||||||
doesn't appear in the drop down list, click 'New Contact'")); ?>
|
doesn't appear in the drop down list, click 'New Contact'")); ?>
|
||||||
|
|
||||||
<div class="enquiries form">
|
<div class="enquiries form">
|
||||||
<?php echo $form->create('Enquiry');?>
|
<?php echo $form->create('Enquiry', array('action' => 'add/customerid:'.$customer['Customer']['id']));?>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?php __("New Enquiry: Step $step");?></legend>
|
<legend><?php __("New Enquiry for: ".$customer['Customer']['name']);?></legend>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if($step == 1) {
|
|
||||||
echo '<div class="input text">';
|
|
||||||
echo '<span>Start typing the Company name and it should appear in a list below. It must already exist in the database</span>';
|
|
||||||
echo $form->label('Customer.name', 'Company Name');
|
|
||||||
echo $ajax->autoComplete('Customer.name', '/enquiries/completeCustomer');
|
|
||||||
echo '</div>';
|
|
||||||
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('Customer.name', array('readonly'=>'readonly', 'value'=>$customer['Customer']['name']));
|
||||||
|
|
||||||
echo $form->input('user_id', array('label' =>'Assigned to User'), $users);
|
echo $form->input('user_id', array('label' =>'Assigned to User'), $users);
|
||||||
echo '<div id="contact">';
|
echo '<div id="contact">';
|
||||||
echo $form->input('contact_id', array('div' => false));
|
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 $html->image('contact-new.png');
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '<span>The Contact will be emailed informing them of the new Enquiry</span>';
|
echo '<span>The Contact will be emailed informing them of the new Enquiry</span>';
|
||||||
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('country_id');
|
||||||
|
|
||||||
echo $form->input('gst', array('label' => 'Is GST Applicable', 'options' => array('1' => 'Yes', '0' => 'No')));
|
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('status_id');
|
||||||
echo $form->input('comments', array('maxlength' => '250000'));
|
echo $form->input('comments', array('maxlength' => '250000'));
|
||||||
echo $form->input('customer_id', array('type'=>'hidden', 'value' => $customer['Customer']['id']));
|
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('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('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->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 $form->end('Add Enquiry');
|
||||||
echo '<span>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.</span>';
|
echo '<span>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.</span>';
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
@ -58,3 +40,4 @@ doesn't appear in the drop down list, click 'New Contact'")); ?>
|
||||||
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
|
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<?php pr($errors); ?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue