From 68026ddd66fbebd0d89a661c3c187072157f97cf Mon Sep 17 00:00:00 2001 From: "Siddhesh.More" Date: Fri, 30 Aug 2024 16:09:07 +0530 Subject: [PATCH] updated final fixes --- .../CreateIO/IOArtifactsVideo.jsx | 3 +- .../IO_Management/CreateIO/IOCashDetails.jsx | 31 ++ .../IO_Management/CreateIO/IONAVDetails.jsx | 4 +- .../HeaderModal/DistributionInvestor.jsx | 32 +- .../IO_Management/ViewIO/HeaderModal/Exit.jsx | 500 +++++++++++++----- .../IO_Management/ViewIO/ViewIOdataHeader.jsx | 9 +- .../InvestorDetails/Transaction.jsx | 35 +- 7 files changed, 427 insertions(+), 187 deletions(-) diff --git a/src/Pages/IO_Management/CreateIO/IOArtifactsVideo.jsx b/src/Pages/IO_Management/CreateIO/IOArtifactsVideo.jsx index 5416043..535f7a7 100644 --- a/src/Pages/IO_Management/CreateIO/IOArtifactsVideo.jsx +++ b/src/Pages/IO_Management/CreateIO/IOArtifactsVideo.jsx @@ -29,8 +29,7 @@ const investmentVideoSchema = yup.object().shape({ artifactName: yup.string().required("Artifact name is required"), artifactStreamingURL: yup.string() .required("Artifact streaming URL is required") - .url("Invalid URL format") - .matches(/\.mp4$/, "URL must end with .mp4"), + .url("Invalid URL format"), }); const IOArtifactsAdd = ({ isOpen, onClose, firstField, actionId, setActionId, data }) => { diff --git a/src/Pages/IO_Management/CreateIO/IOCashDetails.jsx b/src/Pages/IO_Management/CreateIO/IOCashDetails.jsx index a1423fc..82b16ce 100644 --- a/src/Pages/IO_Management/CreateIO/IOCashDetails.jsx +++ b/src/Pages/IO_Management/CreateIO/IOCashDetails.jsx @@ -24,6 +24,8 @@ import ToastBox from "../../../Components/ToastBox"; import { debounce } from "../../Master/Sponser/AddSponser"; import { AddIcon } from "@chakra-ui/icons"; import AddCashDetails from "./AddCashDetails"; +import { LuFileSpreadsheet } from "react-icons/lu"; +import { exportToExcel } from "../../../Constants/Constants"; const formatDate = (date) => new Date(date).toLocaleDateString(); // Simple date formatter @@ -178,6 +180,18 @@ const IOCashDetails = () => { ), })); + + + const customHeaders = [ + { label: "Date", key: "transactionDate" }, + { label: "Transaction type", key: "transactionType" }, + { label: "Amount", key: "transactionAmount" }, + { label: "Comments", key: "comments" }, + // { label: "Update by", key: "creator" }, + // { label: "Update On", key: "updateOn" }, + // Add more headers as needed + ]; + const handleDelete = () => { const updatedSponsors = sponser.filter( (sponsor) => sponsor.id !== actionId @@ -289,6 +303,22 @@ const IOCashDetails = () => { onChange={(e) => setSearchTerm(e.target.value)} /> + + + + {IODetails?.isInvestedAmount ? ( ) : null} + { { label: "Investment Closed", key: "initialNAVvalue" }, { label: "Comments", key: "comments" }, - { label: "Update by", key: "creator" }, + // { label: "Update by", key: "creator" }, { label: "Transaction Type", key: "transactionType" }, - { label: "Comments", key: "comments" }, + // { label: "Comments", key: "comments" }, // Add more headers as needed ]; diff --git a/src/Pages/IO_Management/ViewIO/HeaderModal/DistributionInvestor.jsx b/src/Pages/IO_Management/ViewIO/HeaderModal/DistributionInvestor.jsx index 483fd2f..fca1287 100644 --- a/src/Pages/IO_Management/ViewIO/HeaderModal/DistributionInvestor.jsx +++ b/src/Pages/IO_Management/ViewIO/HeaderModal/DistributionInvestor.jsx @@ -45,7 +45,7 @@ import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; -const DistributionInvestor = ({ isOpen, onClose, exit }) => { +const DistributionInvestor = ({ isOpen, onClose }) => { const params = useParams(); const toast = useToast(); const id = params?.id; @@ -55,6 +55,10 @@ const DistributionInvestor = ({ isOpen, onClose, exit }) => { const [ isCalcualtedData, setIsCalcualtedData ] = useState(false) const { IODetails } = useContext(GlobalStateContext); + + + + // const { // data:IObyID, // error, @@ -94,20 +98,10 @@ const DistributionInvestor = ({ isOpen, onClose, exit }) => { formState: { errors }, reset, } = useForm({ - resolver: yupResolver(!exit? investorExit: investor), + resolver: yupResolver(investor), }); - // useEffect(()=>{ - // try { - // const res = getDistributionInvestment({id,data}) - // console.log(res); - - // } catch (error) { - - // } - // },[]) - - // console.log(IObyID); + // ====================================================[Table Setup]================================================================ const tableHeadRow = [ @@ -357,7 +351,9 @@ const DistributionInvestor = ({ isOpen, onClose, exit }) => { const handleClose = () => { onClose(); setIsFinalCalculateLoading(false); - reset(); + reset({ + amount:"" + }); setCalculatedDate(null); setIsCalcualtedData(false); }; @@ -367,7 +363,7 @@ const DistributionInvestor = ({ isOpen, onClose, exit }) => { - {exit ? "Enter Exit Amount" : " Distribution To Investor Transaction"} + Distribution To Investor Transaction @@ -379,7 +375,7 @@ const DistributionInvestor = ({ isOpen, onClose, exit }) => { {" "} - {exit ? "Enter Exit Amount" : "Amount to Distribute"} + Amount to Distribute { /> )} /> - {/* */} + {errors.amount?.message} diff --git a/src/Pages/IO_Management/ViewIO/HeaderModal/Exit.jsx b/src/Pages/IO_Management/ViewIO/HeaderModal/Exit.jsx index 74fc695..c6d7cc3 100644 --- a/src/Pages/IO_Management/ViewIO/HeaderModal/Exit.jsx +++ b/src/Pages/IO_Management/ViewIO/HeaderModal/Exit.jsx @@ -1,7 +1,10 @@ import { + Alert, + AlertIcon, Box, Button, FormControl, + FormErrorMessage, FormLabel, HStack, Input, @@ -19,115 +22,219 @@ import { Textarea, Th, Tr, + useToast, } from "@chakra-ui/react"; -import DataTable from "../../../../Components/DataTable/DataTable"; -import { useState } from "react"; +import NormalData from "../../../../Components/DataTable/NormalTable"; +import { useContext, useState } from "react"; import { AddIcon } from "@chakra-ui/icons"; +import { + useGetDistributedToInvestorMutation, + useGetDistributionInvestorMutation, + useUpdateExitToInvestorMutation, +} from "../../../../Services/io.service"; +import { useParams } from "react-router-dom"; +import { useEffect } from "react"; +import { Controller, useForm } from "react-hook-form"; +import * as yup from "yup"; +import { yupResolver } from "@hookform/resolvers/yup"; +import ToastBox from "../../../../Components/ToastBox"; +import CurrencyInput from "../../../../Components/CurrencyInput"; +import { IoCalculator } from "react-icons/io5"; +import { debounce } from "../../../Master/Sponser/AddSponser"; +import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; const Exit = ({ isOpen, onClose }) => { + const params = useParams(); + const toast = useToast(); + const id = params?.id; + const [isCalculateLoading, setIsCalculateLoading] = useState(false); + const [isFinalCalculateLoading, setIsFinalCalculateLoading] = useState(false); + const [calcualtedData, setCalculatedDate] = useState(null); + const [isCalcualtedData, setIsCalcualtedData] = useState(false); + const { IODetails } = useContext(GlobalStateContext); + + const investorExit = yup.object().shape({ + amount: yup + .string() + .required("Amount is required") + .test( + "max", + `Distribution amount should not be greater than IO cash amount ${IODetails?.ioCash}`, + function (value) { + const { ioCash } = IODetails || {}; // Safely get ioCash + if (value && ioCash) { + return parseFloat(value) <= parseFloat(ioCash); // Ensure both are compared as numbers + } + return true; // If ioCash is not available, skip validation + } + ), + }); + + const { + control, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: yupResolver(investorExit), + }); + + useEffect(() => { + console.log("hiit useEffectc"); + handleCalculate(id, { + amount: IODetails?.ioMVNAV, + }); + reset({ + amount: IODetails?.ioMVNAV, + }); + }, [IODetails, id]); + + const handleCalculate = async (id, data) => { + try { + const res = await getDistributionInvestment({ id, data }); + console.log(res?.data?.data); + + if (res?.error?.status === 401) { + // toast({ + // render: () => ( + // + // ), + // }); + setIsCalculateLoading(false); + setIsCalcualtedData(false); + } else if (res?.data?.statusCode === 200) { + setCalculatedDate(res?.data?.data); + // toast({ + // render: () => , + // }); + setIsCalculateLoading(false); + setIsCalcualtedData(true); + } + } catch (error) {} + }; + + // const { + // data:IObyID, + // error, + // isLoading, + // } = useGetDistributionInvestorMutation(id); + + const [getDistributionInvestment] = useGetDistributionInvestorMutation(); + const [getFinalDistributionInvestment] = + useGetDistributedToInvestorMutation(); + const [updateExitToInvestor] = useUpdateExitToInvestorMutation(); + + const investor = yup.object().shape({ + amount: yup.string().required("Amount is required"), + }); + + // useEffect(()=>{ + // try { + // const res = getDistributionInvestment({id,data}) + // console.log(res); + + // } catch (error) { + + // } + // },[]) + + // console.log(IObyID); + // ====================================================[Table Setup]================================================================ const tableHeadRow = [ "Sr No.", "Client Id", "First name", "Last Name", - "Invested Amount", - "Distribution %", - "Exit Amount", + "Amount", + "Holding %", + "($)", ]; - const filteredData = [ - { - id: 1, - }, - { - id: 1, - }, - { - id: 1, - }, - { - id: 1, - }, - { - id: 1, - }, - { - id: 1, - }, - ]; - - const [extractedArray, setExtractedArray] = useState( - filteredData?.map((item, index) => ({ - id: item?.id, - "Sr No.": ( - ({ + id: item?.id, + "Sr No.": ( + + + {index + 1} + + + ), + "Client Id": ( + + + {item?.clientId} + + + ), + "First name": ( + + + {item?.firstName} + + + ), + "Last Name": ( + + + {item?.lastName} + + + ), + Amount: ( + + + {item?.amount?.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + + + ), + "Holding %": ( + + - - {index + 1} - - - ), - "Client Id": ( - - - BH0000000 - - - ), - "First name": ( - - - Faisal - - - ), - "Last Name": ( - - - Aljalahma - - - ), - "Invested Amount": ( - - - $100,000 - - - ), - "Distribution %": ( - - - 26.0 % - - - ), - "Exit Amount": ( - - - $100,000 - - - ), - })) - ); + {parseFloat(item?.distribution_per).toFixed(2)}% + + + ), + "($)": ( + + + {item?.distribution_amt?.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + + + ), + })); + + + + + + + + + const Total = () => { return ( - - + + @@ -211,52 +325,166 @@ const Exit = ({ isOpen, onClose }) => { ); }; + const onSubmit = async (data) => { + setIsCalculateLoading(true); + + try { + const res = await getDistributionInvestment({ id, data }); + console.log(res?.data?.data); + + if (res?.error?.status === 401) { + toast({ + render: () => ( + + ), + }); + setIsCalculateLoading(false); + setIsCalcualtedData(false); + } else if (res?.data?.statusCode === 200) { + setCalculatedDate(res?.data?.data); + toast({ + render: () => , + }); + setIsCalculateLoading(false); + setIsCalcualtedData(true); + } + } catch (error) {} + }; + + const onFinalSubmit = async (data) => { + setIsFinalCalculateLoading(true); + if (!isCalcualtedData) { + setIsFinalCalculateLoading(false); + return toast({ + render: () => ( + + ), + }); + } + + const finalData = { + transactionAmount: data?.amount, + }; + + try { + const res = (await exit) + ? updateExitToInvestor({ id, data: finalData }) + : getFinalDistributionInvestment({ id, data: finalData }); + console.log(finalData); + + if (res?.error?.status === 401) { + toast({ + render: () => ( + + ), + }); + } else if (res?.data?.statusCode === 200) { + toast({ + render: () => , + }); + handleClose(); + } + } catch (error) { + console.error("An error occurred:", error); + } finally { + handleClose(); + } + }; + + const handleClose = () => { + onClose(); + setIsFinalCalculateLoading(false); + setCalculatedDate(null); + setIsCalcualtedData(false); + }; + return ( - + - Exit Transaction + Enter Exit Amount - Enter Exit Amount - - - + {/* + Amount to Distribute + */} + + {/* */} + + + Enter Exit Amount + + + ( + + )} + /> + + + {errors.amount?.message} + + - } - // isLoading={isLoading} - /> + {/* {calcualtedData && ( */} + } + // isLoading={isLoading} + /> + {/* ) } */} - - + {isCalcualtedData ? ( + <> + + + + ) : ( + "" + )} diff --git a/src/Pages/IO_Management/ViewIO/ViewIOdataHeader.jsx b/src/Pages/IO_Management/ViewIO/ViewIOdataHeader.jsx index 82b8d51..57e5c0b 100644 --- a/src/Pages/IO_Management/ViewIO/ViewIOdataHeader.jsx +++ b/src/Pages/IO_Management/ViewIO/ViewIOdataHeader.jsx @@ -481,24 +481,17 @@ const ViewIOdataHeader = ({ data, isLoading }) => { {/* Modals */} - {/* */} + - - { // "Sr N/O", "Date", "Transaction", - "Amount in investors currency", + "Amount", // "Currency", - "TO USD", - "From USD", + // "TO USD", + // "From USD", "USD amount", "IO Name", "Payment Method", @@ -133,7 +133,7 @@ const Transaction = () => { ), - "Amount in investors currency": ( + "Amount": ( {/* {item.investorAmount} */} @@ -158,7 +158,10 @@ const Transaction = () => { ), "USD amount": ( + + { + item?.invCurToUSD_Rate === '0.0000' && ( {/* {item.USDAmount} */} {parseFloat(item?.USDAmount || 0).toLocaleString(undefined, { @@ -169,6 +172,8 @@ const Transaction = () => { $ + ) + } ), "IO Name": ( @@ -207,8 +212,8 @@ const Transaction = () => { ), Transaction: null, // "Currency": null, - "Amount in investors currency": ( - + "Amount": ( + InvestorWallet?.currencyCode_InCur&& {parseFloat(InvestorWallet?.WalletBalance_InInvCur).toLocaleString( undefined, @@ -220,21 +225,9 @@ const Transaction = () => { ), - "TO USD": null, - "From USD": null, - "USD amount": ( - - - {parseFloat(InvestorWallet?.WalletBalance_InUSD).toLocaleString( - undefined, - { minimumFractionDigits: 2, maximumFractionDigits: 2 } - )} - - $ - - - - ), + // "TO USD": null, + // "From USD": null, + "USD amount": null, "IO Name": null, "Payment Method": null, };
{ { { { - $1,000,000 + {calcualtedData?.totalInvestedAmt?.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} { whiteSpace="normal" wordBreak="normal" overflowWrap="normal" + opacity={0} > - 100.0% + {calcualtedData?.distributed_per?.toFixed(2)}% { wordBreak="normal" overflowWrap="normal" > - $1,229,750 + {calcualtedData?.distributed_amt?.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })}