diff --git a/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js
index a69d534..f2af3ce 100644
--- a/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js
+++ b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js
@@ -5,6 +5,7 @@ import {
DRAWER,
LOADING_END,
LOADING_START,
+ OPEN_MODAL
} from "../../../../lib/redux/slices/appSlice";
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
import { Grid } from "../../../../components/grid/Grid";
@@ -39,7 +40,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
page: page,
pageSize: perPage,
searchValue: textValue,
- buyer_type: IS_STEWARD ? "Steward" : "Guilds",
+ buyer_type: IS_STEWARD ? "Steward" : "Guilds"
});
setData(response.data.results);
setTotalRows(response.data.count);
@@ -60,31 +61,216 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
setPage(1);
};
+ const killHouseList = (item) =>
+ item?.kill_house_info ?? item?.killHouseInfo ?? [];
+ const stewardList = (item) => item?.steward_info ?? item?.stewardInfo ?? [];
+
+ const openKillHousesModal = (list) => {
+ const rows =
+ list?.map((entry, idx) => {
+ const kh = entry?.Kill_house ?? entry?.KillHouse ?? {};
+ const req = entry?.requests_info ?? entry?.requestsInfo ?? {};
+ return [
+ idx + 1,
+ kh?.name ?? "-",
+ entry?.fullname ?? "-",
+ entry?.mobile ?? "-",
+ entry?.unit_name ?? entry?.unitName ?? "-",
+ entry?.province ?? "-",
+ entry?.city ?? "-",
+ (
+ req?.number_of_requests ??
+ req?.numberOfRequests ??
+ 0
+ ).toLocaleString(),
+ (req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(),
+ (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString()
+ ];
+ }) ?? [];
+ dispatch(
+ OPEN_MODAL({
+ title: "لیست کشتارگاه ها",
+ size: "auto",
+ content: (
+
+ )
+ })
+ );
+ };
+
+ const openStewardsModal = (list) => {
+ const rows =
+ list?.map((entry, idx) => {
+ const req = entry?.requests_info ?? entry?.requestsInfo ?? {};
+ return [
+ idx + 1,
+ entry?.fullname ?? "-",
+ entry?.mobile ?? "-",
+ entry?.unit_name ?? entry?.unitName ?? "-",
+ entry?.province ?? "-",
+ entry?.city ?? "-",
+ (
+ req?.number_of_requests ??
+ req?.numberOfRequests ??
+ 0
+ ).toLocaleString(),
+ (req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(),
+ (req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString()
+ ];
+ }) ?? [];
+ dispatch(
+ OPEN_MODAL({
+ title: "لیست مباشرین",
+ size: "auto",
+ content: (
+
+ )
+ })
+ );
+ };
+
useEffect(() => {
const d = data?.map((item, i) => {
- const killHouseName = item?.KillHouse?.name || "-";
+ const khList = killHouseList(item);
+ const stList = stewardList(item);
+ const firstKillHouse = khList?.[0];
+ const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
+ const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
const killHouseOperator =
- item?.KillHouse?.killHouseOperator?.user?.fullname || "";
- const killHouseInfo = killHouseOperator
- ? `${killHouseName} (${killHouseOperator})`
- : killHouseName;
+ firstKillHouse?.fullname ??
+ item?.KillHouse?.killHouseOperator?.user?.fullname ??
+ "";
+ const killHouseDisplay =
+ killHouseOperator && killHouseOperator !== "-"
+ ? `${killHouseName} (${killHouseOperator})`
+ : killHouseName;
+
+ const totalRequests = khList.reduce(
+ (acc, entry) => {
+ const r = entry?.requests_info ?? entry?.requestsInfo ?? {};
+ return {
+ numberOfRequests:
+ acc.numberOfRequests +
+ (r?.number_of_requests ?? r?.numberOfRequests ?? 0),
+ totalQuantity:
+ acc.totalQuantity + (r?.total_quantity ?? r?.totalQuantity ?? 0),
+ totalWeight:
+ acc.totalWeight + (r?.total_weight ?? r?.totalWeight ?? 0)
+ };
+ },
+ { numberOfRequests: 0, totalQuantity: 0, totalWeight: 0 }
+ );
+
+ const requestsNum =
+ khList.length > 0
+ ? totalRequests.numberOfRequests
+ : item?.requestsInfo?.numberOfRequests ??
+ item?.requests_info?.number_of_requests ??
+ 0;
+ const requestsQty =
+ khList.length > 0
+ ? totalRequests.totalQuantity
+ : item?.requestsInfo?.totalQuantity ??
+ item?.requests_info?.total_quantity ??
+ 0;
+ const requestsWt =
+ khList.length > 0
+ ? totalRequests.totalWeight
+ : item?.requestsInfo?.totalWeight ??
+ item?.requests_info?.total_weight ??
+ 0;
+
+ const hasKillHouses = khList?.length > 0;
+ const hasStewards = stList?.length > 0;
+ const listButtons =
+ hasKillHouses || hasStewards ? (
+
+ {hasKillHouses && (
+
+ )}
+ {hasStewards && (
+
+ )}
+
+ ) : (
+ "-"
+ );
return [
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
- `${item?.fullname} (${item?.mobile})`,
- item?.unitName || "-",
- killHouseInfo,
- item?.province || "-",
- item?.city || "-",
- item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
- item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
- item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
+ `${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
+ item?.unit_name ?? item?.unitName ?? "-",
+ killHouseDisplay,
+ item?.province ?? "-",
+ item?.city ?? "-",
+ listButtons,
+ (requestsNum ?? 0).toLocaleString(),
+ (requestsQty ?? 0).toLocaleString(),
+ (requestsWt ?? 0).toLocaleString(),
fetchApiData(1)}
- />,
+ updateTable={() => fetchApiData(page)}
+ />
];
});
@@ -115,7 +301,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {