refactor(create): remove realisasiAwal, simplify to anggaran-only input
Refactoring: - Remove realisasiAwal field from ItemForm type - Remove NumberInput for realisasi awal from UI - Remove realisasiAwal column from preview table - Simplify state management (no realisasiAwal mapping) - API create: Create items with totalRealisasi=0 (no auto-create realisasi) Rationale: - Cleaner separation: Anggaran dan Realisasi adalah entitas terpisah - User create item untuk ANGGARAN dulu - Setelah item dibuat, user bisa add MULTIPLE REALISASI dengan: * Uraian yang jelas untuk setiap realisasi * Tanggal yang spesifik * Keterangan detail * Bukti file attachment - Follows the original schema design more closely Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -10,7 +10,6 @@ type APBDesItemInput = {
|
||||
anggaran: number;
|
||||
level: number;
|
||||
tipe?: string | null;
|
||||
realisasiAwal?: number; // Realisasi pertama saat create
|
||||
};
|
||||
|
||||
type FormCreate = {
|
||||
@@ -56,15 +55,14 @@ export default async function apbdesCreate(context: Context) {
|
||||
},
|
||||
});
|
||||
|
||||
// Create items dengan auto-calculate totalRealisasi, selisih, persentase
|
||||
// Create items dengan auto-calculate totalRealisasi=0, selisih, persentase
|
||||
const items = await Promise.all(
|
||||
body.items.map(async item => {
|
||||
const anggaran = item.anggaran;
|
||||
const realisasiAwal = item.realisasiAwal || 0;
|
||||
|
||||
// Jika ada realisasiAwal, buat realisasi item pertama
|
||||
let totalRealisasi = realisasiAwal;
|
||||
|
||||
const totalRealisasi = 0; // Belum ada realisasi saat create
|
||||
const selisih = totalRealisasi - anggaran;
|
||||
const persentase = anggaran > 0 ? (totalRealisasi / anggaran) * 100 : 0;
|
||||
|
||||
const itemData = {
|
||||
kode: item.kode,
|
||||
uraian: item.uraian,
|
||||
@@ -72,29 +70,15 @@ export default async function apbdesCreate(context: Context) {
|
||||
level: item.level,
|
||||
tipe: item.tipe || null,
|
||||
totalRealisasi,
|
||||
selisih: totalRealisasi - anggaran,
|
||||
persentase: anggaran > 0 ? (totalRealisasi / anggaran) * 100 : 0,
|
||||
selisih,
|
||||
persentase,
|
||||
apbdesId: apbdes.id,
|
||||
};
|
||||
|
||||
const createdItem = await prisma.aPBDesItem.create({
|
||||
return prisma.aPBDesItem.create({
|
||||
data: itemData,
|
||||
select: { id: true, kode: true },
|
||||
});
|
||||
|
||||
// Jika ada realisasiAwal, buat realisasi item pertama
|
||||
if (realisasiAwal > 0) {
|
||||
await prisma.realisasiItem.create({
|
||||
data: {
|
||||
apbdesItemId: createdItem.id,
|
||||
jumlah: realisasiAwal,
|
||||
tanggal: new Date(),
|
||||
keterangan: 'Realisasi awal saat create APBDes',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return createdItem;
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user