İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\WeldLogTriggers\Triggers;
|
||||
|
||||
use App\Services\WeldLogTriggers\Base\BaseTrigger;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Repair Logs Update Trigger
|
||||
*
|
||||
* Updates repair logs based on test results
|
||||
* Determines repair status: "Not Done", "Done", or "Repair"
|
||||
*/
|
||||
class RepairLogsUpdateTrigger extends BaseTrigger
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Repair Logs Update';
|
||||
}
|
||||
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [
|
||||
'iso_number',
|
||||
'no_of_the_joint_as_per_as_built_survey',
|
||||
'welding_date',
|
||||
'vt_result',
|
||||
'rt_result',
|
||||
'ut_result',
|
||||
'pt_result',
|
||||
'mt_result',
|
||||
'pmi_result',
|
||||
'ht_result',
|
||||
'ferrite_result',
|
||||
];
|
||||
}
|
||||
|
||||
protected function process($data, $beforeData, array $context): array
|
||||
{
|
||||
// Test result fields to check
|
||||
$testResultFields = [
|
||||
'vt_result',
|
||||
'rt_result',
|
||||
'ut_result',
|
||||
'pt_result',
|
||||
'mt_result',
|
||||
'pmi_result',
|
||||
'ht_result',
|
||||
'ferrite_result'
|
||||
];
|
||||
|
||||
$hasRepairOrCut = false;
|
||||
$allFieldsEmpty = true;
|
||||
$rtAndUtEmpty = false;
|
||||
|
||||
// Check if RT or UT results are empty
|
||||
if(empty($data->rt_result) && empty($data->ut_result)) {
|
||||
$rtAndUtEmpty = true;
|
||||
}
|
||||
|
||||
// Check all test result fields
|
||||
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";
|
||||
}
|
||||
|
||||
// Update repair logs
|
||||
$updateResult = 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,
|
||||
]);
|
||||
|
||||
Log::info("Repair logs updated", [
|
||||
'iso_number' => $data->iso_number,
|
||||
'joint_no' => $data->no_of_the_joint_as_per_as_built_survey,
|
||||
'repair_status' => $repairStatus,
|
||||
'updated_records' => $updateResult,
|
||||
'has_repair_or_cut' => $hasRepairOrCut,
|
||||
'all_fields_empty' => $allFieldsEmpty,
|
||||
'rt_and_ut_empty' => $rtAndUtEmpty
|
||||
]);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'repair_status' => $repairStatus,
|
||||
'updated_records' => $updateResult
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user