64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\WeldLogTriggers\Triggers;
|
|
|
|
use App\Services\WeldLogTriggers\Base\BaseTrigger;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* NDE Project Update Trigger
|
|
*
|
|
* Updates NDE Matrix project field from weld_logs when it's null
|
|
* Syncs project information between tables
|
|
*/
|
|
class NdeProjectUpdateTrigger extends BaseTrigger
|
|
{
|
|
public function getName(): string
|
|
{
|
|
return 'NDE Project Update';
|
|
}
|
|
|
|
public function getOrder(): int
|
|
{
|
|
return 6;
|
|
}
|
|
|
|
public function getDependentFields(): array
|
|
{
|
|
return [
|
|
'line_number',
|
|
'project'
|
|
];
|
|
}
|
|
|
|
protected function process($data, $beforeData, array $context): array
|
|
{
|
|
// Update NDE matrices where project is null
|
|
$updatedCount = 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') // Find records where project column is empty
|
|
->where("weld_logs.id", $data->id)
|
|
->update([
|
|
'nde_matrices.project' => DB::raw('weld_logs.project') // Update with project value from weld_logs
|
|
]);
|
|
|
|
Log::info("NDE Matrix project field updated", [
|
|
'weld_log_id' => $data->id,
|
|
'line_number' => $data->line_number,
|
|
'design_area' => $data->design_area,
|
|
'project' => $data->project,
|
|
'updated_records' => $updatedCount
|
|
]);
|
|
|
|
return [
|
|
'success' => true,
|
|
'updated_records' => $updatedCount
|
|
];
|
|
}
|
|
}
|
|
|