add driver rate
This commit is contained in:
@@ -32,6 +32,11 @@ const validationSchema = object({
|
|||||||
province_id: number().required("لطفا استان را وارد کنید!!!"),
|
province_id: number().required("لطفا استان را وارد کنید!!!"),
|
||||||
city_id: number().required("لطفا شهرستان را وارد کنید!!!"),
|
city_id: number().required("لطفا شهرستان را وارد کنید!!!"),
|
||||||
axis_name: string().required("لطفا نام محور را وارد کنید!!!"),
|
axis_name: string().required("لطفا نام محور را وارد کنید!!!"),
|
||||||
|
driver_rate: number()
|
||||||
|
.typeError("سهم راننده باید یک عدد باشد")
|
||||||
|
.required("لطفا سهم راننده را وارد کنید!!!")
|
||||||
|
.min(0, "سهم راننده نمیتواند کمتر از ۰ باشد")
|
||||||
|
.max(100, "سهم راننده نمیتواند بیشتر از ۱۰۰ باشد"),
|
||||||
driver_name: string().when("isForeign", {
|
driver_name: string().when("isForeign", {
|
||||||
is: "0",
|
is: "0",
|
||||||
then: (schema) => schema.required("لطفا نام و نام خانوادگی را وارد کنید!!!"),
|
then: (schema) => schema.required("لطفا نام و نام خانوادگی را وارد کنید!!!"),
|
||||||
@@ -111,6 +116,7 @@ const CreateFormContent = ({ setOpen, SubmitDamage, defaultData }) => {
|
|||||||
plate_part2: defaultData.plate_part2,
|
plate_part2: defaultData.plate_part2,
|
||||||
plate_part3: defaultData.plate_part3,
|
plate_part3: defaultData.plate_part3,
|
||||||
plate_part4: defaultData.plate_part4,
|
plate_part4: defaultData.plate_part4,
|
||||||
|
driver_rate: defaultData.driver_rate,
|
||||||
radio_button: defaultData.radio_button,
|
radio_button: defaultData.radio_button,
|
||||||
damage_picture1: defaultData.damage_picture1,
|
damage_picture1: defaultData.damage_picture1,
|
||||||
damage_picture2: defaultData.damage_picture2,
|
damage_picture2: defaultData.damage_picture2,
|
||||||
@@ -169,7 +175,7 @@ const CreateFormContent = ({ setOpen, SubmitDamage, defaultData }) => {
|
|||||||
"damage_picture2",
|
"damage_picture2",
|
||||||
];
|
];
|
||||||
} else if (tabState === 1) {
|
} else if (tabState === 1) {
|
||||||
fieldsToValidate = ["report_base", "police_file", "police_file_date", "police_serial"];
|
fieldsToValidate = ["report_base", "police_file", "police_file_date", "police_serial", 'driver_rate'];
|
||||||
} else if (tabState === 2) {
|
} else if (tabState === 2) {
|
||||||
fieldsToValidate = ["items_damage"];
|
fieldsToValidate = ["items_damage"];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FormControlLabel, RadioGroup, Stack } from "@mui/material";
|
import { FormControlLabel, RadioGroup, Stack, TextField } from "@mui/material";
|
||||||
import { Controller, useWatch } from "react-hook-form";
|
import { Controller, useWatch } from "react-hook-form";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import PoliceFileReport from "./PoliceFileReport";
|
import PoliceFileReport from "./PoliceFileReport";
|
||||||
@@ -7,14 +7,45 @@ import Radio from "@mui/material/Radio";
|
|||||||
const DamageReport = ({ control }) => {
|
const DamageReport = ({ control }) => {
|
||||||
const watchedStatus = useWatch({ control, name: "radio_button" });
|
const watchedStatus = useWatch({ control, name: "radio_button" });
|
||||||
const [selectedOption, setSelectedOption] = useState(watchedStatus || null);
|
const [selectedOption, setSelectedOption] = useState(watchedStatus || null);
|
||||||
// const [selectedOption, setSelectedOption] = useState("report_base");
|
|
||||||
|
|
||||||
const handleOptionChange = (e) => {
|
const handleOptionChange = (e) => {
|
||||||
setSelectedOption(e.target.value);
|
setSelectedOption(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Stack alignItems={"center"} justifyContent={"center"}>
|
||||||
|
<Controller
|
||||||
|
name="driver_rate"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<TextField
|
||||||
|
value={field.value}
|
||||||
|
variant="outlined"
|
||||||
|
name="driver_rate"
|
||||||
|
type={"tel"}
|
||||||
|
inputProps={{
|
||||||
|
inputMode: "number",
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
pattern: "[0-9]*",
|
||||||
|
}}
|
||||||
|
onChange={(event) => {
|
||||||
|
const inputValue = event.target.value;
|
||||||
|
if (isNaN(Number(inputValue))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.onChange(inputValue);
|
||||||
|
}}
|
||||||
|
label="سهم راننده از خسارت (درصد)"
|
||||||
|
placeholder={"سهم راننده از خسارت را وارد کنید"}
|
||||||
|
sx={{ width: 300, my: 2 }}
|
||||||
|
size="small"
|
||||||
|
error={error}
|
||||||
|
helperText={error?.message}
|
||||||
|
InputLabelProps={{ shrink: true }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
aria-label="file-options"
|
aria-label="file-options"
|
||||||
name="file-options"
|
name="file-options"
|
||||||
@@ -45,7 +76,7 @@ const DamageReport = ({ control }) => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
{selectedOption === "police_file_checkbox" && <PoliceFileReport control={control} />}
|
{selectedOption === "police_file_checkbox" && <PoliceFileReport control={control} />}
|
||||||
</>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default DamageReport;
|
export default DamageReport;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const OperatorCreateForm = ({ open, setOpen, mutate }) => {
|
|||||||
formData.append("driver_national_code", result.national_code);
|
formData.append("driver_national_code", result.national_code);
|
||||||
formData.append("plaque", PlateNumber);
|
formData.append("plaque", PlateNumber);
|
||||||
}
|
}
|
||||||
|
formData.append("driver_rate", result.driver_rate);
|
||||||
formData.append("damage_picture1", result.damage_picture1);
|
formData.append("damage_picture1", result.damage_picture1);
|
||||||
formData.append("damage_picture2", result.damage_picture2);
|
formData.append("damage_picture2", result.damage_picture2);
|
||||||
formData.append("lat", result.start_point.lat);
|
formData.append("lat", result.start_point.lat);
|
||||||
@@ -54,7 +55,7 @@ const OperatorCreateForm = ({ open, setOpen, mutate }) => {
|
|||||||
mutate();
|
mutate();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => { });
|
||||||
};
|
};
|
||||||
const defaultData = {
|
const defaultData = {
|
||||||
isForeign: "0",
|
isForeign: "0",
|
||||||
@@ -72,6 +73,7 @@ const OperatorCreateForm = ({ open, setOpen, mutate }) => {
|
|||||||
plate_part2: "الف",
|
plate_part2: "الف",
|
||||||
plate_part3: "",
|
plate_part3: "",
|
||||||
plate_part4: "",
|
plate_part4: "",
|
||||||
|
driver_rate: "",
|
||||||
radio_button: "report_base",
|
radio_button: "report_base",
|
||||||
damage_picture1: null,
|
damage_picture1: null,
|
||||||
damage_picture2: null,
|
damage_picture2: null,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { CHECK_PAYMENT_STATUS, CREATE_FACTOR_DAMAGE, SEND_SMS_AGAIN } from "@/core/utils/routes";
|
import { CHECK_PAYMENT_STATUS, CREATE_FACTOR_DAMAGE, SEND_SMS_AGAIN } from "@/core/utils/routes";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
|
import { Person } from "@mui/icons-material";
|
||||||
import PaymentIcon from "@mui/icons-material/Payment";
|
import PaymentIcon from "@mui/icons-material/Payment";
|
||||||
import ReceiptLongIcon from "@mui/icons-material/ReceiptLong";
|
import ReceiptLongIcon from "@mui/icons-material/ReceiptLong";
|
||||||
import RequestQuoteIcon from "@mui/icons-material/RequestQuote";
|
import RequestQuoteIcon from "@mui/icons-material/RequestQuote";
|
||||||
@@ -96,6 +97,23 @@ const CreateFactorContent = ({ row, mutate, rowId, setOpenCreateFactorDialog })
|
|||||||
{(row.original?.sum / 1).toLocaleString() || "0"} ریال
|
{(row.original?.sum / 1).toLocaleString() || "0"} ریال
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={12} sx={{ display: "flex", alignItems: "center" }}>
|
||||||
|
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||||
|
<Chip
|
||||||
|
icon={<Person />}
|
||||||
|
label={
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 600, color: "grey.700" }}>
|
||||||
|
سهم راننده از خسارت
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Divider sx={{ flex: 1, mx: 2 }} />
|
||||||
|
<Typography variant="body2" sx={{ fontWeight: 600, color: "grey.800" }}>
|
||||||
|
{(row.original?.driver_share_amount / 1).toLocaleString() || "0"} ریال
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={12} sx={{ display: "flex" }}><Divider sx={{ flex: 1 }} /></Grid>
|
||||||
<Grid item xs={12} sm={12} sx={{ display: "flex", alignItems: "center" }}>
|
<Grid item xs={12} sm={12} sx={{ display: "flex", alignItems: "center" }}>
|
||||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||||
<Chip
|
<Chip
|
||||||
@@ -142,7 +160,7 @@ const CreateFactorContent = ({ row, mutate, rowId, setOpenCreateFactorDialog })
|
|||||||
<Divider sx={{ flex: 1, mx: 2 }} />
|
<Divider sx={{ flex: 1, mx: 2 }} />
|
||||||
<Typography variant="h5" sx={{ fontWeight: 600, color: "primary.main" }}>
|
<Typography variant="h5" sx={{ fontWeight: 600, color: "primary.main" }}>
|
||||||
{(
|
{(
|
||||||
row.original?.sum -
|
row.original?.driver_share_amount -
|
||||||
(row.original?.deposit_insurance_amount + row.original?.deposit_daghi_amount)
|
(row.original?.deposit_insurance_amount + row.original?.deposit_daghi_amount)
|
||||||
).toLocaleString() || "0"}{" "}
|
).toLocaleString() || "0"}{" "}
|
||||||
ریال
|
ریال
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ const EditController = ({ rowId, mutate, setOpenEditDialog }) => {
|
|||||||
plate_part2: plaqueNumber[1] || "",
|
plate_part2: plaqueNumber[1] || "",
|
||||||
plate_part3: plaqueNumber[2] || "",
|
plate_part3: plaqueNumber[2] || "",
|
||||||
plate_part4: plaqueNumber[3] || "",
|
plate_part4: plaqueNumber[3] || "",
|
||||||
|
driver_rate: damageItemDetails?.driver_rate,
|
||||||
radio_button: damageItemDetails?.report_base === 1 ? "report_base" : "police_file_checkbox",
|
radio_button: damageItemDetails?.report_base === 1 ? "report_base" : "police_file_checkbox",
|
||||||
report_base: damageItemDetails?.report_base,
|
report_base: damageItemDetails?.report_base,
|
||||||
province_id: damageItemDetails?.province_id || null,
|
province_id: damageItemDetails?.province_id || null,
|
||||||
@@ -70,6 +71,7 @@ const EditController = ({ rowId, mutate, setOpenEditDialog }) => {
|
|||||||
formData.append("city_id", result.city_id);
|
formData.append("city_id", result.city_id);
|
||||||
formData.append("axis_name", result.axis_name);
|
formData.append("axis_name", result.axis_name);
|
||||||
formData.append("is_foreign", result.isForeign);
|
formData.append("is_foreign", result.isForeign);
|
||||||
|
formData.append("driver_rate", result.driver_rate);
|
||||||
if (result.isForeign == "0") {
|
if (result.isForeign == "0") {
|
||||||
formData.append("driver_name", result.driver_name);
|
formData.append("driver_name", result.driver_name);
|
||||||
formData.append("driver_phone_number", result.phone_number);
|
formData.append("driver_phone_number", result.phone_number);
|
||||||
@@ -103,7 +105,7 @@ const EditController = ({ rowId, mutate, setOpenEditDialog }) => {
|
|||||||
mutate();
|
mutate();
|
||||||
setOpenEditDialog(false);
|
setOpenEditDialog(false);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => { });
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ const validationSchema = object({
|
|||||||
then: (schema) => schema.required("مبلغ داغی الزامی است."),
|
then: (schema) => schema.required("مبلغ داغی الزامی است."),
|
||||||
otherwise: (schema) => schema.notRequired(),
|
otherwise: (schema) => schema.notRequired(),
|
||||||
})
|
})
|
||||||
.test("max-percentage", "مبلغ داغی نباید بیشتر از ۳۰ درصد مبلغ کل خسارت باشد.", function (value) {
|
.test("max-percentage", "مبلغ داغی نباید بیشتر از ۳۰ درصد مبلغ کل سهم راننده از خسارت باشد.", function (value) {
|
||||||
const sum = this.options.context.sum || 0;
|
const driver_share_amount = this.options.context.driver_share_amount || 0;
|
||||||
if (!value || isNaN(value) || !sum) return true;
|
if (!value || isNaN(value) || !driver_share_amount) return true;
|
||||||
return parseFloat(value) <= sum * 0.3;
|
return parseFloat(value) <= driver_share_amount * 0.3;
|
||||||
}),
|
}),
|
||||||
deposit_daghi_image: mixed().when("deposit_daghi_status", {
|
deposit_daghi_image: mixed().when("deposit_daghi_status", {
|
||||||
is: "has_daghi",
|
is: "has_daghi",
|
||||||
@@ -52,10 +52,10 @@ const validationSchema = object({
|
|||||||
otherwise: (schema) => schema.notRequired(),
|
otherwise: (schema) => schema.notRequired(),
|
||||||
}),
|
}),
|
||||||
}).test("total-amount-limit", "مجموع مبلغ بیمه و داغی نباید از کل مبلغ خسارت بیشتر باشد.", function (values) {
|
}).test("total-amount-limit", "مجموع مبلغ بیمه و داغی نباید از کل مبلغ خسارت بیشتر باشد.", function (values) {
|
||||||
const sum = this.options.context.sum || 0;
|
const driver_share_amount = this.options.context.driver_share_amount || 0;
|
||||||
const depositInsuranceAmount = parseFloat(values.deposit_insurance_amount) || 0;
|
const depositInsuranceAmount = parseFloat(values.deposit_insurance_amount) || 0;
|
||||||
const depositDaghiAmount = parseFloat(values.deposit_daghi_amount) || 0;
|
const depositDaghiAmount = parseFloat(values.deposit_daghi_amount) || 0;
|
||||||
return depositInsuranceAmount + depositDaghiAmount <= sum;
|
return depositInsuranceAmount + depositDaghiAmount <= driver_share_amount;
|
||||||
});
|
});
|
||||||
|
|
||||||
const RegisterInsuranceContent = ({ setOpenRegisterInsuranceDialog, row, mutate, rowId }) => {
|
const RegisterInsuranceContent = ({ setOpenRegisterInsuranceDialog, row, mutate, rowId }) => {
|
||||||
@@ -103,7 +103,7 @@ const RegisterInsuranceContent = ({ setOpenRegisterInsuranceDialog, row, mutate,
|
|||||||
defaultValues,
|
defaultValues,
|
||||||
resolver: yupResolver(validationSchema),
|
resolver: yupResolver(validationSchema),
|
||||||
mode: "all",
|
mode: "all",
|
||||||
context: { sum: row?.original?.sum },
|
context: { driver_share_amount: row?.original?.driver_share_amount },
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmitBase = async (data) => {
|
const onSubmitBase = async (data) => {
|
||||||
@@ -127,7 +127,7 @@ const RegisterInsuranceContent = ({ setOpenRegisterInsuranceDialog, row, mutate,
|
|||||||
});
|
});
|
||||||
mutate();
|
mutate();
|
||||||
setOpenRegisterInsuranceDialog(false);
|
setOpenRegisterInsuranceDialog(false);
|
||||||
} catch (error) {}
|
} catch (error) { }
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<StyledForm onSubmit={handleSubmit(onSubmitBase)}>
|
<StyledForm onSubmit={handleSubmit(onSubmitBase)}>
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ const OperatorList = () => {
|
|||||||
props.dependencyFieldValue?.value === ""
|
props.dependencyFieldValue?.value === ""
|
||||||
? "empty"
|
? "empty"
|
||||||
: loadingCityList
|
: loadingCityList
|
||||||
? "loading"
|
? "loading"
|
||||||
: props.filterParameters.value
|
: props.filterParameters.value
|
||||||
}
|
}
|
||||||
columnSelectOption={getColumnSelectOptions}
|
columnSelectOption={getColumnSelectOptions}
|
||||||
/>
|
/>
|
||||||
@@ -421,6 +421,30 @@ const OperatorList = () => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
header: "سهم راننده (درصد)",
|
||||||
|
id: "driver_rate",
|
||||||
|
enableColumnFilter: false,
|
||||||
|
grow: false,
|
||||||
|
size: 100,
|
||||||
|
Cell: ({ row }) => (
|
||||||
|
<Typography variant={"body2"} sx={{ margin: 1 }} component="span">
|
||||||
|
{(row.original.driver_rate / 1).toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "سهم راننده (ریال)",
|
||||||
|
id: "driver_share_amount",
|
||||||
|
enableColumnFilter: false,
|
||||||
|
grow: false,
|
||||||
|
size: 100,
|
||||||
|
Cell: ({ row }) => (
|
||||||
|
<Typography variant={"body2"} sx={{ margin: 1 }} component="span">
|
||||||
|
{(row.original.driver_share_amount / 1).toLocaleString()}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user