diff --git a/src/features/province/components/create-guilds/CreateGuilds.js b/src/features/province/components/create-guilds/CreateGuilds.js index b26c935..24c01b8 100644 --- a/src/features/province/components/create-guilds/CreateGuilds.js +++ b/src/features/province/components/create-guilds/CreateGuilds.js @@ -130,7 +130,6 @@ export const CreateGuilds = ({ guild, updateTable }) => { hasInquiry ); }); - console.log(guildsDataArray); dispatch(updateGuildByNationalIdNewService(guildsDataArray)).then( (result) => { if (result.payload.error) { diff --git a/src/features/province/components/province-dispenser-edit-to-guild/ProvinceDispenserEditToGuild.js b/src/features/province/components/province-dispenser-edit-to-guild/ProvinceDispenserEditToGuild.js index 84b1228..c3b4df8 100644 --- a/src/features/province/components/province-dispenser-edit-to-guild/ProvinceDispenserEditToGuild.js +++ b/src/features/province/components/province-dispenser-edit-to-guild/ProvinceDispenserEditToGuild.js @@ -39,7 +39,6 @@ export const ProvinceDispenserEditToGuild = ({ priceInfo, coldHouseKey, coldHouseItemKey, - remainWeight, fetchDashboardData, }) => { const dispatch = useDispatch(); diff --git a/src/features/province/components/province-dispenser-steward-edit-operation/ProvinceDispenserStewardEditOperation.js b/src/features/province/components/province-dispenser-steward-edit-operation/ProvinceDispenserStewardEditOperation.js index a3ce157..b12ccd0 100644 --- a/src/features/province/components/province-dispenser-steward-edit-operation/ProvinceDispenserStewardEditOperation.js +++ b/src/features/province/components/province-dispenser-steward-edit-operation/ProvinceDispenserStewardEditOperation.js @@ -1,5 +1,5 @@ import { useContext, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { AppContext } from "../../../../contexts/AppContext"; import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; @@ -25,6 +25,7 @@ import { slaughterEditAllocateStewardService, } from "../../../slaughter-house/services/slaughter-allocate-steward"; import { fetchSlaughterBroadcastAndProducts } from "../../../slaughter-house/services/handle-fetch-slaughter-products"; +import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith"; export const ProvinceDispenserStewardEditOperation = ({ item, @@ -47,6 +48,9 @@ export const ProvinceDispenserStewardEditOperation = ({ const [openNotif] = useContext(AppContext); const [value, setValue] = useState("own"); + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const handleChange = (event) => { setValue(event.target.value); @@ -156,7 +160,11 @@ export const ProvinceDispenserStewardEditOperation = ({ msg: "عملیات با موفقیت انجام شد.", severity: "success", }); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchDashboardData(); fetchApiData(1); }; diff --git a/src/features/province/components/province-dispenser-steward-sale-in-operation/ProvinceDispenserStewardSaleInOperation.js b/src/features/province/components/province-dispenser-steward-sale-in-operation/ProvinceDispenserStewardSaleInOperation.js index bbbb938..8aa6288 100644 --- a/src/features/province/components/province-dispenser-steward-sale-in-operation/ProvinceDispenserStewardSaleInOperation.js +++ b/src/features/province/components/province-dispenser-steward-sale-in-operation/ProvinceDispenserStewardSaleInOperation.js @@ -8,7 +8,7 @@ import { Popover, } from "@mui/material"; import TuneIcon from "@mui/icons-material/Tune"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Grid } from "../../../../components/grid/Grid"; import { slaughterDeleteAllocatedService } from "../../../slaughter-house/services/salughter-delete-allocated"; import { OPEN_MODAL } from "../../../../lib/redux/slices/appSlice"; @@ -16,6 +16,7 @@ import { ProvinceDispenserStewardEditOperation } from "../province-dispenser-ste import { fetchSlaughterBroadcastAndProducts } from "../../../slaughter-house/services/handle-fetch-slaughter-products"; import EditIcon from "@mui/icons-material/Edit"; import DeleteIcon from "@mui/icons-material/Delete"; + export const ProvinceDispenserStewardSaleInOperation = ({ fetchApiData, item, @@ -27,7 +28,9 @@ export const ProvinceDispenserStewardSaleInOperation = ({ }) => { const [anchorEl, setAnchorEl] = useState(null); const dispatch = useDispatch(); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const handleClick = (event) => { setAnchorEl(event.currentTarget); }; @@ -62,7 +65,11 @@ export const ProvinceDispenserStewardSaleInOperation = ({ steward_allocation_key: item.key, }) ).then(() => { - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchApiData(1); setAnchorEl(null); }); diff --git a/src/features/province/components/province-dispenser-steward-sale-out-operation/ProvinceDispenserStewardSaleOutOperation.js b/src/features/province/components/province-dispenser-steward-sale-out-operation/ProvinceDispenserStewardSaleOutOperation.js index 433d37f..2f55b07 100644 --- a/src/features/province/components/province-dispenser-steward-sale-out-operation/ProvinceDispenserStewardSaleOutOperation.js +++ b/src/features/province/components/province-dispenser-steward-sale-out-operation/ProvinceDispenserStewardSaleOutOperation.js @@ -10,7 +10,7 @@ import { import TuneIcon from "@mui/icons-material/Tune"; import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Grid } from "../../../../components/grid/Grid"; import { OPEN_MODAL } from "../../../../lib/redux/slices/appSlice"; import { ProvinceStewardEditSaleOutOperation } from "../province-steward-edit-sale-out-operation/ProvinceStewardEditSaleOutOperation"; @@ -28,7 +28,9 @@ export const ProvinceDispenserStewardSaleOutOperation = ({ }) => { const [anchorEl, setAnchorEl] = useState(null); const dispatch = useDispatch(); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const handleClick = (event) => { setAnchorEl(event.currentTarget); }; @@ -60,7 +62,11 @@ export const ProvinceDispenserStewardSaleOutOperation = ({ const handleDeleteClick = () => { handleClose(); dispatch(stewardDeleteOutSellService(item?.key)).then(() => { - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchApiData(1); setAnchorEl(null); }); diff --git a/src/features/province/components/province-steward-edit-sale-out-operation/ProvinceStewardEditSaleOutOperation.js b/src/features/province/components/province-steward-edit-sale-out-operation/ProvinceStewardEditSaleOutOperation.js index 10d15a0..38dc1f5 100644 --- a/src/features/province/components/province-steward-edit-sale-out-operation/ProvinceStewardEditSaleOutOperation.js +++ b/src/features/province/components/province-steward-edit-sale-out-operation/ProvinceStewardEditSaleOutOperation.js @@ -1,5 +1,5 @@ import { useContext } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { AppContext } from "../../../../contexts/AppContext"; import { Yup } from "../../../../lib/yup/yup"; import { useFormik } from "formik"; @@ -20,6 +20,9 @@ export const ProvinceStewardEditSaleOutOperation = ({ }) => { const dispatch = useDispatch(); const [openNotif] = useContext(AppContext); + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const validationSchema = Yup.object({ weight: Yup.number().min(1, "یک مقدار مثبت وارد کنید!"), @@ -45,7 +48,11 @@ export const ProvinceStewardEditSaleOutOperation = ({ msg: "وزن با موفقیت ویرایش شد.", severity: "success", }); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchApiData(1); fetchDashboardData(); }; diff --git a/src/features/slaughter-house/components/slaughter-free-bars-alives-operations/SlaughterFreeBarsAlivesOperations.js b/src/features/slaughter-house/components/slaughter-free-bars-alives-operations/SlaughterFreeBarsAlivesOperations.js index 9eea470..06a4901 100644 --- a/src/features/slaughter-house/components/slaughter-free-bars-alives-operations/SlaughterFreeBarsAlivesOperations.js +++ b/src/features/slaughter-house/components/slaughter-free-bars-alives-operations/SlaughterFreeBarsAlivesOperations.js @@ -1,6 +1,6 @@ import { Button, IconButton, Popover } from "@mui/material"; import { useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Grid } from "../../../../components/grid/Grid"; import { DRAWER, OPEN_MODAL } from "../../../../lib/redux/slices/appSlice"; import { slaughterDeleteInventoryFreeBarService } from "../../services/slaughter-delete-inventory-free-bar"; @@ -16,7 +16,9 @@ export const SlaughterFreeBarsAlivesOperations = ({ type, }) => { const dispatch = useDispatch(); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const [anchorEl, setAnchorEl] = useState(null); const handleClick = (event) => { @@ -129,7 +131,11 @@ export const SlaughterFreeBarsAlivesOperations = ({ slaughterDeleteInventoryFreeBarService(item.key) ).then(() => { updateTable(); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); }); }} > diff --git a/src/features/slaughter-house/components/slaughter-free-bars-operations/SlaughterFreeBarsOperations.js b/src/features/slaughter-house/components/slaughter-free-bars-operations/SlaughterFreeBarsOperations.js index 75b4f41..ae508c8 100644 --- a/src/features/slaughter-house/components/slaughter-free-bars-operations/SlaughterFreeBarsOperations.js +++ b/src/features/slaughter-house/components/slaughter-free-bars-operations/SlaughterFreeBarsOperations.js @@ -8,7 +8,7 @@ import { ListItemIcon, } from "@mui/material"; import { useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { DRAWER, OPEN_MODAL } from "../../../../lib/redux/slices/appSlice"; import { slaughterDeleteInventoryFreeBarService } from "../../services/slaughter-delete-inventory-free-bar"; import { SlaughterSubmitFreeBar } from "../slaughter-submit-free-bar/SlaughterSubmitFreeBar"; @@ -26,7 +26,9 @@ export const SlaughterFreeBarsOperations = ({ type, }) => { const dispatch = useDispatch(); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const [anchorEl, setAnchorEl] = useState(null); const handleClick = (event) => { @@ -158,7 +160,11 @@ export const SlaughterFreeBarsOperations = ({ slaughterDeleteInventoryFreeBarService(item.key) ).then(() => { updateTable(); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); }); }} > diff --git a/src/features/slaughter-house/components/slaughter-house-cold-house-bars-edit/SlaughterHouseColdHouseBarsEdit.js b/src/features/slaughter-house/components/slaughter-house-cold-house-bars-edit/SlaughterHouseColdHouseBarsEdit.js index eb0599c..2f58bfc 100644 --- a/src/features/slaughter-house/components/slaughter-house-cold-house-bars-edit/SlaughterHouseColdHouseBarsEdit.js +++ b/src/features/slaughter-house/components/slaughter-house-cold-house-bars-edit/SlaughterHouseColdHouseBarsEdit.js @@ -1,7 +1,7 @@ import React, { useContext, useEffect } from "react"; import { Grid } from "../../../../components/grid/Grid"; import { Button, InputAdornment } from "@mui/material"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { NumberInput } from "../../../../components/number-format-custom/NumberFormatCustom"; import { useFormik } from "formik"; import { Yup } from "../../../../lib/yup/yup"; @@ -24,6 +24,9 @@ export const SlaughterHouseColdHouseBarsEdit = ({ }) => { const dispatch = useDispatch(); const [openNotif] = useContext(AppContext); + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const validationSchema = Yup.object({ weight: Yup.number() @@ -50,7 +53,11 @@ export const SlaughterHouseColdHouseBarsEdit = ({ msg: "عملیات با موفقیت انجام شد.", severity: "success", }); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchApiData(); updateTable(); fetchData(); 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 f494be6..a5319d5 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 @@ -25,7 +25,7 @@ import { fetchSlaughterBroadcastAndProducts } from "../../services/handle-fetch- export const SlaughterInventoryFreeBuyBarsAlives = ({ title, barState, - fetchDashboardData, + handleUpdate, withDate, selectedDate1, selectedDate2, @@ -87,7 +87,7 @@ export const SlaughterInventoryFreeBuyBarsAlives = ({ const updateTable = () => { fetchApiData(page !== 0 ? page : 1); - fetchDashboardData(); + handleUpdate(); dispatch( fetchSlaughterBroadcastAndProducts({ role_key: checkPathStartsWith("slaughter") diff --git a/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars/SlaughterInventoryFreeBuyBars.js b/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars/SlaughterInventoryFreeBuyBars.js index bc9e8c9..f296568 100644 --- a/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars/SlaughterInventoryFreeBuyBars.js +++ b/src/features/slaughter-house/components/slaughter-inventory-free-buy-bars/SlaughterInventoryFreeBuyBars.js @@ -411,7 +411,7 @@ export const SlaughterInventoryFreeBuyBars = () => { { { const [anchorEl, setAnchorEl] = useState(null); - + const selectedSubUser = useSelector( + (state) => state?.userSlice?.selectedSubUser + ); const handleClick = (event) => { setAnchorEl(event.currentTarget); }; @@ -150,7 +152,11 @@ export const SlaughterManageInventoryAllocationOperations = ({ }) ).then(() => { dispatch(CLOSE_MODAL()); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); fetchApiData(1); }); }} diff --git a/src/features/slaughter-house/components/slaughter-out-province-sales-operations/SlaughterOutProvinceSalesOperations.js b/src/features/slaughter-house/components/slaughter-out-province-sales-operations/SlaughterOutProvinceSalesOperations.js index 9534cfd..f378c3a 100644 --- a/src/features/slaughter-house/components/slaughter-out-province-sales-operations/SlaughterOutProvinceSalesOperations.js +++ b/src/features/slaughter-house/components/slaughter-out-province-sales-operations/SlaughterOutProvinceSalesOperations.js @@ -10,7 +10,7 @@ import { Tooltip, Typography, } from "@mui/material"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { AppContext } from "../../../../contexts/AppContext"; import { DRAWER } from "../../../../lib/redux/slices/appSlice"; import { slaughterDeleteOutOfProvinceSell } from "../../services/slaughter-delete-out-province-sell"; @@ -31,7 +31,9 @@ export const SlaughterOutProvinceSalesOperations = ({ const dispatch = useDispatch(); const [openNotif] = useContext(AppContext); const [anchorEl, setAnchorEl] = useState(null); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const openPopover = (event) => { setAnchorEl(event.currentTarget); }; @@ -70,7 +72,11 @@ export const SlaughterOutProvinceSalesOperations = ({ }); } else { updateTable(); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); openNotif({ vertical: "top", horizontal: "center", diff --git a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js index c9c5c02..75ccec6 100644 --- a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js +++ b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js @@ -10,6 +10,10 @@ import { FormControlLabel, TextField, Typography, + FormControl, + InputLabel, + Select, + MenuItem, } from "@mui/material"; import { useFormik } from "formik"; import { Yup } from "../../../../lib/yup/yup"; @@ -19,7 +23,7 @@ import { slaughterSubmitBuyerDataService, } from "../../services/slaughter-house-submit-buyer"; import { AppContext } from "../../../../contexts/AppContext"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { DRAWER } from "../../../../lib/redux/slices/appSlice"; import { slaughterGetCitiesService, @@ -28,6 +32,10 @@ import { import { provinceGetNationalDocumentsService } from "../../../province/services/province-get-national-documents"; import { LabelField } from "../../../../components/label-field/LabelField"; import { extractProvinceFromAddress } from "../../../../utils/address"; +import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; +import { useLocation } from "react-router-dom"; +import { inspectorGetKillHousesService } from "../../../inspector/services/inspector-get-kill-houses"; +import { slaughterGetStewardsForAllocateService } from "../../services/slaughter-get-guilds-for-allocate"; // userType enums = steward | steward_true | steward_legal | _true | _legal @@ -40,6 +48,12 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ userType, }) => { const IS_STEWARD = userType === "steward"; + const IS_ADMINX = getRoleFromUrl() === "AdminX"; + const { pathname } = useLocation(); + const IS_OUT_PROVINCE = pathname.includes("out-province"); + const { inspectorGetKillHouses } = useSelector( + (state) => state.inspectorSlice + ); const [openNotif] = useContext(AppContext); const [userData, setUserData] = useState(null); const [notFound, setNotFound] = useState(false); @@ -48,16 +62,20 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ const dispatch = useDispatch(); const [provinceData, setProvinceData] = useState([]); const [cityData, setCityData] = useState([]); + const [killhouses, setKillhouses] = useState([]); + const [stewardsData, setStewardsData] = useState([]); const formik = useFormik({ initialValues: { mobile: "", firstName: "", lastName: "", - unitName: "", + unit_name: "", province: "", city: "", nationalId: "", + role_key: "", + type: "", }, validationSchema: Yup.object({ mobile: Yup.string() @@ -71,7 +89,7 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ lastName: Yup.string() .required("این فیلد اجباری است!") .typeError("لطفا فیلد را به درستی وارد کنید!"), - unitName: Yup.string() + unit_name: Yup.string() .required("این فیلد اجباری است!") .typeError("لطفا فیلد را به درستی وارد کنید!"), province: Yup.string() @@ -86,10 +104,42 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ : Yup.string() .required("این فیلد اجباری است!") .matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"), + role_key: + IS_ADMINX && IS_OUT_PROVINCE + ? Yup.string().required("این فیلد اجباری است!") + : Yup.string(), + type: + IS_ADMINX && IS_OUT_PROVINCE + ? Yup.string().oneOf(["Steward", "KillHouse"]).required() + : Yup.string().nullable(), }), validateOnMount: true, }); + useEffect(() => { + const d = inspectorGetKillHouses?.map((item) => { + return { name: item.name, key: item.key, killer: item.killer }; + }); + setKillhouses(d); + }, [inspectorGetKillHouses]); + + useEffect(() => { + if (IS_OUT_PROVINCE && IS_ADMINX) { + if (formik.values.type === "KillHouse") { + dispatch(inspectorGetKillHousesService()); + } else { + dispatch( + slaughterGetStewardsForAllocateService({ + free: true, + }) + ).then((r) => { + setStewardsData(r.payload.data || []); + }); + } + formik.validateForm(); + } + }, [formik.values.type]); + const formik2 = useFormik({ initialValues: { personType: defaultPersonType || "real", // real | legal @@ -153,7 +203,12 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ province: userData.province || "", city: userData.city || "", nationalId: userData.nationalId || "", - unitName: data?.unitName || "", + unit_name: userData?.unitName || "", + ...(IS_ADMINX && + IS_OUT_PROVINCE && { + type: formik.values?.type, + role_key: formik.values?.role_key, + }), }; formik.setValues(formData); @@ -163,8 +218,10 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ "mobile", "firstName", "lastName", - "unitName", + "unit_name", "city", + "type", + "role_key", ]; const locks = fieldKeys.reduce((acc, key) => { const value = userData[key]; @@ -189,7 +246,12 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ province: data.province || "", city: data.city || "", nationalId: (IS_STEWARD ? defaultNationalCode : data.nationalId) || "", - unitName: data?.unitName || "", + unit_name: data?.unitName || "", + ...(IS_ADMINX && + IS_OUT_PROVINCE && { + type: formik.values?.type, + role_key: formik.values?.role_key, + }), }; formik.setValues(formData); @@ -261,10 +323,15 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ mobile: "", firstName: d.name || "", lastName: d.name || "", - unitName: d.name || "", + unitName: (IS_STEWARD ? d.unitName : d.unitName) || "", province: d.state || extractedProvince || "", city: "", // User will select city manually nationalId: d.nationalCode || nationalCode, + ...(IS_ADMINX && + IS_OUT_PROVINCE && { + type: formik.values?.type, + role_key: formik.values?.role_key, + }), }; setUserData(aggregatedUserData); formik2.setFieldValue( @@ -396,6 +463,11 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ layerTwo.nationalcode || selectedGuild?.nationalId || nationalCode, + ...(IS_ADMINX && + IS_OUT_PROVINCE && { + type: formik.values?.type, + role_key: formik.values?.role_key, + }), }; setUserData(aggregatedUserData); @@ -414,6 +486,8 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ } }; + console.log(formik.errors); + return ( + {IS_OUT_PROVINCE && IS_ADMINX ? ( + <> + + { + const value = e.target.value; + formik.setFieldValue("type", value); + }} + > + } + label="مباشر" + /> + } + label="کشتارگاه" + /> + + + {formik.values.type === "Steward" ? ( + { + return { + key: item?.key, + label: `${item?.name || ""} - ${ + item?.user?.fullname || "" + } (${item?.user?.mobile || ""})`, + }; + })} + onChange={(event, value) => { + formik.setFieldValue("role_key", value?.key || ""); + }} + value={ + formik.values.role_key + ? { + key: formik.values.role_key, + label: + stewardsData.find( + (item) => item.key === formik.values.role_key + )?.name || "", + } + : null + } + isOptionEqualToValue={(option, value) => + option.key === value.key + } + label="انتخاب مباشر" + renderInput={(params) => ( + + )} + /> + ) : formik.values.type === "KillHouse" ? ( + + انتخاب کشتارگاه یا کشتارکن + + {formik.errors.role_key && formik.touched.role_key && ( +
{formik.errors.role_key}
+ )} +
+ ) : null} + + ) : null} { updateTable(); diff --git a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-sell/SlaughterSellCarcassOutProvinceSell.js b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-sell/SlaughterSellCarcassOutProvinceSell.js index 6db53b5..13cfee7 100644 --- a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-sell/SlaughterSellCarcassOutProvinceSell.js +++ b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-sell/SlaughterSellCarcassOutProvinceSell.js @@ -22,6 +22,7 @@ import { formatJustDate, formatTime } from "../../../../utils/formatTime"; import { SlaughterOutProvinceRegistrationCodeInput } from "../slaughter-out-province-registration-code-input/SlaughterOutProvinceRegistrationCodeInput"; import { SlaughterOutProvinceSalesOperations } from "../slaughter-out-province-sales-operations/SlaughterOutProvinceSalesOperations"; import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith"; +import { fetchSlaughterBroadcastAndProducts } from "../../services/handle-fetch-slaughter-products"; export const SlaughterSellCarcassOutProvinceSell = () => { const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] = @@ -77,6 +78,13 @@ export const SlaughterSellCarcassOutProvinceSell = () => { const updateTable = () => { fetchApiData(page !== 0 ? page : 1); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: checkPathStartsWith("slaughter") + ? selectedSubUser?.key || "" + : "", + }) + ); }; useEffect(() => { diff --git a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-submit-sell/SlaughterSellCarcassOutProvinceSellSubmitSell.js b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-submit-sell/SlaughterSellCarcassOutProvinceSellSubmitSell.js index 249aec7..013882a 100644 --- a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-submit-sell/SlaughterSellCarcassOutProvinceSellSubmitSell.js +++ b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-submit-sell/SlaughterSellCarcassOutProvinceSellSubmitSell.js @@ -346,7 +346,11 @@ export const SlaughterSellCarcassOutProvinceSellSubmitSell = ({ } else { updateTable(); } - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); dispatch( DRAWER({ right: false, bottom: false, content: null }) ); diff --git a/src/features/slaughter-house/components/slaughter-submit-out-province-sell/SlaughterSubmitOutProvinceSell.js b/src/features/slaughter-house/components/slaughter-submit-out-province-sell/SlaughterSubmitOutProvinceSell.js index 35690a3..6a08a8c 100644 --- a/src/features/slaughter-house/components/slaughter-submit-out-province-sell/SlaughterSubmitOutProvinceSell.js +++ b/src/features/slaughter-house/components/slaughter-submit-out-province-sell/SlaughterSubmitOutProvinceSell.js @@ -4,7 +4,7 @@ import { Formik, Form, Field } from "formik"; import * as Yup from "yup"; import { Grid } from "../../../../components/grid/Grid"; import { AppContext } from "../../../../contexts/AppContext"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { guildSubmitOutOfProvinceService, slaughterSubmitOutOfProvinceService, @@ -36,7 +36,9 @@ export const SlaughterSubmitOutProvinceSell = ({ }) => { const dispatch = useDispatch(); const [openNotif] = useContext(AppContext); - + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); const initialValues = { clearance_code: item?.clearanceCode || "", number_of_carcasses: item?.numberOfCarcasses || "", @@ -100,7 +102,11 @@ export const SlaughterSubmitOutProvinceSell = ({ }) ); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); dispatch(DRAWER({ right: false, bottom: false, content: null })); openNotif({ vertical: "top", diff --git a/src/features/slaughter-house/components/slaughter-submit-real-inventory-free-bar/SLaughterSubmitRealInverntoryFreeBar.js b/src/features/slaughter-house/components/slaughter-submit-real-inventory-free-bar/SLaughterSubmitRealInverntoryFreeBar.js index eeda231..11f272e 100644 --- a/src/features/slaughter-house/components/slaughter-submit-real-inventory-free-bar/SLaughterSubmitRealInverntoryFreeBar.js +++ b/src/features/slaughter-house/components/slaughter-submit-real-inventory-free-bar/SLaughterSubmitRealInverntoryFreeBar.js @@ -9,7 +9,7 @@ import { OPEN_MODAL, } from "../../../../lib/redux/slices/appSlice"; import { SPACING } from "../../../../data/spacing"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { AppContext } from "../../../../contexts/AppContext"; import { slaughterEditFreeSaleService } from "../../services/slaughter-edit-free-sale"; @@ -17,9 +17,12 @@ import { fetchSlaughterBroadcastAndProducts } from "../../services/handle-fetch- export const SlaughterSubmitRealInventoryFreeBar = ({ item, updateTable }) => { const [loss, setLoss] = useState("0"); - const [openNotif] = useContext(AppContext); const dispatch = useDispatch(); + const selectedSubUser = useSelector( + (state) => state.userSlice.selectedSubUser + ); + const formik = useFormik({ initialValues: { realNumber: item.numberOfCarcasses ? item.numberOfCarcasses : "", @@ -36,7 +39,7 @@ export const SlaughterSubmitRealInventoryFreeBar = ({ item, updateTable }) => { }); useEffect(() => { - let difference = item?.liveWeight - formik.values.realWeight; + const difference = item?.liveWeight - formik.values.realWeight; if (difference < item?.liveWeight) { setLoss(((difference / item?.liveWeight) * 100).toPrecision(4)); } else { @@ -182,7 +185,11 @@ export const SlaughterSubmitRealInventoryFreeBar = ({ item, updateTable }) => { dispatch(CLOSE_MODAL()); updateTable(1); handleAlert(); - dispatch(fetchSlaughterBroadcastAndProducts()); + dispatch( + fetchSlaughterBroadcastAndProducts({ + role_key: selectedSubUser?.key || "", + }) + ); } }); }} diff --git a/src/features/steward/components/steward-show-allocations/StewardShowAllocations.js b/src/features/steward/components/steward-show-allocations/StewardShowAllocations.js index 31f83e6..22b6f51 100644 --- a/src/features/steward/components/steward-show-allocations/StewardShowAllocations.js +++ b/src/features/steward/components/steward-show-allocations/StewardShowAllocations.js @@ -88,7 +88,9 @@ export const StewardShowAllocations = forwardRef( }; const updateTable = () => { + console.log("--------------------------------------"); fetchApiData(1); + handleUpdate(); }; useImperativeHandle(ref, () => ({