diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 28b7cc8a..e136dfbd 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -43,7 +43,11 @@ class CustomersController extends AppController { 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)); @@ -68,16 +72,24 @@ class CustomersController extends AppController { } 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'))); @@ -130,5 +142,9 @@ class CustomersController extends AppController { $this->data = $this->Customer->read(null, $id); } } + + + + } ?> diff --git a/models/customer.php b/models/customer.php index 5c0fe723..e65b5cb2 100755 --- a/models/customer.php +++ b/models/customer.php @@ -10,20 +10,26 @@ class Customer extends AppModel { 'message' => 'This Customer name is already taken or has been left blank', 'required' => true, 'allowEmpty' => false), - 'abn' => array( - 'numbers' => array( - 'rule' => 'numeric', - 'message' => 'ABN must only contain numbers - no letters or punctuation', - 'required' => true, - 'allowEmpty' => true), - 'minlength' => array( - 'rule' => array('minLength', '11'), - 'message' => 'ABN must be exactly 11 numbers long') + + + 'abn' => array( + 'rule' => 'checkABN', + 'message' => 'ABN must contain 11 digits' ) ); + /* Custom Validation for ABN */ + + function checkABN($data) { + $numbers = preg_replace("/\s*\D*/", "", $data['abn']); + $length = strlen($numbers); + return $length == 11; + //ABNs must be exactly 11 digits long. + } + + //The Associations below have been created with all possible keys, those that are not needed can be removed var $hasMany = array( 'Address' => array('className' => 'Address', diff --git a/views/addresses/view.ctp b/views/addresses/view.ctp index 31e500e2..ade47ae3 100755 --- a/views/addresses/view.ctp +++ b/views/addresses/view.ctp @@ -1,16 +1,7 @@

- > - > - -   - - > - > - -   - + > > @@ -21,11 +12,19 @@   + > > link($address['State']['name'], array('controller'=> 'states', 'action'=>'view', $address['State']['id'])); ?>   + + > + > + +   + + > > link($address['Country']['name'], array('controller'=> 'countries', 'action'=>'view', $address['Country']['id'])); ?> diff --git a/views/customers/add.ctp b/views/customers/add.ctp index 55600527..32835265 100755 --- a/views/customers/add.ctp +++ b/views/customers/add.ctp @@ -8,13 +8,12 @@
input('name', array('label'=>'Company Name', 'title' => 'The Company Name. Eg. XYZ Business Pty Ltd')); echo '
'; echo $form->label('Customer.name', 'Company Name'); echo $ajax->autoComplete('name', '/customers/completeCustomer'); 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 '
'; - echo $form->input('abn', array('label'=>'ABN', 'title' => 'The 11-digit Australian Business Number for the new Customer. Enter numbers only, no dashes or punctuation')); + echo $form->input('abn', array('label'=>'ABN', 'title' => 'The 11-digit Australian Business Number for the new Customer. Spaces or no spaces - it does not matter')); echo $this->element('payment_terms_box'); echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies')); @@ -23,7 +22,7 @@ echo $form->select('customer_category_id', $customer_categories, 0, array('label'=>'Customer Category'), false); echo '
'; echo $form->input('notes', array('label' => 'Notes about this Customer')); - + echo $form->input('url', array('label'=>'Website URL')); echo '

'; ?>
diff --git a/views/customers/edit.ctp b/views/customers/edit.ctp index c15a2b62..70bc683c 100755 --- a/views/customers/edit.ctp +++ b/views/customers/edit.ctp @@ -8,7 +8,8 @@ echo $form->input('abn'); echo $this->element('payment_terms_box'); echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies')); - echo $form->input('notes'); + echo $form->input('notes'); + echo $form->input('url', array('label'=>'Website URL')); echo '
'; echo $form->label('Customer.customer_category_id', 'Customer Category'); echo $form->select('customer_category_id', $customer_categories, $this->data['Customer']['customer_category_id'], array('label'=>'Customer Category'), false); diff --git a/views/customers/index.ctp b/views/customers/index.ctp index 256b0822..44ff785a 100755 --- a/views/customers/index.ctp +++ b/views/customers/index.ctp @@ -49,7 +49,8 @@ foreach ($customers as $customer): link(__($customer['Customer']['name'], true), array('action'=>'view', $customer['Customer']['id'])); ?> - + link($this->element('abn', array('abn'=>$customer['Customer']['abn'])), 'http://www.abr.business.gov.au/abnDetails.aspx?ABN='.$customer['Customer']['abn'], + array('target'=>'_blank')); ?> diff --git a/views/customers/view.ctp b/views/customers/view.ctp index e7c58c71..81cf10d2 100755 --- a/views/customers/view.ctp +++ b/views/customers/view.ctp @@ -8,7 +8,8 @@ > > - + link($this->element('abn', array('abn'=>$customer['Customer']['abn'])), 'http://www.abr.business.gov.au/abnDetails.aspx?ABN='.$customer['Customer']['abn'], + array('target'=>'_blank')); ?>   > @@ -26,11 +27,21 @@   + > >   + + + > + > + link($customer['Customer']['url'], $customer['Customer']['url'], array('target'=>'_blank'));; ?> +   + + + > > @@ -46,24 +57,6 @@
- - -