class form_labour { public $id; public $db_name; public $config; public $validation; public $reasons; public $suffix; public $data; public function __construct($context = array()) { $this->id = $context['id']; $this->db_name = $context['db_name']; } public function set() { global $database; $id = $this->id; $db_name = $this->db_name; //get data //$sql = "SELECT labours from quotes_labour where quote_id = '$id'"; //$datas = $database->getRow($sql); $datas = common_quotes::get_quote_labour($id); if(!empty($datas['labours'])){ $this->data = json_encode(unserialize($datas['labours'])); } //get the labours if available if($_POST['Submit'] == "Save") { foreach($_POST AS $name => $value) { $splitter = explode("_",$name); $post_name = $splitter[0]; $suffix = $splitter[1]; if($post_name == "labour") { $this->labour = mysql_real_escape_string($_POST['labour_'.$suffix]); $this->supplier = mysql_real_escape_string($_POST['supplier_'.$suffix]); $this->quantity = mysql_real_escape_string($_POST['quantity_'.$suffix]); $this->price = mysql_real_escape_string($_POST['price_'.$suffix]); $this->total = mysql_real_escape_string($_POST['total_'.$suffix]); } } } $this->config['labour'] = array("id"=> $id,"value"=> $this->labour, "input_name" => "labour", "name" => "labour","rule" => "required"); $this->config['supplier'] = array("id"=> $id,"value"=> $this->supplier, "input_name" => "supplier", "name" => "Supplier","rule" => "required"); $this->config['quantity'] = array("id"=> $id,"value"=> $this->quantity, "input_name" => "quantity", "name" => "Quantity","rule" => "required|numeric"); $this->config['price'] = array("id"=> $id,"value"=> $this->price, "input_name" => "price", "name" => "Price","rule" => "required|numeric"); $this->config['total'] = array("id"=> $id,"value"=> $this->total, "input_name" => "total", "name" => "Total","rule" => "required|numeric"); //self::run_validation(); } public function run_validation() { $id = $this->id; $static_function = (($_POST['Submit'] == "")) ? "initial" : "validate"; $this->validation['labour'] = validation::$static_function($this->config['labour']); $this->validation['supplier'] = validation::$static_function($this->config['supplier']); $this->validation['quantity'] = validation::$static_function($this->config['quantity']); $this->validation['price'] = validation::$static_function($this->config['price']); $this->validation['total'] = validation::$static_function($this->config['total']); $this->reasons = validation::formalise($this->validation); } public function form() { global $database; $data = $this->data; $id = $this->id; $results = common_labours::get_sublabours(0); $config = $this->config; $validation = $this->validation; /** Kai 07/11/2012*/ /** disable costing changes fater quote approved, only admin level user to update*/ $display_info = false; $group_id = $_SESSION['user']['group_id']; $admin_groups = array(31,42); if(in_array($group_id, $admin_groups)){ $display_info = false; }else{ $get_job_details = "SELECT * FROM jobs WHERE status <>53 AND quote_id =".$this->id; $job_details = $database->getAll($get_job_details); /** Kai 15/11/2012*/ if(empty($job_details)){ $display_info=false; }else{ /** this query is to get job with id and direction states that Decision will go to Production in order to make sure that quote can be edit before production*/ // $get_job_decisions = "SELECT * FROM project_workflow WHERE foreign_id = ".$job_details[0]['id']." AND project_workflow.table = 'jobs' AND direction = 'yes'"; // $job_decisions = $database->getAll($get_job_decisions); /** this array includes workflow ids that leds to the productions, which means after this stage, quote is not able to edit*/ // $decisions = array(35,373,419,433); // if(!empty($job_decisions)){ // /** no more edit after decisions above have been decided*/ // foreach($job_decisions as $jd){ // if(in_array($jd['workflow_id'],$decisions)){ // $display_info = true; // } // } // }else{ // $display_info = false; // } /** Kai 08/02/2013*/ $get_current_job_tasks = " SELECT project_tasks.*,project_workflow.table,project_workflow.foreign_id FROM project_tasks, project_workflow WHERE project_tasks.project_workflow_id = project_workflow.id AND project_tasks.status=0 AND project_workflow.foreign_id=".$job_details[0]['id']." AND project_workflow.table = 'jobs' "; $current_job_tasks = $database->getRow($get_current_job_tasks); if(in_array($current_job_tasks['workflow_task_id'],array(36,594,699,751,762,777))){ $display_info = true; //bug::bug_array('current workflow_task_id',$current_job_tasks['workflow_task_id']); }else{ $get_finished_job_tasks = " SELECT project_tasks.*,project_workflow.table,project_workflow.foreign_id FROM project_tasks, project_workflow WHERE project_tasks.project_workflow_id = project_workflow.id AND project_tasks.status=1 AND project_workflow.foreign_id=".$job_details[0]['id']." AND project_workflow.table = 'jobs' "; $finished_job_tasks = $database->getAll($get_finished_job_tasks); foreach($finished_job_tasks as $tasks){ if(in_array($tasks['workflow_task_id'],array(36,594,699,751,762,777))){ $display_info = true; //bug::bug_array('finished workflow_task_id',$current_job_tasks['workflow_task_id']); } } } //bug::bug_array('Finished job tasks',$current_job_tasks); /** Changes end, Kai 08/02/2013*/ } } ?>
'.$k.'
'; if(preg_match('/^rate_/',$k) || preg_match('/total_/',$k)) {} else { //echo ''.$k.'
'; $field = explode('_',$k); $dept[$id]= array_pop($field); /*check if the key is artwork_labour, then assign department_id manually*/ if($k=='Artwork_labour'){ $id=11; $dept[$id]=11; }else{ $id = intval(mysql_real_escape_string($_POST['quote_id'])); } if(is_numeric($dept[$id]) && is_numeric($v)) { $arr[] =array($dept[$id] => $v); //create an array for the factory departments (sheetmetal,vinyl,painting, etc) } } } //bug::bug_array('',$arr); foreach($arr as $k =>$v) foreach($v as $j => $i) $jarr[] = $j; $ju=array_unique($jarr); foreach($ju as $jj => $kk) { foreach($arr as $k1 =>$v1) { foreach($v1 as $j1 => $i1) { $jarr[] = $j1; //echo $j1.'=='.$kk.'=>'.$i1.'