228 lines
6.9 KiB
PHP
228 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
class DashboardHelper
|
|
{
|
|
/**
|
|
* Data master untuk setiap jenis izin
|
|
*/
|
|
public static function getStatusDataByType(string $type): array
|
|
{
|
|
$data = [
|
|
'pertek' => [
|
|
['id' => 'ditolak', 'label' => 'Izin Ditolak', 'value' => 8, 'color' => 'danger'],
|
|
['id' => 'selesai', 'label' => 'Izin Selesai', 'value' => 45, 'color' => 'success'],
|
|
['id' => 'proses', 'label' => 'Dalam Proses', 'value' => 12, 'color' => 'info'],
|
|
],
|
|
'rintek' => [
|
|
['id' => 'ditolak', 'label' => 'Izin Ditolak', 'value' => 5, 'color' => 'danger'],
|
|
['id' => 'selesai', 'label' => 'Izin Selesai', 'value' => 28, 'color' => 'success'],
|
|
['id' => 'proses', 'label' => 'Dalam Proses', 'value' => 7, 'color' => 'info'],
|
|
],
|
|
'amdal' => [
|
|
['id' => 'ditolak', 'label' => 'Izin Ditolak', 'value' => 3, 'color' => 'danger'],
|
|
['id' => 'selesai', 'label' => 'Izin Selesai', 'value' => 15, 'color' => 'success'],
|
|
['id' => 'proses', 'label' => 'Dalam Proses', 'value' => 9, 'color' => 'info'],
|
|
],
|
|
'izin_angkut' => [
|
|
['id' => 'ditolak', 'label' => 'Izin Ditolak', 'value' => 12, 'color' => 'danger'],
|
|
['id' => 'selesai', 'label' => 'Izin Selesai', 'value' => 67, 'color' => 'success'],
|
|
['id' => 'proses', 'label' => 'Dalam Proses', 'value' => 18, 'color' => 'info'],
|
|
],
|
|
'uji_emisi' => [
|
|
['id' => 'ditolak', 'label' => 'Izin Ditolak', 'value' => 6, 'color' => 'danger'],
|
|
['id' => 'selesai', 'label' => 'Izin Selesai', 'value' => 89, 'color' => 'success'],
|
|
['id' => 'proses', 'label' => 'Dalam Proses', 'value' => 23, 'color' => 'info'],
|
|
],
|
|
];
|
|
|
|
return $data[$type] ?? [];
|
|
}
|
|
|
|
/**
|
|
* Menambahkan total ke data statuses
|
|
*/
|
|
public static function addTotalToStatuses(array $statuses): array
|
|
{
|
|
$total = array_sum(array_column($statuses, 'value'));
|
|
$statuses[] = [
|
|
'id' => 'total',
|
|
'label' => 'Total Pengajuan',
|
|
'value' => $total,
|
|
'color' => 'primary'
|
|
];
|
|
|
|
return $statuses;
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan label untuk tipe izin
|
|
*/
|
|
public static function getTypeLabel(string $type): string
|
|
{
|
|
$labels = [
|
|
'pertek' => 'PERTEK',
|
|
'rintek' => 'RINTEK',
|
|
'amdal' => 'AMDAL',
|
|
'izin_angkut' => 'IZIN ANGKUT & OLAH',
|
|
'uji_emisi' => 'IZIN TEMPAT UJI EMISI',
|
|
];
|
|
|
|
return $labels[$type] ?? strtoupper($type);
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan icon untuk status
|
|
*/
|
|
public static function getStatusIcon(string $statusId): string
|
|
{
|
|
$icons = [
|
|
'ditolak' => 'circle-x',
|
|
'selesai' => 'circle-check',
|
|
'proses' => 'refresh-cw',
|
|
'total' => 'equal',
|
|
];
|
|
|
|
return $icons[$statusId] ?? 'circle';
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan background color untuk card
|
|
*/
|
|
public static function getCardBackground(string $statusId): string
|
|
{
|
|
$backgrounds = [
|
|
'ditolak' => 'bg-gradient-start-4',
|
|
'selesai' => 'bg-gradient-start-2',
|
|
'proses' => 'bg-gradient-start-3',
|
|
'total' => 'bg-gradient-start-1',
|
|
];
|
|
|
|
return $backgrounds[$statusId] ?? 'bg-gradient-start-1';
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan warna lingkaran icon
|
|
*/
|
|
public static function getIconCircleColor(string $statusId): string
|
|
{
|
|
$colors = [
|
|
'ditolak' => 'bg-red',
|
|
'selesai' => 'bg-green',
|
|
'proses' => 'bg-info',
|
|
'total' => 'bg-yellow',
|
|
];
|
|
|
|
return $colors[$statusId] ?? 'bg-primary';
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan semua tipe izin yang tersedia
|
|
*/
|
|
public static function getAllTypes(): array
|
|
{
|
|
return ['pertek', 'rintek', 'amdal', 'izin_angkut', 'uji_emisi'];
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan statistik lengkap untuk semua tipe
|
|
*/
|
|
public static function getAllStatistics(): array
|
|
{
|
|
$types = self::getAllTypes();
|
|
$allData = [];
|
|
|
|
foreach ($types as $type) {
|
|
$statuses = self::getStatusDataByType($type);
|
|
$statuses = self::addTotalToStatuses($statuses);
|
|
|
|
$allData[$type] = [
|
|
'type' => $type,
|
|
'label' => self::getTypeLabel($type),
|
|
'data' => $statuses
|
|
];
|
|
}
|
|
|
|
return $allData;
|
|
}
|
|
|
|
/**
|
|
* Format percentage dari total
|
|
*/
|
|
public static function calculatePercentage(int $value, int $total): float
|
|
{
|
|
return $total > 0 ? round(($value / $total) * 100, 2) : 0;
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan trend indicator (simulasi)
|
|
*/
|
|
public static function getTrendIndicator(string $type, string $statusId): array
|
|
{
|
|
// Simulasi data trend (bisa diganti dengan data real dari database)
|
|
$trends = [
|
|
'pertek' => ['ditolak' => -2.5, 'selesai' => 5.3, 'proses' => 1.2],
|
|
'rintek' => ['ditolak' => -1.8, 'selesai' => 3.7, 'proses' => 0.5],
|
|
'amdal' => ['ditolak' => -0.9, 'selesai' => 2.1, 'proses' => -0.3],
|
|
'izin_angkut' => ['ditolak' => -3.2, 'selesai' => 7.8, 'proses' => 2.1],
|
|
'uji_emisi' => ['ditolak' => -1.5, 'selesai' => 12.4, 'proses' => 4.2],
|
|
];
|
|
|
|
$value = $trends[$type][$statusId] ?? 0;
|
|
|
|
return [
|
|
'value' => $value,
|
|
'direction' => $value > 0 ? 'up' : ($value < 0 ? 'down' : 'same'),
|
|
'color' => $value > 0 ? 'success' : ($value < 0 ? 'danger' : 'secondary')
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan badge color untuk tipe izin
|
|
*/
|
|
public static function getBadgeColor(string $type): string
|
|
{
|
|
$colors = [
|
|
'pertek' => 'primary',
|
|
'rintek' => 'success',
|
|
'amdal' => 'info',
|
|
'izin_angkut' => 'warning',
|
|
'uji_emisi' => 'secondary',
|
|
];
|
|
|
|
return $colors[$type] ?? 'primary';
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan data untuk chart
|
|
*/
|
|
public static function getChartData(string $type): array
|
|
{
|
|
$statuses = self::getStatusDataByType($type);
|
|
|
|
return [
|
|
'labels' => array_column($statuses, 'label'),
|
|
'values' => array_column($statuses, 'value'),
|
|
'colors' => array_map(function($status) {
|
|
return self::getChartColor($status['id']);
|
|
}, $statuses)
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Mendapatkan warna untuk chart
|
|
*/
|
|
private static function getChartColor(string $statusId): string
|
|
{
|
|
$colors = [
|
|
'ditolak' => '#ef4444',
|
|
'selesai' => '#22c55e',
|
|
'proses' => '#3b82f6',
|
|
'total' => '#f59e0b',
|
|
];
|
|
|
|
return $colors[$statusId] ?? '#6b7280';
|
|
}
|
|
}
|