where("id", $id)->get(); } else { $lineLists = db("line_lists") ->get(); } $say = 0; $count = 0; $added = []; if(Cache::has($cachePrefix.'_added')) { $added = Cache::get($cachePrefix.'_added'); } DB::beginTransaction(); if(isset($id)) { $weldLogs = db("weld_logs")->where("line_number", $lineLists[0]?->line_no)->get(); } else { $weldLogs = db("weld_logs")->get(); } $zones = []; foreach($weldLogs AS $weldLog) { $zones[$weldLog->line_number] = $weldLog->project; } Log::debug("$cachePrefix start " . simdi()); try { foreach($lineLists AS $lineList) { if($lineList->painting_cycle != "") { $updateData = [ 'project' => @$zones[$lineList->line_no], 'area' => $lineList->unit, 'description' => "PIPE", 'line' => $lineList->line_no, 'fluid_code_description' => $lineList->fluid_ru, 'fluid_code' => $lineList->fluid_code, 'design_temperature' => $lineList->design_temperature, 'operation_temperature' => $lineList->working_temperature, 'paint_cycle' => $lineList->painting_cycle, ]; $updateDataPaintFollowUp = [ 'fluid_code_description' => $lineList->fluid_ru, ]; $whereData = [ 'line' => $lineList->line_no, 'fluid_code' => $lineList->fluid_code, ]; $whereDataPaintFollowUp = [ 'line' => $lineList->line_no, ]; PaintMatrix::updateOrCreate($whereData, $updateData); PaintFollowUp::where($whereDataPaintFollowUp)->update($updateDataPaintFollowUp); Cache::put($cachePrefix, $lineList->id); Cache::put($cachePrefix.'_added', $added); $count++; if($say == $commitSize) { DB::commit(); DB::beginTransaction(); $say = 0; } $say++; } } DB::commit(); } catch (\Throwable $th) { //dump($th); DB::rollback(); } //surface preparation if(isset($id)) { $paintFollowUps = PaintFollowUp::where("line", $lineLists[0]?->line_no)->get(); $paintMatrix = PaintMatrix::where("line", $lineLists[0]?->line_no)->get(); } else { $paintMatrix = PaintMatrix::get(); $paintFollowUps = PaintFollowUp::get(); } $surfaces = []; foreach($paintMatrix AS $pm) { $surfaces[$pm->line] = [ 'surface_preparation' => $pm->surface_preparation, 'touch_up_of_damaged_parts' => $pm->touch_up_of_damaged_parts, ]; } DB::beginTransaction(); $k = 0; try { foreach($paintFollowUps AS $pfu) { if(isset($surfaces[$pm->line])) { if(strpos($pfu->spool_no_joint_no, "SPL") !== false) { $thisSurface = $surfaces[$pm->line]['surface_preparation']; } else { $thisSurface = $surfaces[$pm->line]['touch_up_of_damaged_parts']; } db("paint_follow_ups")->where([ 'id' => $pfu->id ])->update([ 'surface_roughness' => $thisSurface ]); $k++; } } DB::commit(); } catch (\Throwable $th) { //throw $th; DB::rollback(); } //dump("$count Data has been sync from lineList"); //dump("$k Data has been sync from paint matrix to paint follow ups"); Log::debug("$cachePrefix finish " . simdi()); ?>