118 lines
3.7 KiB
PHP
118 lines
3.7 KiB
PHP
<?php
|
|
//weld_logs
|
|
$nullEngineering = db("weld_logs")
|
|
->orderBy("id", "DESC");
|
|
|
|
/*
|
|
$updateData['pdf_engineering'] = null;
|
|
$updateData['pdf_spool_iso'] = null;
|
|
$updateData['pdf_as_build'] = null;
|
|
db("weld_logs")->update($updateData);
|
|
*/
|
|
|
|
if(isset($lineNumber)) {
|
|
$nullEngineering = $nullEngineering->where("iso_number", $lineNumber);
|
|
}
|
|
|
|
if(!getesit("q","")) {
|
|
$nullEngineering = $nullEngineering->where("iso_number", get("q"));
|
|
|
|
$updateData = [];
|
|
|
|
$updateData['pdf_engineering'] = null;
|
|
$updateData['pdf_spool_iso'] = null;
|
|
$updateData['pdf_as_build'] = null;
|
|
db("weld_logs")->where("iso_number", get("q"))->update($updateData);
|
|
}
|
|
|
|
$nullEngineering = $nullEngineering->groupBy("iso_number")->get();
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
$say = 0;
|
|
$k = 0;
|
|
Log::debug("📄 PDF Link to DB Start " . simdi());
|
|
try {
|
|
foreach($nullEngineering AS $ne) {
|
|
$data = $ne->iso_number;
|
|
$lineData = $ne->line_number ?? null; // Get line_number if exists
|
|
|
|
//$data = strtolower($data);
|
|
$data = str_replace("/", "*", $data);
|
|
$data = str_replace(" ", "*", $data);
|
|
|
|
if(trim($data) != "") {
|
|
$path = "storage/documents/001_Drawings/001_Engineering/*$data*";
|
|
$path2 = "storage/documents/001_Drawings/002_Iso/*$data*";
|
|
$path3 = "storage/documents/001_Drawings/003_As_Build(ID)/*$data*";
|
|
|
|
$searchEngineering = glob($path);
|
|
$searchSpoolIso = glob($path2);
|
|
$searchAsBuild = glob($path3);
|
|
|
|
$updateData = [];
|
|
|
|
$updateData['pdf_engineering'] = null;
|
|
$updateData['pdf_spool_iso'] = null;
|
|
$updateData['pdf_as_build'] = null;
|
|
|
|
// If files not found with iso_number, try with line_number
|
|
if(empty($searchEngineering) && !empty($lineData)) {
|
|
$lineData = str_replace("/", "*", $lineData);
|
|
$lineData = str_replace(" ", "*", $lineData);
|
|
$linePath = "storage/documents/001_Drawings/001_Engineering/*$lineData*";
|
|
$searchEngineering = glob($linePath);
|
|
}
|
|
|
|
if(empty($searchSpoolIso) && !empty($lineData)) {
|
|
$lineData = str_replace("/", "*", $lineData);
|
|
$lineData = str_replace(" ", "*", $lineData);
|
|
$linePath2 = "storage/documents/001_Drawings/002_Iso/*$lineData*";
|
|
$searchSpoolIso = glob($linePath2);
|
|
}
|
|
|
|
if(empty($searchAsBuild) && !empty($lineData)) {
|
|
$lineData = str_replace("/", "*", $lineData);
|
|
$lineData = str_replace(" ", "*", $lineData);
|
|
$linePath3 = "storage/documents/001_Drawings/003_As_Build(ID)/*$lineData*";
|
|
$searchAsBuild = glob($linePath3);
|
|
}
|
|
|
|
if(isset($searchEngineering[0])) {
|
|
$updateData['pdf_engineering'] = $searchEngineering[0];
|
|
}
|
|
if(isset($searchSpoolIso[0])) {
|
|
$updateData['pdf_spool_iso'] = $searchSpoolIso[0];
|
|
}
|
|
if(isset($searchAsBuild[0])) {
|
|
$updateData['pdf_as_build'] = $searchAsBuild[0];
|
|
}
|
|
|
|
$k += db("weld_logs")
|
|
->where("iso_number", $ne->iso_number)
|
|
->update($updateData);
|
|
|
|
|
|
|
|
|
|
|
|
$say++;
|
|
}
|
|
|
|
|
|
}
|
|
DB::commit();
|
|
Log::debug("update PDF link for $k rows");
|
|
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
Log::error("not update PDF links " . $th->getMessage());
|
|
////dump($th->getMessage());
|
|
}
|
|
|
|
Log::debug("📄 PDF Link to DB Finish " . simdi());
|
|
|
|
?>
|