database investasi

# feat:
- Create investasi
- Edit investasi
- Ubah status investasi
- Masukan berita
### No issue
This commit is contained in:
2023-11-07 21:22:53 +08:00
parent 9fcbba24e3
commit b662b714ad
88 changed files with 1386 additions and 637 deletions

View File

@@ -16,6 +16,8 @@ import {
Select,
TextInput,
Image,
NumberInput,
Stack,
} from "@mantine/core";
import { IconCamera, IconChevronRight } from "@tabler/icons-react";
import Link from "next/link";
@@ -23,21 +25,57 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-simple-toasts";
import { MODEL_Investasi } from "../model/model_investasi";
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
import _ from "lodash";
import { MODEL_DEFAULT_MASTER } from "@/app_modules/models/model_default_master";
import funEditInvestasi from "../fun/fun_edit_investasi";
export default function EditIntroInvestasi() {
export default function EditIntroInvestasi({
dataInvestasi,
listPencarian,
listPeriode,
listPembagian,
}: {
dataInvestasi: MODEL_Investasi;
listPencarian: MODEL_DEFAULT_MASTER[];
listPeriode: MODEL_DEFAULT_MASTER[];
listPembagian: MODEL_DEFAULT_MASTER[];
}) {
const router = useRouter();
const [edit, setEdit] = useState(true);
const [edit_inves, setEdit_inves] = useState(dataInvestasi);
const [img, setImg] = useState<any | null>();
const [value, setValue] = useState({
title: "",
targetDana: "",
hargaLembar: "",
totalLembar: "",
roi: "",
pencarianInvestorId: "",
periodeDevidenId: "",
pembagianDevidenId: "",
});
const [fl, setFl] = useState<File | null>(null);
const [totalLembar, setTotalLembar] = useState<number | any>(
edit_inves.totalLembar
);
async function onTotalLembar(target: any, harga: any) {
const hasil: any = target / harga;
setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil));
}
async function onUpdate() {
if (_.values(edit_inves).includes("")) return toast("Lengkapi data");
// if (!fl) return toast("File Kosong");
const fd = new FormData();
fd.append("file", fl as any);
// router.back()
// await funEditInvestasi(fd, edit_inves).then((res) =>
// res.status === 200 ? router.back() : toast(res.message)
// );
await funEditInvestasi(fd, edit_inves).then(async (res) => {
if (res.status === 200) {
toast(res.message);
router.replace(RouterInvestasi.edit + `${edit_inves.id}`);
} else {
toast(res.message);
}
});
}
return (
<>
@@ -46,7 +84,10 @@ export default function EditIntroInvestasi() {
{img ? (
<Image alt="" src={img} />
) : (
<Image alt="" src={"/aset/no-img.png"} />
<Image
alt=""
src={RouterInvestasi.api_gambar + `${edit_inves.imagesId}`}
/>
)}
</AspectRatio>
<Group position="center" mt={"md"}>
@@ -55,19 +96,13 @@ export default function EditIntroInvestasi() {
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
// setImg(buffer);
// setFl(files);
setImg(buffer);
setFl(files);
}}
accept="image/png,image/jpeg"
>
{(props) => (
<Button
{...props}
w={350}
radius={50}
// bg={Warna.biru}
// onClick={() => router.push("/dev/investasi/upload")}
>
<Button {...props} w={350} radius={50}>
<IconCamera />
</Button>
)}
@@ -78,92 +113,117 @@ export default function EditIntroInvestasi() {
<Box mt={"md"} w={350}>
<TextInput
label="Judul Proyek"
placeholder={"Masukan Judul"}
value={edit_inves.title}
onChange={(val) => {
setValue({
...value,
setEdit_inves({
...edit_inves,
title: val.target.value,
});
}}
/>
<TextInput
<NumberInput
label="Dana Dibutuhan"
type="number"
value={+edit_inves.targetDana}
onChange={(val) => {
setValue({
...value,
targetDana: val.target.value,
setEdit_inves({
...edit_inves,
targetDana: val as any,
});
}}
/>
<TextInput
<NumberInput
label="Harga Per Lember"
type="number"
value={+edit_inves.hargaLembar}
onChange={(val) => {
setValue({
...value,
hargaLembar: val.target.value,
setEdit_inves({
...edit_inves,
hargaLembar: val as any,
});
onTotalLembar(edit_inves.targetDana, val);
}}
/>
<TextInput
label="Total Lembar"
type="number"
onChange={(val) => {
setValue({
...value,
totalLembar: val.target.value,
});
}}
/>
<TextInput
{/* Total Lembar */}
<Stack spacing={3}>
<Text fz={"sm"} fw={500}>
Total Lembar
</Text>
<Stack spacing={0}>
<Text>{totalLembar}</Text>
<Divider />
</Stack>
<Text c={"red"} fz={10}>
*Total lembar dihitung dari, Target Dana : Harga Perlembar
</Text>
</Stack>
<NumberInput
label="Rasio Keuntungan / ROI"
type="number"
value={+edit_inves.roi}
onChange={(val) => {
setValue({
...value,
roi: val.target.value,
setEdit_inves({
...edit_inves,
roi: val as any,
});
}}
/>
{/* Select Start */}
<Select
label="Pencarian Investor"
// data={pencarianInvestor.map((e) => ({
// value: e.id,
// label: e.name,
// }))}
data={[]}
data={listPencarian.map((e) => ({
value: e.id,
label: e.name + " " + "hari",
}))}
value={edit_inves.MasterPencarianInvestor.id}
onChange={(val) => {
setValue({
...(value as any),
pencarianInvestorId: val,
setEdit_inves({
...(edit_inves as any),
MasterPencarianInvestor: {
id: val,
},
});
}}
/>
<Select
label="Periode Deviden"
// data={periodeDeviden.map((e) => ({ value: e.id, label: e.name }))}
data={[]}
data={listPeriode.map((e) => ({
value: e.id,
label: e.name,
}))}
value={edit_inves.MasterPeriodeDeviden.id}
onChange={(val) => {
setValue({
...(value as any),
periodeDevidenId: val,
setEdit_inves({
...(edit_inves as any),
MasterPeriodeDeviden: {
id: val,
},
});
}}
/>
<Select
label="Pembagian Deviden"
// data={pembagianDeviden.map((e) => ({
// value: e.id,
// label: e.name,
// }))}
data={[]}
data={listPembagian.map((e) => ({
value: e.id,
label: e.name + " " + `${"bulan"}`,
}))}
value={edit_inves.MasterPembagianDeviden.id}
onChange={(val) => {
setValue({
...(value as any),
pembagianDevidenId: val,
setEdit_inves({
...(edit_inves as any),
MasterPembagianDeviden: {
id: val,
},
});
}}
/>
{/* Select End */}
</Box>
</Center>
<Center my={"lg"}>
@@ -172,9 +232,8 @@ export default function EditIntroInvestasi() {
radius={50}
bg={Warna.hijau_muda}
color="green"
// onClick={() => onSubmit() }
onClick={() => {
router.back(), toast("Data terupdate");
onUpdate();
}}
>
Update