Files
2026-04-28 21:15:09 +03:00

147 lines
4.6 KiB
PHP
Raw Permalink 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
* NDT Calculation data - reads from cache
*/
if(getesit("type","test_packs")) {
// 1. Cached Veriyi Çek
$ndtData = json_decode(setting("ndtCalculation"), true);
// 2. ISO/Line -> TP Haritasını Oluştur
// Tüm weld_logs'u çekmek yerine sadece eşleştirme için gerekli alanları çekiyoruz
$mappings = db("weld_logs")
->select("line_number", "iso_number", "test_package_no")
->whereNotNull("test_package_no")
->where("test_package_no", "!=", "")
->distinct()
->get();
$isoToTP = [];
foreach($mappings as $map) {
if($map->line_number) {
$isoToTP[$map->line_number] = $map->test_package_no;
}
if($map->iso_number) {
$isoToTP[$map->iso_number] = $map->test_package_no;
}
}
// 3. Veriyi İşle (Referans: ndt-calculation-no-cache.blade.php)
$tpStats = [];
$tpISOStats = [];
if (is_array($ndtData)) {
foreach($ndtData AS $row)
{
// Doğru ISO/TP ilişkisini kullanarak TP numarasını al
$tpNo = "";
// Veri kaynağında line_number varsa ve haritada karşılığı varsa
if(isset($row['line_number']) && isset($isoToTP[$row['line_number']])) {
$tpNo = trim($isoToTP[$row['line_number']]);
}
// Alternatif olarak iso_number kontrolü
else if(isset($row['iso_number']) && isset($isoToTP[$row['iso_number']])) {
$tpNo = trim($isoToTP[$row['iso_number']]);
}
if($tpNo != "")
{
$testTypes = array_keys(log_test_types());
if(!isset($tpStats[$tpNo]))
{
$tpStats[$tpNo]['test_package_no'] = $tpNo;
foreach($testTypes AS $testType)
{
$tpStats[$tpNo][$testType] = 0;
}
}
// ISO numarasını belirle
$isoNum = $row['iso_number'] ?? ($row['line_number'] ?? 'Unknown');
if(!isset($tpISOStats[$tpNo][$isoNum]))
{
$tpISOStats[$tpNo][$isoNum]['test_package_no'] = $tpNo;
$tpISOStats[$tpNo][$isoNum]['iso_number'] = $isoNum;
foreach($testTypes AS $testType)
{
$tpISOStats[$tpNo][$isoNum][$testType] = 0;
}
}
foreach($testTypes AS $testType)
{
// Backlog değeri kontrolü ve negatif değerleri sıfıra dönüştürme
$backlogValue = 0;
if(isset($row[$testType . '_backlog'])) {
$backlogValue = max(0, (int)$row[$testType . '_backlog']);
}
if($backlogValue > 0)
{
$tpStats[$tpNo][$testType] += $backlogValue;
$tpISOStats[$tpNo][$isoNum][$testType] += $backlogValue;
}
}
}
}
}
$tpStatsRefactor = [];
foreach($tpStats AS $tpStat)
{
$tpStatsRefactor[] = $tpStat;
}
$tpISOStatsRefactor = [];
foreach($tpISOStats AS $tpNo => $data)
{
foreach($data AS $d)
{
$tpISOStatsRefactor[] = $d;
}
}
$tpDatas = [
'tp_base' => $tpStatsRefactor,
'tp_base_iso' => $tpISOStatsRefactor,
'tpStats' => $tpStats,
'tpISOStats' => $tpISOStats,
];
echo json_encode_tr($tpDatas);
} elseif(getesit("type", "backlogs")) {
$ndtData = json_decode(setting("ndtCalculation"), true);
$ndtBacklogStats = [];
if (is_array($ndtData)) {
foreach($ndtData as $d) {
foreach($d as $field => $value) {
if(strpos($field, "backlog") !== false) {
$key = strtoupper(str_replace("_backlog", "", $field));
if($value > 0) {
if(!isset($ndtBacklogStats[$key])) {
$ndtBacklogStats[$key] = 0;
}
$ndtBacklogStats[$key] += $value;
}
}
}
}
}
$result = [];
foreach($ndtBacklogStats as $key => $totalBacklog) {
$result[] = [
'type' => $key,
'backlog' => $totalBacklog
];
}
echo json_encode($result);
} else {
cacheBladeLoad('ndt-calculation');
}
?>