feat: implement Kependudukan menu with CRUD admin pages

- Add Distribusi Umur admin pages (list, create, edit)
- Add Data Banjar admin pages (list, create, edit)
- Add Migrasi Penduduk admin pages (list, create, edit)
- Update state management with full CRUD operations for all modules
- Add Kependudukan menu to admin sidebar (devBar, navBar, role1)
- Add public pages for Distribusi Umur with age range sorting
- Update Dinamika Penduduk to use real-time birth/death data
- Add Biome configuration for code linting
- Create API routes for all Kependudukan modules

Features:
- Pagination and search for all admin list pages
- Responsive design (table for desktop, cards for mobile)
- Delete confirmation modal
- Toast notifications for user feedback
- Zod validation for all forms
- Age range auto-sorting in public Distribusi Umur chart

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-04-09 17:10:29 +08:00
parent 34a37dc63b
commit 5e822f0b05
51 changed files with 5964 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
import prisma from "@/lib/prisma";
export default async function dashboardSummary() {
try {
const currentYear = new Date().getFullYear();
// Get dashboard summary
const [
totalPenduduk,
totalKK,
totalKelahiran,
totalKemiskinan,
kelahiranData,
kematianData,
pindahMasukData,
pindahKeluarData,
agamaData,
umurData,
banjarData
] = await Promise.all([
// Total penduduk - hitung dari data banjar
prisma.dataBanjar.aggregate({
where: { isActive: true, tahun: currentYear },
_sum: { penduduk: true }
}),
// Total KK
prisma.dataBanjar.aggregate({
where: { isActive: true, tahun: currentYear },
_sum: { kk: true }
}),
// Total kelahiran tahun ini
prisma.kelahiran.count({
where: {
isActive: true,
tanggal: {
gte: new Date(`${currentYear}-01-01`),
lte: new Date(`${currentYear}-12-31`),
}
}
}),
// Total penduduk miskin
prisma.dataBanjar.aggregate({
where: { isActive: true, tahun: currentYear },
_sum: { miskin: true }
}),
// Kelahiran data
prisma.kelahiran.findMany({
where: {
isActive: true,
tanggal: {
gte: new Date(`${currentYear}-01-01`),
lte: new Date(`${currentYear}-12-31`),
}
},
orderBy: { tanggal: 'asc' }
}),
// Kematian data
prisma.kematian.findMany({
where: {
isActive: true,
tanggal: {
gte: new Date(`${currentYear}-01-01`),
lte: new Date(`${currentYear}-12-31`),
}
},
orderBy: { tanggal: 'asc' }
}),
// Pindah masuk
prisma.migrasiPenduduk.count({
where: {
isActive: true,
jenis: 'MASUK',
tanggal: {
gte: new Date(`${currentYear}-01-01`),
lte: new Date(`${currentYear}-12-31`),
}
}
}),
// Pindah keluar
prisma.migrasiPenduduk.count({
where: {
isActive: true,
jenis: 'KELUAR',
tanggal: {
gte: new Date(`${currentYear}-01-01`),
lte: new Date(`${currentYear}-12-31`),
}
}
}),
// Data agama
prisma.distribusiAgama.findMany({
where: { isActive: true, tahun: currentYear },
orderBy: { jumlah: 'desc' }
}),
// Data umur
prisma.distribusiUmur.findMany({
where: { isActive: true, tahun: currentYear },
orderBy: { createdAt: 'asc' }
}),
// Data banjar
prisma.dataBanjar.findMany({
where: { isActive: true, tahun: currentYear },
orderBy: { nama: 'asc' }
})
]);
return {
success: true,
message: "Dashboard summary berhasil diambil",
data: {
tahun: currentYear,
summary: {
totalPenduduk: totalPenduduk._sum.penduduk || 0,
totalKK: totalKK._sum.kk || 0,
totalKelahiran: totalKelahiran,
totalKemiskinan: totalKemiskinan._sum.miskin || 0,
},
dinamika: {
kelahiran: totalKelahiran,
kematian: kematianData.length,
pindahMasuk: pindahMasukData,
pindahKeluar: pindahKeluarData,
},
agama: agamaData,
umur: umurData,
banjar: banjarData,
}
};
} catch (error) {
console.error("Error fetching dashboard summary:", error);
return {
success: false,
message: "Terjadi kesalahan saat mengambil data dashboard",
data: null,
};
}
}