before killhouses options
This commit is contained in:
@@ -12,7 +12,7 @@ import { useDispatch } from "react-redux";
|
|||||||
import { RiSearchLine } from "react-icons/ri";
|
import { RiSearchLine } from "react-icons/ri";
|
||||||
import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers";
|
import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers";
|
||||||
import { ProvinceTrueGuildsOutProvinceOperations } from "../province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations";
|
import { ProvinceTrueGuildsOutProvinceOperations } from "../province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations";
|
||||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||||
|
|
||||||
export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||||
const IS_STEWARD = userType === "steward";
|
const IS_STEWARD = userType === "steward";
|
||||||
@@ -120,13 +120,12 @@ export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
|||||||
bottom: window.innerWidth <= 600,
|
bottom: window.innerWidth <= 600,
|
||||||
size: 340,
|
size: 340,
|
||||||
content: (
|
content: (
|
||||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
<StewardAddBuyer
|
||||||
updateTable={() => {
|
updateTable={() => {
|
||||||
setPage(1);
|
setPage(1);
|
||||||
fetchApiData(1);
|
fetchApiData(1);
|
||||||
}}
|
}}
|
||||||
defaultPersonType={"legal"}
|
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||||
userType={userType}
|
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
title: `افزودن ${IS_STEWARD ? "مباشر" : "صنف"} خارج از استان`,
|
title: `افزودن ${IS_STEWARD ? "مباشر" : "صنف"} خارج از استان`,
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import { useDispatch } from "react-redux";
|
|||||||
import { RiSearchLine } from "react-icons/ri";
|
import { RiSearchLine } from "react-icons/ri";
|
||||||
import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers";
|
import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers";
|
||||||
import { ProvinceTrueGuildsOutProvinceOperations } from "./ProvinceTrueGuildsOutProvinceOperations";
|
import { ProvinceTrueGuildsOutProvinceOperations } from "./ProvinceTrueGuildsOutProvinceOperations";
|
||||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
|
||||||
import { SPACING } from "../../../../data/spacing";
|
import { SPACING } from "../../../../data/spacing";
|
||||||
|
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||||
|
|
||||||
export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||||
const IS_STEWARD = userType === "steward";
|
const IS_STEWARD = userType === "steward";
|
||||||
@@ -164,17 +164,17 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
const d = data?.map((item, i) => {
|
const d = data?.map((item, i) => {
|
||||||
const khList = killHouseList(item);
|
const khList = killHouseList(item);
|
||||||
const stList = stewardList(item);
|
const stList = stewardList(item);
|
||||||
const firstKillHouse = khList?.[0];
|
// const firstKillHouse = khList?.[0];
|
||||||
const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
|
// const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
|
||||||
const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
|
// const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
|
||||||
const killHouseOperator =
|
// const killHouseOperator =
|
||||||
firstKillHouse?.fullname ??
|
// firstKillHouse?.fullname ??
|
||||||
item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
// item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
||||||
"";
|
// "";
|
||||||
const killHouseDisplay =
|
// const killHouseDisplay =
|
||||||
killHouseOperator && killHouseOperator !== "-"
|
// killHouseOperator && killHouseOperator !== "-"
|
||||||
? `${killHouseName} (${killHouseOperator})`
|
// ? `${killHouseName} (${killHouseOperator})`
|
||||||
: killHouseName;
|
// : killHouseName;
|
||||||
|
|
||||||
const totalRequests = khList.reduce(
|
const totalRequests = khList.reduce(
|
||||||
(acc, entry) => {
|
(acc, entry) => {
|
||||||
@@ -257,8 +257,9 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
return [
|
return [
|
||||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||||
`${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
|
`${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
|
||||||
|
item?.nationalId ?? "-",
|
||||||
item?.unit_name ?? item?.unitName ?? "-",
|
item?.unit_name ?? item?.unitName ?? "-",
|
||||||
killHouseDisplay,
|
// killHouseDisplay,
|
||||||
item?.province ?? "-",
|
item?.province ?? "-",
|
||||||
item?.city ?? "-",
|
item?.city ?? "-",
|
||||||
listButtons,
|
listButtons,
|
||||||
@@ -310,13 +311,13 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
bottom: window.innerWidth <= 600,
|
bottom: window.innerWidth <= 600,
|
||||||
size: 340,
|
size: 340,
|
||||||
content: (
|
content: (
|
||||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
<StewardAddBuyer
|
||||||
updateTable={() => {
|
updateTable={() => {
|
||||||
setPage(1);
|
setPage(1);
|
||||||
fetchApiData(1);
|
fetchApiData(1);
|
||||||
}}
|
}}
|
||||||
defaultPersonType={"real"}
|
isRealPerson
|
||||||
userType={userType}
|
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
title: `افزودن ${
|
title: `افزودن ${
|
||||||
@@ -353,8 +354,8 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
columns={[
|
columns={[
|
||||||
"ردیف",
|
"ردیف",
|
||||||
"مشخصات خریدار",
|
"مشخصات خریدار",
|
||||||
|
"کد ملی",
|
||||||
"نام واحد",
|
"نام واحد",
|
||||||
"کشتارگاه",
|
|
||||||
"استان",
|
"استان",
|
||||||
"شهر",
|
"شهر",
|
||||||
"کشتارگاه ها / مباشرین",
|
"کشتارگاه ها / مباشرین",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
import { deleteOutProvinceTrueGuilds } from "../../services/delete-out-province-true-guilds";
|
import { deleteOutProvinceTrueGuilds } from "../../services/delete-out-province-true-guilds";
|
||||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
import { StewardAddBuyer } from "../../../steward/components/steward-add-buyer/StewardAddBuyer";
|
||||||
|
|
||||||
export const ProvinceTrueGuildsOutProvinceOperations = ({
|
export const ProvinceTrueGuildsOutProvinceOperations = ({
|
||||||
item,
|
item,
|
||||||
@@ -90,21 +90,12 @@ export const ProvinceTrueGuildsOutProvinceOperations = ({
|
|||||||
right: !(window.innerWidth <= 600),
|
right: !(window.innerWidth <= 600),
|
||||||
bottom: window.innerWidth <= 600,
|
bottom: window.innerWidth <= 600,
|
||||||
content: (
|
content: (
|
||||||
<SlaughterSellCarcassOutProvinceAddBuyer
|
<StewardAddBuyer
|
||||||
updateTable={updateTable}
|
updateTable={updateTable}
|
||||||
isEdit
|
isEdit
|
||||||
data={item}
|
data={item}
|
||||||
defaultPersonType={
|
isRealPerson
|
||||||
item?.buyer?.parentLegalPersonNationalCode
|
buyerType={IS_STEWARD ? "Steward" : "Guilds"}
|
||||||
? "legal"
|
|
||||||
: "real"
|
|
||||||
}
|
|
||||||
defaultNationalCode={
|
|
||||||
IS_STEWARD
|
|
||||||
? item?.buyer?.nationalId
|
|
||||||
: item?.buyer?.nationalCode
|
|
||||||
}
|
|
||||||
userType={userType}
|
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||||
import { Grid } from "../../../../components/grid/Grid";
|
import { Grid } from "../../../../components/grid/Grid";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { SlaughterSellCarcassOutProvinceAddBuyer } from "../slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer";
|
|
||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
import { RiSearchLine } from "react-icons/ri";
|
import { RiSearchLine } from "react-icons/ri";
|
||||||
import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith";
|
import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith";
|
||||||
|
|||||||
@@ -4,29 +4,15 @@ import { useDispatch } from "react-redux";
|
|||||||
import { useFormik } from "formik";
|
import { useFormik } from "formik";
|
||||||
import { Yup } from "../../../../lib/yup/yup";
|
import { Yup } from "../../../../lib/yup/yup";
|
||||||
import { Grid } from "../../../../components/grid/Grid";
|
import { Grid } from "../../../../components/grid/Grid";
|
||||||
import {
|
import { Autocomplete, IconButton, TextField, Typography } from "@mui/material";
|
||||||
Autocomplete,
|
|
||||||
FormControl,
|
|
||||||
FormControlLabel,
|
|
||||||
IconButton,
|
|
||||||
InputLabel,
|
|
||||||
MenuItem,
|
|
||||||
Radio,
|
|
||||||
RadioGroup,
|
|
||||||
Select,
|
|
||||||
TextField,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { SPACING } from "../../../../data/spacing";
|
import { SPACING } from "../../../../data/spacing";
|
||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import { extractProvinceFromAddress } from "../../../../utils/address";
|
import { extractProvinceFromAddress } from "../../../../utils/address";
|
||||||
import { provinceGetNationalDocumentsService } from "../../../province/services/province-get-national-documents";
|
import { getCarcassesBuyerInfoService } from "../../../steward/services/get-carcasses-buyer-info";
|
||||||
import {
|
import {
|
||||||
slaughterEditBuyerDataService,
|
slaughterEditBuyerDataService,
|
||||||
slaughterSubmitBuyerDataService,
|
slaughterSubmitBuyerDataService,
|
||||||
} from "../../../slaughter-house/services/slaughter-house-submit-buyer";
|
} from "../../../slaughter-house/services/slaughter-house-submit-buyer";
|
||||||
import { LabelField } from "../../../../components/label-field/LabelField";
|
|
||||||
|
|
||||||
export const validationSchemaForAdminAddBuyer = (isEdit, isRealPerson) =>
|
export const validationSchemaForAdminAddBuyer = (isEdit, isRealPerson) =>
|
||||||
Yup.object({
|
Yup.object({
|
||||||
mobile: Yup.string()
|
mobile: Yup.string()
|
||||||
@@ -55,9 +41,12 @@ export const validationSchemaForAdminAddBuyer = (isEdit, isRealPerson) =>
|
|||||||
: Yup.string()
|
: Yup.string()
|
||||||
.required("این فیلد اجباری است!")
|
.required("این فیلد اجباری است!")
|
||||||
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
||||||
role_key: Yup.string().required("این فیلد اجباری است!"),
|
}).test(
|
||||||
type: Yup.string().oneOf(["Steward", "KillHouse"]).required(),
|
"at-least-one-key",
|
||||||
});
|
"حداقل یک کشتارگاه یا مباشر باید انتخاب شود",
|
||||||
|
(value) =>
|
||||||
|
value?.steward_keys?.length > 0 || value?.kill_house_keys?.length > 0
|
||||||
|
);
|
||||||
|
|
||||||
export const handleSubmitForAdminAddBuyer = (
|
export const handleSubmitForAdminAddBuyer = (
|
||||||
formik,
|
formik,
|
||||||
@@ -81,8 +70,8 @@ export const handleSubmitForAdminAddBuyer = (
|
|||||||
province: formik.values.province,
|
province: formik.values.province,
|
||||||
national_id: formik.values.nationalId,
|
national_id: formik.values.nationalId,
|
||||||
unit_name: formik.values.unit_name,
|
unit_name: formik.values.unit_name,
|
||||||
type: formik.values.type,
|
steward_keys: formik.values.steward_keys || [],
|
||||||
role_key: formik.values.role_key,
|
kill_house_keys: formik.values.kill_house_keys || [],
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch(slaughterEditBuyerDataService(submitData)).then((r) => {
|
dispatch(slaughterEditBuyerDataService(submitData)).then((r) => {
|
||||||
@@ -115,8 +104,8 @@ export const handleSubmitForAdminAddBuyer = (
|
|||||||
province: formik.values.province,
|
province: formik.values.province,
|
||||||
unit_name: formik.values.unit_name,
|
unit_name: formik.values.unit_name,
|
||||||
national_id: !isRealPerson ? null : formik.values.nationalId,
|
national_id: !isRealPerson ? null : formik.values.nationalId,
|
||||||
type: formik.values.type,
|
steward_keys: formik.values.steward_keys || [],
|
||||||
role_key: formik.values.role_key,
|
kill_house_keys: formik.values.kill_house_keys || [],
|
||||||
...(!isRealPerson && {
|
...(!isRealPerson && {
|
||||||
isRealPerson: false,
|
isRealPerson: false,
|
||||||
info_value: formik.values.nationalId,
|
info_value: formik.values.nationalId,
|
||||||
@@ -150,20 +139,41 @@ export const handleSubmitForAdminAddBuyer = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractStewardKeysFromInfo = (steward_info) => {
|
||||||
|
if (!Array.isArray(steward_info)) return [];
|
||||||
|
return steward_info
|
||||||
|
.map((item) => item?.Steward?.key ?? item?.key)
|
||||||
|
.filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractKillHouseKeysFromInfo = (killHouseInfo) => {
|
||||||
|
const arr = killHouseInfo ?? [];
|
||||||
|
if (!Array.isArray(arr)) return [];
|
||||||
|
return arr.map((item) => item?.killHouse?.key).filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
export const handleSetFormDataFromTableDataForAdminAddBuyer = (
|
export const handleSetFormDataFromTableDataForAdminAddBuyer = (
|
||||||
tableData,
|
item,
|
||||||
formik
|
formik
|
||||||
) => {
|
) => {
|
||||||
|
const steward_keys =
|
||||||
|
item?.steward_keys ??
|
||||||
|
extractStewardKeysFromInfo(item?.stewardInfo) ??
|
||||||
|
formik.values?.steward_keys ??
|
||||||
|
[];
|
||||||
|
const kill_house_keys =
|
||||||
|
extractKillHouseKeysFromInfo(item?.killHouseInfo) ?? [];
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
mobile: tableData.mobile || "",
|
mobile: item.mobile || "",
|
||||||
firstName: tableData.firstName || "",
|
firstName: item.firstName || "",
|
||||||
lastName: tableData.lastName || "",
|
lastName: item.lastName || "",
|
||||||
province: tableData.province || "",
|
province: item.province || "",
|
||||||
city: tableData.city || "",
|
city: item.city || "",
|
||||||
nationalId: tableData.nationalId || "",
|
nationalId: item.nationalId || "",
|
||||||
unit_name: tableData?.unitName || "",
|
unit_name: item?.unitName || "",
|
||||||
type: formik.values?.type,
|
steward_keys,
|
||||||
role_key: formik.values?.role_key,
|
kill_house_keys,
|
||||||
};
|
};
|
||||||
|
|
||||||
formik.setValues(formData);
|
formik.setValues(formData);
|
||||||
@@ -186,8 +196,8 @@ export const handleSetFormDataFromUserDataForAdminAddBuyer = (
|
|||||||
city: userData.city || "",
|
city: userData.city || "",
|
||||||
nationalId: userData.nationalId || "",
|
nationalId: userData.nationalId || "",
|
||||||
unit_name: userData?.unitName || "",
|
unit_name: userData?.unitName || "",
|
||||||
type: formik.values?.type,
|
steward_keys: formik.values?.steward_keys ?? [],
|
||||||
role_key: formik.values?.role_key,
|
kill_house_keys: formik.values?.kill_house_keys ?? [],
|
||||||
};
|
};
|
||||||
|
|
||||||
formik.setValues(formData);
|
formik.setValues(formData);
|
||||||
@@ -248,186 +258,76 @@ export const InquiryForAdminAddBuyer = ({
|
|||||||
|
|
||||||
const nationalCode = formik2.values.nationalCode;
|
const nationalCode = formik2.values.nationalCode;
|
||||||
const personType = formik2.values.personType;
|
const personType = formik2.values.personType;
|
||||||
|
const type = personType === "legal" ? "unit" : "person";
|
||||||
|
|
||||||
setInquiryInProgress(true);
|
setInquiryInProgress(true);
|
||||||
setNotFound(false);
|
setNotFound(false);
|
||||||
setUserData(null);
|
setUserData(null);
|
||||||
|
|
||||||
let personData = null;
|
|
||||||
let selectedGuild = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (personType === "legal") {
|
const response = await dispatch(
|
||||||
const url = `https://pay.rasadyar.com/national-documents?info=${encodeURIComponent(
|
getCarcassesBuyerInfoService({ info: nationalCode, type })
|
||||||
nationalCode
|
);
|
||||||
)}&type=unit`;
|
|
||||||
const res = await fetch(url);
|
|
||||||
const json = await res.json();
|
|
||||||
|
|
||||||
if (json?.status && json?.data) {
|
if (response.payload?.error) {
|
||||||
const d = json.data;
|
openNotif({
|
||||||
const extractedProvince = extractProvinceFromAddress(
|
vertical: "top",
|
||||||
d.address || "",
|
horizontal: "center",
|
||||||
provinceData
|
msg: response.payload.error,
|
||||||
);
|
severity: "error",
|
||||||
const aggregatedUserData = {
|
});
|
||||||
mobile: d.mobile,
|
|
||||||
firstName: d.name || "",
|
|
||||||
lastName: d.name || "",
|
|
||||||
unitName: d.unitName || "",
|
|
||||||
province: d.state || extractedProvince || "",
|
|
||||||
city: d.city || "",
|
|
||||||
nationalId: d.nationalCode || nationalCode,
|
|
||||||
type: formik.values?.type,
|
|
||||||
role_key: formik.values?.role_key,
|
|
||||||
};
|
|
||||||
handleSetFormDataFromUserDataForAdminAddBuyer(
|
|
||||||
aggregatedUserData,
|
|
||||||
formik
|
|
||||||
);
|
|
||||||
formik2.setFieldValue(
|
|
||||||
"nationalCode",
|
|
||||||
aggregatedUserData.nationalId || nationalCode
|
|
||||||
);
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات حقوقی با موفقیت دریافت شد.",
|
|
||||||
severity: "success",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setNotFound(true);
|
|
||||||
formik.setFieldValue("nationalId", nationalCode);
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
|
||||||
severity: "warning",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const personResponse = await dispatch(
|
const json = response.payload?.data;
|
||||||
provinceGetNationalDocumentsService({
|
if (json?.status && json?.data) {
|
||||||
info: nationalCode,
|
const d = json.data;
|
||||||
type: "person",
|
const extractedProvince = extractProvinceFromAddress(
|
||||||
})
|
d.address || "",
|
||||||
);
|
provinceData
|
||||||
|
);
|
||||||
if (personResponse.payload?.error) {
|
const aggregatedUserData = {
|
||||||
|
mobile: d.mobile || d.mobilenumber || "",
|
||||||
|
firstName: d.firstName || d.name || "",
|
||||||
|
lastName: d.lastName || d.name || "",
|
||||||
|
unitName:
|
||||||
|
d.unitName || d.title || d.corporationName || d.unionName || "",
|
||||||
|
province: d.province || d.state || extractedProvince || "",
|
||||||
|
city: d.city || "",
|
||||||
|
nationalId:
|
||||||
|
d.nationalId || d.nationalCode || d.nationalcode || nationalCode,
|
||||||
|
};
|
||||||
|
setUserData(aggregatedUserData);
|
||||||
|
handleSetFormDataFromUserDataForAdminAddBuyer(
|
||||||
|
aggregatedUserData,
|
||||||
|
formik
|
||||||
|
);
|
||||||
|
formik2.setFieldValue(
|
||||||
|
"nationalCode",
|
||||||
|
aggregatedUserData.nationalId || nationalCode
|
||||||
|
);
|
||||||
openNotif({
|
openNotif({
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
horizontal: "center",
|
horizontal: "center",
|
||||||
msg: personResponse.payload.error,
|
msg:
|
||||||
severity: "error",
|
type === "unit"
|
||||||
|
? "اطلاعات حقوقی با موفقیت دریافت شد."
|
||||||
|
: "اطلاعات با موفقیت دریافت شد.",
|
||||||
|
severity: "success",
|
||||||
});
|
});
|
||||||
} else if (
|
|
||||||
personResponse.payload?.data?.status &&
|
|
||||||
personResponse.payload?.data?.data
|
|
||||||
) {
|
|
||||||
personData = personResponse.payload.data.data;
|
|
||||||
} else {
|
} else {
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات فردی یافت نشد.",
|
|
||||||
severity: "warning",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildResponse = await dispatch(
|
|
||||||
provinceGetNationalDocumentsService({
|
|
||||||
info: nationalCode,
|
|
||||||
type: "guild",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (guildResponse.payload?.error) {
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: guildResponse.payload.error,
|
|
||||||
severity: "error",
|
|
||||||
});
|
|
||||||
} else if (
|
|
||||||
guildResponse.payload?.data?.status &&
|
|
||||||
guildResponse.payload?.data?.data
|
|
||||||
) {
|
|
||||||
const guildData = guildResponse.payload.data.data;
|
|
||||||
const guildArray = Array.isArray(guildData) ? guildData : [guildData];
|
|
||||||
if (guildArray.length > 0) {
|
|
||||||
const activeGuildIndex = guildArray.findIndex(
|
|
||||||
(g) => g.licenseStatus === "فعال/صادر شده"
|
|
||||||
);
|
|
||||||
selectedGuild =
|
|
||||||
guildArray[activeGuildIndex !== -1 ? activeGuildIndex : 0];
|
|
||||||
} else {
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات صنفی برای این کد ملی یافت نشد.",
|
|
||||||
severity: "warning",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات صنفی برای این کد ملی یافت نشد.",
|
|
||||||
severity: "warning",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!personData && !selectedGuild) {
|
|
||||||
setNotFound(true);
|
setNotFound(true);
|
||||||
formik.setFieldValue("nationalId", nationalCode);
|
formik.setFieldValue("nationalId", nationalCode);
|
||||||
openNotif({
|
openNotif({
|
||||||
vertical: "top",
|
vertical: "top",
|
||||||
horizontal: "center",
|
horizontal: "center",
|
||||||
msg: "اطلاعاتی برای این کد ملی یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
msg:
|
||||||
|
type === "unit"
|
||||||
|
? "اطلاعات حقوقی برای این شناسه یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید."
|
||||||
|
: "اطلاعاتی برای این کد ملی یافت نشد، لطفا اطلاعات را به صورت دستی ثبت کنید.",
|
||||||
severity: "warning",
|
severity: "warning",
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const layerTwo = selectedGuild?.layerTwo || {};
|
|
||||||
const aggregatedUserData = {
|
|
||||||
mobile:
|
|
||||||
layerTwo.mobilenumber ||
|
|
||||||
personData?.mobile ||
|
|
||||||
layerTwo.phonenumber ||
|
|
||||||
"",
|
|
||||||
firstName: personData?.firstName || "",
|
|
||||||
lastName: personData?.lastName || "",
|
|
||||||
unitName:
|
|
||||||
selectedGuild?.title ||
|
|
||||||
layerTwo.corporationName ||
|
|
||||||
layerTwo.unionName ||
|
|
||||||
"",
|
|
||||||
province: selectedGuild?.state || "",
|
|
||||||
city: selectedGuild?.city || "",
|
|
||||||
nationalId:
|
|
||||||
personData?.nationalId ||
|
|
||||||
layerTwo.nationalcode ||
|
|
||||||
selectedGuild?.nationalId ||
|
|
||||||
nationalCode,
|
|
||||||
type: formik.values?.type,
|
|
||||||
role_key: formik.values?.role_key,
|
|
||||||
};
|
|
||||||
|
|
||||||
setUserData(aggregatedUserData);
|
|
||||||
handleSetFormDataFromUserDataForAdminAddBuyer(aggregatedUserData, formik);
|
|
||||||
formik2.setFieldValue(
|
|
||||||
"nationalCode",
|
|
||||||
aggregatedUserData.nationalId || nationalCode
|
|
||||||
);
|
|
||||||
openNotif({
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "center",
|
|
||||||
msg: "اطلاعات با موفقیت دریافت شد.",
|
|
||||||
severity: "success",
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setInquiryInProgress(false);
|
setInquiryInProgress(false);
|
||||||
}
|
}
|
||||||
@@ -486,7 +386,30 @@ export const AdminAddBuyerForm = ({
|
|||||||
isRealPerson,
|
isRealPerson,
|
||||||
killHouses,
|
killHouses,
|
||||||
stewards,
|
stewards,
|
||||||
|
editData,
|
||||||
}) => {
|
}) => {
|
||||||
|
const getStewardLabel = (key) => {
|
||||||
|
const item = stewards?.find((s) => s.key === key);
|
||||||
|
if (item)
|
||||||
|
return `${item?.name || ""} - ${item?.user?.fullname || ""} (${
|
||||||
|
item?.user?.mobile || ""
|
||||||
|
})`;
|
||||||
|
const fromEdit = (editData?.stewardInfo || []).find(
|
||||||
|
(s) => s?.Steward?.key === key || s?.key === key
|
||||||
|
);
|
||||||
|
if (fromEdit)
|
||||||
|
return (
|
||||||
|
fromEdit?.Steward?.name || fromEdit?.fullname || fromEdit?.name || null
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
const killHouseOptions = (killHouses || []).map((option) => ({
|
||||||
|
key: option.key,
|
||||||
|
killer: option.killer,
|
||||||
|
label: option.killer
|
||||||
|
? `کشتارکن ${(option.name || "").trim()}`
|
||||||
|
: `کشتارگاه ${(option.name || "").trim()}`,
|
||||||
|
}));
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
@@ -508,89 +431,61 @@ export const AdminAddBuyerForm = ({
|
|||||||
onBlur={formik.handleBlur}
|
onBlur={formik.handleBlur}
|
||||||
helperText={formik.touched.nationalId && formik.errors.nationalId}
|
helperText={formik.touched.nationalId && formik.errors.nationalId}
|
||||||
/>
|
/>
|
||||||
<LabelField label="انتخاب نوع واحد">
|
<Autocomplete
|
||||||
<RadioGroup
|
fullWidth
|
||||||
row
|
multiple
|
||||||
name="type"
|
disablePortal
|
||||||
value={formik.values.type}
|
id="steward_keys"
|
||||||
onChange={(e) => {
|
options={stewards.map((item) => ({
|
||||||
const value = e.target.value;
|
key: item?.key,
|
||||||
formik.setFieldValue("type", value);
|
label: `${item?.name || ""} - ${item?.user?.fullname || ""} (${
|
||||||
}}
|
item?.user?.mobile || ""
|
||||||
>
|
})`,
|
||||||
<FormControlLabel value="Steward" control={<Radio />} label="مباشر" />
|
}))}
|
||||||
<FormControlLabel
|
getOptionLabel={(option) => option.label || ""}
|
||||||
value="KillHouse"
|
isOptionEqualToValue={(option, value) => option.key === value.key}
|
||||||
control={<Radio />}
|
onChange={(event, value) => {
|
||||||
label="کشتارگاه"
|
formik.setFieldValue(
|
||||||
/>
|
"steward_keys",
|
||||||
</RadioGroup>
|
value ? value.map((v) => v.key) : []
|
||||||
</LabelField>
|
);
|
||||||
{formik.values.type === "Steward" ? (
|
}}
|
||||||
<Autocomplete
|
value={(formik.values.steward_keys || [])
|
||||||
fullWidth
|
.map((key) => {
|
||||||
disablePortal
|
const label = getStewardLabel(key);
|
||||||
id="role_key"
|
return label ? { key, label } : null;
|
||||||
options={stewards.map((item) => {
|
})
|
||||||
return {
|
.filter(Boolean)}
|
||||||
key: item?.key,
|
renderInput={(params) => (
|
||||||
label: `${item?.name || ""} - ${item?.user?.fullname || ""} (${
|
<TextField {...params} label="انتخاب مباشر (چندگانه)" />
|
||||||
item?.user?.mobile || ""
|
)}
|
||||||
})`,
|
/>
|
||||||
};
|
<Autocomplete
|
||||||
})}
|
fullWidth
|
||||||
onChange={(event, value) => {
|
multiple
|
||||||
formik.setFieldValue("role_key", value?.key || "");
|
disablePortal
|
||||||
}}
|
id="kill_house_keys"
|
||||||
value={
|
options={killHouseOptions}
|
||||||
formik.values.role_key
|
getOptionLabel={(option) => option.label || ""}
|
||||||
? {
|
isOptionEqualToValue={(option, value) => option.key === value.key}
|
||||||
key: formik.values.role_key,
|
onChange={(event, value) => {
|
||||||
label:
|
formik.setFieldValue(
|
||||||
stewards.find((item) => item.key === formik.values.role_key)
|
"kill_house_keys",
|
||||||
?.name || "",
|
value ? value.map((v) => v.key) : []
|
||||||
}
|
);
|
||||||
: null
|
}}
|
||||||
}
|
value={(formik.values.kill_house_keys || [])
|
||||||
isOptionEqualToValue={(option, value) => option.key === value.key}
|
.map((key) => {
|
||||||
label="انتخاب مباشر"
|
const option = killHouseOptions.find((k) => k.key === key);
|
||||||
renderInput={(params) => (
|
return option
|
||||||
<TextField fullWidth {...params} label={"انتخاب مباشر"} />
|
? { key, killer: option.killer, label: option.label }
|
||||||
)}
|
: null;
|
||||||
/>
|
})
|
||||||
) : formik.values.type === "KillHouse" ? (
|
.filter(Boolean)}
|
||||||
<FormControl
|
renderInput={(params) => (
|
||||||
fullWidth
|
<TextField {...params} label="انتخاب کشتارگاه یا کشتارکن (چندگانه)" />
|
||||||
error={formik.errors.selectedOption && formik.touched.selectedOption}
|
)}
|
||||||
>
|
/>
|
||||||
<InputLabel>انتخاب کشتارگاه یا کشتارکن</InputLabel>
|
|
||||||
<Select
|
|
||||||
label="انتخاب کشتارگاه یا کشتارکن"
|
|
||||||
id="role_key"
|
|
||||||
name="role_key"
|
|
||||||
// value={formik.values.role_key}
|
|
||||||
onChange={(e) => {
|
|
||||||
const [key] = e.target.value.split("#");
|
|
||||||
formik.setFieldValue("role_key", key);
|
|
||||||
}}
|
|
||||||
onBlur={formik.handleBlur}
|
|
||||||
>
|
|
||||||
{killHouses?.map((option) => (
|
|
||||||
<MenuItem
|
|
||||||
key={option}
|
|
||||||
value={`${option.key + "#" + option.killer}`}
|
|
||||||
>
|
|
||||||
{option.killer
|
|
||||||
? `کشتارکن ${option.name}`
|
|
||||||
: `کشتارگاه ${option.name}`}
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
{formik.errors.role_key && formik.touched.role_key && (
|
|
||||||
<div>{formik.errors.role_key}</div>
|
|
||||||
)}
|
|
||||||
</FormControl>
|
|
||||||
) : null}
|
|
||||||
<TextField
|
<TextField
|
||||||
fullWidth
|
fullWidth
|
||||||
id="mobile"
|
id="mobile"
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ const getInitialValues = (page) => {
|
|||||||
return { ...INITIAL_VALUES_BASE, nationalId: "" };
|
return { ...INITIAL_VALUES_BASE, nationalId: "" };
|
||||||
}
|
}
|
||||||
if (page === PAGE_ADMIN) {
|
if (page === PAGE_ADMIN) {
|
||||||
return { ...INITIAL_VALUES_BASE, role_key: "", type: "" };
|
return { ...INITIAL_VALUES_BASE, steward_keys: [], kill_house_keys: [] };
|
||||||
}
|
}
|
||||||
return { ...INITIAL_VALUES_BASE };
|
return { ...INITIAL_VALUES_BASE };
|
||||||
};
|
};
|
||||||
@@ -169,19 +169,16 @@ export const StewardAddBuyer = ({
|
|||||||
});
|
});
|
||||||
}, [formik.values.province, dispatch]);
|
}, [formik.values.province, dispatch]);
|
||||||
|
|
||||||
// Admin: load stewards or kill houses by type
|
// Admin: load both stewards and kill houses
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (page !== PAGE_ADMIN) return;
|
if (page !== PAGE_ADMIN) return;
|
||||||
if (formik.values.type === "KillHouse") {
|
dispatch(inspectorGetKillHousesService());
|
||||||
dispatch(inspectorGetKillHousesService());
|
dispatch(slaughterGetStewardsForAllocateService({ free: true })).then(
|
||||||
} else {
|
(r) => {
|
||||||
dispatch(slaughterGetStewardsForAllocateService({ free: true })).then(
|
setStewards(r.payload?.data ?? []);
|
||||||
(r) => {
|
}
|
||||||
setStewards(r.payload?.data ?? []);
|
);
|
||||||
}
|
}, [page, dispatch]);
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [page, formik.values.type, dispatch]);
|
|
||||||
|
|
||||||
const handleSubmit = useCallback(() => {
|
const handleSubmit = useCallback(() => {
|
||||||
if (page === PAGE_STEWARD) {
|
if (page === PAGE_STEWARD) {
|
||||||
@@ -315,6 +312,7 @@ export const StewardAddBuyer = ({
|
|||||||
isRealPerson={isRealPerson}
|
isRealPerson={isRealPerson}
|
||||||
killHouses={killHouses}
|
killHouses={killHouses}
|
||||||
stewards={stewards}
|
stewards={stewards}
|
||||||
|
editData={isEdit ? data : null}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/features/steward/services/get-carcasses-buyer-info.js
Normal file
31
src/features/steward/services/get-carcasses-buyer-info.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||||
|
import axios from "axios";
|
||||||
|
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET get_carcasses_buyer_info
|
||||||
|
* @param {Object} payload
|
||||||
|
* @param {string} payload.info - National code or legal ID
|
||||||
|
* @param {string} payload.type - "person" | "unit"
|
||||||
|
*/
|
||||||
|
export const getCarcassesBuyerInfoService = createAsyncThunk(
|
||||||
|
"GET_CARCASSES_BUYER_INFO_SERVICE",
|
||||||
|
async (payload, { dispatch }) => {
|
||||||
|
dispatch(LOADING_START());
|
||||||
|
try {
|
||||||
|
const { data, status } = await axios.get(
|
||||||
|
`get_carcasses_buyer_info/?info=${encodeURIComponent(
|
||||||
|
payload.info
|
||||||
|
)}&type=${payload.type}`,
|
||||||
|
{ timeout: 30000 }
|
||||||
|
);
|
||||||
|
dispatch(LOADING_END());
|
||||||
|
return { data, status };
|
||||||
|
} catch (e) {
|
||||||
|
dispatch(LOADING_END());
|
||||||
|
return {
|
||||||
|
error: e.response?.data?.result || "خطا در دریافت اطلاعات",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user