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

147 lines
4.9 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
// Supports tablosunu çek
$supportsQuery = db("supports")
->select("status", "total_weight", "quantity", "zone", "drawing_no", "line_number")
->whereNotNull('status')
->orderBy("zone");
$supports = method_exists($supportsQuery, 'cursor') ? $supportsQuery->cursor() : $supportsQuery->get();
// Weld_logs'tan project ve design_area mapping'i oluştur (performans için)
$weldLogsMap = [];
if (count($supports) > 0) {
$drawingNos = [];
$lineNumbers = [];
foreach ($supports as $sup) {
if (!empty($sup->drawing_no)) {
$drawingNos[] = $sup->drawing_no;
}
if (!empty($sup->line_number)) {
$lineNumbers[] = $sup->line_number;
}
}
if (!empty($drawingNos) || !empty($lineNumbers)) {
$weldLogsQuery = db("weld_logs")
->select("iso_number", "line_number", "project", "design_area");
if (!empty($drawingNos)) {
$weldLogsQuery->whereIn("iso_number", array_unique($drawingNos));
}
if (!empty($lineNumbers)) {
$weldLogsQuery->whereIn("line_number", array_unique($lineNumbers));
}
$weldLogs = $weldLogsQuery->get();
foreach ($weldLogs as $wl) {
$key = ($wl->iso_number ?? '') . '|' . ($wl->line_number ?? '');
if (!empty($key) && $key !== '|') {
$weldLogsMap[$key] = [
'project' => $wl->project ?? null,
'design_area' => $wl->design_area ?? null
];
}
}
}
}
$results = [];
$projectAreaStats = []; // Project+Area bazında istatistikler için
foreach ($supports as $row) {
$row = (array) $row;
$status = $row['status'] ?? '';
$zone = $row['zone'] ?? '';
$drawingNo = $row['drawing_no'] ?? '';
$lineNumber = $row['line_number'] ?? '';
// Weld_logs mapping'den project ve design_area'yı al
$key = $drawingNo . '|' . $lineNumber;
$weldLogData = $weldLogsMap[$key] ?? null;
// Project: weld_logs.project varsa onu kullan, yoksa zone'u kullan
$project = !empty($weldLogData['project']) ? strtoupper($weldLogData['project']) : strtoupper($zone);
// Area: weld_logs.design_area varsa onu kullan, yoksa zone'u kullan
$area = !empty($weldLogData['design_area']) ? strtoupper($weldLogData['design_area']) : strtoupper($zone);
// Determine status category
// Gerçek status değerleri: "", "0K", "OK"
$statusCategory = 'Other';
$statusTrimmed = trim($status);
// OK = Installed/Complete Support
if (strtoupper($statusTrimmed) === 'OK') {
$statusCategory = 'Installed Support';
}
// 0K veya boş = Incomplete (henüz tamamlanmamış)
elseif (strtoupper($statusTrimmed) === '0K' || empty($statusTrimmed)) {
$statusCategory = 'Incomplete Support Installation';
}
// Eski mantık (eğer gelecekte farklı status değerleri eklenirse)
else {
$statusLower = strtolower($statusTrimmed);
// Önce incomplete kontrolü (daha spesifik)
if (stripos($statusLower, 'incomplete') !== false) {
if (stripos($statusLower, 'weld') !== false) {
$statusCategory = 'Weld-Incomplete Support';
} else {
$statusCategory = 'Incomplete Support Installation';
}
}
// Sonra complete kontrolü (weld ile birlikte)
elseif (stripos($statusLower, 'weld') !== false && stripos($statusLower, 'complete') !== false) {
$statusCategory = 'Weld-Complete Support';
}
// Son olarak installed veya complete (genel)
elseif (stripos($statusLower, 'installed') !== false || stripos($statusLower, 'complete') !== false) {
$statusCategory = 'Installed Support';
}
}
$key = $project . '|' . $area;
if (!isset($projectAreaStats[$key])) {
$projectAreaStats[$key] = [
'total' => 0,
'installed' => 0
];
}
$quantity = (int) ($row['quantity'] ?? 0);
$projectAreaStats[$key]['total'] += $quantity;
// Installed sayısını hesapla - Installed Support veya Weld-Complete Support
if ($statusCategory === 'Installed Support' || $statusCategory === 'Weld-Complete Support') {
$projectAreaStats[$key]['installed'] += $quantity;
}
$results[] = [
'Project' => $project,
'Area' => $area,
'Status' => $statusCategory,
'Weight' => (double) ($row['total_weight'] ?? 0), // kg bazında
'Quantity' => (int) $quantity, // adet bazında
'Original Status' => $status
];
}
// Progress hesapla ve ekle
foreach ($results as &$result) {
$key = $result['Project'] . '|' . $result['Area'];
$total = $projectAreaStats[$key]['total'] ?? 0;
$installed = $projectAreaStats[$key]['installed'] ?? 0;
$progress = 0;
if ($total > 0) {
$progress = round(($installed / $total) * 100, 2);
}
$result['Progress'] = $progress;
}
echo json_encode_tr($results);
?>