376 lines
9.7 KiB
PHP
Executable file
376 lines
9.7 KiB
PHP
Executable file
<?php
|
|
class JobsController extends AppController {
|
|
|
|
var $name = 'Jobs';
|
|
var $helpers = array('Html', 'Form', 'Text', 'Javascript');
|
|
|
|
var $components = array('RequestHandler');
|
|
|
|
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'));*/
|
|
|
|
}
|
|
|
|
|
|
function index_grid() {
|
|
$jobs = $this->paginate();
|
|
$this->layout = 'jqgrid';
|
|
|
|
//print_r($this->params);
|
|
|
|
}
|
|
|
|
|
|
function build_jobs_json() {
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
//print_r($this->params);
|
|
|
|
|
|
$sortCol = 'id'; //Default we Order by ID
|
|
$sortDir = 'desc'; //Descending.
|
|
|
|
|
|
|
|
if(isset($this->params['url']['sidx'])) {
|
|
$sortCol = $this->params['url']['sidx'];
|
|
}
|
|
else {
|
|
$sortCol = 'Job.id';
|
|
}
|
|
|
|
if(isset($this->params['url']['sord'])) {
|
|
$sortDir = $this->params['url']['sord'];
|
|
}
|
|
else {
|
|
$sortDir = 'desc';
|
|
}
|
|
|
|
$jobPaginated = $this->paginate(); //Not used currently.
|
|
|
|
$jobs = $this->Job->find('all', array('recursive'=>1, 'order'=>array('Job.id'=>'desc')));
|
|
//print_r($jobs);
|
|
$this->set('jobs', $jobs);
|
|
|
|
$customers = $this->Job->Enquiry->Customer->find('list');
|
|
$this->set('customers', $customers);
|
|
//$this->set('currencies', $this->Job->Currency->find('list'));
|
|
}
|
|
|
|
|
|
function ajax_edit() {
|
|
if(isset($this->params['form'])) {
|
|
|
|
$formData = $this->params['form'];
|
|
|
|
/* $thisJob['Job'] = array(
|
|
'id'=> $formData['id'],
|
|
'job_status' => $formData['job_status']
|
|
|
|
|
|
);*/
|
|
|
|
$job['Job'] = $this->params['form'];
|
|
|
|
|
|
//print_r($thisJob);
|
|
|
|
|
|
if ($this->Job->save($job)) {
|
|
echo "SUCCESS";
|
|
}
|
|
else {
|
|
echo "FAILURE";
|
|
}
|
|
|
|
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
function index_oldgrid() {
|
|
|
|
$this->layout = 'grid';
|
|
$jobs = $this->paginate();
|
|
|
|
$this->set('jobs', $jobs);
|
|
|
|
$jsonObj = array();
|
|
|
|
$customers = $this->Job->Enquiry->Customer->find('list');
|
|
$this->set('customers', $customers);
|
|
|
|
|
|
foreach($jobs as $job) {
|
|
$jsonObj[] = array(
|
|
'id' => $job['Job']['id'],
|
|
'created' => $job['Job']['created'],
|
|
'title' => $job['Job']['title'],
|
|
'customer' => $customers[$job['Enquiry']['customer_id']],
|
|
'customer_order_number' => $job['Job']['customer_order_number'],
|
|
'supplier_reference' =>$job['Job']['supplier_reference'],
|
|
'date_order_received' => $job['Job']['date_order_received'],
|
|
'date_order_placed_on_principle' => $job['Job']['date_order_placed_on_principle'],
|
|
'date_scheduled_ex_works' => $job['Job']['date_scheduled_ex_works'],
|
|
'date_order_sent_to_customer' => $job['Job']['date_order_sent_to_customer'],
|
|
'domestic_freight_paid_by' => $job['Job']['domestic_freight_paid_by'],
|
|
'sale_category' => $job['Job']['sale_category'],
|
|
'shipment_category' => $job['Job']['shipment_category'],
|
|
'comments' => $job['Job']['comments'],
|
|
'company_gross_sales_aud' => $job['Job']['company_gross_sales_aud'],
|
|
'net_sales_aud' => $job['Job']['net_sales_aud'],
|
|
'gross_profit_aud' => $job['Job']['gross_profit_aud'],
|
|
'ato_exchange_rate' => $job['Job']['ato_exchange_rate'],
|
|
'gst'=> $job['Job']['gst'],
|
|
'currency_id' => $job['Job']['currency_id'],
|
|
'gst_amount' => $job['Job']['gst_amount'],
|
|
'gross_commisions' => $job['Job']['gross_commisions'],
|
|
'invoiced_amount_inc_gst' => $job['Job']['invoiced_amount_inc_gst'],
|
|
'net_export_sales_aud' =>$job['Job']['net_export_sales_aud'],
|
|
'gross_profit_exports_aud' => $job['Job']['gross_profit_exports_aud'],
|
|
'gp_percent' => $job['Job']['gp_percent'],
|
|
'gross_australian_sales_foreign_currency' => $job['Job']['gross_australian_sales_foreign_currency'],
|
|
'net_australian_sales_foreign_currency' => $job['Job']['net_australian_sales_foreign_currency'],
|
|
'gross_profit_value_australian_sales_foreign_currency' => $job['Job']['gross_profit_value_australian_sales_foreign_currency'],
|
|
'gross_export_sales_foreign_currency' => $job['Job']['gross_export_sales_foreign_currency'],
|
|
'net_export_sales_foreign_currency' => $job['Job']['net_export_sales_foreign_currency'],
|
|
'gross_profit_value_after_discount_exports_foreign_currency' => $job['Job']['gross_profit_value_after_discount_exports_foreign_currency'],
|
|
'gross_commissions' => $job['Job']['gross_commissions'],
|
|
'net_commissions' => $job['Job']['net_commissions']
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
$jsonObj = json_encode($jsonObj);
|
|
|
|
$this->set('jsonObj', $jsonObj);
|
|
|
|
$this->set('jobs', $jobs);
|
|
|
|
$this->set('currencies', $this->Job->Currency->find('list'));
|
|
|
|
}
|
|
|
|
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'));
|
|
|
|
|
|
}*/
|
|
|
|
|
|
}
|
|
?>
|