ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
$saat = date("H:i");
|
||||
//dump($saat);
|
||||
//if(date("i") % 10 == 0) {
|
||||
|
||||
$dbuser = env("DB_USERNAME");
|
||||
$dbname = env("DB_DATABASE");
|
||||
$dbpass = env("DB_PASSWORD");
|
||||
$mainPath = storage_path("documents/013_Others/backup");
|
||||
$tableName = "weld_logs";
|
||||
$backup_file = $dbname . "-$tableName-" . date("Y-m-d-H-i-s") . '.gz';
|
||||
$path = "/$mainPath/$tableName/" . date("ymd");
|
||||
@mkdir($path, 0777, true);
|
||||
chmod($path, 0777);
|
||||
$command = "mysqldump -u $dbuser -p$dbpass ". "$dbname $tableName | gzip > $path/$backup_file";
|
||||
echo $command;
|
||||
dump(shell_exec($command));
|
||||
dump("WeldLogs SQL yedeği alındı.");
|
||||
Log::debug("💾 WeldLogs $saat Yedek Alındı");
|
||||
//}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
|
||||
//dump($saat);
|
||||
//if($saat==env("BACKUP_TIME")) {
|
||||
$dbhost = 'localhost:3036';
|
||||
$dbuser = env("DB_USERNAME");
|
||||
$dbname = env("DB_DATABASE");
|
||||
$dbpass = env("DB_PASSWORD");
|
||||
|
||||
$path = storage_path("documents/013_Others/backup");
|
||||
dump($path);
|
||||
@mkdir($path, 0777, true);
|
||||
chmod($path, 0777);
|
||||
$backup_file = $dbname . date("Y-m-d-H-i-s") . '.gz';
|
||||
// chmod("/home/stellar/backup/", 0777);
|
||||
$command = "mysqldump -u $dbuser -p$dbpass ". "$dbname | gzip > $path/$backup_file";
|
||||
// echo $command;
|
||||
dump($command);
|
||||
// dump(shell_exec($command));
|
||||
//dump("SQL yedeği alındı.");
|
||||
Log::debug("💾 $saat Yedek Alındı");
|
||||
dump("ok");
|
||||
//}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// Dashboard View Cache Generator
|
||||
// Bu cron görevi, dashboard blade viewını önbelleğe alır ve storage/app/cache/ dizinine kaydeder
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
// Cache klasörünü oluştur (yoksa)
|
||||
if (!Storage::exists('cache')) {
|
||||
Storage::makeDirectory('cache');
|
||||
}
|
||||
|
||||
// Önbelleğe alınacak view
|
||||
$viewPath = 'admin.dashboard.module.dashboard';
|
||||
$cacheFileName = 'dashboard';
|
||||
|
||||
try {
|
||||
// View içeriğini oluştur
|
||||
$viewContent = view($viewPath)->render();
|
||||
|
||||
// Cache dosyasını kaydet
|
||||
Storage::put("cache/{$cacheFileName}.blade.php", $viewContent);
|
||||
|
||||
// Son güncelleme zamanını kaydet
|
||||
Storage::put("cache/{$cacheFileName}_last_updated.txt", date('Y-m-d H:i:s'));
|
||||
|
||||
echo "{$viewPath} önbelleği başarıyla güncellendi: " . date('Y-m-d H:i:s') . "<br>";
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('view:clear');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo "{$viewPath} önbelleği güncellenirken hata oluştu: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
dispatchCacheBladeViews([
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-calculation-no-cache',
|
||||
'cache' => 'ndt-calculation'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.request-ndt-no-cache',
|
||||
'cache' => 'request-ndt'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.register-no-cache',
|
||||
'cache' => 'register-creator'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.request-ndt-no-cache',
|
||||
'cache' => 'request-ndt'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.repair-log-no-cache',
|
||||
'cache' => 'repair-log'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-order.order-list-no-cache',
|
||||
'cache' => 'ndt-order-list'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.spool-area-release-no-cache',
|
||||
'cache' => 'spool-area-release'
|
||||
],
|
||||
|
||||
[
|
||||
'view' => 'admin-ajax.spool-list-no-cache',
|
||||
'cache' => 'spool-list'
|
||||
],
|
||||
[
|
||||
'view' => 'admin.type.spool-release.spool-list-chart-no-cache',
|
||||
'cache' => 'spool-list-chart'
|
||||
],
|
||||
|
||||
|
||||
|
||||
]);
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// Summary View Cache Generator
|
||||
// Bu cron görevi, summary blade viewını önbelleğe alır ve storage/app/cache/ dizinine kaydeder
|
||||
|
||||
use App\Jobs\CacheBladeViewJob;
|
||||
|
||||
// Önbelleğe alınacak view
|
||||
$viewPath = 'admin-ajax.spool-area-release-no-cache';
|
||||
$cacheFileName = 'spool-area-release';
|
||||
|
||||
// Job'u kuyruğa ekle
|
||||
CacheBladeViewJob::dispatch($viewPath, $cacheFileName);
|
||||
|
||||
echo "{$viewPath} önbellek güncelleme işi kuyruğa eklendi: " . date('Y-m-d H:i:s') . "<br>";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// Summary View Cache Generator
|
||||
// Bu cron görevi, summary blade viewını önbelleğe alır ve storage/app/cache/ dizinine kaydeder
|
||||
|
||||
use App\Jobs\CacheBladeViewJob;
|
||||
|
||||
// Önbelleğe alınacak view
|
||||
$viewPath = 'admin-ajax.spool-list-no-cache';
|
||||
$cacheFileName = 'spool-list';
|
||||
|
||||
// Job'u kuyruğa ekle
|
||||
CacheBladeViewJob::dispatch($viewPath, $cacheFileName);
|
||||
|
||||
echo "{$viewPath} önbellek güncelleme işi kuyruğa eklendi: " . date('Y-m-d H:i:s') . "<br>";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// Summary View Cache Generator
|
||||
// Bu cron görevi, summary blade viewını önbelleğe alır ve storage/app/cache/ dizinine kaydeder
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
// Cache klasörünü oluştur (yoksa)
|
||||
if (!Storage::exists('cache')) {
|
||||
Storage::makeDirectory('cache');
|
||||
}
|
||||
|
||||
// Önbelleğe alınacak view
|
||||
$viewPath = 'admin.type.summary-nocache';
|
||||
$cacheFileName = 'summary';
|
||||
|
||||
try {
|
||||
// View içeriğini oluştur
|
||||
$viewContent = view($viewPath)->render();
|
||||
|
||||
// Cache dosyasını kaydet
|
||||
Storage::put("cache/{$cacheFileName}.blade.php", $viewContent);
|
||||
|
||||
// Son güncelleme zamanını kaydet
|
||||
Storage::put("cache/{$cacheFileName}_last_updated.txt", date('Y-m-d H:i:s'));
|
||||
|
||||
echo "{$viewPath} önbelleği başarıyla güncellendi: " . date('Y-m-d H:i:s') . "<br>";
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('view:clear');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo "{$viewPath} önbelleği güncellenirken hata oluştu: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
Cache::put("subcontractors", table_to_array("subcontractors", "company_name_en"));
|
||||
?>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
use App\Models\PaintFollowUp;
|
||||
use App\Models\LineList;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
// Method 1: Using join which is more efficient than subquery
|
||||
$deletedCount = DB::table('paint_follow_ups')
|
||||
->join('line_lists', 'paint_follow_ups.line', '=', 'line_lists.line_no')
|
||||
->where(function($query) {
|
||||
$query->whereNull('line_lists.painting_cycle')
|
||||
->orWhere('line_lists.painting_cycle', '');
|
||||
});
|
||||
|
||||
if(isset($lineNumber)){
|
||||
$deletedCount = $deletedCount->where('paint_follow_ups.line', $lineNumber);
|
||||
}
|
||||
|
||||
$deletedCount = $deletedCount->delete();
|
||||
|
||||
Log::debug("$deletedCount rows deleted from paint_follow_ups table");
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$nullEngineering = db("document_revisions")
|
||||
->select(
|
||||
"document_revisions.id",
|
||||
"weld_logs.iso_rev",
|
||||
"document_revisions.revision_no",
|
||||
"document_revisions.drawing_no"
|
||||
)
|
||||
->join(
|
||||
"weld_logs",
|
||||
"document_revisions.drawing_no",
|
||||
"weld_logs.iso_number"
|
||||
)
|
||||
->orderBy("document_revisions.id", "DESC");
|
||||
|
||||
if(isset($lineNumber)) {
|
||||
$_GET['q'] = $lineNumber;
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
if(!getesit("q","")) {
|
||||
$nullEngineering = $nullEngineering->where("drawing_no", get("q"));
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['pdf_engineering'] = null;
|
||||
$updateData['pdf_spool_iso'] = null;
|
||||
$updateData['pdf_as_build'] = null;
|
||||
db("document_revisions")->where("drawing_no", get("q"))->update($updateData);
|
||||
}
|
||||
|
||||
$nullEngineering = $nullEngineering->get();
|
||||
|
||||
|
||||
//dump($nullEngineering->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄Document Revisions PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullEngineering AS $ne) {
|
||||
$data = "{$ne->drawing_no}";
|
||||
$dataWithRev = "{$ne->drawing_no}*{$ne->revision_no}";
|
||||
|
||||
//$data = strtolower($data);
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$dataWithRev = str_replace("/", "*", $dataWithRev);
|
||||
$dataWithRev = str_replace(" ", "*", $dataWithRev);
|
||||
|
||||
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);
|
||||
|
||||
if($ne->iso_rev == $ne->revision_no) {
|
||||
$searchSpoolIso = glob($path2);
|
||||
$searchAsBuild = glob($path3);
|
||||
}
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['pdf_engineering'] = null;
|
||||
$updateData['pdf_spool_iso'] = null;
|
||||
$updateData['pdf_as_build'] = null;
|
||||
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
////dump($updateData);
|
||||
|
||||
db("document_revisions")
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("Document Revisions update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄Document Revisions PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
//weldlogs iso number trim problems
|
||||
$weldLogUpdate = db("weld_logs")->update([
|
||||
'iso_number' => DB::raw('TRIM(iso_number)'),
|
||||
'line_number' => DB::raw('TRIM(line_number)'),
|
||||
'fluid_code' => DB::raw('TRIM(fluid_code)'),
|
||||
]);
|
||||
|
||||
$lineListUpdate = db("line_lists")->update([
|
||||
'line_no' => DB::raw('TRIM(line_no)'),
|
||||
'fluid_code' => DB::raw('TRIM(fluid_code)'),
|
||||
]);
|
||||
|
||||
echo "weld_logs: $weldLogUpdate, line_lists: $lineListUpdate";
|
||||
?>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
$tableName = "incoming_control_paints";
|
||||
|
||||
// Verileri çek
|
||||
$list = db($tableName)
|
||||
->select("id", "certificate_no", "akt_number")
|
||||
->orderBy("id", "DESC");
|
||||
|
||||
if(isset($lineNumber)) {
|
||||
$_GET['q'] = $lineNumber;
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
// Eğer belirli bir kayıt için çalıştırılıyorsa (q parametresi veya lineNumber)
|
||||
if(!getesit("q","")) {
|
||||
$q = get("q");
|
||||
$list = $list->where(function($query) use ($q) {
|
||||
$query->where("certificate_no", $q)
|
||||
->orWhere("akt_number", $q);
|
||||
});
|
||||
|
||||
// Güncelleme öncesi ilgili kayıtları sıfırla
|
||||
$resetData = [];
|
||||
$resetData['pdf_certificate'] = null;
|
||||
$resetData['pdf_akt'] = null;
|
||||
|
||||
db($tableName)
|
||||
->where("certificate_no", $q)
|
||||
->orWhere("akt_number", $q)
|
||||
->update($resetData);
|
||||
}
|
||||
|
||||
$list = $list->get();
|
||||
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄Incoming Control Paint PDF Link to DB Start " . simdi());
|
||||
|
||||
try {
|
||||
foreach($list as $item) {
|
||||
$updateData = [];
|
||||
|
||||
// 1. Certificate File Logic
|
||||
// Path: 002_Project_Materials/002_Material Certificate/
|
||||
// Pattern: {certificate_no}*.pdf
|
||||
if($item->certificate_no) {
|
||||
// Dosya sistemi araması için slash ve boşlukları joker (*) ile değiştir
|
||||
$certData = str_replace(["/", " "], "*", $item->certificate_no);
|
||||
|
||||
if(trim($certData) != "") {
|
||||
$pathCert = "storage/documents/002_Project_Materials/002_Material Certificate/*{$certData}*.pdf";
|
||||
$searchCert = glob($pathCert);
|
||||
|
||||
if(isset($searchCert[0])) {
|
||||
$updateData['pdf_certificate'] = $searchCert[0];
|
||||
} else {
|
||||
// Eğer bulunamazsa null yap (manuel silinmiş olabilir)
|
||||
$updateData['pdf_certificate'] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. AKT File Logic
|
||||
// Path: 002_Project_Materials/001_Material Akt/
|
||||
// Pattern: {akt_number}*.pdf
|
||||
if($item->akt_number) {
|
||||
$aktData = str_replace(["/", " "], "*", $item->akt_number);
|
||||
|
||||
if(trim($aktData) != "") {
|
||||
$pathAkt = "storage/documents/002_Project_Materials/001_Material Akt/*{$aktData}*.pdf";
|
||||
$searchAkt = glob($pathAkt);
|
||||
|
||||
if(isset($searchAkt[0])) {
|
||||
$updateData['pdf_akt'] = $searchAkt[0];
|
||||
} else {
|
||||
$updateData['pdf_akt'] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Eğer güncellenecek veri varsa güncelle
|
||||
if(count($updateData) > 0) {
|
||||
db($tableName)
|
||||
->where("id", $item->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
}
|
||||
|
||||
// Transaction commit check
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
Log::debug("Incoming Control Paint update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("Incoming Control Paint PDF Sync Error: " . $th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄Incoming Control Paint PDF Link to DB Finish " . simdi());
|
||||
?>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
use App\Models\IncomingControlPaint;
|
||||
use App\Models\PaintFollowUp;
|
||||
$cachePrefix = 'sync-from-incoming-control-paint-paint-follow-up';
|
||||
$lastId = 0;
|
||||
|
||||
if(Cache::has($cachePrefix)) {
|
||||
$lastId = Cache::get($cachePrefix);
|
||||
}
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$incomingControlPaints = IncomingControlPaint::where("id", $id)->get();
|
||||
} else {
|
||||
$incomingControlPaints = IncomingControlPaint::get();
|
||||
}
|
||||
|
||||
//->where("id",">", $lastId)
|
||||
|
||||
|
||||
|
||||
$count = 0;
|
||||
|
||||
Log::debug("$cachePrefix start " . simdi());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
|
||||
try {
|
||||
foreach($incomingControlPaints AS $incomingControlPaint) {
|
||||
|
||||
$updateData = [
|
||||
'incoming_control_akt_no_1' => $incomingControlPaint->akt_number,
|
||||
'incoming_control_rfi_no_1' => $incomingControlPaint->rfi_no,
|
||||
'akt_date_1' => $incomingControlPaint->akt_date,
|
||||
'standartgost_iso_en_1' => $incomingControlPaint->manufacturing_standard,
|
||||
'certificate_passport_no_1' => $incomingControlPaint->certificate_no,
|
||||
'certificate_passport_date_1' => $incomingControlPaint->certificate_date,
|
||||
'incoming_control_akt_no_2' => $incomingControlPaint->akt_number,
|
||||
'incoming_control_rfi_no_2' => $incomingControlPaint->rfi_no,
|
||||
'akt_date_2' => $incomingControlPaint->akt_date,
|
||||
'standartgost_iso_en_2' => $incomingControlPaint->manufacturing_standard,
|
||||
'certificate_passport_no_2' => $incomingControlPaint->certificate_no,
|
||||
'certificate_passport_date_2' => $incomingControlPaint->certificate_date,
|
||||
'incoming_control_akt_no_3' => $incomingControlPaint->akt_number,
|
||||
'incoming_control_rfi_no_3' => $incomingControlPaint->rfi_no,
|
||||
'akt_date_3' => $incomingControlPaint->akt_date,
|
||||
'standartgost_iso_en_3' => $incomingControlPaint->manufacturing_standard,
|
||||
'certificate_passport_no_3' => $incomingControlPaint->certificate_no,
|
||||
'certificate_passport_date_3' => $incomingControlPaint->certificate_date,
|
||||
];
|
||||
|
||||
$whereData = [
|
||||
'incoming_control_rfi_no_1' => $incomingControlPaint->rfi_no,
|
||||
'ral_code_1' => $incomingControlPaint->ral_code,
|
||||
];
|
||||
|
||||
PaintFollowUp::where($whereData)->update($updateData);
|
||||
|
||||
Cache::put($cachePrefix, $incomingControlPaint->id);
|
||||
|
||||
$count++;
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
//dump($th);
|
||||
DB::rollback();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//dump("$count Data has been sync from Incoming Control Paint to Paint Follow Up");
|
||||
Log::debug("$cachePrefix finish " . simdi());
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
//paint system sync
|
||||
|
||||
$lineLists = DB::table('line_lists')
|
||||
|
||||
->whereNotNull('painting_cycle') // paint_cycle boş olmayan verileri al
|
||||
->get();
|
||||
|
||||
|
||||
$count = 0;
|
||||
foreach ($lineLists as $line) {
|
||||
// paint_cycle'a göre update veya insert işlemi yap
|
||||
// Check if record exists
|
||||
$existingRecord = DB::table('paint_systems')
|
||||
->where('paint_cycle', $line->painting_cycle)
|
||||
->first();
|
||||
|
||||
if ($existingRecord) {
|
||||
// Update existing record
|
||||
DB::table('paint_systems')
|
||||
->where('paint_cycle', $line->painting_cycle)
|
||||
->update([
|
||||
'paint_cycle' => $line->painting_cycle,
|
||||
'revision' => $line->rev ?? "",
|
||||
]);
|
||||
} else {
|
||||
// Insert new record
|
||||
DB::table('paint_systems')
|
||||
->insert([
|
||||
'paint_cycle' => $line->painting_cycle,
|
||||
'revision' => $line->rev ?? "",
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
DB::table('color_systems')->updateOrInsert(
|
||||
['fluid_code' => $line->fluid_code], // Güncellenecek veya eklenecek satırı belirler
|
||||
[
|
||||
'fluid_code_description' => $line->fluid_en ?? "",
|
||||
'fluid_code' => $line->fluid_code,
|
||||
'design_temperature' => $line->design_temperature ?? "",
|
||||
'working_temperature' => $line->working_temperature ?? "",
|
||||
'unit' => $line->unit,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$count++;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
use App\Models\NdeMatrix;
|
||||
use Carbon\Carbon;
|
||||
|
||||
// SaveTrigger'dan çağrılıp çağrılmadığını kontrol et
|
||||
$triggerMode = isset($triggerMode) ? $triggerMode : false;
|
||||
|
||||
if($triggerMode && isset($line_number) && isset($design_area)) {
|
||||
// SaveTrigger'dan çağrıldıysa sadece belirli line_number ve design_area için işlem yap
|
||||
$lineLists = db("line_lists")
|
||||
->where("line_no", $line_number)
|
||||
->where("unit", $design_area)
|
||||
->get();
|
||||
|
||||
$weldlogs = apply_welded_filter(
|
||||
db("weld_logs")
|
||||
->where("line_number", $line_number)
|
||||
->where("design_area", $design_area)
|
||||
)->get();
|
||||
|
||||
Log::debug("SaveTrigger mode: processing specific line for NDE Matrix", [
|
||||
'line_number' => $line_number,
|
||||
'design_area' => $design_area,
|
||||
'line_lists_found' => $lineLists->count(),
|
||||
'weld_logs_found' => $weldlogs->count()
|
||||
]);
|
||||
} elseif(isset($id)) {
|
||||
$lineLists = db("line_lists")->where("id", $id)->get();
|
||||
$weldlogs = db("weld_logs");
|
||||
if(isset($id)) {
|
||||
$weldlogs = $weldlogs->where("line_number", $lineLists[0]?->line_no);
|
||||
}
|
||||
$weldlogs = apply_welded_filter($weldlogs)->get();
|
||||
} else {
|
||||
$lineLists = db("line_lists")->get();
|
||||
$weldlogs = apply_welded_filter(db("weld_logs"))->get();
|
||||
}
|
||||
|
||||
|
||||
$specJointTypes = [];
|
||||
|
||||
foreach($weldlogs AS $weldlog) {
|
||||
// fluid_code null kontrolü ekle - SaveTrigger'daki mantıkla uyumlu
|
||||
$fluidCode = $weldlog->fluid_code ?? '';
|
||||
if(empty($fluidCode)) {
|
||||
// fluid_code null ise line_lists'ten al
|
||||
$lineListForFluid = $lineLists->where('line_no', $weldlog->line_number)->first();
|
||||
if($lineListForFluid) {
|
||||
$fluidCode = $lineListForFluid->fluid_code ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($fluidCode)) {
|
||||
if(!isset($specJointTypes[$fluidCode][$weldlog->line_number]))
|
||||
$specJointTypes[$fluidCode][$weldlog->line_number] = [];
|
||||
|
||||
if(!in_array($weldlog->type_of_welds, $specJointTypes[$fluidCode][$weldlog->line_number]))
|
||||
$specJointTypes[$fluidCode][$weldlog->line_number][] = $weldlog->type_of_welds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$cachePrefix = "sync-from-linelists-nde-matrix";
|
||||
Log::debug("$cachePrefix start " . simdi());
|
||||
$lastId = get_cache_id($cachePrefix);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$ndeMatrix = NdeMatrix::get();
|
||||
if($ndeMatrix->count() == 0) {
|
||||
$lineLists = db("line_lists")
|
||||
->get();
|
||||
}
|
||||
|
||||
if($lineLists->count() == 0) {
|
||||
set_cache_id($cachePrefix, 0);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$say = 0;
|
||||
|
||||
// SaveTrigger'dan gelen commitSize'ı kullan, yoksa varsayılan değer
|
||||
$commitSize = isset($commitSize) ? $commitSize : 50;
|
||||
|
||||
$update = 0;
|
||||
$create = 0;
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach($lineLists AS $lineList) {
|
||||
|
||||
|
||||
// fluid_code null kontrolü ekle - SaveTrigger'daki mantıkla uyumlu
|
||||
$lineListFluidCode = $lineList->fluid_code ?? '';
|
||||
if(empty($lineListFluidCode)) {
|
||||
continue; // fluid_code null ise bu line_list'i atla
|
||||
}
|
||||
|
||||
if(isset($specJointTypes[$lineListFluidCode][$lineList->line_no])) {
|
||||
$typeOfJoint = $specJointTypes[$lineListFluidCode][$lineList->line_no];
|
||||
//dump($typeOfJoint);
|
||||
|
||||
foreach($typeOfJoint AS $jointItem) {
|
||||
$ht = 0;
|
||||
if($lineList->pwht == "YES") $ht = 100;
|
||||
$data = [
|
||||
'design_area' => $lineList->unit,
|
||||
'fluid' => $lineListFluidCode,
|
||||
'line' => $lineList->line_no,
|
||||
'line_spec' => $lineList->line_specification,
|
||||
'operation_temp' => $lineList->working_temperature,
|
||||
'operations_pressure_kg' => $lineList->working_pressure_mpa,
|
||||
'type_of_joint' => $jointItem,
|
||||
'pwht' => $lineList->pwht,
|
||||
'pwht_field' => $lineList->pwht,
|
||||
'pipe_material_class' => $lineList->pipe_material_class,
|
||||
'ht' => $ht,
|
||||
'ndt' => $lineList->ndt,
|
||||
//'ndt' => $lineList->painting_cycle,
|
||||
'piping_class_according_to_gost' => $lineList->category,
|
||||
'piping_group' => $lineList->fluid_group,
|
||||
'rev' => $lineList->rev
|
||||
];
|
||||
|
||||
|
||||
//line design_area fluid unique
|
||||
|
||||
$already = NdeMatrix::where([
|
||||
'line' => $lineList->line_no,
|
||||
'type_of_joint' => $jointItem,
|
||||
'fluid' => $lineListFluidCode,
|
||||
])->first();
|
||||
|
||||
if($already) {
|
||||
|
||||
unset($data['pwht_field']);
|
||||
|
||||
NdeMatrix::where([
|
||||
'line' => $lineList->line_no,
|
||||
'type_of_joint' => $jointItem,
|
||||
'fluid' => $lineListFluidCode,
|
||||
])->update($data);
|
||||
// //dump("{$lineList->line_no} $jointItem Update");
|
||||
$update++;
|
||||
} else {
|
||||
NdeMatrix::create($data);
|
||||
// //dump("{$lineList->line_no} $jointItem Added");
|
||||
$create++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
Log::warning($lineList->line_no . " " . $lineListFluidCode . " [WELDLOG ➡️ NDE MATRIX NOT FOUND]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
set_cache_id($cachePrefix, $lineList->id);
|
||||
|
||||
|
||||
$count++;
|
||||
if($say == $commitSize) {
|
||||
|
||||
$say = 0;
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
}
|
||||
$say++;
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
dump($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
|
||||
//dump("NDE Matrix affected rows: $update updated $create created");
|
||||
Log::debug("$cachePrefix finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
use App\Models\PaintMatrix;
|
||||
use App\Models\PaintFollowUp;
|
||||
$cachePrefix = 'sync-from-linelists-paint-matrix';
|
||||
$lastId = 0;
|
||||
|
||||
if(Cache::has($cachePrefix)) {
|
||||
$lastId = Cache::get($cachePrefix);
|
||||
}
|
||||
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$lineLists = db("line_lists")->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());
|
||||
?>
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
use App\Models\WeldLog;
|
||||
use App\Models\LineList;
|
||||
use Carbon\Carbon;
|
||||
|
||||
$cachePrefix = "sync-from-linelists-to-weldlog";
|
||||
$lastId = get_cache_id($cachePrefix);
|
||||
Log::debug("$cachePrefix start " . simdi());
|
||||
|
||||
// SaveTrigger'dan çağrılıp çağrılmadığını kontrol et
|
||||
$triggerMode = isset($triggerMode) ? $triggerMode : false;
|
||||
|
||||
if($triggerMode && isset($line_number) && isset($design_area)) {
|
||||
// SaveTrigger'dan çağrıldıysa sadece belirli line_number ve design_area için işlem yap
|
||||
$lineLists = LineList::where("line_no", $line_number)
|
||||
->where("unit", $design_area)
|
||||
->get();
|
||||
Log::debug("SaveTrigger mode: processing specific line", [
|
||||
'line_number' => $line_number,
|
||||
'design_area' => $design_area,
|
||||
'found_records' => $lineLists->count()
|
||||
]);
|
||||
} elseif(isset($id)) {
|
||||
$lineLists = LineList::where("id", $id)->get();
|
||||
} else {
|
||||
$lineLists = LineList::get();
|
||||
}
|
||||
|
||||
////dump($lineLists->count());
|
||||
|
||||
if($lineLists->count() == 0) {
|
||||
set_cache_id($cachePrefix, 0);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$say = 0;
|
||||
|
||||
// SaveTrigger'dan gelen commitSize'ı kullan, yoksa varsayılan değer
|
||||
$commitSize = isset($commitSize) ? $commitSize : 50;
|
||||
|
||||
////dump("$cachePrefix $lastId");
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
|
||||
try {
|
||||
foreach($lineLists AS $lineList) {
|
||||
|
||||
|
||||
$data = [
|
||||
'painting_cycle' => $lineList->painting_cycle,
|
||||
'main_nps' => $lineList->dn,
|
||||
'fluid_code' => $lineList->fluid_code,
|
||||
'service_category' => $lineList->category,
|
||||
'fluid_group' => $lineList->fluid_group,
|
||||
'piping_class' => $lineList->pipe_material_class,
|
||||
'external_finish_type' => $lineList->external_finish_type,
|
||||
// 'main_material' => $lineList->pipe_material_class,
|
||||
'circuit_number' => $lineList->circuit_number,
|
||||
'p_id' => $lineList->p_id,
|
||||
'type_of_test' => $lineList->test_media,
|
||||
'test_pressure' => $lineList->test_pressure_mpa,
|
||||
'line_specification' => $lineList->line_specification,
|
||||
'design_pressure_mpa' => $lineList->design_pressure_mpa,
|
||||
'design_temperature_s' => $lineList->design_temperature,
|
||||
'operating_pressure_mpa' => $lineList->working_pressure_mpa,
|
||||
'operating_temperature_s' => $lineList->working_temperature,
|
||||
'ndt_percent' => $lineList->ndt,
|
||||
];
|
||||
Log::debug("WeldLog güncelleniyor", [
|
||||
'line_number' => $lineList->line_no,
|
||||
'design_area' => $lineList->unit,
|
||||
'updated_data' => $data
|
||||
]);
|
||||
|
||||
$result = db("weld_logs")
|
||||
->where("line_number", $lineList->line_no)
|
||||
->where("design_area", $lineList->unit)
|
||||
->update($data);
|
||||
|
||||
set_cache_id($cachePrefix, $lineList->id);
|
||||
|
||||
$count++;
|
||||
|
||||
if($say == $commitSize) {
|
||||
|
||||
$say = 0;
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
}
|
||||
$say++;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
//dump($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
//dump("WeldLog affected rows: $count");
|
||||
|
||||
Log::debug("$count processed");
|
||||
Log::debug("$cachePrefix finish " . simdi());
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
use App\Models\WeldLog;
|
||||
use App\Models\NdeMatrix;
|
||||
use Carbon\Carbon;
|
||||
|
||||
$cachePrefix = "sync-nde-to-weldlog";
|
||||
$lastId = get_cache_id($cachePrefix);
|
||||
Log::debug("$cachePrefix start " . simdi());
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$ndeMatrices = NdeMatrix::where("id", $id)->get();
|
||||
} else {
|
||||
$ndeMatrices = NdeMatrix::get();
|
||||
}
|
||||
|
||||
if($ndeMatrices->count() == 0) {
|
||||
set_cache_id($cachePrefix, 0);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$say = 0;
|
||||
$commitSize = 1000;
|
||||
|
||||
////dump("$cachePrefix $lastId");
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
foreach($ndeMatrices AS $ndeMatrix) {
|
||||
|
||||
$data = [
|
||||
'vt_scope' => 100,
|
||||
'rt_scope' => $ndeMatrix->rt,
|
||||
'ut_scope' => $ndeMatrix->ut,
|
||||
'mt_scope' => $ndeMatrix->mt,
|
||||
'pt_scope' => $ndeMatrix->pt,
|
||||
'pmi_scope' => $ndeMatrix->pmi,
|
||||
'ht_scope' => $ndeMatrix->ht,
|
||||
'pwht' => $ndeMatrix->pwht_field,
|
||||
'ferrite_scope' => $ndeMatrix->fn,
|
||||
'ndt_percent' => $ndeMatrix->ndt,
|
||||
'operating_temperature_s' => $ndeMatrix->operation_temp,
|
||||
'operating_pressure_mpa' => $ndeMatrix->operations_pressure_kg,
|
||||
'piping_class' => $ndeMatrix->piping_class_according_to_gost,
|
||||
'fluid_group' => $ndeMatrix->piping_group,
|
||||
'main_material' => $ndeMatrix->material,
|
||||
'updated_at' => simdi()
|
||||
];
|
||||
|
||||
$result = apply_welded_filter(
|
||||
db("weld_logs")
|
||||
->where("line_number", $ndeMatrix->line)
|
||||
->where("type_of_welds", $ndeMatrix->type_of_joint)
|
||||
)->update($data);
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
$say++;
|
||||
|
||||
set_cache_id($cachePrefix, $ndeMatrix->id);
|
||||
|
||||
$count += $result;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
//dump($th);
|
||||
Log::error("$cachePrefix error", ['message' => $th->getMessage()]);
|
||||
}
|
||||
|
||||
//dump("WeldLog affected rows: $count");
|
||||
|
||||
Log::info("$count processed");
|
||||
Log::debug("$cachePrefix finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
$result = Artisan::call('schedule:run');
|
||||
dump("Schedule run: $result");
|
||||
?>
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
// Calibration Logs PDF to DB Sync
|
||||
// Similar structure to pdf-db-naks-technology-sync.blade.php
|
||||
$table = "calibration_logs";
|
||||
$mainPath = "004_QA/0025_Calibration";
|
||||
$nullDownload = db($table);
|
||||
|
||||
if(isset($fileName)) {
|
||||
// Parse fileName to extract identification info
|
||||
// Example file patterns:
|
||||
// - CLB-001.pdf (item_no format)
|
||||
// - SERIAL123-CALIBRATION.pdf (serial_no format)
|
||||
// - PASSPORT-CERT-2024.pdf (passport_certificate_no format)
|
||||
// - CAL-CERT-123.pdf (calibration_certificate_no format)
|
||||
|
||||
$cleanFileName = $fileName;
|
||||
$cleanFileName = str_replace('.pdf', '', $cleanFileName);
|
||||
$cleanFileName = str_replace('.PDF', '', $cleanFileName);
|
||||
|
||||
|
||||
// Try to match by multiple identifiers
|
||||
$nullDownload = $nullDownload->where(function($query) use ($cleanFileName) {
|
||||
$query->where("item_no", "like", "%$cleanFileName%")
|
||||
->orWhere("serial_no", "like", "%$cleanFileName%")
|
||||
->orWhere("passport_certificate_no", "like", "%$cleanFileName%")
|
||||
->orWhere("calibration_certificate_no", "like", "%$cleanFileName%")
|
||||
->orWhere("equipment_name", "like", "%$cleanFileName%");
|
||||
});
|
||||
$commitSize = 1; // Single file processing
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
|
||||
try {
|
||||
foreach($nullDownload AS $record) {
|
||||
$updateData = [];
|
||||
|
||||
$calibrationSearchTerms = [];
|
||||
|
||||
if(isset($record->item_no) && trim($record->item_no) != "") {
|
||||
$calibrationSearchTerms[] = $record->item_no;
|
||||
}
|
||||
if(isset($record->passport_certificate_no) && trim($record->passport_certificate_no) != "") {
|
||||
$calibrationSearchTerms[] = $record->passport_certificate_no;
|
||||
}
|
||||
if(isset($record->calibration_certificate_no) && trim($record->calibration_certificate_no) != "") {
|
||||
$calibrationSearchTerms[] = $record->calibration_certificate_no;
|
||||
}
|
||||
|
||||
if(count($calibrationSearchTerms) > 0 || isset($record->equipment_name)) {
|
||||
$updateData['calibration_certificate'] = null;
|
||||
$foundFile = false;
|
||||
|
||||
// Try each search term until we find a match for calibration_certificate
|
||||
foreach($calibrationSearchTerms as $searchTerm) {
|
||||
$data = "*$searchTerm*";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$path = "storage/documents/$mainPath/{$data}";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['calibration_certificate'] = $searchPDF[0];
|
||||
$foundFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no match found with specific terms, try equipment_name as fallback for calibration_certificate
|
||||
if(!$foundFile && isset($record->equipment_name) && trim($record->equipment_name) != "") {
|
||||
$data = "*" . $record->equipment_name . "*";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$path = "storage/documents/$mainPath/{$data}";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['calibration_certificate'] = $searchPDF[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($record->serial_no) && trim($record->serial_no) != "") {
|
||||
$serialData = "*" . $record->serial_no . "*";
|
||||
$serialData = str_replace("/", "*", $serialData);
|
||||
$serialData = str_replace(" ", "*", $serialData);
|
||||
|
||||
$serialPath = "storage/documents/$mainPath/{$serialData}";
|
||||
$serialSearchPDF = glob($serialPath);
|
||||
|
||||
if(isset($serialSearchPDF[0])) {
|
||||
$updateData['certification_document'] = $serialSearchPDF[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Update database only if there are changes
|
||||
if(count($updateData) > 0) {
|
||||
db($table)
|
||||
->where("id", $record->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "document_procedures";
|
||||
$mainPath = "004_QA/0018_Procedure";
|
||||
$nullDownload = db($table);
|
||||
|
||||
if(isset($fileName)) {
|
||||
$nullDownload = $nullDownload->where("document_no", $fileName);
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
if(!isset($commitSize)) {
|
||||
$commitSize = 1000;
|
||||
}
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->document_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*.pdf";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
//dump("commmit");
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
$table = "incoming_controls";
|
||||
$certificatePath = "002_Project_Materials/002_Material Certificate";
|
||||
$aktPath = "002_Project_Materials/001_Material Akt";
|
||||
$emailTqPath = "002_Project_Materials/005_Material_Agreement";
|
||||
$osdPath = "002_Project_Materials/006_Defect_Documents";
|
||||
$nullDownload = db($table);
|
||||
|
||||
if(isset($fileName)) {
|
||||
$fileName = str_replace(".pdf", "", $fileName);
|
||||
$nullDownload = $nullDownload->where(function ($query) use ($fileName) {
|
||||
$query->where("certificate_no", $fileName)
|
||||
->orWhere("akt_number", $fileName)
|
||||
->orWhere("email_tq_number", $fileName)
|
||||
->orWhere("osd_report_no", $fileName);
|
||||
});
|
||||
$commitSize = 1;
|
||||
}
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
$commitSize = 100; // Commit her 100 kayıtta bir yapılacak
|
||||
$say = 0;
|
||||
$kCertificate = 0;
|
||||
$kAkt = 0;
|
||||
$kEmailTq = 0;
|
||||
$kOsd = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$updateData = [];
|
||||
$updateData['certificate_file'] = null;
|
||||
$updateData['akt_file'] = null;
|
||||
$updateData['email_tq_file'] = null;
|
||||
$updateData['osd_defect_akt_file'] = null;
|
||||
|
||||
// Certificate File işlemi
|
||||
if(!empty($ne->certificate_no)) {
|
||||
|
||||
|
||||
$certificateNo = trim($ne->certificate_no);
|
||||
$certificateNo = str_replace("/", "*", $certificateNo);
|
||||
$certificateNo = str_replace(" ", "*", $certificateNo);
|
||||
|
||||
if(trim($certificateNo) != "") {
|
||||
$path = "storage/documents/$certificatePath/*$certificateNo*.pdf";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['certificate_file'] = $searchPDF[0];
|
||||
$kCertificate++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AKT File işlemi
|
||||
if(!empty($ne->akt_number)) {
|
||||
$aktNumber = trim($ne->akt_number);
|
||||
$aktNumber = str_replace("/", "*", $aktNumber);
|
||||
$aktNumber = str_replace(" ", "*", $aktNumber);
|
||||
|
||||
if(trim($aktNumber) != "") {
|
||||
$path = "storage/documents/$aktPath/*$aktNumber*.pdf";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['akt_file'] = $searchPDF[0];
|
||||
$kAkt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Email TQ File işlemi
|
||||
if(!empty($ne->email_tq_number)) {
|
||||
$emailTqNumber = trim($ne->email_tq_number);
|
||||
$emailTqNumber = str_replace("/", "*", $emailTqNumber);
|
||||
$emailTqNumber = str_replace(" ", "*", $emailTqNumber);
|
||||
|
||||
if(trim($emailTqNumber) != "") {
|
||||
$path = "storage/documents/$emailTqPath/*$emailTqNumber*.pdf";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['email_tq_file'] = $searchPDF[0];
|
||||
$kEmailTq++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OSD File işlemi
|
||||
if(!empty($ne->osd_report_no)) {
|
||||
$osdReportNo = trim($ne->osd_report_no);
|
||||
$osdReportNo = str_replace("/", "*", $osdReportNo);
|
||||
$osdReportNo = str_replace(" ", "*", $osdReportNo);
|
||||
|
||||
if(trim($osdReportNo) != "") {
|
||||
$path = "storage/documents/$osdPath/*$osdReportNo*.pdf";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['osd_defect_akt_file'] = $searchPDF[0];
|
||||
$kOsd++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Eğer herhangi bir güncelleme varsa
|
||||
if(!is_null($updateData['certificate_file']) || !is_null($updateData['akt_file']) || !is_null($updateData['email_tq_file']) || !is_null($updateData['osd_defect_akt_file'])) {
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update: Certificate PDF link for $kCertificate rows, AKT PDF link for $kAkt rows, Email/TQ PDF link for $kEmailTq rows, OSD PDF link for $kOsd rows");
|
||||
//dump("$table update: Certificate PDF link for $kCertificate rows, AKT PDF link for $kAkt rows, Email/TQ PDF link for $kEmailTq rows, OSD PDF link for $kOsd rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "i_t_p_s";
|
||||
$mainPath = "004_QA/000_ITP";
|
||||
$nullDownload = db($table);
|
||||
|
||||
if(isset($fileName)) {
|
||||
$nullDownload = $nullDownload->where("itp_no", $fileName);
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->itp_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
//dump("commmit");
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "naks_consumables";
|
||||
$mainPath = "003_Welding_Database/0003_Naks_Consumables";
|
||||
$mainPath2 = "003_Welding_Database/0003_Naks_Consumables";
|
||||
$nullDownload = db($table);
|
||||
|
||||
// Eğer fileName değişkeni varsa, sadece ilgili kayıtları filtrele
|
||||
if(isset($fileName) && !empty($fileName)) {
|
||||
$nullDownload = $nullDownload->where(function($query) use ($fileName) {
|
||||
$query->where('naks_certificate_no', 'LIKE', "$fileName")
|
||||
->orWhere('batch_number', 'LIKE', "$fileName")
|
||||
->orWhere('inspection_test_report', 'LIKE', "$fileName")
|
||||
->orWhere('icm_akt_no', 'LIKE', "$fileName");
|
||||
});
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->naks_certificate_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$data2 = "{" . $ne->batch_number . "," . $ne->inspection_test_report . "}";
|
||||
$data2 = str_replace("/", "*", $data2);
|
||||
$data2 = str_replace(" ", "*", $data2);
|
||||
|
||||
// ICM Akt No için arama kriteri
|
||||
$data3 = "{$ne->icm_akt_no}";
|
||||
$data3 = str_replace("/", "*", $data3);
|
||||
$data3 = str_replace(" ", "*", $data3);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
$path2 = "storage/documents/$mainPath/*$data2*";
|
||||
//dump($path2);
|
||||
$searchPDF2 = glob($path2, GLOB_BRACE);
|
||||
|
||||
// ICM Akt No için PDF arama
|
||||
$path3 = "storage/documents/$mainPath/*$data3*";
|
||||
$searchPDF3 = glob($path3);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['naks_technology'] = null;
|
||||
$updateData['inspection_test_report_download'] = null;
|
||||
$updateData['icm_akt_no_download'] = null;
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['naks_technology'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
$updateData['inspection_test_report_download'] = null;
|
||||
|
||||
if(isset($searchPDF2[0])) {
|
||||
$updateData['inspection_test_report_download'] = $searchPDF2[0];
|
||||
}
|
||||
|
||||
if(isset($searchPDF3[0])) {
|
||||
$updateData['icm_akt_no_download'] = $searchPDF3[0];
|
||||
}
|
||||
|
||||
|
||||
//dump($updateData);
|
||||
|
||||
echo db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "naks_certificates";
|
||||
$mainPath = "003_Welding_Database/0000_Naks Technology";
|
||||
$nullDownload = db($table);
|
||||
if(isset($fileName)) {
|
||||
// Parse fileName to extract short_number and certificate_no
|
||||
$fileNameParts = explode('-', $fileName);
|
||||
if(count($fileNameParts) >= 2) {
|
||||
$shortNumber = $fileNameParts[0]; // АЦСТ-161 or АЦСТ-11
|
||||
|
||||
// Handle different certificate number formats
|
||||
if(count($fileNameParts) >= 3) {
|
||||
// Format: АЦСТ-11-08091_ОХНВП(16)_РАД.pdf
|
||||
// Combine the remaining parts and extract the numeric part
|
||||
$remainingParts = implode('-', array_slice($fileNameParts, 2));
|
||||
$certificateNo = $fileNameParts[1]; // 08091
|
||||
|
||||
// Extract numeric part from the remaining string (before underscore)
|
||||
if(preg_match('/^(\d+)/', $remainingParts, $matches)) {
|
||||
$certificateNo = $matches[1];
|
||||
}
|
||||
} else {
|
||||
// Original format: АЦСТ-161-00050.pdf
|
||||
$certificateNo = $fileNameParts[1]; // 00050
|
||||
}
|
||||
|
||||
// Remove file extension if present
|
||||
$certificateNo = str_replace('.pdf', '', $certificateNo);
|
||||
dump($shortNumber, $certificateNo);
|
||||
// Update the query to search by both short_number and certificate_no
|
||||
$nullDownload = $nullDownload->where("short_number", "like", "%$shortNumber%")
|
||||
->where("certificate_no", "like", "%$certificateNo%");
|
||||
}
|
||||
}
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$searchTerm = $ne->short_number;
|
||||
$certNo = isset($ne->certificate_no) ? $ne->certificate_no : '';
|
||||
|
||||
// First try: exact match with both short_number and certificate_no
|
||||
if(trim($searchTerm) != "" && trim($certNo) != "") {
|
||||
// Try different zero-prefix patterns for certificate_no
|
||||
$foundFile = false;
|
||||
|
||||
// Original certificate number from database
|
||||
$certPatterns = [$certNo];
|
||||
|
||||
// Clean leading zeros and generate additional search patterns
|
||||
$trimmedCertNo = ltrim($certNo, '0');
|
||||
if($trimmedCertNo != $certNo) {
|
||||
// Add trimmed version (no leading zeros)
|
||||
$certPatterns[] = $trimmedCertNo;
|
||||
|
||||
// Add versions with different numbers of leading zeros
|
||||
for($i = 1; $i <= 4; $i++) {
|
||||
$certPatterns[] = str_pad($trimmedCertNo, $i, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
$updateData = ['download' => null];
|
||||
|
||||
// Try each pattern until we find a match
|
||||
foreach($certPatterns as $certPattern) {
|
||||
// Format 1: short_number-certPattern (primary format)
|
||||
$searchData = "*{$searchTerm}-{$certPattern}*";
|
||||
$searchData = str_replace("/", "*", $searchData);
|
||||
$searchData = str_replace(" ", "*", $searchData);
|
||||
|
||||
$path = "storage/documents/$mainPath/{$searchData}";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
$foundFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no match found with primary format, try just the short_number as fallback
|
||||
if(!$foundFile) {
|
||||
$data = "*$searchTerm";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$path = "storage/documents/$mainPath/{$data}*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
}
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "naks_welders";
|
||||
$mainPath = "003_Welding_Database/0001_Naks_Welder";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->naks_certificate_no}*{$ne->welder_id}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
////dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "welding_equipment";
|
||||
$mainPath = "003_Welding_Database/0002_Naks_Equipments";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->attestation}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
<?php
|
||||
//weld_logs
|
||||
$logPaths = log_paths();
|
||||
$logTables = log_test_types();
|
||||
if(isset($logTable)) {
|
||||
$logTables = [];
|
||||
$logTables[$logName] = $logTable;
|
||||
}
|
||||
?>
|
||||
@foreach($logTables AS $logName => $logTable)
|
||||
<?php
|
||||
$logPath = $logPaths[$logName];
|
||||
$logDatas = db($logTable)
|
||||
->orderBy("id", "DESC");
|
||||
|
||||
$reportName = $logName . "_report";
|
||||
if($logName == "pmi") {
|
||||
$reportName = "no_of_testing_report";
|
||||
}
|
||||
|
||||
if(isset($fileName)) {
|
||||
$logDatas = $logDatas->where($reportName, $fileName);
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
$logDatas = $logDatas->get();
|
||||
|
||||
//dump($logDatas->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄 $logName PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($logDatas AS $logData) {
|
||||
$data = $logData->{$reportName};
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$logPath/*$data*";
|
||||
$searchReport = glob($path);
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['report_file'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchReport[0])) {
|
||||
$updateData['report_file'] = $searchReport[0];
|
||||
}
|
||||
|
||||
|
||||
////dump($updateData);
|
||||
|
||||
db($logTable)
|
||||
->where("id", $logData->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$logName update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("$logName not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄 $logName PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@endforeach
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "prosedure_qualification_records";
|
||||
$mainPath = "003_Welding_Database/0004_PQR";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->pqr_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "punch_lists";
|
||||
$mainPath = "009_Punch_List/";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->punch_list_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['punch_list_download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['punch_list_download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
//dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
|
||||
|
||||
|
||||
$k++;
|
||||
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,70 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "register_of_experts";
|
||||
$mainPath = "003_Welding_Database/0007_Welding Experts";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->certificate_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
<?php
|
||||
$folder = $folder ?? "006_RFI/001_Created_RFI";
|
||||
$columnName = "";
|
||||
$subFolder = "";
|
||||
|
||||
if (strpos($folder, "001_Created_RFI") !== false) {
|
||||
$columnName = "created_rfi";
|
||||
$subFolder = "001_Created_RFI";
|
||||
} elseif (strpos($folder, "002_Signed_RFI") !== false) {
|
||||
$columnName = "signed_rfi";
|
||||
$subFolder = "002_Signed_RFI";
|
||||
}
|
||||
|
||||
if ($columnName == "") {
|
||||
dump("RFI Sync: Unknown folder $folder");
|
||||
return;
|
||||
}
|
||||
|
||||
$rfiDatas = db("r_f_i_s");
|
||||
|
||||
if (isset($fileName)) {
|
||||
// Optimization: only check RFIs that might match the file name parts
|
||||
// We don't know the exact format, but we know it should contain itp and rfi_no
|
||||
// To be safe and specific, we'll fetch all and match in PHP
|
||||
}
|
||||
|
||||
$rfiDatas = $rfiDatas->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
$count = 0;
|
||||
|
||||
try {
|
||||
foreach ($rfiDatas as $rfi) {
|
||||
$itp = trim($rfi->itp);
|
||||
$rfi_no = trim($rfi->rfi_no);
|
||||
|
||||
if ($itp == "" || $rfi_no == "") continue;
|
||||
|
||||
// If specific fileName is provided, we check if this RFI matches it
|
||||
if (isset($fileName)) {
|
||||
// Pattern check: fileName should contain rfi_no
|
||||
$pattern = "/" . preg_quote($rfi_no, '/') . ".*\.pdf/i";
|
||||
if (!preg_match($pattern, $fileName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$searchPath = storage_path("documents/006_RFI/$subFolder/*$rfi_no*.pdf");
|
||||
$foundFiles = glob($searchPath);
|
||||
|
||||
$updateData = [$columnName => null];
|
||||
if (isset($foundFiles[0])) {
|
||||
$updateData[$columnName] = str_replace(base_path() . "/", "", $foundFiles[0]);
|
||||
db("r_f_i_s")->where("id", $rfi->id)->update($updateData);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
dump("RFI Sync: Found and updated $count rows in r_f_i_s for $columnName");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
dump("RFI Sync Error: " . $th->getMessage());
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "supports";
|
||||
$mainPath = "001_Drawings/004_Support";
|
||||
$nullDownload = db($table);
|
||||
|
||||
if(isset($fileName)) {
|
||||
$nullDownload = $nullDownload->where("support_code", $fileName);
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->support_code}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
//dump("commmit");
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,117 @@
|
||||
<?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());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
<?php
|
||||
//document_revisions
|
||||
$table = "test_packages";
|
||||
$mainPath2 = "008_Test_Pack/001_TP Preperation_Documents";
|
||||
$mainPath = "008_Test_Pack/002_TP_(Scan)";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->test_package_number}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['test_pack_download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['test_pack_download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
//dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
|
||||
|
||||
db("test_pack_base_statuses")
|
||||
->where("test_package_no", $ne->test_package_number)
|
||||
->update($updateData);
|
||||
|
||||
$k++;
|
||||
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "welder_tests";
|
||||
$mainPath = "003_Welding_Database/0006_WPQ";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->wpq_document_no}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
$data2 = "{$ne->naks_id}";
|
||||
$data2 = str_replace("/", "*", $data2);
|
||||
$data2 = str_replace(" ", "*", $data2);
|
||||
|
||||
if(trim($data) != "" || trim($data2) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
/*
|
||||
$path2 = "storage/documents/$mainPath/*$data2*";
|
||||
$searchPDF = glob($path2);
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
*/
|
||||
//dump($updateData['download']);
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
//dump("commmit");
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
<?php
|
||||
|
||||
$table = "w_p_s";
|
||||
$mainPath = "003_Welding_Database/0005_WPS";
|
||||
$nullDownload = db($table);
|
||||
$nullDownload = $nullDownload->get();
|
||||
//dump($nullDownload->count());
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$say = 0;
|
||||
$k = 0;
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Start " . simdi());
|
||||
try {
|
||||
foreach($nullDownload AS $ne) {
|
||||
$data = "{$ne->details}";
|
||||
$data = str_replace("/", "*", $data);
|
||||
$data = str_replace(" ", "*", $data);
|
||||
|
||||
if(trim($data) != "") {
|
||||
$path = "storage/documents/$mainPath/*$data*";
|
||||
$searchPDF = glob($path);
|
||||
|
||||
|
||||
$updateData = [];
|
||||
|
||||
$updateData['download'] = null;
|
||||
|
||||
|
||||
if(isset($searchPDF[0])) {
|
||||
$updateData['download'] = $searchPDF[0];
|
||||
}
|
||||
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db($table)
|
||||
->where("id", $ne->id)
|
||||
->update($updateData);
|
||||
$k++;
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
|
||||
$say++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
Log::debug("$table update PDF link for $k rows");
|
||||
//dump("$table update PDF link for $k rows");
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
Log::error("not update PDF links " . $th->getMessage());
|
||||
////dump($th->getMessage());
|
||||
}
|
||||
|
||||
Log::debug("📄$table PDF Link to DB Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
use App\Models\PunchList;
|
||||
use App\Models\TestPackBaseStatus;
|
||||
$cachePrefix = 'sync-punch-qty';
|
||||
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$punchLists = PunchList::where("id", $id)->get();
|
||||
} else {
|
||||
$punchLists = PunchList::get();
|
||||
}
|
||||
|
||||
|
||||
$punchTotal = [];
|
||||
|
||||
Log::debug("$cachePrefix start");
|
||||
|
||||
foreach($punchLists AS $punchList) {
|
||||
|
||||
if(!isset($punchTotal[$punchList->line_isometric_no][$punchList->test_package][$punchList->category])) {
|
||||
$punchTotal[$punchList->line_isometric_no][$punchList->test_package][$punchList->category] = 0;
|
||||
}
|
||||
|
||||
if($punchList->status == "Open") {
|
||||
$punchTotal[$punchList->line_isometric_no][$punchList->test_package][$punchList->category]++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$count = 0;
|
||||
try {
|
||||
|
||||
foreach($punchTotal AS $isoNumber => $subData) {
|
||||
foreach($subData AS $testPackage => $data) {
|
||||
|
||||
TestPackBaseStatus::where([
|
||||
"test_package_no" => $testPackage,
|
||||
"drawing_no" => $isoNumber,
|
||||
])->update([
|
||||
'punch_a_quantity' => @$data['A'],
|
||||
'punch_b_quantity' => @$data['B'],
|
||||
'punch_c_quantity' => @$data['C'],
|
||||
]);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
db($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
//dump("$count Calculated Punch List ==> Test Pack Base Status");
|
||||
|
||||
Log::debug("$cachePrefix end");
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// General View Cache Generator
|
||||
// Bu cron görevi, belirtilen blade viewlarını önbelleğe alır ve storage/app/cache/ dizinine kaydeder
|
||||
/*
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
// Cache klasörünü oluştur (yoksa)
|
||||
if (!Storage::exists('cache')) {
|
||||
Storage::makeDirectory('cache');
|
||||
}
|
||||
|
||||
// Önbelleğe alınacak view'ların listesi
|
||||
$viewsToCache = [
|
||||
'admin.dashboard.module.dashboard' => 'dashboard',
|
||||
'admin.type.summary-nocache' => 'summary',
|
||||
// Burada daha fazla view ekleyebilirsiniz
|
||||
// 'view.path' => 'cache_filename'
|
||||
];
|
||||
|
||||
// Her bir view için önbellek oluştur
|
||||
foreach ($viewsToCache as $viewPath => $cacheFileName) {
|
||||
try {
|
||||
// View içeriğini oluştur
|
||||
$viewContent = view($viewPath)->render();
|
||||
|
||||
// Cache dosyasını kaydet
|
||||
Storage::put("cache/{$cacheFileName}.blade.php", $viewContent);
|
||||
|
||||
// Son güncelleme zamanını kaydet
|
||||
Storage::put("cache/{$cacheFileName}_last_updated.txt", date('Y-m-d H:i:s'));
|
||||
|
||||
echo "{$viewPath} önbelleği başarıyla güncellendi: " . date('Y-m-d H:i:s') . "<br>";
|
||||
} catch (\Exception $e) {
|
||||
echo "{$viewPath} önbelleği güncellenirken hata oluştu: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "Tüm önbellekler güncellendi: " . date('Y-m-d H:i:s');
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
use App\Models\WeldLog;
|
||||
|
||||
$lastIdPrefix = "spool-status-changer";
|
||||
$lastId = 0;
|
||||
|
||||
if(Cache::has($lastIdPrefix)) {
|
||||
$lastId = Cache::get($lastIdPrefix);
|
||||
}
|
||||
//echo $lastId;
|
||||
|
||||
use Carbon\Carbon;
|
||||
//dump("$lastIdPrefix $lastId");
|
||||
Log::debug("$lastIdPrefix start " . simdi());
|
||||
|
||||
// Initializing filter variables at the top to avoid undefined variable errors in scoped updates
|
||||
$filterSpoolNumber = null;
|
||||
if(!getesit("spool_number", "")) {
|
||||
$filterSpoolNumber = get("spool_number");
|
||||
} else if(isset($spool_number)) {
|
||||
$filterSpoolNumber = $spool_number;
|
||||
}
|
||||
|
||||
$filterIsoNumber = null;
|
||||
if(!getesit("iso_number", "")) {
|
||||
$filterIsoNumber = get("iso_number");
|
||||
} else if(isset($iso_number)) {
|
||||
$filterIsoNumber = $iso_number;
|
||||
}
|
||||
|
||||
$filterPaintChanged = false;
|
||||
if(isset($paintChanged) && $paintChanged) {
|
||||
$filterPaintChanged = true;
|
||||
} else if(getesit("paintChanged", "true")) {
|
||||
$filterPaintChanged = true;
|
||||
}
|
||||
|
||||
$updateEmptyQuery = db("weld_logs")->whereRaw("NULLIF(spool_status, '') IS NULL");
|
||||
|
||||
if($filterIsoNumber) {
|
||||
$updateEmptyQuery->where("iso_number", $filterIsoNumber);
|
||||
}
|
||||
if($filterSpoolNumber) {
|
||||
$updateEmptyQuery->where("spool_number", $filterSpoolNumber);
|
||||
}
|
||||
|
||||
$updateEmpty = apply_welded_filter($updateEmptyQuery)->update([
|
||||
'spool_status' => "Waiting"
|
||||
]);
|
||||
|
||||
|
||||
|
||||
//dump("$updateEmpty spool_status empty updated");
|
||||
|
||||
|
||||
$spoolLists = db("weld_logs")
|
||||
->select(
|
||||
"id",
|
||||
"spool_status",
|
||||
"painting_cycle",
|
||||
"welding_date",
|
||||
"spool_number",
|
||||
"iso_number",
|
||||
"updated_at",
|
||||
"type_of_joint",
|
||||
"no_of_the_joint_as_per_as_built_survey"
|
||||
);
|
||||
|
||||
Log::info("Filter paint changed: {$filterPaintChanged}");
|
||||
|
||||
if($filterSpoolNumber) {
|
||||
$spoolLists = $spoolLists->where("spool_number", $filterSpoolNumber);
|
||||
Log::info("Spool status changer filtering by spool_number: {$filterSpoolNumber}");
|
||||
}
|
||||
|
||||
if($filterIsoNumber) {
|
||||
$spoolLists = $spoolLists->where("iso_number", $filterIsoNumber);
|
||||
Log::info("Spool status changer filtering by iso_number: {$filterIsoNumber}");
|
||||
}
|
||||
|
||||
if(!getesit("rollback", "")) {
|
||||
$rollbackData = db("weld_logs")
|
||||
->where("id", get("rollback"))
|
||||
->first();
|
||||
|
||||
if($rollbackData) {
|
||||
$spoolLists = $spoolLists->where("iso_number", $rollbackData->iso_number)
|
||||
->where("spool_number", $rollbackData->spool_number);
|
||||
}
|
||||
}
|
||||
if($filterPaintChanged) {
|
||||
Log::info("Paint changed paint status refactored");
|
||||
} else {
|
||||
$spoolLists = $spoolLists
|
||||
->whereNotIn("spool_status", ['NDT Release', 'Paint', 'Completed']);
|
||||
}
|
||||
|
||||
$spoolLists = apply_welded_filter($spoolLists);
|
||||
|
||||
$spoolLists = $spoolLists
|
||||
->where("no_of_the_joint_as_per_as_built_survey", "not like", "%clone%");
|
||||
|
||||
$spoolLists = $spoolLists
|
||||
->orderBy("updated_at", "DESC");
|
||||
|
||||
$spoolLists = $spoolLists
|
||||
->get();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DB::beginTransaction();
|
||||
$k = 0;
|
||||
$say = 0;
|
||||
try {
|
||||
foreach($spoolLists AS $spoolList) {
|
||||
|
||||
$isoNumber = $spoolList->iso_number;
|
||||
$spoolNumber = $spoolList->spool_number;
|
||||
|
||||
$otherSpools = apply_welded_filter(
|
||||
db("weld_logs")
|
||||
->where("iso_number", $isoNumber)
|
||||
->where("spool_number", $spoolNumber)
|
||||
)->get();
|
||||
|
||||
$otherSpoolStatus = [];
|
||||
$otherSpoolTypeOfJoint = [];
|
||||
foreach($otherSpools AS $otherSpool) {
|
||||
$otherSpoolStatus[] = $otherSpool->spool_status;
|
||||
$otherSpoolTypeOfJoint[] = $otherSpool->type_of_joint;
|
||||
}
|
||||
|
||||
$spoolStatus = "Waiting";
|
||||
$weldingDateChecks = [];
|
||||
// //dump("{$spoolList->iso_number} {$spoolList->spool_number}");
|
||||
$allSpoolIsField = true;
|
||||
|
||||
$otherSpoolStatusCompletedCheck = false;
|
||||
$otherSpoolShopCheck = false;
|
||||
|
||||
foreach($otherSpools AS $otherSpool) {
|
||||
|
||||
|
||||
|
||||
if($otherSpool->type_of_joint != "F") {
|
||||
$weldingDateCheck = false;
|
||||
$allSpoolIsField = false;
|
||||
|
||||
|
||||
if(in_array("Completed", $otherSpoolStatus)) {
|
||||
$otherSpoolStatusCompletedCheck = true;
|
||||
}
|
||||
|
||||
if(in_array("S", $otherSpoolTypeOfJoint)) {
|
||||
$otherSpoolShopCheck = true;
|
||||
}
|
||||
|
||||
if(!rejected_date($otherSpool->welding_date)) {
|
||||
$weldingDateCheck = true;
|
||||
}
|
||||
$weldingDateChecks[] = $weldingDateCheck;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if($spoolList->iso_number == "PG-900-AH01PG-FA00.030-HC") {
|
||||
if($spoolList->no_of_the_joint_as_per_as_built_survey == "6-NEW") {
|
||||
dump($otherSpoolStatusCompletedCheck);
|
||||
dump($otherSpoolTypeOfJoint);
|
||||
dump($weldingDateChecks);
|
||||
dd($otherSpoolShopCheck);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(in_array(false, $weldingDateChecks) && in_array(true, $weldingDateChecks)) {
|
||||
$spoolStatus = "On Going";
|
||||
} else if(in_array(false, $weldingDateChecks) && !in_array(true, $weldingDateChecks)) {
|
||||
$spoolStatus = "Waiting";
|
||||
} else if(!in_array(false, $weldingDateChecks) && in_array(true, $weldingDateChecks)) {
|
||||
|
||||
if($spoolList->type_of_joint == "F") {
|
||||
if($otherSpoolStatusCompletedCheck && $otherSpoolShopCheck) {
|
||||
$spoolStatus = "Completed";
|
||||
} else {
|
||||
$spoolStatus = "Spool Release";
|
||||
}
|
||||
} else {
|
||||
if($filterPaintChanged) {
|
||||
$spoolStatus = "Completed";
|
||||
} else {
|
||||
$spoolStatus = "Spool Release";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($allSpoolIsField) {
|
||||
if($spoolList->painting_cycle != "") {
|
||||
$spoolStatus = "Paint";
|
||||
} else {
|
||||
$spoolStatus = "Completed";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
db("weld_logs")
|
||||
/*
|
||||
->where("iso_number", $isoNumber)
|
||||
->where("spool_number", $spoolNumber)
|
||||
*/
|
||||
->where("id", $spoolList->id)
|
||||
// ->whereNotIn("spool_status", ['NDT Release', 'Paint', 'Completed'])
|
||||
->update([
|
||||
'spool_status' => $spoolStatus,
|
||||
// 'spool_ndt_check' => null,
|
||||
// 'spool_ndt_check_no' => null,
|
||||
|
||||
]);
|
||||
|
||||
// Update construction_paint_logs table based on iso_drawings and spool
|
||||
// Sync spool_status from weld_logs to construction_paint_logs automatically
|
||||
|
||||
|
||||
$k++;
|
||||
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
*/
|
||||
$say++;
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
// dump($th);
|
||||
Log::error($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
$updatePaintQuery = db("weld_logs")
|
||||
->whereIn("spool_status", ["Completed", "NDT Release"])
|
||||
//painting cycle dolu ise
|
||||
->where(function($query) {
|
||||
$query->whereNotNull("painting_cycle")
|
||||
->orWhere("painting_cycle", "<>", "");
|
||||
})
|
||||
|
||||
//paint release date boş ise
|
||||
->where(function($query) {
|
||||
$query->whereNull("paint_release_date")
|
||||
->orWhere("paint_release_date", "");
|
||||
})
|
||||
|
||||
//ndt release date dolu ise
|
||||
->where(function($query) {
|
||||
$query->whereNotNull("ndt_release_date")
|
||||
->orWhere("ndt_release_date", "<>", "");
|
||||
});
|
||||
|
||||
if($filterIsoNumber) {
|
||||
$updatePaintQuery->where("iso_number", $filterIsoNumber);
|
||||
}
|
||||
|
||||
if($filterSpoolNumber) {
|
||||
$updatePaintQuery->where("spool_number", $filterSpoolNumber);
|
||||
}
|
||||
|
||||
$updatePaint = $updatePaintQuery->update([
|
||||
'spool_status' => "Paint"
|
||||
]);
|
||||
|
||||
$updateCompletedQuery = db("weld_logs")
|
||||
// ->whereIn("spool_status", ["Paint"])
|
||||
->where(function($query) {
|
||||
$query->whereNotNull("painting_cycle")
|
||||
->orWhere("painting_cycle", "<>", "");
|
||||
})
|
||||
->where(function($query) {
|
||||
$query->whereNotNull("paint_release_date")
|
||||
->orWhere("paint_release_date", "<>", "");
|
||||
})
|
||||
//ndt release date dolu ise
|
||||
->where(function($query) {
|
||||
$query->whereNotNull("ndt_release_date")
|
||||
->orWhere("ndt_release_date", "<>", "");
|
||||
});
|
||||
|
||||
if($filterIsoNumber) {
|
||||
$updateCompletedQuery->where("iso_number", $filterIsoNumber);
|
||||
}
|
||||
|
||||
if($filterSpoolNumber) {
|
||||
$updateCompletedQuery->where("spool_number", $filterSpoolNumber);
|
||||
}
|
||||
|
||||
$updateCompleted = $updateCompletedQuery->update([
|
||||
'spool_status' => "Completed"
|
||||
]);
|
||||
|
||||
//dump("$k processed");
|
||||
|
||||
// Performance monitoring - Start paint sync timing
|
||||
$paintSyncStartTime = microtime(true);
|
||||
|
||||
$statusLog = "$lastIdPrefix finish $k processed
|
||||
updateComplete $updateCompleted updatePaint $updatePaint " . simdi();
|
||||
// dump("Status Changer Affected Columns $k");
|
||||
Log::debug($statusLog . simdi());
|
||||
|
||||
// OPTIMIZED SOLUTION 1: Using JOIN with Window Function (Best Performance)
|
||||
$cteConditions = ["spool_status IS NOT NULL"];
|
||||
$cteParams = [];
|
||||
$whereConditions = [];
|
||||
$updateParams = [];
|
||||
|
||||
// Check for spool_number parameter (GET or variable)
|
||||
if(!getesit("spool_number", "") || isset($spool_number)) {
|
||||
$spoolNumberValue = !getesit("spool_number", "") ? get("spool_number") : $spool_number;
|
||||
$cteConditions[] = "spool_number = ?";
|
||||
$cteParams[] = $spoolNumberValue;
|
||||
$whereConditions[] = "cpl.spool = ?";
|
||||
$updateParams[] = $spoolNumberValue;
|
||||
}
|
||||
|
||||
// Check for line_number parameter (GET or variable)
|
||||
if(!getesit("iso_number", "") || isset($iso_number)) {
|
||||
$isoNumberValue = !getesit("iso_number", "") ? get("iso_number") : $iso_number;
|
||||
$cteConditions[] = "iso_number = ?";
|
||||
$cteParams[] = $isoNumberValue;
|
||||
$whereConditions[] = "cpl.iso_drawings = ?";
|
||||
$updateParams[] = $isoNumberValue;
|
||||
}
|
||||
|
||||
$cteWhereClause = "WHERE " . implode(" AND ", $cteConditions);
|
||||
|
||||
// Build WHERE clause for main query
|
||||
$whereClause = !empty($whereConditions) ? " WHERE " . implode(" AND ", $whereConditions) : "";
|
||||
|
||||
// Optimized query using CTE and Window Function (MySQL 8.0+)
|
||||
$sqlQuery = "
|
||||
WITH latest_weld_logs AS (
|
||||
SELECT
|
||||
iso_number,
|
||||
spool_number,
|
||||
spool_status,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY iso_number, spool_number
|
||||
ORDER BY updated_at DESC
|
||||
) as rn
|
||||
FROM weld_logs
|
||||
$cteWhereClause
|
||||
)
|
||||
UPDATE construction_paint_logs cpl
|
||||
INNER JOIN latest_weld_logs lwl ON (
|
||||
lwl.iso_number = cpl.iso_drawings
|
||||
AND lwl.spool_number = cpl.spool
|
||||
AND lwl.rn = 1
|
||||
)
|
||||
SET cpl.spool_status = lwl.spool_status" . $whereClause;
|
||||
|
||||
try {
|
||||
$allParams = array_merge($cteParams, $updateParams);
|
||||
if(!empty($allParams)) {
|
||||
DB::statement($sqlQuery, $allParams);
|
||||
} else {
|
||||
DB::statement($sqlQuery);
|
||||
}
|
||||
Log::info("Paint logs sync completed successfully using optimized CTE query");
|
||||
} catch (\Exception $e) {
|
||||
Log::warning("CTE query failed, falling back to batch processing: " . $e->getMessage());
|
||||
|
||||
// FALLBACK SOLUTION: Batch Processing for MySQL < 8.0 or large datasets
|
||||
$batchSize = 1000;
|
||||
$offset = 0;
|
||||
$totalUpdated = 0;
|
||||
|
||||
do {
|
||||
// Get latest spool status for each iso_number + spool_number combination
|
||||
$latestStatuses = DB::table('weld_logs as wl1')
|
||||
->select('wl1.iso_number', 'wl1.spool_number', 'wl1.spool_status')
|
||||
->leftJoin('weld_logs as wl2', function($join) {
|
||||
$join->on('wl1.iso_number', '=', 'wl2.iso_number')
|
||||
->on('wl1.spool_number', '=', 'wl2.spool_number')
|
||||
->whereRaw('wl1.updated_at < wl2.updated_at');
|
||||
})
|
||||
->whereNull('wl2.id')
|
||||
->whereNotNull('wl1.spool_status')
|
||||
->when($filterIsoNumber, function($query) use ($filterIsoNumber) {
|
||||
return $query->where('wl1.iso_number', $filterIsoNumber);
|
||||
})
|
||||
->when($filterSpoolNumber, function($query) use ($filterSpoolNumber) {
|
||||
return $query->where('wl1.spool_number', $filterSpoolNumber);
|
||||
})
|
||||
->limit($batchSize)
|
||||
->offset($offset)
|
||||
->get();
|
||||
|
||||
if($latestStatuses->isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Batch update construction_paint_logs
|
||||
foreach($latestStatuses as $status) {
|
||||
$updateQuery = DB::table('construction_paint_logs')
|
||||
->where('iso_drawings', $status->iso_number)
|
||||
->where('spool', $status->spool_number);
|
||||
|
||||
if($filterIsoNumber) {
|
||||
$updateQuery->where('iso_drawings', $filterIsoNumber);
|
||||
}
|
||||
|
||||
if($filterSpoolNumber) {
|
||||
$updateQuery->where('spool', $filterSpoolNumber);
|
||||
}
|
||||
|
||||
$updated = $updateQuery->update(['spool_status' => $status->spool_status]);
|
||||
$totalUpdated += $updated;
|
||||
}
|
||||
|
||||
$offset += $batchSize;
|
||||
|
||||
// Memory cleanup
|
||||
unset($latestStatuses);
|
||||
|
||||
} while (true);
|
||||
|
||||
Log::info("Paint logs sync completed using batch processing. Total updated: $totalUpdated");
|
||||
}
|
||||
|
||||
// Performance monitoring - End timing and log results
|
||||
$paintSyncEndTime = microtime(true);
|
||||
$paintSyncDuration = round($paintSyncEndTime - $paintSyncStartTime, 2);
|
||||
|
||||
// Log performance metrics
|
||||
$performanceLog = [
|
||||
'operation' => 'paint_logs_sync',
|
||||
'duration_seconds' => $paintSyncDuration,
|
||||
'weld_logs_processed' => $k,
|
||||
'paint_updates' => $updatePaint,
|
||||
'completed_updates' => $updateCompleted,
|
||||
'memory_usage_mb' => round(memory_get_peak_usage() / 1024 / 1024, 2),
|
||||
'timestamp' => simdi()
|
||||
];
|
||||
|
||||
Log::info("Performance metrics for spool status sync: " . json_encode($performanceLog));
|
||||
|
||||
// Alert if performance is degraded (> 30 seconds for paint sync)
|
||||
if($paintSyncDuration > 30) {
|
||||
Log::warning("Paint sync performance degraded - took {$paintSyncDuration} seconds. Consider database maintenance or optimization.");
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
$supports = db("supports");
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$supports = $supports->where("id", $id);
|
||||
}
|
||||
|
||||
$supports = $supports->get();
|
||||
$k = 0;
|
||||
foreach($supports AS $data)
|
||||
{
|
||||
$uniqueFields = [
|
||||
'line' => $data->line_number,
|
||||
'component_code_id' => $data->support_code,
|
||||
];
|
||||
|
||||
|
||||
$data = [
|
||||
'project' => $data->zone,
|
||||
'discipline' => 'Piping Support',
|
||||
'line' => $data->line_number,
|
||||
'rev' => $data->rev,
|
||||
'component_code_id' => $data->support_code,
|
||||
// 'longdescription' => $data->line_number,
|
||||
// 'description_en' => $data->line_number,
|
||||
'description_ru' => $data->erection_materials_name,
|
||||
'manufacturing_standard' => $data->standart,
|
||||
'material' => $data->materials,
|
||||
// 'material_quality_standard' => $data->line_number,
|
||||
'quantity' => $data->quantity,
|
||||
// 'dia_inch_1' => $data->line_number,
|
||||
// 'dn_1' => $data->line_number,
|
||||
'odmm_1' => $data->welded_pad_measure,
|
||||
// 'schedule_1' => $data->line_number,
|
||||
'thicknessmm_1' => $data->thickness,
|
||||
// 'diainch_2' => $data->line_number,
|
||||
// 'dn_2' => $data->line_number,
|
||||
// 'odmm_2' => $data->line_number,
|
||||
// 'schedule_2' => $data->line_number,
|
||||
// 'thicknessmm_2' => $data->line_number,
|
||||
// 'pn_mpa' => $data->line_number,
|
||||
'weight' => $data->unit_weight,
|
||||
'total_weight' => $data->quantity * $data->unit_weight,
|
||||
'designer' => $data->designer,
|
||||
];
|
||||
|
||||
|
||||
$k += db('m_t_o_s')->updateOrInsert($uniqueFields, $data);
|
||||
|
||||
}
|
||||
|
||||
//dump("$k data sync from supports ==> mtos");
|
||||
Log::debug("$k data sync from supports to mtos");
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$output = shell_exec('php artisan telescope:prune --hours=1');
|
||||
Log::debug($output);
|
||||
//dump($output);
|
||||
?>
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
try {
|
||||
// ============================================================
|
||||
// SECTION 1: Clean empty/null test_package_number records
|
||||
// ============================================================
|
||||
|
||||
// Delete test_packages with empty or null test_package_number
|
||||
$emptyTestPackages = DB::table('test_packages')
|
||||
->where(function($query) {
|
||||
$query->where('test_package_number', '')
|
||||
->orWhereNull('test_package_number');
|
||||
})
|
||||
->where(function($query) {
|
||||
$query->where('is_manual', 0)
|
||||
->orWhereNull('is_manual');
|
||||
})
|
||||
->whereNull('test_date')
|
||||
->whereNull('reinstatement_date')
|
||||
->whereNull('cleaning_blowing_drying_date')
|
||||
->delete();
|
||||
|
||||
Log::info("Deleted empty test_package_number records", [
|
||||
'deleted_count' => $emptyTestPackages,
|
||||
'table' => 'test_packages'
|
||||
]);
|
||||
|
||||
// Delete test_pack_base_statuses with empty or null fields
|
||||
$emptyBaseStatuses = DB::table('test_pack_base_statuses')
|
||||
->where(function($query) {
|
||||
$query->where('test_package_no', '')
|
||||
->orWhereNull('test_package_no')
|
||||
->orWhere('drawing_no', '')
|
||||
->orWhereNull('drawing_no');
|
||||
})
|
||||
->where(function($query) {
|
||||
$query->where('is_manual', 0)
|
||||
->orWhereNull('is_manual');
|
||||
})
|
||||
->delete();
|
||||
|
||||
Log::info("Deleted empty field records", [
|
||||
'deleted_count' => $emptyBaseStatuses,
|
||||
'table' => 'test_pack_base_statuses'
|
||||
]);
|
||||
|
||||
// ============================================================
|
||||
// SECTION 2: Delete non-matching records (not in weld_logs)
|
||||
// ============================================================
|
||||
|
||||
// Find test_package_no not in weld_logs
|
||||
$nonMatchingTestPackages = DB::table('test_packages as tp')
|
||||
->leftJoin('weld_logs as wl', function($join) {
|
||||
$join->on('tp.test_package_number', '=', 'wl.test_package_no')
|
||||
->whereNotNull('wl.test_package_no')
|
||||
->where('wl.test_package_no', '!=', ''); // Exclude empty strings
|
||||
})
|
||||
->whereNull('wl.test_package_no')
|
||||
->whereNotNull('tp.test_package_number') // Ensure test_package_number is not null
|
||||
->where('tp.test_package_number', '!=', '') // Exclude empty test_package_number
|
||||
->where(function($query) {
|
||||
$query->where('tp.is_manual', 0)
|
||||
->orWhereNull('tp.is_manual');
|
||||
})
|
||||
->whereNull('tp.test_date')
|
||||
->whereNull('tp.reinstatement_date')
|
||||
->whereNull('tp.cleaning_blowing_drying_date')
|
||||
->pluck('tp.test_package_number')
|
||||
->toArray();
|
||||
|
||||
// Filter out null and empty values from the array
|
||||
$nonMatchingTestPackages = array_filter($nonMatchingTestPackages, function($value) {
|
||||
return !empty($value) && $value !== null && trim($value) !== '';
|
||||
});
|
||||
|
||||
// Aşama 2: Bulunan test_package_no'ları sil
|
||||
if (!empty($nonMatchingTestPackages)) {
|
||||
Log::info("Deleting non-matching test packages", [
|
||||
'count' => count($nonMatchingTestPackages),
|
||||
'packages' => array_slice($nonMatchingTestPackages, 0, 5) // Log first 5 for debugging
|
||||
]);
|
||||
|
||||
$TPresult = DB::table('test_packages')
|
||||
->whereIn('test_package_number', $nonMatchingTestPackages)
|
||||
->delete();
|
||||
|
||||
Log::info("Test packages deleted", ['deleted_count' => $TPresult]);
|
||||
} else {
|
||||
$TPresult = 0;
|
||||
Log::debug("No non-matching test packages found to delete");
|
||||
}
|
||||
|
||||
// Aşama 1: test_pack_base_statuses için weld_logs'da olmayan kayıtları bul
|
||||
$nonMatchingBaseStatuses = DB::table('test_pack_base_statuses as tpbs')
|
||||
->leftJoin('weld_logs as wl', function($join) {
|
||||
$join->on('tpbs.drawing_no', '=', 'wl.iso_number')
|
||||
->on('tpbs.test_package_no', '=', 'wl.test_package_no')
|
||||
->whereNotNull('wl.test_package_no')
|
||||
->where('wl.test_package_no', '!=', ''); // Exclude empty strings
|
||||
})
|
||||
->leftJoin('test_packages as tp', 'tpbs.test_package_no', '=', 'tp.test_package_number')
|
||||
->whereNull('wl.test_package_no')
|
||||
->whereNotNull('tpbs.test_package_no') // Ensure test_package_no is not null
|
||||
->where('tpbs.test_package_no', '!=', '') // Exclude empty test_package_no
|
||||
->whereNotNull('tpbs.drawing_no') // Ensure drawing_no is not null
|
||||
->where('tpbs.drawing_no', '!=', '') // Exclude empty drawing_no
|
||||
->where(function($query) {
|
||||
$query->where('tpbs.is_manual', 0)
|
||||
->orWhereNull('tpbs.is_manual');
|
||||
})
|
||||
->where(function($query) {
|
||||
$query->whereNull('tp.test_date')
|
||||
->whereNull('tp.reinstatement_date')
|
||||
->whereNull('tp.cleaning_blowing_drying_date');
|
||||
})
|
||||
->pluck('tpbs.id')
|
||||
->toArray();
|
||||
|
||||
// Filter out null values from the array
|
||||
$nonMatchingBaseStatuses = array_filter($nonMatchingBaseStatuses, function($value) {
|
||||
return $value !== null && is_numeric($value) && $value > 0;
|
||||
});
|
||||
|
||||
// Aşama 2: Bulunan kayıtları sil
|
||||
if (!empty($nonMatchingBaseStatuses)) {
|
||||
Log::info("Deleting non-matching test pack base statuses", [
|
||||
'count' => count($nonMatchingBaseStatuses),
|
||||
'ids' => array_slice($nonMatchingBaseStatuses, 0, 5) // Log first 5 for debugging
|
||||
]);
|
||||
|
||||
$TPISOresult = DB::table('test_pack_base_statuses')
|
||||
->whereIn('id', $nonMatchingBaseStatuses)
|
||||
->delete();
|
||||
|
||||
Log::info("Test pack base statuses deleted", ['deleted_count' => $TPISOresult]);
|
||||
} else {
|
||||
$TPISOresult = 0;
|
||||
Log::debug("No non-matching test pack base statuses found to delete");
|
||||
}
|
||||
|
||||
Log::info("Test pack cleanup completed successfully", [
|
||||
'empty_test_packages_deleted' => $emptyTestPackages ?? 0,
|
||||
'empty_base_statuses_deleted' => $emptyBaseStatuses ?? 0,
|
||||
'non_matching_test_packages_deleted' => $TPresult ?? 0,
|
||||
'non_matching_base_statuses_deleted' => $TPISOresult ?? 0,
|
||||
'total_deleted' => ($emptyTestPackages ?? 0) + ($emptyBaseStatuses ?? 0) + ($TPresult ?? 0) + ($TPISOresult ?? 0)
|
||||
]);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("Error in weld_logs-delete-non-matching-test-pack-statuses", [
|
||||
'error' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' => $th->getLine(),
|
||||
'trace' => $th->getTraceAsString()
|
||||
]);
|
||||
// Don't throw - this is a cleanup operation and should not break the main flow
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
use App\Models\NdeMatrix;
|
||||
$lastIdPrefix = "weld-logs-empty-sync";
|
||||
$lastId = 0;
|
||||
|
||||
if(Cache::has($lastIdPrefix)) {
|
||||
$lastId = Cache::get($lastIdPrefix);
|
||||
}
|
||||
|
||||
//dump("$lastIdPrefix $lastId");
|
||||
|
||||
Log::debug("$lastIdPrefix start " . simdi());
|
||||
$ndeMatrixs = NdeMatrix::whereDate("updated_at", ">=", $oneMinuteAgo)->get();
|
||||
|
||||
|
||||
$ndeDatas = [];
|
||||
|
||||
foreach($ndeMatrixs AS $ndeMatrix) {
|
||||
$ndeDatas[$ndeMatrix->line][$ndeMatrix->type_of_joint] = [
|
||||
'rt_scope' => $ndeMatrix->rt,
|
||||
'ut_scope' => $ndeMatrix->ut,
|
||||
'mt_scope' => $ndeMatrix->mt,
|
||||
'pt_scope' => $ndeMatrix->pt,
|
||||
'pmi_scope' => $ndeMatrix->pmi,
|
||||
'ht_scope' => $ndeMatrix->ht,
|
||||
'pwht' => $ndeMatrix->pwht,
|
||||
'ferrite_scope' => $ndeMatrix->fn,
|
||||
'ndt_percent' => $ndeMatrix->ndt,
|
||||
];
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$weldLogs = db("weld_logs")->whereNull("ndt_percent")->groupBy("line_number", "type_of_welds")->get();
|
||||
$count = 0;
|
||||
$say = 0;
|
||||
try {
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
|
||||
if(isset($ndeDatas[$weldLog->line_number][$weldLog->type_of_welds])) {
|
||||
$updateData = $ndeDatas[$weldLog->line_number][$weldLog->type_of_welds];
|
||||
db("weld_logs")
|
||||
->where("line_number", $weldLog->line_number)
|
||||
->where("type_of_welds", $weldLog->type_of_welds)
|
||||
->update($updateData);
|
||||
$count++;
|
||||
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
*/
|
||||
$say++;
|
||||
}
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
//dump($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
Log::debug("$lastIdPrefix finish " . simdi());
|
||||
//dump("$count weldlog data is updated");
|
||||
?>
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
|
||||
//dump("$lastIdPrefix $lastId");
|
||||
|
||||
//dump($saat);
|
||||
|
||||
//if($saat == "00:00") {
|
||||
$materials = db("materials")->where("steel_grade", "<>", "*")->whereNotNull("steel_grade")->get();
|
||||
$materialMap = [];
|
||||
$productRuMap = [];
|
||||
foreach($materials AS $material) {
|
||||
$material->steel_grade = trim($material->steel_grade);
|
||||
$materialMap[$material->steel_grade] = $material->ru_group;
|
||||
$productRuMap[$material->steel_grade] = $material->product_standart;
|
||||
}
|
||||
|
||||
|
||||
function whatMaterialGroup($thisSteelGrade, $materialMap) {
|
||||
|
||||
if(isset($materialMap[$thisSteelGrade]))
|
||||
{
|
||||
return $materialMap[$thisSteelGrade];
|
||||
} else {
|
||||
foreach($materialMap AS $steelGrade => $group) {
|
||||
$similar = similar_text($steelGrade, $thisSteelGrade, $percentage);
|
||||
|
||||
if($percentage > 95) {
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function whatMaterialRuGroup($thisSteelGrade, $productRuMap) {
|
||||
|
||||
if(isset($materialMap[$thisSteelGrade]))
|
||||
{
|
||||
return $materialMap[$thisSteelGrade];
|
||||
} else {
|
||||
foreach($materialMap AS $steelGrade => $group) {
|
||||
$similar = similar_text($steelGrade, $thisSteelGrade, $percentage);
|
||||
|
||||
if($percentage > 95) {
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$weldmaps = db("weld_logs")
|
||||
/*
|
||||
->where(function($query){
|
||||
$query->orWhereNull("ru_material_group_1");
|
||||
$query->orWhereNull("ru_material_group_2");
|
||||
$query->orWhere("ru_material_group_1", "");
|
||||
$query->orWhere("ru_material_group_2", "");
|
||||
$query->orWhere("ru_material_group_1","*");
|
||||
$query->orWhere("ru_material_group_2","*");
|
||||
})
|
||||
->where("id",">", $lastId)
|
||||
->take(setting('cron_job_batch_process_count'))
|
||||
*/
|
||||
->get();
|
||||
|
||||
|
||||
//dump("weldmaps count");
|
||||
//dump($weldmaps->count());
|
||||
$materialGroupUpdateCount = 0;
|
||||
$say = 0;
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
foreach($weldmaps AS $weldmap) {
|
||||
$weldmap->material_no_1 = trim($weldmap->material_no_1);
|
||||
$group1 = whatMaterialGroup($weldmap->material_no_1, $materialMap); //isset($materialMap[$weldmap->material_no_1]) ? $materialMap[$weldmap->material_no_1] : "";
|
||||
$group2 = whatMaterialGroup($weldmap->material_no_2, $materialMap); //isset($materialMap[$weldmap->material_no_2]) ? $materialMap[$weldmap->material_no_2] : "";
|
||||
|
||||
$ruGroup1 = whatMaterialGroup($weldmap->material_no_1, $productRuMap); //isset($materialMap[$weldmap->material_no_1]) ? $materialMap[$weldmap->material_no_1] : "";
|
||||
$ruGroup2 = whatMaterialGroup($weldmap->material_no_2, $productRuMap); //isset($materialMap[$weldmap->material_no_2]) ? $materialMap[$weldmap->material_no_2] : "";
|
||||
|
||||
$updateData = [
|
||||
"ru_material_group_1" => $group1,
|
||||
"ru_material_group_2" => $group2,
|
||||
/*
|
||||
"product_standart_1" => $ruGroup1,
|
||||
"product_standart_2" => $ruGroup2
|
||||
*/
|
||||
];
|
||||
|
||||
|
||||
$materialGroupUpdateCount += db("weld_logs")
|
||||
->where("id", $weldmap->id)
|
||||
->update($updateData);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
|
||||
|
||||
if($weldmap->material_no_1 == "12Х18Н10Т") {
|
||||
dd($group1);
|
||||
}
|
||||
*/
|
||||
$say++;
|
||||
|
||||
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
dump($th->getMessage());
|
||||
DB::rollback();
|
||||
|
||||
}
|
||||
|
||||
//dump("$materialGroupUpdateCount material group update");
|
||||
Log::debug("$materialGroupUpdateCount material group update");
|
||||
//}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
$result = DB::table('weld_logs')
|
||||
->join('document_revisions', 'weld_logs.iso_number', '=', 'document_revisions.drawing_no')
|
||||
->where(function ($query) {
|
||||
$query->whereNull('weld_logs.iso_rev')
|
||||
->orWhere('weld_logs.iso_rev', ''); // iso_rev null veya boş olanlar
|
||||
})
|
||||
->update([
|
||||
'weld_logs.project' => DB::raw('document_revisions.zone'),
|
||||
'weld_logs.design_area' => DB::raw('document_revisions.area'),
|
||||
'weld_logs.iso_rev' => DB::raw('document_revisions.revision_no'),
|
||||
'weld_logs.line_number' => DB::raw('document_revisions.line_number'),
|
||||
]);
|
||||
|
||||
dump("Update WeldLogs from Document Revisions row count: $result");
|
||||
?>
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
use App\Models\PaintMatrix;
|
||||
use App\Models\WeldLog;
|
||||
use App\Models\PaintFollowUp;
|
||||
|
||||
$prefix = "sync-from-weldlog-to-paint-follow-up";
|
||||
|
||||
$weldLogs = apply_welded_filter(
|
||||
db("weld_logs")
|
||||
->where("no_of_the_joint_as_per_as_built_survey", "not like", "%clone%")
|
||||
);
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$weldLogs = $weldLogs->where("id", $id);
|
||||
}
|
||||
|
||||
$weldLogs = $weldLogs
|
||||
->get();
|
||||
|
||||
|
||||
|
||||
$paintMatrices = PaintMatrix:://groupBy("line", "fluid_code")->
|
||||
get();
|
||||
|
||||
Log::debug("$prefix Start " . simdi());
|
||||
|
||||
$spoolDatas = [];
|
||||
$jointDatas = [];
|
||||
$datas = [];
|
||||
$deletedJoints= [];
|
||||
|
||||
$lineStats = [];
|
||||
$processedLines = [];
|
||||
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
$lineKey = $weldLog->line_number . '_' . $weldLog->fluid_code;
|
||||
|
||||
if(!isset($lineStats[$lineKey])) {
|
||||
$lineStats[$lineKey] = [
|
||||
's_count' => 0,
|
||||
'f_count' => 0,
|
||||
'total' => 0
|
||||
];
|
||||
}
|
||||
|
||||
if($weldLog->type_of_joint === 'S') {
|
||||
$lineStats[$lineKey]['s_count']++;
|
||||
} else if($weldLog->type_of_joint === 'F') {
|
||||
$lineStats[$lineKey]['f_count']++;
|
||||
}
|
||||
$lineStats[$lineKey]['total']++;
|
||||
|
||||
// First, check if this line has any 'S' type joints
|
||||
$hasSType = false;
|
||||
foreach($weldLogs as $checkLog) {
|
||||
if($checkLog->line_number === $weldLog->line_number &&
|
||||
$checkLog->fluid_code === $weldLog->fluid_code &&
|
||||
$checkLog->type_of_joint === 'S') {
|
||||
$hasSType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Only proceed if we found an 'S' type joint for this line
|
||||
if($hasSType) {
|
||||
if(!isset($processedLines[$lineKey])) {
|
||||
// Log::debug("$prefix Line {$weldLog->line_number} ve Fluid Code {$weldLog->fluid_code} için işlem başladı. S tipi kayıt bulundu.");
|
||||
$processedLines[$lineKey] = true;
|
||||
}
|
||||
|
||||
$spoolDatas[$weldLog->line_number][$weldLog->fluid_code][] = [
|
||||
'spool_no_joint_no' => $weldLog->spool_number,
|
||||
'fluid_code' => $weldLog->fluid_code,
|
||||
'iso_number' => $weldLog->iso_number,
|
||||
'line' => $weldLog->line_number,
|
||||
];
|
||||
|
||||
$jointNo = $weldLog->no_of_the_joint_as_per_as_built_survey;
|
||||
|
||||
$jointType = "Normal";
|
||||
if(strpos($jointNo, "R") !== false) {
|
||||
$jointType = "Repair";
|
||||
$otherJointNo = deleteAfterR($jointNo);
|
||||
$deletedJoints[] = $otherJointNo;
|
||||
// Log::debug("$prefix Onarım tipi kayıt bulundu: $jointNo -> $otherJointNo");
|
||||
}
|
||||
|
||||
$jointDatas[$weldLog->line_number][$weldLog->fluid_code][] = [
|
||||
'spool_no_joint_no' => $weldLog->no_of_the_joint_as_per_as_built_survey,
|
||||
'fluid_code' => $weldLog->fluid_code,
|
||||
'iso_number' => $weldLog->iso_number,
|
||||
'line' => $weldLog->line_number,
|
||||
];
|
||||
} else {
|
||||
if(!isset($processedLines[$lineKey])) {
|
||||
Log::debug("$prefix Line {$weldLog->line_number} ve Fluid Code {$weldLog->fluid_code} için S tipi kayıt bulunamadı, kayıtlar eklenmeyecek.");
|
||||
$processedLines[$lineKey] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log line statistics
|
||||
foreach($lineStats as $lineKey => $stats) {
|
||||
list($line, $fluid) = explode('_', $lineKey);
|
||||
Log::debug("$prefix Line $line ve Fluid Code $fluid için istatistikler:");
|
||||
Log::debug("$prefix - Toplam kayıt: {$stats['total']}");
|
||||
Log::debug("$prefix - S tipi kayıt: {$stats['s_count']}");
|
||||
Log::debug("$prefix - F tipi kayıt: {$stats['f_count']}");
|
||||
}
|
||||
|
||||
foreach($deletedJoints AS $deleteJoint) {
|
||||
removeItemBySpoolNoJointNo($jointDatas, $deleteJoint);
|
||||
}
|
||||
|
||||
|
||||
foreach($paintMatrices AS $paintMatrix) {
|
||||
|
||||
$thisData = [
|
||||
'project' => $paintMatrix->project,
|
||||
'description' => $paintMatrix->description,
|
||||
'area' => $paintMatrix->area,
|
||||
'cycle' => $paintMatrix->paint_cycle,
|
||||
'primer_coat_name_1' => $paintMatrix->primer_coat,
|
||||
'ral_code_1' => $paintMatrix->ral_code_1,
|
||||
'colour_1' => $paintMatrix->colour_1,
|
||||
'colour_2' => $paintMatrix->colour_2,
|
||||
'colour_3' => $paintMatrix->colour_3,
|
||||
'brend_name_1' => $paintMatrix->brend_name_1,
|
||||
'brend_name_2' => $paintMatrix->brend_name_2,
|
||||
'brend_name_3' => $paintMatrix->brend_name_3,
|
||||
'thickness_1' => $paintMatrix->thickness_1,
|
||||
'intermediate_coat_name_2' => $paintMatrix->intermediate_coat,
|
||||
'ral_code_2' => $paintMatrix->ral_code_2,
|
||||
'thickness_2' => $paintMatrix->thickness_2,
|
||||
'final_coat_name_3' => $paintMatrix->final_coat,
|
||||
'ral_code_3' => $paintMatrix->ral_code_3,
|
||||
'thickness_3' => $paintMatrix->thickness_3,
|
||||
'total_thickness' => $paintMatrix->total_thickness ?? 0,
|
||||
];
|
||||
|
||||
if(isset($spoolDatas[$paintMatrix->line][$paintMatrix->fluid_code])) {
|
||||
foreach($spoolDatas[$paintMatrix->line][$paintMatrix->fluid_code] AS $spoolData) {
|
||||
$thisData['location'] = "SHOP";
|
||||
$mergedData = array_merge($spoolData, $thisData);
|
||||
|
||||
$datas[$paintMatrix->line][$paintMatrix->fluid_code][] = $mergedData;
|
||||
}
|
||||
}
|
||||
if(isset($jointDatas[$paintMatrix->line][$paintMatrix->fluid_code])) {
|
||||
foreach($jointDatas[$paintMatrix->line][$paintMatrix->fluid_code] AS $jointData) {
|
||||
$thisData['location'] = "FIELD";
|
||||
$mergedData = array_merge($jointData, $thisData);
|
||||
$datas[$paintMatrix->line][$paintMatrix->fluid_code][] = $mergedData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$k = 0;
|
||||
$say = 0;
|
||||
try {
|
||||
foreach($datas AS $line => $data) {
|
||||
foreach($data AS $fluid_code => $updateDatas) {
|
||||
|
||||
foreach($updateDatas AS $updateData) {
|
||||
$whereData = [
|
||||
'fluid_code' => $fluid_code,
|
||||
'spool_no_joint_no' => $updateData['spool_no_joint_no'],
|
||||
'line' => $line,
|
||||
];
|
||||
// //dump($updateData);
|
||||
PaintFollowUp::updateOrCreate($whereData, $updateData);
|
||||
$k++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($say == $commitSize) {
|
||||
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
}
|
||||
$say++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
//dump("$k Data has been sync WeldLog ==> Paint Follow Up (update or create)");
|
||||
Log::debug("$k data update Or Create");
|
||||
|
||||
Log::debug("$prefix Finish " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,592 @@
|
||||
<?php
|
||||
use App\Models\TestPackage;
|
||||
use App\Models\PunchList;
|
||||
use App\Models\TestPackBaseStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
$cachePrefix = 'sync-from-weldlog-to-test-pack';
|
||||
$weldLogs = db("weld_logs")->orderBy("test_package_no", "DESC");
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$weldLogs = $weldLogs->where("id", $id);
|
||||
}
|
||||
|
||||
if(isset($test_package_no))
|
||||
{
|
||||
Log::info("specitif test_package_no run: " . $test_package_no);
|
||||
$weldLogs = $weldLogs->where("test_package_no", $test_package_no);
|
||||
}
|
||||
|
||||
|
||||
$weldLogs = $weldLogs->get();
|
||||
$repairLogs = db("repair_logs");
|
||||
if(isset($test_package_no))
|
||||
{
|
||||
$repairLogs = $repairLogs->where("test_package_no", $test_package_no);
|
||||
}
|
||||
$repairLogs = $repairLogs->get();
|
||||
$supports = db("supports");
|
||||
$supports = $supports->get();
|
||||
|
||||
$punchLists = db("punch_lists");
|
||||
if(isset($test_package_no))
|
||||
{
|
||||
$punchLists = $punchLists->where("test_package", $test_package_no);
|
||||
}
|
||||
$punchLists = $punchLists->get();
|
||||
|
||||
$logTypes = array_keys(log_test_types());
|
||||
$repairDatas = [];
|
||||
|
||||
if(!isset($commitSize))
|
||||
{
|
||||
$commitSize = $weldLogs->count();
|
||||
}
|
||||
|
||||
foreach($repairLogs AS $repairLog)
|
||||
{
|
||||
if(!isset($repairDatas[$repairLog->iso_number]))
|
||||
$repairDatas[$repairLog->iso_number] = 0;
|
||||
|
||||
if($repairLog->repair_status == "Not Done" || trim($repairLog->repair_status) == "")
|
||||
{
|
||||
$repairDatas[$repairLog->iso_number]++;
|
||||
}
|
||||
}
|
||||
|
||||
$isoToTP = db("weld_logs")->select('test_package_no', 'line_number');
|
||||
if(isset($test_package_no))
|
||||
{
|
||||
$isoToTP = $isoToTP->where("test_package_no", $test_package_no);
|
||||
}
|
||||
$isoToTP = $isoToTP ->pluck('test_package_no', 'line_number');
|
||||
|
||||
$supportStats = [];
|
||||
$supportStatsTP = [];
|
||||
|
||||
foreach($supports AS $support)
|
||||
{
|
||||
$tpNo = @$isoToTP[$support->line_number];
|
||||
|
||||
if(!isset($supportStatsTP[$tpNo]['support_remaining']))
|
||||
{
|
||||
$supportStatsTP[$tpNo]['support_remaining'] = 0;
|
||||
$supportStatsTP[$tpNo]['welded_support_quantity'] = 0;
|
||||
$supportStatsTP[$tpNo]['support_progress'] = 0;
|
||||
}
|
||||
|
||||
if(!isset($supportStats[$support->line_number]['support_remaining']))
|
||||
$supportStats[$support->line_number]['support_remaining'] = 0;
|
||||
|
||||
if(!isset($supportStats[$support->line_number]['welded_support_quantity']))
|
||||
$supportStats[$support->line_number]['welded_support_quantity'] = 0;
|
||||
|
||||
if(!isset($supportStats[$support->line_number]['support_progress']))
|
||||
$supportStats[$support->line_number]['support_progress'] = 0;
|
||||
|
||||
if(!rejected_date($support->weld_or_assembled_date) && $support->erection_type == "Weld")
|
||||
{
|
||||
$supportStats[$support->line_number]['welded_support_quantity']+= $support->quantity;
|
||||
$supportStatsTP[$tpNo]['welded_support_quantity']+= $support->quantity;
|
||||
} else {
|
||||
$supportStats[$support->line_number]['support_remaining']+= $support->quantity;
|
||||
$supportStatsTP[$tpNo]['support_remaining']+= $support->quantity;
|
||||
}
|
||||
|
||||
if($supportStats[$support->line_number]['welded_support_quantity'] > 0) {
|
||||
$supportStats[$support->line_number]['support_progress'] =
|
||||
100 - ($supportStats[$support->line_number]['support_remaining'] * 100) /
|
||||
($supportStats[$support->line_number]['welded_support_quantity'] + $supportStats[$support->line_number]['support_remaining']);
|
||||
} else {
|
||||
$supportStats[$support->line_number]['support_progress'] = 0; // Eğer welded_support_quantity sıfırsa
|
||||
}
|
||||
|
||||
if($supportStatsTP[$tpNo]['welded_support_quantity'] > 0) {
|
||||
$supportStatsTP[$tpNo]['support_progress'] =
|
||||
100 - ($supportStatsTP[$tpNo]['support_remaining'] * 100) /
|
||||
($supportStatsTP[$tpNo]['welded_support_quantity'] + $supportStatsTP[$tpNo]['support_remaining']);
|
||||
} else {
|
||||
$supportStatsTP[$tpNo]['support_progress'] = 0; // Eğer welded_support_quantity sıfırsa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$testTypeToMedium = [
|
||||
'PNEUMATIC' => 'Air',
|
||||
'HYDRAULIC' => 'Water',
|
||||
'VISUAL' => '-',
|
||||
'ACUISTIC' => '-',
|
||||
];
|
||||
|
||||
Log::debug("$cachePrefix start " . simdi());
|
||||
|
||||
TestPackage::where(function($query) {
|
||||
$query->where("test_package_number", "")->orWhereNull("test_package_number");
|
||||
})->where(function($query) {
|
||||
$query->where("is_manual", 0)->orWhereNull("is_manual");
|
||||
})->delete();
|
||||
|
||||
TestPackBaseStatus::where(function($query) {
|
||||
$query->where("test_package_no", "")->orWhereNull("test_package_no");
|
||||
})->where(function($query) {
|
||||
$query->where("is_manual", 0)->orWhereNull("is_manual");
|
||||
})->delete();
|
||||
|
||||
$count = 0;
|
||||
$say = 0;
|
||||
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
|
||||
|
||||
$stats = [];
|
||||
$quantity_of_iso = [];
|
||||
$punchListNumbers = [];
|
||||
foreach($punchLists AS $punchList) {
|
||||
$drawingNo = $punchList->line_isometric_no;
|
||||
|
||||
if(!isset($stats[$drawingNo][$punchList->test_package]['punch_a_quantity']))
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_a_quantity'] = 0;
|
||||
|
||||
if(!isset($stats[$drawingNo][$punchList->test_package]['punch_b_quantity']))
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_b_quantity'] = 0;
|
||||
|
||||
if(!isset($stats[$drawingNo][$punchList->test_package]['punch_c_quantity']))
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_c_quantity'] = 0;
|
||||
|
||||
if(!isset($punchListNumbers[$punchList->test_package]))
|
||||
$punchListNumbers[$punchList->test_package] = [];
|
||||
|
||||
if(!in_array($punchList->punch_list_no, $punchListNumbers[$punchList->test_package]))
|
||||
$punchListNumbers[$punchList->test_package][] = $punchList->punch_list_no;
|
||||
|
||||
if(!isset($stats[$punchList->test_package]['punch_a_open_quantity']))
|
||||
$stats[$punchList->test_package]['punch_a_open_quantity'] = 0;
|
||||
|
||||
if(!isset($stats[$punchList->test_package]['punch_b_open_quantity']))
|
||||
$stats[$punchList->test_package]['punch_b_open_quantity'] = 0;
|
||||
|
||||
if(!isset($stats[$punchList->test_package]['punch_c_open_quantity']))
|
||||
$stats[$punchList->test_package]['punch_c_open_quantity'] = 0;
|
||||
|
||||
|
||||
if($punchList->category == "A") {
|
||||
if($punchList->status == "Open") {
|
||||
$stats[$punchList->test_package]['punch_a_open_quantity']++;
|
||||
}
|
||||
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_a_quantity']++;
|
||||
}
|
||||
|
||||
|
||||
if($punchList->category == "B") {
|
||||
if($punchList->status == "Open") {
|
||||
$stats[$punchList->test_package]['punch_b_open_quantity']++;
|
||||
}
|
||||
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_b_quantity']++;
|
||||
}
|
||||
|
||||
|
||||
if($punchList->category == "C") {
|
||||
if($punchList->status == "Open") {
|
||||
$stats[$punchList->test_package]['punch_c_open_quantity']++;
|
||||
}
|
||||
$stats[$drawingNo][$punchList->test_package]['punch_c_quantity']++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
$stats[$punchList->test_package]['found_date'] = $punchList?->found_date ?? "";
|
||||
$stats[$punchList->test_package]['punch_list'] = $punchList?->punch_list ?? "";
|
||||
|
||||
}
|
||||
|
||||
$addedSheet = [];
|
||||
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
$jointNo = $weldLog->no_of_the_joint_as_per_as_built_survey;
|
||||
|
||||
$goldenJoints = 0;
|
||||
$goldenJoints2 = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['goldenJoints']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['goldenJoints'] = 0;
|
||||
|
||||
if(!isset($quantity_of_iso[$weldLog->test_package_no]['total_qty']))
|
||||
$quantity_of_iso[$weldLog->test_package_no]['total_qty'] = 0;
|
||||
|
||||
if(!isset($addedSheet[$weldLog->test_package_no]))
|
||||
$addedSheet[$weldLog->test_package_no] = [];
|
||||
|
||||
if(!in_array($weldLog->quantity_of_iso, $addedSheet[$weldLog->test_package_no])) {
|
||||
$quantity_of_iso[$weldLog->test_package_no]['total_qty']++;
|
||||
$addedSheet[$weldLog->test_package_no][] = $weldLog->quantity_of_iso;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!isset($quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_qty']))
|
||||
$quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_qty'] = 0;
|
||||
|
||||
if(!isset($addedSheet[$weldLog->iso_number][$weldLog->test_package_no]))
|
||||
$addedSheet[$weldLog->iso_number][$weldLog->test_package_no] = [];
|
||||
|
||||
if(!in_array($weldLog->quantity_of_iso, $addedSheet[$weldLog->iso_number][$weldLog->test_package_no])) {
|
||||
$quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_qty']++;
|
||||
$addedSheet[$weldLog->iso_number][$weldLog->test_package_no][] = $weldLog->quantity_of_iso;
|
||||
}
|
||||
|
||||
|
||||
$backlogs = [
|
||||
'rt_backlog',
|
||||
'ut_backlog',
|
||||
'mt_backlog',
|
||||
'pmi_backlog',
|
||||
'vt_backlog',
|
||||
'pt_backlog',
|
||||
'ferrit_backlog',
|
||||
'pwht_backlog',
|
||||
'total_backlog',
|
||||
];
|
||||
|
||||
foreach($backlogs AS $backlog)
|
||||
{
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no][$backlog]))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no][$backlog] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->test_package_no][$backlog]))
|
||||
$stats[$weldLog->test_package_no][$backlog] = 0;
|
||||
|
||||
}
|
||||
|
||||
if(!isset($stats[$weldLog->test_package_no]['total_backlog']))
|
||||
$stats[$weldLog->test_package_no]['total_backlog'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->test_package_no]['goldenJoints']))
|
||||
$stats[$weldLog->test_package_no]['goldenJoints'] = 0;
|
||||
|
||||
if(strpos(strtoupper($jointNo), "GJ") !== false) {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['goldenJoints']++;
|
||||
$stats[$weldLog->test_package_no]['goldenJoints']++;
|
||||
}
|
||||
if(!isset($quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_iso_quantity']))
|
||||
$quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_iso_quantity'] = 0;
|
||||
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['rt_ut_status']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['rt_ut_status'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['remaining_wdi']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['remaining_wdi'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['total_wdi']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_wdi'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_wdi']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_wdi'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['total_joint_qty']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_joint_qty'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['total_welded_joint_qty']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_welded_joint_qty'] = 0;
|
||||
|
||||
if(!isset($stats[$weldLog->iso_number][$weldLog->test_package_no]['welded_support_quantity']))
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['welded_support_quantity'] = 0;
|
||||
|
||||
foreach($logTypes AS $logType) {
|
||||
$weldLogArray = (Array) $weldLog;
|
||||
$stats[$weldLog->test_package_no]['total_backlog'] += (float) $weldLogArray[$logType . "_scope"];
|
||||
}
|
||||
|
||||
|
||||
if(!isset($addedSheet[$weldLog->iso_number][$weldLog->test_package_no]['total_iso']))
|
||||
$addedSheet[$weldLog->iso_number][$weldLog->test_package_no]['total_iso'] = [];
|
||||
|
||||
if(!in_array($weldLog->quantity_of_iso, $addedSheet[$weldLog->iso_number][$weldLog->test_package_no]['total_iso']))
|
||||
{
|
||||
$quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_iso_quantity']++;
|
||||
$addedSheet[$weldLog->iso_number][$weldLog->test_package_no]['total_iso'][] = $weldLog->quantity_of_iso;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//welded_support_quantity
|
||||
|
||||
|
||||
if(rejected_date($weldLog->welding_date)) {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['remaining_wdi'] += (float) $weldLog->nps_1;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->rt_test_date)) {
|
||||
// $stats[$weldLog->iso_number][$weldLog->test_package_no]['rt_ut_done']++;
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['rt_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['rt_backlog']++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!rejected_date($weldLog->ut_test_date)) {
|
||||
// $stats[$weldLog->iso_number][$weldLog->test_package_no]['rt_ut_done']++;
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['ut_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['ut_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->pwht_test_date)) {
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['pwht_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['pwht_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->pmi_test_date)) {
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['pmi_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['pmi_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->ferrite_test_date)) {
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['ferrit_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['ferrit_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->pt_test_date)) {
|
||||
//$stats[$weldLog->iso_number][$weldLog->test_package_no]['mt_pt_done']++;
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['pt_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['pt_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->mt_test_date)) {
|
||||
//$stats[$weldLog->iso_number][$weldLog->test_package_no]['mt_pt_done']++;
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['mt_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['mt_backlog']++;
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->vt_test_date)) {
|
||||
//$stats[$weldLog->iso_number][$weldLog->test_package_no]['mt_pt_done']++;
|
||||
|
||||
} else {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['vt_backlog']++;
|
||||
$stats[$weldLog->test_package_no]['vt_backlog']++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!rejected_date($weldLog->welding_date)) {
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_wdi'] += (float) $weldLog->nps_1;
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_welded_joint_qty']++;
|
||||
}
|
||||
|
||||
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_wdi'] += (float) $weldLog->nps_1;
|
||||
|
||||
$stats[$weldLog->iso_number][$weldLog->test_package_no]['total_joint_qty'] ++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$ndtCalculationParams = [
|
||||
'type' => 'test_packs',
|
||||
];
|
||||
|
||||
if(isset($test_package_no)) {
|
||||
$ndtCalculationParams['test_package_no'] = $test_package_no;
|
||||
}
|
||||
|
||||
$ndtCalculation = j(view('admin-ajax.ndt-calculation-no-cache', $ndtCalculationParams)->render());
|
||||
|
||||
$tpStats = $ndtCalculation['tpStats'];
|
||||
$tpIsoStats = $ndtCalculation['tpISOStats'];
|
||||
|
||||
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
//if($weldLog->test_package_no != "") {
|
||||
|
||||
try {
|
||||
$punchListData = implode(",", $punchListNumbers[$weldLog->test_package_no]);
|
||||
} catch (\Throwable $th) {
|
||||
$punchListData = "";
|
||||
}
|
||||
|
||||
$thisStats = @$stats[$weldLog->test_package_no];
|
||||
$thisTpStats = @$tpStats[$weldLog->test_package_no];
|
||||
$thisTpISOStats = @$tpIsoStats[$weldLog->test_package_no][$weldLog->iso_number];
|
||||
$thisSupportStats = @$supportStatsTP[$weldLog->test_package_no];
|
||||
|
||||
$thisTotalBacklog =
|
||||
(@$thisTpStats['vt'] ?? 0) +
|
||||
(@$thisTpStats['ut'] ?? 0) +
|
||||
(@$thisTpStats['mt'] ?? 0) +
|
||||
(@$thisTpStats['pmi'] ?? 0) +
|
||||
(@$thisTpStats['pt'] ?? 0) +
|
||||
(@$thisTpStats['rt'] ?? 0) +
|
||||
(@$thisTpStats['pwht'] ?? 0) +
|
||||
(@$thisTpStats['ferrite'] ?? 0);
|
||||
|
||||
$testPackageData = [
|
||||
'unit' => $weldLog->design_area,
|
||||
'test_package_number' => $weldLog->test_package_no,
|
||||
'discipline' => $weldLog->piping_type,
|
||||
'circuit_number' => $weldLog->circuit_number,
|
||||
'p_id' => $weldLog->p_id,
|
||||
'iso_quantity' => $quantity_of_iso[$weldLog->test_package_no]['total_qty'],//$weldLog->quantity_of_iso, //burada qty toplam sayı gelmeli
|
||||
// 'subcontractor' => $weldLog->ste_subcontractor,
|
||||
'test_type' => $weldLog->type_of_test,
|
||||
'test_medium' => @$testTypeToMedium[strtoupper($weldLog->type_of_test)],
|
||||
'test_pressure' => $weldLog->test_pressure,
|
||||
'golden_joints' => @$stats[$weldLog->test_package_no]['goldenJoints'],
|
||||
'walkdown_date' => @$stats[$weldLog->test_package_no]['found_date'],
|
||||
'punch_list' => $punchListData,
|
||||
|
||||
'welded_support_quantity' => @$thisSupportStats['welded_support_quantity'],
|
||||
'support_remaining' => @$thisSupportStats['support_remaining'],
|
||||
'support_progress' => @$thisSupportStats['support_progress'],
|
||||
|
||||
'a_punch_point_open' => @$stats[$weldLog->test_package_no]['punch_a_open_quantity'],
|
||||
'b_punch_point_open' => @$stats[$weldLog->test_package_no]['punch_b_open_quantity'],
|
||||
'c_punch_point_open' => @$stats[$weldLog->test_package_no]['punch_c_open_quantity'],
|
||||
|
||||
'vt_backlog' => @$thisTpStats['vt'],
|
||||
'ut_backlog' => @$thisTpStats['ut'],
|
||||
'mt_backlog' => @$thisTpStats['mt'],
|
||||
'pmi_backlog' => @$thisTpStats['pmi'],
|
||||
'pt_backlog' => @$thisTpStats['pt'],
|
||||
'rt_backlog' => @$thisTpStats['rt'],
|
||||
'pwht_backlog' => @$thisTpStats['pwht'],
|
||||
'ferrit_backlog' => @$thisTpStats['ferrite'],
|
||||
'ndt_status' => @$thisTotalBacklog == 0 ? "Completed" : "Not Completed",
|
||||
];
|
||||
|
||||
$thisStats = @$stats[$weldLog->iso_number][$weldLog->test_package_no];
|
||||
$thisSupportStats = @$supportStats[$weldLog->iso_number];
|
||||
|
||||
try {
|
||||
$pipeProgress = round($thisStats['total_complated_wdi'] * 100 / $thisStats['total_wdi'], 2);
|
||||
} catch (\Throwable $th) {
|
||||
$pipeProgress = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$repairQty = $repairDatas[$weldLog->iso_number];
|
||||
} catch (\Throwable $th) {
|
||||
$repairQty = 0;
|
||||
}
|
||||
|
||||
|
||||
$testPackBaseStatusData = [
|
||||
'area' => $weldLog->project,
|
||||
'drawing_no' => $weldLog->iso_number,
|
||||
'test_package_no' => $weldLog->test_package_no,
|
||||
'discipline' => $weldLog->piping_type,
|
||||
'iso_qty' => $quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_qty'], //burada qty toplam sayı gelmeli
|
||||
// 'subcontractor' => $weldLog->ste_subcontractor,
|
||||
'test_type' => $weldLog->type_of_test,
|
||||
'test_medium' => @$testTypeToMedium[strtoupper($weldLog->type_of_test)],
|
||||
'test_pressure_mpa' => $weldLog->test_pressure,
|
||||
'tp_status' => '', // bu data test pack base stat. girilecek
|
||||
'total_iso_quantity' => $quantity_of_iso[$weldLog->iso_number][$weldLog->test_package_no]['total_iso_quantity'],
|
||||
// 'welding_status' => '',
|
||||
'remaining_wdi' => $thisStats['remaining_wdi'],
|
||||
'total_wdi' => $thisStats['total_wdi'],
|
||||
'total_complated_wdi' => $thisStats['total_complated_wdi'],
|
||||
'pipe_progress' => $pipeProgress,
|
||||
'total_joint_qty' => $thisStats['total_joint_qty'],
|
||||
'total_welded_joint_qty' => $thisStats['total_welded_joint_qty'],
|
||||
'welded_support_quantity' => @$thisSupportStats['welded_support_quantity'],
|
||||
'support_remaining' => @$thisSupportStats['support_remaining'],
|
||||
'support_progress' => @$thisSupportStats['support_progress'],
|
||||
'punch_a_quantity' => @$thisStats['punch_a_quantity'], //punch listteki a lar
|
||||
'punch_b_quantity' => @$thisStats['punch_b_quantity'],
|
||||
'punch_c_quantity' => @$thisStats['punch_c_quantity'],
|
||||
// 'repair_qty' => $repairQty,
|
||||
'rt_ut_status' => $thisStats['rt_ut_status'],
|
||||
'rt_backlog' => @$thisTpISOStats['rt'],
|
||||
'ut_backlog' => @$thisTpISOStats['ut'],
|
||||
'mt_backlog' => @$thisTpISOStats['mt'],
|
||||
'pmi_backlog' => @$thisTpISOStats['pmi'],
|
||||
'vt_backlog' => @$thisTpISOStats['vt'],
|
||||
'pt_backlog' => @$thisTpISOStats['pt'],
|
||||
'pwht_backlog' => @$thisTpISOStats['pwht'],
|
||||
'ferrit_backlog' => @$thisTpISOStats['ferrite'],
|
||||
];
|
||||
|
||||
|
||||
$testPackWhereData = [
|
||||
'test_package_number' => $weldLog->test_package_no
|
||||
];
|
||||
|
||||
$testPackBaseStatusWhereData = [
|
||||
'test_package_no' => $weldLog->test_package_no,
|
||||
'drawing_no' => $weldLog->iso_number,
|
||||
];
|
||||
|
||||
if($weldLog->test_package_no != "") {
|
||||
if(!is_null($weldLog->test_package_no)) {
|
||||
|
||||
/*
|
||||
TestPackBaseStatus::where([
|
||||
'test_package_no' => "",
|
||||
'drawing_no' => $weldLog->iso_number,
|
||||
])->delete();
|
||||
|
||||
TestPackage::where([
|
||||
'test_package_number' => "",
|
||||
])->delete();
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
TestPackage::updateOrCreate($testPackWhereData, $testPackageData);
|
||||
TestPackBaseStatus::updateOrCreate($testPackBaseStatusWhereData, $testPackBaseStatusData);
|
||||
|
||||
if($say == $commitSize) {
|
||||
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
$say++;
|
||||
|
||||
$count++;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
//dump("$count Data has been sync from WeldLog ==> Test Packages");
|
||||
|
||||
Log::debug("$count Data has been sync from WeldLog ==> Test Packages");
|
||||
Log::debug("$cachePrefix finish " . simdi());
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
dump($th);
|
||||
Log::error($th->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Weld Logs to Handovers Sync Cron Job
|
||||
*
|
||||
* This cron job synchronizes data from weld_logs table to handovers table
|
||||
* using chunk processing and database transactions for better performance and reliability.
|
||||
*/
|
||||
|
||||
try {
|
||||
// Configuration
|
||||
$chunkSize = 1000; // Process records in chunks to avoid memory issues
|
||||
$batchSize = 100; // Process database operations in smaller batches
|
||||
|
||||
// Get base column from settings
|
||||
$handOverZoneColumn = setting('hand_over_zone_column') ?? "line_number";
|
||||
|
||||
// Statistics tracking
|
||||
$stats = [
|
||||
'total_processed' => 0,
|
||||
'handovers_created' => 0,
|
||||
'handovers_updated' => 0,
|
||||
'errors' => 0,
|
||||
'start_time' => microtime(true)
|
||||
];
|
||||
|
||||
echo "=== Weld Logs to Handovers Sync Started ===\n";
|
||||
echo "Time: " . now() . "\n\n";
|
||||
|
||||
// Get total count for progress tracking
|
||||
$totalRecords = db("weld_logs")->count();
|
||||
echo "Total weld_logs records to process: {$totalRecords}\n\n";
|
||||
|
||||
// Process in chunks to avoid memory issues
|
||||
db("weld_logs")
|
||||
->select($handOverZoneColumn, 'project', 'design_area', 'piping_type')
|
||||
->distinct()
|
||||
->orderBy($handOverZoneColumn) // Laravel chunk() için orderBy gerekli
|
||||
->chunk($chunkSize, function ($weldLogs) use (&$stats, $batchSize, $handOverZoneColumn) {
|
||||
|
||||
// Group by base column to avoid duplicates
|
||||
$uniqueLines = [];
|
||||
foreach ($weldLogs as $weldLog) {
|
||||
$baseValue = $weldLog->{$handOverZoneColumn};
|
||||
if (!empty($baseValue)) {
|
||||
$uniqueLines[$baseValue] = $weldLog;
|
||||
}
|
||||
}
|
||||
|
||||
// Process unique lines in smaller batches for database operations
|
||||
$batch = [];
|
||||
foreach ($uniqueLines as $baseValue => $weldLog) {
|
||||
|
||||
$batch[] = [
|
||||
'base_value' => $baseValue,
|
||||
'weld_log' => $weldLog
|
||||
];
|
||||
|
||||
// Process batch when it reaches batch size
|
||||
if (count($batch) >= $batchSize) {
|
||||
processBatch($batch, $stats);
|
||||
$batch = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Process remaining records in the last batch
|
||||
if (!empty($batch)) {
|
||||
processBatch($batch, $stats);
|
||||
}
|
||||
|
||||
$stats['total_processed'] += count($uniqueLines);
|
||||
|
||||
// Progress update
|
||||
echo "Processed chunk: " . count($uniqueLines) . " unique lines\n";
|
||||
});
|
||||
|
||||
// Final statistics
|
||||
$executionTime = round(microtime(true) - $stats['start_time'], 2);
|
||||
|
||||
echo "\n=== Sync Completed ===\n";
|
||||
echo "Total processed: {$stats['total_processed']}\n";
|
||||
echo "Handovers created: {$stats['handovers_created']}\n";
|
||||
echo "Handovers updated: {$stats['handovers_updated']}\n";
|
||||
echo "Errors: {$stats['errors']}\n";
|
||||
echo "Execution time: {$executionTime} seconds\n";
|
||||
echo "Time: " . now() . "\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "CRITICAL ERROR: " . $e->getMessage() . "\n";
|
||||
echo "Stack trace: " . $e->getTraceAsString() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a batch of weld logs to create/update handovers
|
||||
*/
|
||||
function processBatch($batch, &$stats)
|
||||
{
|
||||
try {
|
||||
// Use database transaction for batch operations
|
||||
\DB::beginTransaction();
|
||||
|
||||
foreach ($batch as $item) {
|
||||
$baseValue = $item['base_value'];
|
||||
$weldLog = $item['weld_log'];
|
||||
|
||||
try {
|
||||
// Prepare handover data
|
||||
$handoverData = [
|
||||
'project' => $baseValue, // base column -> project (location)
|
||||
'object' => $weldLog->project ?? '', // project -> object
|
||||
'location' => $weldLog->design_area ?? '', // design_area -> location
|
||||
'work_type' => 'ТРУБКА', // piping_type -> work_type
|
||||
'status1' => 'In Progress',
|
||||
'updated_at' => now()
|
||||
];
|
||||
|
||||
// Check if handover record exists
|
||||
$existingHandover = db("handovers")
|
||||
->where('project', $baseValue)
|
||||
->first();
|
||||
|
||||
if ($existingHandover) {
|
||||
// Update existing record
|
||||
db("handovers")
|
||||
->where('id', $existingHandover->id)
|
||||
->update($handoverData);
|
||||
|
||||
$stats['handovers_updated']++;
|
||||
|
||||
} else {
|
||||
// Create new record
|
||||
$handoverData['created_at'] = now();
|
||||
$handoverData['final_status'] = 'Waiting';
|
||||
db("handovers")->insert($handoverData);
|
||||
|
||||
$stats['handovers_created']++;
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$stats['errors']++;
|
||||
echo "Error processing base value {$baseValue}: " . $e->getMessage() . "\n";
|
||||
continue; // Continue with next record instead of failing entire batch
|
||||
}
|
||||
}
|
||||
|
||||
// Commit transaction if all operations successful
|
||||
\DB::commit();
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Rollback transaction on error
|
||||
\DB::rollBack();
|
||||
$stats['errors']++;
|
||||
echo "Batch processing error: " . $e->getMessage() . "\n";
|
||||
throw $e; // Re-throw to be caught by main try-catch
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
$ndeMatrices = DB::table('nde_matrices')
|
||||
->join('weld_logs', 'nde_matrices.line', '=', 'weld_logs.line_number')
|
||||
->whereNull('nde_matrices.project'); // project sütunu boş olanları bul
|
||||
|
||||
if(isset($id))
|
||||
{
|
||||
$ndeMatrices = $ndeMatrices->where("weld_logs.id", $id);
|
||||
}
|
||||
|
||||
$ndeMatrices = $ndeMatrices
|
||||
->update([
|
||||
'nde_matrices.project' => DB::raw('weld_logs.project') // weld_logs tablosundaki project değeri ile güncelle
|
||||
]);
|
||||
|
||||
//dump("$ndeMatrices NDE Matrix Sync Project Name");
|
||||
?>
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
use App\Models\TestPackage;
|
||||
use App\Models\TestPackBaseStatus;
|
||||
|
||||
|
||||
$commitSize = 100;
|
||||
use Carbon\Carbon;
|
||||
//dump("$lastIdPrefix $lastId");
|
||||
|
||||
$testPackages = TestPackage::all();
|
||||
$testPackagesIso = TestPackBaseStatus::all();
|
||||
|
||||
$weldLogs = db("weld_logs")
|
||||
// ->where("updated_at", Carbon::today())
|
||||
->get();
|
||||
|
||||
//dump($weldLogs->count());
|
||||
|
||||
$repairLogs = db("repair_logs")
|
||||
//->where("updated_at", Carbon::today())
|
||||
->get();
|
||||
|
||||
$testPackagesSummary = [];
|
||||
$testPackagesIsoSummary = [];
|
||||
|
||||
$totalFields = [
|
||||
'total_wdi',
|
||||
'total_complated_wdi',
|
||||
'welding_progress',
|
||||
'total_shop_wdi',
|
||||
'total_complated_shop_wdi',
|
||||
'total_field_wdi',
|
||||
'total_complated_field_wdi',
|
||||
];
|
||||
|
||||
|
||||
$repairLogsSummary = [];
|
||||
$repairLogsSummary2 = [];
|
||||
$repairLogsSummaryCompleted = [];
|
||||
$repairLogsSummaryCompleted2 = [];
|
||||
$repairLogsSummaryRemaining = [];
|
||||
$repairLogsSummaryRemaining2 = [];
|
||||
|
||||
foreach($repairLogs AS $repairLog) {
|
||||
if(!isset($repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no]))
|
||||
$repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no] = 0;
|
||||
|
||||
if(!isset($repairLogsSummary2[$repairLog->test_package_no]))
|
||||
$repairLogsSummary2[$repairLog->test_package_no] = 0;
|
||||
|
||||
if(!isset($repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no]))
|
||||
$repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no] = 0;
|
||||
|
||||
if(!isset($repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no]))
|
||||
$repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no] = 0;
|
||||
|
||||
if(!isset($repairLogsSummaryCompleted2[$repairLog->test_package_no]))
|
||||
$repairLogsSummaryCompleted2[$repairLog->test_package_no] = 0;
|
||||
|
||||
if(!isset($repairLogsSummaryRemaining2[$repairLog->test_package_no]))
|
||||
$repairLogsSummaryRemaining2[$repairLog->test_package_no] = 0;
|
||||
|
||||
// if($repairLog->repair_status == "Not Done") {
|
||||
$repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no]++;
|
||||
$repairLogsSummary2[$repairLog->test_package_no]++;
|
||||
// }
|
||||
|
||||
if(!rejected_date($repairLog->repair_date))
|
||||
{
|
||||
$repairLogsSummaryCompleted[$repairLog->iso_number][$repairLog->test_package_no]++;
|
||||
$repairLogsSummaryCompleted2[$repairLog->test_package_no]++;
|
||||
} else {
|
||||
$repairLogsSummaryRemaining[$repairLog->iso_number][$repairLog->test_package_no]++;
|
||||
$repairLogsSummaryRemaining2[$repairLog->test_package_no]++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
|
||||
foreach($totalFields AS $field) {
|
||||
if(!isset($testPackagesSummary[$weldLog->test_package_no][$field]))
|
||||
$testPackagesSummary[$weldLog->test_package_no][$field] = 0;
|
||||
|
||||
if(!isset($testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no][$field]))
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no][$field] = 0;
|
||||
}
|
||||
|
||||
$wdi = (float) $weldLog->nps_1;
|
||||
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_wdi'] += $wdi ;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_wdi'] += $wdi;
|
||||
|
||||
|
||||
if($weldLog->type_of_joint == "F") {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_field_wdi'] += $wdi;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_field_wdi'] += $wdi ;
|
||||
|
||||
if(!rejected_date($weldLog->welding_date)) {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_complated_field_wdi'] += $wdi;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_field_wdi'] += $wdi;
|
||||
}
|
||||
}
|
||||
|
||||
if($weldLog->type_of_joint == "S") {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_shop_wdi'] += $wdi;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_shop_wdi'] += $wdi;
|
||||
|
||||
if(!rejected_date($weldLog->welding_date)) {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_complated_shop_wdi'] += $wdi;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_shop_wdi'] += $wdi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!rejected_date($weldLog->welding_date)) {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['total_complated_wdi'] += $wdi;
|
||||
$testPackagesIsoSummary[$weldLog->iso_number][$weldLog->test_package_no]['total_complated_wdi'] += $wdi;
|
||||
}
|
||||
|
||||
|
||||
// Welding progress hesaplama
|
||||
$totalWdi = $testPackagesSummary[$weldLog->test_package_no]['total_wdi'];
|
||||
$totalComplatedWdi = $testPackagesSummary[$weldLog->test_package_no]['total_complated_wdi'];
|
||||
|
||||
if ($totalWdi > 0) {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['welding_progress'] =
|
||||
round(($totalComplatedWdi * 100) / $totalWdi, 2);
|
||||
} else {
|
||||
$testPackagesSummary[$weldLog->test_package_no]['welding_progress'] = 0; // Sıfırsa
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
|
||||
try {
|
||||
foreach($testPackagesIsoSummary AS $isoNumber => $data) {
|
||||
foreach($data AS $tpNo => $data2) {
|
||||
|
||||
if($data2['total_complated_wdi'] == $data2['total_wdi']) {
|
||||
$status = "Completed";
|
||||
}
|
||||
|
||||
if($data2['total_complated_wdi'] < $data2['total_wdi']) {
|
||||
$status = "On Going";
|
||||
}
|
||||
|
||||
if($data2['total_complated_wdi'] == 0) {
|
||||
$status = "Waiting";
|
||||
}
|
||||
/*
|
||||
//dump($isoNumber);
|
||||
//dump($tpNo);
|
||||
//dump($data2);
|
||||
*/
|
||||
$updateData = [
|
||||
'welding_status' => $status,
|
||||
'repair_qty' => @$repairLogsSummary[$isoNumber][$tpNo],
|
||||
'repair_completed' => @$repairLogsSummaryCompleted[$isoNumber][$tpNo],
|
||||
'repair_remaining' => @$repairLogsSummaryRemaining[$isoNumber][$tpNo],
|
||||
];
|
||||
|
||||
// //dump($updateData);
|
||||
|
||||
db("test_pack_base_statuses")
|
||||
->where("drawing_no", $isoNumber)
|
||||
->where("test_package_no", $tpNo)
|
||||
->update(
|
||||
$updateData
|
||||
);
|
||||
|
||||
$updateData = [
|
||||
'welding_status' => $status,
|
||||
'repair_qty' => @$repairLogsSummary2[$tpNo],
|
||||
'repair_completed' => @$repairLogsSummaryCompleted2[$tpNo],
|
||||
'repair_remaining' => @$repairLogsSummaryRemaining2[$tpNo],
|
||||
];
|
||||
|
||||
db("test_packages")
|
||||
->where("test_package_number", $tpNo)
|
||||
->update(
|
||||
$updateData
|
||||
);
|
||||
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
*/
|
||||
$say++;
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
$say = 0;
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach($testPackagesSummary AS $tpNo => $data2) {
|
||||
|
||||
if($data2['total_complated_wdi'] == $data2['total_wdi']) {
|
||||
$status = "Completed";
|
||||
}
|
||||
|
||||
if($data2['total_complated_wdi'] < $data2['total_wdi']) {
|
||||
$status = "On Going";
|
||||
}
|
||||
|
||||
if($data2['total_complated_wdi'] == 0) {
|
||||
$status = "Waiting";
|
||||
}
|
||||
|
||||
db("test_packages")
|
||||
->where("test_package_number", $tpNo)
|
||||
->update(
|
||||
[
|
||||
'welding_status' => $status,
|
||||
'repair_status_total' => @$repairLogsSummary2[$tpNo]
|
||||
]
|
||||
);
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
$say++;
|
||||
*/
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
//code...
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DB::beginTransaction();
|
||||
$k = 0;
|
||||
$say = 0;
|
||||
try {
|
||||
|
||||
foreach($testPackages AS $testPackage) {
|
||||
|
||||
$updateData = [];
|
||||
|
||||
if(isset($testPackagesSummary[$testPackage->test_package_number])) {
|
||||
foreach($totalFields AS $field) {
|
||||
$testPackage->$field = $testPackagesSummary[$testPackage->test_package_number][$field];
|
||||
|
||||
$updateData[$field] = $testPackagesSummary[$testPackage->test_package_number][$field];
|
||||
}
|
||||
}
|
||||
|
||||
$updateData = array_merge($updateData, updateTestPackageStatus($testPackage));
|
||||
|
||||
|
||||
db("test_packages")->where("id", $testPackage->id)
|
||||
->update(
|
||||
$updateData
|
||||
);
|
||||
|
||||
db("test_pack_base_statuses")->where("test_package_no", $testPackage->test_package_number)
|
||||
->update(
|
||||
[
|
||||
'tp_status' => $status,
|
||||
'priority' => $testPackage->priority,
|
||||
'priority_info' => $testPackage->priority_info,
|
||||
'responsible_person' => $testPackage->responsible_test,
|
||||
'target_test_date' => $testPackage->planned_test_date,
|
||||
]
|
||||
);
|
||||
|
||||
/*
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
*/
|
||||
$say++;
|
||||
|
||||
$k++;
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
////dump($th->getMessage());
|
||||
Log::error($th->getMessage());
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
dump($k);
|
||||
Log::debug("$k Processed " . simdi());
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,107 @@
|
||||
Bu cron verinin anasını bellediği için durdurulmuştur.
|
||||
|
||||
<!?php
|
||||
|
||||
|
||||
|
||||
$weldLogs = db("weld_logs")
|
||||
->
|
||||
->get();
|
||||
|
||||
//dump($weldLogs->count());
|
||||
|
||||
if($weldLogs->count() == 0) {
|
||||
Cache::put($lastIdPrefix, 0);
|
||||
}
|
||||
|
||||
$testTypes = log_test_types();
|
||||
|
||||
DB::beginTransaction();
|
||||
$k = 0;
|
||||
$say = 0;
|
||||
try {
|
||||
foreach($weldLogs AS $weldLog) {
|
||||
|
||||
$run = false;
|
||||
|
||||
foreach($testTypes AS $testType => $testTableName) {
|
||||
$requestDate = $testType. "_request_date";
|
||||
|
||||
if(isset($weldLog->$requestDate)) {
|
||||
if(!rejected_date($weldLog->$requestDate)) {
|
||||
$tableName = $testTableName;
|
||||
$run = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($run) {
|
||||
$data = [];
|
||||
$columns = table_columns($tableName);
|
||||
unset($columns['id']);
|
||||
|
||||
|
||||
foreach($columns AS $column) {
|
||||
if(array_key_exists($column, (Array) $weldLog)) {
|
||||
$data[$column] = $weldLog->$column;
|
||||
} else {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
unset($data['id']);
|
||||
|
||||
$whereData = [
|
||||
'iso_number' => $weldLog->iso_number,
|
||||
'no_of_the_joint_as_per_as_built_survey' => $weldLog->no_of_the_joint_as_per_as_built_survey
|
||||
];
|
||||
|
||||
db($tableName)->updateOrInsert($whereData, $data);
|
||||
|
||||
|
||||
if($say == $commitSize) {
|
||||
DB::commit();
|
||||
DB::beginTransaction();
|
||||
$say = 0;
|
||||
}
|
||||
$say++;
|
||||
/*
|
||||
if($weldLog->iso_number == "KWR-150-AH01PZ-FA00.870-PP") {
|
||||
|
||||
if($weldLog->no_of_the_joint_as_per_as_built_survey == "6R1") {
|
||||
echo "ok";
|
||||
//dump($whereData);
|
||||
//dump($data);
|
||||
//dump($tableName);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
$k++;
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
//dump($data);
|
||||
Log::error($th->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
//dump($th);
|
||||
DB::rollback();
|
||||
Log::error($th->getMessage());
|
||||
}
|
||||
|
||||
//dump("$k data processed");
|
||||
Log::debug("$k data processed");
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user