İlk temizlik tamamlandı bir önceki projeden

This commit is contained in:
Ümit Tunç
2026-04-28 21:14:25 +03:00
commit f80443aec0
10000 changed files with 959965 additions and 0 deletions
@@ -0,0 +1,319 @@
<?php
use App\Models\TestPackage;
use App\Models\TestPackBaseStatus;
use Carbon\Carbon;
$testPackage = db("test_pack_base_statuses")->where("id", $request['key'])->first();
try {
db("test_packages")
->where("test_package_number", $testPackage->test_package_no)
->update([
'subcontractor' => $refactoringData['subcontractor']
]);
} catch (\Throwable $th) {
//throw $th;
}
$testPackages = TestPackage::where("test_package_number", $testPackage->test_package_no)->get();
$testPackagesIso = TestPackBaseStatus::where("test_package_no", $testPackage->test_package_no)->get();
$weldLogs = apply_welded_filter(
db("weld_logs")->where("test_package_no", $testPackage->test_package_no)
)->get();
$repairLogs = db("repair_logs")
->where("test_package_no", $testPackage->test_package_no)
->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 = [];
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($repairLog->repair_status == "Not Done") {
$repairLogsSummary[$repairLog->iso_number][$repairLog->test_package_no]++;
$repairLogsSummary2[$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();
$k = 0;
try {
// Test Package ISO Summary işlemlerini chunk'lara böl
$testPackagesIsoSummaryChunked = collect($testPackagesIsoSummary)->chunk(5); // 5'li gruplar
foreach($testPackagesIsoSummaryChunked as $isoSummaryChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($isoSummaryChunk, $repairLogsSummary) {
foreach($isoSummaryChunk 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]
];
// dump($updateData);
db("test_pack_base_statuses")
->where("drawing_no", $isoNumber)
->where("test_package_no", $tpNo)
->update(
$updateData
);
}
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
// Test Package Summary işlemlerini chunk'lara böl
$testPackagesSummaryChunked = collect($testPackagesSummary)->chunk(5); // 5'li gruplar
foreach($testPackagesSummaryChunked as $tpSummaryChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($tpSummaryChunk, $repairLogsSummary2) {
foreach($tpSummaryChunk 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]
]
);
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
// Test Packages işlemlerini chunk'lara böl
$testPackagesChunked = $testPackages->chunk(5); // 5'li gruplar
foreach($testPackagesChunked as $testPackageChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($testPackageChunk, $testPackagesSummary, $totalFields, &$k) {
foreach($testPackageChunk 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];
}
}
$status = "Waiting";
$ndt_status = $testPackage->ndt_status;
if(!rejected_date($testPackage->test_package_sent_date)) {
$status = "Prepairing";
}
if(!rejected_date($testPackage->test_package_approval_date)) {
$status = "Walkdown";
}
if(!rejected_date($testPackage->walkdown_date)) {
$status = "Punch";
}
if($testPackage->a_punch_point_open == "0" || $testPackage->a_punch_point_open == "") {
$status = "QC";
}
if($testPackage->welding_status != "Completed") {
$ndt_status = $testPackage->welding_status;
$status = "Welding Ongoing";
}
if($testPackage->ndt_status == "Accepted") {
$status = "Ready for Test";
}
if($testPackage->test_status == "Accepted") {
$status = "Ready Cleaning-Blowing";
}
if($testPackage->cleaning_blowing_drying_status == "Accepted") {
$status = "Ready for Reinstatement";
}
if($testPackage->reinstatement_status == "Accepted") {
$status = "Completed";
}
$updateData['tp_general_status'] = $status;
$updateData['ndt_status'] = $ndt_status;
// dump($updateData);
$resultTestPack = db("test_packages")->where("id", $testPackage->id)
->update(
$updateData
);
$resultIsoTestPack = 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,
]
);
$k += $resultTestPack + $resultIsoTestPack;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
DB::commit();
} catch (\Throwable $th) {
//dump($th->getMessage());
DB::rollback();
}
dump("$k Processed " . simdi());
// Sync weld logs to test packages for this specific test package
try {
$syncParams = [
'test_package_no' => $testPackage->test_package_no
];
$syncResult = view('cron.weld_logs-sync-from-weldlog-to-test-pack', $syncParams)->render();
Log::debug("Weld logs sync completed for test package: " . $testPackage->test_package_no);
} catch (\Throwable $th) {
Log::error("Weld logs sync failed for test package: " . $testPackage->test_package_no . " - " . $th->getMessage());
}
?>