diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php
index 24628ece..f3919fed 100755
--- a/controllers/customers_controller.php
+++ b/controllers/customers_controller.php
@@ -1,111 +1,113 @@
array('order' => array('Customer.name' => 'asc'),
- 'limit' => 200
- ),
- 'Enquiry' => array('order' => array('Enquiry.id' => 'desc'))
- );
-
- function index() {
- $this->Customer->recursive = 0;
- $this->set('customers', $this->paginate());
- $this->set('customer_categories', $this->Customer->CustomerCategory->find('all'));
- /* Show only customers from a particular category name */
- if(isset($this->params['named']['showonly'])) {
- $this->set('customers', $this->paginate('Customer', array('Customer.customer_category_id' => $this->params['named']['showonly'])));
- }
-
- }
-
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid Customer.', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->set('customer', $this->Customer->read(null, $id));
- $this->set('addresses', $this->Customer->Address->findAllByCustomerId($id));
- $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.customer_id' => $id)));
- $this->set('contacts', $this->Customer->Contact->find('all', array('conditions' => array('customer_id' => $id), 'order' => 'Contact.last_name ASC')));
-
-
-
- $statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0));
- $status_list = array();
- foreach ($statuses as $status) {
- $statusid = $status['Status']['id'];
- $status_list[$statusid] = $status['Status']['name'];
- }
- $this->set('status_list', $status_list);
-
-
- $this->set('parent_industry_list', $this->Customer->Industry->find('list', array('conditions' => array('parent_id' => null))));
- }
-
- function add() {
- if (!empty($this->data)) {
-
- /* Remove all whitespace and non-digit characters from the user input */
- $this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
+ var $name = 'Customers';
+ var $helpers = array('Html', 'Form', 'Time', 'Ajax');
+ var $components = array('RequestHandler');
- if($this->Customer->saveAll($this->data, array('validate'=>'first')) ) {
- $newcustomerid = $this->Customer->id;
- $this->Session->setFlash(__('The Customer has been saved', true));
- $this->redirect(array('action'=>'view', 'id'=>$newcustomerid));
- }
-
- }
- $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
- $this->set('states', $this->Customer->Address->State->find('list'));
- //$this->set('countries', $this->Customer->Country->find('list', array('order'=>array('Country.name ASC'))));
-
- }
-
+ var $paginate = array(
+ 'Customer' => array('order' => array('Customer.name' => 'asc'),
+ 'limit' => 200
+ ),
+ 'Enquiry' => array('order' => array('Enquiry.id' => 'desc'))
+ );
- function edit($id = null) {
+ function index() {
+ $this->Customer->recursive = 0;
+ $this->set('customers', $this->paginate());
+ $this->set('customer_categories', $this->Customer->CustomerCategory->find('all'));
+ /* Show only customers from a particular category name */
+ if(isset($this->params['named']['showonly'])) {
+ $this->set('customers', $this->paginate('Customer', array('Customer.customer_category_id' => $this->params['named']['showonly'])));
+ }
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid Customer', true));
- $this->redirect(array('action'=>'index'));
- }
+ }
- if (!empty($this->data)) {
- /* Remove all whitespace and non-digit characters from the user input */
- $this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
- if ($this->Customer->saveAll($this->data)) {
- $this->Session->setFlash(__('The Customer has been saved', true));
- $id = $this->Customer->id;
- $this->redirect(array('action'=>'view/'.$id));
- } else {
- $this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true));
-
- $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
- $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
- 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->Customer->read(null, $id);
-
- $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
- $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
- 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
- }
+ function view($id = null) {
+ if (!$id) {
+ $this->Session->setFlash(__('Invalid Customer.', true));
+ $this->redirect(array('action'=>'index'));
+ }
+ $this->set('customer', $this->Customer->read(null, $id));
+ $this->set('addresses', $this->Customer->Address->findAllByCustomerId($id));
+ $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.customer_id' => $id)));
+ $this->set('contacts', $this->Customer->Contact->find('all', array('conditions' => array('customer_id' => $id), 'order' => 'Contact.last_name ASC')));
- }
-
- /* Autocomplete the customer name - Used in: add.ctp */
- function completeCustomer() {
+
+
+ $statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0));
+ $status_list = array();
+ foreach ($statuses as $status) {
+ $statusid = $status['Status']['id'];
+ $status_list[$statusid] = $status['Status']['name'];
+ }
+ $this->set('status_list', $status_list);
+
+
+ $this->set('parent_industry_list', $this->Customer->Industry->find('list', array('conditions' => array('parent_id' => null))));
+ }
+
+ function add() {
+ if (!empty($this->data)) {
+
+ /* Remove all whitespace and non-digit characters from the user input */
+ $this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
+
+
+ if($this->Customer->saveAll($this->data, array('validate'=>'first')) ) {
+ $newcustomerid = $this->Customer->id;
+ $this->Session->setFlash(__('The Customer has been saved', true));
+ $this->redirect(array('action'=>'view', 'id'=>$newcustomerid));
+ }
+
+ }
+ $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
+ $this->set('states', $this->Customer->Address->State->find('list'));
+ //$this->set('countries', $this->Customer->Country->find('list', array('order'=>array('Country.name ASC'))));
+
+ }
+
+
+ function edit($id = null) {
+
+ if (!$id && empty($this->data)) {
+ $this->Session->setFlash(__('Invalid Customer', true));
+ $this->redirect(array('action'=>'index'));
+ }
+
+ if (!empty($this->data)) {
+ /* Remove all whitespace and non-digit characters from the user input */
+ $this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
+ if ($this->Customer->saveAll($this->data)) {
+ $this->Session->setFlash(__('The Customer has been saved', true));
+ $id = $this->Customer->id;
+ $this->redirect(array('action'=>'view/'.$id));
+ } else {
+ $this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true));
+
+ $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
+ $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
+ 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
+ }
+ }
+ if (empty($this->data)) {
+ $this->data = $this->Customer->read(null, $id);
+
+ $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
+ $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
+ 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
+ }
+
+ }
+
+ /* Autocomplete the customer name - Used in: find.ctp */
+ function completeCustomer() {
$query = strtolower($_GET["term"]);
-
+
+ //$this->set('customers_json', print_r($this->data));
+
if($query == null) {
return;
}
@@ -113,12 +115,12 @@ class CustomersController extends AppController {
App::import('Core', 'Sanitize');
$query = Sanitize::clean($query);
-
+
$customers = $this->Customer->find('all', array(
- 'conditions' => array(
- 'Customer.name LIKE' => '%'.$query.'%'
- ),'fields' => array('Customer.name'),
- 'order' => array('Customer.name ASC')
+ 'conditions' => array(
+ 'Customer.name LIKE' => '%'.$query.'%'
+ ),'fields' => array('Customer.name'),
+ 'order' => array('Customer.name ASC')
@@ -129,55 +131,77 @@ class CustomersController extends AppController {
$custid = $customer['Customer']['id'];
$cust_list[] = array('id'=> $custid, 'label' => $customer['Customer']['name']);
}
-
+
$customers_json = json_encode($cust_list);
- $this->set('customers_json', $customers_json);
+ $this->set('customers_json', $customers_json);
$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 tagindustries($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid Customer', true));
- $this->redirect(array('action'=>'index'));
- }
- if(!empty($this->data)) {
- if($this->Customer->saveAll($this->data)) {
- $this->Session->setFlash(__('The Industry Tags have been Saved to the Customer', true));
- $this->redirect(array('action'=>'view/'.$this->data['Customer']['id']));
- }
- else {
- $this->Session->setFlash(__('Something went wrong saving the Tags. Call for help!', true));
- $this->redirect(array('action'=>'index'));
- }
- }
- else {
- $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
- 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
- $this->data = $this->Customer->read(null, $id);
- }
- }
+ }
+
+
+ function similarCustomers() {
+ App::import('Core', 'Sanitize');
+
+ $query = Sanitize::clean($this->data['Customer']['name']);
+
+
+ $customers = $this->Customer->find('all', array(
+ 'conditions' => array(
+ 'Customer.name LIKE' => '%'.$query.'%'
+ ),'fields' => array('Customer.name'),
+ 'order' => array('Customer.name ASC')
+
+
+
+ ));
+
+
+ $this->set('customers', $customers);
+ $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 tagindustries($id = null) {
+ if (!$id && empty($this->data)) {
+ $this->Session->setFlash(__('Invalid Customer', true));
+ $this->redirect(array('action'=>'index'));
+ }
+ if(!empty($this->data)) {
+ if($this->Customer->saveAll($this->data)) {
+ $this->Session->setFlash(__('The Industry Tags have been Saved to the Customer', true));
+ $this->redirect(array('action'=>'view/'.$this->data['Customer']['id']));
+ }
+ else {
+ $this->Session->setFlash(__('Something went wrong saving the Tags. Call for help!', true));
+ $this->redirect(array('action'=>'index'));
+ }
+ }
+ else {
+ $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
+ 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
+ $this->data = $this->Customer->read(null, $id);
+ }
+ }
+
-
}
?>
diff --git a/views/customers/add.ctp b/views/customers/add.ctp
index fffb1b2e..75c92c23 100755
--- a/views/customers/add.ctp
+++ b/views/customers/add.ctp
@@ -8,8 +8,7 @@
input('name', array('id'=>'customerName'));
- echo "
If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "
Do Not Add Duplicates.";
-
+
echo $form->input('country_name', array('default'=>'Australia'));
echo $form->input('country_id', array('type'=>'hidden', 'value'=>1));
@@ -44,3 +43,9 @@
+
Please confirm the customer you are adding is not one of these customers:
+