feat(create): add realisasi awal input di create page
Features: - Add realisasiAwal field to ItemForm type - Add NumberInput for realisasi awal (optional) - Update table preview to show realisasi awal - Update state to send realisasiAwal to API - Update API create to handle realisasiAwal: * Create APBDesItem with totalRealisasi = realisasiAwal * Auto-create first RealisasiItem if realisasiAwal > 0 * Auto-calculate selisih and persentase UX Improvements: - User can input initial realization during create - Optional field with clear label and description - Auto-calculation of percentages on backend - Single transaction for item + first realisasi Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -5,11 +5,12 @@ import { toast } from "react-toastify";
|
||||
import { proxy } from "valtio";
|
||||
import { z } from "zod";
|
||||
|
||||
// --- Zod Schema untuk APBDes Item (tanpa field kalkulasi) ---
|
||||
// --- Zod Schema untuk APBDes Item (dengan realisasiAwal opsional) ---
|
||||
const ApbdesItemSchema = z.object({
|
||||
kode: z.string().min(1, "Kode wajib diisi"),
|
||||
uraian: z.string().min(1, "Uraian wajib diisi"),
|
||||
anggaran: z.number().min(0, "Anggaran tidak boleh negatif"),
|
||||
realisasiAwal: z.number().min(0).optional(), // Realisasi pertama saat create
|
||||
level: z.number().int().min(1).max(3),
|
||||
tipe: z.enum(['pendapatan', 'belanja', 'pembiayaan']).nullable().optional(),
|
||||
});
|
||||
@@ -91,7 +92,21 @@ const apbdes = proxy({
|
||||
|
||||
try {
|
||||
this.loading = true;
|
||||
const res = await ApiFetch.api.landingpage.apbdes["create"].post(parsed.data);
|
||||
|
||||
// Extract realisasiAwal dari items
|
||||
const itemsWithRealisasi = this.form.items.map(item => ({
|
||||
kode: item.kode,
|
||||
uraian: item.uraian,
|
||||
anggaran: item.anggaran,
|
||||
level: item.level,
|
||||
tipe: item.tipe,
|
||||
realisasiAwal: item.realisasiAwal || 0,
|
||||
}));
|
||||
|
||||
const res = await ApiFetch.api.landingpage.apbdes["create"].post({
|
||||
...parsed.data,
|
||||
items: itemsWithRealisasi,
|
||||
});
|
||||
|
||||
if (res.data?.success) {
|
||||
toast.success("APBDes berhasil dibuat");
|
||||
|
||||
Reference in New Issue
Block a user