Files
citrus-cms/resources/views/admin-ajax/get-incoming-for-weldlog.blade.php
T
2026-04-28 21:15:09 +03:00

110 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* @api-readonly
* Returns incoming control data for weld logs
*/
use App\Models\IncomingControl;
// Parametreleri al
$componentCode = request('component_code');
$lineCode = request('line_code');
$ruMaterialGroup = request('ru_group');
$weldingDate = request('welding_date');
$skip = (int) request('skip', 0);
$take = (int) request('take', 50);
// Response array
$response = [];
// Incoming Control verilerini getir
// Öncelikle element_code ile ara, eğer boşsa line_code (drawing_number) ile ara
// Hiçbir filtre yoksa veya filtre ile sonuç bulunamazsa tüm tabloyu göster
$query = IncomingControl::query();
$hasFilter = false;
if(!empty($componentCode)) {
// Önce component_code ile ara
$query->where('component_code', $componentCode);
$hasFilter = true;
} else if(!empty($lineCode)) {
// component_code boşsa, line_code ile drawing_number'a göre ara
$query->where('drawing_number', $lineCode);
$hasFilter = true;
}
// RU Material Group filtresi (opsiyonel)
if(!empty($ruMaterialGroup)) {
$ruGroups = explode(",", $ruMaterialGroup);
$materials = db("materials")->whereIn("ru_group", $ruGroups)->select("steel_grade")->get()->pluck("steel_grade")->toArray();
if(count($materials) > 0) {
$query = $query->whereIn("material", $materials);
}
}
// Total count for pagination
$totalCount = $query->count();
$filterFailed = false;
// Eğer filtre uygulandı ama sonuç bulunamadıysa, filtresiz tüm veriyi getir
if($hasFilter && $totalCount === 0) {
$query = IncomingControl::query();
$totalCount = $query->count();
$filterFailed = true; // Filtre uygulanamadı, tüm veri gösteriliyor
}
// Sıralama: En son girilen önce, sonra RFI tarihine göre
// Pagination uygula
$incomingData = $query
->orderBy('id', 'DESC') // En son girilen önce
->orderBy('rfi_date', 'ASC') // RFI tarihine göre sıralı
->skip($skip)
->take($take)
->get();
// Verileri formatla ve renklendirme flag'i ekle
foreach($incomingData as $item) {
$row = [
'id' => $item->id,
'component_code' => $item->component_code,
'rfi' => $item->rfi,
'rfi_date' => $item->rfi_date,
'description_en' => $item->description_en,
'description_ru' => $item->description_ru,
'project' => $item->project, // Zone olarak gösterilecek
'drawing_number' => $item->drawing_number,
'certificate_no' => $item->certificate_no,
'certificate_date' => $item->certificate_date,
'heat_number' => $item->heat_number,
'received_quantity' => $item->received_quantity,
'constructor' => $item->constructor,
'inspection_photo_file' => $item->inspection_photo_file,
'email_tq_file' => $item->email_tq_file,
'email_tq_number' => $item->email_tq_number,
'osd_defect_akt_file' => $item->osd_defect_akt_file,
'osd_report_date' => $item->osd_report_date,
'osd_report_no' => $item->osd_report_no,
];
// RFI date > welding_date kontrolü için flag
$row['highlight'] = false;
if(!empty($item->rfi_date) && !empty($weldingDate)) {
$rfiDate = strtotime($item->rfi_date);
$weldDate = strtotime($weldingDate);
if($rfiDate > $weldDate) {
$row['highlight'] = true;
}
}
$response[] = $row;
}
// JSON response döndür - pagination için data ve totalCount döndür
echo json_encode([
'data' => $response,
'totalCount' => $totalCount,
'filterFailed' => $filterFailed
]);
exit();