Made good progress on issue #9. Will finish it up on Friday

This commit is contained in:
Karl Cordes 2011-06-29 17:25:33 +10:00
parent 3b39a2f96a
commit 9b63ac06ac
11 changed files with 97 additions and 103 deletions

View file

@ -169,18 +169,31 @@ class CustomersController extends AppController {
$this->layout = 'ajax'; $this->layout = 'ajax';
} }
function find() {
if(!empty($this->data)) { function customerContacts($id = null) {
$customer = $this->Customer->findByName($this->data['Customer']['name']); $this->layout = 'ajax';
if(!$customer) {
$this->Session->setFlash(__('Could not find the Requested Customer. Please select one from the drop down box as you type.', true)); if(!$id) {
return;
} }
else { else {
$this->redirect(array('action'=>'view/'.$customer['Customer']['id'])); $contacts = $this->Customer->Contact->find('all', array('conditions'=>array('Contact.customer_id'=>$id)));
$contactList = array();
foreach($contacts as $contact) {
$contactList[$contact['Contact']['id']] = $contact['Contact']['first_name'].' '.$contact['Contact']['last_name'];
} }
$this->set('contacts',$contactList);
} }
} }
function tagindustries($id = null) { function tagindustries($id = null) {
if (!$id && empty($this->data)) { if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Customer', true)); $this->Session->setFlash(__('Invalid Customer', true));
@ -211,5 +224,9 @@ class CustomersController extends AppController {
} }
?> ?>

View file

@ -77,44 +77,18 @@ class EnquiriesController extends AppController {
} }
function add_enquiry() { function add() {
$this->set('users',$this->Enquiry->User->find('list', array('conditions'=>array('User.type'=>'user', 'User.enabled'=>true))));
Configure::write('debug', 0);
$this->layout = 'ajax';
if (!empty($this->data)) {
$this->Enquiry->create();
$this->Enquiry->set($this->data['Enquiry']);
if($this->User->validates()) {
if ($this->User->save($this->data)) {
$message = __('The User has been saved.', true);
$data = $this->data;
$this->set('success', compact('message', 'data'));
}
}
else {
$message = __('The User could not be saved. Please, try again.', true);
$User = $this->User->invalidFields();
$data = compact('User');
$this->set('errors', compact('message', 'data'));
} }
} /*
else {
$this->redirect('/');
}
}
function add() { function add() {
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->Cu
* stomer->findById($this->params['named']['customerid']);
} }
else { else {
$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));
@ -122,9 +96,9 @@ class EnquiriesController extends AppController {
} }
} }
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*/
if(!$customer) { /*if(!$customer) {
$this->Session->setFlash(__('The customer must already exist in the database. Please try again', true)); $this->Session->setFlash(__('The customer must already exist in the database. Please try again', true));
$this->redirect(array('action'=>'add')); $this->redirect(array('action'=>'add'));
} }
@ -176,15 +150,15 @@ class EnquiriesController extends AppController {
} }
} }
} }*/
/* 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.
* */ * */
function __showPage2($customer) { /* function __showPage2($customer) { */
/* Combine the first_name and last_name for the Contact Drop Down Box */ /* Combine the first_name and last_name for the Contact Drop Down Box */
$contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id']))); /* $contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
$contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name')); $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
$states = $this->Enquiry->State->find('list'); $states = $this->Enquiry->State->find('list');
$countries = $this->Enquiry->Country->find('list', array('order'=> 'Country.name asc')); $countries = $this->Enquiry->Country->find('list', array('order'=> 'Country.name asc'));
@ -195,9 +169,9 @@ class EnquiriesController extends AppController {
$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);
$this->set('errors', $this->Enquiry->invalidFields()); $this->set('errors', $this->Enquiry->invalidFields()); */
/* Feels like an ugly hack. But it gets the desired effect and it will do for now */ /* Feels like an ugly hack. But it gets the desired effect and it will do for now */
/*
if(isset($customerAddresses[0]['BillingAddress'])) { if(isset($customerAddresses[0]['BillingAddress'])) {
$billing_address_list[0] = "No Address Selected"; $billing_address_list[0] = "No Address Selected";
foreach ($customerAddresses as $address) { foreach ($customerAddresses as $address) {
@ -211,7 +185,7 @@ class EnquiriesController extends AppController {
$this->set('billing_addresses_list', 'No Addresses exist for this Customer. Please add one'); $this->set('billing_addresses_list', 'No Addresses exist for this Customer. Please add one');
$this->set('shipping_addresses_list', 'No Addresses exist for this Customer. Please add one'); $this->set('shipping_addresses_list', 'No Addresses exist for this Customer. Please add one');
} }
} }*/

View file

@ -244,7 +244,5 @@ class UsersController extends AppController {
} }
?> ?>

View file

@ -1,4 +1,4 @@
<?php echo $javascript->link('autocomplete-customer'); ?> <?php echo $javascript->link('similar-customer.js'); ?>
<div class="customers form"> <div class="customers form">

View file

@ -0,0 +1,5 @@
<?
echo $form->radio('Enquiry.contact_id', $contacts, array('legend'=>'Choose Contact'));
?>

View file

@ -1,27 +0,0 @@
<?php echo $javascript->link('findcustomer'); ?>
<div class="customers form">
<?php echo $form->create('Customer', array('action'=>'find'));
echo '<h2>Find Customer';
echo $html->image('system-search.png');
echo '</h2>';
echo $form->input('Customer.name', array('Label'=>'Customer Name', 'id'=>'customerName'));
//echo $form->input('Customer.id', array('type'=>'hidden'));
//echo $form->end('Find');
?>
<div class ="ui-widget">
<button id="findButton">Find Customer</button>
</div>
</div>
<div id="dialog" title="Search Results">
<ul id="similarCustList">
</ul>
</div>

View file

@ -1,30 +1,39 @@
<?php echo $this->element('tipbox', array('tip'=> <?php echo $javascript->link('add_enquiry'); ?>
"You can add a new Contact to an Existing Customer while creating the enquiry. If the Contact you want to assign to the enquiry
doesn't appear in the drop down list, click 'New Contact'")); ?>
<div class="enquiries form"> <div class="addEnquiry form">
<?php echo $form->create('Enquiry', array('action' => 'add/customerid:'.$customer['Customer']['id']));?> <?php echo $form->create('Enquiry', array('action' => 'add'));?>
<fieldset> <fieldset>
<legend><?php __("New Enquiry");?></legend> <legend><?php __("New Enquiry");?></legend>
<?php <?php
echo $form->input('Customer.name', array('readonly'=>'readonly', 'value'=>$customer['Customer']['name'])); $customerInstructions = '<div class="instructions">Start typing then select the Customer from the list</div>';
echo $form->input('user_id', array('label' =>'Assigned to User'), $users); echo $form->input('Customer.name', array('id'=>'customer_autocomplete', 'label'=>'Customer Name', 'after'=>$customerInstructions));
echo $form->input('contact_user_id', array('type'=>'select', 'options'=>$contacts)); echo $form->input('customer_id', array('type'=>'hidden','id'=>'customer_id'));
?>
<div id="contacts">
</div>
<?
//echo $form->input('contact_user_id', array('type'=>'select', 'id'=>'contacts'));
echo $form->input('user_id', array('label' =>'Assign to User'), $users);
//echo $ajax->link('New Contact', array('controller' => 'contacts', 'action' => 'add_one',$customer['Customer']['id']), array('update'=>'contact')); //echo $ajax->link('New Contact', array('controller' => 'contacts', 'action' => 'add_one',$customer['Customer']['id']), array('update'=>'contact'));
//echo $html->image('contact-new.png'); //echo $html->image('contact-new.png');
echo '<span>The Contact will be emailed informing them of the new Enquiry</span>';
echo $form->input('state_id', array('label'=>'State', 'empty' => 'Please Choose A State')); 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', array('label'=>'Principle', 'empty'=>'Please Choose the Principle')); 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');
echo $form->input('customer_id', array('type'=>'hidden', 'value' => $customer['Customer']['id'])); echo $form->input('customer_id', array('type'=>'hidden'));
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>';
@ -33,8 +42,3 @@ doesn't appear in the drop down list, click 'New Contact'")); ?>
</div> </div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
</div>

View file

@ -62,7 +62,8 @@ if (isset($currentuser) == FALSE) {
<ul id="nav"> <ul id="nav">
<li><?php echo $html->link('Enquiries', '/enquiries/index'); ?> <li><?php echo $html->link('Enquiries', '/enquiries/index'); ?>
<ul> <ul>
<li class="last"><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li> <li class=""><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
<li class="last"><?php echo $html->link('Add Enquiry', '/enquiries/add'); ?></li>
</ul> </ul>
</li> </li>

View file

@ -851,6 +851,22 @@ form.addproduct {
} }
#contacts label {
float: left;
padding-bottom: 1em;
}
div.form {
width: 50%;
}
div.instructions {
font-size: x-small;
padding: 0px;
margin-top: 1em;
font-weight: bold;
}
div.address-radio { div.address-radio {

View file

@ -127,7 +127,7 @@ $(function() {
}); });
} }
}) });
$("#addBox").button().click(function() { $("#addBox").button().click(function() {

View file

@ -14,7 +14,15 @@ $(function() {
/*If the user has entered 3 or more characters. Check to see if its similar to existing customers. */ /*If the user has entered 3 or more characters. Check to see if its similar to existing customers. */
$("#customerName").change(function () { $("#customerName").change(function () {
getSimilar();
});
function getSimilar() {
if($("#customerName").val().length >= 3) { if($("#customerName").val().length >= 3) {
$.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) { $.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) {
@ -28,9 +36,7 @@ $(function() {
}); });
} }
}
});
$("#CustomerCountryName").autocomplete({ $("#CustomerCountryName").autocomplete({