fix: File view
Deksripsi: - Tampilan file view pdf - Optimalisasi admin ## No Isuue
This commit is contained in:
@@ -2,13 +2,43 @@
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAdminInvestasi } from "@/app/lib/router_admin/router_admin_investasi";
|
||||
import { toNumber } from "lodash";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function adminInvestasi_funAcceptTransaksiById({
|
||||
invoiceId,
|
||||
investasiId,
|
||||
lembarTerbeli,
|
||||
}: {
|
||||
invoiceId: string;
|
||||
investasiId: string;
|
||||
lembarTerbeli: string;
|
||||
}) {
|
||||
const dataInvestasi: any = await prisma.investasi.findFirst({
|
||||
where: {
|
||||
id: investasiId,
|
||||
},
|
||||
select: {
|
||||
totalLembar: true,
|
||||
sisaLembar: true,
|
||||
lembarTerbeli: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung TOTAL SISA LEMBAR
|
||||
const investasi_sisaLembar = toNumber(dataInvestasi?.sisaLembar);
|
||||
const invoice_lembarTerbeli = toNumber(lembarTerbeli);
|
||||
const resultSisaLembar = investasi_sisaLembar - invoice_lembarTerbeli;
|
||||
|
||||
// TAMBAH LEMBAR TERBELI
|
||||
const investasi_lembarTerbeli = toNumber(dataInvestasi?.lembarTerbeli);
|
||||
const resultLembarTerbeli = investasi_lembarTerbeli + invoice_lembarTerbeli;
|
||||
|
||||
// Progress
|
||||
const investasi_totalLembar = toNumber(dataInvestasi?.totalLembar);
|
||||
const progress = (resultLembarTerbeli / investasi_totalLembar) * 100;
|
||||
const resultProgres = toNumber(progress).toFixed(2);
|
||||
|
||||
const updt = await prisma.investasi_Invoice.update({
|
||||
where: {
|
||||
id: invoiceId,
|
||||
@@ -18,10 +48,27 @@ export async function adminInvestasi_funAcceptTransaksiById({
|
||||
},
|
||||
});
|
||||
|
||||
if (!updt) return { status: 400, message: "Gagal Update" };
|
||||
revalidatePath(RouterAdminInvestasi.detail_publish);
|
||||
return {
|
||||
status: 200,
|
||||
message: "Update Berhasil",
|
||||
};
|
||||
if (!updt) {
|
||||
return { status: 400, message: "Gagal Update Status" };
|
||||
} else {
|
||||
const updateInvestasi = await prisma.investasi.update({
|
||||
where: {
|
||||
id: investasiId,
|
||||
},
|
||||
data: {
|
||||
sisaLembar: resultSisaLembar.toString(),
|
||||
lembarTerbeli: resultLembarTerbeli.toString(),
|
||||
progress: resultProgres,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updateInvestasi)
|
||||
return { status: 400, message: "Gagal Update Data Investasi" };
|
||||
|
||||
revalidatePath(RouterAdminInvestasi.detail_publish);
|
||||
return {
|
||||
status: 200,
|
||||
message: "Update Berhasil",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ export async function adminInvestasi_funGetAllPublish({
|
||||
const data = await prisma.investasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
countDown: "desc",
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
countDown: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
active: true,
|
||||
masterStatusInvestasiId: "1",
|
||||
@@ -27,17 +29,7 @@ export async function adminInvestasi_funGetAllPublish({
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
hargaLembar: true,
|
||||
targetDana: true,
|
||||
totalLembar: true,
|
||||
roi: true,
|
||||
active: true,
|
||||
imagesId: true,
|
||||
catatan: true,
|
||||
include: {
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
@@ -46,8 +38,11 @@ export async function adminInvestasi_funGetAllPublish({
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
progress: true,
|
||||
sisaLembar: true,
|
||||
Investasi_Invoice: {
|
||||
where: {
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user