push rasad front on new repo
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import {
|
||||
Typography,
|
||||
Box,
|
||||
ButtonBase,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import {
|
||||
Spa as SpaIcon,
|
||||
Grass as GrassIcon,
|
||||
Grain as GrainIcon,
|
||||
BlurOn as BlurOnIcon,
|
||||
Texture as TextureIcon,
|
||||
} from "@mui/icons-material";
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
const products = {
|
||||
bran: { label: "سبوس", icon: <SpaIcon fontSize="small" /> },
|
||||
barley: { label: "جو", icon: <GrassIcon fontSize="small" /> },
|
||||
soy: { label: "سویا", icon: <BlurOnIcon fontSize="small" /> },
|
||||
corn: { label: "ذرت", icon: <GrainIcon fontSize="small" /> },
|
||||
sheep_concentrate: {
|
||||
label: "کنسانتره گوسفندی",
|
||||
icon: <TextureIcon fontSize="small" />,
|
||||
},
|
||||
high_cow_concentrate: {
|
||||
label: "کنسانتره گاو شیری پرتولید",
|
||||
icon: <TextureIcon fontSize="small" />,
|
||||
},
|
||||
medium_cow_concentrate: {
|
||||
label: "کنسانتره گاو شیری متوسط",
|
||||
icon: <TextureIcon fontSize="small" />,
|
||||
},
|
||||
fattening_calf_concentrate: {
|
||||
label: "کنسانتره گوساله پرواری",
|
||||
icon: <TextureIcon fontSize="small" />,
|
||||
},
|
||||
};
|
||||
|
||||
const LOCAL_STORAGE_KEY = "selectedProduct";
|
||||
|
||||
const MotionBox = motion(Box);
|
||||
|
||||
const ProductSelector = ({ onSelect }) => {
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||
const [selected, setSelected] = useState("bran");
|
||||
|
||||
useEffect(() => {
|
||||
const saved = localStorage.getItem(LOCAL_STORAGE_KEY);
|
||||
if (saved) {
|
||||
const parsed = JSON.parse(saved);
|
||||
if (parsed.key && products[parsed.key]) {
|
||||
setSelected(parsed.key);
|
||||
onSelect(parsed);
|
||||
}
|
||||
} else {
|
||||
onSelect({ key: "bran", label: products["bran"].label });
|
||||
}
|
||||
}, [onSelect]);
|
||||
|
||||
const handleSelect = (key) => {
|
||||
const selectedProduct = { key, label: products[key].label };
|
||||
setSelected(key);
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(selectedProduct));
|
||||
onSelect(selectedProduct);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ mt: 2 }}>
|
||||
<Typography variant="h6" textAlign="center" color="primary" mb={1}>
|
||||
انتخاب محصول
|
||||
</Typography>
|
||||
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexWrap: isMobile ? "nowrap" : "wrap",
|
||||
overflowX: isMobile ? "auto" : "visible",
|
||||
gap: 1,
|
||||
px: 2,
|
||||
py: 1,
|
||||
justifyContent: isMobile ? "flex-start" : "center",
|
||||
scrollbarWidth: "none",
|
||||
"&::-webkit-scrollbar": { display: "none" },
|
||||
}}
|
||||
>
|
||||
{Object.entries(products).map(([key, { label, icon }]) => {
|
||||
const isSelected = selected === key;
|
||||
|
||||
return (
|
||||
<MotionBox
|
||||
key={key}
|
||||
whileTap={{ scale: 0.95 }}
|
||||
whileHover={{ scale: 1.05 }}
|
||||
transition={{ duration: 0.15 }}
|
||||
>
|
||||
<ButtonBase
|
||||
onClick={() => handleSelect(key)}
|
||||
sx={{
|
||||
borderRadius: "30px",
|
||||
border: `1px solid ${
|
||||
isSelected ? theme.palette.primary.main : "#ddd"
|
||||
}`,
|
||||
backgroundColor: isSelected ? "#e3f2fd" : "#fff",
|
||||
px: 2,
|
||||
py: 1,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 1,
|
||||
whiteSpace: "nowrap",
|
||||
boxShadow: isSelected ? "0 2px 5px rgba(0,0,0,0.1)" : "none",
|
||||
transition: "all 0.2s ease-in-out",
|
||||
minWidth: 150,
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
<Typography fontSize={13}>{label}</Typography>
|
||||
</ButtonBase>
|
||||
</MotionBox>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProductSelector;
|
||||
@@ -0,0 +1,202 @@
|
||||
import {
|
||||
Button,
|
||||
IconButton,
|
||||
Popover,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useContext, useState } from "react";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { ProvinceJahadSubmitAllocation } from "../province-jahad-submit-allocation/ProvinceJahadSubmitAllocation";
|
||||
import { CLOSE_MODAL, OPEN_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
|
||||
import { provinceJahadDeleteAllocationService } from "../../services/province-jahad-submit-allocation";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
|
||||
export const ProvinceJahadAllocationOperations = ({
|
||||
item,
|
||||
// fileUrl,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dispatch = useDispatch();
|
||||
const handleClick = (event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const open = Boolean(anchorEl);
|
||||
const id = open ? "popover" : undefined;
|
||||
|
||||
return (
|
||||
<Grid container>
|
||||
<IconButton
|
||||
aria-describedby={id}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
id={id}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<div
|
||||
style={{ padding: "20px", display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Tooltip title={"ویرایش"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "ویرایش",
|
||||
content: (
|
||||
<ProvinceJahadSubmitAllocation
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
item={item}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title={"حذف "} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="error"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "حذف تخصیص",
|
||||
content: (
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<Typography variant="body2" color="red">
|
||||
آیا از حذف تخصیص اطمینان دارید؟
|
||||
</Typography>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
mt={2}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
spacing={2}
|
||||
>
|
||||
<Grid item xs={6}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
provinceJahadDeleteAllocationService(
|
||||
item?.key
|
||||
)
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
dispatch(CLOSE_MODAL());
|
||||
}
|
||||
});
|
||||
}}
|
||||
variant="contained"
|
||||
color="error"
|
||||
fullWidth
|
||||
>
|
||||
تایید
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
fullWidth
|
||||
>
|
||||
رد
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
{/* {getRoleFromUrl() === "Cooperative" && (
|
||||
<>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "ثبت مقدار دریافتی",
|
||||
content: (
|
||||
<ProvinceJahadUnionSubmitRealWeight
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ثبت مقدار دریافتی
|
||||
</Button>
|
||||
</>
|
||||
)} */}
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,182 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Tab, Tabs } from "@mui/material";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import {
|
||||
provinceJahadGetDistributionInfoService,
|
||||
provinceJahadGetInventoryDataService,
|
||||
} from "../../services/province-jahad-get-distribution-info";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { ProvinceJahadBranDistributionsInventoryAllocations } from "../province-jahad-bran-distributions-inventory-allocation/ProvinceJahadBranDistributionsInventoryAllocation";
|
||||
import { ProvinceJahadBranDistributionsUnionAllocations } from "../province-jahad-bran-distributions-union-allocation/ProvinceJahadBranDistributionsUnionAllocation";
|
||||
|
||||
export const ProvinceJahadBranDistributionsAllocation = ({ product }) => {
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
const [inventoryData, setInventoryData] = useState([]);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadGetDistributionInfoService({
|
||||
name: product?.key,
|
||||
search: "filter",
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
dispatch(
|
||||
provinceJahadGetInventoryDataService({
|
||||
name: product?.key,
|
||||
search: "filter",
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
).then((r) => {
|
||||
setInventoryData(r.payload.data);
|
||||
});
|
||||
};
|
||||
|
||||
// const updateTable = (event) => {
|
||||
// event.preventDefault();
|
||||
// if (childRef.current) {
|
||||
// childRef.current.handleSubmit(event);
|
||||
// }
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
getDashboardData();
|
||||
}, [dispatch]);
|
||||
|
||||
const [selectedTab, setSelectedTab] = useState(0);
|
||||
|
||||
const handleTabChange = (event, newValue) => {
|
||||
setSelectedTab(newValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid container mt={2} mb={4} isDashboard xs={12}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad"
|
||||
? [
|
||||
"ورودی به انبار",
|
||||
"تخصیص جهاد به اتحادیه",
|
||||
"تخصیص جهاد به تعاونی ها",
|
||||
"مجموع تخصیصات",
|
||||
"مجموع تخصیص اتحادیه به تعاونی",
|
||||
"مجموع تخصیص به تعاونی ها",
|
||||
"توزیع به دامداران",
|
||||
"مجموع توزیع به دامداران",
|
||||
"مانده انبار جهاد استان",
|
||||
"مانده انبار اتحادیه",
|
||||
"مانده انبار تعاونی ها",
|
||||
]
|
||||
: getRoleFromUrl() === "Union"
|
||||
? [
|
||||
"ورودی به انبار",
|
||||
"تخصیص به تعاونی ها",
|
||||
// "توزیع مستقیم به دامداران",
|
||||
"مجموع تخصیص و توزیع",
|
||||
"مانده انبار",
|
||||
]
|
||||
: [
|
||||
"سهمیه دریافتی",
|
||||
"مانده سهمیه دریافتی",
|
||||
"ورودی به انبار",
|
||||
"توزیع به دامداران",
|
||||
"مانده انبار",
|
||||
]
|
||||
}
|
||||
data={
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad"
|
||||
? [
|
||||
[
|
||||
dashboardData?.totalWeight?.toLocaleString(),
|
||||
dashboardData?.jahadToUnion?.toLocaleString(),
|
||||
dashboardData?.jahatToCooperative?.toLocaleString(),
|
||||
dashboardData?.allocationCount?.toLocaleString(),
|
||||
dashboardData?.unionToCooperative?.toLocaleString(),
|
||||
parseInt(
|
||||
dashboardData?.unionToCooperative +
|
||||
dashboardData?.jahatToCooperative
|
||||
)?.toLocaleString(),
|
||||
0,
|
||||
0,
|
||||
dashboardData?.totalRemainWeightJahad?.toLocaleString(),
|
||||
dashboardData?.totalRemainWeightUnion?.toLocaleString(),
|
||||
dashboardData?.totalRemainWeightCooperative?.toLocaleString(),
|
||||
],
|
||||
]
|
||||
: getRoleFromUrl() === "Union"
|
||||
? [
|
||||
[
|
||||
dashboardData?.jahadToUnion?.toLocaleString(),
|
||||
dashboardData?.unionToCooperative?.toLocaleString(),
|
||||
// 0,
|
||||
parseInt(
|
||||
0 + dashboardData?.unionToCooperative
|
||||
)?.toLocaleString(),
|
||||
dashboardData?.totalRemainWeight?.toLocaleString(),
|
||||
],
|
||||
]
|
||||
: [
|
||||
[
|
||||
dashboardData?.roleProductCooperativeReceiptWeight?.toLocaleString(),
|
||||
parseInt(
|
||||
dashboardData?.roleProductCooperativeReceiptWeight -
|
||||
dashboardData?.totalWeight
|
||||
)?.toLocaleString(),
|
||||
dashboardData?.totalWeight?.toLocaleString(),
|
||||
0,
|
||||
dashboardData?.totalRemainWeight?.toLocaleString(),
|
||||
],
|
||||
]
|
||||
}
|
||||
title={`اطلاعات انبار و تخصیصات ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
container
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
mb={SPACING.MEDIUM}
|
||||
mt={SPACING.SMALL}
|
||||
xs={12}
|
||||
>
|
||||
<Tabs
|
||||
scrollButtons="auto"
|
||||
variant="scrollable"
|
||||
allowScrollButtonsMobile
|
||||
value={selectedTab}
|
||||
onChange={handleTabChange}
|
||||
>
|
||||
<Tab label="انبار" />
|
||||
<Tab label="تخصیصات" />
|
||||
</Tabs>
|
||||
</Grid>
|
||||
{selectedTab === 0 && (
|
||||
<ProvinceJahadBranDistributionsUnionAllocations
|
||||
inventoryData={inventoryData}
|
||||
getDashboardData={getDashboardData}
|
||||
product={product}
|
||||
maxAllow={dashboardData?.roleProductCooperativeReceiptWeight}
|
||||
/>
|
||||
)}
|
||||
|
||||
{selectedTab === 1 && (
|
||||
<ProvinceJahadBranDistributionsInventoryAllocations
|
||||
inventoryData={inventoryData}
|
||||
getDashboardData={getDashboardData}
|
||||
maxAllow={dashboardData?.roleProductCooperativeReceiptWeight}
|
||||
product={product}
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
export const ProvinceJahadBranDistributionsAllocationsOperations = () => {
|
||||
return <div>provinceJahadBranDistributionsAllocationsOperations</div>;
|
||||
};
|
||||
@@ -0,0 +1,325 @@
|
||||
import React, { useEffect, useState, useContext } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import {
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { formatTime } from "../../../../utils/formatTime";
|
||||
import { getFaUserRole } from "../../../../utils/getFaUserRole";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import moment from "moment";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import { Button, Checkbox, TextField, Tooltip } from "@mui/material";
|
||||
import { ProvinceJahadSubmitAllocation } from "../province-jahad-submit-allocation/ProvinceJahadSubmitAllocation";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import { ProvinceJahadAllocationOperations } from "../province-jahad-allocation-operations/ProvinceJahadAllocationOperations";
|
||||
import ToggleOffOutlinedIcon from "@mui/icons-material/ToggleOffOutlined";
|
||||
import ToggleOnIcon from "@mui/icons-material/ToggleOn";
|
||||
|
||||
export const ProvinceJahadBranDistributionsInventoryAllocations = ({
|
||||
inventoryData,
|
||||
getDashboardData,
|
||||
maxAllow,
|
||||
product,
|
||||
}) => {
|
||||
const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] =
|
||||
useContext(AppContext);
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
const currentDate = moment(new Date()).format("YYYY-MM-DD");
|
||||
setSelectedDate1(currentDate);
|
||||
setSelectedDate2(currentDate);
|
||||
}, []);
|
||||
|
||||
const [textValue, setTextValue] = useState("");
|
||||
|
||||
const [withDate, setWithDate] = useState(false);
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`LiveStock/jahad/live-stock-allocation/?search=filter&value=${textValue}&role=${getRoleFromUrl()}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${page}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// const getCooperativeState = (item) => {
|
||||
// if (getRoleFromUrl() === "Cooperative") {
|
||||
// return [item?.state === "accepted" ? "تایید شده" : "در انتظار تایید"];
|
||||
// } else {
|
||||
// return [];
|
||||
// }
|
||||
// };
|
||||
// const getCooperativeStateLabel = () => {
|
||||
// if (getRoleFromUrl() === "Cooperative") {
|
||||
// return ["وضعیت"];
|
||||
// } else {
|
||||
// return [];
|
||||
// }
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
const from =
|
||||
item?.allocateFrom === "LiveStockProvinceJahad"
|
||||
? item?.jahad?.name
|
||||
: item?.union?.name;
|
||||
const fromRole = getFaUserRole(item?.allocateFrom);
|
||||
const to =
|
||||
item?.allocateTo === "Union"
|
||||
? item?.union?.name
|
||||
: item?.cooperative?.name;
|
||||
const toRole = getFaUserRole(item?.allocateTo);
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.weight?.toLocaleString(),
|
||||
// ...getCooperativeState(item),
|
||||
`${fromRole} (${from})`,
|
||||
`${toRole} (${to})`,
|
||||
item?.allocateFrom === "LiveStockProvinceJahad"
|
||||
? item?.jahad?.user?.fullname
|
||||
: item?.union?.user?.fullname,
|
||||
formatTime(item?.date),
|
||||
item?.place,
|
||||
item?.description,
|
||||
<ProvinceJahadAllocationOperations
|
||||
key={i}
|
||||
updateTable={updateTable}
|
||||
item={item}
|
||||
getDashboardData={getDashboardData}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, selectedDate1, selectedDate2, perPage, withDate]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`LiveStock/jahad/live-stock-allocation/?role=${getRoleFromUrl()}&search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${1}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
const getColumns = () => {
|
||||
if (
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad" ||
|
||||
getRoleFromUrl() === "Union"
|
||||
) {
|
||||
return [
|
||||
"ردیف",
|
||||
"وزن (کیلوگرم)",
|
||||
"مبدا",
|
||||
"مقصد",
|
||||
"ثبت کننده",
|
||||
"تاریخ ثبت",
|
||||
"مکان دریافت",
|
||||
"توضیحات",
|
||||
"عملیات",
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
"ردیف",
|
||||
"وزن (کیلوگرم)",
|
||||
// ...getCooperativeStateLabel(),
|
||||
"مبدا",
|
||||
"مقصد",
|
||||
"ثبت کننده",
|
||||
"تاریخ ثبت",
|
||||
"مکان دریافت",
|
||||
"توضیحات",
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
{(getRoleFromUrl() === "LiveStockProvinceJahad" ||
|
||||
getRoleFromUrl() === "Union") && (
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `تخصیص ${product?.label}`,
|
||||
content: (
|
||||
<ProvinceJahadSubmitAllocation
|
||||
updateTable={updateTable}
|
||||
type={"allocate"}
|
||||
productKey={inventoryData?.key}
|
||||
getDashboardData={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
تخصیص {product?.label}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Grid
|
||||
container
|
||||
gap={1}
|
||||
style={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "1px",
|
||||
padding: "5px",
|
||||
borderRadius: "15px",
|
||||
borderColor: "gray",
|
||||
justifyContent: "left",
|
||||
}}
|
||||
alignItems="center"
|
||||
>
|
||||
<Checkbox
|
||||
icon={<ToggleOffOutlinedIcon />}
|
||||
checkedIcon={<ToggleOnIcon />}
|
||||
checked={withDate}
|
||||
onChange={() => setWithDate(!withDate)}
|
||||
color="primary"
|
||||
size="large"
|
||||
/>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="از تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate1}
|
||||
onChange={(e) => {
|
||||
setSelectedDate1(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="تا تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate2}
|
||||
onChange={(e) => {
|
||||
setSelectedDate2(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل" placement="left-start">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}LiveStock/jahad/allocation_live_stock_excel/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&key=${userKey}&name=${
|
||||
product?.key
|
||||
}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />{" "}
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
ignoreTextsLength
|
||||
data={tableData}
|
||||
columns={getColumns()}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title={`تخصیصات ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,324 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
Switch,
|
||||
TextField,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { provinceJahadEditRancher } from "../../services/province-jahad-rancher-activation";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadGetProductInfoService } from "../../services/province-jahad-get-product-info";
|
||||
import { ProvinceJahadEditProduct } from "../province-jahad-edit-product/ProvinceJahadEditProduct";
|
||||
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
|
||||
export const ProvinceJahadBranDistributionsPolicy = ({ product }) => {
|
||||
const dispatch = useDispatch();
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadGetProductInfoService({ product: product?.key })
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (getRoleFromUrl() === "LiveStockProvinceJahad") {
|
||||
getDashboardData();
|
||||
}
|
||||
}, []);
|
||||
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`/LiveStock/rancher/rancher-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}&name=${
|
||||
product?.key
|
||||
}`
|
||||
);
|
||||
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.herdCode,
|
||||
item?.epidemiologicalCode,
|
||||
item?.postalCode,
|
||||
item?.unitId,
|
||||
item?.herdName,
|
||||
item?.nationalId,
|
||||
item?.user?.fullname.replace(":", " "),
|
||||
item?.mobile,
|
||||
item?.contractorCode || "-",
|
||||
item?.city,
|
||||
// item?.lightLivestock?.toLocaleString(),
|
||||
// item?.heavyLivestock?.toLocaleString(),
|
||||
// Math.round(
|
||||
// item?.lightLivestock + item?.heavyLivestock
|
||||
// )?.toLocaleString(),
|
||||
// item?.weightQuotaLight?.toLocaleString(),
|
||||
// item?.weightQuotaHeavy?.toLocaleString(),
|
||||
// Math.round(
|
||||
// item?.weightQuotaLight + item?.weightQuotaHeavy
|
||||
// )?.toLocaleString(),
|
||||
<FormControlLabel
|
||||
key={i}
|
||||
control={
|
||||
<Switch
|
||||
checked={item?.allowBuy}
|
||||
onChange={() => {
|
||||
dispatch(
|
||||
provinceJahadEditRancher({
|
||||
key: item?.key,
|
||||
allow_buy: !item?.allowBuy,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={item?.allowBuy ? "فعال" : "غیرفعال"}
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/LiveStock/rancher/rancher-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}&name=${
|
||||
product?.key
|
||||
}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
{getRoleFromUrl() === "LiveStockProvinceJahad" && (
|
||||
<Grid container mt={2} mb={4} isDashboard xs={12}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={[
|
||||
"محصول",
|
||||
"سهمیه دام سبک روستایی (کیلوگرم)",
|
||||
"سهمیه دام سنگین روستایی (کیلوگرم)",
|
||||
"سهمیه دام سبک صنعتی (کیلوگرم)",
|
||||
"سهمیه دام سنگین صنعتی (کیلوگرم)",
|
||||
"سهمیه دام سبک DHI (کیلوگرم)",
|
||||
"سهمیه دام سنگین DHI (کیلوگرم)",
|
||||
"قیمت سبوس (ریال)",
|
||||
"کارمزد اتحادیه",
|
||||
"کارمزد تعاونی",
|
||||
"هزینه حمل و نقل",
|
||||
"قیمت درب کارخانه (ریال)",
|
||||
"قیمت درب تعاونی (ریال)",
|
||||
"عملیات",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
dashboardData?.name,
|
||||
dashboardData?.lightWight?.toLocaleString() || "0",
|
||||
dashboardData?.heavyWight?.toLocaleString() || "0",
|
||||
dashboardData?.lightWightIndustrial?.toLocaleString() || "0",
|
||||
dashboardData?.heavyWightIndustrial?.toLocaleString() || "0",
|
||||
dashboardData?.lightWightDha?.toLocaleString() || "0",
|
||||
dashboardData?.heavyWightDha?.toLocaleString() || "0",
|
||||
dashboardData?.price?.toLocaleString() || "0",
|
||||
dashboardData?.unionPrice?.toLocaleString() || "0",
|
||||
dashboardData?.cooperativePrice?.toLocaleString() || "0",
|
||||
dashboardData?.shippingPrice?.toLocaleString() || "0",
|
||||
(
|
||||
(dashboardData?.price || 0) +
|
||||
(dashboardData?.unionPrice || 0) +
|
||||
(dashboardData?.cooperativePrice || 0)
|
||||
)?.toLocaleString() || "0",
|
||||
(
|
||||
(dashboardData?.price || 0) +
|
||||
(dashboardData?.unionPrice || 0) +
|
||||
(dashboardData?.cooperativePrice || 0) +
|
||||
(dashboardData?.shippingPrice || 0)
|
||||
)?.toLocaleString() || "0",
|
||||
<Tooltip
|
||||
key={`edit-${dashboardData?.name || "product"}`}
|
||||
title="ویرایش محصول"
|
||||
placement="left"
|
||||
>
|
||||
<IconButton
|
||||
color="primary"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ویرایش محصول",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvinceJahadEditProduct
|
||||
item={dashboardData}
|
||||
updateTable={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<RemoveRedEyeIcon />
|
||||
</IconButton>
|
||||
</Tooltip>,
|
||||
],
|
||||
]}
|
||||
title={`محدودیت های توزیع ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
{/* <Tooltip title="خروجی اکسل">
|
||||
<a href={`${axios.defaults.baseURL}`} rel="noreferrer">
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip> */}
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"کد گله",
|
||||
"کد اپیدمیولوژیک",
|
||||
"کد پستی",
|
||||
"شناسه یکتا",
|
||||
"نام گله",
|
||||
"کد ملی دامدار",
|
||||
"نام دامدار",
|
||||
"موبایل",
|
||||
"کد پیمانکار",
|
||||
"شهرستان",
|
||||
// "تعداد دام سبک",
|
||||
// "تعداد دام سنگین",
|
||||
// "جمع کل گله",
|
||||
// "سهمیه دام سبک",
|
||||
// "سهمیه دام سنگین",
|
||||
// "مجموع سهمیه",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title={`مجوز دریافت ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,311 @@
|
||||
import React, { useEffect, useState, useContext } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import {
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { formatTime } from "../../../../utils/formatTime";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import moment from "moment";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import { Button, Checkbox, TextField, Tooltip } from "@mui/material";
|
||||
import { ProvinceJahadSubmitAllocation } from "../province-jahad-submit-allocation/ProvinceJahadSubmitAllocation";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import { ProvinceJahadAllocationOperations } from "../province-jahad-allocation-operations/ProvinceJahadAllocationOperations";
|
||||
import ToggleOffOutlinedIcon from "@mui/icons-material/ToggleOffOutlined";
|
||||
import ToggleOnIcon from "@mui/icons-material/ToggleOn";
|
||||
|
||||
export const ProvinceJahadBranDistributionsUnionAllocations = ({
|
||||
inventoryData,
|
||||
getDashboardData,
|
||||
product,
|
||||
maxAllow,
|
||||
}) => {
|
||||
const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] =
|
||||
useContext(AppContext);
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
const currentDate = moment(new Date()).format("YYYY-MM-DD");
|
||||
setSelectedDate1(currentDate);
|
||||
setSelectedDate2(currentDate);
|
||||
}, []);
|
||||
|
||||
const [textValue, setTextValue] = useState("");
|
||||
|
||||
const [withDate, setWithDate] = useState(false);
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`/LiveStock/jahad/live-stock-warehouse-charge-allocation/?search=filter&value=${textValue}&role=${getRoleFromUrl()}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${page}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const getRegisterarData = (item) => {
|
||||
if (getRoleFromUrl() === "Cooperative") {
|
||||
return {
|
||||
key: [],
|
||||
value: [],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
key: "ثبت کننده",
|
||||
value: [item?.jahad?.user?.fullname || item?.union?.user?.fullname],
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.weight?.toLocaleString(),
|
||||
getRegisterarData(item)?.value,
|
||||
formatTime(item?.date),
|
||||
item?.place,
|
||||
item?.description,
|
||||
<ProvinceJahadAllocationOperations
|
||||
key={i}
|
||||
updateTable={updateTable}
|
||||
item={item}
|
||||
getDashboardData={getDashboardData}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, selectedDate1, selectedDate2, perPage, withDate]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`LiveStock/jahad/live-stock-warehouse-charge-allocation/?role=${getRoleFromUrl()}&search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${1}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
"ردیف",
|
||||
"وزن (کیلوگرم)",
|
||||
getRegisterarData()?.key,
|
||||
"تاریخ ثبت",
|
||||
"مبدا",
|
||||
"توضیحات",
|
||||
"عملیات",
|
||||
];
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
{getRoleFromUrl() === "LiveStockProvinceJahad" && (
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `شارژ انبار ${product?.label}`,
|
||||
content: (
|
||||
<ProvinceJahadSubmitAllocation
|
||||
updateTable={updateTable}
|
||||
type="charge"
|
||||
productKey={inventoryData?.key}
|
||||
getDashboardData={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
شارژ انبار {product?.label}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{getRoleFromUrl() === "Cooperative" && (
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `ورود ${product?.label} به انبار`,
|
||||
content: (
|
||||
<ProvinceJahadSubmitAllocation
|
||||
updateTable={updateTable}
|
||||
type="charge"
|
||||
productKey={inventoryData?.key}
|
||||
getDashboardData={getDashboardData}
|
||||
maxAllow={maxAllow}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ورود {product?.label} به انبار
|
||||
</Button>
|
||||
)}
|
||||
<Grid
|
||||
container
|
||||
gap={1}
|
||||
style={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "1px",
|
||||
padding: "5px",
|
||||
borderRadius: "15px",
|
||||
borderColor: "gray",
|
||||
justifyContent: "left",
|
||||
}}
|
||||
alignItems="center"
|
||||
>
|
||||
<Checkbox
|
||||
icon={<ToggleOffOutlinedIcon />}
|
||||
checkedIcon={<ToggleOnIcon />}
|
||||
checked={withDate}
|
||||
onChange={() => setWithDate(!withDate)}
|
||||
color="primary"
|
||||
size="large"
|
||||
/>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="از تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate1}
|
||||
onChange={(e) => {
|
||||
setSelectedDate1(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="تا تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate2}
|
||||
onChange={(e) => {
|
||||
setSelectedDate2(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}LiveStock/jahad/warehouse_live_stock_excel/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&key=${userKey}&name=${
|
||||
product?.key
|
||||
}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad" ||
|
||||
getRoleFromUrl() === "Cooperative"
|
||||
? [...columns]
|
||||
: columns.slice(0, -1)
|
||||
}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title={`شارژ انبار ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,132 @@
|
||||
import React from "react";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { NavLink } from "../../../../components/nav-link/NavLink";
|
||||
import LinkItem from "../../../../components/link-item/LinkItem";
|
||||
import {
|
||||
VscAdd,
|
||||
VscOutput,
|
||||
VscSymbolProperty,
|
||||
VscTable,
|
||||
} from "react-icons/vsc";
|
||||
import {
|
||||
ROUTE_COOPERATIVE_PRODUCT_DISTRIBUTION_ALLOCATION,
|
||||
ROUTE_COOPERATIVE_PRODUCT_DISTRIBUTION_POLICY,
|
||||
ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION,
|
||||
ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_ALLOCATION,
|
||||
ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_POLICY,
|
||||
ROUTE_PROVINCE_JAHAD_PRODUCT_SHARES,
|
||||
ROUTE_PROVINCE_JAHAD_SELL_REPORT,
|
||||
ROUTE_UNION_PRODUCT_DISTRIBUTION,
|
||||
ROUTE_UNION_PRODUCT_DISTRIBUTION_ALLOCATION,
|
||||
ROUTE_UNION_PRODUCT_DISTRIBUTION_POLICY,
|
||||
ROUTE_UNION_SELL_REPORT,
|
||||
} from "../../../../routes/routes";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
|
||||
export const ProvinceJahadBranDistributions = ({ product }) => {
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const getProductColor =
|
||||
product?.key === "bran"
|
||||
? "rgba(224, 224, 224, 0.5)"
|
||||
: product?.key === "barley"
|
||||
? "rgba(245, 194, 149, 0.5)"
|
||||
: product?.key === "soy"
|
||||
? "rgba(164, 239, 204, 0.5)"
|
||||
: product?.key === "corn"
|
||||
? "rgba(193, 239, 164, 0.5)"
|
||||
: "rgba(132, 243, 233, 0.5)";
|
||||
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
gap={SPACING.SMALL}
|
||||
p={SPACING.SMALL}
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
justifyContent="center"
|
||||
style={{ placeContent: "baseline" }}
|
||||
>
|
||||
<Grid container direction="column" style={{ width: "100%" }}>
|
||||
<Grid container gap={SPACING.SMALL} justifyContent="center">
|
||||
<NavLink
|
||||
active={ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_ALLOCATION}
|
||||
to={
|
||||
pathname === ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION
|
||||
? ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_ALLOCATION
|
||||
: pathname === ROUTE_UNION_PRODUCT_DISTRIBUTION
|
||||
? ROUTE_UNION_PRODUCT_DISTRIBUTION_ALLOCATION
|
||||
: ROUTE_COOPERATIVE_PRODUCT_DISTRIBUTION_ALLOCATION
|
||||
}
|
||||
>
|
||||
<LinkItem
|
||||
style={{ backgroundColor: getProductColor }}
|
||||
icon={<VscAdd size={30} color="#244CCC" />}
|
||||
title={`انبار و تخصیص ${product?.label}`}
|
||||
description={`انبار و تخصیص ${product?.label}`}
|
||||
/>
|
||||
</NavLink>
|
||||
|
||||
{(getRoleFromUrl() === "LiveStockProvinceJahad" ||
|
||||
getRoleFromUrl() === "Union") && (
|
||||
<NavLink
|
||||
active={ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_POLICY}
|
||||
to={
|
||||
pathname === ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION
|
||||
? ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION_POLICY
|
||||
: pathname === ROUTE_UNION_PRODUCT_DISTRIBUTION
|
||||
? ROUTE_UNION_PRODUCT_DISTRIBUTION_POLICY
|
||||
: ROUTE_COOPERATIVE_PRODUCT_DISTRIBUTION_POLICY
|
||||
}
|
||||
>
|
||||
<LinkItem
|
||||
style={{ backgroundColor: getProductColor }}
|
||||
icon={<VscSymbolProperty size={30} color="#244CCC" />}
|
||||
title={`مدیریت توزیع ${product?.label}`}
|
||||
description={`مدیریت توزیع ${product?.label}`}
|
||||
/>
|
||||
</NavLink>
|
||||
)}
|
||||
|
||||
{(getRoleFromUrl() === "LiveStockProvinceJahad" ||
|
||||
getRoleFromUrl() === "Union") && (
|
||||
<NavLink
|
||||
active={
|
||||
pathname === ROUTE_PROVINCE_JAHAD_PRODUCT_DISTRIBUTION
|
||||
? ROUTE_PROVINCE_JAHAD_SELL_REPORT
|
||||
: ROUTE_UNION_SELL_REPORT
|
||||
}
|
||||
to={
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad"
|
||||
? ROUTE_PROVINCE_JAHAD_SELL_REPORT
|
||||
: ROUTE_UNION_SELL_REPORT
|
||||
}
|
||||
>
|
||||
<LinkItem
|
||||
style={{ backgroundColor: getProductColor }}
|
||||
icon={<VscOutput size={30} color="#244CCC" />}
|
||||
title={`گزارش فروش ${product?.label}`}
|
||||
description={`گزارش فروش ${product?.label}`}
|
||||
/>
|
||||
</NavLink>
|
||||
)}
|
||||
|
||||
{getRoleFromUrl() === "LiveStockProvinceJahad" && (
|
||||
<NavLink
|
||||
active={ROUTE_PROVINCE_JAHAD_PRODUCT_SHARES}
|
||||
to={ROUTE_PROVINCE_JAHAD_PRODUCT_SHARES}
|
||||
>
|
||||
<LinkItem
|
||||
style={{ backgroundColor: getProductColor }}
|
||||
icon={<VscTable size={30} color="#244CCC" />}
|
||||
title={`سهم بندی ${product?.label}`}
|
||||
description={`سهم بندی ${product?.label}`}
|
||||
/>
|
||||
</NavLink>
|
||||
)}
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
|
||||
import { provinceJahadGetCooperativesPosInfoService } from "../../services/province-jahad-get-cooperatives-pos";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
export const ProvinceJahadCooperativesModal = ({ item }) => {
|
||||
const dispatch = useDispatch();
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(provinceJahadGetCooperativesPosInfoService(item.key)).then((r) => {
|
||||
const d = r.payload.data?.map((item, i) => {
|
||||
return [i + 1, item?.companyName, item?.posId];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Grid container xs={12}>
|
||||
<SimpleTable
|
||||
columns={["ردیف", "نام شرکت", "شناسه POS"]}
|
||||
data={tableData}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,141 @@
|
||||
import {
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
Popover,
|
||||
Switch,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { useContext, useState } from "react";
|
||||
// import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
|
||||
import { ProvinceJahadEditCooperative } from "../province-jahad-edit-cooperative/ProvinceJahadEditCooperative";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadEditCooperativeService } from "../../services/province-jahad-submit-cooperatives";
|
||||
|
||||
export const ProvinceJahadCooperativesOperations = ({
|
||||
item,
|
||||
// fileUrl,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dispatch = useDispatch();
|
||||
const handleClick = (event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const open = Boolean(anchorEl);
|
||||
const id = open ? "popover" : undefined;
|
||||
|
||||
return (
|
||||
<Grid container>
|
||||
<IconButton
|
||||
aria-describedby={id}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
id={id}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<div
|
||||
style={{ padding: "20px", display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Tooltip title={"ویرایش"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ویرایش اطلاعات ",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvinceJahadEditCooperative
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
item={item}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={item?.active}
|
||||
onChange={() => {
|
||||
dispatch(
|
||||
provinceJahadEditCooperativeService({
|
||||
cooperative_key: item?.key,
|
||||
active: !item?.active,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={item?.active ? "فعال" : "غیرفعال"}
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* <Tooltip title={"حذف "} placement="left-start">
|
||||
<IconButton aria-label="delete" color="error">
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip> */}
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,205 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, IconButton, TextField, Tooltip } from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { ProvinceJahadCooperativesOperations } from "../province-jahad-cooperatives-operations/ProvinceJahadCooperativesOperations";
|
||||
import { ProvinceJahadEditCooperative } from "../province-jahad-edit-cooperative/ProvinceJahadEditCooperative";
|
||||
import TabletAndroidIcon from "@mui/icons-material/TabletAndroid";
|
||||
import { ProvinceJahadCooperativesModal } from "../province-jahad-cooperatives-modal/ProvinceJahadCooperativesModal";
|
||||
|
||||
export const ProvinceJahadCooperatives = () => {
|
||||
const dispatch = useDispatch();
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`/LiveStock/cooperative/cooperative-views/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.name,
|
||||
item?.user.fullname,
|
||||
item?.address?.province?.name,
|
||||
item?.address?.city?.name,
|
||||
item?.user.mobile,
|
||||
item?.nationalId,
|
||||
item?.account || "-",
|
||||
item?.user?.password || "-",
|
||||
<Tooltip placement="left" title="لیست دستگاه POS" key={i}>
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `لیست دستگاههای POS تعاونی ${item?.name}`,
|
||||
content: <ProvinceJahadCooperativesModal item={item} />,
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<TabletAndroidIcon />
|
||||
</IconButton>
|
||||
</Tooltip>,
|
||||
<ProvinceJahadCooperativesOperations
|
||||
key={i}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/LiveStock/cooperative/cooperative-views/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ایجاد تعاونی",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvinceJahadEditCooperative updateTable={updateTable} />
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ایجاد تعاونی
|
||||
</Button>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}live-stock-cooperatives-excel/?role=${getRoleFromUrl()}&key=${userKey}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"نام تعاونی",
|
||||
"کاربر",
|
||||
"استان",
|
||||
"شهر",
|
||||
"موبایل",
|
||||
"کد ملی",
|
||||
"شماره شبا",
|
||||
"کلمه عبور",
|
||||
"POS",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title="تعاونی ها "
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,325 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import {
|
||||
Grid,
|
||||
TextField,
|
||||
Button,
|
||||
Autocomplete,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { useDispatch } from "react-redux";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import {
|
||||
provinceJahadEditCooperativeService,
|
||||
provinceJahadSubmitCooperativeService,
|
||||
} from "../../services/province-jahad-submit-cooperatives";
|
||||
import { cityGetProvinces } from "../../../city/services/CityGetProvinces";
|
||||
import { cityGetCity } from "../../../city/services/city-get-city";
|
||||
|
||||
export const ProvinceJahadEditCooperative = ({
|
||||
updateTable,
|
||||
item,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const [provinceData, setProvinceData] = useState([]);
|
||||
const [cityData, setCityData] = useState([]);
|
||||
const [provinceKey, setProvinceKey] = useState();
|
||||
const [cityKey, setCityKey] = useState();
|
||||
const [isExistProvince, setIsExistProvince] = useState(true);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string().required("این فیلد الزامی است"),
|
||||
first_name: Yup.string().required("این فیلد الزامی است"),
|
||||
last_name: Yup.string().required("این فیلد الزامی است"),
|
||||
address: Yup.string().required("این فیلد الزامی است"),
|
||||
nationalId: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(10, "کد ملی باید ۱۰ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
postalCode: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(10, "کد پستی باید ۱۰ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
mobile: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(11, "شماره موبایل باید ۱۱ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
account: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.typeError("صرفا اعداد شماره شبا را وارد کنید!"),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetProvinces())?.then((r) => {
|
||||
dispatch(LOADING_END());
|
||||
setProvinceData(r.payload.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_END());
|
||||
if (provinceKey) {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetCity(provinceKey)).then((r) => {
|
||||
setCityData(r.payload.data);
|
||||
setIsExistProvince(false);
|
||||
dispatch(LOADING_END());
|
||||
});
|
||||
}
|
||||
}, [provinceKey]);
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
name: item?.name || "",
|
||||
first_name: item?.user?.firstName || "",
|
||||
last_name: item?.user?.lastName || "",
|
||||
mobile: item?.user?.mobile || "",
|
||||
address: item?.address?.address || "",
|
||||
nationalId: item?.nationalId || "",
|
||||
postalCode: item?.address?.postalCode || "",
|
||||
account: item?.account?.replace(/ir/gi, "") ?? "",
|
||||
},
|
||||
validationSchema,
|
||||
enableReinitialize: true,
|
||||
onSubmit: (values) => {
|
||||
if (item) {
|
||||
dispatch(
|
||||
provinceJahadEditCooperativeService({
|
||||
cooperative_key: item?.key,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
name: values.name,
|
||||
address: values.address,
|
||||
mobile: values.mobile,
|
||||
account: "IR" + values.account,
|
||||
national_id: values.nationalId,
|
||||
postal_code: values.postalCode,
|
||||
city: cityKey || item?.address?.city?.name,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
provinceJahadSubmitCooperativeService({
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
name: values.name,
|
||||
mobile: values.mobile,
|
||||
address: values.address,
|
||||
national_id: values.nationalId,
|
||||
postal_code: values.postalCode,
|
||||
account: "IR" + values.account,
|
||||
city: cityKey,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const isFormValid = () => {
|
||||
if (item) {
|
||||
return formik.isValid;
|
||||
} else {
|
||||
return formik.isValid && cityKey;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container direction="column" gap={SPACING.SMALL}>
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<TextField
|
||||
name="name"
|
||||
label=" نام تعاونی"
|
||||
fullWidth
|
||||
value={formik.values.name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.name && Boolean(formik.errors.name)}
|
||||
helperText={formik.touched.name && formik.errors.name}
|
||||
/>
|
||||
|
||||
<Autocomplete
|
||||
disablePortal
|
||||
id="province"
|
||||
options={provinceData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setProvinceKey(value.id);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="استان را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
|
||||
<Autocomplete
|
||||
disabled={isExistProvince}
|
||||
disablePortal
|
||||
id="city"
|
||||
options={cityData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setCityKey(value.label);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="شهر را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
{item && !cityKey && (
|
||||
<Typography variant="caption" color="error">
|
||||
شهر: {item?.address?.city?.name}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
<TextField
|
||||
name="first_name"
|
||||
label="نام "
|
||||
fullWidth
|
||||
value={formik.values.first_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.first_name && Boolean(formik.errors.first_name)
|
||||
}
|
||||
helperText={formik.touched.first_name && formik.errors.first_name}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="last_name"
|
||||
label=" نام خانوادگی"
|
||||
fullWidth
|
||||
value={formik.values.last_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.last_name && Boolean(formik.errors.last_name)}
|
||||
helperText={formik.touched.last_name && formik.errors.last_name}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="mobile"
|
||||
label="تلفن"
|
||||
fullWidth
|
||||
value={formik.values.mobile}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.mobile && Boolean(formik.errors.mobile)}
|
||||
helperText={formik.touched.mobile && formik.errors.mobile}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="address"
|
||||
label="آدرس "
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="nationalId"
|
||||
label="کد ملی"
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
fullWidth
|
||||
value={formik.values.nationalId}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.nationalId && Boolean(formik.errors.nationalId)
|
||||
}
|
||||
helperText={formik.touched.nationalId && formik.errors.nationalId}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="postalCode"
|
||||
label="کد پستی"
|
||||
fullWidth
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
value={formik.values.postalCode}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.postalCode && Boolean(formik.errors.postalCode)
|
||||
}
|
||||
helperText={formik.touched.postalCode && formik.errors.postalCode}
|
||||
/>
|
||||
<TextField
|
||||
name="account"
|
||||
label="شماره شبا"
|
||||
fullWidth
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
value={formik.values.account}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.account && Boolean(formik.errors.account)}
|
||||
helperText={formik.touched.account && formik.errors.account}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={!isFormValid()}
|
||||
>
|
||||
ثبت اطلاعات
|
||||
</Button>
|
||||
</Grid>
|
||||
</form>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,310 @@
|
||||
import React, { useContext, useEffect } from "react";
|
||||
import { Button, TextField } from "@mui/material";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadUpdateProductService } from "../../services/province-jahad-update-product";
|
||||
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
|
||||
import { NumberInput } from "../../../../components/number-format-custom/NumberFormatCustom";
|
||||
|
||||
export const ProvinceJahadEditProduct = ({ item, updateTable }) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const validationSchema = Yup.object({
|
||||
light_weight: Yup.number().required("این فیلد اجباری است!"),
|
||||
heavy_weight: Yup.number().required("این فیلد اجباری است!"),
|
||||
light_wight_industrial: Yup.number().required("این فیلد اجباری است!"),
|
||||
heavy_wight_industrial: Yup.number().required("این فیلد اجباری است!"),
|
||||
light_wight_dha: Yup.number().required("این فیلد اجباری است!"),
|
||||
heavy_wight_dha: Yup.number().required("این فیلد اجباری است!"),
|
||||
price: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.positive("عدد مثبت وارد کنید!"),
|
||||
unionPrice: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.positive("عدد مثبت وارد کنید!"),
|
||||
cooperativePrice: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.positive("عدد مثبت وارد کنید!"),
|
||||
shippingPrice: Yup.number()
|
||||
.required("این فیلد اجباری است!")
|
||||
.positive("عدد مثبت وارد کنید!"),
|
||||
});
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
light_weight: item.lightWight || 0,
|
||||
heavy_weight: item.heavyWight || 0,
|
||||
light_wight_industrial: item.lightWightIndustrial || 0,
|
||||
heavy_wight_industrial: item.heavyWightIndustrial || 0,
|
||||
light_wight_dha: item.lightWightDha || 0,
|
||||
heavy_wight_dha: item.heavyWightDha || 0,
|
||||
price: item.price || 0,
|
||||
unionPrice: item.unionPrice || 0,
|
||||
cooperativePrice: item.cooperativePrice || 0,
|
||||
shippingPrice: item.shippingPrice || 0,
|
||||
},
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
dispatch(
|
||||
provinceJahadUpdateProductService({
|
||||
key: item?.key,
|
||||
light_wight: values.light_weight,
|
||||
heavy_wight: values.heavy_weight,
|
||||
light_wight_industrial: values.light_wight_industrial,
|
||||
heavy_wight_industrial: values.heavy_wight_industrial,
|
||||
light_wight_dha: values.light_wight_dha,
|
||||
heavy_wight_dha: values.heavy_wight_dha,
|
||||
price: values.price,
|
||||
union_price: values.unionPrice,
|
||||
cooperative_price: values.cooperativePrice,
|
||||
shipping_price: values.shippingPrice,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
formik.validateForm();
|
||||
}, [dispatch]);
|
||||
|
||||
return (
|
||||
<Grid container xs={12} alignItems="center" justifyContent="center" gap={1}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="light_weight"
|
||||
name="light_weight"
|
||||
label="سهمیه دام سبک روستایی"
|
||||
value={formik.values.light_weight}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.light_weight && Boolean(formik.errors.light_weight)
|
||||
}
|
||||
helperText={formik.touched.light_weight && formik.errors.light_weight}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="heavy_weight"
|
||||
name="heavy_weight"
|
||||
label="سهمیه دام سنگین روستایی"
|
||||
value={formik.values.heavy_weight}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.heavy_weight && Boolean(formik.errors.heavy_weight)
|
||||
}
|
||||
helperText={formik.touched.heavy_weight && formik.errors.heavy_weight}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="light_wight_industrial"
|
||||
name="light_wight_industrial"
|
||||
label="سهمیه دام سبک صنعتی"
|
||||
value={formik.values.light_wight_industrial}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.light_wight_industrial &&
|
||||
Boolean(formik.errors.light_wight_industrial)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.light_wight_industrial &&
|
||||
formik.errors.light_wight_industrial
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="heavy_wight_industrial"
|
||||
name="heavy_wight_industrial"
|
||||
label="سهمیه دام سنگین صنعتی"
|
||||
value={formik.values.heavy_wight_industrial}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.heavy_wight_industrial &&
|
||||
Boolean(formik.errors.heavy_wight_industrial)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.heavy_wight_industrial &&
|
||||
formik.errors.heavy_wight_industrial
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="light_wight_dha"
|
||||
name="light_wight_dha"
|
||||
label="سهمیه دام سبک DHA"
|
||||
value={formik.values.light_wight_dha}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.light_wight_dha &&
|
||||
Boolean(formik.errors.light_wight_dha)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.light_wight_dha && formik.errors.light_wight_dha
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="heavy_wight_dha"
|
||||
name="heavy_wight_dha"
|
||||
label="سهمیه دام سنگین DHA"
|
||||
value={formik.values.heavy_wight_dha}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.heavy_wight_dha &&
|
||||
Boolean(formik.errors.heavy_wight_dha)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.heavy_wight_dha && formik.errors.heavy_wight_dha
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<NumberInput
|
||||
allowLeadingZeros
|
||||
thousandSeparator=","
|
||||
fullWidth
|
||||
id="price"
|
||||
label="قیمت هر کیلو (ریال)"
|
||||
// InputProps={{
|
||||
// inputComponent: NumberFormatCustom,
|
||||
// }}
|
||||
variant="outlined"
|
||||
value={formik.values.price}
|
||||
error={formik.touched.price ? Boolean(formik.errors.price) : null}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.price && Boolean(formik.errors.price)
|
||||
? formik.errors.price
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<NumberInput
|
||||
allowLeadingZeros
|
||||
thousandSeparator=","
|
||||
fullWidth
|
||||
id="unionPrice"
|
||||
label="کارمزد اتحادیه (ریال)"
|
||||
// InputProps={{
|
||||
// inputComponent: NumberFormatCustom,
|
||||
// }}
|
||||
variant="outlined"
|
||||
value={formik.values.unionPrice}
|
||||
error={
|
||||
formik.touched.unionPrice ? Boolean(formik.errors.unionPrice) : null
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.unionPrice && Boolean(formik.errors.unionPrice)
|
||||
? formik.errors.unionPrice
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<NumberInput
|
||||
allowLeadingZeros
|
||||
thousandSeparator=","
|
||||
fullWidth
|
||||
id="cooperativePrice"
|
||||
label="کارمزد تعاونی (ریال)"
|
||||
// InputProps={{
|
||||
// inputComponent: NumberFormatCustom,
|
||||
// }}
|
||||
variant="outlined"
|
||||
value={formik.values.cooperativePrice}
|
||||
error={
|
||||
formik.touched.cooperativePrice
|
||||
? Boolean(formik.errors.cooperativePrice)
|
||||
: null
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.cooperativePrice &&
|
||||
Boolean(formik.errors.cooperativePrice)
|
||||
? formik.errors.cooperativePrice
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<NumberInput
|
||||
allowLeadingZeros
|
||||
thousandSeparator=","
|
||||
fullWidth
|
||||
id="shippingPrice"
|
||||
label="هزینه حمل و نقل (ریال)"
|
||||
// InputProps={{
|
||||
// inputComponent: NumberFormatCustom,
|
||||
// }}
|
||||
variant="outlined"
|
||||
value={formik.values.shippingPrice}
|
||||
error={
|
||||
formik.touched.shippingPrice
|
||||
? Boolean(formik.errors.shippingPrice)
|
||||
: null
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.shippingPrice && Boolean(formik.errors.shippingPrice)
|
||||
? formik.errors.shippingPrice
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
ثبت
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,359 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Grid,
|
||||
TextField,
|
||||
Button,
|
||||
Autocomplete,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { cityGetProvinces } from "../../../city/services/CityGetProvinces";
|
||||
import { cityGetCity } from "../../../city/services/city-get-city";
|
||||
import { useDispatch } from "react-redux";
|
||||
import {
|
||||
provinceJahadEditRancher,
|
||||
provinceJahadSubmitRancher,
|
||||
} from "../../services/province-jahad-rancher-activation";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
mobile: Yup.string()
|
||||
.required("این فیلد اجباری است!")
|
||||
.min(11, "شماره موبایل باید 11 رقم باشد")
|
||||
.max(11, "شماره موبایل باید 11 رقم باشد")
|
||||
.matches(/^09\d{9}$/, "شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),
|
||||
first_name: Yup.string().required("این فیلد اجباریست!"),
|
||||
last_name: Yup.string().required("این فیلد اجباریست!"),
|
||||
national_id: Yup.string()
|
||||
.required("این فیلد اجباریست!")
|
||||
.matches(/^\d{10}$/, "کد ملی باید 10 رقم باشد!"),
|
||||
postal_code: Yup.string().required("این فیلد اجباریست!"),
|
||||
name: Yup.string().required("این فیلد اجباریست!"),
|
||||
epidemiological_code: Yup.string().required("این فیلد اجباریست!"),
|
||||
herd_code: Yup.string().required("این فیلد اجباریست!"),
|
||||
herd_name: Yup.string().required("این فیلد اجباریست!"),
|
||||
});
|
||||
|
||||
export const ProvinceJahadEditRancher = ({ item, updateTable }) => {
|
||||
const [provinceData, setProvinceData] = useState([]);
|
||||
const [cityData, setCityData] = useState([]);
|
||||
const [provinceKey, setProvinceKey] = useState();
|
||||
const [cityKey, setCityKey] = useState();
|
||||
const [isExistProvince, setIsExistProvince] = useState(true);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
mobile: item?.mobile || "",
|
||||
first_name: item?.user?.firstName || "",
|
||||
last_name: item?.user?.lastName || "",
|
||||
national_id: item?.nationalId || "",
|
||||
postal_code: item?.postalCode || "",
|
||||
name: item?.name || "",
|
||||
epidemiological_code: item?.epidemiologicalCode || "",
|
||||
herd_code: item?.herdCode || "",
|
||||
herd_name: item?.herdName || "",
|
||||
},
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
if (item) {
|
||||
dispatch(
|
||||
provinceJahadEditRancher({
|
||||
key: item?.key,
|
||||
city: cityKey || item?.city,
|
||||
mobile: values.mobile,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
national_id: values.national_id,
|
||||
postal_code: values.postal_code,
|
||||
name: values.name,
|
||||
epidemiological_code: values.epidemiological_code,
|
||||
herd_code: values.herd_code,
|
||||
herd_name: values.herd_name,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
provinceJahadSubmitRancher({
|
||||
city: cityKey,
|
||||
mobile: values.mobile,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
national_id: values.national_id,
|
||||
postal_code: values.postal_code,
|
||||
name: values.name,
|
||||
epidemiological_code: values.epidemiological_code,
|
||||
herd_code: values.herd_code,
|
||||
herd_name: values.herd_name,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const isFormValid = () => {
|
||||
if (item) {
|
||||
return formik.isValid;
|
||||
} else {
|
||||
return formik.isValid && cityKey;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetProvinces())?.then((r) => {
|
||||
dispatch(LOADING_END());
|
||||
setProvinceData(r.payload.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_END());
|
||||
if (provinceKey) {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetCity(provinceKey)).then((r) => {
|
||||
setCityData(r.payload.data);
|
||||
setIsExistProvince(false);
|
||||
dispatch(LOADING_END());
|
||||
});
|
||||
}
|
||||
}, [provinceKey]);
|
||||
|
||||
return (
|
||||
<Grid container direction="column" gap={SPACING.SMALL}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="name"
|
||||
name="name"
|
||||
label="نام دامداری"
|
||||
value={formik.values.name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.name && Boolean(formik.errors.name)}
|
||||
helperText={formik.touched.name && formik.errors.name}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="herd_name"
|
||||
name="herd_name"
|
||||
label="نام گله"
|
||||
value={formik.values.herd_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.herd_name && Boolean(formik.errors.herd_name)}
|
||||
helperText={formik.touched.herd_name && formik.errors.herd_name}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="first_name"
|
||||
name="first_name"
|
||||
label="نام"
|
||||
value={formik.values.first_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.first_name && Boolean(formik.errors.first_name)
|
||||
}
|
||||
helperText={formik.touched.first_name && formik.errors.first_name}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="last_name"
|
||||
name="last_name"
|
||||
label="نام خانوادگی"
|
||||
value={formik.values.last_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.last_name && Boolean(formik.errors.last_name)}
|
||||
helperText={formik.touched.last_name && formik.errors.last_name}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="mobile"
|
||||
name="mobile"
|
||||
label="موبایل"
|
||||
value={formik.values.mobile}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.mobile && Boolean(formik.errors.mobile)}
|
||||
helperText={formik.touched.mobile && formik.errors.mobile}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Autocomplete
|
||||
disablePortal
|
||||
id="province"
|
||||
options={provinceData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setProvinceKey(value.id);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="استان را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
|
||||
<Autocomplete
|
||||
disabled={isExistProvince}
|
||||
disablePortal
|
||||
id="city"
|
||||
options={cityData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setCityKey(value.label);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="شهر را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
{item && !cityKey && (
|
||||
<Typography variant="caption" color="error">
|
||||
شهر: {item?.city}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="national_id"
|
||||
name="national_id"
|
||||
label="کد ملی"
|
||||
value={formik.values.national_id}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.national_id && Boolean(formik.errors.national_id)
|
||||
}
|
||||
helperText={formik.touched.national_id && formik.errors.national_id}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="postal_code"
|
||||
name="postal_code"
|
||||
label="کد پستی"
|
||||
value={formik.values.postal_code}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.postal_code && Boolean(formik.errors.postal_code)
|
||||
}
|
||||
helperText={formik.touched.postal_code && formik.errors.postal_code}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="epidemiological_code"
|
||||
name="epidemiological_code"
|
||||
label="کد اپیدمیولوژیک"
|
||||
value={formik.values.epidemiological_code}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.epidemiological_code &&
|
||||
Boolean(formik.errors.epidemiological_code)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.epidemiological_code &&
|
||||
formik.errors.epidemiological_code
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="herd_code"
|
||||
name="herd_code"
|
||||
label="کد گله"
|
||||
value={formik.values.herd_code}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.herd_code && Boolean(formik.errors.herd_code)}
|
||||
helperText={formik.touched.herd_code && formik.errors.herd_code}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Button
|
||||
disabled={!isFormValid()}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
ثبت
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,148 @@
|
||||
import React, { useContext } from "react";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { Grid, TextField, Button } from "@mui/material";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
|
||||
import { provinceJahadSubmitShareService } from "../../services/province-jahad-submit-share";
|
||||
|
||||
export const ProvinceJahadEditShare = ({ updateTable, item }) => {
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const dispatch = useDispatch();
|
||||
const validationSchema = Yup.object().shape({
|
||||
price: Yup.string().required("این فیلد الزامی است"),
|
||||
shipping_price: Yup.string().required("این فیلد الزامی است"),
|
||||
union_price: Yup.string().required("این فیلد الزامی است"),
|
||||
cooperative_price: Yup.string().required("این فیلد الزامی است"),
|
||||
company_price: Yup.string().required("این فیلد الزامی است"),
|
||||
});
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
price: item?.price || "",
|
||||
shipping_price: item?.shippingPrice || "",
|
||||
union_price: item?.unionPrice || "",
|
||||
company_price: item?.companyPrice || "",
|
||||
cooperative_price: item?.cooperativePrice || "",
|
||||
},
|
||||
validationSchema,
|
||||
enableReinitialize: true,
|
||||
onSubmit: (values) => {
|
||||
dispatch(
|
||||
provinceJahadSubmitShareService({
|
||||
share_key: item?.key,
|
||||
shipping_price: values.shipping_price,
|
||||
union_price: values.union_price,
|
||||
company_price: values.company_price,
|
||||
price: values.price,
|
||||
cooperative_price: values.cooperative_price,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Grid container direction="column" gap={SPACING.SMALL}>
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<TextField
|
||||
name="price"
|
||||
label="قیمت پایه "
|
||||
fullWidth
|
||||
value={formik.values.price}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.price && Boolean(formik.errors.price)}
|
||||
helperText={formik.touched.price && formik.errors.price}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="shipping_price"
|
||||
label="هزینه حمل و نقل"
|
||||
fullWidth
|
||||
value={formik.values.shipping_price}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.shipping_price &&
|
||||
Boolean(formik.errors.shipping_price)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.shipping_price && formik.errors.shipping_price
|
||||
}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="union_price"
|
||||
label="سهم اتحادیه"
|
||||
fullWidth
|
||||
value={formik.values.union_price}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.union_price && Boolean(formik.errors.union_price)
|
||||
}
|
||||
helperText={formik.touched.union_price && formik.errors.union_price}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="cooperative_price"
|
||||
label="سهم تعاونی"
|
||||
fullWidth
|
||||
value={formik.values.cooperative_price}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.cooperative_price &&
|
||||
Boolean(formik.errors.cooperative_price)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.cooperative_price &&
|
||||
formik.errors.cooperative_price
|
||||
}
|
||||
/>
|
||||
<TextField
|
||||
name="company_price"
|
||||
label="سهم شرکت"
|
||||
fullWidth
|
||||
value={formik.values.company_price}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.company_price &&
|
||||
Boolean(formik.errors.company_price)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.company_price && formik.errors.company_price
|
||||
}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="contained" color="primary">
|
||||
ثبت اطلاعات
|
||||
</Button>
|
||||
</Grid>
|
||||
</form>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,276 @@
|
||||
import {
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
Popover,
|
||||
Switch,
|
||||
Tooltip,
|
||||
Button,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useContext, useState } from "react";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import {
|
||||
DRAWER,
|
||||
OPEN_MODAL,
|
||||
CLOSE_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { ProvicneJahadSubmitHerd } from "../province-jahad-submit-herd/ProvicneJahadSubmitHerd";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import UnarchiveIcon from "@mui/icons-material/Unarchive";
|
||||
import ArchiveIcon from "@mui/icons-material/Archive";
|
||||
import {
|
||||
provinceJahadEditHerdService,
|
||||
provinceJahadDeleteHerdService,
|
||||
} from "../../services/province-jahad-submit-herd";
|
||||
|
||||
export const ProvinceJahadHerdsOperations = ({
|
||||
item,
|
||||
// fileUrl,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
dataType,
|
||||
}) => {
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dispatch = useDispatch();
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const handleClick = (event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const open = Boolean(anchorEl);
|
||||
const id = open ? "popover" : undefined;
|
||||
|
||||
const handleArchive = () => {
|
||||
dispatch(
|
||||
provinceJahadDeleteHerdService({
|
||||
live_stock_key: item?.key,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(CLOSE_MODAL());
|
||||
}
|
||||
});
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleUnarchive = () => {
|
||||
dispatch(
|
||||
provinceJahadEditHerdService({
|
||||
live_stock_key: item?.key,
|
||||
return_from_archive: true,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
dispatch(CLOSE_MODAL());
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const showConfirmationModal = (action) => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "آیا مطمئن هستید؟",
|
||||
content: (
|
||||
<Grid container spacing={2}>
|
||||
<Grid
|
||||
item
|
||||
xs={12}
|
||||
container
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<Typography variant="body2">
|
||||
{action === "archive"
|
||||
? "آیا میخواهید این گله را به بایگانی منتقل کنید؟"
|
||||
: "آیا میخواهید این گله را از بایگانی خارج کنید؟"}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Button
|
||||
fullWidth
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
if (action === "archive") {
|
||||
handleArchive();
|
||||
} else {
|
||||
handleUnarchive();
|
||||
}
|
||||
}}
|
||||
>
|
||||
بله
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<Button
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
onClick={() => dispatch(CLOSE_MODAL())}
|
||||
>
|
||||
خیر
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container>
|
||||
<IconButton
|
||||
aria-describedby={id}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
id={id}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<div
|
||||
style={{ padding: "20px", display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Tooltip title={"ویرایش"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ویرایش اطلاعات",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvicneJahadSubmitHerd
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
item={item}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={item?.active}
|
||||
onChange={() => {
|
||||
dispatch(
|
||||
provinceJahadEditHerdService({
|
||||
live_stock_key: item?.key,
|
||||
active: !item?.active,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={item?.active ? "فعال" : "غیرفعال"}
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
/>
|
||||
{dataType === "archive" ? (
|
||||
<Tooltip title="برگشت از بایگانی" placement="left-start">
|
||||
<IconButton
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={() => showConfirmationModal("unarchive")}
|
||||
style={{ marginTop: "10px" }}
|
||||
>
|
||||
<UnarchiveIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Tooltip title="انتقال به بایگانی" placement="left-start">
|
||||
<IconButton
|
||||
variant="outlined"
|
||||
color="error"
|
||||
onClick={() => showConfirmationModal("archive")}
|
||||
style={{ marginTop: "10px" }}
|
||||
>
|
||||
<ArchiveIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,277 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, Tab, Tabs, TextField, Tooltip } from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { provinceJahadGetHerdInfoDashboardService } from "../../services/province-jahad-get-herd-dashbored";
|
||||
import { ProvinceJahadHerdsOperations } from "../province-jahad-herds-operations/ProvinceJahadHerdsOperations";
|
||||
import { ProvicneJahadSubmitHerd } from "../province-jahad-submit-herd/ProvicneJahadSubmitHerd";
|
||||
import { convertDaysToYMD } from "../../../../utils/formatTime";
|
||||
|
||||
export const ProvinceJahadHerds = () => {
|
||||
const dispatch = useDispatch();
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
const [value, setValue] = useState("0");
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`/LiveStock/live-stock/live-stock-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}&type=${
|
||||
value === "0" ? "pending" : "archive"
|
||||
}`
|
||||
);
|
||||
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
const handleChange = (event, newValue) => {
|
||||
setValue(newValue);
|
||||
};
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadGetHerdInfoDashboardService({
|
||||
search: textValue,
|
||||
type: value === "0" ? "pending" : "archive",
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.rancher?.fullname || "-",
|
||||
item?.rancher?.nationalId,
|
||||
item?.rancher?.mobile || "-",
|
||||
item?.rancher?.city || "-",
|
||||
item?.nationalIdLivestockCode || "-",
|
||||
item?.herdCode || "-",
|
||||
item?.type || "-",
|
||||
item?.birthDay || "-",
|
||||
item?.gender || "-",
|
||||
convertDaysToYMD(item?.age) || "-",
|
||||
item?.contractorCode || "-",
|
||||
item?.uniqueIdentifier || "-",
|
||||
item?.agent || "-",
|
||||
item?.registeringUser || "-",
|
||||
item?.registeringDate || "-",
|
||||
<ProvinceJahadHerdsOperations
|
||||
dataType={value === "0" ? "pending" : "archive"}
|
||||
key={i}
|
||||
item={item}
|
||||
getDashboardData={getDashboardData}
|
||||
updateTable={updateTable}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage, value]);
|
||||
|
||||
useEffect(() => {
|
||||
getDashboardData();
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/LiveStock/live-stock/live-stock-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=1&page_size=${perPage}&type=${
|
||||
value === "0" ? "pending" : "archive"
|
||||
}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
getDashboardData();
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Tabs value={value} onChange={handleChange}>
|
||||
<Tab value="0" label="فعال" />
|
||||
<Tab value="1" label="بایگانی شده" />
|
||||
</Tabs>
|
||||
</Grid>
|
||||
<Button
|
||||
variant="contained"
|
||||
// disabled
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ایجاد گله",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvicneJahadSubmitHerd
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ایجاد گله
|
||||
</Button>
|
||||
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}live-stock-herds-excel/?role=${getRoleFromUrl()}&key=${userKey}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
|
||||
<Grid container mt={2} mb={4} isDashboard xs={12}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={[
|
||||
"تعداد گله",
|
||||
"تعداد گوسفندان",
|
||||
"تعداد بزها ",
|
||||
"تعداد گاوها",
|
||||
"تعداد اسب ها ",
|
||||
"تعداد شترها",
|
||||
"تعداد دام سبک",
|
||||
"تعداد دام سنگین",
|
||||
"مجموع دام ها",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
dashboardData?.liveStocksCount?.toLocaleString(),
|
||||
dashboardData?.sheep?.toLocaleString(),
|
||||
dashboardData?.goat?.toLocaleString(),
|
||||
dashboardData?.cow?.toLocaleString(),
|
||||
dashboardData?.horse?.toLocaleString(),
|
||||
dashboardData?.camel?.toLocaleString(),
|
||||
dashboardData?.lightLivestock?.toLocaleString(),
|
||||
dashboardData?.heavyLivestock?.toLocaleString(),
|
||||
Math.round(
|
||||
dashboardData?.lightLivestock + dashboardData?.heavyLivestock
|
||||
)?.toLocaleString(),
|
||||
],
|
||||
]}
|
||||
title={"خلاصه اطلاعات"}
|
||||
/>
|
||||
</Grid>
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"دامدار",
|
||||
"کد ملی دامدار",
|
||||
"موبایل",
|
||||
"شهرستان",
|
||||
"کد ملی دام",
|
||||
"کد گله",
|
||||
"گونه",
|
||||
"تاریخ تولد",
|
||||
"جنسیت",
|
||||
"سن",
|
||||
"کد پیمانکار",
|
||||
"شناسه یکتای واحد کشاورزی",
|
||||
"مامور",
|
||||
"کاربر ثبت کننده",
|
||||
"تاریخ تکمیل فرم",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title="گله ها "
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { provinceJahadGetRancherDetailsService } from "../../services/province-jahad-get-rancher-details";
|
||||
|
||||
export const ProvinceJahadRancherDetails = ({ item }) => {
|
||||
const dispatch = useDispatch();
|
||||
const [tableData, setTableData] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(
|
||||
provinceJahadGetRancherDetailsService({ herd_code: item?.herdCode })
|
||||
).then((r) => {
|
||||
setTableData(r.payload.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center">
|
||||
<SimpleTable
|
||||
columns={[
|
||||
"تعداد دام سبک",
|
||||
"تعداد دام سنگین",
|
||||
"جمع کل گله",
|
||||
"گاو",
|
||||
"گوسفند",
|
||||
"بز",
|
||||
"شتر",
|
||||
"اسب",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
tableData?.lightLivestock,
|
||||
tableData?.heavyLivestock,
|
||||
Math.round(
|
||||
tableData?.lightLivestock + tableData?.heavyLivestock
|
||||
).toLocaleString(),
|
||||
tableData?.cow,
|
||||
tableData?.sheep,
|
||||
tableData?.goat,
|
||||
tableData?.camel,
|
||||
tableData?.horse,
|
||||
],
|
||||
]}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,272 @@
|
||||
import {
|
||||
Button,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
Popover,
|
||||
Switch,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { useContext, useState } from "react";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import {
|
||||
CLOSE_MODAL,
|
||||
DRAWER,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { useDispatch } from "react-redux";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { ProvinceJahadRancherDetails } from "../province-jahad-rancher-details/ProvinceJahadRancherDetails";
|
||||
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
|
||||
import { ProvinceJahadEditRancher } from "../province-jahad-edit-rancher/ProvinceJahadEditRancher";
|
||||
import { ProvicneJahadSubmitHerd } from "../province-jahad-submit-herd/ProvicneJahadSubmitHerd";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { ProvinceJahadSubmitDhi } from "../province-jahad-submit-dhi/ProvinceJahadSubmitDhi";
|
||||
import { provinceJahadEditRancher } from "../../services/province-jahad-rancher-activation";
|
||||
import { provinceJahadDeleteRancherService } from "../../services/province-jahad-unions-delete-rancher";
|
||||
|
||||
export const ProvinceJahadRancherOperations = ({
|
||||
item,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const dispatch = useDispatch();
|
||||
const [popoverOpen, setPopoverOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const openPopover = (event) => {
|
||||
setPopoverOpen(true);
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const closePopover = () => {
|
||||
setPopoverOpen(false);
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid>
|
||||
<IconButton variant="contained" color="primary" onClick={openPopover}>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
open={popoverOpen}
|
||||
anchorEl={anchorEl}
|
||||
onClose={closePopover}
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
>
|
||||
<div style={{ padding: 10 }}>
|
||||
<Grid
|
||||
container
|
||||
direction="column"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
gap={1}
|
||||
>
|
||||
<Tooltip title={"جزِئیات گله"} placement="left-start">
|
||||
<IconButton
|
||||
color="primary"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `جزئیات گله`,
|
||||
content: <ProvinceJahadRancherDetails item={item} />,
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<RemoveRedEyeIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title={"DHI"} placement="left-start">
|
||||
<Button
|
||||
variant="outlined"
|
||||
// disabled
|
||||
size="small"
|
||||
aria-label="delete"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "DHI",
|
||||
content: (
|
||||
<ProvinceJahadSubmitDhi
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
DHI
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title={"ایجاد گله"} placement="left-start">
|
||||
<IconButton
|
||||
// disabled
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ایجاد گله برای دامدار",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvicneJahadSubmitHerd
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
rancherKey={item?.key}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<AddIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title={"ویرایش دامدار"} placement="left-start">
|
||||
<IconButton
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
right: true,
|
||||
top: false,
|
||||
content: (
|
||||
<ProvinceJahadEditRancher
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
title: "ویرایش دامدار ",
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={item?.type === "industrial"}
|
||||
onChange={() => {
|
||||
dispatch(
|
||||
provinceJahadEditRancher({
|
||||
key: item?.key,
|
||||
type: item?.type === "rural" ? "industrial" : "rural",
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={item?.type === "rural" ? "روستایی" : "صنعتی"}
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
/>
|
||||
|
||||
<Tooltip title={"حذف"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="error"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "آیا مطمئن هستید؟",
|
||||
content: (
|
||||
<Grid container>
|
||||
<Button
|
||||
color="error"
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
provinceJahadDeleteRancherService(item?.key)
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
dispatch(CLOSE_MODAL());
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.data.result,
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
تایید
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(CLOSE_MODAL());
|
||||
}}
|
||||
>
|
||||
لغو
|
||||
</Button>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,257 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, TextField, Tooltip } from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { provinceJahadGetRancherInfoDashboardService } from "../../services/province-jahad-get-rancher-dashbored";
|
||||
import { ProvinceJahadRancherOperations } from "../province-jahad-rancher-operations/ProvinceJahadRancherOperations";
|
||||
import { ProvinceJahadEditRancher } from "../province-jahad-edit-rancher/ProvinceJahadEditRancher";
|
||||
|
||||
export const ProvinceJahadRanchers = () => {
|
||||
const dispatch = useDispatch();
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`/LiveStock/rancher/rancher-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadGetRancherInfoDashboardService({
|
||||
search: textValue,
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
};
|
||||
useEffect(() => {
|
||||
getDashboardData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.type === "rural" ? "روستایی" : "صنعتی",
|
||||
item?.name,
|
||||
item?.herdCode,
|
||||
item?.epidemiologicalCode,
|
||||
item?.postalCode,
|
||||
item?.unitId,
|
||||
item?.herdName,
|
||||
item?.nationalId,
|
||||
// item?.user?.fullname,
|
||||
item?.mobile,
|
||||
item?.contractorCode || "-",
|
||||
item?.city,
|
||||
item?.registeringUser || "-",
|
||||
item?.type === "rural" ? "-" : item?.dhiAmount?.toLocaleString(),
|
||||
<ProvinceJahadRancherOperations
|
||||
key={i}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
getDashboardData={getDashboardData}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/LiveStock/rancher/rancher-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(
|
||||
provinceJahadGetRancherInfoDashboardService({
|
||||
search: textValue,
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
right: true,
|
||||
top: false,
|
||||
content: <ProvinceJahadEditRancher updateTable={updateTable} />,
|
||||
title: "ایجاد دامدار",
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ایجاد دامدار
|
||||
</Button>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}live-stock-ranchers-excel/?role=${getRoleFromUrl()}&key=${userKey}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid container mt={2} mb={4} isDashboard xs={12}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={[
|
||||
"تعداد دامداران",
|
||||
"تعداد گوسفندان",
|
||||
"تعداد بزها ",
|
||||
"تعداد گاوها",
|
||||
"تعداد اسب ها ",
|
||||
"تعداد شترها",
|
||||
"تعداد دام سبک",
|
||||
"تعداد دام سنگین",
|
||||
"تعداد دام DHI",
|
||||
"مجموع دام ها",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
dashboardData?.rancherCount?.toLocaleString(),
|
||||
dashboardData?.sheep?.toLocaleString(),
|
||||
dashboardData?.goat?.toLocaleString(),
|
||||
dashboardData?.cow?.toLocaleString(),
|
||||
dashboardData?.horse?.toLocaleString(),
|
||||
dashboardData?.camel?.toLocaleString(),
|
||||
dashboardData?.lightLivestock?.toLocaleString(),
|
||||
dashboardData?.heavyLivestock?.toLocaleString(),
|
||||
dashboardData?.dhiAmount?.toLocaleString(),
|
||||
dashboardData?.liveStocksCount?.toLocaleString(),
|
||||
],
|
||||
]}
|
||||
title={"خلاصه اطلاعات"}
|
||||
/>
|
||||
</Grid>
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"مجوز فعالیت",
|
||||
"نام دامداری",
|
||||
"کد گله",
|
||||
"کد اپیدمیولوژیک",
|
||||
"کد پستی",
|
||||
"شناسه یکتا",
|
||||
"نام گله",
|
||||
"کد ملی دامدار",
|
||||
// "نام دامدار",
|
||||
"موبایل",
|
||||
"کد پیمانکار",
|
||||
"شهرستان",
|
||||
"کاربر ثبت کننده",
|
||||
// "دام سبک",
|
||||
// "دام سنگین",
|
||||
// "جمع کل گله",
|
||||
// "گاو",
|
||||
// "گوسفند",
|
||||
// "بز",
|
||||
// "شتر",
|
||||
// "اسب",
|
||||
"تعداد دام DHI",
|
||||
"جزئیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title=" دامداران "
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,338 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
TextField,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import moment from "moment";
|
||||
import { useDispatch } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import {
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
|
||||
import { formatTime } from "../../../../utils/formatTime";
|
||||
|
||||
export const ProvinceJahadSellReportTransactions = ({
|
||||
cooperative_key,
|
||||
product,
|
||||
}) => {
|
||||
const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] =
|
||||
useContext(AppContext);
|
||||
const [withDate, setWithDate] = useState(false);
|
||||
|
||||
const [transactionType, setTransactionType] = useState("all");
|
||||
|
||||
const handleChange = (event) => {
|
||||
setTransactionType(event.target.value);
|
||||
};
|
||||
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
const currentDate = moment(new Date()).format("YYYY-MM-DD");
|
||||
setSelectedDate1(currentDate);
|
||||
setSelectedDate2(currentDate);
|
||||
}, []);
|
||||
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`live-stock-transactions/?search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${page}&page_size=${perPage}&cooperative_key=${cooperative_key}&state=${transactionType}&name=${
|
||||
product?.key
|
||||
}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// const updateTable = () => {
|
||||
// fetchApiData(page !== 0 ? page : 1);
|
||||
// };
|
||||
|
||||
const convertToJson = (data) => {
|
||||
if (data) {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
const products = item?.products?.map((option, index) => {
|
||||
return [
|
||||
index + 1,
|
||||
option?.name,
|
||||
option?.curWeight?.toLocaleString(),
|
||||
option?.price?.toLocaleString(),
|
||||
option?.curPrice?.toLocaleString(),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
formatTime(item?.date),
|
||||
item?.fullname || "-",
|
||||
item?.natcode || "-",
|
||||
item?.mobile || "-",
|
||||
`${item?.pos?.cooperative?.name} شهرستان ${item?.pos?.cooperative?.user?.cityName} (${item?.pos?.cooperative?.user?.fullname})`,
|
||||
item?.pos?.cooperative?.user?.mobile,
|
||||
item?.paid ? "پرداخت شده" : `پرداخت نشده (${item?.result})`,
|
||||
convertToJson(item?.additional).isTaavoni ? "تعاونی" : "کارخانه",
|
||||
item?.products
|
||||
? item?.products.map((option) => option.name).join("-")
|
||||
: "-",
|
||||
convertToJson(item?.additional)?.ownerNatcode?.toLocaleString() || 0,
|
||||
convertToJson(item?.additional)?.cur_heavy?.toLocaleString() || 0,
|
||||
convertToJson(item?.additional)?.cur_light?.toLocaleString() || 0,
|
||||
item?.products
|
||||
.reduce(
|
||||
(accumulator, currentValue) =>
|
||||
accumulator + currentValue?.curWeight,
|
||||
0
|
||||
)
|
||||
.toLocaleString(),
|
||||
item?.price?.toLocaleString(),
|
||||
convertToJson(item?.additional)?.cooperative_price?.toLocaleString() ||
|
||||
0,
|
||||
convertToJson(item?.additional)?.union_price?.toLocaleString() || 0,
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
key={i}
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "جزئیات محصول",
|
||||
content: (
|
||||
<Grid container xs={12} justifyContent="center">
|
||||
<SimpleTable
|
||||
columns={["ردیف", "محصول", "وزن", "فی", "قیمت کل"]}
|
||||
data={products}
|
||||
/>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
مشاهده
|
||||
</Button>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [
|
||||
dispatch,
|
||||
selectedDate1,
|
||||
selectedDate2,
|
||||
perPage,
|
||||
withDate,
|
||||
transactionType,
|
||||
]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`live-stock-transactions/?search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${1}&page_size=${perPage}&cooperative_key=${cooperative_key}&state=${transactionType}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid width="200px">
|
||||
<FormControl size="small">
|
||||
<InputLabel id="demo-simple-select-label">فیلتر تراکنش</InputLabel>
|
||||
<Select
|
||||
labelId="demo-simple-select-label"
|
||||
id="demo-simple-select"
|
||||
value={transactionType}
|
||||
label="Age"
|
||||
onChange={handleChange}
|
||||
>
|
||||
<MenuItem value={"all"}>همه</MenuItem>
|
||||
<MenuItem value={"paid"}>تراکنش های موفق</MenuItem>
|
||||
<MenuItem value={"unpaid"}>تراکنش های ناموفق</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
container
|
||||
style={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "1px",
|
||||
padding: "10px",
|
||||
borderRadius: "15px",
|
||||
borderColor: "gray",
|
||||
justifyContent: "left",
|
||||
}}
|
||||
>
|
||||
<Grid>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={withDate}
|
||||
onChange={() => setWithDate(!withDate)}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="از تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate1}
|
||||
onChange={(e) => {
|
||||
setSelectedDate1(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="تا تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate2}
|
||||
onChange={(e) => {
|
||||
setSelectedDate2(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a href={`${axios.defaults.baseURL}`} rel="noreferrer">
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
ignoreTextsLength
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"تاریخ",
|
||||
"خریدار",
|
||||
"کد ملی خریدار",
|
||||
"موبایل خریدار",
|
||||
"فروشنده",
|
||||
"تلفن فروشنده",
|
||||
"وضعیت",
|
||||
"محل تحویل",
|
||||
"کالا",
|
||||
"کد ملی فروشنده",
|
||||
"دام سنگین",
|
||||
"دام سبک",
|
||||
"وزن (کیلوگرم)",
|
||||
"مبلغ تراکنش",
|
||||
"سهم تعاونی",
|
||||
"سهم اتحادیه",
|
||||
"جزئیات محصولات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title={`تراکنش های ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,372 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
IconButton,
|
||||
TextField,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import moment from "moment";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { ProvinceJahadSellReportTransactions } from "../province-jahad-sell-report-transactions/ProvinceJahadSellReportTransactions";
|
||||
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
|
||||
|
||||
import ToggleOffOutlinedIcon from "@mui/icons-material/ToggleOffOutlined";
|
||||
import ToggleOnIcon from "@mui/icons-material/ToggleOn";
|
||||
import { provinceJahadSellReportInfoDashboardService } from "../../services/province-get-jahad-sell-report-dashboard";
|
||||
|
||||
export const ProvinceJahadSellReport = ({ product }) => {
|
||||
const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] =
|
||||
useContext(AppContext);
|
||||
const [withDate, setWithDate] = useState(false);
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
const currentDate = moment(new Date()).format("YYYY-MM-DD");
|
||||
setSelectedDate1(currentDate);
|
||||
setSelectedDate2(currentDate);
|
||||
}, []);
|
||||
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadSellReportInfoDashboardService({
|
||||
date1: selectedDate1,
|
||||
date2: selectedDate2,
|
||||
search: "filter",
|
||||
role: getRoleFromUrl(),
|
||||
value: textValue,
|
||||
name: product?.key,
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
};
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`cooperative-warehouse/?search=filter&value=${textValue}&role=${getRoleFromUrl()}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${page}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
getDashboardData();
|
||||
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// const updateTable = () => {
|
||||
// fetchApiData(page !== 0 ? page : 1);
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
product?.label,
|
||||
item?.name,
|
||||
item?.user?.fullname,
|
||||
item?.user?.provinceName,
|
||||
item?.user?.cityName,
|
||||
item?.user?.mobile,
|
||||
item?.user?.nationalId,
|
||||
item?.info?.totalReceiptWeight?.toLocaleString() || 0,
|
||||
item?.info?.totalWeight?.toLocaleString() || 0,
|
||||
item?.info?.totalAllocatedWeight?.toLocaleString() || 0,
|
||||
item?.info?.totalRemainWeight?.toLocaleString() || 0,
|
||||
item?.info?.transactions?.toLocaleString() || 0,
|
||||
item?.info?.totalTransactionsPrice?.toLocaleString() || 0,
|
||||
item?.info?.totalTransactionsWeight?.toLocaleString() || 0,
|
||||
<Grid key={i} container gap={1} alignItems="center" direction="column">
|
||||
<Tooltip title="جزئیات" placement="left">
|
||||
<IconButton
|
||||
key={i}
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
top: true,
|
||||
title: "تراکنش ها",
|
||||
content: (
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<Grid
|
||||
container
|
||||
xs={10}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<ProvinceJahadSellReportTransactions
|
||||
cooperative_key={item?.key}
|
||||
product={product}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<RemoveRedEyeIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${axios.defaults.baseURL}LiveStock/jahad/live_stock_transaction_excel/?search=filter&value=${textValue}&key=${userKey}&cooperative_key=${item?.key}&name=${product?.key}`}
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={24} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, selectedDate1, selectedDate2, perPage, withDate]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`cooperative-warehouse/?role=${getRoleFromUrl()}&search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${1}&page_size=${perPage}&name=${product?.key}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
getDashboardData();
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid
|
||||
container
|
||||
gap={1}
|
||||
style={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "1px",
|
||||
padding: "5px",
|
||||
borderRadius: "15px",
|
||||
borderColor: "gray",
|
||||
justifyContent: "left",
|
||||
}}
|
||||
alignItems="center"
|
||||
>
|
||||
<Checkbox
|
||||
icon={<ToggleOffOutlinedIcon />}
|
||||
checkedIcon={<ToggleOnIcon />}
|
||||
checked={withDate}
|
||||
onChange={() => setWithDate(!withDate)}
|
||||
color="primary"
|
||||
size="large"
|
||||
/>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="از تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate1}
|
||||
onChange={(e) => {
|
||||
setSelectedDate1(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="تا تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate2}
|
||||
onChange={(e) => {
|
||||
setSelectedDate2(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}LiveStock/jahad/cooperative_warehouse_excel/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&key=${userKey}&name=${
|
||||
product?.key
|
||||
}`}
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title="خروجی اکسل تراکنش مشکوک">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}LiveStock/jahad/rancher_management/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&key=${userKey}&name=${
|
||||
product?.key
|
||||
}`}
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<Button color="error">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid container mt={2} mb={4} isDashboard gap={2}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={[
|
||||
"محصول",
|
||||
"تعداد کل تراکنش ها",
|
||||
"وزن کل تراکنش ها",
|
||||
"مبلغ کل تراکنش ها",
|
||||
"کل وزن ورود به انبار",
|
||||
"کل وزن دریافتی",
|
||||
"کل وزن تخصیص داده شده",
|
||||
"کل وزن باقی مانده",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
product?.label,
|
||||
dashboardData?.transactions?.toLocaleString(),
|
||||
dashboardData?.totalTransactionsWeight?.toLocaleString(),
|
||||
dashboardData?.totalTransactionsPrice?.toLocaleString(),
|
||||
dashboardData?.totalWeight?.toLocaleString(),
|
||||
dashboardData?.totalReceiptWeight?.toLocaleString(),
|
||||
dashboardData?.totalAllocatedWeight?.toLocaleString(),
|
||||
dashboardData?.totalRemainWeight?.toLocaleString(),
|
||||
],
|
||||
]}
|
||||
title={"خلاصه اطلاعات"}
|
||||
/>
|
||||
</Grid>
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"محصول",
|
||||
"نام تعاونی",
|
||||
"کاربر",
|
||||
"استان",
|
||||
"شهر",
|
||||
"موبایل",
|
||||
"کد ملی",
|
||||
"سهمیه دریافتی",
|
||||
"وزن تحویلی",
|
||||
"وزن فروش رفته",
|
||||
"مانده انبار",
|
||||
"تعداد تراکنش ها",
|
||||
"جمع کل تراکنش ها",
|
||||
"وزن کل تراکنش ها",
|
||||
"جزئیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title="گزارش فروش تعاونی ها"
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
import { IconButton, Popover, Tooltip } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
// import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
|
||||
import { ProvinceJahadEditShare } from "../province-jahad-edit-share/ProvinceJahadEditShare";
|
||||
|
||||
export const ProvinceJahadSharesOperations = ({ item, updateTable }) => {
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const dispatch = useDispatch();
|
||||
const handleClick = (event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const open = Boolean(anchorEl);
|
||||
const id = open ? "popover" : undefined;
|
||||
|
||||
return (
|
||||
<Grid container>
|
||||
<IconButton
|
||||
aria-describedby={id}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
id={id}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<div
|
||||
style={{ padding: "20px", display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Tooltip title={"ویرایش"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
title: "ویرایش اطلاعات ",
|
||||
right: !(window.innerWidth <= 600),
|
||||
bottom: window.innerWidth <= 600,
|
||||
content: (
|
||||
<ProvinceJahadEditShare
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
{/* <Tooltip title={"حذف "} placement="left-start">
|
||||
<IconButton aria-label="delete" color="error">
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip> */}
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,152 @@
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, TextField } from "@mui/material";
|
||||
import { useDispatch } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { ProvinceJahadSharesOperations } from "../province-jahad-share-operations/ProvinceJahadSharesOperations";
|
||||
|
||||
export const ProvinceJahadShares = ({ product }) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`LiveStock/jahad/cooperative-shares/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}&name=${
|
||||
product?.label
|
||||
}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
`${item?.cooperative?.name} (${item?.cooperative?.user?.fullname})`,
|
||||
item?.price?.toLocaleString(),
|
||||
item?.unionPrice?.toLocaleString(),
|
||||
item?.cooperativePrice?.toLocaleString(),
|
||||
item?.companyPrice?.toLocaleString(),
|
||||
item?.shippingPrice?.toLocaleString(),
|
||||
<ProvinceJahadSharesOperations
|
||||
key={i}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`LiveStock/jahad/cooperative-shares/?role=${getRoleFromUrl()}&search=filter&value=${textValue}&page=${1}&page_size=${perPage}&name=${
|
||||
product?.label
|
||||
}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
data={tableData}
|
||||
ignoreTextsLength
|
||||
columns={[
|
||||
"ردیف",
|
||||
"تعاونی",
|
||||
"قیمت پایه",
|
||||
"سهم اتحادیه",
|
||||
"سهم تعاونی",
|
||||
"سهم شرکت",
|
||||
"هزینه حمل و نقل",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title={`سهم بندی ${product?.label}`}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,301 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import {
|
||||
RadioGroup,
|
||||
FormControlLabel,
|
||||
Radio,
|
||||
FormControl,
|
||||
Button,
|
||||
Typography,
|
||||
Autocomplete,
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { NumberInput } from "../../../../components/number-format-custom/NumberFormatCustom";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { provinceJahadSubmitAllocationGetUsers } from "../../services/province-jahad-submit-allocation-get-users";
|
||||
import {
|
||||
provinceJahadEditAllocationService,
|
||||
provinceJahadSubmitAllocationService,
|
||||
} from "../../services/province-jahad-submit-allocation";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { CLOSE_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const ProvinceJahadSubmitAllocation = ({
|
||||
type,
|
||||
productKey,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
item,
|
||||
// getRemainWeight,
|
||||
maxAllow,
|
||||
}) => {
|
||||
const validationSchema = Yup.object({
|
||||
allocationType: Yup.string().required("لطفا یک گزینه را انتخاب کنید"),
|
||||
weight: Yup.number()
|
||||
.required("این فیلد اجباریست!")
|
||||
.positive("عدد مثبت وارد کنید!"),
|
||||
place: Yup.string().required("این فیلد اجباریست!"),
|
||||
description: Yup.string(),
|
||||
});
|
||||
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
allocationType:
|
||||
type === "charge" ? "LiveStockProvinceJahad" : "Cooperative",
|
||||
buyer_key: null,
|
||||
weight: item?.weight || "",
|
||||
place: item?.place || "",
|
||||
description: item?.description || "",
|
||||
},
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
if (item) {
|
||||
let req = {
|
||||
allocation_key: item?.key,
|
||||
weight: values.weight,
|
||||
place: values.place,
|
||||
description: values.description,
|
||||
};
|
||||
|
||||
req = Object.fromEntries(
|
||||
Object.entries(req).filter(([_, value]) => value !== null)
|
||||
);
|
||||
|
||||
dispatch(provinceJahadEditAllocationService(req)).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(CLOSE_MODAL());
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
let req = {
|
||||
allocator: getRoleFromUrl(),
|
||||
receiver:
|
||||
getRoleFromUrl() === "Cooperative"
|
||||
? "Cooperative"
|
||||
: values.allocationType,
|
||||
product_key: productKey,
|
||||
buyer_key: values.buyer_key,
|
||||
weight: values.weight,
|
||||
place: values.place,
|
||||
description: values.description,
|
||||
};
|
||||
|
||||
req = Object.fromEntries(
|
||||
Object.entries(req).filter(([_, value]) => value !== null)
|
||||
);
|
||||
|
||||
if (maxAllow && values.weight > maxAllow) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "مقدار وارد شده از سهیه دریافتی بیشتر است!",
|
||||
severity: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(provinceJahadSubmitAllocationService(req)).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(CLOSE_MODAL());
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (type !== "charge" && !item) {
|
||||
formik.setFieldValue("buyer_key", null);
|
||||
dispatch(
|
||||
provinceJahadSubmitAllocationGetUsers({
|
||||
type: formik.values.allocationType,
|
||||
})
|
||||
).then((r) => {
|
||||
setUsers(r.payload.data);
|
||||
});
|
||||
}
|
||||
}, [formik.values.allocationType]);
|
||||
|
||||
useEffect(() => {
|
||||
formik.validateForm();
|
||||
}, []);
|
||||
|
||||
const isFormValid = () => {
|
||||
if (type === "charge") {
|
||||
return formik.isValid;
|
||||
} else if (item) {
|
||||
return (
|
||||
formik.values.weight && formik.values.place && formik.values.description
|
||||
);
|
||||
} else {
|
||||
return formik.isValid && formik.values.buyer_key;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
{type !== "charge" &&
|
||||
!item &&
|
||||
getRoleFromUrl() === "LiveStockProvinceJahad" && (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center">
|
||||
<FormControl component="fieldset">
|
||||
<RadioGroup
|
||||
row
|
||||
name="allocationType"
|
||||
value={formik.values.allocationType}
|
||||
onChange={formik.handleChange}
|
||||
>
|
||||
<FormControlLabel
|
||||
value="Cooperative"
|
||||
control={<Radio />}
|
||||
label="تخصیص به تعاونی"
|
||||
/>
|
||||
<FormControlLabel
|
||||
value="Union"
|
||||
control={<Radio />}
|
||||
label="تخصیص به اتحادیه"
|
||||
/>
|
||||
</RadioGroup>
|
||||
{formik.touched.allocationType &&
|
||||
formik.errors.allocationType && (
|
||||
<Typography color="error">
|
||||
{formik.errors.allocationType}
|
||||
</Typography>
|
||||
)}
|
||||
</FormControl>
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
<Grid item xs={12}>
|
||||
<NumberInput
|
||||
allowLeadingZeros
|
||||
thousandSeparator=","
|
||||
fullWidth
|
||||
id="weight"
|
||||
label="وزن"
|
||||
variant="outlined"
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
value={formik.values.weight}
|
||||
error={formik.touched.weight ? Boolean(formik.errors.weight) : null}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.weight && Boolean(formik.errors.weight)
|
||||
? formik.errors.weight
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
{type !== "charge" && !item && (
|
||||
<Grid xs={12} container>
|
||||
<Autocomplete
|
||||
fullWidth
|
||||
style={{ minWidth: 210 }}
|
||||
disablePortal
|
||||
id="hatching"
|
||||
options={
|
||||
users
|
||||
? users.map((i) => {
|
||||
return {
|
||||
data: i,
|
||||
label: `${i?.name}`,
|
||||
};
|
||||
})
|
||||
: []
|
||||
}
|
||||
onChange={(event, value) => {
|
||||
formik.setFieldValue("buyer_key", value?.data?.key);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField fullWidth {...params} label="انتخاب تخصیص گیرنده" />
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
<TextField
|
||||
id="place"
|
||||
label={type === "charge" ? "مبدا" : "مکان دریافت "}
|
||||
variant="outlined"
|
||||
sx={{ width: "100%", height: "100%" }}
|
||||
value={formik.values.place}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.place ? Boolean(formik.errors.place) : null}
|
||||
helperText={
|
||||
formik.touched.place && Boolean(formik.errors.place)
|
||||
? formik.errors.place
|
||||
: null
|
||||
}
|
||||
/>
|
||||
<TextField
|
||||
id="description"
|
||||
label="توضیحات"
|
||||
variant="outlined"
|
||||
sx={{ width: "100%", height: "100%" }}
|
||||
value={formik.values.description}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.description ? Boolean(formik.errors.description) : null
|
||||
}
|
||||
helperText={
|
||||
formik.touched.description && Boolean(formik.errors.description)
|
||||
? formik.errors.description
|
||||
: null
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
disabled={!isFormValid()}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
{item ? "ویرایش" : "ثبت"}
|
||||
</Button>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
import React, { useContext } from "react";
|
||||
import { TextField, Button, Typography } from "@mui/material";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadEditRancher } from "../../services/province-jahad-rancher-activation";
|
||||
import { CLOSE_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
amount: Yup.number()
|
||||
.required("تعداد الزامی است")
|
||||
.integer("تعداد باید یک عدد صحیح باشد"),
|
||||
});
|
||||
|
||||
export const ProvinceJahadSubmitDhi = ({
|
||||
updateTable,
|
||||
item,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const dispatch = useDispatch();
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
amount: item?.dhiAmount || "",
|
||||
},
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
dispatch(
|
||||
provinceJahadEditRancher({
|
||||
key: item?.key,
|
||||
dhi_amount: values.amount,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(CLOSE_MODAL());
|
||||
getDashboardData();
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center">
|
||||
<Typography variant="body2" color="error">
|
||||
در صورت وارد کردن مقدار 0 دامدار از پروژه DHI خارج میشود.
|
||||
</Typography>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="amount"
|
||||
name="amount"
|
||||
label="تعداد دام DHI"
|
||||
variant="outlined"
|
||||
margin="normal"
|
||||
value={formik.values.amount}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.amount && Boolean(formik.errors.amount)}
|
||||
helperText={formik.touched.amount && formik.errors.amount}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
ثبت
|
||||
</Button>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,338 @@
|
||||
import React, { useContext, useState } from "react";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import {
|
||||
TextField,
|
||||
FormControlLabel,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Button,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
IconButton,
|
||||
FormHelperText,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { useDispatch } from "react-redux";
|
||||
import {
|
||||
provinceJahadEditHerdService,
|
||||
provinceJahadSubmitHerdService,
|
||||
} from "../../services/province-jahad-submit-herd";
|
||||
import { DRAWER } from "../../../../lib/redux/slices/appSlice";
|
||||
import SearchIcon from "@mui/icons-material/Search";
|
||||
import { provinceJahadGetSingleRancherService } from "../../services/province-jahad-get-single-rancher";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
|
||||
export const ProvicneJahadSubmitHerd = ({
|
||||
item,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
rancherKey,
|
||||
}) => {
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const dispatch = useDispatch();
|
||||
const [searchedRancherKey, setSearchedRancherKey] = useState(null);
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
herd_code: item?.herdCode || "",
|
||||
type: item?.type || "",
|
||||
contractor_code: item?.contractorCode || "",
|
||||
agent: item?.agent || "",
|
||||
unique_identifier: item?.uniqueIdentifier || "",
|
||||
gender: item?.gender || "نر",
|
||||
userInfoCheck: null,
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
...(item && {
|
||||
herd_code: Yup.string().required("این فیلد اجباریست!"),
|
||||
contractor_code: Yup.string().required("این فیلد اجباریست!"),
|
||||
}),
|
||||
type: Yup.string().required("این فیلد اجباریست!"),
|
||||
agent: Yup.string().required("این فیلد اجباریست!"),
|
||||
unique_identifier: Yup.string().required("این فیلد اجباریست!"),
|
||||
gender: Yup.string().required("این فیلد اجباریست!"),
|
||||
}),
|
||||
onSubmit: (values) => {
|
||||
if (item) {
|
||||
dispatch(
|
||||
provinceJahadEditHerdService({
|
||||
live_stock_key: item?.key,
|
||||
unique_identifier: values.unique_identifier,
|
||||
agent: values.agent,
|
||||
contractor_code: values.contractor_code,
|
||||
gender: values.gender,
|
||||
type: values.type,
|
||||
herd_code: values.herd_code,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
provinceJahadSubmitHerdService({
|
||||
unique_identifier: values.unique_identifier,
|
||||
agent: values.agent,
|
||||
gender: values.gender,
|
||||
type: values.type,
|
||||
rancher_key: rancherKey || searchedRancherKey?.key,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{!rancherKey && !searchedRancherKey ? (
|
||||
<Grid>
|
||||
<Typography>جستجو کاربر</Typography>
|
||||
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="userInfoCheck"
|
||||
label="شماره موبایل، کد گله یا کد ملی دامدار"
|
||||
variant="outlined"
|
||||
value={formik.values.userInfoCheck}
|
||||
error={
|
||||
formik.touched.userInfoCheck
|
||||
? Boolean(formik.errors.userInfoCheck)
|
||||
: null
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
helperText={
|
||||
formik.touched.userInfoCheck &&
|
||||
Boolean(formik.errors.userInfoCheck)
|
||||
? formik.errors.userInfoCheck
|
||||
: null
|
||||
}
|
||||
/>
|
||||
|
||||
<IconButton
|
||||
disabled={!formik.values.userInfoCheck}
|
||||
aria-label="delete"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
provinceJahadGetSingleRancherService({
|
||||
value: formik.values.userInfoCheck,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "کاربر یافت نشد",
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
setSearchedRancherKey(r.payload.data);
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
<FormHelperText>
|
||||
شماره موبایل، کد گله یا کد ملی دامدار را وارد کنید
|
||||
</FormHelperText>
|
||||
</Grid>
|
||||
) : (
|
||||
<Grid
|
||||
container
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
direction="column"
|
||||
gap={2}
|
||||
>
|
||||
{searchedRancherKey && (
|
||||
<Grid
|
||||
container
|
||||
p={2}
|
||||
direction="column"
|
||||
gap={1}
|
||||
xs={12}
|
||||
style={{
|
||||
border: "1px solid #d9d9d9",
|
||||
borderRadius: "10px",
|
||||
padding: "20px",
|
||||
backgroundColor: "#f0f0f0",
|
||||
}}
|
||||
>
|
||||
<Grid container gap={1} xs={12}>
|
||||
<Typography variant="body">نام دامدای:</Typography>
|
||||
<Typography variant="body2" color="primary">
|
||||
{searchedRancherKey?.name}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid container gap={1} xs={12}>
|
||||
<Typography variant="body">کد گله:</Typography>
|
||||
<Typography variant="body2" color="primary">
|
||||
{searchedRancherKey?.herdCode}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid container gap={1} xs={12}>
|
||||
<Typography variant="body">کد اپیدمیولوژیک:</Typography>
|
||||
<Typography variant="body2" color="primary">
|
||||
{searchedRancherKey?.epidemiologicalCode}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid container gap={1} xs={12}>
|
||||
<Typography variant="body">نام گله:</Typography>
|
||||
<Typography variant="body2" color="primary">
|
||||
{searchedRancherKey?.herdName}
|
||||
</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
{item && (
|
||||
<TextField
|
||||
fullWidth
|
||||
id="herd_code"
|
||||
name="herd_code"
|
||||
label="کد گله"
|
||||
value={formik.values.herd_code}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.herd_code && Boolean(formik.errors.herd_code)
|
||||
}
|
||||
helperText={formik.touched.herd_code && formik.errors.herd_code}
|
||||
/>
|
||||
)}
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
id="type"
|
||||
name="type"
|
||||
label="نوع"
|
||||
value={formik.values.type}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.type && Boolean(formik.errors.type)}
|
||||
helperText={formik.touched.type && formik.errors.type}
|
||||
/>
|
||||
|
||||
{item && (
|
||||
<TextField
|
||||
fullWidth
|
||||
id="contractor_code"
|
||||
name="contractor_code"
|
||||
label="کد پیمانکار"
|
||||
value={formik.values.contractor_code}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.contractor_code &&
|
||||
Boolean(formik.errors.contractor_code)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.contractor_code && formik.errors.contractor_code
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
id="agent"
|
||||
name="agent"
|
||||
label="مامور"
|
||||
value={formik.values.agent}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.agent && Boolean(formik.errors.agent)}
|
||||
helperText={formik.touched.agent && formik.errors.agent}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
fullWidth
|
||||
id="unique_identifier"
|
||||
name="unique_identifier"
|
||||
label="شناسه یکتا دام"
|
||||
value={formik.values.unique_identifier}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.unique_identifier &&
|
||||
Boolean(formik.errors.unique_identifier)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.unique_identifier &&
|
||||
formik.errors.unique_identifier
|
||||
}
|
||||
/>
|
||||
|
||||
<FormControl component="fieldset">
|
||||
<FormLabel component="legend">جنسیت</FormLabel>
|
||||
<RadioGroup
|
||||
row
|
||||
id="gender"
|
||||
name="gender"
|
||||
value={formik.values.gender}
|
||||
onChange={formik.handleChange}
|
||||
>
|
||||
<FormControlLabel value="نر" control={<Radio />} label="نر" />
|
||||
<FormControlLabel value="ماده" control={<Radio />} label="ماده" />
|
||||
</RadioGroup>
|
||||
{formik.touched.gender && formik.errors.gender && (
|
||||
<div style={{ color: "red" }}>{formik.errors.gender}</div>
|
||||
)}
|
||||
</FormControl>
|
||||
|
||||
<Button
|
||||
disabled={!formik.isValid}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
ثبت
|
||||
</Button>
|
||||
</Grid>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,422 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
FormControl,
|
||||
IconButton,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
TextField,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import moment from "moment";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import axios from "axios";
|
||||
import { RiFileExcel2Fill, RiSearchLine } from "react-icons/ri";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import {
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
|
||||
import { formatTime } from "../../../../utils/formatTime";
|
||||
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
|
||||
import ToggleOffOutlinedIcon from "@mui/icons-material/ToggleOffOutlined";
|
||||
import ToggleOnIcon from "@mui/icons-material/ToggleOn";
|
||||
import { provinceJahadGetTransactionInfoDashboardService } from "../../services/province-jahad-get-transaction-dashboard";
|
||||
|
||||
export const ProvinceJahadTransactions = ({ product }) => {
|
||||
const [, , selectedDate1, setSelectedDate1, selectedDate2, setSelectedDate2] =
|
||||
useContext(AppContext);
|
||||
const userKey = useSelector((state) => state.userSlice.userProfile.key);
|
||||
const [dashboardData, setDashboardData] = useState([]);
|
||||
const [transactionType, setTransactionType] = useState("all");
|
||||
const [productType, setProductType] = useState("bran");
|
||||
|
||||
const handleChange = (event) => {
|
||||
setTransactionType(event.target.value);
|
||||
};
|
||||
const handleChangeProduct = (event) => {
|
||||
setProductType(event.target.value);
|
||||
};
|
||||
|
||||
const dispatch = useDispatch();
|
||||
useEffect(() => {
|
||||
const currentDate = moment(new Date()).format("YYYY-MM-DD");
|
||||
setSelectedDate1(currentDate);
|
||||
setSelectedDate2(currentDate);
|
||||
}, []);
|
||||
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [withDate, setWithDate] = useState(false);
|
||||
|
||||
const getDashboardData = () => {
|
||||
dispatch(
|
||||
provinceJahadGetTransactionInfoDashboardService({
|
||||
date1: withDate ? selectedDate1 : "",
|
||||
date2: withDate ? selectedDate2 : "",
|
||||
search: "filter",
|
||||
role: getRoleFromUrl(),
|
||||
value: textValue,
|
||||
name: productType || product?.key,
|
||||
state: transactionType,
|
||||
})
|
||||
).then((r) => {
|
||||
setDashboardData(r.payload.data);
|
||||
});
|
||||
};
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`live-stock-transactions/?search=filter&value=${textValue}&role=${getRoleFromUrl()}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${page}&page_size=${perPage}&state=${transactionType}&name=${productType}`
|
||||
);
|
||||
getDashboardData();
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// const updateTable = () => {
|
||||
// fetchApiData(page !== 0 ? page : 1);
|
||||
// };
|
||||
|
||||
const convertToJson = (data) => {
|
||||
if (data) {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
const products = item?.products?.map((option, index) => {
|
||||
return [
|
||||
index + 1,
|
||||
option?.name,
|
||||
option?.curWeight?.toLocaleString(),
|
||||
option?.price?.toLocaleString(),
|
||||
option?.curPrice?.toLocaleString(),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
formatTime(item?.date),
|
||||
item?.fullname || "-",
|
||||
item?.natcode || "-",
|
||||
item?.mobile || "-",
|
||||
`${item?.pos?.cooperative?.name} شهرستان ${item?.pos?.cooperative?.user?.cityName} (${item?.pos?.cooperative?.user?.fullname})`,
|
||||
item?.pos?.cooperative?.user?.mobile,
|
||||
item?.paid ? "پرداخت شده" : `پرداخت نشده (${item?.result})`,
|
||||
convertToJson(item?.additional).isTaavoni ? "تعاونی" : "کارخانه",
|
||||
item?.products
|
||||
? item?.products.map((option) => option.name).join("-")
|
||||
: "-",
|
||||
convertToJson(item?.additional)?.ownerNatcode?.toLocaleString() || 0,
|
||||
|
||||
item?.shares?.curHeavy?.toLocaleString() || 0,
|
||||
item?.shares?.curLight?.toLocaleString() || 0,
|
||||
item?.shares?.curWeight?.toLocaleString() || 0,
|
||||
// item?.products
|
||||
// .reduce(
|
||||
// (accumulator, currentValue) =>
|
||||
// accumulator + currentValue?.curWeight,
|
||||
// 0
|
||||
// )
|
||||
// .toLocaleString(),
|
||||
item?.price?.toLocaleString(),
|
||||
convertToJson(item?.additional)?.cooperative_price?.toLocaleString() ||
|
||||
0,
|
||||
item?.shares?.totalUnionPrice?.toLocaleString() || 0,
|
||||
item?.shares?.totalCompanyPrice?.toLocaleString() || 0,
|
||||
|
||||
<Tooltip key={i} placement="left" title="مشاهده">
|
||||
<IconButton
|
||||
size="small"
|
||||
color="primary"
|
||||
key={i}
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "جزئیات محصول",
|
||||
content: (
|
||||
<Grid container xs={12} justifyContent="center">
|
||||
<SimpleTable
|
||||
columns={["ردیف", "محصول", "وزن", "فی", "قیمت کل"]}
|
||||
data={products}
|
||||
/>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<RemoveRedEyeIcon />
|
||||
</IconButton>
|
||||
</Tooltip>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [
|
||||
dispatch,
|
||||
selectedDate1,
|
||||
selectedDate2,
|
||||
perPage,
|
||||
transactionType,
|
||||
withDate,
|
||||
productType,
|
||||
]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`live-stock-transactions/?role=${getRoleFromUrl()}&search=filter&value=${textValue}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}&page=${1}&page_size=${perPage}&state=${transactionType}&name=${productType}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
getDashboardData();
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Grid width="200px">
|
||||
<FormControl size="small">
|
||||
<InputLabel id="demo-simple-select-label">انتخاب محصول</InputLabel>
|
||||
<Select
|
||||
labelId="demo-simple-select-label"
|
||||
id="demo-simple-select"
|
||||
value={productType}
|
||||
label="Age"
|
||||
onChange={handleChangeProduct}
|
||||
>
|
||||
<MenuItem value={"bran"}>سبوس</MenuItem>
|
||||
<MenuItem value={"barley"}>جو</MenuItem>
|
||||
<MenuItem value={"soy"}>سویا</MenuItem>
|
||||
<MenuItem value={"corn"}>ذرت</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid width="200px">
|
||||
<FormControl size="small">
|
||||
<InputLabel id="demo-simple-select-label">فیلتر تراکنش</InputLabel>
|
||||
<Select
|
||||
labelId="demo-simple-select-label"
|
||||
id="demo-simple-select"
|
||||
value={transactionType}
|
||||
label="Age"
|
||||
onChange={handleChange}
|
||||
>
|
||||
<MenuItem value={"all"}>همه</MenuItem>
|
||||
<MenuItem value={"paid"}>تراکنش های موفق</MenuItem>
|
||||
<MenuItem value={"unpaid"}>تراکنش های ناموفق</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid
|
||||
container
|
||||
gap={1}
|
||||
style={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "1px",
|
||||
padding: "5px",
|
||||
borderRadius: "15px",
|
||||
borderColor: "gray",
|
||||
justifyContent: "left",
|
||||
}}
|
||||
alignItems="center"
|
||||
>
|
||||
<Checkbox
|
||||
icon={<ToggleOffOutlinedIcon />}
|
||||
checkedIcon={<ToggleOnIcon />}
|
||||
checked={withDate}
|
||||
onChange={() => setWithDate(!withDate)}
|
||||
color="primary"
|
||||
size="large"
|
||||
/>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="از تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate1}
|
||||
onChange={(e) => {
|
||||
setSelectedDate1(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<DatePicker
|
||||
disabled={!withDate}
|
||||
label="تا تاریخ"
|
||||
id="date"
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
size="small"
|
||||
style={{ width: "160px" }}
|
||||
{...params}
|
||||
/>
|
||||
)}
|
||||
value={selectedDate2}
|
||||
onChange={(e) => {
|
||||
setSelectedDate2(moment(e).format("YYYY-MM-DD"));
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>{" "}
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<Tooltip title="خروجی اکسل">
|
||||
<a
|
||||
href={`${
|
||||
axios.defaults.baseURL
|
||||
}LiveStock/jahad/live_stock_transaction_excel/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&key=${userKey}&name=${productType}${
|
||||
withDate ? `&date1=${selectedDate1}&date2=${selectedDate2}` : ``
|
||||
}`}
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Button color="success">
|
||||
<RiFileExcel2Fill size={32} />
|
||||
</Button>
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
<Grid container mt={2} mb={4} isDashboard xs={12}>
|
||||
<ResponsiveTable
|
||||
noPagination
|
||||
isDashboard
|
||||
columns={[
|
||||
"کل وزن فروش",
|
||||
|
||||
"تعداد تراکنش ها",
|
||||
"مبلغ کل تراکنش ها",
|
||||
"مجموع سهم تعاونی ها",
|
||||
"مجموع سهم اتحادیه",
|
||||
"مجموع سهم شرکت",
|
||||
"مجموع دام سنگین",
|
||||
"مجموع دام سبک",
|
||||
]}
|
||||
data={[
|
||||
[
|
||||
dashboardData?.curWeight?.toLocaleString(),
|
||||
dashboardData?.lenTransaction?.toLocaleString(),
|
||||
dashboardData?.price?.toLocaleString(),
|
||||
dashboardData?.totalCooperativePrice?.toLocaleString(),
|
||||
dashboardData?.totalUnionPrice?.toLocaleString(),
|
||||
dashboardData?.totalCompanyPrice?.toLocaleString(),
|
||||
dashboardData?.curHeavy?.toLocaleString(),
|
||||
dashboardData?.curLight?.toLocaleString(),
|
||||
],
|
||||
]}
|
||||
title={"خلاصه اطلاعات"}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
ignoreTextsLength
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"تاریخ",
|
||||
"خریدار",
|
||||
"کد ملی خریدار",
|
||||
"موبایل خریدار",
|
||||
"فروشنده",
|
||||
"تلفن فروشنده",
|
||||
"وضعیت",
|
||||
"محل تحویل",
|
||||
"کالا",
|
||||
"کد ملی فروشنده",
|
||||
"دام سنگین",
|
||||
"دام سبک",
|
||||
"وزن (کیلوگرم)",
|
||||
"مبلغ تراکنش",
|
||||
"سهم تعاونی",
|
||||
"سهم اتحادیه",
|
||||
"سهم شرکت",
|
||||
"جزئیات محصولات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title="تراکنش ها"
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,132 @@
|
||||
import React, { useContext, useEffect } from "react";
|
||||
import { TextField } from "@mui/material";
|
||||
import { Button } from "@mui/material";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadEditAllocationService } from "../../services/province-jahad-submit-allocation";
|
||||
import { CLOSE_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
|
||||
export const ProvinceJahadUnionSubmitRealWeight = ({
|
||||
item,
|
||||
updateTable,
|
||||
getDashboardData,
|
||||
}) => {
|
||||
const validationSchema = Yup.object({
|
||||
factory: Yup.string(),
|
||||
weight: Yup.number()
|
||||
.required("وزن الزامی است")
|
||||
.positive("وزن باید مثبت باشد"),
|
||||
billOfLadingCode: Yup.string(),
|
||||
});
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
factory: "",
|
||||
weight: item?.weight || "",
|
||||
billOfLadingCode: "",
|
||||
},
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
let req = {
|
||||
state: "accepted",
|
||||
code: values.billOfLadingCode,
|
||||
place: values.factory,
|
||||
role: getRoleFromUrl(),
|
||||
allocation_key: item?.key,
|
||||
};
|
||||
|
||||
dispatch(provinceJahadEditAllocationService(req)).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(CLOSE_MODAL());
|
||||
updateTable();
|
||||
getDashboardData();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
formik.validateForm();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" gap={2}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="weight"
|
||||
name="weight"
|
||||
label="وزن"
|
||||
type="number"
|
||||
value={formik.values.weight}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.weight && Boolean(formik.errors.weight)}
|
||||
helperText={formik.touched.weight && formik.errors.weight}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="factory"
|
||||
name="factory"
|
||||
label="مکان دریافت"
|
||||
value={formik.values.factory}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.factory && Boolean(formik.errors.factory)}
|
||||
helperText={formik.touched.factory && formik.errors.factory}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="billOfLadingCode"
|
||||
name="billOfLadingCode"
|
||||
label="کد بارنامه"
|
||||
value={formik.values.billOfLadingCode}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.billOfLadingCode &&
|
||||
Boolean(formik.errors.billOfLadingCode)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.billOfLadingCode && formik.errors.billOfLadingCode
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Button
|
||||
fullWidth
|
||||
variant="contained"
|
||||
type="submit"
|
||||
onClick={formik.handleSubmit}
|
||||
>
|
||||
ارسال
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,192 @@
|
||||
import {
|
||||
Button,
|
||||
FormControlLabel,
|
||||
IconButton,
|
||||
Popover,
|
||||
Switch,
|
||||
Tooltip,
|
||||
} from "@mui/material";
|
||||
import { useContext, useState } from "react";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import {
|
||||
CLOSE_MODAL,
|
||||
DRAWER,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { useDispatch } from "react-redux";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceJahadDeleteUnionsService } from "../../services/province-jahad-unions-delete-union";
|
||||
import { ProvinceJahadUnionsSubmit } from "../province-jahad-unions-submit/ProvinceJahadUnionsSubmit";
|
||||
import { provinceJahadUpdateUnionService } from "../../services/province-jahad-edit-union";
|
||||
|
||||
export const ProvinceJahadUnionsOperations = ({ item, updateTable }) => {
|
||||
const dispatch = useDispatch();
|
||||
const [popoverOpen, setPopoverOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const openPopover = (event) => {
|
||||
setPopoverOpen(true);
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const closePopover = () => {
|
||||
setPopoverOpen(false);
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid>
|
||||
<IconButton variant="contained" color="primary" onClick={openPopover}>
|
||||
<TuneIcon />
|
||||
</IconButton>
|
||||
<Popover
|
||||
open={popoverOpen}
|
||||
anchorEl={anchorEl}
|
||||
onClose={closePopover}
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "right",
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: "top",
|
||||
horizontal: "left",
|
||||
}}
|
||||
>
|
||||
<div style={{ padding: 2 }}>
|
||||
<Grid
|
||||
container
|
||||
direction="column"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
gap={1}
|
||||
>
|
||||
<Tooltip title={"ویرایش اتحادیه"} placement="left-start">
|
||||
<IconButton
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
DRAWER({
|
||||
right: true,
|
||||
top: false,
|
||||
content: (
|
||||
<ProvinceJahadUnionsSubmit
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
title: "ویرایش اتحادیه ",
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={item?.active}
|
||||
onChange={() => {
|
||||
dispatch(
|
||||
provinceJahadUpdateUnionService({
|
||||
union_key: item?.key,
|
||||
active: !item?.active,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={item?.active ? "فعال" : "غیرفعال"}
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
display: "flex",
|
||||
}}
|
||||
/>
|
||||
|
||||
<Tooltip title={"حذف"} placement="left-start">
|
||||
<IconButton
|
||||
aria-label="delete"
|
||||
color="error"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "آیا مطمئن هستید؟",
|
||||
content: (
|
||||
<Grid container>
|
||||
<Button
|
||||
color="error"
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
provinceJahadDeleteUnionsService(item?.key)
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
updateTable();
|
||||
dispatch(CLOSE_MODAL());
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.data.result,
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
تایید
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(CLOSE_MODAL());
|
||||
}}
|
||||
>
|
||||
لغو
|
||||
</Button>
|
||||
</Grid>
|
||||
),
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</div>
|
||||
</Popover>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,303 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import {
|
||||
Grid,
|
||||
TextField,
|
||||
Button,
|
||||
Autocomplete,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
|
||||
import { useDispatch } from "react-redux";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { cityGetProvinces } from "../../../city/services/CityGetProvinces";
|
||||
import { cityGetCity } from "../../../city/services/city-get-city";
|
||||
import {
|
||||
provinceJahadSubmitUnionService,
|
||||
provinceJahadUpdateUnionService,
|
||||
} from "../../services/province-jahad-edit-union";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
|
||||
export const ProvinceJahadUnionsSubmit = ({ updateTable, item }) => {
|
||||
const [provinceData, setProvinceData] = useState([]);
|
||||
const [cityData, setCityData] = useState([]);
|
||||
const [provinceKey, setProvinceKey] = useState();
|
||||
const [cityKey, setCityKey] = useState();
|
||||
const [isExistProvince, setIsExistProvince] = useState(true);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string().required("این فیلد الزامی است"),
|
||||
first_name: Yup.string().required("این فیلد الزامی است"),
|
||||
last_name: Yup.string().required("این فیلد الزامی است"),
|
||||
address: Yup.string().required("این فیلد الزامی است"),
|
||||
nationalId: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(10, "کد ملی باید ۱۰ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
postalCode: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(10, "کد پستی باید ۱۰ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
mobile: Yup.string()
|
||||
.matches(/^\d+$/, "لطفا فقط عدد وارد کنید")
|
||||
.length(11, "شماره موبایل باید ۱۱ رقم باشد")
|
||||
.required("این فیلد الزامی است"),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetProvinces())?.then((r) => {
|
||||
dispatch(LOADING_END());
|
||||
setProvinceData(r.payload.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_END());
|
||||
if (provinceKey) {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetCity(provinceKey)).then((r) => {
|
||||
setCityData(r.payload.data);
|
||||
setIsExistProvince(false);
|
||||
dispatch(LOADING_END());
|
||||
});
|
||||
}
|
||||
}, [provinceKey]);
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
name: item?.name || "",
|
||||
first_name: item?.user?.firstName || "",
|
||||
last_name: item?.user?.lastName || "",
|
||||
mobile: item?.user?.mobile || "",
|
||||
address: item?.address?.address || "",
|
||||
nationalId: item?.nationalId || "",
|
||||
postalCode: item?.address?.postalCode || "",
|
||||
},
|
||||
validationSchema,
|
||||
enableReinitialize: true,
|
||||
onSubmit: (values) => {
|
||||
if (item) {
|
||||
dispatch(
|
||||
provinceJahadUpdateUnionService({
|
||||
union_key: item?.key,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
name: values.name,
|
||||
address: values.address,
|
||||
mobile: values.mobile,
|
||||
national_id: values.nationalId,
|
||||
postal_code: values.postalCode,
|
||||
city: cityKey || item?.address?.city?.name,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
provinceJahadSubmitUnionService({
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
name: values.name,
|
||||
address: values.address,
|
||||
mobile: values.mobile,
|
||||
national_id: values.nationalId,
|
||||
postal_code: values.postalCode,
|
||||
city: cityKey || item?.address?.city?.name,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
|
||||
updateTable();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const isFormValid = () => {
|
||||
if (item) {
|
||||
return formik.isValid;
|
||||
} else {
|
||||
return formik.isValid && cityKey;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container direction="column" gap={SPACING.SMALL}>
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<TextField
|
||||
name="name"
|
||||
label=" نام اتحادیه"
|
||||
fullWidth
|
||||
value={formik.values.name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.name && Boolean(formik.errors.name)}
|
||||
helperText={formik.touched.name && formik.errors.name}
|
||||
/>
|
||||
|
||||
<Autocomplete
|
||||
disablePortal
|
||||
id="province"
|
||||
options={provinceData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setProvinceKey(value.id);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="استان را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
|
||||
<Autocomplete
|
||||
disabled={isExistProvince}
|
||||
disablePortal
|
||||
id="city"
|
||||
options={cityData?.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))}
|
||||
onChange={(e, value) => {
|
||||
setCityKey(value.label);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="شهر را انتخاب کنید*" />
|
||||
)}
|
||||
/>
|
||||
{item && !cityKey && (
|
||||
<Typography variant="caption" color="error">
|
||||
شهر: {item?.address?.city?.name}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
<TextField
|
||||
name="first_name"
|
||||
label="نام "
|
||||
fullWidth
|
||||
value={formik.values.first_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.first_name && Boolean(formik.errors.first_name)
|
||||
}
|
||||
helperText={formik.touched.first_name && formik.errors.first_name}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="last_name"
|
||||
label=" نام خانوادگی"
|
||||
fullWidth
|
||||
value={formik.values.last_name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.last_name && Boolean(formik.errors.last_name)}
|
||||
helperText={formik.touched.last_name && formik.errors.last_name}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="mobile"
|
||||
label="تلفن"
|
||||
fullWidth
|
||||
value={formik.values.mobile}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.mobile && Boolean(formik.errors.mobile)}
|
||||
helperText={formik.touched.mobile && formik.errors.mobile}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="address"
|
||||
label="آدرس "
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="nationalId"
|
||||
label="کد ملی"
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
fullWidth
|
||||
value={formik.values.nationalId}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.nationalId && Boolean(formik.errors.nationalId)
|
||||
}
|
||||
helperText={formik.touched.nationalId && formik.errors.nationalId}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
name="postalCode"
|
||||
label="کد پستی"
|
||||
fullWidth
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
value={formik.values.postalCode}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={
|
||||
formik.touched.postalCode && Boolean(formik.errors.postalCode)
|
||||
}
|
||||
helperText={formik.touched.postalCode && formik.errors.postalCode}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={!isFormValid()}
|
||||
>
|
||||
ثبت اطلاعات
|
||||
</Button>
|
||||
</Grid>
|
||||
</form>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,169 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Button, TextField } from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { ProvinceJahadUnionsOperations } from "../province-jahad-unions-operations/ProvinceJahadUnionsOperations";
|
||||
import { ProvinceJahadUnionsSubmit } from "../province-jahad-unions-submit/ProvinceJahadUnionsSubmit";
|
||||
|
||||
export const ProvinceJahadUnions = () => {
|
||||
const dispatch = useDispatch();
|
||||
const handleTextChange = (event) => {
|
||||
setTextValue(event.target.value);
|
||||
};
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [totalRows, setTotalRows] = useState(0);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
let response;
|
||||
dispatch(LOADING_START());
|
||||
response = await axios.get(
|
||||
`LiveStock/union/union-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
fetchApiData(page);
|
||||
setPage(page);
|
||||
};
|
||||
|
||||
const handlePerRowsChange = (perRows) => {
|
||||
setPerPage(perRows);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const updateTable = () => {
|
||||
fetchApiData(page !== 0 ? page : 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.name,
|
||||
item?.user.fullname,
|
||||
item?.user.provinceName,
|
||||
item?.user.cityName,
|
||||
item?.user.mobile,
|
||||
item?.nationalId,
|
||||
<ProvinceJahadUnionsOperations
|
||||
key={i}
|
||||
updateTable={updateTable}
|
||||
item={item}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
setTableData(d);
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchApiData(1);
|
||||
}, [dispatch, perPage]);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`LiveStock/union/union-view/?search=filter&value=${textValue}&role=${getRoleFromUrl()}&page=${page}&page_size=${perPage}`
|
||||
);
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container xs={12} justifyContent="center" alignItems="center" gap={2}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={2}
|
||||
>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
DRAWER({
|
||||
right: true,
|
||||
top: false,
|
||||
content: (
|
||||
<ProvinceJahadUnionsSubmit updateTable={updateTable} />
|
||||
),
|
||||
title: "ایجاد اتحادیه ",
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
ایجاد اتحادیه
|
||||
</Button>
|
||||
|
||||
<Grid>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
size="small"
|
||||
label="جستجو"
|
||||
variant="outlined"
|
||||
style={{ width: 250 }}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
<Button
|
||||
// disabled={!textValue}
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
endIcon={<RiSearchLine />}
|
||||
>
|
||||
جستجو
|
||||
</Button>
|
||||
</form>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<ResponsiveTable
|
||||
ignoreTextsLength
|
||||
data={tableData}
|
||||
columns={[
|
||||
"ردیف",
|
||||
"نام اتحادیه",
|
||||
"کاربر",
|
||||
"استان",
|
||||
"شهر",
|
||||
"موبایل",
|
||||
"کد ملی",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
page={page}
|
||||
perPage={perPage}
|
||||
handlePerRowsChange={handlePerRowsChange}
|
||||
title="اتحادیه ها"
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
export const ProvinceJahadUsers = () => {
|
||||
return <div>این بخش در دست توسعه است</div>;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadSellReportInfoDashboardService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_SELL_REPORT_INFO_DASHBOARD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
"/cooperative-warehouse-dashboard",
|
||||
{
|
||||
params: {
|
||||
...d,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadDeleteHerdService = createAsyncThunk(
|
||||
"PROVINCE-JAHAD-DELETE-HERD-SERVICE",
|
||||
async (id, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.delete(
|
||||
"/LiveStock/union/union-view/0/?key=" + id
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadUpdateUnionService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_UPDATE_PRODUCT_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"LiveStock/union/union-view/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadSubmitUnionService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_PRODUCT_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"LiveStock/union/union-view/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadGetCooperativesPosInfoService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_COOPERATIVES_POS_INFO",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`/cooperative-pos/?cooperative_key=${d}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadGetDistributionInfoService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_DISTRIBUTION_INFO",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`LiveStock/jahad/dashboard-live-stock-allocation/`,
|
||||
{
|
||||
params: d,
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadGetInventoryDataService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_INVENTORY_INFO",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`LiveStock/jahad/live-stock-role-products/`,
|
||||
{
|
||||
params: d,
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";
|
||||
|
||||
export const provinceJahadGetHerdInfoDashboardService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_HERD_INFO_DASHBOARD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
"/LiveStock/live-stock/dashboard_live_stock/",
|
||||
{
|
||||
params: {
|
||||
role: getRoleFromUrl(),
|
||||
search: "filter",
|
||||
value: d.search,
|
||||
type: d.type,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadGetProductInfoService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_PRODUCT_INFO",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`LiveStock/jahad/live-stock-product/`,
|
||||
{
|
||||
params: {
|
||||
name: d.product,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";
|
||||
|
||||
export const provinceJahadGetRancherInfoDashboardService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_RANCHERD_INFO_DASHBOARD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
"/LiveStock/rancher/dashboard_rancher",
|
||||
{
|
||||
params: {
|
||||
role: getRoleFromUrl(),
|
||||
search: "filter",
|
||||
value: d.search,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadGetRancherDetailsService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_PRODUCT_INFO",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`LiveStock/rancher/get_detail_rancher/`,
|
||||
{
|
||||
params: {
|
||||
herd_code: d.herd_code,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";
|
||||
|
||||
export const provinceJahadGetSingleRancherService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_SINGLE_RANCHER",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
`LiveStock/rancher/rancher-view/`,
|
||||
{
|
||||
params: {
|
||||
value: d.value,
|
||||
search: "filter",
|
||||
role: getRoleFromUrl(),
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import axios from "axios";
|
||||
|
||||
export const provinceJahadGetTransactionInfoDashboardService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_GET_TRANSACTION_INFO_DASHBOARD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
"/live-stock-transactions-dashboard",
|
||||
{
|
||||
params: {
|
||||
...d,
|
||||
},
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadEditRancher = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_RANCHER_ACTIVATION",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"LiveStock/rancher/rancher-view/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadSubmitRancher = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_RANCHER",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"LiveStock/rancher/rancher-view/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadSubmitAllocationGetUsers = createAsyncThunk(
|
||||
"SLAUGHTER_GET_GUILDS_FOR_ALLOCATE_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.get(
|
||||
"LiveStock/jahad/get_user_live_stock/",
|
||||
{
|
||||
params: d,
|
||||
}
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,56 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadSubmitAllocationService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_ALLOCATION_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"LiveStock/jahad/live-stock-allocation/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadEditAllocationService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_EDIT_ALLOCATION_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"/LiveStock/jahad/live-stock-allocation/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadDeleteAllocationService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_DELETE_ALLOCATION",
|
||||
async (id, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.delete(
|
||||
"LiveStock/jahad/live-stock-allocation/0/?allocation_key=" + id
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
|
||||
export const provinceJahadEditCooperativeService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_COOPERATIVE_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"/LiveStock/cooperative/cooperative-views/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadSubmitCooperativeService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_COOPERATIVE_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"/LiveStock/cooperative/cooperative-views/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,56 @@
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
|
||||
export const provinceJahadEditHerdService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_EDIT_HERD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"/LiveStock/live-stock/live-stock-view/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadSubmitHerdService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_HERD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"/LiveStock/live-stock/live-stock-view/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceJahadDeleteHerdService = createAsyncThunk(
|
||||
"PROVINCE-JAHAD-DELETE-HERD-SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.delete(
|
||||
`/LiveStock/live-stock/live-stock-view/0/?live_stock_key=${d.live_stock_key}`
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response?.data?.result || "خطا در بایگانی گله" };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
|
||||
export const provinceJahadSubmitShareService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_SUBMIT_SHARE_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"/LiveStock/jahad/cooperative-shares/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadDeleteRancherService = createAsyncThunk(
|
||||
"PROVINCE-JAHAD-DELETE-RANCHER-SERVICE",
|
||||
async (id, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.delete(
|
||||
"/LiveStock/rancher/rancher-view/0/?rancher_key=" + id
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadDeleteUnionsService = createAsyncThunk(
|
||||
"PROVINCE-JAHAD-DELETE-UNIONS-SERVICE",
|
||||
async (id, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.delete(
|
||||
"/LiveStock/union/union-view/0/?key=" + id
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadUnionsSubmitService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_UNIONS_SUBMIT_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"/LiveStock/union/union-view/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const provinceJahadUpdateProductService = createAsyncThunk(
|
||||
"PROVINCE_JAHAD_UPDATE_PRODUCT_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.put(
|
||||
"LiveStock/jahad/live-stock-product/0/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user