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*/ } } ?>
getAll($sql1); $subresults = common_production_department::get_active_departments(); foreach($subresults as $subs) { //2nd foreach $slabour = $subs['department_name']; $sid = $subs['id']; //production department ?> 0) { foreach($subresults2 as $subs2) { //3rd foreach $slabour2 = $subs2['labour_name']; $sunits2 = $subs2['units']; $srate2 = $subs2['rate']; $sid2 = $subs2['id']; $sfieldtype = $subs2['fieldtype']; ?>
Labour Hrs Quantity Rate Total
Sub Total Production / Installation Labour
"readonly"); $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options);?>
"readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=$rate; echo forms::input_text($config,$validation,$options); ?> "readonly") ; $options['style'] = "border:0;text-align:right;width:70px; "; $config['value']=''; echo forms::input_text($config ,$validation,$options); }?>
getAll($sql2); $subresults2 = common_production_department::get_active_subdepartments($sid); //bug::bug_array('',$subresults2); ?>        
$ "readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=$srate2; echo forms::input_text($config,$validation,$options); } ?> "readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options);?>
$ "readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=$d_rate; echo forms::input_text($config,$validation,$options); ?> "readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options);?>
Sub Total Delivery
"readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options);?>
Sub Total External Installation
"readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options);?>
TOTAL COST
"readonly") ; $options['style'] = "border:0;text-align:right;width:70px;"; $config['value']=''; echo forms::input_text($config ,$validation,$options); ?>
 
       
db_name; $reasons = "

"; $reasons .= trim($this->reasons); $check_reasons = strip_tags($reasons); $results = false; $sql_string = ""; if($check_reasons == "") { $submitter = $_SESSION['user']['id']; $current_date_time = date('Y-m-d G:i:s'); } } public function new_submit() { global $database; $db_name = $this->db_name; $id = $this->id; $reasons = "

"; $reasons .= trim($this->reasons); $check_reasons = strip_tags($reasons); $results = false; $sql_string = ""; if($check_reasons == "") { $submitter = $_SESSION['user']['id']; $current_date_time = date('Y-m-d G:i:s'); $id = intval(mysql_real_escape_string($_POST['quote_id'])); $dept_id = intval(mysql_real_escape_string($_POST['department'])); $status_id = intval(mysql_real_escape_string($_POST['status'])); $install_total = mysql_real_escape_string(str_replace(',','',str_replace('$','',$_POST['installation_total_labour']))); $delivery_total = mysql_real_escape_string(str_replace(',','',str_replace('$','',$_POST['delivery_total_labour']))); $artwork_total = str_replace(',','',str_replace('$','',$_POST['total_Artwork_labour'])); $permit_total = str_replace(',','',str_replace('$','',$_POST['total_Permits-Survey_labour'])); $subcontractor_total =str_replace(',','',str_replace('$','',$_POST['total_Alternative_Sub_Contractor_supplied_price_labour'])); /*Kai 2013-03-06 rather than substract to get labour costing, grab straight away from inpunt inhouse subtotal labour*/ //$labour_total = str_replace(',','',str_replace('$','',$_POST['grand_total_labour'])) - $install_total - $delivery_total - $artwork_total - $permit_total - $subcontractor_total; $labour_total = str_replace(',','',str_replace('$','',$_POST['inhouse_subtotal_labour'])); $current_date_time = date('Y-m-d G:i:s'); foreach($_POST as $key => $val ) if(preg_match('/labour/',$key)) $posst[$key] = $val; //bug::bug_array('',$_POST); foreach($_POST as $k => $v ) { //echo '

'.$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.'
'; if($j1==$kk) { $sum[$j1] += $i1; } } } } foreach($sum as $s => $m) { if($s > 40) {} else { $fac .= "('$id','".$s."','".$m."','1','$current_date_time','$submitter','$current_date_time'),"; } //echo $m.'
'; } // echo $fac; //die; $fac = substr($fac,0,-1); $database->StartTrans(); $labourdata = serialize($posst); $sub_total = $artwork_total + $delivery_total + $install_total + $permit_total + $subcontractor_total + $labour_total; $context = array( "labourdata" => $labourdata, "delivery_total" => $delivery_total, "install_total" => $install_total, "labour_total" => $labour_total, "artwork_total" => $artwork_total, "permit_total" => $permit_total, "subcontractor_total" => $subcontractor_total, "dept_id" => $dept_id, "id" => $id ); //common_labours::update($context); /** Kai 20/11/2012*/ common_labours::update_quote_labour($context); logs::submit_logs(array("table" => "quotes_labour", "action_type" => 2,"foreign_id" => $id, "description" => "Modified")); $context = array( "sub_total" => $sub_total, "delivery_total" => $delivery_total, "install_total" => $install_total, "labour_total" => $labour_total, "artwork_total" => $artwork_total, "permit_total" => $permit_total, "subcontractor_total" => $subcontractor_total, "quote_id" => $id ); common_quotesheets::update_all($context ); logs::submit_logs(array("table" => "quotes_sheets", "action_type" => 2,"foreign_id" => $id, "description" => "Modified")); $last_id = common_quotes_productiontime::create($id, $fac); logs::submit_logs(array("table" => "quotes_production_time", "action_type" => 2,"foreign_id" => $last_id, "description" => "Modified")); logs::submit_logs(array("table" => "quotes", "action_type" => 10,"foreign_id" => $_POST['quote_id'], "description" => "Updated Labour Costing")); $results = $database->CompleteTrans(); } if(!$results) { confirmation::error_temp("Add Labour Costing ".$reasons); return false; } else { confirmation::success_temp("Added/Updated Labour costing"); return true; } } public function template_assigned(){ global $database; $quote_id = $_POST['quote_id']; $sql = "SELECT COUNT(*) AS count FROM template_assigned WHERE quote_id = $quote_id"; $result=$database->getRow($sql); if($result['count'] > 0){ $sql = "UPDATE template_assigned SET template_ids = '".$_POST['template_ids']."' WHERE quote_id = $quote_id"; $result=$database->query($sql); }else{ $sql = "INSERT INTO template_assigned SET template_ids = '".$_POST['template_ids']."', quote_id = $quote_id"; $result=$database->query($sql); } } } ?>