From d14a713ab9b0327e65da9f6849ff61dafe5c814e Mon Sep 17 00:00:00 2001 From: yenugukeerthana Date: Fri, 29 Sep 2023 12:01:13 +0530 Subject: [PATCH 1/7] Add. Inward Api workflow Co-authored-by: deeptirawat1510 --- src/inventory/aushada/aushada.jsx | 98 ++++++++++++++++--- .../aushada/eaushadha-response-mapper.js | 28 +++++- src/service/save-receipt.js | 3 +- src/utils/api-utils.js | 6 +- 4 files changed, 115 insertions(+), 20 deletions(-) diff --git a/src/inventory/aushada/aushada.jsx b/src/inventory/aushada/aushada.jsx index 5afbf57..0932356 100644 --- a/src/inventory/aushada/aushada.jsx +++ b/src/inventory/aushada/aushada.jsx @@ -3,6 +3,8 @@ import { ButtonSet, Column, DataTable, + DatePicker, + DatePickerInput, Grid, Loading, Row, @@ -30,11 +32,15 @@ import saveReceipt from '../../service/save-receipt'; import { fetcher, fetcherPost, + getRequest, + globalPropertyUrl, + stockInwardURL, stockReceiptURL, stockRoomURL } from '../../utils/api-utils'; import { getCalculatedQuantity, + getInwardStockReceiptObj, getStockReceiptObj, } from './eaushadha-response-mapper'; import styles from './aushada.module.scss'; @@ -55,18 +61,30 @@ const Aushada = (props) => { const [cookies] = useCookies(); const { setReloadData } = props; const { itemStock} = useItemStockContext(); + const [institutionId, setInstitutionId] = useState(''); + const [isDateSelected, setIsDateSelected] = useState(false); + const [isInstitutionIdDisabled, setInstitutionIdDisabled] = useState(true); + const [selectedDate, setSelectedDate] = useState(''); + const [enableEaushadhaInwardApi, setEnableEaushadhaInwardApi] = useState(''); const { data: stockRoom, error: stockRoomError } = useSWR( stockRoomURL(cookies[locationCookieName]?.name.trim()), fetcher, ); + useEffect(async ()=>{ + const response=await getRequest(globalPropertyUrl('eAushadha.inward')) + if(response==true){ + setEnableEaushadhaInwardApi(true); + } + },[enableEaushadhaInwardApi]) + useEffect(() => { if (stockIntakeButtonClick) { let outwardMatch = false; for (const result of itemStock) { for(const stockOperation of result.details){ - if (stockOperation.batchOperation.outwardId === outwardNumber) { + if (stockOperation.batchOperation.outwardId && stockOperation.batchOperation.outwardId === outwardNumber ) { outwardMatch = true; break; } @@ -84,9 +102,19 @@ const Aushada = (props) => { const fetchData = async () => { try { - const response = await fetcherPost(stockReceiptURL(), { ouid: outwardNumber }); + let url, requestBody; + + if (enableEaushadhaInwardApi) { + url = stockInwardURL(); + const formattedDate = new Date(new Date(selectedDate).setDate(new Date(selectedDate).getDate() + 1)).toISOString().split('T')[0]; + requestBody = { "inwardDate":formattedDate, "instituteId":institutionId}; + } else { + url = stockReceiptURL(); + requestBody = { ouid: outwardNumber }; + } + const response = await fetcherPost(url, requestBody); if (response) { - setItems(getStockReceiptObj(response)); + setItems(enableEaushadhaInwardApi ? getInwardStockReceiptObj(response) : getStockReceiptObj(response)); setReceivedResponse(response); setStockEmptyResonseMessage(response.length === 0); } @@ -98,7 +126,7 @@ const Aushada = (props) => { fetchData(); } } - }, [stockIntakeButtonClick, outwardNumber]); + }, [stockIntakeButtonClick, outwardNumber,selectedDate,institutionId,items]); useEffect(() => { if (items.length > 0) { @@ -113,19 +141,21 @@ const Aushada = (props) => { }, [items]); useEffect(() => { - if (outwardNumber.length > 0) { + if (outwardNumber.length > 0 || (institutionId.length > 0 && isDateSelected)) { setIsOutwardNumberDisabled(false); setIsFetchStockDisabled(false); + setInstitutionIdDisabled(false) } else { setIsOutwardNumberDisabled(false); setIsFetchStockDisabled(true); + setInstitutionIdDisabled(false) } if (items.length > 0) { setIsOutwardNumberDisabled(true); setIsFetchStockDisabled(true); } - }, [items, outwardNumber]); + }, [items, outwardNumber, institutionId, isDateSelected]); useEffect(() => { if (onSuccesful) { @@ -184,6 +214,11 @@ const Aushada = (props) => { setOnFailure(status); }; + + const handleDateChange = (date) => { + setSelectedDate(date[0]); + setIsDateSelected(true); + }; return ( <> @@ -196,16 +231,47 @@ const Aushada = (props) => { ResponseNotification('error', 'Error', failureMessage, setOnSuccessAndFailure)} - - setOutwardNumber(e.target.value)} - disabled={isOutwardNumberDisabled} - /> - + {enableEaushadhaInwardApi ? ( + <> + + setInstitutionId(e.target.value)} + disabled={isInstitutionIdDisabled} + /> + + + + + + + ) : ( + <> + + setOutwardNumber(e.target.value)} + disabled={isOutwardNumberDisabled} + /> + + + )}