131 lines
4.9 KiB
PHP
131 lines
4.9 KiB
PHP
<?php
|
||
use App\Models\TestPackBaseStatus;
|
||
use App\Services\Dashboards\TestPackageDashboardService;
|
||
|
||
header('Content-Type: application/json');
|
||
|
||
try {
|
||
$chartType = $_GET['chart'] ?? null;
|
||
$year = (int) ($_GET['year'] ?? date('Y'));
|
||
|
||
if (in_array($chartType, ['monthly', 'pie', 'subcontractor', 'summary'], true)) {
|
||
$trends = TestPackageDashboardService::monthlyTrends($year);
|
||
|
||
switch ($chartType) {
|
||
case 'monthly':
|
||
echo json_encode_tr($trends['monthly']);
|
||
break;
|
||
case 'pie':
|
||
echo json_encode_tr([
|
||
'pie' => $trends['pie'],
|
||
'summary' => $trends['summary']
|
||
]);
|
||
break;
|
||
case 'subcontractor':
|
||
echo json_encode_tr($trends['subcontractor']);
|
||
break;
|
||
case 'summary':
|
||
echo json_encode_tr($trends['summary']);
|
||
break;
|
||
}
|
||
return;
|
||
}
|
||
|
||
// Area bazında Subcontractor grafiği
|
||
if ($chartType === 'area-subcontractor') {
|
||
$data = db('test_pack_base_statuses')
|
||
->select('area', 'subcontractor')
|
||
->selectRaw('COUNT(*) as total_packages')
|
||
->whereNotNull('area')
|
||
->where('area', '!=', '')
|
||
->whereNotNull('subcontractor')
|
||
->where('subcontractor', '!=', '')
|
||
->groupBy('area', 'subcontractor')
|
||
->orderBy('area')
|
||
->orderBy('subcontractor')
|
||
->get();
|
||
|
||
echo json_encode_tr($data);
|
||
return;
|
||
}
|
||
|
||
if ($chartType === 'ndt') {
|
||
// NDT Backlog by Discipline
|
||
$data = db('test_pack_base_statuses')
|
||
->select('discipline')
|
||
->selectRaw('SUM(COALESCE(rt_backlog, 0)) as rt_backlog')
|
||
->selectRaw('SUM(COALESCE(ut_backlog, 0)) as ut_backlog')
|
||
->selectRaw('SUM(COALESCE(mt_backlog, 0)) as mt_backlog')
|
||
->selectRaw('SUM(COALESCE(pt_backlog, 0)) as pt_backlog')
|
||
->selectRaw('SUM(COALESCE(vt_backlog, 0)) as vt_backlog')
|
||
->selectRaw('SUM(COALESCE(pmi_backlog, 0)) as pmi_backlog')
|
||
->selectRaw('SUM(COALESCE(ferrit_backlog, 0)) as ferrit_backlog')
|
||
->selectRaw('SUM(COALESCE(pwht_backlog, 0)) as pwht_backlog')
|
||
->whereNotNull('discipline')
|
||
->where('discipline', '!=', '')
|
||
->groupBy('discipline')
|
||
->get();
|
||
|
||
// Veri yoksa boş array döndür
|
||
if (!$data || $data->isEmpty()) {
|
||
echo json_encode_tr([]);
|
||
} else {
|
||
// Sayısal değerleri float'a çevir
|
||
$formattedData = $data->map(function($item) {
|
||
return [
|
||
'discipline' => $item->discipline,
|
||
'rt_backlog' => (float) $item->rt_backlog,
|
||
'ut_backlog' => (float) $item->ut_backlog,
|
||
'mt_backlog' => (float) $item->mt_backlog,
|
||
'pt_backlog' => (float) $item->pt_backlog,
|
||
'vt_backlog' => (float) $item->vt_backlog,
|
||
'pmi_backlog' => (float) $item->pmi_backlog,
|
||
'ferrit_backlog' => (float) $item->ferrit_backlog,
|
||
'pwht_backlog' => (float) $item->pwht_backlog
|
||
];
|
||
});
|
||
echo json_encode_tr($formattedData);
|
||
}
|
||
} elseif ($chartType === 'progress') {
|
||
// Progress Analysis by Discipline
|
||
$data = db('test_pack_base_statuses')
|
||
->select('discipline')
|
||
->selectRaw('AVG(COALESCE(pipe_progress, 0)) as pipe_progress')
|
||
->selectRaw('AVG(COALESCE(support_progress, 0)) as support_progress')
|
||
->selectRaw('SUM(COALESCE(remaining_wdi, 0)) as remaining_wdi')
|
||
->whereNotNull('discipline')
|
||
->where('discipline', '!=', '')
|
||
->groupBy('discipline')
|
||
->get();
|
||
|
||
// Veri yoksa boş array döndür
|
||
if (!$data || $data->isEmpty()) {
|
||
echo json_encode_tr([]);
|
||
} else {
|
||
// Sayısal değerleri float'a çevir
|
||
$formattedData = $data->map(function($item) {
|
||
return [
|
||
'discipline' => $item->discipline,
|
||
'pipe_progress' => (float) $item->pipe_progress,
|
||
'support_progress' => (float) $item->support_progress,
|
||
'remaining_wdi' => (float) $item->remaining_wdi
|
||
];
|
||
});
|
||
echo json_encode_tr($formattedData);
|
||
}
|
||
} else {
|
||
// Default: Tüm veriler (PivotGrid için)
|
||
$testPackages = TestPackBaseStatus::get();
|
||
echo json_encode_tr($testPackages);
|
||
}
|
||
} catch (\Exception $e) {
|
||
http_response_code(500);
|
||
echo json_encode([
|
||
'error' => true,
|
||
'message' => $e->getMessage(),
|
||
'file' => $e->getFile(),
|
||
'line' => $e->getLine()
|
||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
?>
|