add delete violation and base report page
This commit is contained in:
@@ -4,16 +4,18 @@ import { Box } from "@mui/material";
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
import RowActions from "./RowActions";
|
import RowActions from "./RowActions";
|
||||||
|
import { GET_DRIVERS_ACTIVITY_REPORT } from "@/core/utils/routes";
|
||||||
|
|
||||||
const DriverReportsList = ({ data, specialFilter }) => {
|
const DriverReportsList = ({ specialFilter }) => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "driver_id",
|
accessorKey: "driver_id",
|
||||||
header: "کد یکتا",
|
header: "کد یکتا",
|
||||||
id: "driver_id",
|
id: "driver_id",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
enableSorting: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -22,8 +24,9 @@ const DriverReportsList = ({ data, specialFilter }) => {
|
|||||||
accessorKey: "driver_name",
|
accessorKey: "driver_name",
|
||||||
header: "نام راننده",
|
header: "نام راننده",
|
||||||
id: "driver_name",
|
id: "driver_name",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
enableSorting: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -33,7 +36,7 @@ const DriverReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "کارکرد",
|
header: "کارکرد",
|
||||||
id: "func",
|
id: "func",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: true,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -43,7 +46,7 @@ const DriverReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "تعداد ماموریت",
|
header: "تعداد ماموریت",
|
||||||
id: "missions",
|
id: "missions",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: true,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -56,8 +59,9 @@ const DriverReportsList = ({ data, specialFilter }) => {
|
|||||||
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
TableToolbar={Toolbar}
|
TableToolbar={Toolbar}
|
||||||
|
need_filter={true}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data.data}
|
table_url={GET_DRIVERS_ACTIVITY_REPORT}
|
||||||
page_name={"driverReport"}
|
page_name={"driverReport"}
|
||||||
table_name={"driverReportList"}
|
table_name={"driverReportList"}
|
||||||
enablePagination={false}
|
enablePagination={false}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import { GET_DRIVER_COUNTRY_ACTIVITY_REPORT, GET_DRIVER_PROVINCE_ACTIVITY_REPORT } from "@/core/utils/routes";
|
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { LinearProgress, Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -14,10 +12,8 @@ import DriverReportsList from "./DriverReportsList";
|
|||||||
import SearchReportList from "./Search";
|
import SearchReportList from "./Search";
|
||||||
|
|
||||||
const DriverReportsPage = () => {
|
const DriverReportsPage = () => {
|
||||||
const [data, setData] = useState(null);
|
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const requestServer = useRequest();
|
|
||||||
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
@@ -32,38 +28,32 @@ const DriverReportsPage = () => {
|
|||||||
];
|
];
|
||||||
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const onSearchSubmit = async (data) => {
|
const onSearchSubmit = (data) => {
|
||||||
const params = new URLSearchParams();
|
const filters = [
|
||||||
params.set("from_date", `${data.from_date} 00:00:00`);
|
{
|
||||||
params.set("date_to", `${data.date_to} 23:59:59`);
|
value: `${data.from_date} 00:00:00`,
|
||||||
setSpecialFilter([
|
datatype: "date",
|
||||||
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
id: "start_time",
|
||||||
{ value: `${data.from_date} 00:00:00`, datatype: "date", id: "start_time", fn: "greaterThan" },
|
fn: "greaterThan",
|
||||||
{ value: `${data.date_to} 23:59:59`, datatype: "date", id: "finish_time", fn: "lessThan" },
|
},
|
||||||
]);
|
{
|
||||||
if (data.province_id === "-1") {
|
value: `${data.date_to} 23:59:59`,
|
||||||
try {
|
datatype: "date",
|
||||||
const response = await requestServer(`${GET_DRIVER_COUNTRY_ACTIVITY_REPORT}?${params}`);
|
id: "finish_time",
|
||||||
const result = response.data.data;
|
fn: "lessThan",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
setData({
|
if (data.province_id !== "-1") {
|
||||||
data: result.activities,
|
filters.unshift({
|
||||||
filters: data,
|
value: data.province_id,
|
||||||
});
|
datatype: "numeric",
|
||||||
} catch (e) {}
|
id: "province_id",
|
||||||
} else {
|
fn: "equals",
|
||||||
try {
|
});
|
||||||
params.set("province_id", `${data.province_id}`);
|
|
||||||
const response = await requestServer(`${GET_DRIVER_PROVINCE_ACTIVITY_REPORT}?${params}`);
|
|
||||||
|
|
||||||
const result = response.data.data;
|
|
||||||
|
|
||||||
setData({
|
|
||||||
data: result.activities,
|
|
||||||
filters: data,
|
|
||||||
});
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSpecialFilter(filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -100,7 +90,7 @@ const DriverReportsPage = () => {
|
|||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
/>
|
/>
|
||||||
{!data ? <LinearProgress /> : <DriverReportsList specialFilter={specialFilter} data={data} />}
|
<DriverReportsList specialFilter={specialFilter} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,17 +4,23 @@ import { Box } from "@mui/material";
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
import RowActions from "./RowActions";
|
import RowActions from "./RowActions";
|
||||||
|
import {
|
||||||
|
GET_MACHINES_ACTIVITY_REPORT,
|
||||||
|
GET_MACHINES_COUNTRY_ACTIVITY_REPORT,
|
||||||
|
GET_MACHINES_PROVINCE_ACTIVITY_REPORT,
|
||||||
|
} from "@/core/utils/routes";
|
||||||
|
|
||||||
const MachinesReportsList = ({ data, specialFilter }) => {
|
const MachinesReportsList = ({ specialFilter }) => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "machine_id",
|
accessorKey: "machine_id",
|
||||||
header: "کد یکتا",
|
header: "کد یکتا",
|
||||||
id: "machine_id",
|
id: "machine_id",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
datatype: "numeric",
|
enableSorting: true,
|
||||||
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
@@ -22,8 +28,9 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
accessorKey: "car_name",
|
accessorKey: "car_name",
|
||||||
header: "مدل ماشین",
|
header: "مدل ماشین",
|
||||||
id: "car_name",
|
id: "car_name",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
enableSorting: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -32,8 +39,9 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
accessorKey: "machine_code",
|
accessorKey: "machine_code",
|
||||||
header: "کد ماشین",
|
header: "کد ماشین",
|
||||||
id: "machine_code",
|
id: "machine_code",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
enableSorting: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -43,6 +51,7 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "کارکرد",
|
header: "کارکرد",
|
||||||
id: "func",
|
id: "func",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
@@ -53,7 +62,7 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "تعداد ماموریت",
|
header: "تعداد ماموریت",
|
||||||
id: "missions",
|
id: "missions",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: true,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -67,11 +76,12 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
TableToolbar={Toolbar}
|
TableToolbar={Toolbar}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data.data}
|
table_url={GET_MACHINES_ACTIVITY_REPORT}
|
||||||
page_name={"roadMissionReport"}
|
page_name={"roadMissionReport"}
|
||||||
table_name={"roadMissionReportList"}
|
table_name={"roadMissionReportList"}
|
||||||
enablePagination={false}
|
enablePagination={true}
|
||||||
specialFilter={specialFilter}
|
specialFilter={specialFilter}
|
||||||
|
need_filter={true}
|
||||||
enableRowActions
|
enableRowActions
|
||||||
RowActions={RowActionsWithRowData}
|
RowActions={RowActionsWithRowData}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import { GET_MACHINES_COUNTRY_ACTIVITY_REPORT, GET_MACHINES_PROVINCE_ACTIVITY_REPORT } from "@/core/utils/routes";
|
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { LinearProgress, Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -14,10 +12,8 @@ import MachinesReportsList from "./MachinesReportsList";
|
|||||||
import SearchReportList from "./Search";
|
import SearchReportList from "./Search";
|
||||||
|
|
||||||
const MachinesReportsPage = () => {
|
const MachinesReportsPage = () => {
|
||||||
const [data, setData] = useState(null);
|
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const requestServer = useRequest();
|
|
||||||
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
@@ -32,38 +28,32 @@ const MachinesReportsPage = () => {
|
|||||||
];
|
];
|
||||||
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const onSearchSubmit = async (data) => {
|
const onSearchSubmit = (data) => {
|
||||||
const params = new URLSearchParams();
|
const filters = [
|
||||||
params.set("from_date", `${data.from_date} 00:00:00`);
|
{
|
||||||
params.set("date_to", `${data.date_to} 23:59:59`);
|
value: `${data.from_date} 00:00:00`,
|
||||||
setSpecialFilter([
|
datatype: "date",
|
||||||
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
id: "start_time",
|
||||||
{ value: `${data.from_date} 00:00:00`, datatype: "date", id: "start_time", fn: "greaterThan" },
|
fn: "greaterThan",
|
||||||
{ value: `${data.date_to} 23:59:59`, datatype: "date", id: "finish_time", fn: "lessThan" },
|
},
|
||||||
]);
|
{
|
||||||
if (data.province_id === "-1") {
|
value: `${data.date_to} 23:59:59`,
|
||||||
try {
|
datatype: "date",
|
||||||
const response = await requestServer(`${GET_MACHINES_COUNTRY_ACTIVITY_REPORT}?${params}`);
|
id: "finish_time",
|
||||||
const result = response.data.data;
|
fn: "lessThan",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
setData({
|
if (data.province_id !== "-1") {
|
||||||
data: result.activities,
|
filters.unshift({
|
||||||
filters: data,
|
value: data.province_id,
|
||||||
});
|
datatype: "numeric",
|
||||||
} catch (e) {}
|
id: "province_id",
|
||||||
} else {
|
fn: "equals",
|
||||||
try {
|
});
|
||||||
params.set("province_id", `${data.province_id}`);
|
|
||||||
const response = await requestServer(`${GET_MACHINES_PROVINCE_ACTIVITY_REPORT}?${params}`);
|
|
||||||
|
|
||||||
const result = response.data.data;
|
|
||||||
|
|
||||||
setData({
|
|
||||||
data: result.activities,
|
|
||||||
filters: data,
|
|
||||||
});
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSpecialFilter(filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -100,7 +90,7 @@ const MachinesReportsPage = () => {
|
|||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
/>
|
/>
|
||||||
{!data ? <LinearProgress /> : <MachinesReportsList specialFilter={specialFilter} data={data} />}
|
<MachinesReportsList specialFilter={specialFilter} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,17 +3,22 @@ import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
|||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
|
import {
|
||||||
|
GET_MACHINES_TYPE_COUNTRY_ACTIVITY_REPORT,
|
||||||
|
GET_MACHINES_TYPE_PROVINCE_ACTIVITY_REPORT,
|
||||||
|
} from "@/core/utils/routes";
|
||||||
// import RowActions from "./RowActions";
|
// import RowActions from "./RowActions";
|
||||||
|
|
||||||
const MachinesReportsList = ({ data, specialFilter }) => {
|
const MachinesReportsList = ({ specialFilter }) => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "car_type",
|
accessorKey: "car_type",
|
||||||
header: "نوع ماشین",
|
header: "نوع ماشین",
|
||||||
id: "car_type",
|
id: "car_type",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: true,
|
||||||
enableSorting: false,
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
enableSorting: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -23,7 +28,7 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "کارکرد",
|
header: "کارکرد",
|
||||||
id: "func",
|
id: "func",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: true,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -33,7 +38,7 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
header: "تعداد ماموریت",
|
header: "تعداد ماموریت",
|
||||||
id: "missions",
|
id: "missions",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: true,
|
||||||
datatype: "number",
|
datatype: "number",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
@@ -46,11 +51,16 @@ const MachinesReportsList = ({ data, specialFilter }) => {
|
|||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
TableToolbar={Toolbar}
|
TableToolbar={Toolbar}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data.data}
|
table_url={
|
||||||
|
specialFilter.find((x) => x.id === "province_id")?.value === "-1"
|
||||||
|
? GET_MACHINES_TYPE_COUNTRY_ACTIVITY_REPORT
|
||||||
|
: GET_MACHINES_TYPE_PROVINCE_ACTIVITY_REPORT
|
||||||
|
}
|
||||||
page_name={"roadMissionReportMachineTypeReport"}
|
page_name={"roadMissionReportMachineTypeReport"}
|
||||||
table_name={"roadMissionReportMachineTypeReportList"}
|
table_name={"roadMissionReportMachineTypeReportList"}
|
||||||
enablePagination={false}
|
enablePagination={false}
|
||||||
specialFilter={specialFilter}
|
specialFilter={specialFilter}
|
||||||
|
need_filter={true}
|
||||||
// enableRowActions
|
// enableRowActions
|
||||||
// RowActions={RowActions}
|
// RowActions={RowActions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import {
|
|
||||||
GET_MACHINES_TYPE_COUNTRY_ACTIVITY_REPORT,
|
|
||||||
GET_MACHINES_TYPE_PROVINCE_ACTIVITY_REPORT,
|
|
||||||
} from "@/core/utils/routes";
|
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { LinearProgress, Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -17,10 +12,8 @@ import MachinesReportsList from "./MachinesReportsList";
|
|||||||
import SearchReportList from "./Search";
|
import SearchReportList from "./Search";
|
||||||
|
|
||||||
const MachinesTypeReportsPage = () => {
|
const MachinesTypeReportsPage = () => {
|
||||||
const [data, setData] = useState(null);
|
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const requestServer = useRequest();
|
|
||||||
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
@@ -30,43 +23,37 @@ const MachinesTypeReportsPage = () => {
|
|||||||
};
|
};
|
||||||
const defaultFilter = [
|
const defaultFilter = [
|
||||||
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
||||||
{ value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
{ value: `${defaultValues.from_date} 00:00:00`, datatype: "date", id: "start_time", fn: "greaterThan" },
|
||||||
{ value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
{ value: `${defaultValues.date_to} 23:59:59`, datatype: "date", id: "finish_time", fn: "lessThan" },
|
||||||
];
|
];
|
||||||
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const onSearchSubmit = async (data) => {
|
const onSearchSubmit = (data) => {
|
||||||
const params = new URLSearchParams();
|
const filters = [
|
||||||
params.set("from_date", `${data.from_date} 00:00:00`);
|
{
|
||||||
params.set("date_to", `${data.date_to} 23:59:59`);
|
value: `${data.from_date} 00:00:00`,
|
||||||
setSpecialFilter([
|
datatype: "date",
|
||||||
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
id: "start_time",
|
||||||
{ value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
fn: "greaterThan",
|
||||||
{ value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
},
|
||||||
]);
|
{
|
||||||
if (data.province_id === "-1") {
|
value: `${data.date_to} 23:59:59`,
|
||||||
try {
|
datatype: "date",
|
||||||
const response = await requestServer(`${GET_MACHINES_TYPE_COUNTRY_ACTIVITY_REPORT}?${params}`);
|
id: "finish_time",
|
||||||
const result = response.data.data;
|
fn: "lessThan",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
setData({
|
if (data.province_id !== "-1") {
|
||||||
data: result.activities,
|
filters.unshift({
|
||||||
filters: data,
|
value: data.province_id,
|
||||||
});
|
datatype: "numeric",
|
||||||
} catch (e) {}
|
id: "province_id",
|
||||||
} else {
|
fn: "equals",
|
||||||
try {
|
});
|
||||||
params.set("province_id", `${data.province_id}`);
|
|
||||||
const response = await requestServer(`${GET_MACHINES_TYPE_PROVINCE_ACTIVITY_REPORT}?${params}`);
|
|
||||||
|
|
||||||
const result = response.data.data;
|
|
||||||
|
|
||||||
setData({
|
|
||||||
data: result.activities,
|
|
||||||
filters: data,
|
|
||||||
});
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSpecialFilter(filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -103,7 +90,7 @@ const MachinesTypeReportsPage = () => {
|
|||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
/>
|
/>
|
||||||
{!data ? <LinearProgress /> : <MachinesReportsList specialFilter={specialFilter} data={data} />}
|
<MachinesReportsList specialFilter={specialFilter} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
|
import { DELETE_VIOLATION } from "@/core/utils/routes";
|
||||||
|
|
||||||
|
const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
|
const handleClick = () => {
|
||||||
|
setSubmitting(true);
|
||||||
|
requestServer(`${DELETE_VIOLATION}/${rowId}`, "post", {
|
||||||
|
hasSidebarUpdate: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
mutate();
|
||||||
|
setOpenDeleteDialog(false);
|
||||||
|
setSubmitting(false);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setSubmitting(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DialogContent>
|
||||||
|
<Stack alignItems="center" spacing={2}>
|
||||||
|
<Typography mt={2}>آیا از حذف تخلف اطمینان دارید؟</Typography>
|
||||||
|
</Stack>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
|
||||||
|
<Button onClick={() => setOpenDeleteDialog(false)} variant="outlined" color="secondary">
|
||||||
|
خیر !
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleClick} variant="contained" color="error" disabled={submitting}>
|
||||||
|
{submitting ? "درحال حذف..." : "بله اطمینان دارم"}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeleteContent;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
||||||
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
|
import DeleteContent from "./DeleteContent";
|
||||||
|
|
||||||
|
const DeleteViolation = ({ mutate, rowId }) => {
|
||||||
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Tooltip title="حذف">
|
||||||
|
<IconButton color="error" onClick={() => setOpenDeleteDialog(true)}>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Dialog
|
||||||
|
open={openDeleteDialog}
|
||||||
|
onClose={() => setOpenDeleteDialog(false)}
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
dir="rtl"
|
||||||
|
maxWidth={"md"}
|
||||||
|
>
|
||||||
|
<DialogTitle>حذف تخلف</DialogTitle>
|
||||||
|
<DeleteContent rowId={rowId} mutate={mutate} setOpenDeleteDialog={setOpenDeleteDialog} />
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default DeleteViolation
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
// import CreateWithoutProcess from "../Actions/CreateWithoutProcess";
|
// import CreateWithoutProcess from "../Actions/CreateWithoutProcess";
|
||||||
import EditViolation from "../Actions/EditViolation";
|
import EditViolation from "../Actions/EditViolation";
|
||||||
|
import DeleteViolation from "../Actions/DeleteViolation";
|
||||||
|
|
||||||
const RowActions = ({ row, mutate }) => {
|
const RowActions = ({ row, mutate }) => {
|
||||||
// const canEdit = row.original.status === 0 && row.original.type === 1;
|
// const canEdit = row.original.status === 0 && row.original.type === 1;
|
||||||
@@ -7,6 +8,7 @@ const RowActions = ({ row, mutate }) => {
|
|||||||
<>
|
<>
|
||||||
{!row.original.mileage && <EditViolation row={row} mutate={mutate} rowId={row.getValue("id")} />}
|
{!row.original.mileage && <EditViolation row={row} mutate={mutate} rowId={row.getValue("id")} />}
|
||||||
{/*{canEdit && <CreateWithoutProcess row={row} mutate={mutate} />}*/}
|
{/*{canEdit && <CreateWithoutProcess row={row} mutate={mutate} />}*/}
|
||||||
|
<DeleteViolation />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,23 +61,6 @@ const ViolationsList = () => {
|
|||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "status",
|
|
||||||
header: "وضعیت",
|
|
||||||
id: "status",
|
|
||||||
enableColumnFilter: true,
|
|
||||||
datatype: "numeric",
|
|
||||||
filterMode: "equals",
|
|
||||||
sortDescFirst: true,
|
|
||||||
grow: false,
|
|
||||||
columnSelectOption: () => {
|
|
||||||
return violationsCategoryStatus.map((category) => ({
|
|
||||||
value: category.id,
|
|
||||||
label: category.name_fa,
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "machine_code",
|
accessorKey: "machine_code",
|
||||||
header: "کد خودرو",
|
header: "کد خودرو",
|
||||||
@@ -142,16 +125,6 @@ const ViolationsList = () => {
|
|||||||
grow: false,
|
grow: false,
|
||||||
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "mission_id",
|
|
||||||
header: "کد ماموریت",
|
|
||||||
id: "mission_id",
|
|
||||||
enableColumnFilter: false,
|
|
||||||
datatype: "numeric",
|
|
||||||
filterMode: "equals",
|
|
||||||
grow: false,
|
|
||||||
Cell: ({ row }) => row.original.mission_id || "-",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "request_date",
|
accessorKey: "request_date",
|
||||||
header: "تاریخ تخلف",
|
header: "تاریخ تخلف",
|
||||||
|
|||||||
@@ -249,14 +249,14 @@ export const FINISH_MISSION = api + "/api/v3/missions/control_unit/finish";
|
|||||||
export const GET_ROAD_MISSIONS_VIOLATIONS_LIST = api + "/api/v3/missions/violation_management";
|
export const GET_ROAD_MISSIONS_VIOLATIONS_LIST = api + "/api/v3/missions/violation_management";
|
||||||
export const GET_MISSION_PROVINCE_ACTIVITY_REPORT = api + "/api/v3/missions/report/country_activity";
|
export const GET_MISSION_PROVINCE_ACTIVITY_REPORT = api + "/api/v3/missions/report/country_activity";
|
||||||
export const GET_MISSION_CITY_ACTIVITY_REPORT = api + "/api/v3/missions/report/country_activity";
|
export const GET_MISSION_CITY_ACTIVITY_REPORT = api + "/api/v3/missions/report/country_activity";
|
||||||
export const GET_MACHINES_COUNTRY_ACTIVITY_REPORT = api + "/api/v3/missions/report_machine/country_machines_activity";
|
export const GET_MACHINES_ACTIVITY_REPORT = api + "/api/v3/missions/report_machine/machines_activity";
|
||||||
export const GET_MACHINES_PROVINCE_ACTIVITY_REPORT = api + "/api/v3/missions/report_machine/province_machines_activity";
|
export const GET_MACHINES_PROVINCE_ACTIVITY_REPORT = api + "/api/v3/missions/report_machine/province_machines_activity";
|
||||||
export const EXPORT_GET_MACHINES_COUNTRY_ACTIVITY_REPORT =
|
export const EXPORT_GET_MACHINES_COUNTRY_ACTIVITY_REPORT =
|
||||||
api + "/api/v3/missions/report_machine/country_machines_activity_excel";
|
api + "/api/v3/missions/report_machine/country_machines_activity_excel";
|
||||||
export const EXPORT_GET_MACHINES_PROVINCE_ACTIVITY_REPORT =
|
export const EXPORT_GET_MACHINES_PROVINCE_ACTIVITY_REPORT =
|
||||||
api + "/api/v3/missions/report_machine/province_machines_activity_excel";
|
api + "/api/v3/missions/report_machine/province_machines_activity_excel";
|
||||||
|
|
||||||
export const GET_DRIVER_COUNTRY_ACTIVITY_REPORT =
|
export const GET_DRIVERS_ACTIVITY_REPORT =
|
||||||
api + "/api/v3/missions/report_machine/country_machine_drivers_activity";
|
api + "/api/v3/missions/report_machine/country_machine_drivers_activity";
|
||||||
export const GET_DRIVER_PROVINCE_ACTIVITY_REPORT =
|
export const GET_DRIVER_PROVINCE_ACTIVITY_REPORT =
|
||||||
api + "/api/v3/missions/report_machine/province_machine_drivers_activity";
|
api + "/api/v3/missions/report_machine/province_machine_drivers_activity";
|
||||||
@@ -275,6 +275,7 @@ export const EXPORT_GET_MACHINES_TYPE_PROVINCE_ACTIVITY_REPORT =
|
|||||||
api + "/api/v3/missions/report_machine/province_machine_types_activity_excel";
|
api + "/api/v3/missions/report_machine/province_machine_types_activity_excel";
|
||||||
export const CREATE_VIOLATION = api + "/api/v3/missions/violation_management";
|
export const CREATE_VIOLATION = api + "/api/v3/missions/violation_management";
|
||||||
export const EDIT_VIOLATION = api + "/api/v3/missions/violation_management";
|
export const EDIT_VIOLATION = api + "/api/v3/missions/violation_management";
|
||||||
|
export const DELETE_VIOLATION = api + "/api/v3/missions/violation_management";
|
||||||
export const EXPORT_COUNTRY_ROAD_MISSIONS_REPORTS = api + "/api/v3/missions/report/country_excel_activity";
|
export const EXPORT_COUNTRY_ROAD_MISSIONS_REPORTS = api + "/api/v3/missions/report/country_excel_activity";
|
||||||
export const EXPORT_PROVINCE_ROAD_MISSIONS_REPORTS = api + "/api/v3/missions/report/province_excel_activity";
|
export const EXPORT_PROVINCE_ROAD_MISSIONS_REPORTS = api + "/api/v3/missions/report/province_excel_activity";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user