New Enquiry for this Customer works. Moved Enquiry number generation to its own private function thus tidying up Enquiries controller a bit
This commit is contained in:
parent
c5d30b7263
commit
588e58bb5e
|
|
@ -53,19 +53,26 @@ class EnquiriesController extends AppController {
|
|||
|
||||
if(empty($this->data)) {
|
||||
$this->set('step', 1);
|
||||
$users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username')));
|
||||
$this->set('users', $users);
|
||||
}
|
||||
|
||||
elseif( (!empty($this->data)) && ($this->data['Enquiry']['step'] == 1) ) {
|
||||
$customer = $this->Enquiry->Customer->findByName($this->data['Customer']['name']);
|
||||
$this->set('customer', $customer);
|
||||
$contacts = $this->Enquiry->Contact->find('list', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
|
||||
}
|
||||
|
||||
if(isset($this->params['named']['customerid'])) {
|
||||
$customer = $this->Enquiry->Customer->findById($this->params['named']['customerid']);
|
||||
}
|
||||
|
||||
|
||||
if(isset($customer)) {
|
||||
|
||||
/* Check if the customer exists in the database - otherwise send the user back to step 1*/
|
||||
if(!$customer) {
|
||||
$this->Session->setFlash(__('The customer must already exist in the database. Please try again', true));
|
||||
$this->redirect(array('action'=>'add'));
|
||||
}
|
||||
$this->set('customer', $customer);
|
||||
$contacts = $this->Enquiry->Contact->find('list', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
|
||||
$this->set('step',2);
|
||||
|
||||
$this->set('contacts', $contacts);
|
||||
|
|
@ -126,8 +133,29 @@ class EnquiriesController extends AppController {
|
|||
}
|
||||
else {
|
||||
$this->Enquiry->create();
|
||||
$state = $this->Enquiry->State->findById($this->data['Enquiry']['state_id']);
|
||||
|
||||
$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 ($this->Enquiry->save($this->data)) {
|
||||
$id = $this->Enquiry->id;
|
||||
$this->__sendNewEnquiryEmail($id);
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Generate Enquiry number and return it as a string */
|
||||
|
||||
function __generateEnquiryNumber($data) {
|
||||
$state = $this->Enquiry->State->findById($data['Enquiry']['state_id']);
|
||||
$principle = $this->Enquiry->Principle->findById($data['Enquiry']['principle_id']);
|
||||
/* Generate the enquiry number for this enquiry */
|
||||
/* CMC Enquiry number format is:
|
||||
* CMC<INCREMENTAL_NUMBER><STATE_INITIAL>E<PRINCIPLE_CODE><NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE>-<NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE_IN_THIS_STATE>
|
||||
|
|
@ -161,7 +189,7 @@ class EnquiriesController extends AppController {
|
|||
$principleconditions = array
|
||||
(
|
||||
"Enquiry.principle_code" => $principle['Principle']['code'],
|
||||
"Enquiry.state_id" => $this->data['Enquiry']['state_id']
|
||||
"Enquiry.state_id" => $data['Enquiry']['state_id']
|
||||
);
|
||||
|
||||
$stateprincipleenquiries = $this->Enquiry->findCount($principleconditions);
|
||||
|
|
@ -210,21 +238,7 @@ class EnquiriesController extends AppController {
|
|||
/* Generate/set the enquiry number */
|
||||
$enquiryno = 'CMC'.$enquiryid.$state['State']['enqform'].'E'.$principle['Principle']['code'].$principleenquiries.
|
||||
'-'.$stateprincipleenquiries;
|
||||
|
||||
|
||||
$this->data['Enquiry']['title'] = $enquiryno;
|
||||
$this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to.
|
||||
Sanitize::clean($this->data);
|
||||
}
|
||||
|
||||
if ($this->Enquiry->save($this->data)) {
|
||||
$id = $this->Enquiry->id;
|
||||
$this->__sendNewEnquiryEmail($id);
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
|
||||
}
|
||||
}
|
||||
|
||||
return $enquiryno;
|
||||
}
|
||||
|
||||
/* Autocomplete the customer name - Used in: add.ctp */
|
||||
|
|
@ -232,7 +246,7 @@ class EnquiriesController extends AppController {
|
|||
|
||||
$this->set('customers', $this->Enquiry->Customer->find('all', array(
|
||||
'conditions' => array(
|
||||
'Customer.name LIKE' => $this->data['Customer']['name'].'%'
|
||||
'Customer.name LIKE' => '%'.$this->data['Customer']['name'].'%'
|
||||
),'fields' => array('Customer.name')
|
||||
)));
|
||||
$this->layout = 'ajax';
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
echo $form->input('id');
|
||||
echo $form->input('name');
|
||||
echo $form->input('abn');
|
||||
echo $form->input('notes');
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end('Submit');?>
|
||||
|
|
|
|||
|
|
@ -16,11 +16,18 @@
|
|||
<?php echo $time->nice($customer['Customer']['created']); ?>
|
||||
|
||||
</dd>
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Notes'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $customer['Customer']['notes']; ?>
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('Edit Customer', true), array('action'=>'edit', $customer['Customer']['id'])); ?> </li>
|
||||
<li><?php echo $html->link(__('New Enquiry for this Customer', true), array('controller'=>'enquiries', 'action'=>'add/customerid:'.$customer['Customer']['id'])); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -83,7 +90,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="related">
|
||||
<h3><?php __('Enquiries');?></h3>
|
||||
<h3><?php __('Enquiries');?><?php echo $html->image('folder.png'); ?></h3>
|
||||
<?php if (!empty($customer['Enquiry'])) {
|
||||
echo $this->element('enquiry_table', $enquiries);
|
||||
}
|
||||
|
|
@ -91,11 +98,12 @@
|
|||
echo "No Enquiries from this Customer";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('New Enquiry', true), array('controller'=> 'enquiries', 'action'=>'add'));?> </li>
|
||||
<li><?php echo $html->link(__('New Enquiry for this Customer', true), array('controller'=> 'enquiries', 'action'=>'add/customerid:'.$customer['Customer']['id']));?><?php echo $html->link($html->image('folder-new.png'), array('controller'=> 'enquiries', 'action'=>'add/customerid:'.$customer['Customer']['id']), null, null, false); ?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
BIN
webroot/img/folder-new.png
Normal file
BIN
webroot/img/folder-new.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
webroot/img/folder.png
Normal file
BIN
webroot/img/folder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1,015 B |
Loading…
Reference in a new issue