"use client"; import { MainColor } from "@/app_modules/_global/color/color_pallet"; import { ComponentGlobal_BoxInformation, ComponentGlobal_BoxUploadImage, ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import { ComponentGlobal_WarningMaxUpload, maksimalUploadFile, } from "@/app_modules/_global/component/waring_popup"; import { MODEL_DEFAULT_MASTER_OLD } from "@/app_modules/model_global/model_default_master"; import { AspectRatio, Box, Button, Center, FileButton, Grid, Group, Image, Select, Stack, Text, TextInput, } from "@mantine/core"; import { IconCamera, IconCircleCheck, IconFileTypePdf, IconUpload } from "@tabler/icons-react"; import _ from "lodash"; import { useState } from "react"; import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component"; export default function InvestasiCreate({ pencarianInvestor, periodeDeviden, pembagianDeviden, }: { pencarianInvestor: MODEL_DEFAULT_MASTER_OLD[]; periodeDeviden: MODEL_DEFAULT_MASTER_OLD[]; pembagianDeviden: MODEL_DEFAULT_MASTER_OLD[]; }) { const [fileImage, setFileImage] = useState(null); const [img, setImg] = useState(); const [filePdf, setFilePdf] = useState(null); const [fPdf, setFPdf] = useState(null); const [totalLembar, setTotalLembar] = useState(0); const [value, setValue] = useState({ title: "", targetDana: 0, hargaLembar: 0, roi: 0, pencarianInvestorId: "", periodeDevidenId: "", pembagianDevidenId: "", }); const [target, setTarget] = useState(""); const [harga, setHarga] = useState(""); async function onTotalLembar({ target, harga, }: { target?: number | any; harga?: number | any; }) { if (target !== 0 && harga !== 0) { const hasil: any = target / harga; setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil)); } } return ( <> {/* Upload Image */} {img ? ( Foto ) : ( Upload Gambar )} {/* Upload Foto */} { try { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); // console.log(files.size); if (files.size > maksimalUploadFile) { ComponentGlobal_WarningMaxUpload({}); } else { setImg(buffer); setFileImage(files); } } catch (error) { console.log(error); } }} accept="image/png,image/jpeg" > {(props) => ( )} {/* Upload File */} {!filePdf ? ( Upload File Prospektus ) : ( {filePdf.name}
)}
{/* {!pdf ? ( Upload File Prospektus ) : ( {pdf.name} )} */} {/* {JSON.stringify(filePdf)} */} { try { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); setFPdf(buffer); setFilePdf(files); } catch (error) { console.log(error); } }} > {(props) => ( )}
{ setValue({ ...value, title: val.target.value, }); }} /> Rp.} min={0} withAsterisk label="Dana Dibutuhkan" placeholder="0" value={target} onChange={(val) => { // console.log(typeof val) const match = val.currentTarget.value .replace(/\./g, "") .match(/^[0-9]+$/); if (val.currentTarget.value === "") return setTarget(0 + ""); if (!match?.[0]) return null; const nilai = val.currentTarget.value.replace(/\./g, ""); const targetNilai = Intl.NumberFormat("id-ID").format(+nilai); onTotalLembar({ target: +nilai, harga: +value.hargaLembar, }); setTarget(targetNilai); setValue({ ...value, targetDana: +nilai, }); }} /> Rp.} min={0} withAsterisk label="Harga Per Lembar" placeholder="0" value={harga} onChange={(val) => { try { // console.log(typeof +val.currentTarget.value); const match = val.currentTarget.value .replace(/\./g, "") .match(/^[0-9]+$/); if (val.currentTarget.value === "") return setHarga(0 + ""); if (!match?.[0]) return null; const nilai = val.currentTarget.value.replace(/\./g, ""); const targetNilai = Intl.NumberFormat("id-ID").format(+nilai); onTotalLembar({ harga: +nilai, target: +value.targetDana, }); setHarga(targetNilai); setValue({ ...value, hargaLembar: +nilai, }); } catch (error) { console.log(error); } }} /> % } withAsterisk type="number" label={"Rasio Keuntungan / ROI %"} placeholder="Masukan rasio keuntungan" onChange={(val) => { setValue({ ...value, roi: _.toNumber(val.target.value), }); }} /> ({ value: e.id, label: e.name }))} onChange={(val) => { setValue({ ...(value as any), periodeDevidenId: val, }); }} />