2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class Customer extends AppModel {
|
|
|
|
|
|
|
|
|
|
var $name = 'Customer';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $validate = array(
|
|
|
|
|
'name' => array(
|
|
|
|
|
'rule' => 'isUnique',
|
|
|
|
|
'message' => 'This Customer name is already taken or has been left blank',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'allowEmpty' => false),
|
|
|
|
|
|
2009-07-12 23:55:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
'abn' => array(
|
|
|
|
|
'rule' => 'checkABN',
|
2009-07-16 21:57:44 -07:00
|
|
|
'required' => true,
|
|
|
|
|
'message' => 'ABN must contain 11 digits',
|
|
|
|
|
'allowEmpty' => true,
|
|
|
|
|
)
|
2009-01-12 21:13:18 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2009-07-12 23:55:17 -07:00
|
|
|
/* 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.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
//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',
|
|
|
|
|
'foreignKey' => 'customer_id',
|
|
|
|
|
'dependent' => false,
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => '',
|
|
|
|
|
'limit' => '',
|
|
|
|
|
'offset' => '',
|
|
|
|
|
'exclusive' => '',
|
|
|
|
|
'finderQuery' => '',
|
|
|
|
|
'counterQuery' => ''
|
|
|
|
|
),
|
|
|
|
|
'Contact' => array('className' => 'Contact',
|
|
|
|
|
'foreignKey' => 'customer_id',
|
|
|
|
|
'dependent' => false,
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => '',
|
|
|
|
|
'limit' => '',
|
|
|
|
|
'offset' => '',
|
|
|
|
|
'exclusive' => '',
|
|
|
|
|
'finderQuery' => '',
|
|
|
|
|
'counterQuery' => ''
|
|
|
|
|
),
|
|
|
|
|
'Enquiry' => array('className' => 'Enquiry',
|
|
|
|
|
'foreignKey' => 'customer_id',
|
|
|
|
|
'dependent' => false,
|
|
|
|
|
'conditions' => '',
|
|
|
|
|
'fields' => '',
|
|
|
|
|
'order' => '',
|
|
|
|
|
'limit' => '',
|
|
|
|
|
'offset' => '',
|
|
|
|
|
'exclusive' => '',
|
|
|
|
|
'finderQuery' => '',
|
|
|
|
|
'counterQuery' => ''
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-02-11 20:02:05 -08:00
|
|
|
|
|
|
|
|
var $belongsTo = array('CustomerCategory'=>array('className' => 'CustomerCategory',
|
|
|
|
|
'foreignKey' => 'customer_category_id'));
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2009-07-02 18:11:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var $hasAndBelongsToMany = array (
|
|
|
|
|
'Industry' => array(
|
|
|
|
|
'className' => 'Industry',
|
|
|
|
|
'joinTable' => 'industries_customers',
|
|
|
|
|
'foreignKey' => 'customer_id',
|
2009-07-09 00:09:59 -07:00
|
|
|
'associationForeignKey' => 'industry_id'
|
2009-07-02 18:11:22 -07:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
?>
|