File: /home/cafsindia/cpaqua.cafsinfotech.in/dump/application/controllers/Project_list.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Project_list extends Action_controller{
public function __construct(){
parent::__construct('project_list');
$this->collect_base_info();
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//ESITMATION USED FOR
$est_qry = 'SELECT prime_est_used_for,est_used_for FROM cw_est_used_for WHERE trans_status = 1 ';
$est_info = $this->db->query("CALL sp_a_run ('SELECT','$est_qry')");
$est_rslt = $est_info->result();
$est_info->next_result();
$est_list[""] = "---- EST USED ----";
foreach($est_rslt as $for){
$prime_id = $for->prime_est_used_for;
$est_status = $for->est_used_for;
$est_list[$prime_id] = $est_status;
}
//BID STATUS
$bid_qry = 'SELECT prime_bid_status_id,bid_status FROM cw_bid_status WHERE trans_status = 1 ';
$bid_info = $this->db->query("CALL sp_a_run ('SELECT','$bid_qry')");
$bid_rslt = $bid_info->result();
$bid_info->next_result();
$bid_list[""] = "---- BID STATUS ----";
foreach($bid_rslt as $for){
$prime_id = $for->prime_bid_status_id;
$bid_status = $for->bid_status;
$bid_list[$prime_id] = $bid_status;
}
//JOB TYPE
$job_type_qry = 'SELECT prime_job_type_id,job_type FROM cw_job_type WHERE trans_status = 1 ';
$job_type_info = $this->db->query("CALL sp_a_run ('SELECT','$job_type_qry')");
$job_type_rslt = $job_type_info->result();
$job_type_info->next_result();
$job_type_list[""] = "---- JOB TYPE ----";
foreach($job_type_rslt as $for){
$prime_id = $for->prime_job_type_id;
$job = $for->job_type;
$job_type_list[$prime_id] = $job;
}
//USPM
$uspm_qry = 'SELECT prime_uspm_id,uspm FROM cw_uspm WHERE trans_status = 1 ';
$uspm_info = $this->db->query("CALL sp_a_run ('SELECT','$uspm_qry')");
$uspm_rslt = $uspm_info->result();
$uspm_info->next_result();
$uspm_list[""] = "---- USPM ----";
foreach($uspm_rslt as $for){
$prime_id = $for->prime_uspm_id;
$uspm = $for->uspm;
$uspm_list[$prime_id] = $uspm;
}
//BRANCH
$branch_qry = 'SELECT prime_branch_id,branch FROM cw_branch WHERE trans_status = 1 ';
$branch_info = $this->db->query("CALL sp_a_run ('SELECT','$branch_qry')");
$branch_rslt = $branch_info->result();
$branch_info->next_result();
foreach($branch_rslt as $for){
$prime_id = $for->prime_branch_id;
$branch = $for->branch;
$branch_list[$prime_id] = $branch;
}
//TEAM
$team_qry = 'SELECT prime_team_list_id,team FROM cw_team_list WHERE trans_status = 1 ';
$team_info = $this->db->query("CALL sp_a_run ('SELECT','$team_qry')");
$team_rslt = $team_info->result();
$team_info->next_result();
foreach($team_rslt as $for){
$prime_id = $for->prime_team_list_id;
$team = $for->team;
$team_list[$prime_id] = $team;
}
//STATE
$state_qry = 'SELECT prime_state_list_id,state_id as state_name FROM cw_state_list WHERE trans_status = 1 ';
$state_info = $this->db->query("CALL sp_a_run ('SELECT','$state_qry')");
$state_rslt = $state_info->result();
$state_info->next_result();
$state_list[""] = "---- STATE ----";
foreach($state_rslt as $for){
$prime_id = $for->prime_state_list_id;
$state = $for->state_name;
$state_list[$prime_id] = $state;
}
//MARKET CATEGORY
$market_qry = 'SELECT prime_market_category_id,market_category FROM cw_market_category WHERE trans_status = 1 ';
$market_info = $this->db->query("CALL sp_a_run ('SELECT','$market_qry')");
$market_rslt = $market_info->result();
$market_info->next_result();
$market_list[""] = "---- MARKET CATEGORY ----";
foreach($market_rslt as $for){
$prime_id = $for->prime_market_category_id;
$market = $for->market_category;
$market_list[$prime_id] = $market;
}
//EXCEL FORMAT
$excel_format_qry= 'SELECT prime_excel_format_id,excel_name FROM cw_util_excel_format WHERE excel_module_id = "project_list" AND trans_status = 1';
$excel_format = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
$excel_result = $excel_format->result();
$excel_format->next_result();
$user_role = (int)$this->session->userdata('logged_user_role'); //[MS 26-10-2024]
$excel_format_drop[""] = "---- EXCEL FORMAT ----";
foreach($excel_result as $excel){
$prime_excel_format_id = $excel->prime_excel_format_id;
$excel_name = $excel->excel_name;
if(!($user_role === 16 && (int)$prime_excel_format_id === 15)){ //[MS 26-10-2024]
$excel_format_drop[$prime_excel_format_id] = $excel_name;
}
}
$data['est_used_for'] = $est_list;
$data['bid_sts'] = $bid_list;
$data['job_type'] = $job_type_list;
$data['state'] = $state_list;
$data['branch'] = $branch_list;
$data['team'] = $team_list;
$data['uspm'] = $uspm_list;
$data['module_id'] = "project_list";
$data['market_category'] = $market_list;
$data['excel_format_drop'] = $excel_format_drop;
$data['encKey'] = $this->generateKey();
$this->load->view("$this->control_name/manage",$data);
}
//ESTIMATOR AUTO COMPLETE
public function est_suggest_name(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$team_qry = '';
$search_term = $this->input->post('term');
if($this->input->post('team')){
$team = implode(',',$this->input->post('team'));
$team_qry = ' AND cw_employees.estimation_team IN ('.$team.')';
}
$final_qry = 'SELECT employee_code,emp_name FROM cw_employees WHERE trans_status = 1 AND prime_employees_id != 1 AND (employee_code like "'.$search_term.'%" OR emp_name like "'.$search_term.'%") AND role IN (12,15) '.$team_qry;
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$employee_code = $rslt->employee_code;
$emp_name = $rslt->emp_name;
$suggestions[] = array('value' => "$employee_code", 'label' =>"$employee_code - $emp_name",'est_name' => "$employee_code - $emp_name");
}
if(empty($suggestions)){
$suggestions[] = array('value' => "0", 'label' => "No data found for this search",'est_name' => "");
}
echo json_encode($suggestions);
}
//CLIENT NAME AUTOCOMPLETE
public function client_suggest_name(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$search_term = $this->input->post_get('term');
$final_qry = 'SELECT client_name FROM cw_client WHERE trans_status = 1 AND client_name like "%'.$search_term.'%"';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$client_name = $rslt->client_name;
$suggestions[] = array('value' => "$client_name", 'label' =>"$client_name");
}
if(empty($suggestions)){
$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
}
echo json_encode($suggestions);
}
//EXISTING REA AUTOCOMPLETE
public function rea_suggest_name(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$search_term = $this->input->post_get('term');
$final_qry = 'SELECT rea,project_name FROM cw_project_list WHERE trans_status = 1 AND rea like "%'.$search_term.'%"';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$rea = $rslt->rea;
$name = $rslt->project_name;
$suggestions[] = array('value' => "$rea", 'label' =>"$rea - $name");
}
if(empty($suggestions)){
$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
}
echo json_encode($suggestions);
}
//FETCH CITY BASED ON STATE
public function fetch_city(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$state_id = $this->input->post('state');
$city_qry = 'SELECT prime_city_list_id,city_name FROM cw_city_list WHERE trans_status = 1 AND state_id = "'.$state_id.'" ';
$city_info = $this->db->query("CALL sp_a_run ('SELECT','$city_qry')");
$city_rslt = $city_info->result();
$city_info->next_result();
$city_list = "<option value = ''>---- city ----</option>";
foreach($city_rslt as $for){
$prime_id = $for->prime_city_list_id;
$city = $for->city_name;
$city_list .= "<option value='$prime_id'> $city </option>";
}
if(count($city_rslt) > 0){
echo json_encode(array('success' => True,'city_rslt' => $city_list));
}else{
echo json_encode(array('success' => False,'city_rslt' => []));
}
}
//FETCH MASTER CHECKER BASED ON TEAM
public function fetch_master_checker(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$team = $this->input->post('team');
if(is_array($team)){
$team = implode(',',$team);
}
$mas_check_qry = 'SELECT employee_code,emp_name FROM cw_employees WHERE ROLE IN (13) AND estimation_team IN ('.$team.') AND trans_status = 1 ';
$mas_check_info = $this->db->query("CALL sp_a_run ('SELECT','$mas_check_qry')");
$mas_check_rslt = $mas_check_info->result();
$mas_check_info->next_result();
$mas_check_list = "<option value = ''>---- MASTER CHECKER ----</option>";
foreach($mas_check_rslt as $for){
$emp_code = $for->employee_code;
$emp_name = $for->emp_name;
$mas_check_list .= "<option value='$emp_code'> $emp_code - $emp_name </option>";
}
if(count($mas_check_rslt) > 0){
echo json_encode(array('success' => True,'master_chk_rslt' => $mas_check_list));
}else{
echo json_encode(array('success' => False,'master_chk_rslt' => []));
}
}
//PROJECT DATA EDIT
public function project_edit(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$prime_id = $this->input->post('prime_id');
$type = $this->input->post('type');
if($type === "edit"){
$cond_qry = 'AND prime_project_list_id = "'.$prime_id.'"';
}else{
$cond_qry = 'AND rea = "'.$prime_id.'"';
}
$pro_qry = 'SELECT * from cw_project_list WHERE trans_status = 1 '.$cond_qry.' ';
$pro_info = $this->db->query("CALL sp_a_run ('SELECT','$pro_qry')");
$pro_rslt = $pro_info->result();
$pro_info->next_result();
echo json_encode(array('success' => True,'pro_rslt' => $pro_rslt));
}
// PROJECT DATA SAVE
public function project_list_save(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$client_name = $this->input->post('client_name');
$job_type = $this->input->post('job_type');
$rea = $this->input->post('rea');
$rea_id = $this->input->post('rea_id');
$proposed_rea = $this->input->post('proposed_rea');
$project_name = $this->input->post('project_name');
$state = $this->input->post('state');
$city = $this->input->post('city');
$bid_received_date = date("Y-m-d",strtotime($this->input->post('bid_received_date')));
$bid_date = date("Y-m-d",strtotime($this->input->post('bid_date')));
$uspm = $this->input->post('uspm');
$target_date = date("Y-m-d",strtotime($this->input->post('target_date')));
$duplicate_job = $this->input->post('duplicate_job');
$existing_rea = $this->input->post('existing_rea');
$engineer_name = $this->input->post('engineer_name');
$market_category = $this->input->post('market_category');
$pro_remarks = $this->input->post('pro_remarks');
if($this->input->post('branch')){
$branch = implode(',',$this->input->post('branch'));# JOB ALLOCATION
}
if($this->input->post('team')){
$team = implode(',',$this->input->post('team'));
}
$master_checker = $this->input->post('master_checker');
$approx_weight = $this->input->post('approx_weight');
$approx_days = $this->input->post('approx_days');
$sub_plan_for = date("Y-m-d",strtotime($this->input->post('sub_plan_for')));
$job_remarks = $this->input->post('job_remarks');
# ATTACHMENT
$filename = $_FILES['pro_docs']['name'];
$tmp_name = $_FILES['pro_docs']['tmp_name'];
$filetype = $_FILES['pro_docs']['type'];
$filesize = $_FILES['pro_docs']['size'];
$created_on = date("Y-m-d h:i:s");
$pro_docs = [];
$doc_files = '';
$file_path = "./project_list/docs/";
if(!file_exists($file_path)){
mkdir($file_path, 0777, true);
}
$format = ['text/xml','image/png','image/jpeg','text/plain','application/pdf','application/zip','application/vnd.ms-excel','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-outlook','message/rfc822','application/x-zip-compressed','application/octet-stream'];
# FILE TYPE VALIDATION
foreach($filetype as $type){
if(!in_array($type, $format)){
echo json_encode(array('success' => False,'message' => "File type $type is not allowed."));
exit(0);
}
}
# FILE SIZE VALIDATION
foreach($filesize as $size){
if($size > 5242880){ # MB IN BYTES (5 * 1024) * 5024
echo json_encode(array('success' => False,'message' => "File size above 5MB not allowed."));
exit(0);
}
}
if($filename){
for($i = 0; $i < count($filename);$i++){
$pro_docs[] = ['name' => $filename[$i],'tmp_name' => $tmp_name[$i]];
}
}
$doc_files = array();
foreach($pro_docs as $val){
$name = str_replace(' ', '_', $val['name']);
if(file_exists($file_path.$name)){
$doc_files[] = $file_path.$name;
}else{
$tmp_file = $val['tmp_name'];
$random = rand(1000000000, 9999999999);
$filename = $random.'_'.$name;
$doc_files[] = $file_path .$filename;
$uploaded_file= $file_path .$filename;
move_uploaded_file($tmp_file, $uploaded_file);
}
}
if($doc_files){
$doc_files = implode(',',$doc_files);
}else{
$doc_files = "";
}
//DUPLICATE REA EXIST
$rea_qry = 'SELECT * from cw_project_list WHERE trans_status = 1 AND rea = "'.$rea.'"';
$rea_info = $this->db->query("CALL sp_a_run ('SELECT','$rea_qry')");
$rea_rslt = $rea_info->result();
$rea_info->next_result();
//PROJECT LIST DATA INSERT
$pro_qry = 'SELECT * from cw_project_list WHERE trans_status = 1 AND prime_project_list_id = "'.$rea_id.'"';
$pro_info = $this->db->query("CALL sp_a_run ('SELECT','$pro_qry')");
$pro_rslt = $pro_info->result();
$pro_info->next_result();
$pro_count = count($pro_rslt);
$data = array('client_name' => $client_name,'job_type' => $job_type,'proposed_rea' => $proposed_rea,'project_name' => $project_name,'state' => $state,'city' => $city,'bid_received_date' => $bid_received_date,'bid_date' => $bid_date,'uspm' => $uspm,'target_date' => $target_date,'duplicate_job' => $duplicate_job,'existing_rea' => $existing_rea,'engineer_name' => $engineer_name,'market_category' => $market_category,'documents' => $doc_files,'pro_remarks' => $pro_remarks,'branch' => $branch,'team' => $team,'master_checker' => $master_checker,'approx_weight' => $approx_weight,'approx_days' => $approx_days,'sub_plan_for' => $sub_plan_for,'job_remarks' => $job_remarks);
if((int)$pro_count === 0){ # INSERT
if(count($rea_rslt) > 0){
echo json_encode(array('success' => FALSE,'message' => 'Failed - Duplicate REA Number.'));
exit(0);
}else{
$data['rea'] = $rea;
$data['trans_created_date'] = $created_on;
$data['trans_created_by'] = $this->logged_id;
$this->db->insert('cw_project_list', $data);
$insert_id = $this->db->insert_id();
$message = "Project Data Inserted Successfully!";
}
}else{ # UPDATE
$data['rea'] = $rea;
$data['trans_updated_date'] = $created_on;
$data['trans_updated_by'] = $this->logged_id;
$this->db->where('prime_project_list_id', $rea_id);
$this->db->update('cw_project_list', $data);
$insert_id = $rea_id;
$message = "Project Data Updated Successfully!";
}
echo json_encode(array('success' => true,'message' => $message,'rea_id' => $insert_id));
}
//ASSIGNMENT DATA INSERT
public function assign_data(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$assign_name = $this->input->post('assign_name');
$estimator = $this->input->post('estimator');
$completion_date = date("Y-m-d",strtotime($this->input->post('completion_date')));
$assign_remarks = $this->input->post('assign_remarks');
$rea_id = $this->input->post('rea_id'); //PRO LIST PRIME ID
$assign_id = $this->input->post('assign_id'); //ASSIGN TBL PRIME ID
//ESTIMATOR EMP CODE VALIDATION
$est_team = $this->session->userdata('logged_est_team');
$team = str_replace(',', '|', $est_team);
if($team){
$fil_qry =' and cw_employees.estimation_team REGEXP "(^|,)('.$team.')(,|$)"';
}
//SAME ASSIGN NAME SHOULD NOT ALLOW
$ass_name_qry = 'SELECT assign_name from cw_assignment WHERE trans_status = 1 AND prime_assignment_id != "'.$assign_id.'" AND assign_name = "'.$assign_name.'" AND pro_id = "'.$rea_id.'" ';
$ass_name_info = $this->db->query($ass_name_qry);
$ass_name_rslt = $ass_name_info->result();
$ass_name_info->next_result();
$final_qry = 'SELECT employee_code,emp_name FROM cw_employees WHERE trans_status = 1 AND prime_employees_id != 1 AND employee_code = "'.$estimator.'" AND role IN (12,15) '.$fil_qry.'';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
if(count($ass_name_rslt) > 0){
echo json_encode(array('success' => False,'message' => 'Same Assignment name could not allow.try again different name!'));
exit(0);
}else
if(count($final_result) === 0){
echo json_encode(array('success' => False,'message' => 'Invalid Employee code['.$estimator.'] Or Employee Not exist in the logged team'));
exit(0);
}else{
$assign_qry = 'SELECT assign_name,estimator,completion_date,assign_remarks from cw_assignment WHERE trans_status = 1 AND prime_assignment_id = "'.$assign_id.'"';
$assign_info = $this->db->query("CALL sp_a_run ('SELECT','$assign_qry')");
$assign_rslt = $assign_info->result();
$assign_info->next_result();
$assign_count = count($assign_rslt);
if((int)$assign_count === 0){ # INSERT
$ins_data = array('assign_name' => $assign_name,'estimator' => $estimator,'completion_date' => $completion_date,'assign_remarks' => $assign_remarks,'pro_id' => $rea_id,'trans_created_date' => date("Y-m-d h:i:s"),'trans_created_by' => $this->logged_id);
$this->db->insert('cw_assignment', $ins_data);
$insert_id = $this->db->insert_id();
echo json_encode(array('success' => True,'message' => 'Data Inserted Successfully!'));
}else{ # UPDATE
$upd_data = array('assign_name' => $assign_name,'estimator' => $estimator,'completion_date' => $completion_date,'assign_remarks' => $assign_remarks,'trans_updated_date' => date("Y-m-d h:i:s"),'trans_updated_by' => $this->logged_id);
$this->db->where('prime_assignment_id', $assign_id);
$this->db->update('cw_assignment', $upd_data);
// LOG INSERT TO ASSIGNMENT LOG
$upd_data['assign_id'] = $assign_id;
$this->db->insert('cw_assignment_log', $upd_data);
echo json_encode(array('success' => True,'message' => 'Data Updated Successfully!'));
}
}
}
//ASSIGNMENT DATA EDIT
public function assign_edit(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$prime_id = $this->input->post('prime_id');
$assign_qry = 'SELECT emp_name,assign_name,estimator,completion_date,assign_remarks FROM cw_assignment INNER JOIN cw_employees on cw_assignment.estimator = cw_employees.employee_code WHERE cw_assignment.trans_status = 1 AND cw_assignment.trans_status = 1 AND prime_assignment_id = "'.$prime_id.'"';
$assign_info = $this->db->query("CALL sp_a_run ('SELECT','$assign_qry')");
$assign_rslt = $assign_info->result();
$assign_info->next_result();
$assign_name = $assign_rslt[0]->assign_name;
$estimator = $assign_rslt[0]->estimator;
$est_name = $assign_rslt[0]->emp_name;
$completion_date = date('d-m-Y',strtotime($assign_rslt[0]->completion_date));
$assign_remarks = $assign_rslt[0]->assign_remarks;
echo json_encode(array('success' => True,'assign_name' => $assign_name,'estimator' => $estimator,'completion_date' => $completion_date,'assign_remarks' => $assign_remarks,'est_name' => $estimator ." - ". $est_name));
}
//ASSIGNMENT DATA DELETE
public function assign_delete(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$prime_id = $this->input->post('prime_id');
$update_qry = 'UPDATE cw_assignment SET trans_status = 0 WHERE prime_assignment_id = "'.$prime_id.'"';
$update_info = $this->db->query($update_qry);
if($update_info){
echo json_encode(array('success' => True,'message' => 'Deleted Successfully'));
}else{
echo json_encode(array('success' => True,'message' => 'Try again later.'));
}
}
// PROJECT DATA ONLOAD
public function search(){
$dec_data = $this->cryptoDecrypt($_POST['Payload']);
$_POST = $dec_data['d'];
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..'));
exit(0);
}
$draw = $this->input->post('draw');
$start = $this->input->post('start');
$per_page = $this->input->post('length');
$order = $this->input->post('order');
$order_col = $this->input->post('columns');
$search = $this->input->post('search');
$column = $order[0]['column'];
$order_sor = $order[0]['dir'];
$order_col = $order_col[$column]['data'];
$search = trim($search['value']);
$uspm = $this->input->post('uspm');
$team = $this->input->post('team');
$bid_received_date = $this->input->post('bid_received_date');
$sub_date = $this->input->post('sub_date');
$target_date = $this->input->post('target_date');
$est_used = $this->input->post('est');
$bid_sts = $this->input->post('bid');
$job_sts = $this->input->post('job');
$market_sts = $this->input->post('market');
$rea_no = $this->input->post('rea');
$client = $this->input->post('client');
$branch_sts = $this->input->post('branch');
$state = $this->input->post('state');
$logged_est_team = $this->session->userdata('logged_est_team');
$logged_role = (int)$this->session->userdata('logged_role');
$log_team = str_replace(',', '|', $logged_est_team);
if($log_team && $logged_role !== 1 && $logged_role !== 2){
$fil_qry =' and cw_project_list.team REGEXP "(^|,)('.$log_team.')(,|$)"';
}
//FILTER
$filter_query = "";
if(!empty($uspm) && array_filter($uspm)){
$uspm_list = implode(',', $uspm);
$filter_query .= ' AND uspm IN (' . $uspm_list . ')';
}
if(!empty($branch_sts) && array_filter($branch_sts)){
$branch_list = implode(',', $branch_sts);
$filter_query .= ' AND branch IN (' . $branch_list . ')';
}
if(!empty($team) && array_filter($team)){
$team_list = implode(',', $team);
$filter_query .= ' AND team IN (' . $team_list . ')';
}
if($state !== ''){
$filter_query .= ' AND state = "'.$state.'"';
}
if($est_used !== ''){
$filter_query .= ' AND est_used = "'.$est_used.'"';
}
if($bid_sts !== ''){
$filter_query .= ' AND bid_status = "'.$bid_sts.'"';
}
if($rea_no !== ''){
$filter_query .= ' AND (rea like "%'.$rea_no.'%")';
}
if($client !== ''){
$filter_query .= ' AND (client_name like "%'.$client.'%")';
}
if($job_sts !== ''){
$filter_query .= ' AND cw_project_list.job_type = "'.$job_sts.'"';
}
if($market_sts !== ''){
$filter_query .= ' AND market_category = "'.$market_sts.'"';
}
if($sub_date !== ''){
$sub_date = date('Y-m-d',strtotime($sub_date));
$filter_query .= ' AND submitted_date = "'.$sub_date.'"';
}
if($target_date !== ''){
$target_date = date('Y-m-d',strtotime($target_date));
$filter_query .= ' AND target_date = "'.$target_date.'"';
}
if($bid_received_date !== ''){
$bid_received_date = date('Y-m-d',strtotime($bid_received_date));
$filter_query .= ' AND bid_received_date = "'.$bid_received_date.'"';
}
$common_search = "";
if($search){
$common_search .= ' or client_name like "'.$search.'%" or rea like "'.$search.'%" or project_name like "'.$search.'%" or engineer_name like "'.$search.'%" or master_checker like "'.$search.'%"';
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
$common_search = str_replace("(,","(",$common_search);
$common_search = str_replace("()","(0)",$common_search);
}
$search_query = 'SELECT client_name,rea,project_name,bid_received_date,bid_date,target_date,approx_days,approx_weight,engineer_name,prime_project_list_id,cw_job_type.job_type,billable_ton,billable_hour,working_hour,submitted_date,master_checker FROM cw_project_list INNER JOIN cw_job_type ON cw_project_list.job_type = cw_job_type.prime_job_type_id WHERE cw_project_list.trans_status = 1 AND cw_job_type.trans_status = 1 '.$fil_qry.' '.$filter_query.''.$common_search.' ';
$search_query .= " ORDER BY $order_col $order_sor";
if((int)$per_page !== -1){
$search_query .= " LIMIT $start,$per_page";
}
$count_all_query = 'SELECT count(*) as allcount FROM cw_project_list where trans_status = 1 '.$fil_qry.'';
$count_query = 'SELECT count(*) as allcount FROM cw_project_list where trans_status = 1 '.$fil_qry.' '.$filter_query.' '.$common_search.'' ;
$search_pro_qry = [];
$search_pro_qry[] = array("return"=>"total_count","qry"=>$count_all_query);
$search_pro_qry[] = array("return"=>"filtered_count","qry"=>$count_query);
$search_pro_qry[] = array("return"=>"search_result","qry"=>$search_query);
$search_info_rslt = $this->run_multi_qry($search_pro_qry);
$total_count = $search_info_rslt->rslt->total_count[0]->allcount;
$filtered_count = $search_info_rslt->rslt->filtered_count[0]->allcount;
$search_result = json_decode(json_encode($search_info_rslt->rslt->search_result),true);
$emp_list_qry = 'SELECT employee_code,emp_name FROM cw_employees WHERE trans_status = 1';
$emp_list_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_list_qry')");
$emp_list_rslt = $emp_list_info->result();
$emp_list_info->next_result();
# EMP NAME LIST
$emp_array = [];
foreach($emp_list_rslt as $value){
$emp_array[$value->employee_code] = $value->employee_code.' - '.$value->emp_name;
}
foreach($search_result as &$search){
if($emp_array[$search['master_checker']]){
$search['master_checker'] = $emp_array[$search['master_checker']];
}
}
unset($search);
if($search_result === null || $search_result === ''){
$search_result = [];
}
echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));
}
//ASSIGNMENT ROWSET TABLE
public function assign_search(){
$dec_data = $this->cryptoDecrypt($_POST['Payload']);
$_POST = $dec_data['d'];
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..'));
exit(0);
}
$draw = $this->input->post('draw');
$start = $this->input->post('start');
$per_page = $this->input->post('length');
$order = $this->input->post('order');
$order_col = $this->input->post('columns');
$search = $this->input->post('search');
$column = $order[0]['column'];
$order_sor = $order[0]['dir'];
$order_col = $order_col[$column]['data'];
$search = trim($search['value']);
$pro_id = $this->input->post('pro_id');
$common_search = "";
if($search){
$common_search .= 'or assign_name like "'.$search.'%" or estimator like "'.$search.'%" or completion_date like "'.date("Y-m-d",strtotime($search)).'%"';
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
$common_search = str_replace("(,","(",$common_search);
$common_search = str_replace("()","(0)",$common_search);
}
$search_query = 'SELECT assign_name,CONCAT_WS(" - ", estimator,emp_name) AS estimator,completion_date,prime_assignment_id,assign_remarks from cw_assignment INNER JOIN cw_employees ON cw_assignment.estimator = cw_employees.employee_code WHERE cw_assignment.trans_status = 1 AND cw_employees.trans_status = 1 AND pro_id = "'.$pro_id.'"'.$common_search.' ';
$search_query .= " ORDER BY $order_col $order_sor";
if((int)$per_page !== -1){
$search_query .= " LIMIT $start,$per_page";
}
$count_all_query = 'SELECT count(*) as allcount FROM cw_assignment where trans_status = 1 AND pro_id = "'.$pro_id.'"';
$count_query = 'SELECT count(*) as allcount FROM cw_assignment where trans_status = 1 AND pro_id = "'.$pro_id.'"'.$common_search.'' ;
$search_pro_qry = [];
$search_pro_qry[] = array("return"=>"total_count","qry"=>$count_all_query);
$search_pro_qry[] = array("return"=>"filtered_count","qry"=>$count_query);
$search_pro_qry[] = array("return"=>"search_result","qry"=>$search_query);
$search_info_rslt = $this->run_multi_qry($search_pro_qry);
$total_count = $search_info_rslt->rslt->total_count[0]->allcount;
$filtered_count = $search_info_rslt->rslt->filtered_count[0]->allcount;
$search_result = json_decode(json_encode($search_info_rslt->rslt->search_result),true);
if($search_result === null || $search_result === ''){
$search_result = [];
}
echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));
}
//ASSIGNMENT LOG HISTORY
public function assign_history(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$draw = $this->input->post('draw');
$start = $this->input->post('start');
$per_page = $this->input->post('length');
$order = $this->input->post('order');
$order_col = $this->input->post('columns');
$search = $this->input->post('search');
$column = $order[0]['column'];
$order_sor = $order[0]['dir'];
$order_col = $order_col[$column]['data'];
$search = trim($search['value']);
$log_id = $this->input->post('log_id');
$common_search = "";
if($search){
$common_search .= ' or assign_name like "'.$search.'%" or estimator like "'.$search.'%" or completion_date like "'.$search.'%"';
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
$common_search = str_replace("(,","(",$common_search);
$common_search = str_replace("()","(0)",$common_search);
}
$search_query = 'SELECT assign_name,estimator,completion_date,assign_remarks,cw_assignment_log.trans_updated_date,emp_name FROM cw_assignment_log INNER JOIN cw_employees on cw_employees.prime_employees_id = cw_assignment_log.trans_updated_by WHERE cw_assignment_log.trans_status = 1 AND assign_id = "'.$log_id.'" '.$common_search.' ';
$search_query .= " ORDER BY $order_col $order_sor";
if((int)$per_page !== -1){
$search_query .= " LIMIT $start,$per_page";
}
$count_all_query = 'SELECT count(*) as allcount FROM cw_assignment_log where trans_status = 1 AND assign_id = "'.$log_id.'"';
$count_query = 'SELECT count(*) as allcount FROM cw_assignment_log where trans_status = 1 AND assign_id = "'.$log_id.'" '.$common_search.'' ;
$search_pro_qry = [];
$search_pro_qry[] = array("return"=>"total_count","qry"=>$count_all_query);
$search_pro_qry[] = array("return"=>"filtered_count","qry"=>$count_query);
$search_pro_qry[] = array("return"=>"search_result","qry"=>$search_query);
$search_info_rslt = $this->run_multi_qry($search_pro_qry);
$total_count = $search_info_rslt->rslt->total_count[0]->allcount;
$filtered_count = $search_info_rslt->rslt->filtered_count[0]->allcount;
$search_result = json_decode(json_encode($search_info_rslt->rslt->search_result),true);
if($search_result === null || $search_result === ''){
$search_result = [];
}
echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));
}
//IMPORT FILE VIEW INFORMATION
public function import(){
$data['encKey'] = $this->generateKey();
$data['module_id'] = $this->control_name;
$excel_format_qry = 'select prime_excel_format_id,excel_name from cw_util_excel_format where excel_module_id = "'.$this->control_name.'" and trans_status = 1';
$excel_format = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
$excel_result = $excel_format->result();
$excel_format->next_result();
$excel_format_drop[""] = "---- Excel Format ----";
foreach($excel_result as $excel){
$prime_excel_format_id = $excel->prime_excel_format_id;
$excel_name = $excel->excel_name;
$excel_format_drop[$prime_excel_format_id] = $excel_name;
}
$data['excel_format_drop'] = $excel_format_drop;
$this->load->view("$this->control_name/import",$data);
}
//SHEET NAME
// public function sheet_name(){
// $encString = file_get_contents('php://input');
// $_POST = $this->cryptoDecrypt($encString);
// if(!$_POST){
// echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
// exit(0);
// }
// $file_path = $this->input->post('file_path');
// $filename = dirname(__FILE__)."/php_excel/PHPExcel/IOFactory.php";
// include($filename);
// $excel_obj = PHPExcel_IOFactory::load($file_path);
// $sheet_count = $excel_obj->getSheetCount();
// $sheet_name = array();
// for($i= 0; $i< $sheet_count; $i++){
// $sheet = $excel_obj->getSheet($i);
// $sheet_name[] = $sheet->getTitle();
// }
// echo json_encode(array('sheet_name' =>$sheet_name));
// }
//EXCEL MAPPING FORMAT
// public function excel($Payload){
// //Decryption
// $_POST = $this->cryptoDecrypt(base64_decode(urldecode($Payload)));
// $module_id = $this->input->post('module_id');
// $excel_format = $this->input->post('excel_format');
// $excel_format_qry = 'select view_name,excel_line_column_name,excel_line_value from cw_util_excel_format_line inner join cw_form_setting on cw_form_setting.label_name = excel_line_column_name where excel_line_module_id = "'.$module_id.'" and prime_excel_format_id ="'.$excel_format.'" and cw_util_excel_format_line.trans_status = 1 GROUP BY cw_form_setting.label_name';
// $excel_format = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
// $excel_result = $excel_format->result();
// $excel_format->next_result();
// //require_once APPPATH."/third_party/PHPExcel.php";
// $obj = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls');//('Excel5');
// $excel2 = $excel2->load('./excel_download/detailer_report.xls');//default excel template
// //Set the first row as the header row
// foreach($excel_result as $excel){
// $excel_line_column_name = $excel->view_name;
// $excel_line_value = $excel->excel_line_value;
// $obj->getActiveSheet()->setCellValue($excel_line_value."1", $excel_line_column_name);
// }
// // Rename worksheet name
// $filename= $module_id.".xls"; //save our workbook as this file name
// ob_end_clean();
// header('Content-Type: application/vnd.ms-excel'); //mime type
// header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
// header('Cache-Control: max-age=0'); //no cache
// ob_end_clean();
// //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
// //if you want to save it as .XLSX Excel 2007 format
// $objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel5');
// //force user to download the Excel file without writing it to server's HD
// $objWriter->save('php://output');
// echo json_encode(array('success' => TRUE, 'output' => $excelOutput));
// }
//SAVE IMPORT FILE PATH
public function save_import(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$module_id = $this->control_name;
$process_month = $this->input->post('transaction_month');
$excel_format = $this->input->post('excel_format');
$excel_file_path = $this->input->post('excel_file_path');
$excel_sheet_name = $this->input->post('excel_sheet_name');
$excel_start_row = $this->input->post('excel_start_row');
$excel_end_row = $this->input->post('excel_end_row');
$logged_id = $this->session->userdata('logged_id');
$today_date = date("Y-m-d h:i:s");
$import_query = 'INSERT INTO cw_month_import (module_id,excel_format,excel_file_path,excel_sheet_name,excel_start_row,excel_end_row,process_month,trans_created_by,trans_created_date) VALUES ("'.$module_id.'","'.$excel_format.'","'.$excel_file_path.'","'.$excel_sheet_name.'","'.$excel_start_row.'","'.$excel_end_row.'","'.$process_month.'","'.$logged_id.'","'.$today_date.'")';
$import_info = $this->db->query("CALL sp_a_run ('INSERT','$import_query')");
$import_result = $import_info->result();
$import_info->next_result();
$import_id = $import_result[0]->ins_id;
echo $this->do_excel_import($import_id);
}
//IMPORT DATA FROM FILE PATH
public function do_excel_import($import_id){
$filename = dirname(__FILE__)."/php_excel/PHPExcel/IOFactory.php";
include($filename);
if($import_id < 0){
return json_encode(array('success' => false, 'message' => "Invalid file upload"));
}
$excel_path_qry = 'SELECT * FROM cw_month_import WHERE import_id = "'.$import_id.'"';
$excel_path_info = $this->db->query("CALL sp_a_run ('SELECT','$excel_path_qry')");
$excel_path_result = $excel_path_info->result();
$excel_path_info->next_result();
if(!$excel_path_result){
return json_encode(array('success' => false, 'message' => "Invalid file upload"));
}else{
$this->prime_table = "cw_project_list";
$excel_file_path = $excel_path_result[0]->excel_file_path;
$module_id = "project_list";
$excel_format = $excel_path_result[0]->excel_format;
$excel_sheet_name = (int)$excel_path_result[0]->excel_sheet_name;
$excel_row_start = (int)$excel_path_result[0]->excel_start_row;
$excel_row_end = (int)$excel_path_result[0]->excel_end_row;
$format_qry = 'SELECT * FROM cw_util_excel_format WHERE prime_excel_format_id = "'.$excel_format.'" AND cw_util_excel_format.trans_status = 1';
$format_info = $this->db->query("CALL sp_a_run ('SELECT','$format_qry')");
$format_rslt = $format_info->result();
$format_info->next_result();
if(!$format_rslt){
return json_encode(array('success' => false, 'message' => "Please add excel format before import"));
}else{
$excel_format_qry = 'SELECT unique_field,pick_list_import,view_name,label_name,field_type,pick_table,pick_list_type,pick_list,mandatory_field,field_isdefault,excel_line_column_name,excel_line_value FROM cw_util_excel_format_line INNER JoIN cw_form_setting ON label_name = excel_line_column_name WHERE excel_line_module_id = "'.$module_id.'" AND prime_excel_format_id = "'.$excel_format.'" AND cw_form_setting.prime_module_id = "project_list" AND cw_util_excel_format_line.trans_status = 1 ORDER BY prime_excel_format_line_id ASC';
$excel_format = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
$excel_format_result = $excel_format->result();
$excel_format->next_result();
if(!$excel_format_result){
return json_encode(array('success' => false, 'message' => "Please map excel cell column before import"));
}else{
try{
$excel_obj = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel_file_path); // [MS 18-11-2024]
}catch(Exception $e){
die('Error loading file "' . pathinfo($excel_file_path, PATHINFO_BASENAME). '": ' . $e->getMessage());
return json_encode(array('success' => false, 'message' => "Invalid file or path"));
}
$sheet = $excel_obj->getSheet($excel_sheet_name);
if($excel_row_end){
$total_rows = $excel_row_end;
}else{
$total_rows = $sheet->getHighestRow();
}
//CHECKING VALIDAITON
$columnwise_result = $this->excel_columnwise_validation($sheet,$excel_format_result,$excel_row_start,$total_rows);
$err_column_array = $columnwise_result['err_column_array'];
$err_column_tabview = $columnwise_result['err_column_tabview'];
$err_column_count = count($err_column_array['error']);
if((int)$err_column_count > 0){
$table_info = $this->get_excel_error_ui($err_column_tabview);
echo json_encode(array('success'=>false,'message'=>"Column Wise Error",'table_info'=>$table_info));
exit(0);
}else{
$rowwise_result = $this->excel_rowwise_validation($sheet,$excel_format_result,$excel_row_start,$total_rows);
$err_column_array = $rowwise_result['err_column_array'];
$err_column_tabview = $rowwise_result['err_column_tabview'];
$err_column_count = count($err_column_array['error']);
if((int)$err_column_count > 0){
$table_info = $this->get_excel_error_ui($err_column_tabview);
echo json_encode(array('success'=>false,'message'=>"Row wise Error",'table_info'=>$table_info));
exit(0);
}else{
// IMPORT TO DB
$final_result = $this->final_excel_import($sheet,$excel_format_result,$excel_row_start,$total_rows);
}
}
}
}
}
}
//COLUMNWISE VALIDATION.
public function excel_columnwise_validation($sheet,$excel_format_result,$excel_row_start,$total_rows){
$err_column_tabview = array();
foreach($excel_format_result as $key => $value){
$date_type = (int)$value->date_type;
$text_type = (int)$value->text_type;
$mandatory_field = (int)$value->mandatory_field;
$label_name = $value->label_name;
$view_name = $value->view_name;
$field_type = (int)$value->field_type;
$pick_table = $value->pick_table;
$pick_list_type = (int)$value->pick_list_type;
$excel_line_value = $value->excel_line_value;
$pick_list_import = (int)$value->pick_list_import;
$pick_list = $value->pick_list;
$get_cell_value = $sheet->rangeToArray("$excel_line_value$excel_row_start:$excel_line_value$total_rows", NULL, TRUE, TRUE, TRUE);
$i = $excel_row_start;
foreach($get_cell_value as $common_value){
foreach($common_value as $col_key =>$col_value){
if(empty($col_value) && !is_numeric($col_value) && $mandatory_field === 1){
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = ": Invalid - Empty Columns and Invalid Data - Please verify the data..!";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}else{
if($field_type === 1){
$excel_string = $sheet->getCell("$col_key$i")->getValue();
if($text_type === 1){ //TEXT
if(!empty($excel_string)){
if (!ctype_alpha($excel_string) ) {
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = ": Invalid - Please provide valid Text.!";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}
}
}
}elseif($field_type === 4){ // FOR DATE
if($date_type === 1){
$format = $sheet->getCell("$excel_line_value$i")->getStyle()->getNumberFormat()->getFormatCode();
if($format === "General" || $format === "@"){
$cell = $sheet->getCell("$excel_line_value$i");
$excelDate = $cell->getFormattedValue();
}else
if($format === "m/d/yyyy" || $format === "[$-14009]dd/mm/yyyy" || $format === "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" || $format === "[$-14009]dd/mm/yyyy;@" || $format === "[$-4009]dd/mm/yyyy;@"){
$excelDate = trim(date('d-m-Y',PHPExcel_Shared_Date::ExcelToPHP($sheet->getCell("$excel_line_value$i")->getValue())));
}else{
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = " Invalid... Please check the format and try again.";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name . " " . $msg_line;
}
if($excelDate){
if($excelDate === "31-01-1900"){
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = "- Invalid Date. Please change it!";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}elseif((int)$this->validateDATE($excelDate) === 0){
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = "[$excelDate] - Invalid ... Please map the correct DATE format (DD-MM-YYYY)";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}
}
}
}elseif(($field_type === 5)){ //PICKLIST
if($pick_list_type === 1 && $label_name !== 'job_type'){
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
$pick_list_where = $pick_list_val_2.' = "'.$col_value.'"';
if($pick_list_import === 1){
$pick_list_where = $pick_list_val_1.' = "'.$col_value.'"';
}
$pick_query = 'SELECT '.$pick_list.' FROM '.$pick_table.' WHERE '.$pick_list_where.'';
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_count = $pick_data->num_rows();
$pick_data->next_result();
if((int)$pick_count === 0){
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = "Invalid Data is Present Please Check it.!";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}
}
}else
if($field_type === 7){
if($pick_list_type === 1 && $label_name !== 'job_type'){
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
$multi_value = explode(',',$col_value);
foreach($multi_value as $pick){
$pick_list_where = $pick_list_val_2.' = "'.$pick.'"';
if($pick_list_import === 1){
$pick_list_where = $pick_list_val_1.' = "'.$pick.'"';
}
$pick_query = 'SELECT '.$pick_list.' FROM '.$pick_table.' WHERE '.$pick_list_where.'';
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_count = $pick_data->num_rows();
$pick_data->next_result();
if((int)$pick_count === 0){
$err_column_array['error']["$excel_line_value$i"] = $view_name;
$msg_line = "Invalid Data is Present Please Check it.!";
$err_column_tabview['error']["$excel_line_value$i"] = $view_name." ".$msg_line;
}
}
}
}
}
$i++;
}
}
}
$check_array = array("err_column_array" => $err_column_array,"err_column_tabview" => $err_column_tabview);
return $check_array;
}
//ROW WISE VALIDATION
public function excel_rowwise_validation($sheet,$excel_format_result,$excel_row_start,$total_rows){
$pro_qry = 'SELECT rea FROM cw_project_list WHERE trans_status = 1';
$pro_info = $this->db->query("CALL sp_a_run ('SELECT','$pro_qry')");
$pro_rslt = $pro_info->result_array();
$pro_info->next_result();
$rea_arr = array_column($pro_rslt,'rea');
for($row = $excel_row_start; $row <= $total_rows;$row++){
foreach($excel_format_result as $excel_info){
$label_name = $excel_info->label_name;
$field_type = (int)$excel_info->field_type;
$text_type = (int)$excel_info->text_type;
$excel_line_column_name = $excel_info->excel_line_column_name;
$excel_line_value = $excel_info->excel_line_value;
$view_name = $excel_info->view_name;
$pick_list_type = (int)$excel_info->pick_list_type;
$pick_list = $excel_info->pick_list;
$pick_table = $excel_info->pick_table;
$pick_list_import = (int)$excel_info->pick_list_import;
$mandatory_field = (int)$excel_info->mandatory_field;
$field_length = (int)$excel_info->field_length;
$module_id = $excel_info->prime_module_id;
$get_cell_value = trim($sheet->getCell("$excel_line_value$row")->getCalculatedValue());
if($excel_line_column_name === "rea"){
$rea = $get_cell_value;
if(in_array($rea,$rea_arr)){
$err_column_array['error']["$row"] = $view_name;
$msg_line = "Invalid - REA Number[$rea] already exist.";
$err_column_tabview['error']["$row"] = $msg_line;
}
}
}
}
$check_array = array("err_column_array" => $err_column_array,"err_column_tabview" => $err_column_tabview);
return $check_array;
}
//FINAL IMPORT
public function final_excel_import($sheet,$excel_format_result,$excel_row_start,$total_rows){
$created_on = date("Y-m-d H:i:s");
for($row = $excel_row_start; $row <= $total_rows; $row++){
$prime_column_val = "";
$prime_cell_val = "";
foreach($excel_format_result as $excel_info){
$label_id = $excel_info->label_name;
$field_type = (int)$excel_info->field_type;
$pick_table = $excel_info->pick_table;
$date_type = (int)$excel_info->date_type;
$pick_list_type = (int)$excel_info->pick_list_type;
$pick_list_import = (int)$excel_info->pick_list_import;
$pick_list = $excel_info->pick_list;
$field_isdefault = (int)$excel_info->field_isdefault;
$excel_line_value = $excel_info->excel_line_value;
$excel_line_column_name = $excel_info->excel_line_column_name;
$get_cell_value = trim($sheet->getCell("$excel_line_value$row")->getCalculatedValue());
//CHANGING "",'',& TO ~,^,`
if($get_cell_value){
$get_cell_value = str_replace('"',"~",$get_cell_value);
$get_cell_value = str_replace("'","`",$get_cell_value);
$get_cell_value = str_replace("&","^",$get_cell_value);
}
if($excel_line_column_name === "rea"){
$get_cell_value = $get_cell_value;
}
//DATE
if($field_type === 4){
$format = $sheet->getCell("$excel_line_value$row")->getStyle()->getNumberFormat()->getFormatCode();
if($format === "General" || $format === "@"){
$rawDateValue = $sheet->getCell("$excel_line_value$row")->getValue();
$parsedDate = DateTime::createFromFormat('d-m-Y', $rawDateValue);
if($parsedDate){
$get_cell_value = $parsedDate->format('Y-m-d');
}
}else
if($format === "m/d/yyyy" || $format === "[$-14009]dd/mm/yyyy" || $format === "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" || $format === "[$-14009]dd/mm/yyyy;@"){
$get_cell_value = trim(Date::excelToDateTimeObject($sheet->getCell("$excel_line_value$row")->getValue())->format('Y-m-d'));
}else{
$get_cell_value = '';
}
}
// FOR PICKLIST CHECK
if(($field_type === 5) || ($field_type === 9)){
if(($get_cell_value !='') || ($get_cell_value !=0)){
if($pick_list_type === 1){ //From table
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
if($pick_list_import === 1){
$pick_query = 'select '.$pick_list.' from '.$pick_table.' where '.$pick_list_val_1.' = "'.$get_cell_value.'"';
}else{
$pick_query = 'select '.$pick_list.' from '.$pick_table.' where '.$pick_list_val_2.' = "'.$get_cell_value.'"';
}
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_count = $pick_data->num_rows();
$pick_data->next_result();
$created_on = date("Y-m-d H:i:s");
if((int)$pick_count === 0){
$pick_list_val_2 .= ",trans_created_by,trans_created_date";
$get_cell_value_val = '"'.$get_cell_value.'",';
$get_cell_value_val .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
if($pick_table !== $this->prime_table){
$ins_query = 'insert into '.$pick_table.'('.$pick_list_val_2.') VALUES ('.$get_cell_value_val.')';
$ins_info = $this->db->query("CALL sp_a_run ('INSERT','$ins_query')");
$ins_result = $ins_info->result();
$ins_info->next_result();
$get_cell_value = $ins_result[0]->ins_id;
$second_insert_id = $ins_result[0]->ins_id;
$prime_id = $pick_table."_id";
$prime_id = str_replace("cw_","prime_",$prime_id);
}
}else
if((int)$pick_count > 0){
if($pick_table !== $this->prime_table){
$pick_id = $pick_result[0]->$pick_list_val_1;
$pick_status = (int)$pick_result[0]->trans_status;
if($pick_status === 0){
$upd_query = 'update '.$pick_table.' set trans_status = 1 where '.$pick_list_val_1.' = '.$pick_id;
$this->db->query("CALL sp_a_run ('RUN','$upd_query')");
}
$get_cell_value = $pick_id;
}
}
}
}
}
// FOR MULTIPICKLIST
if(($field_type === 7)){
if(($get_cell_value !='') || ($get_cell_value !=0)){
if($pick_list_type === 1){ //From table
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
$multi_value = explode(',',$get_cell_value);
$cell_values = '';
foreach($multi_value as $pick){
if($pick_list_import === 1){
$pick_query = 'select '.$pick_list.' from '.$pick_table.' where '.$pick_list_val_1.' = "'.$pick.'"';
}else{
$pick_query = 'select '.$pick_list.' from '.$pick_table.' where '.$pick_list_val_2.' = "'.$pick.'"';
}
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_count = $pick_data->num_rows();
$pick_data->next_result();
$created_on = date("Y-m-d H:i:s");
if((int)$pick_count === 0){
$pick_list_val_2 .= ",trans_created_by,trans_created_date";
$get_cell_value_val = '"'.$get_cell_value.'",';
$get_cell_value_val .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
if($pick_table !== $this->prime_table){
$ins_query = 'insert into '.$pick_table.'('.$pick_list_val_2.') VALUES ('.$get_cell_value_val.')';
$ins_info = $this->db->query("CALL sp_a_run ('INSERT','$ins_query')");
$ins_result = $ins_info->result();
$ins_info->next_result();
$cell_values .= $ins_result[0]->ins_id.',';
$second_insert_id = $ins_result[0]->ins_id;
$prime_id = $pick_table."_id";
$prime_id = str_replace("cw_","prime_",$prime_id);
}
}else
if((int)$pick_count > 0){
if($pick_table !== $this->prime_table){
$pick_id = $pick_result[0]->$pick_list_val_1;
$pick_status = (int)$pick_result[0]->trans_status;
if($pick_status === 0){
$upd_query = 'update '.$pick_table.' set trans_status = 1 where '.$pick_list_val_1.' = '.$pick_id;
$this->db->query("CALL sp_a_run ('RUN','$upd_query')");
}
$cell_values .= $pick_id.',';
}
}
}
$get_cell_value = rtrim($cell_values,',');
}
}
}
if($field_isdefault === 1){
$prime_column_val .= $excel_line_column_name . ",";
$prime_cell_val .= "\'" . $get_cell_value . "\',";
}
}
$prime_column_val = rtrim($prime_column_val,",");
$prime_cell_val = rtrim($prime_cell_val,",");
$prime_query = "INSERT INTO cw_project_list ($prime_column_val) VALUES ($prime_cell_val)";
$insert_info = $this->db->query("CALL sp_a_run ('INSERT','$prime_query')");
$insert_result = $insert_info->result();
$insert_info->next_result();
}
echo json_encode(array('success' => true,'message' => "Successfully file imported"));
}
public function save_importAssign(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$excel_file_path = $this->input->post('excel_file_path');
$excel_sheet_name = $this->input->post('excel_sheet_name');
$excel_start_row = $this->input->post('excel_start_row');
$excel_end_row = $this->input->post('excel_end_row');
$pro_id = $this->input->post('pro_id');
$logged_id = $this->session->userdata('logged_id');
$prime_column_val = '';
try{
$excel_obj = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel_file_path); // [MS 18-11-2024]
}catch(Exception $e){
die('Error loading file "' . pathinfo($excel_file_path, PATHINFO_BASENAME). '": ' . $e->getMessage());
return json_encode(array('success' => false, 'message' => "Invalid file or path"));
}
$sheet = $excel_obj->getSheet($excel_sheet_name);
if($excel_end_row){
$total_rows = $excel_end_row;
}else{
$total_rows = $sheet->getHighestRow();
}
if($excel_start_row > $total_rows){
echo json_encode(array('success'=>false,'message'=>"No record available after row $excel_start_row in excel",'table_info'=>''));
exit(0);
}
//ESTIMATOR EMP CODE VALIDATION
$est_team = $this->session->userdata('logged_est_team');
$team = str_replace(',', '|', $est_team);
if($team){
$fil_qry =' and cw_employees.estimation_team REGEXP "(^|,)('.$team.')(,|$)"';
}
$final_qry = 'SELECT employee_code FROM cw_employees WHERE trans_status = 1 AND prime_employees_id != 1 AND role = 12 '.$fil_qry.'';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
$est_array = array();
foreach($final_result as $est){
$code = $est->employee_code;
$est_array[$code] = $code;
}
for($row = $excel_start_row; $row <= $total_rows; $row++){
$columns = ['A', 'B', 'C', 'D'];
foreach($columns as $excel_line_value){
$view_name = trim($sheet->getCell($excel_line_value.'1')->getCalculatedValue());
$get_cell_value = trim($sheet->getCell($excel_line_value.$row)->getCalculatedValue());
if(($excel_line_value === "A" || $excel_line_value === "B" || $excel_line_value === "C") && empty($get_cell_value)){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = ": Invalid - Empty Columns and Invalid Data - Please verify the data..!";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}
if($excel_line_value === "A" && !ctype_alpha($get_cell_value)){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = ": Invalid - Please provide valid Text.!";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}
if($excel_line_value === "B" && !$est_array[$get_cell_value]){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = ": Invalid - Estimator code.!";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}
if($excel_line_value === "B" && (int)$this->validateinteger($get_cell_value) === 0){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = ": Invalid - Please provide a valid integer.!";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}
if($excel_line_value === "C"){
$format = $sheet->getCell("$excel_line_value$row")->getStyle()->getNumberFormat()->getFormatCode();
if($format === "General" || $format === "@"){
$cell = $sheet->getCell("$excel_line_value$row");
$excelDate = $cell->getFormattedValue();
}else
if($format === "m/d/yyyy" || $format === "[$-14009]dd/mm/yyyy" || $format === "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" || $format === "[$-14009]dd/mm/yyyy;@" || $format === "[$-4009]dd/mm/yyyy;@"){
$excelDate = trim(date('d-m-Y',PHPExcel_Shared_Date::ExcelToPHP($sheet->getCell("$excel_line_value$row")->getValue())));
}else{
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = " Invalid... Please check the format and try again.";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name . " " . $msg_line;
}
if($excelDate){
if($excelDate === "31-01-1900"){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = "- Invalid Date. Please change it!";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}elseif((int)$this->validateDATE($excelDate) === 0){
$err_column_array['error']["$excel_line_value$row"] = $view_name;
$msg_line = "[$excelDate] - Invalid ... Please map the correct DATE format (DD-MM-YYYY)";
$err_column_tabview['error']["$excel_line_value$row"] = $view_name." ".$msg_line;
}
}
}
}
}
if($err_column_array['error']){
$err_column_count = count($err_column_array['error']);
}
if((int)$err_column_count > 0){
$table_info = $this->get_excel_error_ui($err_column_tabview);
echo json_encode(array('success'=>false,'message'=>"Row wise Error",'table_info'=>$table_info));
exit(0);
}else{
for($row = $excel_start_row; $row <= $total_rows; $row++){
$prime_cell_val = "";
$columns = ['A', 'B', 'C', 'D'];
foreach($columns as $excel_line_value){
$view_name = trim($sheet->getCell($excel_line_value.'1')->getCalculatedValue());
$get_cell_value = trim($sheet->getCell($excel_line_value.$row)->getCalculatedValue());
$get_cell_value = str_replace('"',"~",$get_cell_value);
$get_cell_value = str_replace("'","`",$get_cell_value);
$get_cell_value = str_replace("&","^",$get_cell_value);
if($excel_line_value === "C"){
$format = $sheet->getCell("$excel_line_value$row")->getStyle()->getNumberFormat()->getFormatCode();
if($format === "General" || $format === "@"){
$rawDateValue = $sheet->getCell("$excel_line_value$row")->getValue();
$parsedDate = DateTime::createFromFormat('d-m-Y', $rawDateValue);
if($parsedDate){
$get_cell_value = $parsedDate->format('Y-m-d');
}
}else
if($format === "m/d/yyyy" || $format === "[$-14009]dd/mm/yyyy" || $format === "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" || $format === "[$-14009]dd/mm/yyyy;@"){
$get_cell_value = trim(Date::excelToDateTimeObject($sheet->getCell("$excel_line_value$row")->getValue())->format('Y-m-d'));
}else{
$get_cell_value = '';
}
}
$prime_column_val .= $view_name . ",";
$prime_cell_val .= "\'" . $get_cell_value . "\',";
}
$status = 0;
$prime_cell_val .= "\'" . $pro_id . "\',\'" . $status . "\'";
$prime_query = "INSERT INTO cw_assignment(assign_name,estimator,completion_date,assign_remarks,pro_id,assign_status) VALUES ($prime_cell_val)";
$insert_info = $this->db->query("CALL sp_a_run ('INSERT','$prime_query')");
$insert_result = $insert_info->result();
$insert_info->next_result();
}
echo json_encode(array('success' => true,'message' => "Successfully file imported"));
}
}
//JOB COMPLETION
public function job_completion(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$pro_id = $this->input->post('prime_id');
$pro_qry = 'SELECT * from cw_project_list WHERE trans_status = 1 AND prime_project_list_id = "'.$pro_id.'" ';
$pro_info = $this->db->query("CALL sp_a_run ('SELECT','$pro_qry')");
$pro_rslt = $pro_info->result();
$pro_info->next_result();
//CLAIM TYPE
$claim_qry = 'SELECT prime_claim_type_id,claim_type FROM cw_claim_type WHERE trans_status = 1 ';
$claim_info = $this->db->query("CALL sp_a_run ('SELECT','$claim_qry')");
$claim_rslt = $claim_info->result();
$claim_info->next_result();
$claim_list["0"] = "---- claim type ----";
foreach($claim_rslt as $for){
$prime_id = $for->prime_claim_type_id;
$claim_type = $for->claim_type;
$claim_list[$prime_id] = $claim_type;
}
//STATUS MODE
$sts_qry = 'SELECT prime_status_mode_id,status_mode_value FROM cw_status_mode WHERE trans_status = 1 ';
$sts_info = $this->db->query("CALL sp_a_run ('SELECT','$sts_qry')");
$sts_rslt = $sts_info->result();
$sts_info->next_result();
$sts_list["0"] = "---- select ----";
foreach($sts_rslt as $for){
$prime_id = $for->prime_status_mode_id;
$status_mode = $for->status_mode_value;
$sts_list[$prime_id] = $status_mode;
}
//DETAILING TEAM
$team_qry = 'SELECT prime_team_id,team_name FROM cw_team WHERE trans_status = 1 ';
$team_info = $this->db->query("CALL sp_a_run ('SELECT','$team_qry')");
$team_rslt = $team_info->result();
$team_info->next_result();
$team_list["0"] = "---- team ----";
foreach($team_rslt as $for){
$prime_id = $for->prime_team_id;
$team = $for->team_name;
$team_list[$prime_id] = $team;
}
//ESITMATION USED FOR
$est_qry = 'SELECT prime_est_used_for,est_used_for FROM cw_est_used_for WHERE trans_status = 1 ';
$est_info = $this->db->query("CALL sp_a_run ('SELECT','$est_qry')");
$est_rslt = $est_info->result();
$est_info->next_result();
$est_list["0"] = "---- est used ----";
foreach($est_rslt as $for){
$prime_id = $for->prime_est_used_for;
$est_status = $for->est_used_for;
$est_list[$prime_id] = $est_status;
}
//BID STATUS
$bid_qry = 'SELECT prime_bid_status_id,bid_status FROM cw_bid_status WHERE trans_status = 1 ';
$bid_info = $this->db->query("CALL sp_a_run ('SELECT','$bid_qry')");
$bid_rslt = $bid_info->result();
$bid_info->next_result();
$bid_list["0"] = "---- bid status ----";
foreach($bid_rslt as $for){
$prime_id = $for->prime_bid_status_id;
$bid_status = $for->bid_status;
$bid_list[$prime_id] = $bid_status;
}
//EMPLOYEE NAME
$emp_list_qry = 'SELECT employee_code,emp_name FROM cw_employees WHERE trans_status = 1';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_list_qry')");
$emp_rslt = $emp_info->result();
$emp_info->next_result();
$emp_array = [];
foreach($emp_rslt as $value){
$emp_array[$value->employee_code] = $value->emp_name;
}
$data['pro_id'] = $pro_id;
$data['sts_list'] = $sts_list;
$data['team_list'] = $team_list;
$data['bid_sts'] = $bid_list;
$data['claim_list'] = $claim_list;
$data['rea'] = $pro_rslt[0]->rea;
$data['project'] = $pro_rslt[0]->project_name;
$data['client'] = $pro_rslt[0]->client_name;
$data['bid_date'] = date('d-m-Y',strtotime($pro_rslt[0]->bid_received_date));
$data['mast_chk'] = $pro_rslt[0]->master_checker." - ".$emp_array[$pro_rslt[0]->master_checker];
$data['det_award'] = $pro_rslt[0]->detailed_award;
$data['det_team'] = $pro_rslt[0]->detailing_team;
if($pro_rslt[0]->submitted_date){
$data['sub_date'] = ($pro_rslt[0]->submitted_date !== '1970-01-01') ? date('d-m-Y',strtotime($pro_rslt[0]->submitted_date)) : '';
}
$data['bid_status'] = $pro_rslt[0]->bid_status;
$data['est_used'] = $pro_rslt[0]->est_used;
$data['job_type'] = $pro_rslt[0]->job_type;
$data['bill_type'] = $pro_rslt[0]->billable_type;
$data['bill_ton'] = $pro_rslt[0]->billable_ton;
$data['bill_hour'] = $pro_rslt[0]->billable_hour;
$data['work_hour'] = $pro_rslt[0]->working_hour;
$data['sub_files'] = $pro_rslt[0]->sub_files;
$data['est_used_for'] = $est_list;
$data['encKey'] = $this->generateKey();
$this->load->view("$this->control_name/job_status",$data);
}
public function job_completion_save(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$prime_id = $this->input->post('project_id');
$submitted_date = date("Y-m-d",strtotime($this->input->post('submitted_date')));
$bid_status = $this->input->post('bid_status');
$est_used = $this->input->post('est_used');
$billable_type = $this->input->post('billable_type');
$billable_ton = $this->input->post('billable_ton');
$billable_hour = $this->input->post('billable_hour');
$working_hour = $this->input->post('working_hour');
$detailed_award = $this->input->post('detailed_award');
if($this->input->post('detailing_team')){
$detailing_team = implode(',',$this->input->post('detailing_team'));
}
# ATTACHMENT
$filename = $_FILES['pro_docs']['name'];
$tmp_name = $_FILES['pro_docs']['tmp_name'];
$filetype = $_FILES['pro_docs']['type'];
$filesize = $_FILES['pro_docs']['size'];
$created_on = date("Y-m-d h:i:s");
$pro_docs = [];
$doc_files = '';
$file_path = "./project_list/docs/";
if(!file_exists($file_path)){
mkdir($file_path, 0777, true);
}
$format = ['text/xml','image/png','image/jpeg','text/plain','application/pdf','application/zip','application/vnd.ms-excel','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-outlook','message/rfc822','application/x-zip-compressed','application/octet-stream'];
# FILE TYPE VALIDATION
foreach($filetype as $type){
if(!in_array($type, $format)){
echo json_encode(array('success' => False,'message' => "File type $type is not allowed."));
exit(0);
}
}
# FILE SIZE VALIDATION
foreach($filesize as $size){
if($size > 5242880){ # MB IN BYTES (5 * 1024) * 5024
echo json_encode(array('success' => False,'message' => "File size above 5MB not allowed."));
exit(0);
}
}
if($filename){
for($i = 0; $i < count($filename);$i++){
$pro_docs[] = ['name' => $filename[$i],'tmp_name' => $tmp_name[$i]];
}
}
$doc_files = array();
foreach($pro_docs as $val){
$name = str_replace(' ', '_', $val['name']);
if(file_exists($file_path.$name)){
$doc_files[] = $file_path.$name;
}else{
$tmp_file = $val['tmp_name'];
$random = rand(1000000000, 9999999999);
$filename = $random.'_'.$name;
$doc_files[] = $file_path .$filename;
$uploaded_file = $file_path .$filename;
move_uploaded_file($tmp_file, $uploaded_file);
}
}
if($doc_files){
$doc_files = implode(',',$doc_files);
}
$upd_qry = 'UPDATE cw_project_list SET submitted_date = "'.$submitted_date.'",bid_status = "'.$bid_status.'",est_used = "'.$est_used.'",billable_type = "'.$billable_type.'",billable_ton = "'.$billable_ton.'",billable_hour = "'.$billable_hour.'",working_hour = "'.$working_hour.'",sub_files = "'.$doc_files.'",detailed_award = "'.$detailed_award.'",detailing_team = "'.$detailing_team.'" WHERE trans_status = 1 AND prime_project_list_id = "'.$prime_id.'"';
$upd_info = $this->db->query($upd_qry);
if($upd_info){
echo json_encode(array('success' => TRUE, 'message' => 'Data updated successfully'));
}else{
echo json_encode(array('success' => FALSE, 'message' => 'Data not updated'));
}
}
}
?>