add: one time purchase limit
This commit is contained in:
@@ -70,7 +70,7 @@ export const AddQuota = ({ item, getData }: Props) => {
|
|||||||
const handleSubmitForm = async () => {
|
const handleSubmitForm = async () => {
|
||||||
if (item && item?.quota_distributed > 0) {
|
if (item && item?.quota_distributed > 0) {
|
||||||
const confirmed = await showConfirmToast(
|
const confirmed = await showConfirmToast(
|
||||||
"اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!"
|
"اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!",
|
||||||
);
|
);
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
return;
|
return;
|
||||||
@@ -96,15 +96,16 @@ export const AddQuota = ({ item, getData }: Props) => {
|
|||||||
broker_data: formData?.broker_data,
|
broker_data: formData?.broker_data,
|
||||||
pos_sale_type: formData?.pos_sale_type,
|
pos_sale_type: formData?.pos_sale_type,
|
||||||
livestock_allocation_data: formData?.livestockTypes?.filter(
|
livestock_allocation_data: formData?.livestockTypes?.filter(
|
||||||
(opt: { quantity_kg: number }) => opt?.quantity_kg > 0
|
(opt: { quantity_kg: number }) => opt?.quantity_kg > 0,
|
||||||
),
|
),
|
||||||
livestock_age_limitations: formData?.livestock_age_limitations,
|
livestock_age_limitations: formData?.livestock_age_limitations,
|
||||||
pre_sale: formData?.pre_sale,
|
pre_sale: formData?.pre_sale,
|
||||||
free_sale: formData?.free_sale,
|
free_sale: formData?.free_sale,
|
||||||
|
one_time_purchase_limit: formData?.one_time_purchase_limit,
|
||||||
};
|
};
|
||||||
|
|
||||||
let filterEmptyKeys = Object.fromEntries(
|
let filterEmptyKeys = Object.fromEntries(
|
||||||
Object.entries(submitData).filter(([, v]) => v != null)
|
Object.entries(submitData).filter(([, v]) => v != null),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -24,13 +24,17 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
const internalRef = useRef<HTMLFormElement>(null);
|
const internalRef = useRef<HTMLFormElement>(null);
|
||||||
|
|
||||||
const [limitByHerdSize, setLimitByHerdSize] = useState(
|
const [limitByHerdSize, setLimitByHerdSize] = useState(
|
||||||
item?.limit_by_herd_size || false
|
item?.limit_by_herd_size || false,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [preSale, setPreSale] = useState(item?.pre_sale || false);
|
const [preSale, setPreSale] = useState(item?.pre_sale || false);
|
||||||
|
|
||||||
const [freeSale, setFreeSale] = useState(item?.free_sale || false);
|
const [freeSale, setFreeSale] = useState(item?.free_sale || false);
|
||||||
|
|
||||||
|
const [oneTimePurchase, setOneTimePurchase] = useState(
|
||||||
|
item?.one_time_purchase_limit || false,
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
setFormRef(internalRef.current);
|
setFormRef(internalRef.current);
|
||||||
@@ -66,7 +70,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
(option: any) =>
|
(option: any) =>
|
||||||
option?.livestock_type?.weight_type === allocate?.weight_type &&
|
option?.livestock_type?.weight_type === allocate?.weight_type &&
|
||||||
option?.livestock_type?.id === allocate?.id &&
|
option?.livestock_type?.id === allocate?.id &&
|
||||||
option?.livestock_type?.name === allocate?.name
|
option?.livestock_type?.name === allocate?.name,
|
||||||
);
|
);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result.age_month;
|
return result.age_month;
|
||||||
@@ -105,6 +109,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
}),
|
}),
|
||||||
pre_sale: preSale,
|
pre_sale: preSale,
|
||||||
free_sale: freeSale,
|
free_sale: freeSale,
|
||||||
|
one_time_purchase_limit: oneTimePurchase,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -234,7 +239,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
const originalIndex = livestockTypes.findIndex(
|
const originalIndex = livestockTypes.findIndex(
|
||||||
(type) =>
|
(type) =>
|
||||||
type.livestock_type === item.livestock_type &&
|
type.livestock_type === item.livestock_type &&
|
||||||
type.weight_type === item.weight_type
|
type.weight_type === item.weight_type,
|
||||||
);
|
);
|
||||||
if (originalIndex !== -1) {
|
if (originalIndex !== -1) {
|
||||||
handleLivestockTypeChange(originalIndex, value);
|
handleLivestockTypeChange(originalIndex, value);
|
||||||
@@ -268,7 +273,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
const originalIndex = livestockTypes.findIndex(
|
const originalIndex = livestockTypes.findIndex(
|
||||||
(type) =>
|
(type) =>
|
||||||
type.livestock_type === item.livestock_type &&
|
type.livestock_type === item.livestock_type &&
|
||||||
type.weight_type === item.weight_type
|
type.weight_type === item.weight_type,
|
||||||
);
|
);
|
||||||
if (originalIndex !== -1) {
|
if (originalIndex !== -1) {
|
||||||
handleLivestockTypeChange(originalIndex, value);
|
handleLivestockTypeChange(originalIndex, value);
|
||||||
@@ -301,6 +306,16 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<Grid className="flex gap-2 p-2 border-1 border-gray-200 rounded-xl items-center">
|
||||||
|
<Checkbox
|
||||||
|
label="محدودیت یکبار خرید از سهیمه"
|
||||||
|
checked={oneTimePurchase}
|
||||||
|
onChange={() => {
|
||||||
|
setOneTimePurchase(!oneTimePurchase);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -129,8 +129,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
group === "rural"
|
group === "rural"
|
||||||
? "روستایی"
|
? "روستایی"
|
||||||
: group === "industrial"
|
: group === "industrial"
|
||||||
? "صنعتی"
|
? "صنعتی"
|
||||||
: "عشایری"
|
: "عشایری",
|
||||||
)
|
)
|
||||||
.join(", ") || "-"
|
.join(", ") || "-"
|
||||||
}
|
}
|
||||||
@@ -145,10 +145,10 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
item?.pos_sale_type === "all"
|
item?.pos_sale_type === "all"
|
||||||
? "بر اساس تعداد راس دام و وزن"
|
? "بر اساس تعداد راس دام و وزن"
|
||||||
: item?.pos_sale_type === "weight"
|
: item?.pos_sale_type === "weight"
|
||||||
? "بر اساس وزن"
|
? "بر اساس وزن"
|
||||||
: item?.pos_sale_type === "count"
|
: item?.pos_sale_type === "count"
|
||||||
? "بر اساس تعداد راس دام"
|
? "بر اساس تعداد راس دام"
|
||||||
: "-"
|
: "-"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -202,8 +202,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
acc[group].push(allocation);
|
acc[group].push(allocation);
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as Record<string, any[]>
|
{} as Record<string, any[]>,
|
||||||
)
|
),
|
||||||
) as [string, any[]][]
|
) as [string, any[]][]
|
||||||
).map(([group, allocations]) => (
|
).map(([group, allocations]) => (
|
||||||
<div key={group} className="space-y-2">
|
<div key={group} className="space-y-2">
|
||||||
@@ -215,8 +215,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
{group === "rural"
|
{group === "rural"
|
||||||
? "روستایی"
|
? "روستایی"
|
||||||
: group === "industrial"
|
: group === "industrial"
|
||||||
? "صنعتی"
|
? "صنعتی"
|
||||||
: "سایر"}
|
: "سایر"}
|
||||||
</Typography>
|
</Typography>
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
|
<table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
|
||||||
@@ -296,6 +296,13 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<div>
|
||||||
|
<Typography variant="body1" sign="info" className="mb-2">
|
||||||
|
محدودیت یکبار خرید از سهیمه:{" "}
|
||||||
|
{item?.one_time_purchase_limit ? "دارد" : "ندارد"}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
<Divider />
|
||||||
<div>
|
<div>
|
||||||
<Typography
|
<Typography
|
||||||
variant="body2"
|
variant="body2"
|
||||||
@@ -308,7 +315,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
<ShowStringList
|
<ShowStringList
|
||||||
showSearch={false}
|
showSearch={false}
|
||||||
strings={item?.limit_by_organizations?.map(
|
strings={item?.limit_by_organizations?.map(
|
||||||
(opt: { name: string }) => opt?.name
|
(opt: { name: string }) => opt?.name,
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -341,7 +348,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
opt?.livestock_type?.weight_type === "L"
|
opt?.livestock_type?.weight_type === "L"
|
||||||
? "سبک"
|
? "سبک"
|
||||||
: "سنگین"
|
: "سنگین"
|
||||||
}) با سن ${opt?.age_month}`
|
}) با سن ${opt?.age_month}`,
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -423,7 +430,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
),
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -453,7 +460,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
pricing_type_name: string;
|
pricing_type_name: string;
|
||||||
name: string;
|
name: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
},
|
||||||
) => {
|
) => {
|
||||||
const key = itm.pricing_type_name;
|
const key = itm.pricing_type_name;
|
||||||
if (acc[key]) {
|
if (acc[key]) {
|
||||||
@@ -463,8 +470,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as Record<string, any>
|
{} as Record<string, any>,
|
||||||
)
|
),
|
||||||
).map((priceItem: any, priceIndex: number) => (
|
).map((priceItem: any, priceIndex: number) => (
|
||||||
<div
|
<div
|
||||||
key={priceIndex}
|
key={priceIndex}
|
||||||
@@ -499,8 +506,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
|
|||||||
acc[key].push(itm);
|
acc[key].push(itm);
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as Record<string, any[]>
|
{} as Record<string, any[]>,
|
||||||
)
|
),
|
||||||
) as [string, any[]][]
|
) as [string, any[]][]
|
||||||
).map(([pricingTypeName, items]) => (
|
).map(([pricingTypeName, items]) => (
|
||||||
<div key={pricingTypeName} className="space-y-2">
|
<div key={pricingTypeName} className="space-y-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user