72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\LineListTriggers\Triggers;
|
|
|
|
use App\Services\LineListTriggers\Base\BaseLineListTrigger;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Test Package Tracing Sync Trigger
|
|
*
|
|
* Syncs tracing_type from Line List to:
|
|
* - Test Packages (tracing field)
|
|
* - Test Pack Base Statuses (tracing field)
|
|
* - NDE Matrices (tracing and tracing_type fields)
|
|
* Triggered when tracing_type field changes in Line List
|
|
*/
|
|
class TestPackageTracingSyncTrigger extends BaseLineListTrigger
|
|
{
|
|
public function getName(): string
|
|
{
|
|
return 'Tracing Sync';
|
|
}
|
|
|
|
public function getDependentFields(): array
|
|
{
|
|
return ['tracing', 'tracing_type'];
|
|
}
|
|
|
|
protected function process($lineListData, $beforeData, array $context): array
|
|
{
|
|
// Update 'tracing' field in test_packages table where p_id matches line_no
|
|
// user requirement: p id no = line no match
|
|
// 1. Get test_package_no's from test_pack_base_statuses where drawing_no matches line_no
|
|
$testPackageNos = db('test_pack_base_statuses')
|
|
->where('drawing_no', $lineListData->line_no)
|
|
->pluck('test_package_no')
|
|
->toArray();
|
|
|
|
Log::info("Test Package Tracing Sync Trigger", [
|
|
'line_no' => $lineListData->line_no,
|
|
'test_package_nos' => $testPackageNos,
|
|
]);
|
|
// 2. Update test_packages where test_package_no matches the found ones
|
|
if (!empty($testPackageNos)) {
|
|
$result = db("test_packages")
|
|
->whereIn("test_package_number", $testPackageNos)
|
|
->update([
|
|
'tracing' => $lineListData->tracing
|
|
]);
|
|
} else {
|
|
$result = 0;
|
|
}
|
|
|
|
// No need to update test_pack_base_statuses per user request
|
|
|
|
// Sync to nde_matrices (using line_no)
|
|
|
|
|
|
Log::info("Line List Tracing Sync completed", [
|
|
'line_no' => $lineListData->line_no,
|
|
'tracing' => $lineListData->tracing,
|
|
'test_packages_updated' => $result,
|
|
]);
|
|
|
|
return [
|
|
'success' => true,
|
|
'test_packages_updated' => $result,
|
|
];
|
|
}
|
|
}
|
|
|