From a772891ae0f8421b855904f40e0ed8bcbea38150 Mon Sep 17 00:00:00 2001 From: workashrafi77-web Date: Tue, 10 Feb 2026 12:16:49 +0330 Subject: [PATCH] Add: add colhouse fields to waiting bars --- .../CityNewKillRequest.js | 25 ++- .../SlaughterInventoryFreeBuyBarsAlives.js | 20 +-- .../SlaughterInventoryInProvinceBars.js | 28 ++-- .../SlaughterSubmitRealInventory.js | 155 +++++++++++++++++- .../InquiryForAdminAddBuyer.js | 13 +- .../StewardSellOutOfProvinceAddBuyer.js | 40 ++--- 6 files changed, 220 insertions(+), 61 deletions(-) diff --git a/src/features/city/components/city-new-kill-request/CityNewKillRequest.js b/src/features/city/components/city-new-kill-request/CityNewKillRequest.js index 941c366..33cba17 100644 --- a/src/features/city/components/city-new-kill-request/CityNewKillRequest.js +++ b/src/features/city/components/city-new-kill-request/CityNewKillRequest.js @@ -977,6 +977,30 @@ export const CityNewKillRequest = ({ اطلاعات کشتار + + prop.palette.grey["A700"]} + variant="caption" + > + سن (روز): + + + {hatchingSelected?.age != null && hatchingSelected?.age !== "" + ? Number(hatchingSelected.age).toLocaleString() + : "-"} + + + {/* {!data?.approved && formik.values.avicultureSellType !== "goverment" && ( diff --git a/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars-alives/SlaughterInventoryFreeBuyBarsAlives.js b/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars-alives/SlaughterInventoryFreeBuyBarsAlives.js index 74b520a..4fb016b 100644 --- a/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars-alives/SlaughterInventoryFreeBuyBarsAlives.js +++ b/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars-alives/SlaughterInventoryFreeBuyBarsAlives.js @@ -8,7 +8,7 @@ import ResponsiveTable from "../../../../components/responsive-table/ResponsiveT import { LOADING_END, LOADING_START, - OPEN_MODAL + OPEN_MODAL, } from "../../../../lib/redux/slices/appSlice"; import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; import { formatJustDate } from "../../../../utils/formatTime"; @@ -30,7 +30,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ withDate, selectedDate1, selectedDate2, - searchValue + searchValue, }) => { const dispatch = useDispatch(); const [openNotif] = useContext(AppContext); @@ -43,7 +43,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ slaughterGetProfile({ role_key: checkPathStartsWith("slaughter") ? selectedSubUser?.key || "" - : "" + : "", }) ); }, [selectedSubUser?.key]); @@ -93,7 +93,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ fetchSlaughterBroadcastAndProducts({ role_key: checkPathStartsWith("slaughter") ? selectedSubUser?.key || "" - : "" + : "", }) ); }; @@ -106,11 +106,11 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ selectedDate1, selectedDate2, searchValue, - selectedSubUser?.key + selectedSubUser?.key, ]); useEffect(() => { - if (refreshTrigger != null && refreshTrigger > 0) { + if (refreshTrigger !== null && refreshTrigger > 0) { setPage(1); fetchApiData(1); } @@ -161,7 +161,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ item={item} updateTable={updateTable} /> - ) + ), }) ); }} @@ -169,7 +169,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ تایید / رد )} - + , ]; }); @@ -198,7 +198,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ vertical: "top", horizontal: "center", msg: "فایل اکسل در حال دانلود می باشد، این علمیات ممکن است زمان بر باشد لطفا صبر کنید.", - severity: "success" + severity: "success", }); const link = `${ axios.defaults.baseURL @@ -238,7 +238,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ "وزن لاشه (کیلوگرم)", "درصد افت", "بارنامه", - "عملیات" + "عملیات", ]} handlePageChange={handlePageChange} totalRows={totalRows} diff --git a/src/features/slaughter-house/components/slaughter-inventory-in-province-bars/SlaughterInventoryInProvinceBars.js b/src/features/slaughter-house/components/slaughter-inventory-in-province-bars/SlaughterInventoryInProvinceBars.js index 8a91bb1..b9ef391 100644 --- a/src/features/slaughter-house/components/slaughter-inventory-in-province-bars/SlaughterInventoryInProvinceBars.js +++ b/src/features/slaughter-house/components/slaughter-inventory-in-province-bars/SlaughterInventoryInProvinceBars.js @@ -9,7 +9,7 @@ import { MenuItem, Select, TextField, - Tooltip + Tooltip, } from "@mui/material"; import { DatePicker } from "@mui/x-date-pickers"; import moment from "moment"; @@ -18,7 +18,7 @@ import axios from "axios"; import { LOADING_END, LOADING_START, - OPEN_MODAL + OPEN_MODAL, } from "../../../../lib/redux/slices/appSlice"; import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable"; @@ -34,7 +34,7 @@ export const SlaughterInventoryInProvinceBars = ({ useExternalFilters = false, filterValues = {}, onAfterUpdate, - refreshTrigger + refreshTrigger, }) => { const [selectedDate1, setSelectedDate1] = useState( moment(new Date()).format("YYYY-MM-DD") @@ -65,14 +65,14 @@ export const SlaughterInventoryInProvinceBars = ({ selectedDate2: filterValues.selectedDate2 ?? selectedDate2, withDate: filterValues.withDate ?? withDate, textValue: filterValues.textValue ?? textValue, - quota: filterValues.quota ?? quota + quota: filterValues.quota ?? quota, } : { selectedDate1, selectedDate2, withDate, textValue, - quota + quota, }; const fetchApiData = useCallback( @@ -106,7 +106,9 @@ export const SlaughterInventoryInProvinceBars = ({ perPage, type, dispatch, - selectedSubUser?.key + selectedSubUser?.key, + setData, + setTotalRows, ] ); @@ -151,7 +153,11 @@ export const SlaughterInventoryInProvinceBars = ({ item?.killhouseUser?.name } (${item?.killhouseUser?.killHouseOperator?.user?.mobile})`, item?.poultryRequest?.poultryReqOrderCode, - item?.freezing ? "انجماد" : item?.export ? "صادرات" : "عادی", + item?.poultryRequest?.freezing + ? "انجماد" + : item?.poultryRequest?.export + ? "صادرات" + : "عادی", item?.killer ? `${item?.killer?.name} (${item?.killer?.killHouseOperator?.user?.mobile})` : "-", @@ -187,14 +193,14 @@ export const SlaughterInventoryInProvinceBars = ({ updateTable={updateTable} item={item} /> - ) + ), }) ); }} > - + , ]; }); @@ -241,7 +247,7 @@ export const SlaughterInventoryInProvinceBars = ({ padding: "10px", borderRadius: "15px", borderColor: "gray", - justifyContent: "left" + justifyContent: "left", }} > {type === "notentered" && ( @@ -356,7 +362,7 @@ export const SlaughterInventoryInProvinceBars = ({ "درصد افت در لحظه", "درصد افت ورود به انبار", "تاریخ ورود به انبار", - "عملیات" + "عملیات", ]} handlePageChange={handlePageChange} totalRows={totalRows} diff --git a/src/features/slaughter-house/components/slaughter-submit-real-inventory/SlaughterSubmitRealInventory.js b/src/features/slaughter-house/components/slaughter-submit-real-inventory/SlaughterSubmitRealInventory.js index 03fea3a..4b24e02 100644 --- a/src/features/slaughter-house/components/slaughter-submit-real-inventory/SlaughterSubmitRealInventory.js +++ b/src/features/slaughter-house/components/slaughter-submit-real-inventory/SlaughterSubmitRealInventory.js @@ -6,8 +6,11 @@ import { Button, FormControl, FormControlLabel, + InputLabel, + MenuItem, Radio, RadioGroup, + Select, TextField, Typography, } from "@mui/material"; @@ -19,6 +22,7 @@ import { AppContext } from "../../../../contexts/AppContext"; import { provincePolicyGetDropLimitService } from "../../../province/services/province-policy-drop-limit"; import { fetchSlaughterBroadcastAndProducts } from "../../services/handle-fetch-slaughter-products"; import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith"; +import { liveStockGetInventoryData } from "../../../live-stock-support/services/live-stock-get-inventory-data"; export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { const [value, setValue] = useState("weight"); @@ -33,6 +37,7 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { const [inputWarehouse, setInputWarehouse] = useState( item?.killer ? "killer" : "self" ); + const [coldHouses, setColdHouses] = useState([]); const handleChangeInputWarehouse = (event) => { setInputWarehouse(event.target.value); @@ -52,6 +57,15 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { }); }, []); + useEffect(() => { + if (item?.poultryRequest?.freezing || item?.freezing) { + dispatch(liveStockGetInventoryData()).then((r) => { + const list = r.payload?.data ?? []; + setColdHouses(Array.isArray(list) ? list : list?.results ?? []); + }); + } + }, [item?.poultryRequest?.freezing, item?.freezing, dispatch]); + const formik = useFormik({ initialValues: { realNumber: item?.acceptedRealQuantity ? item?.acceptedRealQuantity : "", @@ -90,6 +104,52 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { }), }); + const maxWeightForColdHouse = + value === "weight" + ? formik.values.realWeight + ? parseFloat(formik.values.realWeight) + : 0 + : parseFloat(loss) || 0; + + const formik3 = useFormik({ + initialValues: { + coldHouseKey: "", + coldHouseTransferWeight: "", + }, + validate: (values) => { + const errors = {}; + if (!item?.poultryRequest?.freezing && !item?.freezing) return errors; + const w = values.coldHouseTransferWeight; + const hasFreezingWeight = + w !== "" && w !== undefined && w !== null && String(w).trim() !== ""; + if (hasFreezingWeight) { + if (!values.coldHouseKey) { + errors.coldHouseKey = + "با وارد کردن وزن انتقالی، انتخاب سردخانه اجباری است!"; + } + const num = Number(w); + if (Number.isNaN(num)) { + errors.coldHouseTransferWeight = "لطفا فیلد را به درستی وارد کنید!"; + } else if (num < 0) { + errors.coldHouseTransferWeight = "مقدار نمی‌تواند منفی باشد"; + } else if (num > maxWeightForColdHouse) { + errors.coldHouseTransferWeight = + "وزن انتقالی نباید بیشتر از وزن لاشه باشد!"; + } + } + return errors; + }, + }); + + useEffect(() => { + if ( + (item?.poultryRequest?.freezing || item?.freezing) && + formik3.values.coldHouseTransferWeight + ) { + formik3.validateForm(); + } + }, [maxWeightForColdHouse]); + useEffect(() => { if (value === "weight") { if (item?.acceptedRealWeight && formik.values.realWeight) { @@ -119,11 +179,20 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { }; const isFormValid = () => { + let base = false; if (value === "weight") { - return formik.isValid && isLossInRange(); + base = formik.isValid && isLossInRange(); } else { - return formik2.isValid; + base = formik2.isValid; } + if (item?.poultryRequest?.freezing || item?.freezing) { + const hasFreezingWeight = + formik3.values.coldHouseTransferWeight !== "" && + formik3.values.coldHouseTransferWeight !== null && + String(formik3.values.coldHouseTransferWeight).trim() !== ""; + return base && (!hasFreezingWeight || formik3.isValid); + } + return base; }; const handleSubmit = () => { @@ -146,12 +215,19 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { kill_house_request_key: item?.key, }; - dispatch( - killhouseSubmitRealInventoryService({ - ...payload, - ...(item?.killer ? { input_warehouse: inputWarehouse } : {}), - }) - ).then((r) => { + const submitPayload = { + ...payload, + ...(item?.killer ? { input_warehouse: inputWarehouse } : {}), + ...((item?.poultryRequest?.freezing || item?.freezing) && + formik3.values.coldHouseTransferWeight + ? { + cold_house_key: formik3.values.coldHouseKey, + freezing_weight: parseFloat(formik3.values.coldHouseTransferWeight), + } + : {}), + }; + + dispatch(killhouseSubmitRealInventoryService(submitPayload)).then((r) => { if (r.payload.error) { openNotif({ vertical: "top", @@ -381,6 +457,69 @@ export const SlaughterSubmitRealInventory = ({ item, updateTable }) => { )} + {(item?.poultryRequest?.freezing || item?.freezing) && ( + + + + + انتخاب سردخانه + + + {formik3.touched.coldHouseKey && + formik3.errors.coldHouseKey && ( + + {formik3.errors.coldHouseKey} + + )} + + + )}