fix(api): correct selisih calculation formula
Bug Fix: - Change selisih formula from: totalRealisasi - anggaran - To: anggaran - totalRealisasi Reason: - Selisih positif = Sisa anggaran (belum digunakan) - Selisih negatif = Over budget (melebihi anggaran) Example: - Anggaran: Rp 30.000.000 - Realisasi: Rp 5.000.000 - Selisih (OLD): 5jt - 30jt = -25jt ❌ Wrong - Selisih (NEW): 30jt - 5jt = 25jt ✅ Correct (sisa anggaran) Files Updated: - create.ts: Fix initial item creation - updt.ts: Fix item update - realisasi/create.ts: Fix after adding realisasi - realisasi/update.ts: Fix after updating realisasi - realisasi/delete.ts: Fix after deleting realisasi Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -60,7 +60,7 @@ export default async function apbdesCreate(context: Context) {
|
||||
body.items.map(async item => {
|
||||
const anggaran = item.anggaran;
|
||||
const totalRealisasi = 0; // Belum ada realisasi saat create
|
||||
const selisih = totalRealisasi - anggaran;
|
||||
const selisih = anggaran - totalRealisasi; // Sisa anggaran (positif = belum digunakan)
|
||||
const persentase = anggaran > 0 ? (totalRealisasi / anggaran) * 100 : 0;
|
||||
|
||||
const itemData = {
|
||||
|
||||
@@ -47,7 +47,7 @@ export default async function realisasiCreate(context: Context) {
|
||||
});
|
||||
|
||||
const totalRealisasi = allRealisasi.reduce((sum, r) => sum + r.jumlah, 0);
|
||||
const selisih = totalRealisasi - item.anggaran;
|
||||
const selisih = item.anggaran - totalRealisasi; // Sisa anggaran (positif = belum digunakan)
|
||||
const persentase = item.anggaran > 0 ? (totalRealisasi / item.anggaran) * 100 : 0;
|
||||
|
||||
await prisma.aPBDesItem.update({
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function realisasiDelete(context: Context) {
|
||||
|
||||
if (item) {
|
||||
const totalRealisasi = allRealisasi.reduce((sum, r) => sum + r.jumlah, 0);
|
||||
const selisih = totalRealisasi - item.anggaran;
|
||||
const selisih = item.anggaran - totalRealisasi; // Sisa anggaran (positif = belum digunakan)
|
||||
const persentase = item.anggaran > 0 ? (totalRealisasi / item.anggaran) * 100 : 0;
|
||||
|
||||
await prisma.aPBDesItem.update({
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function realisasiUpdate(context: Context) {
|
||||
|
||||
if (item) {
|
||||
const totalRealisasi = allRealisasi.reduce((sum, r) => sum + r.jumlah, 0);
|
||||
const selisih = totalRealisasi - item.anggaran;
|
||||
const selisih = item.anggaran - totalRealisasi; // Sisa anggaran (positif = belum digunakan)
|
||||
const persentase = item.anggaran > 0 ? (totalRealisasi / item.anggaran) * 100 : 0;
|
||||
|
||||
await prisma.aPBDesItem.update({
|
||||
|
||||
@@ -48,7 +48,7 @@ export default async function apbdesUpdate(context: Context) {
|
||||
data: body.items.map((item) => {
|
||||
const anggaran = item.anggaran;
|
||||
const totalRealisasi = 0; // Reset karena items baru
|
||||
const selisih = totalRealisasi - anggaran;
|
||||
const selisih = anggaran - totalRealisasi; // Sisa anggaran (positif = belum digunakan)
|
||||
const persentase = anggaran > 0 ? (totalRealisasi / anggaran) * 100 : 0;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user