2010-05-03 23:49:57 -07:00
|
|
|
<?php
|
|
|
|
|
class JobsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Jobs';
|
|
|
|
|
var $helpers = array('Html', 'Form');
|
|
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
|
$this->Job->recursive = 0;
|
|
|
|
|
$this->set('jobs', $this->paginate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->flash(__('Invalid Job', true), array('action'=>'index'));
|
|
|
|
|
}
|
2010-05-17 23:45:38 -07:00
|
|
|
|
|
|
|
|
$job = $this->Job->read(null, $id);
|
|
|
|
|
$this->set('job', $job);
|
|
|
|
|
$this->set('customer', $this->Job->Enquiry->Customer->findById($job['Enquiry']['customer_id']));
|
|
|
|
|
|
|
|
|
|
$this->pageTitle = $job['Job']['title'];
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add() {
|
2010-05-13 00:10:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->Job->create();
|
2010-05-13 15:37:05 -07:00
|
|
|
|
2010-05-19 16:56:02 -07:00
|
|
|
$job_offset = 6141;
|
2010-05-13 15:37:05 -07:00
|
|
|
|
|
|
|
|
$number_of_jobs = $this->Job->findCount();
|
|
|
|
|
$new_job_number = $job_offset + $number_of_jobs;
|
|
|
|
|
|
|
|
|
|
$enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']);
|
|
|
|
|
|
2010-05-17 23:45:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$monthYearShort = strtoupper(date("My"));
|
|
|
|
|
|
|
|
|
|
$jobLetter = $enquiry['State']['enqform'];
|
|
|
|
|
|
|
|
|
|
$this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number;
|
|
|
|
|
|
2010-05-13 15:37:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
if ($this->Job->save($this->data)) {
|
2010-05-13 00:10:10 -07:00
|
|
|
$jobid = $this->Job->id;
|
|
|
|
|
|
2010-05-17 23:45:38 -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
|
|
|
|
2010-05-17 23:45:38 -07:00
|
|
|
$this->Job->Enquiry->save($enquiry);
|
2010-05-13 15:37:05 -07:00
|
|
|
|
|
|
|
|
|
2010-05-13 00:10:10 -07:00
|
|
|
$this->Session->setFlash(__('Job Saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'view', $jobid));
|
2010-05-03 23:49:57 -07:00
|
|
|
} else {
|
2010-05-13 00:10:10 -07:00
|
|
|
$this->Session->setFlash(__('Please Fix the Errors Below', true));
|
|
|
|
|
$enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']);
|
|
|
|
|
$this->set(compact('enquiry'));
|
2010-05-03 23:49:57 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-13 00:10:10 -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) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->flash(__('Invalid Job', true), array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Job->save($this->data)) {
|
|
|
|
|
$this->flash(__('The Job has been saved.', true), array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $this->Job->read(null, $id);
|
|
|
|
|
}
|
2010-05-17 23:45:38 -07:00
|
|
|
|
|
|
|
|
|
2010-05-03 23:49:57 -07:00
|
|
|
$enquiries = $this->Job->Enquiry->find('list');
|
2010-05-17 23:45:38 -07:00
|
|
|
|
|
|
|
|
$this->set(compact('enquiries'));
|
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'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|