ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @api-readonly
|
||||
* Returns material performance statistics
|
||||
*/
|
||||
$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"
|
||||
)
|
||||
->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
|
||||
// Each row represents one material with all columns
|
||||
$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,
|
||||
// For Welded Supports Sum (WDI sum)
|
||||
'WDI' => round($data['Welded Joints WDI'], 2),
|
||||
// For Welded Count Sum (count)
|
||||
'Count' => $data['Welded Joints Quantity']
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode_tr($results);
|
||||
?>
|
||||
Reference in New Issue
Block a user