diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index eaebeb67..511edb8d 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -34,6 +34,8 @@ class CustomersController extends AppController { $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'))); + $this->set('invoices', $this->Customer->Invoice->find('all', array('conditions'=>array('Invoice.customer_id'=>$id), 'order'=> 'Invoice.id DESC'))); + $this->set('jobs', $this->Customer->Job->find('all', array('conditions'=>array('Job.customer_id'=>$id), 'order'=> 'Job.id DESC'))); $statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0)); diff --git a/controllers/email_attachments_controller.php b/controllers/email_attachments_controller.php index 63b1d1a1..1bcc63bd 100755 --- a/controllers/email_attachments_controller.php +++ b/controllers/email_attachments_controller.php @@ -55,6 +55,12 @@ class EmailAttachmentsController extends AppController { $contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']); + + if($file['EmailAttachment']['type'] == 'text/plain') { + $contents = nl2br($contents, true); + } + + $this->set('contents', $contents); } diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index 7cc5d990..58f25c88 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -481,16 +481,21 @@ class EnquiriesController extends AppController { if(count($words) == 2) { $contactConditions = array('AND'=>array('Contact.first_name LIKE' => "%$words[0]%", - 'Contact.last_name LIKE' => "%$words[1]%")); + 'Contact.last_name LIKE' => "%$words[1]%")); } else { $contactConditions = array('OR'=>array('Contact.first_name LIKE' => "%$searchQuery%", 'Contact.last_name LIKE' => "%$searchQuery%")); } - $customerResults = $this->Enquiry->Customer->find('all', array('conditions' => $custConditions, 'recursive'=>0)); - $enquiryResults = $this->Enquiry->find('all', array('conditions'=>$enqConditions, 'recursive'=>0)); - $contactResults = $this->Enquiry->Contact->find('all', array('conditions'=>$contactConditions, 'recursive'=>0)); + $customerFields = array('Customer.id', 'Customer.name'); + $enquiryFields = array('Enquiry.id', 'Enquiry.title', 'Customer.name', 'Customer.id'); + $contactFields = array('Contact.id', 'Contact.type','Contact.customer_id', 'Contact.first_name','Contact.last_name', 'Customer.name'); + + + $customerResults = $this->Enquiry->Customer->find('all', array('conditions' => $custConditions, 'recursive'=>0, 'fields'=>$customerFields)); + $enquiryResults = $this->Enquiry->find('all', array('conditions'=>$enqConditions, 'recursive'=>0, 'fields'=>$enquiryFields)); + $contactResults = $this->Enquiry->Contact->find('all', array('conditions'=>$contactConditions, 'recursive'=>0, 'fields'=>$contactFields)); $searchDone = true; diff --git a/controllers/invoices_controller.php b/controllers/invoices_controller.php index 424e821c..f8ade88c 100755 --- a/controllers/invoices_controller.php +++ b/controllers/invoices_controller.php @@ -2,7 +2,7 @@ class InvoicesController extends AppController { var $name = 'Invoices'; - var $helpers = array('Html', 'Form', 'Time'); + var $helpers = array('Html', 'Form', 'Time', 'Text','Javascript'); var $paginate = array( @@ -21,7 +21,17 @@ class InvoicesController extends AppController { $this->Session->setFlash(__('Invalid Invoice.', true)); $this->redirect(array('action'=>'index')); } - $this->set('invoice', $this->Invoice->read(null, $id)); + $invoice = $this->Invoice->read(null, $id); + $this->set('invoice', $invoice); + + $emailIDs = array(); + foreach($invoice['Email'] as $email) { + $emailIDs[] = $email['id']; + } + $emails = $this->Invoice->Email->find('all', array('conditions'=>array('Email.id'=>$emailIDs))); + $this->set('emails', $emails); + + } diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php index 484e6cce..20bada3e 100755 --- a/controllers/jobs_controller.php +++ b/controllers/jobs_controller.php @@ -2,156 +2,167 @@ class JobsController extends AppController { var $name = 'Jobs'; - var $helpers = array('Html', 'Form'); + var $helpers = array('Html', 'Form', 'Text', 'Javascript'); var $components = array('RequestHandler'); - - var $paginate = array( - 'contain' => false, - 'limit' => 100, - 'order'=>array('Job.id' => 'desc') + var $paginate = array( + + 'contain' => false, + 'limit' => 100, + 'order'=>array('Job.id' => 'desc') ); function index() { - //$this->Job->recursive = 1; - $this->set('jobs', $this->paginate()); - $this->set('customers', $this->Job->Enquiry->Customer->find('list')); - $this->set('currencies', $this->Job->Currency->find('list')); + //$this->Job->recursive = 1; + $this->set('jobs', $this->paginate()); + $this->set('customers', $this->Job->Enquiry->Customer->find('list')); + $this->set('currencies', $this->Job->Currency->find('list')); } function view($id = null) { - if (!$id) { - $this->flash(__('Invalid Job', true), array('action'=>'index')); - } + if (!$id) { + $this->flash(__('Invalid Job', true), array('action'=>'index')); + } - $job = $this->Job->read(null, $id); - $this->set('job', $job); - $this->set('customer', $this->Job->Enquiry->Customer->findById($job['Enquiry']['customer_id'])); + $job = $this->Job->read(null, $id); + + $emailIDs = array(); + foreach($job['Email'] as $email) { + $emailIDs[] = $email['id']; + } + $emails = $this->Job->Email->find('all', array('conditions'=>array('Email.id'=>$emailIDs))); + $this->set('emails', $emails); + + + + + $this->set('job', $job); + $this->set('customer', $this->Job->Enquiry->Customer->findById($job['Enquiry']['customer_id'])); $this->set('principles', $this->Job->PurchaseOrder->Principle->find('list')); - $this->pageTitle = $job['Job']['title']; + $this->pageTitle = $job['Job']['title']; } function add() { - - if (!empty($this->data)) { - $this->Job->create(); - $job_offset = 6141; + if (!empty($this->data)) { + $this->Job->create(); - $number_of_jobs = $this->Job->findCount(); - $new_job_number = $job_offset + $number_of_jobs; + $job_offset = 6141; - $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); + $number_of_jobs = $this->Job->findCount(); + $new_job_number = $job_offset + $number_of_jobs; + + $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); - $monthYearShort = strtoupper(date("My")); + $monthYearShort = strtoupper(date("My")); - $jobLetter = $enquiry['State']['enqform']; + $jobLetter = $enquiry['State']['enqform']; - $this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number; + $this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number; - if ($this->Job->save($this->data)) { - $jobid = $this->Job->id; + if ($this->Job->save($this->data)) { + $jobid = $this->Job->id; - //$this->Job->Enquiry->set('status_id', 3); //Change status to 'Job Won'; - $enquiry['Enquiry']['status_id'] = 3; + //$this->Job->Enquiry->set('status_id', 3); //Change status to 'Job Won'; + $enquiry['Enquiry']['status_id'] = 3; - $this->Job->Enquiry->save($enquiry); + $this->Job->Enquiry->save($enquiry); - $this->Session->setFlash(__('Job Saved', true)); - $this->redirect(array('action'=>'view', $jobid)); - } else { - $this->Session->setFlash(__('Please Fix the Errors Below', true)); - $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); - $this->set(compact('enquiry')); - } - } - else { - if(isset($this->params['named']['enquiryid'])) { + $this->Session->setFlash(__('Job Saved', true)); + $this->redirect(array('action'=>'view', $jobid)); + } else { + $this->Session->setFlash(__('Please Fix the Errors Below', true)); + $enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']); + $this->set(compact('enquiry')); + } + } + else { + if(isset($this->params['named']['enquiryid'])) { - $enquiry = $this->Job->Enquiry->findById($this->params['named']['enquiryid']); - - $this->set(compact('enquiry')); - } - else { - $this->Session->setFlash(__('Invalid Enquiry ID', true)); - $this->redirect(array('action'=>'index')); - } - } + $enquiry = $this->Job->Enquiry->findById($this->params['named']['enquiryid']); - $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); - $this->set('freight_paid_options', $freight_paid_options); + $this->set(compact('enquiry')); + } + else { + $this->Session->setFlash(__('Invalid Enquiry ID', true)); + $this->redirect(array('action'=>'index')); + } + } - $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); - $this->set('sale_category_options', $sale_category_options); + $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); + $this->set('freight_paid_options', $freight_paid_options); - $shipment_category_options = array( - "AUSTRALIA"=>"AUSTRALIA", - "EXPORT"=>"EXPORT", - "DIRECT-INTL"=>"DIRECT-INTL", - "DIRECT-AUST"=>"DIRECT-AUST", - "NO-SHIP"=>"NO-SHIP" - ); - $this->set('shipment_category_options', $shipment_category_options); + $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); + $this->set('sale_category_options', $sale_category_options); - } + $shipment_category_options = array( + "AUSTRALIA"=>"AUSTRALIA", + "EXPORT"=>"EXPORT", + "DIRECT-INTL"=>"DIRECT-INTL", + "DIRECT-AUST"=>"DIRECT-AUST", + "NO-SHIP"=>"NO-SHIP" + ); + $this->set('shipment_category_options', $shipment_category_options); + + } function edit($id = null) { - if (!$id && empty($this->data)) { - $this->flash(__('Invalid Job', true), array('action'=>'index')); - } - if (!empty($this->data)) { - $jobid = $this->data['Job']['id']; - if ($this->Job->save($this->data)) { - // $this->flash(__('The Job has been saved.', true), array('action'=>'view', $jobid)); + if (!$id && empty($this->data)) { + $this->flash(__('Invalid Job', true), array('action'=>'index')); + } + if (!empty($this->data)) { + $jobid = $this->data['Job']['id']; + if ($this->Job->save($this->data)) { + // $this->flash(__('The Job has been saved.', true), array('action'=>'view', $jobid)); - $this->Session->setFlash(__('The Job has been saved', true)); + $this->Session->setFlash(__('The Job has been saved', true)); - $this->redirect(array('action' =>'view/'.$jobid), null, false); + $this->redirect(array('action' =>'view/'.$jobid), null, false); - } else { - } - } - if (empty($this->data)) { - $job = $this->Job->read(null, $id); - $this->data = $job; - $this->set('currencies', $this->Job->Currency->find('list')); + } else { + } + } + if (empty($this->data)) { + $job = $this->Job->read(null, $id); + $this->data = $job; + $this->set('currencies', $this->Job->Currency->find('list')); - } + } - $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); - $this->set('freight_paid_options', $freight_paid_options); + $freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer"); + $this->set('freight_paid_options', $freight_paid_options); - $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); - $this->set('sale_category_options', $sale_category_options); + $sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION"); + $this->set('sale_category_options', $sale_category_options); - $shipment_category_options = array( - "AUSTRALIA"=>"AUSTRALIA", - "EXPORT"=>"EXPORT", - "DIRECT-INTL"=>"DIRECT-INTL", - "DIRECT-AUST"=>"DIRECT-AUST", - "NO-SHIP"=>"NO-SHIP" - ); - $this->set('shipment_category_options', $shipment_category_options); + $shipment_category_options = array( + "AUSTRALIA"=>"AUSTRALIA", + "EXPORT"=>"EXPORT", + "DIRECT-INTL"=>"DIRECT-INTL", + "DIRECT-AUST"=>"DIRECT-AUST", + "NO-SHIP"=>"NO-SHIP" + ); + $this->set('shipment_category_options', $shipment_category_options); } -/* + /* function delete($id = null) { if (!$id) { $this->flash(__('Invalid Job', true), array('action'=>'index')); @@ -160,18 +171,27 @@ class JobsController extends AppController { $this->flash(__('Job deleted', true), array('action'=>'index')); } } -*/ + */ function __isNotEmptyDate($date) { - if($date == "0000-00-00") { - return true; - } - else { - return false; - } + if($date == "0000-00-00") { + return true; + } + else { + return false; + } + } + /** + * Need to fix the customer_id which hasn't been set for these 500odd records. + * + * Will fetch the right ID the same way the Index does, then update each record. + */ + function fixCustomerIDs() { + + } } ?> \ No newline at end of file diff --git a/models/customer.php b/models/customer.php index 94f8fc81..eaa35db3 100755 --- a/models/customer.php +++ b/models/customer.php @@ -1,95 +1,99 @@ array( - 'rule' => 'isUnique', - 'message' => 'This Customer name is already taken or has been left blank', - 'required' => true, - 'allowEmpty' => false), - - - - 'abn' => array( - 'rule' => 'checkABN', - 'required' => false, - 'message' => 'ABN must contain 11 digits', - 'allowEmpty' => true, - ) - ); - - - /* 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', - 'foreignKey' => 'customer_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ), - 'Contact' => array('className' => 'User', - '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' => '' - ) - ); + var $validate = array( + 'name' => array( + 'rule' => 'isUnique', + 'message' => 'This Customer name is already taken or has been left blank', + 'required' => true, + 'allowEmpty' => false), - var $belongsTo = array('CustomerCategory'=> - array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id'), - 'Country' => - array('className' =>'Country', 'foreignKey' => 'country_id') - ); + 'abn' => array( + 'rule' => 'checkABN', + 'required' => false, + 'message' => 'ABN must contain 11 digits', + 'allowEmpty' => true, + ) + ); - - var $hasAndBelongsToMany = array ( - 'Industry' => array( - 'className' => 'Industry', - 'joinTable' => 'industries_customers', - 'foreignKey' => 'customer_id', - 'associationForeignKey' => 'industry_id' - ) - ); + /* 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', + 'foreignKey' => 'customer_id', + 'dependent' => false, + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ), + 'Contact' => array('className' => 'User', + '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' => '' + ), + 'Invoice' => array('className'=>'Invoice', + 'foreignKey' => 'customer_id'), + 'Job' => array('className'=>'Job', + 'foreignKey' => 'customer_id') + ); + + + + var $belongsTo = array('CustomerCategory'=> + array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id'), + 'Country' => + array('className' =>'Country', 'foreignKey' => 'country_id') + ); + + + + var $hasAndBelongsToMany = array ( + 'Industry' => array( + 'className' => 'Industry', + 'joinTable' => 'industries_customers', + 'foreignKey' => 'customer_id', + 'associationForeignKey' => 'industry_id' + ) + ); } ?> \ No newline at end of file diff --git a/models/enquiry.php b/models/enquiry.php index 82792a46..b6000854 100755 --- a/models/enquiry.php +++ b/models/enquiry.php @@ -118,7 +118,7 @@ class Enquiry extends AppModel { ),*/ 'Contact' => array('className' => 'User', 'foreignKey' => 'contact_user_id', - 'conditions' => '', + 'conditions' => array('Contact.type'=>'contact'), 'fields' => '', 'order' => '' ), diff --git a/models/invoice.php b/models/invoice.php index 4848ee91..de7bb54f 100755 --- a/models/invoice.php +++ b/models/invoice.php @@ -41,5 +41,14 @@ class Invoice extends AppModel { ) ); + + var $hasAndBelongsToMany = array( + + 'Email' => array( + 'className' => 'Email', + 'joinTable' => 'emails_invoices', + ) + ); + } ?> \ No newline at end of file diff --git a/models/job.php b/models/job.php index 9a6e2a55..ca106f8e 100755 --- a/models/job.php +++ b/models/job.php @@ -3,42 +3,46 @@ class Job extends AppModel { var $name = 'Job'; var $validate = array( - 'title' => array('notempty'), + 'title' => array('notempty'), - 'enquiry_id' => array('numeric'), + 'enquiry_id' => array('numeric'), - 'date_order_received' => array('date'), + 'date_order_received' => array('date'), - 'domestic_freight_paid_by' => array('notempty'), - 'sale_category' => array('notempty'), - 'shipment_category' => array('notempty') + 'domestic_freight_paid_by' => array('notempty'), + 'sale_category' => array('notempty'), + 'shipment_category' => array('notempty') ); - + //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( - 'Enquiry' => array( - 'className' => 'Enquiry', - 'foreignKey' => 'enquiry_id', - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'counterCache' => true - ), + 'Enquiry' => array( + 'className' => 'Enquiry', + 'foreignKey' => 'enquiry_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => true + ), - 'Currency' + 'Currency' ); - var $hasAndBelongsToMany = array( - 'PurchaseOrder' => array( - 'className' => 'PurchaseOrder', - 'joinTable' => 'jobs_purchase_orders', - 'unique' => true - ) - ); + var $hasAndBelongsToMany = array( + 'PurchaseOrder' => array( + 'className' => 'PurchaseOrder', + 'joinTable' => 'jobs_purchase_orders', + 'unique' => true + ), + 'Email' => array( + 'className' => 'Email', + 'joinTable' => 'emails_jobs', + ) + ); } ?> \ No newline at end of file diff --git a/models/principle.php b/models/principle.php index 9e0468e3..a53a938d 100755 --- a/models/principle.php +++ b/models/principle.php @@ -1,59 +1,59 @@ array('className' => 'Country', - 'foreignKey' => 'country_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Currency' => array('className' => 'Currency', - 'foreignKey' => 'currency_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); + //The Associations below have been created with all possible keys, those that are not needed can be removed + var $belongsTo = array( + 'Country' => array('className' => 'Country', + 'foreignKey' => 'country_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ), + 'Currency' => array('className' => 'Currency', + 'foreignKey' => 'currency_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); - var $hasMany = array( - 'Enquiry' => array('className' => 'Enquiry', - 'foreignKey' => 'principle_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ), - 'Product' => array('className' => 'Product', - 'foreignKey' => 'principle_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ), - 'PrincipleAddress' => array('className' => 'PrincipleAddress', - 'foreignKey' => 'principle_id' - ), - - 'PrincipleContact' => array('className' => 'Users', - 'foreignKey' => 'principle_id' - ), - ); + var $hasMany = array( + 'Enquiry' => array('className' => 'Enquiry', + 'foreignKey' => 'principle_id', + 'dependent' => false, + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ), + 'Product' => array('className' => 'Product', + 'foreignKey' => 'principle_id', + 'dependent' => false, + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ), + 'PrincipleAddress' => array('className' => 'PrincipleAddress', + 'foreignKey' => 'principle_id' + ), + + 'PrincipleContact' => array('className' => 'Users', + 'foreignKey' => 'principle_id' + ), + ); } ?> diff --git a/views/customers/view.ctp b/views/customers/view.ctp index a27405a3..c5b5f51e 100755 --- a/views/customers/view.ctp +++ b/views/customers/view.ctp @@ -145,22 +145,6 @@ -
-