middleware('auth',['except' => ['filestable_data']]); } function index() { return view('uploadfiles'); } function upload(Request $request) { @set_time_limit(-1); $file = $request->file; $request->validate([ 'file' => 'required|mimes:pdf', ]); // use of pdf parser to read content from pdf $fileName = $file->getClientOriginalName(); $pdfParser = new Parser(); $pdf = $pdfParser->parseFile($file->path()); $content = $pdf->getText(); $pages = $pdf->getPages(); $pagecount = count($pages); $text = $pdf->getText(); // dd($text); $searchTerm="Date: Monday 10/23/2023"; $pagess = explode("Foreman(s)", $text); $pagecounts = count($pagess); //dd($pagecounts); $i=1; if(!File::isDirectory('files/'.$request->thedate)){ File::makeDirectory('files/'. $request->thedate, 0777); $file->move(public_path('files/'. $request->thedate), $fileName); } for($i=1;$i<$pagecounts;$i++){ $fourth_table=''; $bit_data_table=''; $year=date('Y',strtotime($request->thedate)); $patternToExtract1= '/Page\s+\d+\s+of\s+\d+\s+.*?\d{2}\/\d{2}\/\d{4}\s+-\s+\d{2}\/\d{2}\/\d{4}/s'; $patternToExtract2 = '/Page\s+\d+\s+of\s+\d+\s+(.*?)\d{2}\/\d{2}\/\d{4}\s+-\s+\d{2}\/\d{2}\/\d{4}/s'; $patternToExtract = '/Page\s+\d+\s+of\s+\d+\s+.*?\d{2}\/\d{2}\/\d{4}\s+-\s+\d{2}\/\d{2}\/\d{4}/s'; preg_match($patternToExtract, $pagess[$i], $matchesd); if (!empty($matchesd)) { $pagess[$i]=str_replace($matchesd[0], '', str_replace("Copyright ".$year." Saudi Aramco. All Rights Reserved", '', $pagess[$i])); } preg_match($patternToExtract1, $pagess[$i], $matchesd1); if (!empty($matchesd1)) { $pagess[$i]=str_replace($matchesd1[0], '', str_replace("Copyright ".$year." Saudi Aramco. All Rights Reserved", '', $pagess[$i])); } preg_match($patternToExtract2, $pagess[$i], $matchesd2); if (!empty($matchesd2)) { $pagess[$i]=str_replace($matchesd2[0], '', str_replace("Copyright ".$year." Saudi Aramco. All Rights Reserved", '', $pagess[$i])); } //dd($pagess[$i]); $startKeyword = "Date: "; $endKeyword = "Rig"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $date=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword =$date; $endKeyword = "Well"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $reg_namee=str_replace('"""', '', str_replace("\n", '', $extractedText)); $a=explode('Rig',$reg_namee); $reg_name=$a[1]; } $startKeyword = "Well"; $endKeyword = "Charge"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $sec_name=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Well"; $endKeyword = "Prev. Depth (ft)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $first_block = trim($matches[1]); } $new_name = $fileName; $u= new MultipleFiles(); $u->reg_name=$reg_name; $u->sec_name=$sec_name; $u->file_path=$new_name; $u->upload_date=$request->thedate; $u->save(); $file_id=$u->id; $startKeyword = "MISCELLANEOUS\n"; $endKeyword = "TRUCKS/BOATS"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $pattern2 = '/Weight.*?Operating Hours. /s'; $pattern3 = 'Company'; $pattern4 = 'Category'; // $pattern5 = 'No. of Persons'; $pattern6 = 'Personnel on Loc. Hrs.'; $pattern7 = 'Operating Hours.'; $pattern8 = '/PERSONNEL.*?INFORMATION/s'; $extractedText = preg_replace($pattern2, '', $extractedText); $extractedText = preg_replace($pattern8, '', $extractedText); $extractedText = str_replace($pattern3, '', $extractedText); $extractedText = str_replace($pattern4, '', $extractedText); // $extractedText = str_replace($pattern5, '', $extractedText); $extractedText = str_replace($pattern6, '', $extractedText); $extractedText = str_replace($pattern7, '', $extractedText); $companies_table=str_replace('"""', '', str_replace("\n", ' ', $extractedText)); } if(isset($companies_table)){ $targetWord1 = 'Bit Number'; $position1 = strpos( $companies_table,$targetWord1); if ($position1 !== false) { $pattern_all88 = '/Bit Number.*?No. of Persons/s'; $companies_table = preg_replace($pattern_all88, '', $companies_table); $pattern_all89 = '/Bit Number.*?BOP Test/s'; $companies_table = preg_replace($pattern_all89, '', $companies_table); $ffg="c1"; }else{ $pattern_all99 = '/BOP Test.*?Operating Hours./s'; $companies_table = preg_replace($pattern_all99, '', $companies_table); $pattern5 = 'No. of Persons'; $companies_table = str_replace($pattern5, '', $companies_table); $ffg="c2"; } $data_comp=[]; $lines_comp=[]; $rt=explode('Total',$companies_table); //dd($pagess[$i],$companies_table,$rt); if(isset($rt[1])){ $cc=trim($rt[1]); $c =explode(' ',$cc); if(count($c)==1){ $ff="go"; }else{ $ff="No go"; } $targetWord = 'Weight'; $position = strpos($rt[1], $targetWord); if ($position !== false) { $pattern_all = '/Weight.*$/s'; $pattern_all2 = '/BOP Test.*$/s'; $companies_table = preg_replace($pattern_all, '', $companies_table); $companies_table = preg_replace($pattern_all2, '', $companies_table); $rt=explode('Total',$companies_table); $d1= isset($rt[0])?trim($rt[0]):''; $d2= isset($rt[1])?trim($rt[1]):''; $rr0=explode(' ',$d1); $rr1=explode(' ',$d2); $chunks = array_chunk($rr0, 5); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($chunk[2])?$chunk[2]:''; $lines_comp['On_Location_Hrs']=isset($chunk[3])?$chunk[3]:''; $lines_comp['Operating_Hrs']=isset($chunk[4])?$chunk[4]:''; $lines_comp['file_id']=$file_id; $lines_comp['total']=$rr1[0]; array_push($data_comp,$lines_comp); $lines_comp=[]; $res="1"; } }else{ $d1=trim($rt[0]); $d2=trim($rt[1]); $rr0=explode(' ',$d1); $rr1=explode(' ',$d2); $total=$rr1[0]; $rr1=array_slice($rr1, 1); if($ff=="go"){ $d1=trim($rt[0]); $d2=trim($rt[1]); $rr0=explode(' ',$d1); $rr1=explode(' ',$d2); $total=$d2; //dd($rr0,$rr1); $chunks = array_chunk($rr0, 5); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($chunk[2])?$chunk[2]:''; $lines_comp['On_Location_Hrs']=isset($chunk[3])?$chunk[3]:''; $lines_comp['Operating_Hrs']=isset($chunk[4])?$chunk[4]:''; $lines_comp['file_id']=$file_id; $lines_comp['total']=$total; array_push($data_comp,$lines_comp); $lines_comp=[]; $res="2"; } }else{ $hasNumericValues = count(array_filter($rr1, 'is_numeric')) === count($rr1); if ($hasNumericValues) { // $pattern9 = '/PERSONNEL.*?Operating Hours./s'; // $companies_table = preg_replace($pattern9, '', $companies_table); $rt=explode('Total',$companies_table); $d1=trim($rt[0]); $d2=trim($rt[1]); $rr0=explode(' ',$d1); $rr1=explode(' ',$d2); if((is_numeric($rr0[2]))&&(is_numeric($rr0[3]))){ $v=1; $chunks = array_chunk($rr0, 4); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($chunk[2])?$chunk[2]:''; $lines_comp['On_Location_Hrs']=isset($chunk[3])?$chunk[3]:''; $lines_comp['Operating_Hrs']=$rr1[$v]; $lines_comp['total']=$total; $lines_comp['file_id']=$file_id; array_push($data_comp,$lines_comp); $lines_comp=[]; $v++; } $res="3"; }elseif((is_numeric($rr0[2]))&&(!is_numeric($rr0[3]))){ $v=0; $v2=1; $chunks = array_chunk($rr0, 3); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($chunk[2])?$chunk[2]:''; $lines_comp['On_Location_Hrs']=$rr1[$v]; $lines_comp['Operating_Hrs']=$rr1[$v2]; $lines_comp['total']=$total; $lines_comp['file_id']=$file_id; array_push($data_comp,$lines_comp); $lines_comp=[]; $v+=2; $v2+=2; } $res="4"; }else{ $v=0; $v2=1; $v3=2; $chunks = array_chunk($rr0, 2); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($rr1[$v])?$rr1[$v]:''; $lines_comp['On_Location_Hrs']=isset($rr1[$v2])?$rr1[$v2]:''; $lines_comp['Operating_Hrs']=isset($rr1[$v3])?$rr1[$v3]:''; $lines_comp['total']=$total; $lines_comp['file_id']=$file_id; array_push($data_comp,$lines_comp); $lines_comp=[]; $v+=3; $v2+=3; $v3+=3; } $res="5"; } }else{ // $pattern_all89 = '/BOP Drills.*?Operating Hours./s'; // $companies_table = preg_replace($pattern_all89, '', $companies_table); $rt=explode('Total',$companies_table); $d1=trim($rt[0]); $d2=trim($rt[1]); $rr0=explode(' ',$d1); $rr1=explode(' ',$d2); if((!is_numeric($rr1[1]))&&(is_numeric($rr1[2]))){ $v=1; $v2=2; $v3=3; $v4=4; $chunks = array_chunk($rr0, 1); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($rr1[$v])?$rr1[$v]:''; $lines_comp['No_of_Persons']=isset($rr1[$v2])?$rr1[$v2]:''; $lines_comp['On_Location_Hrs']=isset($rr1[$v3])?$rr1[$v3]:''; $lines_comp['Operating_Hrs']=isset($rr1[$v4])?$rr1[$v4]:''; $lines_comp['total']=$total; $lines_comp['file_id']=$file_id; array_push($data_comp,$lines_comp); $lines_comp=[]; $v+=4; $v2+=4; $v3+=4; $v4+=4; } $res="8"; }else{ $v=1; $chunks = array_chunk($rr0, 4); foreach ($chunks as $chunk) { $lines_comp['Company']=isset($chunk[0])?$chunk[0]:''; $lines_comp['Category']=isset($chunk[1])?$chunk[1]:''; $lines_comp['No_of_Persons']=isset($chunk[2])?$chunk[2]:''; $lines_comp['On_Location_Hrs']=isset($chunk[3])?$chunk[3]:''; $lines_comp['Operating_Hrs']=isset($rr1[$v])?$rr1[$v]:''; $lines_comp['total']=$total; $lines_comp['file_id']=$file_id; array_push($data_comp,$lines_comp); $lines_comp=[]; $v++; } $res="6"; } } } } }else{ $ff="No go"; } // dd($pagess[$i],$res,$ffg,$data_comp,$chunks,$companies_table,$rt,$rr0,$rr1); foreach ($data_comp as $item){ $r=Companies::create($item); } } $startKeyword = "Charge #:"; $endKeyword = "Wellbores"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $well_no_and_charge=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Wellbores:"; $endKeyword = "Objective :"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $first_block, $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Wellbores=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Objective :"; $endKeyword = "THURAYA"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $first_block, $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Objective=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $longText=$pagess[$i]; $targetWord = 'Engineer'; $position = strpos($longText, $targetWord); if ($position !== false) { $extractedText = substr($longText, 0, $position); $Foreman_Engineer = str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Engineer"; $endKeyword = "Manager"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Engineer=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Manager "; $endKeyword = " Morning Report (Service Providers View)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Manager=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "THURAYA"; $endKeyword = "RIG FORMAN VSAT"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $THURAYA=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "RIG FORMAN VSAT"; $endKeyword = "Last 24 hr operations"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $RIG_FORMAN_VSAT=str_replace('"""', '', str_replace("\n", '', $extractedText)); } if(isset($RIG_FORMAN_VSAT)){ $a=explode('CONTRACTOR /CLERK VSA',$RIG_FORMAN_VSAT); } // dd($a[0],$a[1]); $first_data = array( 'date' => isset($date)?$date:'', 'file_id' => $file_id, 'well_no_and_charge' => isset($well_no_and_charge)?$well_no_and_charge:'', 'Wellbores' => isset($Wellbores)?$Wellbores:'', 'Objective' => isset($Objective)?$Objective:'', 'rig' => isset($reg_name)?$reg_name:'', 'Foreman_Engineer' => isset($Foreman_Engineer)?$Foreman_Engineer:'', 'Manager' => isset($Manager)?$Manager:'', 'Engineer' => isset($Engineer)?$Engineer:'', 'THURAYA_RIG_FORMAN' => isset($THURAYA)?$THURAYA:'', 'RIG_FORMAN_VSAT' => isset($a)?isset($a[0])?$a[0]:'':'', 'CONTRACTOR_CLERK' => isset($a)?isset($a[1])?$a[1]:'':'', ); //dd($pagess[$i],$first_data); // dd($first_data); FirstTable::create($first_data); $startKeyword = "Last 24 hr operations"; $endKeyword = "Next 24 hr plan"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $last_24_hours=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Next 24 hr plan"; $endKeyword = "Location"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Next_24_hr_plan=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Location"; $endKeyword = "Next Location"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Location=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Next Location"; $endKeyword = "Current Depth (ft)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $next_location=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Current Depth (ft)"; $endKeyword = "Last Csg Size"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Depth=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Last Csg Size"; $endKeyword = "Liner"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Depth=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Size"; $endKeyword = "Prev. Depth (ft)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Liner_Size_TOL_MD_TVD=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $ff=explode('Liner Size',$Liner_Size_TOL_MD_TVD); $startKeyword = "Prev. Depth (ft)"; $endKeyword = "Days Since Spud/Comm"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Prev_Depth=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "(Date)"; $endKeyword = "Circ %"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Days_Since_Spud_and_Date=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Circ %"; $endKeyword = "Footage (ft)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Circ=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Footage (ft)"; $endKeyword = "Distance from DHA M/Gate (KM)"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Footage=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Distance from DHA M/Gate (KM)"; $endKeyword = "Formation Tops"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Distance_from_DHA=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Formation Tops"; $endKeyword = "Depth Comments"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Formation_tops=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Depth Comments"; $endKeyword = "Hole depth Event depth"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Depth_Comments=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $second_data = array( 'Last_24_hr_operations' =>isset($last_24_hours)?$last_24_hours:'', 'file_id' => $file_id, 'Next_24_hr_plan' => isset($Next_24_hr_plan)?$Next_24_hr_plan:'', 'Location' => isset($Location)?$Location:'', 'next_location' => isset($next_location)?$next_location:'', 'Depth' =>isset($Depth)?$Depth:'', 'Last_Csg_Size_MD_TVD' => isset($ff[0])?$ff[0]:'', 'Liner_Size_TOL_MD_TVD' => isset($ff[1])?$ff[1]:'', 'Prev_Depth' => isset($Prev_Depth)?$Prev_Depth:'', 'Days_Since_Spud_and_Date' => isset($Days_Since_Spud_and_Date)?$Days_Since_Spud_and_Date:'', 'Circ' =>isset($Circ)?$Circ:'', 'Footage' => isset($Footage)?$Footage:'', 'Formation_tops' =>isset($Formation_tops)?$Formation_tops:'', 'Depth_Comments' => isset($Depth_Comments)?$Depth_Comments:'', ); //dd($second_data); SecondTable::create($second_data); $longText=$pagess[$i]; $targetWord = 'Lost Time Details'; $position = strpos($longText, $targetWord); if ($position !== false) { $is_lost_table="Yes"; $lost_table=''; }else{ $is_lost_table="No"; } $targetWord2 = 'Out Of Scope Details'; $position = strpos($longText, $targetWord2); if ($position !== false) { $is_scop_table="Yes"; $scop_table=''; }else{ $is_scop_table="No"; } $startKeyword = "Summary of Operations"; $endKeyword = "Lost Time Details"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $table=str_replace('"""', '', $extractedText); } if($is_lost_table=="No"){ $startKeyword = "Summary of Operations"; $endKeyword ="Out Of Scope Details"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $table=str_replace('"""', '', str_replace("\n", '', $extractedText)); } } if(($is_lost_table=="No")&&($is_scop_table=="No")){ $startKeyword = "Summary of Operations"; $endKeyword ="Foreman Remarks"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $table=str_replace('"""', '', $extractedText); } } if (isset($table)) { $rows_t = preg_split('/\n/', $table); $data_t = []; $linee = []; $Summary_of_Operations = ''; foreach ($rows_t as $row_t) { $row_t = trim($row_t); if ($row_t === '') continue; // هل السطر يبدأ بـ From-To + Hrs ؟ if (preg_match('/^(\d{4}-\d{4})(\s*[\d\.]+)/', $row_t, $m)) { // flush للسطر السابق if (!empty($linee)) { $linee['Summary_of_Operations'] = trim($Summary_of_Operations); $data_t[] = $linee; $linee = []; $Summary_of_Operations = ''; } $fromTo = $m[1]; $hrs = trim($m[2]); // باقي السطر بعد From-To + Hrs $rest = trim(substr($row_t, strlen($m[0]))); $tokens = $rest === '' ? [] : preg_split('/\s+/', $rest, -1, PREG_SPLIT_NO_EMPTY); $i2 = 0; $linee = [ 'file_id' => $file_id, 'From_To' => $fromTo, 'Hrs' => $hrs, 'Lateral' => '', 'Hole_size' => '', 'Cat' => '', 'Major_OP' => '', 'Action' => '', 'Object' => '', 'Resp_Co' => '', 'Hole_depth' => ' - ', 'Event_depth' => ' - ', 'LT_TYPE' => '', 'LT_ID' => '', ]; // الحقول الرئيسية $fields = ['Lateral','Hole_size','Cat','Major_OP','Action','Object']; foreach ($fields as $f) { $linee[$f] = $tokens[$i2] ?? ''; $i2++; } // --- Resp_Co + الأرقام $numbers = []; while ($i2 < count($tokens)) { $tok = $tokens[$i2]; if (preg_match('/^\d+$/', $tok)) { $numbers[] = $tok; } else { // أول نص بعد Object = Resp_Co if ($linee['Resp_Co'] === '') { $linee['Resp_Co'] = $tok; } else { // إذا طلع نصوص تانية بعد Resp_Co → معناها بداية الـ Summary break; } } $i2++; } // توزيع الأرقام على Hole_depth / Event_depth if (count($numbers) == 2) { $linee['Hole_depth'] = $numbers[0]; $linee['Event_depth'] = $numbers[1]; } elseif (count($numbers) == 4) { $linee['Hole_depth'] = $numbers[0] . ' - ' . $numbers[1]; $linee['Event_depth'] = $numbers[2] . ' - ' . $numbers[3]; } elseif (count($numbers) > 4) { $chunk = array_slice($numbers, 0, 4); $linee['Hole_depth'] = $chunk[0] . ' - ' . $chunk[1]; $linee['Event_depth'] = $chunk[2] . ' - ' . $chunk[3]; } // إذا في tokens باقية = بداية Summary if ($i2 < count($tokens)) { $Summary_of_Operations = implode(' ', array_slice($tokens, $i2)); } } else { // أي سطر مش From-To = تكملة للـ Summary $Summary_of_Operations .= ($Summary_of_Operations ? ' ' : '') . $row_t; } } // flush آخر سطر if (!empty($linee)) { $linee['Summary_of_Operations'] = trim($Summary_of_Operations); $data_t[] = $linee; } //dd($rows_t,$data_t); // إدخال مرة واحدة if (!empty($data_t)) { ThirdTable::insert($data_t); // \Log::info("Inserted " . count($data_t) . " rows into ThirdTable (file_id=$file_id)"); } } if($is_lost_table=="Yes"){ $startKeyword = "Lost Time Summary"; $endKeyword = "Out Of Scope"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $pattern3="Workover Objectives"; $patternToRemove = '/Hole depth.*?Summary of Operations/s'; $extractedText = str_replace($pattern3, '', $extractedText); $extractedText = preg_replace($patternToRemove, '', $extractedText); $lost_table=str_replace('"""', '', $extractedText); } if($lost_table==''){ $startKeyword = "Lost Time Summary"; $endKeyword ="Foreman Remarks"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $pattern3="Workover Objectives"; $patternToRemove = '/Hole depth.*?Summary of Operations/s'; $extractedText = str_replace($pattern3, '', $extractedText); $extractedText = preg_replace($patternToRemove, '', $extractedText); $lost_table=str_replace('"""', '', $extractedText); } } // dd($lost_table); if ($lost_table != '') { $rows = preg_split('/\R/', $lost_table); $data2 = []; $line2 = []; $LT_Summary = ''; foreach ($rows as $row2) { $row2 = trim($row2); if ($row2 === '') continue; // نبحث عن "Day Month Time" $pattern = '/^(\d{1,2})\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{4})/'; if (preg_match($pattern, $row2, $matches)) { // flush للسطر السابق if (!empty($line2)) { $data2[] = $line2; $line2 = []; $LT_Summary = ''; } $day = $matches[1]; $month = $matches[2]; $time = $matches[3]; // 1700 // نخلي From_To = "16 Nov 1700" $line2['file_id'] = $file_id; $line2['From_To'] = "$day $month $time"; // قص الباقي بعد الـ date+time $rest = trim(substr($row2, strlen($matches[0]))); $tokens = preg_split('/\s+/', $rest); // وزع الحقول $line2['Hrs'] = $tokens[0] ?? ''; $line2['Cum_Hrs'] = $tokens[1] ?? ''; $line2['LT_ID'] = $tokens[2] ?? ''; $line2['Parent_LT_ID'] = ''; $line2['Type'] = $tokens[3] ?? ''; $line2['Cause'] = $tokens[4] ?? ''; $line2['Object'] = $tokens[5] ?? ''; $line2['Resp_Co'] = $tokens[6] ?? ''; $line2['Depth'] = $tokens[7] ?? ''; // الباقي → Summary if (count($tokens) > 8) { $LT_Summary = implode(' ', array_slice($tokens, 8)); $line2['LT_Summary'] = trim($LT_Summary); } else { $line2['LT_Summary'] = ''; } } else { // أي سطر إضافي = تكملة Summary $LT_Summary .= ' ' . $row2; $line2['LT_Summary'] = trim($LT_Summary); } } if (!empty($line2)) { $data2[] = $line2; } //dd($data2); foreach ($data2 as $item) { if (!empty($item)) { LostTime::create($item); } } } } if ($is_scop_table == "Yes") { $startKeyword = "Out Of Scope Summary"; $endKeyword = "Foreman Remarks"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { $extractedText = trim($matches[1]); $scop_table = str_replace('"""', '', $extractedText); } $rows = preg_split('/\R/', $scop_table); $data = []; $line = []; $Out_Summary = ''; foreach ($rows as $row) { $row = trim($row); if ($row === '') continue; // استبدال non-breaking space بمسافة عادية $row = preg_replace('/\x{00A0}/u', ' ', $row); // تخطي الهيدر if (stripos($row, 'From') !== false && stripos($row, 'Out Of Scope Summary') !== false) { continue; } $a = preg_split('/\s+/', $row); $ff = count($a); $monthNames = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; // إذا السطر فيه تاريخ = بداية Row جديد if (isset($a[1]) && in_array($a[1], $monthNames)) { // خزّن السطر السابق إذا موجود if (!empty($line)) { $data[] = $line; $line = []; $Out_Summary = ''; } $line['file_id'] = $file_id; $line['From_To'] = ($a[0] ?? '') . " " . ($a[1] ?? '') . " " . ($a[2] ?? ''); $line['Hrs'] = $a[3] ?? ''; $line['Cum_Hrs'] = $a[4] ?? ''; $line['Doos_Id'] = $a[5] ?? ''; $line['Type'] = $a[6] ?? ''; $line['Category'] = $a[7] ?? ''; $line['Hole_Section'] = $a[8] ?? ''; $line['Lateral'] = $a[9] ?? ''; // Out_Summary = باقي النص $line['Out_Summary'] = ($ff > 10) ? implode(' ', array_slice($a, 10)) : ''; } else { // أي سطر إضافي = تكملة Out_Summary $Out_Summary .= " " . $row; $line['Out_Summary'] = trim($Out_Summary); } } // ضيف آخر Row if (!empty($line)) { $data[] = $line; } // dd($data); // إدخال البيانات بالجدول foreach ($data as $item) { OutOfScop::create($item); } } $startKeyword = "Foreman Remarks"; $endKeyword = "DAILY SURVEY"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $Comments_table=str_replace('"""', '', $extractedText); } // dd($Comments_table); $other_data = array( 'file_id' => $file_id, 'comment' => isset($Comments_table)?$Comments_table:'', ); OtherDataTable::create($other_data); $startKeyword = "Sec DLS"; $endKeyword = "MUD DATA"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $fourth_table=str_replace('"""', '', str_replace("DAILY SURVEY", '', $extractedText)); } //dd($fourth_table); if($fourth_table!=''){ $rows=preg_split('/\R/',$fourth_table); $data = []; $line = []; foreach ($rows as $row){ $a=explode(' ',$row); if(is_numeric($a[0])) { $line['file_id'] = $file_id; $line['Lateral'] = isset($a[0]) ? $a[0] : ''; $line['Survey_MD'] = isset($a[1]) ? $a[1] : ''; $line['Angle'] = isset($a[2]) ? $a[2] : ''; $line['Azimuth'] = isset($a[3]) ? $a[3] : ''; $line['CLength'] = isset($a[4]) ? $a[4] : ''; $line['TVD'] = isset($a[5]) ? $a[5] : ''; $line['NS_Coordinate'] = isset($a[6]) ? $a[6] : ''; $line['EW_Coordinate'] = isset($a[7]) ? $a[7] : ''; $line['Vertical_Sec'] = isset($a[8]) ? $a[8] : ''; $line['DLS'] = isset($a[9]) ? $a[9] : ''; array_push($data, $line); $line = []; } } //dd($data); foreach ($data as $item){ $r=FourthTable::create($item); } $data = []; } /*$startKeyword = "MUD DATA"; $endKeyword = "BOP Test"; $endKeyword2 = "PPT Total"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; $pattern2 = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword2, '/') . '/s'; $patternToRemove = '/MUD TREATMENT.*?Communication & V-Sat Issues/s'; if (preg_match($pattern, $pagess[$i], $matches)) { $extractedText = trim($matches[1]); $mud_data_table2 = str_replace('"""', '', str_replace("\n", '', $extractedText)); $mud_data_table2 = preg_replace($patternToRemove, '', $mud_data_table2); $mud_data_table2 = str_replace('BIT DATA', '', $mud_data_table2); // <-- changed here $pattern = '/Weight\d+\s.*?(?=(Weight\d+|\z))/s'; preg_match_all($pattern, $mud_data_table2, $matches); $mud_data_table = $matches[0]; } elseif (preg_match($pattern2, $pagess[$i], $matches)) { $extractedText = trim($matches[1]); $mud_data_table2 = str_replace('"""', '', str_replace("\n", '', $extractedText)); $mud_data_table2 = preg_replace($patternToRemove, '', $mud_data_table2); $mud_data_table2 = str_replace('BIT DATA', '', $mud_data_table2); // <-- changed here $pattern = '/Weight\d+\s.*?(?=(Weight\d+|\z))/s'; preg_match_all($pattern, $mud_data_table2, $matches); $mud_data_table = $matches[0]; }*/ // 1) التقط كل بلوكات MUD DATA: من Weight حتى "PPT Total " $mudDataBlocks = []; if (preg_match_all('/Weight[\s\S]*?PPT\s*Total\s*[0-9.]+/i', $pagess[$i], $mm)) { $mudDataBlocks = $mm[0]; } // 2) مرّ على كل بلوك وافصله حسب العناوين $rows = []; foreach ($mudDataBlocks as $raw) { // توحيد المسافات $txt = preg_replace('/\s+/', ' ', trim($raw)); $txt = preg_replace('/\b(MUD\s*DATA|BIT\s*DATA)\b/i', '', $txt); // العناوين كما تظهر بالجدول $labels = [ 'Weight','FL Temp','Funnel Vis.(SEC)','Cake HTHP','Filtrate(WL)','Cake API','Filtrate(WL)', 'Water Vol. %','PV','Oil Vol. %','YP','Solids Vol. %','Elec. Stability','Sand Vol. %', '3/6 RPM','% LGS','Gels Sec/Min','MBT','PH','Mud Type','CA PPM','CL PPM','PPT Spurt','PPT Total' ]; // خريطة العناوين لأسماء الأعمدة بقاعدة البيانات $map = [ 'Weight' => 'Weight_PCF', 'FL Temp' => 'FL_Temp', 'Funnel Vis.(SEC)' => 'Funnel_SEC', 'Cake HTHP' => 'Cake_HTHP', 'Cake API' => 'Cake_API', 'Water Vol. %' => 'Water_Vol', 'PV' => 'PV', 'Oil Vol. %' => 'Oil_Vol', 'YP' => 'YP', 'Solids Vol. %' => 'Solids_Vol', 'Elec. Stability' => 'Electrical_Stability_Volts', 'Sand Vol. %' => 'Sand_Vol', '3/6 RPM' => 'RPM_3_6', '% LGS' => 'LGS', 'Gels Sec/Min' => 'Gels_Sec_Min', 'MBT' => 'MBT', 'PH' => 'PH', 'Mud Type' => 'Mud_type', 'CA PPM' => 'CA_PPM', 'CL PPM' => 'CL_PPM', 'PPT Spurt' => 'PPT_Spurt', 'PPT Total' => 'PPT_Total', ]; // نبني regex للفصل $regex = '/(' . implode('|', array_map(fn($l)=>preg_quote($l,'/'), $labels)) . ')/i'; $chunks = preg_split($regex, $txt, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $row = []; $filtrateCount = 0; for ($k = 0; $k < count($chunks) - 1; $k += 2) { $label = trim($chunks[$k]); $value = trim($chunks[$k + 1]); // طبع العنوان canonical case foreach ($labels as $L) { if (strcasecmp($label, $L) === 0) { $label = $L; break; } } if ($label === 'Filtrate(WL)') { $filtrateCount++; $field = ($filtrateCount === 1) ? 'FiltrateWL_HTHP' : 'FiltrateWL_API'; } else { $field = $map[$label] ?? null; } if ($field) { $value = preg_replace($regex, '', $value); // تنظيف $value = trim($value); $row[$field] = $value; } } if (!empty($row)) { $row['file_id'] = $file_id; $rows[] = $row; } } // 3) إدخال البلوكات بالجدول mud_data foreach ($rows as $row) { MudData::create($row); } // ===== 1) جيب آخر PPT Total وحدودها مع الأوفست ===== $mudDataMatches = []; $lastPptValue = null; $lastPptEnd = null; if (preg_match_all('/Weight.*?PPT\s*Total\s*([0-9]+(?:\.[0-9]+)?)/si', $pagess[$i], $m, PREG_OFFSET_CAPTURE)) { // كل بلوكات MUD DATA (مش مستخدمينها هون بس منخليها لو بدّك تطبعها) $allBlocks = $m[0]; // نص كل بلوك + أوفست $pptVals = $m[1]; // قيمة PPT Total + أوفست $lastIdx = count($pptVals) - 1; $lastPptValue = $pptVals[$lastIdx][0]; // نهاية آخر بلوك MUD DATA (بعد "PPT Total ") $lastBlockStart = $allBlocks[$lastIdx][1]; $lastBlockLen = strlen($allBlocks[$lastIdx][0]); $lastPptEnd = $lastBlockStart + $lastBlockLen; } // ===== 2) قصّ بلوك الـ MUD TREATMENT من بعد آخر PPT Total لحد أول عنوان تالي ===== $mudTreatBlock = ''; if ($lastPptEnd !== null) { $tail = substr($pagess[$i], $lastPptEnd); // العناوين اللي بتوقّف عندها $stopPatterns = [ '/\bBIT\s*DATA\b/si', '/\bBit\s*Number\b/si', '/\bDRILL\s*STRING\b/si', '/\bMISCELLANEOUS\b/si', '/\bPERSONNEL\b/si', '/\bBOP\s*Test\b/si', ]; $cut = strlen($tail); foreach ($stopPatterns as $sp) { if (preg_match($sp, $tail, $mm, PREG_OFFSET_CAPTURE)) { $cut = min($cut, $mm[0][1]); } } $mudTreatBlock = trim(substr($tail, 0, $cut)); } if ($mudTreatBlock === '' && preg_match('/MUD\s*TREATMENT\s*(.*?)(?=\b(BIT\s*DATA|Bit\s*Number|DRILL\s*STRING|MISCELLANEOUS|PERSONNEL|BOP\s*Test)\b)/si', $pagess[$i], $mm)) { $mudTreatBlock = trim($mm[1]); } $mud_treatment_data = []; if ($mudTreatBlock !== '') { $lines = preg_split('/\R+/', $mudTreatBlock); $lines = array_values(array_filter(array_map('trim', $lines), fn($x)=>$x !== '')); // السطر يكون كمية إذا شكله مثل: 12 ( 55LB ) / 1 ( 2200L ) $isQuantity = function($s) { return (bool)preg_match('/^\d[\d\s,\.]*\s*\(\s*[\d\s,\.]+\s*[A-Za-z%\/-]+\s*\)$/', $s); }; for ($k = 0; $k < count($lines) - 1; $k++) { $material = $lines[$k]; $next = $lines[$k + 1]; // خُذ الزوج فقط إذا السطر التالي كمية، والمادة فيها حروف وما بتبدأ برقم if ($isQuantity($next) && preg_match('/[A-Za-z]/', $material) && !preg_match('/^\d/', $material)) { // فكّ الكمية والوِحدة من الشكل: "12 ( 55LB )" $qty = $next; $unit = ''; if (preg_match('/^(\d[\d\s,\.]*)\s*\(\s*([\d\s,\.]+)\s*([A-Za-z%\/-]+)\s*\)$/', $next, $q)) { $qty = trim($q[1] .$q[2] . $q[3]); // مثال: "12" } $mud_treatment_data[] = [ 'file_id' => $file_id, 'material' => $material, 'quantity' => $qty, ]; $k++; // ننطّ سطر الكمية المستهلك } } } if (!empty($mud_treatment_data)) { foreach ($mud_treatment_data as $item) { MUDTREATMENT::create([ 'file_id' => $item['file_id'], 'material' => $item['material'], 'quantity' => $item['quantity'], ]); } } $startKeyword = "Standby/Tankers"; $endKeyword = "Drill Wtr.-BBLS"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $truck_table=str_replace('"""', '', str_replace("\n", '', $extractedText)); } if(isset($truck_table)){ $r=Truck::create(['file_id'=>$file_id,'truck'=>$truck_table]); } $startKeyword = "MISCELLANEOUS"; $endKeyword = "Standby/Tankers"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; $miscTableText = ''; if (preg_match_all($pattern, $pagess[$i], $matches) && !empty($matches[1])) { $block = trim($matches[1][0]); $block = str_replace('"""', '', $block); // قص من بداية BOP Test if (preg_match('/BOP\s*Test/i', $block, $m, PREG_OFFSET_CAPTURE)) { $pos = $m[0][1]; $miscTableText = substr($block, $pos); } else { $miscTableText = $block; } } if (!empty($miscTableText)) { // 2) تنظيف النص: إزالة NBSP وتحويل الأسطر لمسافات $clean = preg_replace('/\x{00A0}/u', ' ', $miscTableText); $clean = preg_replace('/\s+/', ' ', trim($clean)); // 3) حضّر مصفوفة النتيجة $miscRow = [ 'file_id' => $file_id, 'BOP_Test' => '', 'BOP_Drills' => '', 'Wind' => '', 'Sea' => '', 'Weather' => '', 'DSLTA' => '', 'Safety_Meeting' => '', ]; if (preg_match('/BOP\s*Test\s+([0-9\/-]+)/i', $clean, $m)) { $miscRow['BOP_Test'] = trim($m[1]); } if (preg_match('/BOP\s*Drills\s+(.+?)\s+Wind/i', $clean, $m)) { $miscRow['BOP_Drills'] = trim($m[1]); } if (preg_match('/Wind\s+(.+?)\s+Sea/i', $clean, $m)) { $miscRow['Wind'] = trim($m[1]); } if (preg_match('/Sea\s+(.+?)\s+Weather/i', $clean, $m)) { $miscRow['Sea'] = trim($m[1]); } if (preg_match('/Weather\s+(.+?)\s+DSLTA/i', $clean, $m)) { $miscRow['Weather'] = trim($m[1]); } if (preg_match('/DSLTA\s+([0-9,.\-]+)\s+Safety/i', $clean, $m)) { $miscRow['DSLTA'] = trim($m[1]); } if (preg_match('/Safety\s*Meeting\s+(.+)$/i', $clean, $m)) { $val = trim($m[1]); // احذف أي زوائد بعد Safety Meeting $val = preg_replace( '/(?:PERSONNEL\s+AND\s+SERVICES|TRUCKS\/BOATS|Category|No\.\s+of\s+Persons|TOURLY|2\s+X\s+DAILY).*?Communication\s*&\s*V-?Sat\s*Issues/i', '', $val ); $miscRow['Safety_Meeting'] = trim($val); } Miscellaneous::create($miscRow); // Miscellaneous::create($miscRow); } $floatPattern = '/Float\s*(.*?)BOP\s*Test/s'; $floatBlock = ''; if (preg_match($floatPattern, $pagess[$i], $m)) { $floatBlock = trim($m[1]); } if (!empty($floatBlock)) { // تنظيف الأسطر $clean = preg_replace('/\s+/', ' ', $floatBlock); $row = [ 'file_id' => $file_id, 'Float' => '', 'BHA_Hrs' => '', 'String_Wt' => '', 'Pick_Up' => '', 'Slack_Off' => '', 'Rot_Torque' => '', 'Jars' => '', 'Serial_Hrs' => '', 'Shock' => '', 'Sub' => '', 'Mud_Motor' => '', ]; // Float if (preg_match('/Float\s+([YN])\b/i', $clean, $m)) { $row['Float'] = $m[1]; } // BHA Hrs if (preg_match('/BHA\s*Hrs\s+([0-9NA\/\.]+)/i', $clean, $m)) { $row['BHA_Hrs'] = $m[1]; } if (preg_match('/String\s*Wt\.?\s+([0-9NA\/\.]+)/i', $clean, $m)) { $row['String_Wt'] = $m[1]; } // Pick Up if (preg_match('/Pick\s*Up\s+([0-9NA\.]+)/i', $clean, $m)) { $row['Pick_Up'] = $m[1]; } // Slack Off if (preg_match('/Slack\s*Off\s+([0-9NA\.]+)/i', $clean, $m)) { $row['Slack_Off'] = $m[1]; } // Rot. Torque if (preg_match('/Rot\.?\s*Torque\s+([0-9,NA]+)/i', $clean, $m)) { $row['Rot_Torque'] = str_replace(',', '', $m[1]); } // Jars Serial # / Jars Hrs if (preg_match('/Jars\s*Serial\s*#\s*Jars\s*Hrs\s*([0-9NA\.]+)/i', $clean, $m)) { $row['Jars'] = $m[1]; } // Shock Sub Serial # Shock Sub Hrs Mud Motor Serial # Mud Motor Hrs if (preg_match('/Shock\s*Sub.*?Mud\s*Motor\s*Hrs\s*([0-9NA\.]+)/i', $clean, $m)) { $row['Mud_Motor'] = $m[1]; } // dd($row); // للتأكد قبل الإدخال DRILL_STRING_Float::create($row); } $startKeyword = "Bit Number"; $endKeyword = "Float\n"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $pattern88 = 'MD In MD Out Run Footage Hours Average ROP WOB RPM IADC Size Manufacturer'; $extractedText = str_replace($pattern88, '', $extractedText); $bit_data_table2=str_replace('"""', '', str_replace("\n", '', $extractedText)); $bit_data_table=explode("Bit Number",$bit_data_table2); $rt="1"; } if($bit_data_table!=''){ $startKeyword = "Bit Number"; $endKeyword = "TFA"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $pagess[$i], $matches)) { // $matches[1] contains the text between the start and end keywords $extractedText = trim($matches[1]); $pattern88 = 'MD In MD Out Run Footage Hours Average ROP WOB RPM IADC Size Manufacturer'; $extractedText = str_replace($pattern88, '', $extractedText); /* $pattern88 = '/MD In MD Out.*?Manufacturer/s'; $extractedText = preg_replace($pattern88, '', $extractedText);*/ $bit_data_table2=str_replace('"""', '', str_replace("\n", '', $extractedText)); $bit_data_table=explode("Bit Number",$bit_data_table2); $rt="2"; } } if($bit_data_table!=''){ $bit_lines=[]; $bit_data=[]; $ad2=$bit_data_table; $t=count($ad2); for($p2=0;$p2<$t;$p2++){ if(!empty($ad2)){ $targetWord = 'DRILL STRING'; $position = strpos($ad2[$p2], $targetWord); if ($position !== false) { $pattern2 = '/DRILL STRING.*?Computer, Communication & V-Sat Issues/s'; $ad2[$p2] = preg_replace($pattern2, '', $ad2[$p2]); $to="Yes"; }else{ $to="No"; } if($to=="Yes"){ $targetWord = 'Pressure'; $position = strpos($ad2[$p2], $targetWord); if ($position !== false) { $extractedText = substr($ad2[$p2], 0, $position); $bit_lines['Bit_Number'] = str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Pressure"; $endKeyword = "GPM"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf=explode(' ',$nn); $bit_lines['Pressure'] = $cf[0]; $bit_lines['MD_In'] = $cf[0]; } // dd($bit_lines['Pressure'],$rt,$to,$bit_data_table,$pagess[$i],$ad2); $startKeyword = "GPM"; $endKeyword = "Jet Vel"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['GPM'] = $cf1[0]; $bit_lines['MD_Out'] = $cf1[0]; } $startKeyword = "Jet Vel"; $endKeyword = "DP Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Jet_Vel'] = trim($matches[1]); } $startKeyword = "Run Footage"; $endKeyword = "DP Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Feet'] = trim($matches[1]); } $startKeyword = "DP Av"; $endKeyword = "DC Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['DP_Av'] = trim($matches[1]); } $startKeyword = "Hours"; $endKeyword = "DC Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Hours'] = trim($matches[1]); } $startKeyword = "DC Av"; $endKeyword = "Bit HHP"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['DC_Av'] = trim($matches[1]); } $startKeyword = "Average ROP"; $endKeyword = "Bit HHP"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Average_ROP'] = trim($matches[1]); } $startKeyword = "Bit HHP"; $endKeyword = "I-Row"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['Bit_HHP'] = $cf1[0]; $bit_lines['WOB'] = $cf1[0]; } $startKeyword = "I-Row"; $endKeyword = "O-Row"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['I_Row'] = $cf1[0]; $bit_lines['RPM'] = $cf1[0]; } $startKeyword = "O-Row"; $endKeyword = "DC"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['O_Row'] = $cf1[0]; $bit_lines['IADC'] = $cf1[0]; } $startKeyword = "DC"; $endKeyword = "Location"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['DC'] = $cf1[0]; $bit_lines['Size'] = $cf1[0]; } $startKeyword = "Location"; $endKeyword = "Bearings"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $nn=trim($matches[1]); $cf1=explode(' ',$nn); $bit_lines['Loc'] = $cf1[0]; $bit_lines['Manufacturer'] = $cf1[0]; } $startKeyword = "Bearings"; $endKeyword = "Serial Number"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['B'] = trim($matches[1]); } $startKeyword = "Serial Number"; $endKeyword = "Gauge"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Serial_Number'] = trim($matches[1]); } $startKeyword = "Gauge"; $endKeyword = "Type"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['G'] = trim($matches[1]); } $startKeyword = "Type"; $endKeyword = "Other"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Type'] = trim($matches[1]); } $startKeyword = "Other"; $endKeyword = "Jets"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Other'] = trim($matches[1]); } $startKeyword = "Jets"; $endKeyword = "POOH Reason"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Jets'] = trim($matches[1]); } $startKeyword = "POOH Reason"; $endKeyword = "TFA"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['POOH_Reason'] = trim($matches[1]); } if (preg_match('/TFA([\d.]+)/', $ad2[$p2], $matches)) { $pptTotal = $matches[1]; $bit_lines['TFA'] = $pptTotal; } }else{ $targetWord = 'Pressure'; $position = strpos($ad2[$p2], $targetWord); if ($position !== false) { $extractedText = substr($ad2[$p2], 0, $position); $bit_lines['Bit_Number'] = str_replace('"""', '', str_replace("\n", '', $extractedText)); } $startKeyword = "Pressure"; $endKeyword = "MD In"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Pressure'] = trim($matches[1]); } $startKeyword = "MD In"; $endKeyword = "GPM"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['MD_In'] = trim($matches[1]); } $startKeyword = "GPM"; $endKeyword = "MD Out"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['GPM'] = trim($matches[1]); } $startKeyword = "MD Out"; $endKeyword = "Jet Vel"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['MD_Out'] = trim($matches[1]); } $startKeyword = "Jet Vel"; $endKeyword = "Run Footage"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Jet_Vel'] = trim($matches[1]); } $startKeyword = "Run Footage"; $endKeyword = "DP Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Feet'] = trim($matches[1]); } $startKeyword = "DP Av"; $endKeyword = "Hours"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['DP_Av'] = trim($matches[1]); } $startKeyword = "Hours"; $endKeyword = "DC Av"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Hours'] = trim($matches[1]); } $startKeyword = "DC Av"; $endKeyword = "Average ROP"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['DC_Av'] = trim($matches[1]); } $startKeyword = "Average ROP"; $endKeyword = "Bit HHP"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Average_ROP'] = trim($matches[1]); } $startKeyword = "Bit HHP"; $endKeyword = "WOB"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Bit_HHP'] = trim($matches[1]); } $startKeyword = "WOB"; $endKeyword = "I-Row"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['WOB'] = trim($matches[1]); } $startKeyword = "I-Row"; $endKeyword = "RPM"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['I_Row'] = trim($matches[1]); } $startKeyword = "RPM"; $endKeyword = "O-Row"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['RPM'] = trim($matches[1]); } $startKeyword = "O-Row"; $endKeyword = "IADC"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['O_Row'] = trim($matches[1]); } $startKeyword = "IADC"; $endKeyword = "DC"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['IADC'] = trim($matches[1]); $startKeyword = $bit_lines['IADC']; $endKeyword = "Size"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $dc2 = trim($matches[1]); $bit_lines['DC'] = str_replace("DC", '', $dc2); } } $startKeyword = "Size"; $endKeyword = "Location"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Size'] = trim($matches[1]); } $startKeyword = "Location"; $endKeyword = "Manufacturer"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Loc'] = trim($matches[1]); } $startKeyword = "Manufacturer"; $endKeyword = "Bearings"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Manufacturer'] = trim($matches[1]); } $startKeyword = "Bearings"; $endKeyword = "Serial Number"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['B'] = trim($matches[1]); } $startKeyword = "Serial Number"; $endKeyword = "Gauge"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Serial_Number'] = trim($matches[1]); } $startKeyword = "Gauge"; $endKeyword = "Type"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['G'] = trim($matches[1]); } $startKeyword = "Type"; $endKeyword = "Other"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Type'] = trim($matches[1]); } $startKeyword = "Other"; $endKeyword = "Jets"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Other'] = trim($matches[1]); } $startKeyword = "Jets"; $endKeyword = "POOH Reason"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['Jets'] = trim($matches[1]); } $startKeyword = "POOH Reason"; $endKeyword = "TFA"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $ad2[$p2], $matches)) { $bit_lines['POOH_Reason'] = trim($matches[1]); } if (preg_match('/TFA([\d.]+)/', $ad2[$p2], $matches)) { $pptTotal = $matches[1]; $bit_lines['TFA'] = $pptTotal; } } $bit_lines['file_id']=$file_id; if( isset($bit_lines['Bit_Number'])){ array_push($bit_data, $bit_lines); $bit_lines = []; } } } // dd($bit_data,$bit_data_table); foreach ($bit_data as $item){ $r=BITDATA::create($item); } } $drillData = []; if (preg_match('/Order\s+Component\s+Provider(.*?)(?=MISCELLANEOUS)/is', $pagess[$i], $m)) { $block = $m[1]; // 🔹 1) شيل جداول غير مطلوبة $block = preg_replace('/(MUD\s*DATA|MUD\s*TREATMENT|BIT\s*DATA).*?(?=Order\s+Component\s+Provider|$)/is', '', $block); // 🔹 2) شيل جدول DRILL STRING float/bit section $block = preg_replace('/DRILL\s+STRING.*?(?=Order\s+Component\s+Provider|$)/is', '', $block); // 🔹 3) قص لأسطر $lines = preg_split('/\R+/', $block); // 🔹 4) دمج الأسطر بحيث كل row يبدأ برقم $rows = []; $current = ''; foreach ($lines as $line) { $line = trim($line); if ($line === '') continue; // تجاهل headers أو أسطر مالها علاقة if (preg_match('/^(Nominal|Size|Order|Component|Provider)/i', $line)) continue; if (stripos($line, 'DRILL STRING') !== false) continue; // إذا السطر يبدأ برقم → row جديد if (preg_match('/^\d+\s/', $line)) { if ($current !== '') { $rows[] = trim($current); } $current = $line; } else { // تابع للسطر السابق $current .= ' ' . $line; } } if ($current !== '') { $rows[] = trim($current); } // 🔹 5) حول كل row لمصفوفة أعمدة foreach ($rows as $row) { if (!preg_match('/^\d+/', $row)) continue; // لازم يبدأ برقم $parts = preg_split('/\s+/', trim($row)); if (count($parts) < 5) continue; $order = array_shift($parts); // أول عمود: OrderNum $serial = array_pop($parts); // آخر عمود: Serial $item = [ 'file_id' => $file_id ?? null, 'OrderNum' => $order, 'Component' => $parts[0] ?? '', 'Provider' => $parts[1] ?? '', 'Nominal_Size' => $parts[2] ?? '', 'Joints' => $parts[3] ?? '', 'OD_Size' => $parts[4] ?? '', 'ID_Size' => $parts[5] ?? '', 'Length' => $parts[6] ?? '', 'Cum_Length' => $parts[7] ?? '', 'Top_Thread' => $parts[8] ?? '', 'Bottom_Thread' => $parts[9] ?? '', 'Weight' => $parts[10] ?? '', 'Cum_Weight' => $parts[11] ?? '', 'Grade' => $parts[12] ?? '', 'Class' => $parts[13] ?? '', 'Serial' => $serial, ]; foreach ($item as $k => $v) { $item[$k] = trim($v, ",; \t"); } $drillData[] = $item; // إذا وصلنا للرقم 1 → نوقف if ($order == 1) break; } foreach ($drillData as $item2){ $r=DRILL_STRING::create($item2); } } // dd($rows, $drillData); $pattern = '/Drill Wtr\.-BBLS(.*)/s'; preg_match($pattern, $pagess[$i], $matches); $bulk_table = $matches[1]; $pattern9 = '/REPAIR ASAP Instrumentation.*?Communication & V-Sat./s'; $bulk_table = preg_replace($pattern9, '', $bulk_table); $data_b=[]; $line_b=[]; if(isset($bulk_table)){ $rows=preg_split('/\R/',$bulk_table); if(!empty($rows)){ $line_b['Drill_Wtr'] = str_replace("Pot Wtr.-BBLS", '', $rows[1]); $line_b['Pot_Wtr'] = str_replace("Fuel- BBLS", '', $rows[2]); $line_b['Fuel_BBLS'] = str_replace("Barite- SX", '', $rows[3]); $line_b['Barite_SX'] = str_replace("Bentonite- SX", '', $rows[4]); $line_b['Bentonite_SX'] = str_replace("Cement G-SX", '', $rows[5]); $line_b['Cement_G_SX'] = $rows[6]; $line_b['file_id']=$file_id; array_push($data_b, $line_b); $line_b = []; } // dd($data_b); foreach ($data_b as $item){ $r=BULKS::create($item); } $bulk_table=''; } $pattern = '/REPAIR ASAP Instrumentation.*$/s'; if (preg_match($pattern, $pagess[$i], $matchess)) { $extractedText = $matchess; $repair_table=str_replace('"""', '', str_replace("\n", '', $extractedText)); } $data_r=[]; $line_r=[]; $arr=''; if(isset($repair_table)){ $startKeyword = "REPAIR ASAP Instrumentation"; $endKeyword = "Other"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $repair_table, $matches)) { $line_r['Instrumentation'] = trim($matches[1]); $arr.=$line_r['Instrumentation']; } $startKeyword = "Other"; $endKeyword = "Reporter"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $repair_table, $matches)) { $line_r['Other'] = trim($matches[1]); $arr.=$line_r['Other']; } $startKeyword = "Reporter"; $endKeyword = "Computer, Communication & V-Sat Issues"; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $repair_table, $matches)) { $line_r['Reporter'] = trim($matches[1]); $arr.=$line_r['Reporter']; } $startKeyword = "Computer, Communication & V-Sat Issues"; $endKeyword = "Standby/Tankers"; $patternToRemove = '/Weight.*?Mud Motor Hrs/s'; $pattern = '/' . preg_quote($startKeyword, '/') . '(.*?)' . preg_quote($endKeyword, '/') . '/s'; if (preg_match($pattern, $repair_table, $matches)) { $dd = trim($matches[1]); $line_r['Computer']=preg_replace($patternToRemove, '', $dd); $arr.=$line_r['Computer']; } if($arr!=''){ // dd($arr,$line_r); $line_r['file_id']=$file_id; array_push($data_r, $line_r); $line_r = []; foreach ($data_r as $item){ $r=REPAIR_TABLE::create($item); } } } MultipleFiles::where('id',$file_id)->update(['is_parsed'=>1]); } $success = array( 'success' => 'File uploaded successfully', ); return redirect()->to(route('uploadfiles'))->with('success', 'File uploaded successfully'); //return response()->json($output); } function read_file(Request $request) { $image_code = ''; $the_date=$request->input('thedate'); if(!File::isDirectory('files/'.$the_date)){ File::makeDirectory('files/'. $the_date, 0777); } $images = $request->file('file'); foreach($images as $image) { $new_name = $image->getClientOriginalName(); $image->move(public_path('files/'. $the_date), $new_name); $content = File::get('files/'.$the_date.'/'.$new_name); $a=explode('Depth ',$content); $acc=explode('',$a[1]); $fff=count($a); $image_code .= '
'.$content.'
'; $split_name = explode('.' ,$new_name); $file_name = explode(' ' ,$split_name[0]); $reg_name=$file_name[0]; $sec_name=$file_name[1]; $u= new MultipleFiles(); $u->reg_name=$reg_name; $u->sec_name=$sec_name; $u->file_path=$new_name; $u->upload_date=$the_date; $u->save(); } $output = array( 'success' => 'Files uploaded successfully', 'image' => $acc[0] ); return response()->json($output); } function filestable() { /* $now=date('Y-m-d'); $from_date=date('2023-07-13'); $to_date=date('2023-07-15'); $period = CarbonPeriod::create($from_date, $to_date); foreach ($period as $day) { $files=ZipFiles::where('upload_date',$day)->first(); //dd($files); $the_date=$day; $tday=date('m-d-Y',strtotime($day)); $a=explode('-',$tday); $c=substr($a[0],1,1); $tday=$c.'-'.$a[1].'-'.$a[2]; $reg_name="MR ".$tday; $file_path = "files/".date('Y-m-d',strtotime($day))."/".$reg_name.'.zip'; $form_data = ['file_name' => $reg_name,'file_path'=>$file_path,'is_parsed'=>0]; $zip_file= new ZipFiles(); $zip_file->file_name=$reg_name; $zip_file->file_path=$file_path; $zip_file->upload_date=$the_date; $zip_file->is_parsed=0; $zip_file->save(); }*/ $arr=[]; $arr2=[]; $arrr=[]; $arrr2=[]; $years = MultipleFiles::selectRaw('Distinct(upload_date) as years')->get(); foreach ($years as $year){ $arr[]=date('Y',strtotime($year->years)); $arr2[]=date('F',strtotime($year->years)); } $data2['yearss']=array_unique($arr); $data2['months']=array_unique($arr2); return view('filestable')->with($data2); } function filestable_data() { $year=date('2023-06-01'); $data['data'] = MultipleFiles::select('*')->selectRaw('CONCAT("","Browse whereDate('upload_date','>=',$year)->orderBy('upload_date', 'Desc')->get(); return $data; //return view('filestable'); } function getTextBetweenWords($text, $word1, $word2, $rowsAfter = 1) { $start = strpos($text, $word1); if ($start === false) { return false; // Word 1 not found } $start += strlen($word1); $end = strpos($text, $word2, $start); if ($end === false) { return false; // Word 2 not found } $result = trim(substr($text, $start, $end - $start)); // Get rows after 'TFA' $rows = explode("\n", $text); $key = array_search($word2, $rows); if ($key !== false) { for ($i = 1; $i <= $rowsAfter; $i++) { if (isset($rows[$key + $i])) { $result .= "\n" . trim($rows[$key + $i]); } } } return $result; } function filestable_table(Request $request) { // dd($request->all()); $first_date=$request->date.'-01'; $last_date2=date('Y-m-t', strtotime($first_date)); $data['data'] = MultipleFiles::select('upload_date')->selectRaw('CONCAT("","Browse whereDate('upload_date','>=',$first_date)->whereDate('upload_date','<=',$last_date2)->groupby('upload_date')->orderBy('upload_date', 'Desc')->get(); // dd($data['data']); return $data; //return view('filestable'); } }