İ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,263 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
$id = $request['key'];
// Get color system data for the current ID
$colorSystem = DB::table('color_systems')->where(is_array($id) ? $id : ['id' => $id])->first();
$ralCodes = j(setting("ral-codes"));
$ralCodeValues =array_column($ralCodes, 'ral_code');
// Helper function to find Russian color description for a RAL code
if(!function_exists('findRussianColorDescription')) {
function findRussianColorDescription($ralCodes, $ralCode) {
if (empty($ralCode)) {
return '';
}
foreach ($ralCodes as $entry) {
if (isset($entry['ral_code']) && $entry['ral_code'] == $ralCode && isset($entry['ru'])) {
return $entry['ru'];
}
}
return '';
}
}
if (!$colorSystem) {
Log::debug("Color system record not found for ID: $id");
return;
}
Log::debug("Starting synchronization from Color Systems...");
Log::debug("Processing color system for fluid_code: {$colorSystem->fluid_code}");
DB::beginTransaction();
try {
// Skip processing if essential fields are missing
if (empty($colorSystem->fluid_code)) {
Log::debug("Skipping sync - missing fluid_code");
DB::commit();
return;
}
// Get RAL values from color_systems
$ral1 = $colorSystem->ral_1 ?? $colorSystem->ral_code_1 ?? $colorSystem->color_code_1 ?? '';
$ral2 = $colorSystem->ral_2 ?? $colorSystem->ral_code_2 ?? $colorSystem->color_code_2 ?? '';
$ral3 = $colorSystem->ral_3 ?? $colorSystem->ral_code_3 ?? $colorSystem->color_code_3 ?? '';
// Get Russian color descriptions from RAL codes
$colorRu1 = findRussianColorDescription($ralCodes, $ral1);
$colorRu2 = findRussianColorDescription($ralCodes, $ral2);
$colorRu3 = findRussianColorDescription($ralCodes, $ral3);
Log::debug("RAL values from color_systems - RAL1: {$ral1}, RAL2: {$ral2}, RAL3: {$ral3}");
Log::debug("Russian color descriptions - Color1: {$colorRu1}, Color2: {$colorRu2}, Color3: {$colorRu3}");
// ===== SYNC TO CONSTRUCTION_PAINT_LOGS =====
Log::debug("Syncing to Construction Paint Logs...");
// Find all construction paint logs that match this fluid_code and unit
$cpWhereCondition = [
'fluid_code' => $colorSystem->fluid_code
];
// Add unit condition if available
if (!empty($colorSystem->unit)) {
$cpWhereCondition['unit'] = $colorSystem->unit;
Log::debug("Using both fluid_code and unit for matching Construction Paint Logs records");
} else {
Log::debug("Using only fluid_code for matching Construction Paint Logs records (unit is empty)");
}
// Prepare update data for construction_paint_logs
$cpUpdateData = [
'ral_1' => $ral1,
'ral_2' => $ral2,
'ral_3' => $ral3,
'color_1' => $colorRu1, // Russian color description
'color_2' => $colorRu2, // Russian color description
'color_3' => $colorRu3, // Russian color description
'updated_at' => now()
];
// Construction Paint Logs işlemlerini chunk'lara böl
$constructionPaintLogs = DB::table('construction_paint_logs')
->where($cpWhereCondition)
->whereNull('painting_date_1')
->get();
$constructionPaintLogsChunked = $constructionPaintLogs->chunk(10); // 10'lu gruplar
$cpUpdatedCount = 0;
foreach($constructionPaintLogsChunked as $cpLogsChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($cpLogsChunk, $cpUpdateData, &$cpUpdatedCount) {
foreach($cpLogsChunk as $cpLog) {
DB::table('construction_paint_logs')
->where('id', $cpLog->id)
->update($cpUpdateData);
$cpUpdatedCount++;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
if ($cpUpdatedCount > 0) {
Log::debug("Updated {$cpUpdatedCount} Construction Paint Logs records with RAL values and Russian color descriptions");
} else {
Log::debug("No Construction Paint Logs records found to update");
}
// ===== SYNC TO PAINT_FOLLOW_UPS =====
Log::debug("Syncing to Paint Follow Ups...");
// Find all paint follow ups that match this fluid_code and unit
$pfuWhereCondition = [
'fluid_code' => $colorSystem->fluid_code
];
// Add unit condition if available
if (!empty($colorSystem->unit)) {
$pfuWhereCondition['area'] = $colorSystem->unit;
Log::debug("Using both fluid_code and unit for matching Paint Follow Ups records");
} else {
Log::debug("Using only fluid_code for matching Paint Follow Ups records (unit is empty)");
}
// Prepare update data for paint_follow_ups
$pfuUpdateData = [
'ral_code_1' => $ral1,
'ral_code_2' => $ral2,
'ral_code_3' => $ral3,
'colour_1' => $colorRu1,
'colour_2' => $colorRu2,
'colour_3' => $colorRu3,
'updated_at' => now()
];
// Paint Follow Ups işlemlerini chunk'lara böl
$paintFollowUps = DB::table('paint_follow_ups')
->where($pfuWhereCondition)
->whereNull('primer_coating_start_date')
->get();
$paintFollowUpsChunked = $paintFollowUps->chunk(10); // 10'lu gruplar
$pfuUpdatedCount = 0;
foreach($paintFollowUpsChunked as $followUpsChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($followUpsChunk, $pfuUpdateData, &$pfuUpdatedCount) {
foreach($followUpsChunk as $followUp) {
DB::table('paint_follow_ups')
->where('id', $followUp->id)
->update($pfuUpdateData);
$pfuUpdatedCount++;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
if ($pfuUpdatedCount > 0) {
Log::debug("Updated {$pfuUpdatedCount} Paint Follow Ups records with RAL values");
} else {
Log::debug("No Paint Follow Ups records found to update");
}
// ===== SYNC TO PAINT_MATRICES =====
Log::debug("Syncing to Paint Matrices...");
// Skip paint_matrices sync if area is missing
if (empty($colorSystem->unit)) {
Log::debug("Skipping Paint Matrices sync - missing area");
} else {
// Find all paint matrices records that match this area and fluid_code
$pmWhereCondition = [
'fluid_code' => $colorSystem->fluid_code,
'area' => $colorSystem->unit
];
Log::debug("Using area+fluid_code as key for matching Paint Matrices records");
// Prepare update data for paint_matrices
$pmUpdateData = [
'ral_code_1' => $ral1,
'ral_code_2' => $ral2,
'ral_code_3' => $ral3,
'colour_1' => $colorRu1, // Add Russian color description
'colour_2' => $colorRu2, // Add Russian color description
'colour_3' => $colorRu3, // Add Russian color description
'updated_at' => now()
];
Log::debug($pmWhereCondition);
Log::debug($pmUpdateData);
// Paint Matrices işlemlerini chunk'lara böl
$paintMatrices = DB::table('paint_matrices')
->where($pmWhereCondition)
->get();
$paintMatricesChunked = $paintMatrices->chunk(8); // 8'li gruplar
$pmUpdatedCount = 0;
foreach($paintMatricesChunked as $matricesChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($matricesChunk, $pmUpdateData, &$pmUpdatedCount) {
foreach($matricesChunk as $matrix) {
DB::table('paint_matrices')
->where('id', $matrix->id)
->update($pmUpdateData);
$pmUpdatedCount++;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
if ($pmUpdatedCount > 0) {
Log::debug("Updated {$pmUpdatedCount} Paint Matrices records with RAL values and Russian color descriptions");
} else {
Log::debug("No Paint Matrices records found to update. Creating a new record.");
// Create new record with all available data
$newPmData = array_merge($pmWhereCondition, $pmUpdateData, [
'created_at' => now()
]);
// Insert new record to paint_matrices
DB::table('paint_matrices')->insert($newPmData);
Log::debug("Created new Paint Matrices record for fluid_code: {$colorSystem->fluid_code}, area: {$colorSystem->unit}");
}
}
DB::commit();
Log::debug("Synchronization from Color Systems completed successfully.");
} catch (\Throwable $th) {
DB::rollback();
Log::debug("Error synchronizing from Color Systems: " . $th->getMessage());
Log::error("Sync error from Color Systems: " . $th->getMessage());
// Log detailed error information for debugging
Log::error("Error details: ", [
'colorSystemId' => $id,
'fluid_code' => $colorSystem->fluid_code ?? 'unknown',
'area' => $colorSystem->area ?? 'unknown',
'unit' => $colorSystem->unit ?? 'unknown',
'exception' => get_class($th),
'file' => $th->getFile(),
'line' => $th->getLine(),
'trace' => $th->getTraceAsString()
]);
}
?>
@@ -0,0 +1,287 @@
<?php
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
$id = $request['key'];
Log::debug("=== CONSTRUCTION PAINT LOGS SYNC BAŞLATILIYOR ===", [
'id' => $id,
'timestamp' => now()
]);
try {
// Get paint system data for the current ID
$constructionPaintLog = DB::table('construction_paint_logs')->where(is_array($id) ? $id : ['id' => $id])->first();
if ($constructionPaintLog) {
Log::debug("Construction Paint Log bulundu", [
'id' => $id,
'line' => $constructionPaintLog->line ?? 'NULL',
'spool' => $constructionPaintLog->spool ?? 'NULL',
'iso_drawings' => $constructionPaintLog->iso_drawings ?? 'NULL'
]);
// Comprehensive field mapping from construction_paint_logs to paint_follow_ups
// Based on line_lists.php comprehensive sync structure
$fieldMappings = [
// Date fields
'blasting_date' => 'protocol_date_cleaning',
'blasting_rfi_no' => 'surface_preparation_rfi_no',
'painting_date_1' => 'primer_coating_start_date',
'painting_finish_date_1' => 'primer_coating_finish_date',
'rfi_date_1' => 'primer_coating_rfi_date_1',
'rfi_no_1' => 'primer_coating_rfi_no',
'painting_date_2' => 'start_intermediate_date2',
'painting_finish_date_2' => 'finish_intermediate_date2',
'rfi_date_2' => 'intermediate_coating_rfi_date_3',
'rfi_no_2' => 'intermediate_coating_rfi_no2',
'painting_date_3' => 'final_coat_start_date3',
'painting_finish_date_3' => 'final_coat_finish_date3',
'rfi_date_3' => 'final_coating_rfi_date_3',
'rfi_no_3' => 'final_coating_rfi_no3',
// Thickness fields
'thickness_1' => 'primer_measured_thickness_1',
'thickness_2' => 'intermediate_measured_thickness_2',
'thickness_3' => 'final_coating_measured_thickness_3',
// Brand and coating information
'brend_name_1' => 'brend_name_1',
'brend_name_2' => 'brend_name_2',
'brend_name_3' => 'brend_name_3',
'ral_1' => 'ral_code_1',
'ral_2' => 'ral_code_2',
'ral_3' => 'ral_code_3',
// Additional fields (only existing columns in paint_follow_ups)
'fluid_code' => 'fluid_code',
'fluid_code_description' => 'fluid_code_description',
'line' => 'line',
'area' => 'project',
'spool' => 'spool_no_joint_no',
'iso_drawings' => 'iso_number'
];
// Prepare update data for paint_follow_ups
$updateData = [];
// Add fields from construction_paint_logs to updateData
foreach ($fieldMappings as $sourceField => $targetField) {
if (isset($constructionPaintLog->$sourceField) && $constructionPaintLog->$sourceField !== null) {
$updateData[$targetField] = $constructionPaintLog->$sourceField;
}
}
// Calculate total thickness
$updateData['total_thickness'] = (float)($constructionPaintLog->thickness_1 ?? 0) +
(float)($constructionPaintLog->thickness_2 ?? 0) +
(float)($constructionPaintLog->thickness_3 ?? 0);
Log::debug("Field mapping tamamlandı", [
'updateData' => $updateData,
'fieldMappings_count' => count($fieldMappings)
]);
// Add additional fields from line_lists.php comprehensive sync
// These fields are available in paint_follow_ups table
$additionalFields = [
'project' => $constructionPaintLog->area ?? '',
'description' => 'PIPE',
'location' => 'SHOP', // Default location for construction paint logs
'cycle' => $constructionPaintLog->painting_system_type_1 ?? '',
'status' => 'In Progress'
];
// Merge additional fields into updateData
foreach ($additionalFields as $key => $value) {
if (!empty($value)) {
$updateData[$key] = $value;
}
}
// Load temperature settings for volume and temperature calculations
$temperatures = j(setting("temperatures"));
$todayTempData = null;
// Get blasting_date from construction_paint_logs to determine temperature data
// Only proceed if blasting_date is not null, not empty, and not blank
if (!is_null($temperatures) &&
!empty($constructionPaintLog->blasting_date) &&
trim($constructionPaintLog->blasting_date) !== '') {
$blastingDate = Carbon::parse($constructionPaintLog->blasting_date);
$dayOfYear = $blastingDate->format('z');
$todayTempData = $temperatures[$dayOfYear] ?? null;
Log::debug('Temperature data loaded based on blasting_date:', [
'blasting_date' => $constructionPaintLog->blasting_date,
'day_of_year' => $dayOfYear,
'temp_data' => $todayTempData
]);
} else {
if (is_null($temperatures)) {
Log::debug('Temperature settings not found, temperature updates will be skipped');
} else {
Log::debug('No blasting_date found, empty or blank - temperature updates will be skipped', [
'blasting_date_value' => $constructionPaintLog->blasting_date ?? 'NULL'
]);
}
}
// Only proceed if we have data to update
if (!empty($updateData)) {
// Set updated_at timestamp
$updateData['updated_at'] = now();
// Find matching records in paint_follow_ups by line and spool
$whereConditions = [
['iso_number', $constructionPaintLog->iso_drawings],
['spool_no_joint_no', $constructionPaintLog->spool]
];
// Also try to match by line if iso_drawings is empty
if (empty($constructionPaintLog->iso_drawings) && !empty($constructionPaintLog->line)) {
$whereConditions = [
['line', $constructionPaintLog->line],
['spool_no_joint_no', $constructionPaintLog->spool]
];
}
// Update paint_follow_ups with construction paint log data
$affectedRows = DB::table('paint_follow_ups')
->where($whereConditions)
->update($updateData);
Log::debug("Paint Follow Ups güncellendi", [
'whereConditions' => $whereConditions,
'affectedRows' => $affectedRows,
'updateData' => $updateData
]);
// Update temperature fields if todayTempData is available and fields are empty
if ($todayTempData && $affectedRows > 0) {
// Get existing records to check if temperature fields are empty
$existingRecords = DB::table('paint_follow_ups')
->where($whereConditions)
->get();
foreach ($existingRecords as $existingRecord) {
$tempUpdateData = [];
// Add temperature data based on location (SHOP or FIELD)
if ($existingRecord->location === 'SHOP') {
if (empty($existingRecord->substrate_temprature)) {
$tempUpdateData['substrate_temprature'] = $todayTempData['temp_material_shop'];
}
if (empty($existingRecord->ambient_temprature)) {
$tempUpdateData['ambient_temprature'] = $todayTempData['shop_ambient'];
}
} elseif ($existingRecord->location === 'FIELD') {
if (empty($existingRecord->substrate_temprature)) {
$tempUpdateData['substrate_temprature'] = $todayTempData['temp_material_field'];
}
if (empty($existingRecord->ambient_temprature)) {
$tempUpdateData['ambient_temprature'] = $todayTempData['field_ambient'];
}
}
if (!empty($tempUpdateData)) {
$tempUpdateData['updated_at'] = now();
DB::table('paint_follow_ups')
->where('id', $existingRecord->id)
->update($tempUpdateData);
Log::debug("Updated temperature fields for paint follow up record", [
'record_id' => $existingRecord->id,
'location' => $existingRecord->location,
'updated_fields' => array_keys($tempUpdateData)
]);
}
}
}
// Sync with Incoming Control Paints for each brand
$brands = ['brend_name_1', 'brend_name_2', 'brend_name_3'];
foreach ($brands as $index => $brandField) {
if (!empty($constructionPaintLog->$brandField)) {
Log::debug("Marka için incoming_control_paints aranıyor", [
'brandField' => $brandField,
'brandValue' => $constructionPaintLog->$brandField
]);
// Get the latest incoming control paint record for this brand
$incomingControl = DB::table('incoming_control_paints')
->where('brend_name', $constructionPaintLog->$brandField)
->orderBy('rfi_date', 'desc')
->first();
if ($incomingControl) {
Log::debug("Incoming control paint bulundu", [
'incomingControl' => (array)$incomingControl
]);
$suffix = $index + 1;
$incomingUpdateData = [
'incoming_control_akt_no_' . $suffix => $incomingControl->akt_number,
'incoming_control_rfi_no_' . $suffix => $incomingControl->rfi_no,
'akt_date_' . $suffix => $incomingControl->akt_date,
'standartgost_iso_en_' . $suffix => $incomingControl->manufacturing_standard,
'certificate_passport_no_' . $suffix => $incomingControl->certificate_no,
'certificate_passport_date_' . $suffix => $incomingControl->certificate_date,
'updated_at' => now()
];
// Update paint_follow_ups with incoming control data
$incomingAffectedRows = DB::table('paint_follow_ups')
->where($whereConditions)
->update($incomingUpdateData);
Log::debug("Paint Follow Ups incoming control güncellendi", [
'whereConditions' => $whereConditions,
'incomingUpdateData' => $incomingUpdateData,
'affectedRows' => $incomingAffectedRows
]);
} else {
Log::debug("Incoming control paint bulunamadı", [
'brandField' => $brandField,
'brandValue' => $constructionPaintLog->$brandField
]);
}
}
}
Log::debug("Construction Paint Logs to Paint Follow Ups sync tamamlandı", [
'constructionPaintLogId' => $id,
'affectedRows' => $affectedRows
]);
} else {
Log::debug("Senkronize edilecek alan yok", [
'constructionPaintLogId' => $id
]);
}
} else {
Log::debug("Construction Paint Log bulunamadı", [
'id' => $id
]);
}
// Run spool status changer after construction paint logs sync
$spool_number = $constructionPaintLog->spool ?? null;
$line_number = $constructionPaintLog->line ?? null;
echo view('cron.spool-status-changer', ['line_number' => $line_number, 'spool_number' => $spool_number])->render();
Log::debug("=== CONSTRUCTION PAINT LOGS SYNC BAŞARIYLA TAMAMLANDI ===", [
'id' => $id,
'timestamp' => now()
]);
} catch (\Exception $e) {
Log::error("Construction Paint Logs synchronization failed: " . $e->getMessage(), [
'id' => $id,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
throw $e;
}
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,17 @@
<?php
$data = db("i_t_p_s")->where("id", $request['key'])->first();
$dataToUpdate = [
'sub' => $data->subcontractor,
'ste' => $data->ste,
'cas' => $data->cas,
'mf' => $data->mf
];
$uniqueFields = [
'itp' => $data->itp_no,
'phase' => $data->item_no
];
echo db('r_f_i_s')->updateOrInsert($uniqueFields, $dataToUpdate);
?>
@@ -0,0 +1,75 @@
<?php
use App\Models\IncomingControlPaint;
use App\Models\PaintFollowUp;
$id = $request['key'];
/*
$incomingControlPaints = IncomingControlPaint::where("id", $id)->get();
//->where("id",">", $lastId)
$count = 0;
foreach($incomingControlPaints AS $incomingControlPaint) {
// Update for brand_name_1
$updateData1 = [
'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,
];
$whereData1 = [
'brend_name_1' => $incomingControlPaint->brend_name,
];
PaintFollowUp::where($whereData1)->update($updateData1);
// Update for brand_name_2
$updateData2 = [
'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,
];
$whereData2 = [
'brend_name_2' => $incomingControlPaint->brend_name,
];
PaintFollowUp::where($whereData2)->update($updateData2);
// Update for brand_name_3
$updateData3 = [
'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,
];
$whereData3 = [
'brend_name_3' => $incomingControlPaint->brend_name,
];
PaintFollowUp::where($whereData)->update($updateData);
Cache::put($cachePrefix, $incomingControlPaint->id);
$count++;
}
dump("$count Data has been sync from Incoming Control Paint to Paint Follow Up");
*/
?>
@@ -0,0 +1,73 @@
<?php
// app/Http/Controllers/SaveTrigger/line_lists.php
use App\Services\LineListTriggers\LineListTriggerManager;
use App\Services\LineListTriggers\LineListTriggerRegistry;
use Illuminate\Support\Facades\Log;
// Memory and execution settings
ini_set('memory_limit', '2G');
ini_set('max_execution_time', 600);
$id = $request['key'];
// Get line list data
$lineList = db($tableName)->where("id", $id)->first();
if(is_null($lineList)) {
$lineList = db($tableName)->where($id)->first();
}
// Safety check - ensure we have data
if(is_null($lineList)) {
Log::error("LineList not found for trigger execution", [
'line_list_id' => $id,
'table_name' => $tableName
]);
return;
}
// Detect changes and new record status
$isNewRecord = is_null($beforeData);
$changedFields = detectChangedFields($lineList, $beforeData);
// Execute triggers via manager
$registry = new LineListTriggerRegistry();
$manager = new LineListTriggerManager($registry);
try {
$results = $manager->executeTriggers(
$lineList,
$beforeData,
$changedFields,
$isNewRecord
);
Log::info("LineList triggers execution completed", [
'line_list_id' => $id,
'line_no' => $lineList->line_no ?? 'NULL',
'results_summary' => array_map(function($result) {
if (isset($result['skipped']) && $result['skipped']) {
return 'skipped';
} elseif (isset($result['success']) && $result['success']) {
return 'success';
} elseif (isset($result['error'])) {
return 'failed';
}
return 'unknown';
}, $results)
]);
} catch (\Throwable $th) {
Log::error("LineList triggers execution failed with critical error", [
'line_list_id' => $id,
'line_no' => $lineList->line_no ?? 'NULL',
'error' => $th->getMessage(),
'file' => $th->getFile(),
'line' => $th->getLine(),
'trace' => $th->getTraceAsString()
]);
throw $th;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,41 @@
<?php
$data = db("m_t_o_s")->where("id", $request['key'])->first();
$uniqueFields = [
'line_number' => $data->line,
'support_code' => $data->component_code_id,
];
$dataToUpdate = [
'zone' => $data->project,
'line_number' => $data->line,
'rev' => $data->rev,
'support_code' => $data->component_code_id,
// 'longdescription' => $data->line,
// 'description_en' => $data->line,
'erection_materials_name' => $data->description_ru,
'standart' => $data->manufacturing_standard,
'materials' => $data->material,
// 'material_quality_standard' => $data->line,
'quantity' => $data->quantity,
// 'dia_inch_1' => $data->line,
// 'dn_1' => $data->line,
'welded_pad_measure' => $data->odmm_1,
// 'schedule_1' => $data->line,
'thickness' => $data->thicknessmm_1,
// 'diainch_2' => $data->line,
// 'dn_2' => $data->line,
// 'odmm_2' => $data->line,
// 'schedule_2' => $data->line,
// 'thicknessmm_2' => $data->line,
// 'pn_mpa' => $data->line,
'unit_weight' => $data->weight,
'total_weight' => $data->total_weight,
// 'total_weight' => $data->line,
'designer' => $data->designer,
];
echo db('supports')->updateOrInsert($uniqueFields, $dataToUpdate);
//dump("save trigger");
dump($dataToUpdate);
?>
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,32 @@
<?php
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
if (isset($data['source_project'])) {
// If source_project was changed or is empty (meaning this project is now the source)
// We should trigger a sync to other projects
// Check if it was actually changed or if this is a new record
// In SaveTrigger context, we might not have the old data easily accessible unless we query it or passed it
// But since this runs AFTER save, we can just trigger it if source_project is empty (owned by us)
// or if we want to propagate changes regardless.
// The requirement is: "When I make 'Viksa' empty, it is saved with this project's name and triggers others".
// Empty means "This Project".
$sourceProject = $data['source_project'];
// If source_project is empty/null, it means we originated/modified it as the master.
// If source_project is NOT empty, it means it belongs to another project, so normally we shouldn't be editing it
// unless we are "stealing" ownership or it's a sync update.
// However, if we are the one triggering the save (via UI), we should notify others.
// We'll trigger the sync job to notify others.
Log::info("SaveTrigger: naks_certificates updated. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'technology',
'source_project' => config('app.name', 'Unknown Project'),
]);
}
@@ -0,0 +1,12 @@
<?php
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
if (isset($data['source_project'])) {
Log::info("SaveTrigger: naks_consumables updated. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'consumables',
'source_project' => config('app.name', 'Unknown Project'),
]);
}
@@ -0,0 +1,12 @@
<?php
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
if (isset($data['source_project'])) {
Log::info("SaveTrigger: naks_welders updated. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'welder',
'source_project' => config('app.name', 'Unknown Project'),
]);
}
@@ -0,0 +1,111 @@
<?php
use App\Models\WeldLog;
use App\Models\NdeMatrix;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
$id = $request['key'];
Log::debug("NDE Matrix güncelleme işlemi başlatıldı", [
'istek_id' => $id,
'request' => $request
]);
$ndeMatrices = NdeMatrix::where("id", $id)->get();
Log::debug("NDE Matrix kayıtları çekildi", [
'matrix_count' => $ndeMatrices->count(),
'matrix_examples' => $ndeMatrices->take(2)->toArray()
]);
$count = 0;
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,
// 'service_category' => $ndeMatrix->piping_group,
'updated_at' => simdi()
];
Log::debug("WeldLog güncelleme verisi hazırlanıyor", [
'line_number' => $ndeMatrix->line,
'type_of_joint' => $ndeMatrix->type_of_joint,
'update_data' => $data
]);
$result = db("weld_logs")
->where("line_number", $ndeMatrix->line)
->where("type_of_welds", $ndeMatrix->type_of_joint)
->update($data);
Log::debug("WeldLog güncelleme sonucu", [
'line_number' => $ndeMatrix->line,
'type_of_joint' => $ndeMatrix->type_of_joint,
'guncellenen_kayit_sayisi' => $result
]);
// NDT Log Tablolarını Senkronize Et (Control Standart & Naks Technology)
$testTypes = log_test_types();
foreach ($testTypes as $key => $tableName) {
// Tablolar migration ile güncellendiği için direct update atıyoruz
// line_number eşleşmesi üzerinden matrix standartlarını loglara basar
db($tableName)
->where("line_number", $ndeMatrix->line)
->where("type_of_welds", $ndeMatrix->type_of_joint)
->update([
'control_standart' => $ndeMatrix->control_standart,
]);
}
$count += $result;
}
$ndeMatrices = DB::table('nde_matrices')
->join('weld_logs', function($join) {
$join->on('nde_matrices.line', '=', 'weld_logs.line_number')
->on('nde_matrices.design_area', '=', 'weld_logs.design_area');
})
->whereNull('nde_matrices.project'); // project sütunu boş olanları bul
$ndeMatrices = $ndeMatrices
->update([
'nde_matrices.project' => DB::raw('weld_logs.project') // weld_logs tablosundaki project değeri ile güncelle
]);
Log::debug("NDE Matrix güncelleme işlemi tamamlandı", [
'toplam_guncellenen_kayit' => $count
]);
dump("WeldLog updated rows: $count");
// Request NDT Cache tetiklemesi
if(function_exists('dispatchCacheBladeViews')) {
dispatchCacheBladeViews([
[
'view' => 'admin-ajax.request-ndt-no-cache',
'cache' => 'request-ndt'
]
]);
Log::info("NDE Matrix update triggered request-ndt cache update.");
}
?>
@@ -0,0 +1,46 @@
<?php
use Illuminate\Support\Facades\Log;
/**
* Shared NDT Log Trigger Logic
*
* This file is included by individual NDT log save triggers to
* invalidate the 'request-ndt' cache when 'control_standart' changes.
*/
$shouldUpdate = false;
// If we have data and it has control_standart
if(isset($data) && property_exists($data, 'control_standart')) {
// If it's a new record (no beforeData) or if the value changed
// We also check if beforeData has the property, just in case
if(!isset($beforeData) || !property_exists($beforeData, 'control_standart') || $data->control_standart != $beforeData->control_standart) {
$shouldUpdate = true;
}
}
if($shouldUpdate) {
if(function_exists('dispatchCacheBladeViews')) {
dispatchCacheBladeViews([
[
'view' => 'admin-ajax.request-ndt-no-cache',
'cache' => 'request-ndt'
],
[
'view' => 'admin-ajax.ndt-calculation-no-cache',
'cache' => 'ndt-calculation'
],
[
'view' => 'admin-ajax.ndt-order.order-list-no-cache',
'cache' => 'ndt-order-list'
]
]);
Log::info("NDT Log triggered request-ndt cache update due to control_standart change.", [
'table' => $tableName ?? 'unknown',
'id' => $data->id ?? 'unknown',
'new_value' => $data->control_standart ?? 'null',
'old_value' => $beforeData->control_standart ?? 'null'
]);
}
}
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,348 @@
<?php
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
$id = $request['key'];
Log::debug("=== PAINT FOLLOW UPS SYNC BAŞLATILIYOR ===", [
'id' => $id,
'timestamp' => now()
]);
try {
// Get paint follow up data for the current ID
$paintFollowUp = DB::table('paint_follow_ups')->where(is_array($id) ? $id : ['id' => $id])->first();
if ($paintFollowUp) {
Log::debug("Paint Follow Up bulundu", [
'id' => $id,
'line' => $paintFollowUp->line ?? 'NULL',
'spool_no_joint_no' => $paintFollowUp->spool_no_joint_no ?? 'NULL',
'iso_number' => $paintFollowUp->iso_number ?? 'NULL'
]);
// Comprehensive field mapping from paint_follow_ups to construction_paint_logs
// Based on line_lists.php comprehensive sync structure
$fieldMappings = [
// Date fields
'protocol_date_cleaning' => 'blasting_date',
'surface_preparation_rfi_no' => 'blasting_rfi_no',
'primer_coating_start_date' => 'painting_date_1',
'primer_coating_finish_date' => 'painting_finish_date_1',
'primer_coating_rfi_no' => 'rfi_no_1',
'primer_coating_rfi_date_1' => 'rfi_date_1',
'start_intermediate_date2' => 'painting_date_2',
'finish_intermediate_date2' => 'painting_finish_date_2',
'intermediate_coating_rfi_no2' => 'rfi_no_2',
'intermediate_coating_rfi_date_3' => 'rfi_date_2',
'final_coat_start_date3' => 'painting_date_3',
'final_coat_finish_date3' => 'painting_finish_date_3',
'final_coating_rfi_no3' => 'rfi_no_3',
'final_coating_rfi_date_3' => 'rfi_date_3',
// Thickness fields
'primer_measured_thickness_1' => 'thickness_1',
'intermediate_measured_thickness_2' => 'thickness_2',
'final_coating_measured_thickness_3' => 'thickness_3',
// Brand and coating information
'brend_name_1' => 'brend_name_1',
'brend_name_2' => 'brend_name_2',
'brend_name_3' => 'brend_name_3',
'ral_code_1' => 'ral_1',
'ral_code_2' => 'ral_2',
'ral_code_3' => 'ral_3',
// Additional fields (only existing columns in construction_paint_logs)
'fluid_code' => 'fluid_code',
'fluid_code_description' => 'fluid_code_description',
'line' => 'line',
'unit' => 'area',
'spool_no_joint_no' => 'spool',
'iso_number' => 'iso_drawings'
];
// Prepare update data for construction_paint_logs
$updateData = [];
// Add fields from paint_follow_ups to updateData
foreach ($fieldMappings as $sourceField => $targetField) {
if (isset($paintFollowUp->$sourceField) && $paintFollowUp->$sourceField !== null) {
$updateData[$targetField] = $paintFollowUp->$sourceField;
}
}
Log::debug("Field mapping tamamlandı", [
'updateData' => $updateData,
'fieldMappings_count' => count($fieldMappings)
]);
// Add additional fields from line_lists.php comprehensive sync
// These fields are available in construction_paint_logs table
$additionalFields = [
'painting_system_type_1' => $paintFollowUp->cycle ?? '',
'painting_system_type_2' => $paintFollowUp->cycle ?? '',
/*
'rev' => '0', // Default revision
'isolation_info' => 'WEQE', // Default isolation info
'engineering' => 'DANIELI', // Default engineering
*/
'unit' => $paintFollowUp->area ?? '',
'test_package' => '',
'spool_status' => 'Waiting',
'construction_report_no' => '',
'dn_1' => '0',
'dn_2' => '0',
'dn_3' => '0',
'total_layer' => (float)($paintFollowUp->primer_measured_thickness_1 ?? 0) +
(float)($paintFollowUp->intermediate_measured_thickness_2 ?? 0) +
(float)($paintFollowUp->final_coating_measured_thickness_3 ?? 0)
];
// Merge additional fields into updateData
foreach ($additionalFields as $key => $value) {
if (!empty($value) || $value === '0' || $value === 0) {
$updateData[$key] = $value;
}
}
// Load temperature settings for volume and temperature calculations
$temperatures = j(setting("temperatures"));
$todayTempData = null;
// Get protocol_date_cleaning from paint_follow_ups to determine temperature data
// Only proceed if protocol_date_cleaning is not null, not empty, and not blank
if (!is_null($temperatures) &&
!empty($paintFollowUp->protocol_date_cleaning) &&
trim($paintFollowUp->protocol_date_cleaning) !== '') {
$protocolDate = Carbon::parse($paintFollowUp->protocol_date_cleaning);
$dayOfYear = $protocolDate->format('z');
$todayTempData = $temperatures[$dayOfYear] ?? null;
Log::debug('Temperature data loaded based on protocol_date_cleaning:', [
'protocol_date_cleaning' => $paintFollowUp->protocol_date_cleaning,
'day_of_year' => $dayOfYear,
'temp_data' => $todayTempData
]);
} else {
if (is_null($temperatures)) {
Log::debug('Temperature settings not found, temperature updates will be skipped');
} else {
Log::debug('No protocol_date_cleaning found, empty or blank - temperature updates will be skipped', [
'protocol_date_cleaning_value' => $paintFollowUp->protocol_date_cleaning ?? 'NULL'
]);
}
}
// Only proceed if we have data to update
if (!empty($updateData)) {
// Set updated_at timestamp
$updateData['updated_at'] = now();
// Find matching records in construction_paint_logs by line and spool
$whereConditions = [
['iso_drawings', $paintFollowUp->iso_number],
['spool', $paintFollowUp->spool_no_joint_no]
];
// Also try to match by line if iso_number is empty
if (empty($paintFollowUp->iso_number) && !empty($paintFollowUp->line)) {
$whereConditions = [
'iso_drawings' => $paintFollowUp->iso_number,
'spool' => $paintFollowUp->spool_no_joint_no,
'painting_system_type_1' => $paintFollowUp->cycle
];
}
$affectedRows = DB::table('construction_paint_logs')
->where($whereConditions)
->update($updateData);
Log::debug("Construction Paint Logs güncellendi", [
'whereConditions' => $whereConditions,
'affectedRows' => $affectedRows,
'updateData' => $updateData
]);
// Update temperature fields in current paint_follow_ups record if todayTempData is available
if ($todayTempData) {
$tempUpdateDataPaintFollowUp = [];
// Add temperature data based on location (SHOP or FIELD)
if ($paintFollowUp->location === 'SHOP') {
if (empty($paintFollowUp->substrate_temprature)) {
$tempUpdateDataPaintFollowUp['substrate_temprature'] = $todayTempData['temp_material_shop'];
}
if (empty($paintFollowUp->ambient_temprature)) {
$tempUpdateDataPaintFollowUp['ambient_temprature'] = $todayTempData['shop_ambient'];
}
} elseif ($paintFollowUp->location === 'FIELD') {
if (empty($paintFollowUp->substrate_temprature)) {
$tempUpdateDataPaintFollowUp['substrate_temprature'] = $todayTempData['temp_material_field'];
}
if (empty($paintFollowUp->ambient_temprature)) {
$tempUpdateDataPaintFollowUp['ambient_temprature'] = $todayTempData['field_ambient'];
}
}
if (!empty($tempUpdateDataPaintFollowUp)) {
$tempUpdateDataPaintFollowUp['updated_at'] = now();
DB::table('paint_follow_ups')
->where('id', $id)
->update($tempUpdateDataPaintFollowUp);
Log::debug("Updated temperature fields for current paint follow up record", [
'record_id' => $id,
'location' => $paintFollowUp->location,
'updated_fields' => array_keys($tempUpdateDataPaintFollowUp)
]);
}
}
// Sync thickness values from construction_paint_logs back to paint_follow_ups
$constructionPaintLog = DB::table('construction_paint_logs')
->where($whereConditions)
->first();
if ($constructionPaintLog) {
Log::debug("Construction Paint Log bulundu, kalınlık değerleri senkronize ediliyor", [
'constructionPaintLog' => (array)$constructionPaintLog
]);
// Update thickness values from construction_paint_logs
$thicknessUpdateData = [
'primer_measured_thickness_1' => $constructionPaintLog->thickness_1,
'intermediate_measured_thickness_2' => $constructionPaintLog->thickness_2,
'final_coating_measured_thickness_3' => $constructionPaintLog->thickness_3,
'total_thickness' => (float)($constructionPaintLog->thickness_1 ?? 0) +
(float)($constructionPaintLog->thickness_2 ?? 0) +
(float)($constructionPaintLog->thickness_3 ?? 0),
'updated_at' => now()
];
$thicknessAffected = DB::table('paint_follow_ups')
->where('id', $id)
->update($thicknessUpdateData);
Log::debug("Paint Follow Ups kalınlık güncellemesi", [
'id' => $id,
'thicknessUpdateData' => $thicknessUpdateData,
'affectedRows' => $thicknessAffected
]);
// Note: Temperature fields are only updated in paint_follow_ups table
// construction_paint_logs table does not have temperature columns
} else {
Log::debug("Construction Paint Log bulunamadı", [
'whereConditions' => $whereConditions
]);
}
// Sync with Incoming Control Paints for each brand
$brands = ['brend_name_1', 'brend_name_2', 'brend_name_3'];
foreach ($brands as $index => $brandField) {
if (!empty($paintFollowUp->$brandField)) {
Log::debug("Marka için incoming_control_paints aranıyor", [
'brandField' => $brandField,
'brandValue' => $paintFollowUp->$brandField
]);
// Get the latest incoming control paint record for this brand
$incomingControl = DB::table('incoming_control_paints')
->where('brend_name', $paintFollowUp->$brandField)
->orderBy('rfi_date', 'desc')
->first();
if ($incomingControl) {
Log::debug("Incoming control paint bulundu", [
'incomingControl' => (array)$incomingControl
]);
$suffix = $index + 1;
$incomingUpdateData = [
'incoming_control_akt_no_' . $suffix => $incomingControl->akt_number,
'incoming_control_rfi_no_' . $suffix => $incomingControl->rfi_no,
'akt_date_' . $suffix => $incomingControl->akt_date,
'standartgost_iso_en_' . $suffix => $incomingControl->manufacturing_standard,
'certificate_passport_no_' . $suffix => $incomingControl->certificate_no,
'certificate_passport_date_' . $suffix => $incomingControl->certificate_date,
'updated_at' => now()
];
$incomingAffected = DB::table('paint_follow_ups')
->where('id', $id)
->update($incomingUpdateData);
Log::debug("Paint Follow Ups incoming control güncellemesi", [
'id' => $id,
'incomingUpdateData' => $incomingUpdateData,
'affectedRows' => $incomingAffected
]);
// Update construction_paint_logs with incoming control data
if ($affectedRows > 0) {
/*
$constructionIncomingUpdateData = [
'rfi_no_' . $suffix => $incomingControl->rfi_no,
'updated_at' => now()
];
// Update construction_paint_logs with incoming control data
$constructionIncomingAffected = DB::table('construction_paint_logs')
->where($whereConditions)
->update($constructionIncomingUpdateData);
Log::debug("Construction Paint Logs incoming control güncellendi", [
'whereConditions' => $whereConditions,
'constructionIncomingUpdateData' => $constructionIncomingUpdateData,
'affectedRows' => $constructionIncomingAffected
]);
*/
}
} else {
Log::debug("Incoming control paint bulunamadı", [
'brandField' => $brandField,
'brandValue' => $paintFollowUp->$brandField
]);
}
}
}
Log::debug("Paint Follow Ups to Construction Paint Logs sync tamamlandı", [
'paintFollowUpId' => $id,
'affectedRows' => $affectedRows
]);
} else {
Log::debug("Senkronize edilecek alan yok", [
'paintFollowUpId' => $id
]);
}
} else {
Log::debug("Paint Follow Up bulunamadı", [
'id' => $id
]);
}
// Run spool status changer after paint follow ups sync
$spool_number = $paintFollowUp->spool_no_joint_no ?? null;
$line_number = $paintFollowUp->line ?? null;
spoolStatusChanger($line_number, $spool_number);
Log::debug("=== PAINT FOLLOW UPS SYNC BAŞARIYLA TAMAMLANDI ===", [
'id' => $id,
'timestamp' => now()
]);
} catch (\Exception $e) {
Log::error("Paint Follow Ups synchronization failed: " . $e->getMessage(), [
'id' => $id,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
throw $e;
}
@@ -0,0 +1,108 @@
<?php
$id = $request['key'];
$paintMatrix = db('paint_matrices')->where(is_array($id) ? $id : ['id' => $id])->first();
// Get external_finish_type from line_lists
$lineList = db('line_lists')
->where('line_no', $paintMatrix->line)
->first();
$updateArray = [
'cycle' => $paintMatrix->paint_cycle,
'primer_coat_name_1' => $paintMatrix->primer_coat,
'brend_name_1' => $paintMatrix->brend_name_1,
'colour_1' => $paintMatrix->colour_1,
'ral_code_1' => $paintMatrix->ral_code_1,
'thickness_1' => $paintMatrix->thickness_1,
'intermediate_coat_name_2' => $paintMatrix->intermediate_coat,
'brend_name_2' => $paintMatrix->brend_name_2,
'colour_2' => $paintMatrix->colour_2,
'ral_code_2' => $paintMatrix->ral_code_2,
'thickness_2' => $paintMatrix->thickness_2,
'final_coat_name_3' => $paintMatrix->final_coat,
'brend_name_3' => $paintMatrix->brend_name_3,
'colour_3' => $paintMatrix->colour_3,
'ral_code_3' => $paintMatrix->ral_code_3,
'thickness_3' => $paintMatrix->thickness_3,
'project' => $paintMatrix->project,
'description' => $paintMatrix->description,
'area' => $paintMatrix->area,
'line' => $paintMatrix->line,
'fluid_code' => $paintMatrix->fluid_code,
'fluid_code_description' => $paintMatrix->fluid_code_description,
'total_thickness' => floatval($paintMatrix->thickness_1 ?? 0) + floatval($paintMatrix->thickness_2 ?? 0) + floatval($paintMatrix->thickness_3 ?? 0),
];
$existingRecords = db('paint_follow_ups')->where([
'line' => $paintMatrix->line,
'area' => $paintMatrix->area,
])->get();
if ($existingRecords->isEmpty()) {
// Create new record if none exists
$updateArray['created_at'] = now();
$result = db('paint_follow_ups')->insert($updateArray);
dump("New record created in Paint Follow Ups");
} else {
// Update existing records
$result = db('paint_follow_ups')->where([
'line' => $paintMatrix->line,
'area' => $paintMatrix->area,
])
->whereNull('primer_coating_start_date')
->update($updateArray);
dump("$result data sync Paint Matrix ==> Paint Follow Ups");
}
// Sync to construction_paint_logs table
$constructionPaintLogData = [
// Painting System
'painting_system_type_1' => $paintMatrix->paint_cycle,
'painting_system_type_2' => $paintMatrix->paint_cycle,
'brend_name_1' => $paintMatrix->brend_name_1,
'ral_1' => $paintMatrix->ral_code_1,
'thickness_1' => $paintMatrix->thickness_1,
'brend_name_2' => $paintMatrix->brend_name_2,
'ral_2' => $paintMatrix->ral_code_2,
'thickness_2' => $paintMatrix->thickness_2,
'brend_name_3' => $paintMatrix->brend_name_3,
'ral_3' => $paintMatrix->ral_code_3,
'thickness_3' => $paintMatrix->thickness_3,
// Project Information
'unit' => $paintMatrix->area,
'line' => $paintMatrix->line,
'fluid_code' => $paintMatrix->fluid_code,
'fluid_code_description' => $paintMatrix->fluid_code_description,
'isolation_info' => $lineList ? $lineList->external_finish_type : null,
// Timestamps
'updated_at' => now()
];
// Update existing records or create new ones
$whereCondition = [
'line' => $paintMatrix->line,
'unit' => $paintMatrix->area
];
// Check if record exists
$existingRecord = db('construction_paint_logs')
->where($whereCondition)
->first();
if ($existingRecord) {
// Update existing record
$updatedPaintLog = db('construction_paint_logs')
// ->where('id', $existingRecord->id)
->whereNull('painting_date_1')
->update($constructionPaintLogData);
dump("$updatedPaintLog Construction paint log updated for line: " . $whereCondition['line']);
} else {
// Create new record
$constructionPaintLogData['created_at'] = now();
db('construction_paint_logs')->insert($constructionPaintLogData);
dump("New construction paint log created for line: " . $whereCondition['line']);
}
?>
@@ -0,0 +1,379 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
$id = $request['key'];
// Get paint system data for the current ID
$paintSystem = DB::table('paint_systems')->where(is_array($id) ? $id : ['id' => $id])->first();
if (!$paintSystem) {
Log::debug("Paint system record not found", ['id' => $id]);
return;
}
Log::debug("Starting synchronization from Paint Systems", [
'paint_cycle' => $paintSystem->paint_cycle
]);
DB::beginTransaction();
try {
// Skip processing if essential fields are missing
if (empty($paintSystem->paint_cycle)) {
Log::debug("Skipping synchronization - missing paint_cycle");
DB::commit();
return;
}
// ===== SYNC TO CONSTRUCTION_PAINT_LOGS =====
Log::debug("Syncing to Construction Paint Logs");
// Field mappings from paint_systems to construction_paint_logs
// Only including relevant fields based on construction_paint_logs table structure
$cpUpdateData = [
// Essential paint system fields
'rev' => $paintSystem->revision ?? '',
// First layer
'brend_name_1' => $paintSystem->brand_name_1 ?? $paintSystem->brend_name_1 ?? '',
'thickness_1' => $paintSystem->thickness_1 ?? '',
// Second layer
'brend_name_2' => $paintSystem->brand_name_2 ?? $paintSystem->brend_name_2 ?? '',
'thickness_2' => $paintSystem->thickness_2 ?? '',
// Third layer
'brend_name_3' => $paintSystem->brand_name_3 ?? $paintSystem->brend_name_3 ?? '',
'thickness_3' => $paintSystem->thickness_3 ?? '',
// Totals
'total_layer' => $paintSystem->total_kg ?? '',
// Timestamps
'updated_at' => now(),
'created_at' => DB::raw('CASE WHEN created_at IS NULL THEN NOW() ELSE created_at END')
];
// Remove empty fields to avoid overwriting existing data with empty values
foreach ($cpUpdateData as $key => $value) {
if ($value === '' && $key !== 'painting_system_type_1') { // Keep the key field
unset($cpUpdateData[$key]);
}
}
// Log the fields being synced
if (count($cpUpdateData) > 2) { // >2 because 'updated_at' and 'created_at' are always included
Log::debug("Syncing fields to Construction Paint Logs", ['fields' => array_diff_key($cpUpdateData, array_flip(['updated_at', 'created_at']))]);
} else {
Log::debug("No relevant data found to sync to Construction Paint Logs. Only updating timestamp.");
}
// Count existing records for logging purposes
$existingCount1 = DB::table('construction_paint_logs')
->where('painting_system_type_1', $paintSystem->paint_cycle)
->count();
$existingCount2 = DB::table('construction_paint_logs')
->where('painting_system_type_2', $paintSystem->paint_cycle)
->count();
// Get all existing records to check which ones to update vs create
$existingRecords = DB::table('construction_paint_logs')
->where('painting_system_type_1', $paintSystem->paint_cycle)
->orWhere('painting_system_type_2', $paintSystem->paint_cycle)
->get();
$cpUpdatedCount = 0;
$cpCreatedCount = 0;
// Construction Paint Logs işlemlerini chunk'lara böl
$existingRecordsChunked = $existingRecords->chunk(10); // 10'lu gruplar
foreach($existingRecordsChunked as $recordsChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($recordsChunk, $paintSystem, $cpUpdateData, &$cpUpdatedCount, &$cpCreatedCount) {
if ($recordsChunk->isNotEmpty()) {
// Update existing records
foreach ($recordsChunk as $record) {
// Create a copy of updateData to avoid modifying the original
$recordUpdateData = $cpUpdateData;
// For existing records, don't modify painting_system_type fields to avoid breaking relations
if ($record->painting_system_type_1 === $paintSystem->paint_cycle) {
unset($recordUpdateData['painting_system_type_2']); // Don't change type_2 if type_1 matches
} else {
unset($recordUpdateData['painting_system_type_1']); // Don't change type_1 if type_2 matches
}
DB::table('construction_paint_logs')
->where('id', $record->id)
->whereNull('painting_date_1')
->update($recordUpdateData);
$cpUpdatedCount++;
}
Log::debug("Updated existing Construction Paint Logs records", ['count' => $cpUpdatedCount]);
} else {
Log::debug("No existing Construction Paint Logs records found", ['paint_cycle' => $paintSystem->paint_cycle]);
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
// ===== SYNC TO PAINT_MATRICES =====
Log::debug("Syncing to Paint Matrices");
// Get RAL codes JSON for Russian color mapping
$ralCodes = j(setting("ral-codes"));
// Helper function to find Russian color description from RAL code
$findRussianColorDescription = function($ralCodes, $ralCode) {
if (empty($ralCode)) {
return '';
}
foreach ($ralCodes as $entry) {
if (isset($entry['ral_code']) && $entry['ral_code'] == $ralCode && isset($entry['ru'])) {
return $entry['ru'];
}
}
return '';
};
// Field mappings from paint_systems to paint_matrices
$pmUpdateData = [
// Main identifiers
'paint_cycle' => $paintSystem->paint_cycle ?? '',
// Preparation fields
'surface_preparation' => $paintSystem->surface_preparation ?? '',
'touch_up_of_damaged_parts' => $paintSystem->surface_roughness ?? '',
// First layer (Primer coat)
'primer_coat' => $paintSystem->primer_coat_name_1 ?? '',
'brend_name_1' => $paintSystem->brand_name_1 ?? '',
'thickness_1' => $paintSystem->thickness_1 ?? '',
// Second layer (Intermediate coat)
'intermediate_coat' => $paintSystem->primer_coat_name_2 ?? '',
'brend_name_2' => $paintSystem->brand_name_2 ?? '',
'thickness_2' => $paintSystem->thickness_2 ?? '',
// Third layer (Final coat)
'final_coat' => $paintSystem->primer_coat_name_3 ?? '',
'brend_name_3' => $paintSystem->brand_name_3 ?? '',
'thickness_3' => $paintSystem->thickness_3 ?? '',
// Totals
'total_thickness' => ($paintSystem->thickness_1 ?? 0) + ($paintSystem->thickness_2 ?? 0) + ($paintSystem->thickness_3 ?? 0) ?? '',
// Timestamps
'updated_at' => now()
];
// Remove empty fields to avoid overwriting existing data with empty values
foreach ($pmUpdateData as $key => $value) {
if ($value === '' && $key !== 'paint_cycle') { // Keep the key field
unset($pmUpdateData[$key]);
}
}
// Log the fields being synced (base fields, color data will be added per matrix)
if (count($pmUpdateData) > 2) { // >2 because 'updated_at' is always included
Log::debug("Syncing fields to Paint Matrices (base data from paint_systems)", ['fields' => array_diff_key($pmUpdateData, array_flip(['updated_at']))]);
Log::debug("Color data (RAL codes and Russian descriptions) will be fetched from color_systems for each matrix based on fluid_code");
} else {
Log::debug("No relevant data found to sync to Paint Matrices. Only updating timestamp.");
}
// Paint Matrices işlemlerini chunk'lara böl
$paintMatrices = DB::table('paint_matrices')
->where('paint_cycle', $paintSystem->paint_cycle)
->get();
$paintMatricesChunked = $paintMatrices->chunk(8); // 8'li gruplar
$pmUpdatedCount = 0;
foreach($paintMatricesChunked as $matricesChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($matricesChunk, $pmUpdateData, $findRussianColorDescription, $ralCodes, &$pmUpdatedCount) {
foreach($matricesChunk as $matrix) {
// Create a copy of update data for each matrix
$matrixUpdateData = $pmUpdateData;
// Get color system data for this matrix's fluid_code
if (!empty($matrix->fluid_code)) {
$colorSystem = DB::table('color_systems')
->where('fluid_code', $matrix->fluid_code)
->first();
if ($colorSystem) {
// Get RAL values from color_systems
$ral1 = $colorSystem->ral_1 ?? $colorSystem->ral_code_1 ?? '';
$ral2 = $colorSystem->ral_2 ?? $colorSystem->ral_code_2 ?? '';
$ral3 = $colorSystem->ral_3 ?? $colorSystem->ral_code_3 ?? '';
// Get Russian color descriptions
$colorRu1 = $findRussianColorDescription($ralCodes, $ral1);
$colorRu2 = $findRussianColorDescription($ralCodes, $ral2);
$colorRu3 = $findRussianColorDescription($ralCodes, $ral3);
// Add RAL codes and Russian colors to update data
$matrixUpdateData['ral_code_1'] = $ral1;
$matrixUpdateData['ral_code_2'] = $ral2;
$matrixUpdateData['ral_code_3'] = $ral3;
$matrixUpdateData['colour_1'] = $colorRu1;
$matrixUpdateData['colour_2'] = $colorRu2;
$matrixUpdateData['colour_3'] = $colorRu3;
// Add fluid code description and temperature data
$matrixUpdateData['fluid_code_description'] = $colorSystem->fluid_code_description ?? '';
$matrixUpdateData['design_temperature'] = $colorSystem->design_temperature ?? '';
$matrixUpdateData['operation_temperature'] = $colorSystem->working_temperature ?? '';
Log::debug("Added color data for matrix {$matrix->id} - fluid_code: {$matrix->fluid_code}, RAL1: {$ral1}, Color1: {$colorRu1}");
} else {
Log::debug("No color system found for fluid_code: {$matrix->fluid_code} in matrix {$matrix->id}");
}
}
DB::table('paint_matrices')
->where('id', $matrix->id)
->update($matrixUpdateData);
$pmUpdatedCount++;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
if ($pmUpdatedCount > 0) {
Log::debug("Updated Paint Matrices records with paint system and color system data", ['count' => $pmUpdatedCount]);
} else {
Log::debug("No Paint Matrices records found", ['paint_cycle' => $paintSystem->paint_cycle]);
}
// ===== SYNC TO PAINT_FOLLOW_UPS =====
Log::debug("Syncing to Paint Follow Ups");
// Field mappings from paint_systems to paint_follow_ups
$pfUpdateData = [
// Main identifiers
'cycle' => $paintSystem->paint_cycle ?? '',
// Preparation fields
'surface_preparation_equipment' => $paintSystem->surface_preparation ?? '',
'surface_roughness' => $paintSystem->surface_roughness ?? '',
// First layer
'primer_coat_name_1' => $paintSystem->primer_coat_name_1 ?? '',
'brend_name_1' => $paintSystem->brand_name_1 ?? '',
'thickness_1' => $paintSystem->thickness_1 ?? '',
// Second layer
'intermediate_coat_name_2' => $paintSystem->primer_coat_name_2 ?? '',
'brend_name_2' => $paintSystem->brand_name_2 ?? '',
'thickness_2' => $paintSystem->thickness_2 ?? '',
// Third layer
'final_coat_name_3' => $paintSystem->primer_coat_name_3 ?? '',
'brend_name_3' => $paintSystem->brand_name_3 ?? '',
'thickness_3' => $paintSystem->thickness_3 ?? '',
// Totals
'total_thickness' => ($paintSystem->thickness_1 ?? 0) + ($paintSystem->thickness_2 ?? 0) + ($paintSystem->thickness_3 ?? 0),
// Timestamps
'updated_at' => now(),
'created_at' => DB::raw('CASE WHEN created_at IS NULL THEN NOW() ELSE created_at END')
];
// Remove empty fields to avoid overwriting existing data with empty values
foreach ($pfUpdateData as $key => $value) {
if ($value === '' && $key !== 'cycle') { // Keep the key field
unset($pfUpdateData[$key]);
}
}
// Log the fields being synced
if (count($pfUpdateData) > 2) { // >2 because timestamps are always included
Log::debug("Syncing fields to Paint Follow Ups", ['fields' => array_diff_key($pfUpdateData, array_flip(['updated_at', 'created_at']))]);
} else {
Log::debug("No relevant data found to sync to Paint Follow Ups. Only updating timestamp.");
}
// Paint Follow Ups işlemlerini chunk'lara böl
$paintFollowUps = DB::table('paint_follow_ups')
->where('cycle', $paintSystem->paint_cycle)
->whereNull('primer_coating_start_date')
->get();
$paintFollowUpsChunked = $paintFollowUps->chunk(8); // 8'li gruplar
$pfUpdatedCount = 0;
foreach($paintFollowUpsChunked as $followUpsChunk) {
// Her chunk için ayrı transaction
DB::transaction(function () use ($followUpsChunk, $pfUpdateData, &$pfUpdatedCount) {
foreach($followUpsChunk as $followUp) {
DB::table('paint_follow_ups')
->where('id', $followUp->id)
->update($pfUpdateData);
$pfUpdatedCount++;
}
}, 3); // 3 deneme ile retry
// Her chunk arasında kısa bekleme
usleep(100000); // 0.1 saniye
}
if ($pfUpdatedCount > 0) {
Log::debug("Updated Paint Follow Ups records", ['count' => $pfUpdatedCount]);
} else {
// Check if this paint_cycle exists in weld_logs before creating new record
$weldLogExists = DB::table('weld_logs')
->where('painting_cycle', $paintSystem->paint_cycle)
->exists();
if ($weldLogExists) {
// If no records with this cycle exist but weld_log exists, create a new one
$newRecordData = array_merge($pfUpdateData, [
'cycle' => $paintSystem->paint_cycle ?? '',
'status' => 'Not Started',
'created_at' => now()
]);
// DB::table('paint_follow_ups')->insert($newRecordData);
Log::debug("Created new Paint Follow Ups record", ['cycle' => $paintSystem->paint_cycle]);
} else {
Log::debug("Skipped creating Paint Follow Ups record - no related weld_log found", ['cycle' => $paintSystem->paint_cycle]);
}
}
DB::commit();
Log::debug("Synchronization completed", [
'construction_paint_logs' => ['updated' => $cpUpdatedCount, 'created' => $cpCreatedCount],
'paint_matrices' => ['updated' => $pmUpdatedCount],
'paint_follow_ups' => ['updated' => $pfUpdatedCount]
]);
} catch (\Throwable $th) {
DB::rollback();
Log::error("Error synchronizing from Paint Systems: " . $th->getMessage());
// Log detailed error information for debugging
Log::error("Error details: ", [
'paintSystemId' => $id,
'paint_cycle' => $paintSystem->paint_cycle ?? 'unknown',
'exception' => get_class($th),
'file' => $th->getFile(),
'line' => $th->getLine(),
'trace' => $th->getTraceAsString()
]);
}
?>
@@ -0,0 +1,91 @@
<?php
use App\Models\PunchList;
use App\Models\TestPackage;
use App\Models\TestPackBaseStatus;
$id = $request['key'];
$punchListOne = PunchList::where("id", $id)->first();
$punchLists = PunchList::where("test_package", $punchListOne->test_package)->get();
$punchTotal = [];
$punchTotalTP = [];
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(!isset($punchTotalTP[$punchList->test_package][$punchList->category])) {
$punchTotalTP[$punchList->test_package][$punchList->category] = 0;
}
if($punchList->status == "Open") {
$punchTotal[$punchList->line_isometric_no][$punchList->test_package][$punchList->category]++;
}
if($punchList->status == "Open") {
$punchTotalTP[$punchList->test_package][$punchList->category]++;
}
}
$count = 0;
$count2 = 0;
foreach($punchTotalTP AS $testPackage => $subData)
{
$punchStatus = $punchList->status;
if(@$subData['A']>0) {
$punchStatus = "Open";
}
$updatedCount = TestPackage::where([
"test_package_number" => $testPackage,
])->update([
'a_punch_point_open' => @$subData['A'],
'b_punch_point_open' => @$subData['B'],
'c_punch_point_open' => @$subData['C'],
'punch_list' => $punchList->punch_list_no,
'punch_status' => $punchStatus,
'walkdown_date' => $punchList->found_date,
]);
$count2 += $updatedCount;
}
foreach($punchTotal AS $isoNumber => $subData) {
foreach($subData AS $testPackage => $data) {
$updatedCount = TestPackBaseStatus::where([
"test_package_no" => $testPackage,
"drawing_no" => $isoNumber,
])->update([
'punch_a_quantity' => @$data['A'],
'punch_status' => $punchList->status,
'punch_b_quantity' => @$data['B'],
'punch_c_quantity' => @$data['C'],
]);
$count += $updatedCount;
}
}
dump("$count Calculated Punch List ==> Test Pack ISO Base Status");
dump("$count2 Calculated Punch List ==> Test Pack Base Status");
?>
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,12 @@
<?php
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
if (isset($data['source_project'])) {
Log::info("SaveTrigger: naks_expert (register_of_experts) updated. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'expert',
'source_project' => config('app.name', 'Unknown Project'),
]);
}
@@ -0,0 +1,194 @@
<?php
$data = db($tableName)->where($request['key'])->first();
$whereData = [
'no_of_the_joint_as_per_as_built_survey' => $data->new_joint_no,
'iso_number' => $data->iso_number,
];
$acceptColumns = [
'new_joint_no',
'general_contractor',
'contractor',
'ste_subcontractor',
'project',
'design_area',
'line_specification',
'line_number',
'main_material',
'main_nps',
'fluid_code',
'service_category',
'fluid_group',
'piping_type',
'piping_class',
'design_temperature_s',
'design_pressure_mpa',
'operating_temperature_s',
'operating_pressure_mpa',
'painting_cycle',
'external_finish_type',
'iso_number',
'quantity_of_iso',
'iso_rev',
'spool_number',
'spool_release_date',
'type_of_joint',
'type_of_welds',
'pose_no_1',
'element_code_1',
'member_no_1',
'material_no_1',
'product_standart_1',
'ru_material_group_1',
'certificate_number_of_1',
'heat_number_1',
'nps_1',
'thickness_by_asme_1',
'outside_diameter_1',
'wall_thickness_1',
'pose_no_2',
'element_code_2',
'member_no_2',
'material_no_2',
'product_standart_2',
'ru_material_group_2',
'certificate_number_of_2',
'heat_number_2',
'nps_2',
'thickness_by_asme_2',
'outside_diameter_2',
'wall_thickness_2',
'ndt_percent',
'vt_scope',
'rt_scope',
'ut_scope',
'pt_scope',
'mt_scope',
'pmi_scope',
'pwht',
'ht_scope',
'ferrite_scope',
'test_package_no',
'test_pressure',
'type_of_test',
'ste_subcontructer',
];
$insertData = [];
foreach($data AS $column => $value) {
if(in_array($column, $acceptColumns)) {
if($column == "new_joint_no") $column = 'no_of_the_joint_as_per_as_built_survey';
if($value == "") $value = null;
$insertData[$column] = $value;
}
}
dump($insertData);
db("weld_logs")->updateOrInsert($whereData, $insertData);
$repairLogs = db("repair_logs")
->where("test_package_no", $data->test_package_no)
->get();
$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) && $repairLog->repair_status == "Done")
{
$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]++;
}
}
$tpNo = $data->test_package_no;
$isoNumber = $data->iso_number;
$updateData = [
'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", $data->iso_number)
->where("test_package_no", $data->test_package_no)
->update(
$updateData
);
$updateData = [
'repair_qty' => $repairLogsSummary2[$tpNo],
'repair_completed' => $repairLogsSummaryCompleted2[$tpNo],
'repair_remaining' => $repairLogsSummaryRemaining2[$tpNo],
];
dump($updateData);
db("test_packages")
->where("test_package_number", $data->test_package_no)
->update(
$updateData
);
// Update Cache for NDT Calculation
if (function_exists('dispatchCacheBladeViews')) {
dispatchCacheBladeViews([
[
'view' => 'admin-ajax.ndt-order.order-list-no-cache',
'cache' => 'ndt-order-list'
],
[
'view' => 'admin-ajax.ndt-calculation-no-cache',
'cache' => 'ndt-calculation'
],
[
'view' => 'admin-ajax.repair-log-no-cache',
'cache' => 'repair-log'
]
]);
}
?>
@@ -0,0 +1,28 @@
<?php
$id = $request['key'];
// Get the updated subcontractor record
$subcontractor = db("subcontractors")->where("id", $id)->first();
dump($subcontractor);
if ($subcontractor) {
// Update work_permit_documents table to sync job_description and sign_order
$updateWorkPermitDocuments = db("work_permit_documents")
->where("company", $subcontractor->company_name_ru)
->update([
'job_description' => $subcontractor->job_description,
'company_sign_order' => $subcontractor->sign_order
]);
dump([
"message" => "Subcontractor data synced to work_permit_documents",
"updated_records" => $updateWorkPermitDocuments,
"company" => $subcontractor->company_name_ru
]);
} else {
dump([
"message" => "Subcontractor not found",
"company" => $subcontractor->company_name_ru
]);
}
?>
@@ -0,0 +1,235 @@
<?php
$data = db("supports")->where("id", $request['key'])->first();
$uniqueFields = [
'line' => $data->drawing_no,
'component_code_id' => $data->support_code,
];
$dataToUpdate = [
'project' => $data->zone,
'line' => $data->line_number,
'rev' => $data->rev,
'discipline' => 'Piping Support',
'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->pipe_dia,
'dn_1' => $data->pipe_dia,
'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->total_weight,
// 'total_weight' => $data->line_number,
'designer' => $data->designer,
];
echo db('m_t_o_s')->updateOrInsert($uniqueFields, $dataToUpdate);
//dump("save trigger");
dump($dataToUpdate);
// Update or insert into weld_logs table
db("weld_logs")
->where([
'iso_number' => $data->drawing_no,
'element_code_1' => $data->support_code,
])
->update([
'product_standart_1' => $data->standart
]);
db("weld_logs")
->where([
'iso_number' => $data->drawing_no,
'element_code_2' => $data->support_code,
])
->update([
'product_standart_2' => $data->standart
]);
$isoToTP = db("weld_logs")
->where("line_number", $data->line_number)
->select('test_package_no', 'line_number')->pluck('test_package_no', 'line_number');
$supports = db("supports")->where("line_number", $data->line_number)->get();
$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($support->erection_type == "Weld")
{
$thisQty = $support->quantity - $support->assembled_su_rt_quanti;
if(!rejected_date($support->weld_or_assembled_date))
{
$supportStats[$support->line_number]['welded_support_quantity']+= $thisQty;
$supportStatsTP[$tpNo]['welded_support_quantity']+= $thisQty;
$supportStats[$support->line_number]['support_remaining']+= $support->assembled_su_rt_quanti;
$supportStatsTP[$tpNo]['support_remaining']+= $support->assembled_su_rt_quanti;
} else {
$supportStats[$support->line_number]['support_remaining']+= $thisQty;
$supportStatsTP[$tpNo]['support_remaining']+= $thisQty;
}
}
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
}
}
dump($supportStatsTP);
dump($supportStats);
// Repair logs calculation - similar to repair_logs.php
$repairLogs = db("repair_logs")
->whereIn("iso_number", array_keys($supportStats))
->get();
$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;
$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]++;
}
}
dump("Repair Logs Summary:");
dump($repairLogsSummary);
dump($repairLogsSummaryCompleted);
dump($repairLogsSummaryRemaining);
foreach($supportStats AS $isoNumber => $thisSupportStats)
{
if($isoNumber != "")
{
// Get test package number for this ISO
$tpNo = @$isoToTP[$isoNumber];
// Prepare update data with repair information
$updateData = [
'welded_support_quantity' => $thisSupportStats['welded_support_quantity'],
'support_remaining' => $thisSupportStats['support_remaining'],
'support_progress' => $thisSupportStats['support_progress'],
];
// Add repair data if available
if($tpNo && isset($repairLogsSummary[$isoNumber][$tpNo])) {
$updateData['repair_qty'] = $repairLogsSummary[$isoNumber][$tpNo];
$updateData['repair_completed'] = $repairLogsSummaryCompleted[$isoNumber][$tpNo];
$updateData['repair_remaining'] = $repairLogsSummaryRemaining[$isoNumber][$tpNo];
}
db("test_pack_base_statuses")
->where("drawing_no", $isoNumber)
->update($updateData);
}
}
// Update test packages with repair data as well
foreach($supportStatsTP AS $tpNo => $thisSupportStats)
{
if($tpNo != "")
{
// Prepare update data with repair information
$updateData = [
'welded_support_quantity' => $thisSupportStats['welded_support_quantity'],
'support_remaining' => $thisSupportStats['support_remaining'],
'support_progress' => $thisSupportStats['support_progress'],
];
// Add repair data if available
if(isset($repairLogsSummary2[$tpNo])) {
$updateData['repair_qty'] = $repairLogsSummary2[$tpNo];
$updateData['repair_completed'] = $repairLogsSummaryCompleted2[$tpNo];
$updateData['repair_remaining'] = $repairLogsSummaryRemaining2[$tpNo];
}
db("test_packages")
->where("test_package_number", $tpNo)
->update($updateData);
}
}
?>
@@ -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());
}
?>
@@ -0,0 +1,512 @@
<?php
use App\Models\TestPackage;
use App\Models\TestPackBaseStatus;
use Carbon\Carbon;
$testPackage = db("test_packages")->where("id", $request['key'])->first();
try {
db("test_pack_base_statuses")
->where("test_package_no", $testPackage->test_package_number)
->update([
'subcontractor' => $refactoringData['subcontractor']
]);
} catch (\Throwable $th) {
//throw $th;
}
$updateWeldLogTestDate = db("weld_logs")
->where("test_package_no", $testPackage->test_package_number)
->update([
'test_result' => $testPackage->test_status,
'date_test' => $testPackage->test_date,
]);
dump("updateWeldLogTestDate: $updateWeldLogTestDate");
$testPackages = TestPackage::where("test_package_number", $testPackage->test_package_number)->get();
$testPackagesIso = TestPackBaseStatus::where("test_package_no", $testPackage->test_package_number)->get();
$weldLogs = db("weld_logs")
->where("test_package_no", $testPackage->test_package_number)
->get();
$repairLogs = db("repair_logs")
->where("test_package_no", $testPackage->test_package_number)
->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());
//test package sttatus change
//test pack base status changer
$testPackages = TestPackage::where("test_package_number", $testPackage->test_package_number)->get();
$testPackagesIso = TestPackBaseStatus::where("test_package_no", $testPackage->test_package_number)->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',
];
$repairLogsSummary2 = [];
foreach($repairLogs AS $repairLog) {
if(!isset($repairLogsSummary2[$repairLog->test_package_no]))
$repairLogsSummary2[$repairLog->test_package_no] = 0;
if($repairLog->repair_status == "Not Done") {
$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;
}
}
$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]
]
);
}
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,
]
);
$k++;
}
DB::commit();
} catch (\Throwable $th) {
dump($th->getMessage());
DB::rollback();
}
// Sync weld logs to test packages for this specific test package
try {
$syncParams = [
'test_package_no' => $testPackage->test_package_number
];
$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_number);
} catch (\Throwable $th) {
Log::error("Weld logs sync failed for test package: " . $testPackage->test_package_number . " - " . $th->getMessage());
}
?>
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,2 @@
<?php
include 'ndt_log_cache_clear.php';
@@ -0,0 +1,150 @@
<?php
/**
* WeldLog Save Trigger - Refactored Version
*
* This file is the entry point for all weld log save triggers.
* All trigger logic has been extracted to separate classes in:
* app/Services/WeldLogTriggers/Triggers/
*
* The trigger system uses:
* - WeldLogTriggerInterface: Contract for all triggers
* - BaseTrigger: Base class with common functionality
* - WeldLogTriggerRegistry: Central registry for all triggers
* - WeldLogTriggerManager: Orchestrates trigger execution
*
* @see app/Services/WeldLogTriggers/
*/
use App\Services\WeldLogTriggers\WeldLogTriggerManager;
use App\Services\WeldLogTriggers\WeldLogTriggerRegistry;
use Illuminate\Support\Facades\Log;
// Memory and execution settings
ini_set('memory_limit', '2G');
ini_set('max_execution_time', 600); // 10 minutes
// Get weld log ID from request
$id = $request['key'];
// Fetch current weld log data
$data = db($tableName)->where("id", $id)->first();
if(is_null($data)) {
$data = db($tableName)->where($id)->first();
}
// Safety check - ensure we have data
if(is_null($data)) {
Log::error("WeldLog not found for trigger execution", [
'weld_log_id' => $id,
'table_name' => $tableName
]);
return;
}
// Detect if this is a new record
// beforeData comes from the Job - no need for additional checks
$isNewRecord = false;
if (is_null($beforeData)) {
// Batch Excel job'dan changedColumns geliyorsa bu yeni kayıt DEĞİL, update'tir
if (!empty($changedColumns)) {
$isNewRecord = false;
Log::info("WeldLog batch update detected (changedColumns present, beforeData null)", [
'weld_log_id' => $id,
'reason' => 'batch_excel_update'
]);
} else {
$isNewRecord = true;
Log::info("WeldLog new record detected", [
'weld_log_id' => $id,
'reason' => 'beforeData_is_null'
]);
}
} else {
// Check if all fields match - could be a new record
$allFieldsMatch = true;
$dataArray = (array) $data;
foreach ($dataArray as $key => $value) {
if (isset($beforeData->$key) && $beforeData->$key != $value) {
$allFieldsMatch = false;
break;
}
}
if ($allFieldsMatch) {
$isNewRecord = true;
Log::info("WeldLog new record detected", [
'weld_log_id' => $id,
'reason' => 'all_fields_match'
]);
}
}
// Detect changed fields
// Batch Excel job'dan changedColumns geliyorsa onu kullan (beforeData batch'te yanlış/null)
if (!empty($changedColumns)) {
$changedFields = $changedColumns;
// changedColumns varsa bu bir update'tir, tüm trigger'ları çalıştırma
if ($isNewRecord && !is_null($beforeData)) {
$isNewRecord = false;
}
Log::info("WeldLog using changedColumns from batch Excel", [
'weld_log_id' => $id,
'changed_columns_count' => count($changedColumns),
'changed_columns' => $changedColumns
]);
} else {
$changedFields = detectChangedFields($data, $beforeData);
}
Log::info("WeldLog changed fields detected", [
'weld_log_id' => $id,
'changed_fields' => $changedFields,
'changed_fields_count' => count($changedFields),
'is_new_record' => $isNewRecord,
'source' => !empty($changedColumns) ? 'batch_excel_columns' : 'detectChangedFields',
'action' => $action ?? 'unknown'
]);
// Initialize trigger system
$registry = new WeldLogTriggerRegistry();
$manager = new WeldLogTriggerManager($registry);
// Execute all triggers
try {
$results = $manager->executeTriggers(
$data,
$beforeData,
$changedFields,
$isNewRecord,
$action ?? null
);
Log::info("WeldLog triggers execution completed", [
'weld_log_id' => $id,
'results_summary' => array_map(function($result) {
if (isset($result['skipped']) && $result['skipped']) {
return 'skipped';
} elseif (isset($result['executed']) && $result['executed']) {
return 'executed';
} elseif (isset($result['queued']) && $result['queued']) {
return 'queued';
} elseif (isset($result['error'])) {
return 'failed';
}
return 'unknown';
}, $results)
]);
} catch (\Throwable $th) {
Log::error("WeldLog triggers execution failed with critical error", [
'weld_log_id' => $id,
'error' => $th->getMessage(),
'file' => $th->getFile(),
'line' => $th->getLine(),
'trace' => $th->getTraceAsString()
]);
// Re-throw to ensure error is visible
throw $th;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,24 @@
<?php
$id = $request['key'];
$data = db($tableName)->where("id", $id)->first();
$location = $data->shop_or_field;
$updateWelderLocation = db("welder_locations")
->where("naks_id", $data->naks_id)
->update([
'location' => $location
]);
$updateNaksWelders = db("naks_welders")
->where("welder_id", $data->naks_id)
->update([
'status' => $location
]);
dump([
"updateWelderLocation" => $updateWelderLocation,
"updateNaksWelders" => $updateNaksWelders
]);
?>
@@ -0,0 +1,12 @@
<?php
use App\Jobs\TriggerNaksSyncJob;
use Illuminate\Support\Facades\Log;
if (isset($data['source_project'])) {
Log::info("SaveTrigger: welding_equipment (NAKS Equipment) updated. Dispatching TriggerNaksSyncJob.");
TriggerNaksSyncJob::dispatch([
'module' => 'equipment',
'source_project' => config('app.name', 'Unknown Project'),
]);
}