2010-05-03 23:49:57 -07:00
|
|
|
<?php
|
|
|
|
|
class JobsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Jobs';
|
2011-03-13 17:21:56 -07:00
|
|
|
var $helpers = array('Html', 'Form', 'Text', 'Javascript');
|
2010-05-03 23:49:57 -07:00
|
|
|
|
2010-09-06 20:57:28 -07:00
|
|
|
var $components = array('RequestHandler');
|
2010-07-07 23:25:55 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
var $paginate = array(
|
|
|
|
|
|
|
|
|
|
'contain' => false,
|
|
|
|
|
'limit' => 100,
|
|
|
|
|
'order'=>array('Job.id' => 'desc')
|
2010-07-07 23:25:55 -07:00
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
function index() {
|
2011-03-13 17:21:56 -07:00
|
|
|
//$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'));
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
2011-03-13 17:21:56 -07:00
|
|
|
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);
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->set('job', $job);
|
|
|
|
|
$this->set('customer', $this->Job->Enquiry->Customer->findById($job['Enquiry']['customer_id']));
|
2010-09-06 20:57:28 -07:00
|
|
|
$this->set('principles', $this->Job->PurchaseOrder->Principle->find('list'));
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->pageTitle = $job['Job']['title'];
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add() {
|
2010-05-13 00:10:10 -07:00
|
|
|
|
|
|
|
|
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->Job->create();
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$job_offset = 6141;
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$number_of_jobs = $this->Job->findCount();
|
|
|
|
|
$new_job_number = $job_offset + $number_of_jobs;
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']);
|
2010-05-17 23:45:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$monthYearShort = strtoupper(date("My"));
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$jobLetter = $enquiry['State']['enqform'];
|
2010-05-17 23:45:38 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number;
|
2011-03-13 18:30:03 -07:00
|
|
|
$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'];
|
2010-05-13 15:37:05 -07:00
|
|
|
|
|
|
|
|
|
2010-05-13 00:10:10 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
if ($this->Job->save($this->data)) {
|
|
|
|
|
$jobid = $this->Job->id;
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
//$this->Job->Enquiry->set('status_id', 3); //Change status to 'Job Won';
|
|
|
|
|
$enquiry['Enquiry']['status_id'] = 3;
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->Job->Enquiry->save($enquiry);
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$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'])) {
|
2010-05-13 00:10:10 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$enquiry = $this->Job->Enquiry->findById($this->params['named']['enquiryid']);
|
2010-05-13 00:10:10 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->set(compact('enquiry'));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Enquiry ID', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-13 00:10:10 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
}
|
2010-05-03 23:49:57 -07:00
|
|
|
|
|
|
|
|
function edit($id = null) {
|
2011-03-13 17:21:56 -07:00
|
|
|
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));
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->Session->setFlash(__('The Job has been saved', true));
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$this->redirect(array('action' =>'view/'.$jobid), null, false);
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$job = $this->Job->read(null, $id);
|
|
|
|
|
$this->data = $job;
|
|
|
|
|
$this->set('currencies', $this->Job->Currency->find('list'));
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
}
|
2010-06-07 21:11:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$freight_paid_options = array("CMC"=>"CMC", "Customer"=>"Customer");
|
|
|
|
|
$this->set('freight_paid_options', $freight_paid_options);
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$sale_category_options = array("INDENT"=>"INDENT", "STOCK"=>"STOCK", "COMMISSION"=>"COMMISSION");
|
|
|
|
|
$this->set('sale_category_options', $sale_category_options);
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
$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);
|
2010-06-07 21:11:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
2011-03-13 17:21:56 -07:00
|
|
|
/*
|
2010-05-03 23:49:57 -07:00
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-13 17:21:56 -07:00
|
|
|
*/
|
2010-06-07 21:11:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
function __isNotEmptyDate($date) {
|
2011-03-13 17:21:56 -07:00
|
|
|
if($date == "0000-00-00") {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 21:11:06 -07:00
|
|
|
|
2011-03-13 17:21:56 -07:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2011-03-13 18:30:03 -07:00
|
|
|
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'));
|
|
|
|
|
|
2010-06-07 21:11:06 -07:00
|
|
|
|
|
|
|
|
}
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
?>
|