İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
<?php function weldlog_accepted_columns() {
|
||||
return [
|
||||
'vt_result',
|
||||
'pwht',
|
||||
'ndt_percent',
|
||||
'vt_report',
|
||||
'vt_request_date',
|
||||
'vt_request_no',
|
||||
'vt_test_date',
|
||||
'test_laboratory_vt',
|
||||
'rt_request_no',
|
||||
'rt_request_date',
|
||||
'rt_report',
|
||||
'rt_test_date',
|
||||
'test_laboratory_rt',
|
||||
'rt_result',
|
||||
'ut_request_no',
|
||||
'ut_type',
|
||||
'ut_request_date',
|
||||
'ut_report',
|
||||
'ut_test_date',
|
||||
'test_laboratory_ut',
|
||||
'ut_result',
|
||||
'pt_request_no',
|
||||
'pt_request_date',
|
||||
'pt_report',
|
||||
'pt_test_date',
|
||||
'test_laboratory_pt',
|
||||
'pt_result',
|
||||
'mt_request_no',
|
||||
'mt_report',
|
||||
'mt_test_date',
|
||||
'test_laboratory_mt',
|
||||
'mt_result',
|
||||
'mt_request_date',
|
||||
'pmi_request_no',
|
||||
'pmi_request_date',
|
||||
'no_of_testing_report',
|
||||
'pmi_test_date',
|
||||
'test_laboratory_pmi',
|
||||
'pmi_result',
|
||||
'pwht_date',
|
||||
'pwht_request_no',
|
||||
'pwht_request_date',
|
||||
'no_of_pwht_report',
|
||||
'diagram_number_pwht',
|
||||
'test_laboratory_pwht',
|
||||
'ht_request_no',
|
||||
'no_of_ht_hardnes_test',
|
||||
'ht_request_date',
|
||||
'test_laboratory_ht',
|
||||
'diagram_number_pwht',
|
||||
'ht_test_date',
|
||||
'ht_result',
|
||||
'ht_request_date',
|
||||
'ferrite_request_no',
|
||||
'ferrite_request_date',
|
||||
'no_of_ferrite_check',
|
||||
'date_of_ferrite_check',
|
||||
'ferrite_test_date',
|
||||
'test_laboratory_ferrite',
|
||||
'ferrite_result',
|
||||
'ferrite_report',
|
||||
'pwht_result',
|
||||
'pwht_operator_id',
|
||||
'pwht_operator_name',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
function logToWeldlogUpdate($data) {
|
||||
$data = (Array) $data;
|
||||
// dump($data);
|
||||
if(isset($data['iso_number'])) {
|
||||
$isoNumber = $data['iso_number'];
|
||||
$jointNumber = $data['no_of_the_joint_as_per_as_built_survey'];
|
||||
$weldingDate = $data['welding_date'];
|
||||
|
||||
// Generate unique key for tracking this update
|
||||
$logKey = 'WELDLOG_SYNC_' . time() . '_' . rand(1000, 9999);
|
||||
|
||||
\Log::info("[$logKey] === logToWeldlogUpdate START ===");
|
||||
\Log::info("[$logKey] ISO Number: $isoNumber, Joint: $jointNumber, Welding Date: $weldingDate");
|
||||
|
||||
$updateData = [];
|
||||
$weldlogAcceptedColumns = weldlog_accepted_columns();
|
||||
|
||||
// Check which test types are canceled
|
||||
$canceledTests = [];
|
||||
foreach($data AS $column => $value) {
|
||||
if($value === 'Cancel / отмена') {
|
||||
// Check for standard _result pattern (e.g., 'vt_result', 'ferrite_result')
|
||||
if(strpos($column, '_result') !== false) {
|
||||
$testType = str_replace('_result', '', $column);
|
||||
$canceledTests[] = $testType;
|
||||
\Log::info("[$logKey] CANCEL DETECTED: Test type '$testType' is canceled (column: $column)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($canceledTests)) {
|
||||
\Log::info("[$logKey] No canceled tests found");
|
||||
} else {
|
||||
\Log::info("[$logKey] Canceled test types: " . implode(', ', $canceledTests));
|
||||
}
|
||||
|
||||
// Handle PWHT operator fields
|
||||
if(isset($data['pwht_operator_id'])) {
|
||||
$updateData['pwht_operator_id'] = $data['pwht_operator_id'];
|
||||
\Log::info("[$logKey] PWHT Operator ID: " . $data['pwht_operator_id']);
|
||||
}
|
||||
|
||||
if(isset($data['pwht_operator'])) {
|
||||
$updateData['pwht_operator_name'] = $data['pwht_operator'];
|
||||
\Log::info("[$logKey] PWHT Operator Name: " . $data['pwht_operator']);
|
||||
}
|
||||
|
||||
// Process all fields
|
||||
$canceledColumnsCount = 0;
|
||||
$normalColumnsCount = 0;
|
||||
$canceledColumnsList = [];
|
||||
|
||||
foreach($data AS $column => $value) {
|
||||
if(in_array($column, $weldlogAcceptedColumns)) {
|
||||
// Check if this column belongs to a canceled test
|
||||
$isCanceledColumn = false;
|
||||
foreach($canceledTests as $testType) {
|
||||
// Check if column contains the test type (e.g., 'vt' in 'test_laboratory_vt' or 'vt_result')
|
||||
if(strpos($column, $testType) !== false) {
|
||||
$isCanceledColumn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If canceled, set to null; otherwise process normally
|
||||
if($isCanceledColumn) {
|
||||
$canceledColumnsCount++;
|
||||
$canceledColumnsList[] = $column;
|
||||
$updateData[$column] = null;
|
||||
} else {
|
||||
$normalColumnsCount++;
|
||||
if($value == "") $value = null;
|
||||
$updateData[$column] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log only canceled columns
|
||||
if(!empty($canceledColumnsList)) {
|
||||
\Log::info("[$logKey] Columns set to NULL: " . implode(', ', $canceledColumnsList));
|
||||
}
|
||||
|
||||
\Log::info("[$logKey] Summary: $canceledColumnsCount columns set to NULL (canceled), $normalColumnsCount columns processed normally");
|
||||
|
||||
$whereData = [
|
||||
'iso_number' => $isoNumber,
|
||||
'no_of_the_joint_as_per_as_built_survey' => $jointNumber,
|
||||
'welding_date' => $weldingDate,
|
||||
];
|
||||
|
||||
\Log::info("[$logKey] WHERE condition: " . json_encode($whereData));
|
||||
\Log::info("[$logKey] UPDATE data: " . json_encode($updateData));
|
||||
|
||||
$result = db("weld_logs")
|
||||
->where($whereData)
|
||||
->update($updateData);
|
||||
|
||||
\Log::info("[$logKey] weld_logs UPDATE result: $result affected rows");
|
||||
|
||||
// Sync to other tables and clear cache
|
||||
if ($result > 0) {
|
||||
$weldLogId = db("weld_logs")
|
||||
->where($whereData)
|
||||
->value('id');
|
||||
|
||||
if ($weldLogId) {
|
||||
if (function_exists('syncTrigger')) {
|
||||
\Log::info("[$logKey] Calling syncTrigger for weld_logs ID: $weldLogId");
|
||||
syncTrigger('weld_logs', $weldLogId);
|
||||
}
|
||||
|
||||
if (function_exists('dispatchCacheBladeViews')) {
|
||||
\Log::info("[$logKey] Dispatching cache invalidation for NDT calculation");
|
||||
dispatchCacheBladeViews([
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-calculation-no-cache',
|
||||
'cache' => 'ndt-calculation'
|
||||
],
|
||||
[
|
||||
'view' => 'admin-ajax.ndt-order.order-list-no-cache',
|
||||
'cache' => 'ndt-order-list'
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repairLogUpdate($data);
|
||||
|
||||
\Log::info("[$logKey] === logToWeldlogUpdate END ===\n");
|
||||
|
||||
dump($whereData);
|
||||
dump($updateData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function repairLogUpdate($data) {
|
||||
// Check if any test result contains "Repair / Ремонт" or "Cut / Резать"
|
||||
$testResultFields = [
|
||||
'vt_result',
|
||||
'rt_result',
|
||||
'ut_result',
|
||||
'pt_result',
|
||||
'mt_result',
|
||||
'pmi_result',
|
||||
'ht_result',
|
||||
'ferrite_result'
|
||||
];
|
||||
|
||||
|
||||
// Convert object properties to array access
|
||||
$hasRepairOrCut = false;
|
||||
$allFieldsEmpty = true;
|
||||
$rtAndUtEmpty = false;
|
||||
|
||||
// Check if RT or UT results are empty (array access)
|
||||
if (empty($data['rt_result']) && empty($data['ut_result'])) {
|
||||
$rtAndUtEmpty = true;
|
||||
}
|
||||
|
||||
foreach ($testResultFields as $field) {
|
||||
if (isset($data[$field]) && !empty($data[$field])) {
|
||||
$allFieldsEmpty = false;
|
||||
if (in_array($data[$field], ['Repair / Ремонт', 'Cut / Резать'])) {
|
||||
$hasRepairOrCut = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine repair status based on test results
|
||||
if ($allFieldsEmpty || $rtAndUtEmpty) {
|
||||
$repairStatus = "Not Done";
|
||||
} elseif (!$hasRepairOrCut) {
|
||||
$repairStatus = "Done";
|
||||
} else {
|
||||
$repairStatus = "Repair";
|
||||
}
|
||||
|
||||
$affected = db("repair_logs")
|
||||
->where([
|
||||
'iso_number' => $data['iso_number'],
|
||||
'new_joint_no' => $data['no_of_the_joint_as_per_as_built_survey'],
|
||||
])
|
||||
->update([
|
||||
'repair_date' => $data['welding_date'],
|
||||
'repair_status' => $repairStatus,
|
||||
]);
|
||||
dump("repairLogUpdate affected rows: " . $affected);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user