id = $context['id']; $this->db_name = $context['db_name']; } public function set() { global $database; $id = $this->id; $db_name = $this->db_name; if(!empty($id)) { /*$get_material = " SELECT * FROM $db_name"."quotes_material WHERE id = '$id' LIMIT 1 "; $results = $database->getRow($get_material);*/ $results = common_materials::get_quote_materials_by_id($id); $this->id = $results['id']; $this->materials = $results['item']; $this->materials = $results['materials']; $this->supplier = $results['supplier']; $this->quantity = $results['quantity']; $this->price = $results['price']; $this->total = $results['total']; } if($_POST['Submit'] == "Save") { foreach($_POST AS $name => $value) { $splitter = explode("_",$name); $post_name = $splitter[0]; $suffix = $splitter[1]; if($post_name == "materials") { $this->item = mysql_real_escape_string($_POST['item_'.$suffix]); $this->materials = mysql_real_escape_string($_POST['materials_'.$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->material_no = mysql_real_escape_string($_POST['id_'.$suffix]); } } } $this->config['item'] = array("id"=> $id,"value"=> $this->item, "input_name" => "item", "name" => "Item","rule" => ""); $this->config['materials'] = array("id"=> $id,"value"=> $this->materials, "input_name" => "materials", "name" => "Materials","rule" => "required"); $this->config['supplier'] = array("id"=> $id,"value"=> $this->supplier, "input_name" => "supplier", "name" => "Supplier","rule" => ""); $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"); $this->config['material_no'] = array("id"=> $id,"value"=> $this->material_no, "input_name" => "id", "name" => "Material","rule" => ""); self::run_validation(); } public function run_validation() { $id = $this->id; $static_function = (($_POST['Submit'] == "")) ? "initial" : "validate"; $this->validation['item'] = validation::$static_function($this->config['item']); $this->validation['materials'] = validation::$static_function($this->config['materials']); $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->validation['material_no'] = validation::$static_function($this->config['material_no']); $this->reasons = validation::formalise($this->validation); } public function form() { global $database; $id = $this->id; $config = $this->config; $validation = $this->validation; $text_options = array("class" => "medium"); $text_options_small = array("class" => "small"); $text_area_options = array("class" => "medium"); $select_options = array("class" => "medium form"); $text_options_small_readonly['class'] = "small"; $text_options_small_readonly['attr'] = "readonly"; /** 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 22/11/2012*/ $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))){ $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))){ $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 22/11/2012*/ } } ?>
Code Material Description Supplier Quantity Total Available Price Total Not Inventory  
      Add Material
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; $cntr =0; $sql_string = ""; if($check_reasons == "") { $submitter = $_SESSION['user']['id']; $current_date_time = date('Y-m-d G:i:s'); $id = mysql_real_escape_string($_POST['id']); foreach($_POST AS $name => $value) { $splitter = explode("_",$name); $post_name = $splitter[0]; $suffix = $splitter[1]; if($post_name == "materials") { $item = mysql_real_escape_string($_POST['item_'.$suffix]); $materials = addslashes(mysql_real_escape_string($_POST['materials_'.$suffix])); $supplier = addslashes(mysql_real_escape_string($_POST['supplier_'.$suffix])); $quantity = mysql_real_escape_string($_POST['quantity_'.$suffix]); $price = mysql_real_escape_string($_POST['price_'.$suffix]); $total = mysql_real_escape_string($_POST['total_'.$suffix]); $material_no = mysql_real_escape_string($_POST['id_'.$suffix]); $exclude = mysql_real_escape_string($_POST['exclude_'.$suffix]); $data = array( 'materials' => $materials, 'supplier' => $supplier, 'quantity' => $quantity, 'price' => $price, 'quote_id' => $id ); $res_ce = common_materials::check_exists($data); if($res_ce){ //$reasons .= $data['materials'].' already exists
'; $cntr++; continue; }else{ $cntr--; } $materials_total += $total; $job_flag='0'; if($material_no ==0){ $exclude = 1; }else{ $exclude = 0; } logs::submit_logs(array("table" => "quotes", "action_type" => 8,"foreign_id" => $id, "description" => "Added New Material - ".$materials)); //$sql_string .= "('$id','$item','$materials','$supplier','$quantity','$price','$total',$job_flag,'$submitter','$current_date_time'), "; $sql_string .= "('$id','$material_no','$item','$materials','$supplier','$quantity','$price','$total','$exclude',$job_flag,'$submitter','$current_date_time'), "; } } //echo $sql_string; if(!empty($sql_string)) { $sql_string = substr($sql_string,0, strlen($sql_string) - 2); $database->StartTrans(); //common_materials::create_new($sql_string); common_materials::create_new_material($sql_string); logs::submit_logs(array("table" => "quotes_materials", "action_type" => 1,"foreign_id" => $id, "description" => "Created")); common_quotesheets::update_materials($materials_total,$id); logs::submit_logs(array("table" => "quotes_sheets", "action_type" => 2,"foreign_id" => $id, "description" => "Modified")); $results = $database->CompleteTrans(); } } if(!$results) { if($cntr > 0){ $reasons .= 'Nothing to save'; } return array("status" => false,"reasons" => "Failed to add materials because of the following reasons".$reasons); } else { return array("status" => true,"reasons" => $reasons); } } public function template_assigned($quote_id){ global $database; $sql = "UPDATE template_assigned SET saved_in_material_costing = 1 WHERE quote_id = $quote_id"; $result=$database->query($sql); } } ?>