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->set('sale_category_options', $this->sale_category_options()); $this->set('sale_category_array', $this->sale_category_array()); $this->set('job_type_options', $this->job_type_options()); $this->set('shipment_options', $this->shipment_options()); $this->set('freight_paid_by_options',$this->freight_paid_options()); $this->set('gst_options', $this->gst_options()); } /** Called via AJAX to get an editable row */ function getEditableRow($id) { $this->layout = 'ajax'; $this->set('job', $this->Job->find('first', array('conditions'=>array('Job.id'=>$id)))); $this->set('currencies', $this->Job->Currency->find('list')); $this->set('sale_category_options', $this->sale_category_options()); $this->set('sale_category_array', $this->sale_category_array()); $this->set('job_type_options', $this->job_type_options()); $this->set('shipment_options', $this->shipment_options()); $this->set('freight_paid_by_options',$this->freight_paid_options()); $this->set('gst_options', $this->gst_options()); $this->set('job_status_options', $this->job_status_options()); } /** Called via AJAX to get an viewable row */ function getViewableRow($id) { $this->layout = 'ajax'; $this->set('job', $this->Job->find('first', array('conditions'=>array('Job.id'=>$id)))); $this->set('sale_category_options', $this->sale_category_options()); $this->set('sale_category_array', $this->sale_category_array()); $this->set('job_type_options', $this->job_type_options()); $this->set('shipment_options', $this->shipment_options()); $this->set('freight_paid_by_options',$this->freight_paid_options()); $this->set('gst_options', $this->gst_options()); } function reports() { $this->Job->recursive = 1; $this->set('jobs', $this->Job->find('all', array('order'=>array('Job.date_order_received'=>'asc')))); $this->set('customers', $this->Job->Enquiry->Customer->find('list')); $this->set('currencies', $this->Job->Currency->find('list')); } function job_status_options() { $options = array('ORDER RECEIVED FROM CUSTOMER', 'ORDER PLACED ON PRINCIPLE - WAITING ON DELIVERY', 'GOODS SHIPPED TO CUSTOMER - CMC WAITING ON PAYMENT', 'WAITING ON PAYMENT AND ANOTHER DELIVERY', 'GOODS DELIVERED TO CUSTOMER - CMC PAID IN FULL', 'PAID IN FULL WAITING ON DELIVERY', 'JOB CANCELLED', 'JOB ON HOLD', 'CUSTOMER TO PAY 100% WITH ORDER'); $options = $this->buildEnumOpts($options); return $options; } /** * For the 'sale_category' column. */ function sale_category_options() { $options['Australian Sale'] = array( 0 => "Australian Customer & Australian Destination (GST Applies)", 1 => "Overseas Customer & Australian Destination (GST Applies)", 2 => "Commission from Australian Company or Supplier (GST Applies)", ); $options['Exports'] = array( 3 => "Overseas Customer & Overseas Destination (no GST)", 4 => "Australian Customer & Overseas Destination (no GST)", 5 => "Commission from Overseas Company (no GST)" ); return $options; } /** For viewing the sale Cat */ function sale_category_array() { $options = array( 0 => "Australian Customer & Australian Destination (GST Applies)", 1 => "Overseas Customer & Australian Destination (GST Applies)", 2 => "Commission from Australian Company or Supplier (GST Applies)", 3 => "Overseas Customer & Overseas Destination (no GST)", 4 => "Australian Customer & Overseas Destination (no GST)", 5 => "Commission from Overseas Company (no GST)" ); return $options; } /** * Build the Array for 'job_type' */ function job_type_options() { $options = array('INDENT','STOCK','COMMISSION','SERVICE'); $enumOpts = $this->buildEnumOpts($options); return $enumOpts; } function shipment_options() { $options = array('AUSTRALIA','EXPORT','DIRECT-INTL','DIRECT-AUST','NO-SHIP'); $enumOpts = $this->buildEnumOpts($options); return $enumOpts; } function freight_paid_options() { $options = array('CMC', 'CUSTOMER'); return $this->buildEnumOpts($options); } function gst_options() { $options = array(1=>'YES', 0=>'NO'); return $options; } function buildEnumOpts($options) { $enumOpts = array(); foreach($options as $opt) { $enumOpts[$opt] = $opt; } return $enumOpts; } function ajax_edit() { if(!empty($this->data)) { if ($this->Job->save($this->data)) { echo "SUCCESS"; } else { echo "FAILURE"; } } else { return; } } function view($id = null) { if (!$id) { $this->flash(__('Invalid Job', true), array('action'=>'index')); } $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']; } function save_jobs() { if(isset($this->data)) { //$data = json_decode($this->data); print_r($this->data); } } function add() { if (!empty($this->data)) { $this->Job->create(); $job_offset = 6141; $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")); $jobLetter = $enquiry['State']['enqform']; $this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number; $this->data['Job']['state_id'] = $enquiry['Enquiry']['state_id']; $this->data['Job']['customer_id'] = $enquiry['Enquiry']['customer_id']; $this->data['Job']['contact_id'] = $enquiry['Enquiry']['contact_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->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'])) { $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')); } } $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); $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)); $this->Session->setFlash(__('The Job has been saved', true)); $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')); } $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); $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')); } if ($this->Job->del($id)) { $this->flash(__('Job deleted', true), array('action'=>'index')); } } */ function __isNotEmptyDate($date) { 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 fixJobs() { $jobs = $this->Job->find('all'); foreach($jobs as $job) { $this->Job->id = $job['Job']['id']; $this->data = $job; $this->data['Job']['customer_id'] = $job['Enquiry']['customer_id']; $this->data['Job']['state_id'] = $job['Enquiry']['state_id']; $this->data['Job']['contact_id'] = $job['Enquiry']['contact_id']; $this->Job->save($this->data); } $this->set('jobs', $this->Job->find('all')); }*/ } ?>