cmc-sales/controllers/jobs_controller.php
2010-05-14 08:37:05 +10:00

111 lines
3.4 KiB
PHP

<?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'));
}
$this->set('job', $this->Job->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->Job->create();
$job_offset = 6130;
$number_of_jobs = $this->Job->findCount();
$new_job_number = $job_offset + $number_of_jobs;
$enquiry = $this->Job->Enquiry->findById($this->data['Job']['enquiry_id']);
// $this->data['Job']['title'] =
if ($this->Job->save($this->data)) {
$jobid = $this->Job->id;
$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)) {
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);
}
$states = $this->Job->State->find('list');
$customers = $this->Job->Customer->find('list');
$enquiries = $this->Job->Enquiry->find('list');
$contacts = $this->Job->Contact->find('list');
$this->set(compact('states','customers','enquiries','contacts'));
}
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'));
}
}
}
?>