From 9b63ac06acae017d36fec57767f65f4cb0ab74a8 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Wed, 29 Jun 2011 17:25:33 +1000 Subject: [PATCH] Made good progress on issue #9. Will finish it up on Friday --- controllers/customers_controller.php | 37 +++++++++---- controllers/enquiries_controller.php | 52 +++++-------------- controllers/users_controller.php | 2 - views/customers/add.ctp | 2 +- views/customers/customer_contacts.ctp | 5 ++ views/customers/find.ctp | 27 ---------- views/enquiries/add.ctp | 40 +++++++------- views/layouts/default.ctp | 3 +- webroot/css/quotenik.css | 16 ++++++ webroot/js/add_edit_shipment.js | 2 +- ...mplete-customer.js => similar-customer.js} | 14 +++-- 11 files changed, 97 insertions(+), 103 deletions(-) create mode 100644 views/customers/customer_contacts.ctp delete mode 100755 views/customers/find.ctp rename webroot/js/{autocomplete-customer.js => similar-customer.js} (92%) diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 71e60c33..1d0278d5 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -169,17 +169,30 @@ class CustomersController extends AppController { $this->layout = 'ajax'; } - function find() { - if(!empty($this->data)) { - $customer = $this->Customer->findByName($this->data['Customer']['name']); - if(!$customer) { - $this->Session->setFlash(__('Could not find the Requested Customer. Please select one from the drop down box as you type.', true)); - } - else { - $this->redirect(array('action'=>'view/'.$customer['Customer']['id'])); - } + + function customerContacts($id = null) { + $this->layout = 'ajax'; + + if(!$id) { + return; } - } + else { + $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) { if (!$id && empty($this->data)) { @@ -208,6 +221,10 @@ class CustomersController extends AppController { $this->set('customers', $this->Customer->find('all', array('recursive'=>0))); $this->layout = 'csv'; } + + + + diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index 37bc219d..f9039cba 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -77,44 +77,18 @@ class EnquiriesController extends AppController { } - function add_enquiry() { - - 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() { + $this->set('users',$this->Enquiry->User->find('list', array('conditions'=>array('User.type'=>'user', 'User.enabled'=>true)))); } - + /* function add() { if(empty($this->data)) { 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 { $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*/ - if(!$customer) { + /*if(!$customer) { $this->Session->setFlash(__('The customer must already exist in the database. Please try again', true)); $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 * 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 */ - $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')); $states = $this->Enquiry->State->find('list'); $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']))); $this->set('billing_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 */ - +/* if(isset($customerAddresses[0]['BillingAddress'])) { $billing_address_list[0] = "No Address Selected"; 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('shipping_addresses_list', 'No Addresses exist for this Customer. Please add one'); } - } + }*/ diff --git a/controllers/users_controller.php b/controllers/users_controller.php index c2ee6324..a22cbd0b 100755 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -244,7 +244,5 @@ class UsersController extends AppController { - - } ?> diff --git a/views/customers/add.ctp b/views/customers/add.ctp index 75c92c23..2597a7ab 100755 --- a/views/customers/add.ctp +++ b/views/customers/add.ctp @@ -1,4 +1,4 @@ -link('autocomplete-customer'); ?> +link('similar-customer.js'); ?>
diff --git a/views/customers/customer_contacts.ctp b/views/customers/customer_contacts.ctp new file mode 100644 index 00000000..60cd6b10 --- /dev/null +++ b/views/customers/customer_contacts.ctp @@ -0,0 +1,5 @@ +radio('Enquiry.contact_id', $contacts, array('legend'=>'Choose Contact')); + +?> \ No newline at end of file diff --git a/views/customers/find.ctp b/views/customers/find.ctp deleted file mode 100755 index 9ea476d1..00000000 --- a/views/customers/find.ctp +++ /dev/null @@ -1,27 +0,0 @@ - -link('findcustomer'); ?> -
- - create('Customer', array('action'=>'find')); - echo '

Find Customer'; - echo $html->image('system-search.png'); - echo '

'; - - echo $form->input('Customer.name', array('Label'=>'Customer Name', 'id'=>'customerName')); - - //echo $form->input('Customer.id', array('type'=>'hidden')); - - //echo $form->end('Find'); - - ?> -
- -
- - -
- -
-
    -
-
\ No newline at end of file diff --git a/views/enquiries/add.ctp b/views/enquiries/add.ctp index c4b0254d..91a6ccfc 100755 --- a/views/enquiries/add.ctp +++ b/views/enquiries/add.ctp @@ -1,30 +1,39 @@ -element('tipbox', array('tip'=> -"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'")); ?> +link('add_enquiry'); ?> -
-create('Enquiry', array('action' => 'add/customerid:'.$customer['Customer']['id']));?> +
+create('Enquiry', array('action' => 'add'));?>
+ + input('Customer.name', array('readonly'=>'readonly', 'value'=>$customer['Customer']['name'])); - echo $form->input('user_id', array('label' =>'Assigned to User'), $users); - echo $form->input('contact_user_id', array('type'=>'select', 'options'=>$contacts)); + $customerInstructions = '
Start typing then select the Customer from the list
'; + echo $form->input('Customer.name', array('id'=>'customer_autocomplete', 'label'=>'Customer Name', 'after'=>$customerInstructions)); + echo $form->input('customer_id', array('type'=>'hidden','id'=>'customer_id')); + + ?> +
+ +
+ 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 $html->image('contact-new.png'); - echo 'The Contact will be emailed informing them of the new Enquiry'; 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', 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('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('comments'); + 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('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.'; @@ -33,8 +42,3 @@ doesn't appear in the drop down list, click 'New Contact'")); ?>
-
-
    -
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • -
-
diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 349730bf..032d053d 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -62,7 +62,8 @@ if (isset($currentuser) == FALSE) {