ABN validation made better. SQL changes to Contacts, Prinicple Contacts, extra fields added
This commit is contained in:
parent
4723ae59d1
commit
a6aedb0198
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
<div class="addresses view">
|
||||
<h2><?php __('Address');?></h2>
|
||||
<dl><?php $i = 0; $class = ' class="altrow"';?>
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $address['Address']['id']; ?>
|
||||
|
||||
</dd>
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $address['Address']['name']; ?>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Address'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $address['Address']['address']; ?>
|
||||
|
|
@ -21,11 +12,19 @@
|
|||
<?php echo $address['Address']['city']; ?>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('State'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $html->link($address['State']['name'], array('controller'=> 'states', 'action'=>'view', $address['State']['id'])); ?>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Post Code'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $address['Address']['postcode']; ?>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Country'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $html->link($address['Country']['name'], array('controller'=> 'countries', 'action'=>'view', $address['Country']['id'])); ?>
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@
|
|||
<fieldset>
|
||||
<legend><?php __('Add Customer');?></legend>
|
||||
<?php
|
||||
//echo $form->input('name', array('label'=>'Company Name', 'title' => 'The Company Name. Eg. XYZ Business Pty Ltd'));
|
||||
echo '<div class="input text">';
|
||||
echo $form->label('Customer.name', 'Company Name');
|
||||
echo $ajax->autoComplete('name', '/customers/completeCustomer');
|
||||
echo "<br><br><span class=\"warning\">If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "<br>Do Not Add Duplicates.</span>";
|
||||
echo '</div>';
|
||||
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 '</div>';
|
||||
echo $form->input('notes', array('label' => 'Notes about this Customer'));
|
||||
|
||||
echo $form->input('url', array('label'=>'Website URL'));
|
||||
echo '<br><br>';
|
||||
?>
|
||||
<div id="contacts0">
|
||||
|
|
|
|||
|
|
@ -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 '<div class="input select">';
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ foreach ($customers as $customer):
|
|||
<?php echo $html->link(__($customer['Customer']['name'], true), array('action'=>'view', $customer['Customer']['id'])); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $customer['Customer']['abn']; ?>
|
||||
<?php echo $html->link($this->element('abn', array('abn'=>$customer['Customer']['abn'])), 'http://www.abr.business.gov.au/abnDetails.aspx?ABN='.$customer['Customer']['abn'],
|
||||
array('target'=>'_blank')); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $customer['Customer']['payment_terms']; ?>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
</dd>
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('ABN'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $customer['Customer']['abn']; ?>
|
||||
<?php echo $html->link($this->element('abn', array('abn'=>$customer['Customer']['abn'])), 'http://www.abr.business.gov.au/abnDetails.aspx?ABN='.$customer['Customer']['abn'],
|
||||
array('target'=>'_blank')); ?>
|
||||
|
||||
</dd>
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Record Created'); ?></dt>
|
||||
|
|
@ -26,11 +27,21 @@
|
|||
<?php echo $customer['Customer']['payment_terms']; ?>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('URL'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $html->link($customer['Customer']['url'], $customer['Customer']['url'], array('target'=>'_blank'));; ?>
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Category'); ?></dt>
|
||||
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
|
||||
<?php echo $customer['CustomerCategory']['name']; ?>
|
||||
|
|
@ -46,24 +57,6 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="related">
|
||||
<h3><?php __('Industries that this Customer has been tagged in'); ?></h3>
|
||||
<?php if(!empty($customer['Industry'])): ?>
|
||||
<ul id="industrytaglist">
|
||||
<?php foreach ($customer['Industry'] as $industry) {
|
||||
echo "<li>".$html->link(__($industry['name'],true), array('action'=>'view', 'controller'=>'industries', $industry['id']))."</li>";
|
||||
|
||||
}
|
||||
echo "</ul>";
|
||||
endif;
|
||||
echo "<br>";
|
||||
echo "<div class=\"actions\">".$html->link("Tag Industries for this Customer", array('action'=>'tagindustries',$customer['Customer']['id']))."</div>";
|
||||
?>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="related">
|
||||
<h3><?php __('Contacts');?><?php echo $html->image('system-users.png'); ?></h3>
|
||||
<div class="actions">
|
||||
|
|
@ -109,7 +102,10 @@ echo "<div class=\"actions\">".$html->link("Tag Industries for this Customer", a
|
|||
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
18
views/elements/abn.ctp
Normal file
18
views/elements/abn.ctp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?
|
||||
|
||||
if(strlen($abn) == 11) {
|
||||
|
||||
for($i=0; $i<11; $i++) {
|
||||
if( ($i == 2) || ($i == 5) || ($i == 8) ) {
|
||||
echo " ";
|
||||
|
||||
}
|
||||
echo $abn[$i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo $abn;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
<th><?php __('Address'); ?></th>
|
||||
<th><?php __('City'); ?></th>
|
||||
<th><?php __('State'); ?></th>
|
||||
<th><?php __('Post Code'); ?></th>
|
||||
<th><?php __('Country'); ?></th>
|
||||
<th><?php __('Type'); ?></th>
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
<td><?php echo $address['Address']['address'];?></td>
|
||||
<td><?php echo $address['Address']['city'];?></td>
|
||||
<td><?php echo $html->link(__($address['State']['name'], true), array('controller'=>'states', 'action' => 'view', $address['State']['id']));?></td>
|
||||
<td><?php echo $address['Address']['postcode']; ?></td>
|
||||
<td><?php echo $html->link(__($address['Country']['name'], true), array('controller'=>'countries', 'action' => 'view', $address['Country']['id']));?></td>
|
||||
<td><?php
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue