Files
citrus-cms/resources/views/admin-ajax/material-performance-welded-supports.blade.php
T
2026-04-28 21:15:09 +03:00

96 lines
3.2 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
// Filtered for Supports
$materials = db("materials")
->select("ru_group", "short_name")
->get()
->pluck("short_name", "ru_group")
->toArray();
// İzin verilen material grupları: CS, SS, NI (task gereksinimi)
$allowedMaterials = ['CS', 'SS', 'NI'];
$query = apply_welded_filter(
db("weld_logs")
->select(
"ru_material_group_1",
"project",
"welding_date",
"fit_up_date",
"nps_1"
)
->where('piping_type', 'like', '%Support%') // Filter for Supports
->orWhere('piping_type', 'like', '%Опора%') // Russian for Support
->orderBy("id")
);
$iterator = method_exists($query, 'cursor') ? $query->cursor() : $query->get();
$processedData = [];
foreach ($iterator as $row) {
$row = (array) $row;
try {
$ru_material_group_1 = $materials[$row['ru_material_group_1']] ?? $row['ru_material_group_1'];
} catch (\Throwable $th) {
$ru_material_group_1 = $row['ru_material_group_1'];
}
if (empty($ru_material_group_1)) {
$ru_material_group_1 = 'Unknown';
}
$ru_material_group_1_upper = strtoupper(trim($ru_material_group_1));
if (stripos($ru_material_group_1_upper, 'POLIMER') !== false ||
stripos($ru_material_group_1_upper, 'POLYMER') !== false ||
!in_array($ru_material_group_1_upper, $allowedMaterials)) {
continue;
}
if (!isset($processedData[$ru_material_group_1])) {
$processedData[$ru_material_group_1] = [
'Welded Joints Quantity' => 0,
'Welded Joints WDI' => 0,
'Fit-Up Quantity (Not welded)' => 0,
'Fit-Up WDI (Not welded)' => 0,
'Weld Backlog' => 0,
];
}
$nps_1 = (double) ($row['nps_1'] ?? 0);
if ($row['welding_date']) {
// Welded
$processedData[$ru_material_group_1]['Welded Joints Quantity']++;
$processedData[$ru_material_group_1]['Welded Joints WDI'] += $nps_1;
} elseif ($row['fit_up_date']) {
// Fit-Up but not welded
$processedData[$ru_material_group_1]['Fit-Up Quantity (Not welded)']++;
$processedData[$ru_material_group_1]['Fit-Up WDI (Not welded)'] += $nps_1;
} else {
// Backlog
$processedData[$ru_material_group_1]['Weld Backlog']++;
}
}
// Convert to results array for pivot grid
$results = [];
foreach ($processedData as $material => $data) {
$total = $data['Welded Joints Quantity'] + $data['Fit-Up Quantity (Not welded)'] + $data['Weld Backlog'];
$progress = $total > 0 ? round(($data['Welded Joints Quantity'] / $total) * 100, 2) : 0;
$results[] = [
'Material' => $material,
'Welded Joints Quantity' => $data['Welded Joints Quantity'],
'Welded Joints WDI' => round($data['Welded Joints WDI'], 2),
'Fit-Up Quantity (Not welded)' => $data['Fit-Up Quantity (Not welded)'],
'Fit-Up WDI (Not welded)' => round($data['Fit-Up WDI (Not welded)'], 2),
'Weld Backlog' => $data['Weld Backlog'],
'Progress' => $progress,
'WDI' => round($data['Welded Joints WDI'], 2),
'Count' => $data['Welded Joints Quantity']
];
}
echo json_encode_tr($results);
?>