86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
use App\Models\WeldLog;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
// Helper function to sanitize input
|
|
$rfiNo = request('rfi_no');
|
|
$skip = (int) request('skip', 0);
|
|
$take = (int) request('take', 50);
|
|
|
|
// Response array
|
|
$response = [];
|
|
|
|
if (empty($rfiNo)) {
|
|
echo json_encode(['data' => [], 'totalCount' => 0]);
|
|
exit;
|
|
}
|
|
|
|
// Columns to search in WeldLog
|
|
$searchColumns = [
|
|
'joint_release_rfi_no',
|
|
'rt_release_rfi_no',
|
|
'ut_release_rfi_no',
|
|
'pt_release_rfi_no',
|
|
'mt_release_rfi_no',
|
|
'pmi_release_rfi_no',
|
|
'vt_release_rfi_no',
|
|
'pwht_release_rfi_no',
|
|
'ht_release_rfi_no',
|
|
'ferrite_release_rfi_no',
|
|
];
|
|
|
|
// Query Construction
|
|
$query = WeldLog::query();
|
|
|
|
$query->where(function($q) use ($searchColumns, $rfiNo) {
|
|
foreach ($searchColumns as $col) {
|
|
$q->orWhere($col, 'like', '%' . $rfiNo . '%'); // Using LIKE to catch exact matches or substrings if applicable, but RFI usually exact. matching exact is safer?
|
|
// User might want exact match. Let's try exact first?
|
|
// But get-rfi-for-release-log uses LIKE. "like %$rfiNo%".
|
|
// Let's stick to LIKE for flexibility.
|
|
}
|
|
});
|
|
|
|
$totalCount = $query->count();
|
|
|
|
$data = $query
|
|
->orderBy('id', 'DESC')
|
|
->skip($skip)
|
|
->take($take)
|
|
->get();
|
|
|
|
// Prepare response data
|
|
$resultData = [];
|
|
foreach ($data as $item) {
|
|
// Determine which type(s) matched (optional, but helpful)
|
|
$matchedTypes = [];
|
|
foreach ($searchColumns as $col) {
|
|
if (strpos($item->$col, $rfiNo) !== false) {
|
|
$matchedTypes[] = str_replace('_release_rfi_no', '', $col);
|
|
}
|
|
}
|
|
|
|
$resultData[] = [
|
|
'id' => $item->id,
|
|
'iso_number' => $item->iso_number,
|
|
'line_number' => $item->line_number,
|
|
'spool_number' => $item->spool_number,
|
|
'joint_no' => $item->no_of_the_joint_as_per_as_built_survey,
|
|
'type_of_welds' => $item->type_of_welds,
|
|
'type_of_joint' => $item->type_of_joint,
|
|
'welding_date' => $item->welding_date,
|
|
'matched_types' => implode(', ', $matchedTypes),
|
|
// Add all release RFI nos for reference
|
|
'joint_release' => $item->joint_release_rfi_no,
|
|
'rt_release' => $item->rt_release_rfi_no,
|
|
'ut_release' => $item->ut_release_rfi_no,
|
|
// ... add others if needed, or just rely on matched_types
|
|
];
|
|
}
|
|
|
|
echo json_encode([
|
|
'data' => $resultData,
|
|
'totalCount' => $totalCount
|
|
]);
|
|
?>
|