add: one time purchase limit

This commit is contained in:
2026-02-15 10:17:42 +03:30
parent c0b8472c72
commit abe53b885a
3 changed files with 48 additions and 25 deletions

View File

@@ -70,7 +70,7 @@ export const AddQuota = ({ item, getData }: Props) => {
const handleSubmitForm = async () => {
if (item && item?.quota_distributed > 0) {
const confirmed = await showConfirmToast(
"اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!"
"اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!",
);
if (!confirmed) {
return;
@@ -96,15 +96,16 @@ export const AddQuota = ({ item, getData }: Props) => {
broker_data: formData?.broker_data,
pos_sale_type: formData?.pos_sale_type,
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,
pre_sale: formData?.pre_sale,
free_sale: formData?.free_sale,
one_time_purchase_limit: formData?.one_time_purchase_limit,
};
let filterEmptyKeys = Object.fromEntries(
Object.entries(submitData).filter(([, v]) => v != null)
Object.entries(submitData).filter(([, v]) => v != null),
);
try {

View File

@@ -24,13 +24,17 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
const internalRef = useRef<HTMLFormElement>(null);
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 [freeSale, setFreeSale] = useState(item?.free_sale || false);
const [oneTimePurchase, setOneTimePurchase] = useState(
item?.one_time_purchase_limit || false,
);
useEffect(() => {
if (visible) {
setFormRef(internalRef.current);
@@ -66,7 +70,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
(option: any) =>
option?.livestock_type?.weight_type === allocate?.weight_type &&
option?.livestock_type?.id === allocate?.id &&
option?.livestock_type?.name === allocate?.name
option?.livestock_type?.name === allocate?.name,
);
if (result) {
return result.age_month;
@@ -105,6 +109,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
}),
pre_sale: preSale,
free_sale: freeSale,
one_time_purchase_limit: oneTimePurchase,
};
if (
@@ -234,7 +239,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
const originalIndex = livestockTypes.findIndex(
(type) =>
type.livestock_type === item.livestock_type &&
type.weight_type === item.weight_type
type.weight_type === item.weight_type,
);
if (originalIndex !== -1) {
handleLivestockTypeChange(originalIndex, value);
@@ -268,7 +273,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
const originalIndex = livestockTypes.findIndex(
(type) =>
type.livestock_type === item.livestock_type &&
type.weight_type === item.weight_type
type.weight_type === item.weight_type,
);
if (originalIndex !== -1) {
handleLivestockTypeChange(originalIndex, value);
@@ -301,6 +306,16 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => {
}}
/>
</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>
</form>

View File

@@ -129,8 +129,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
group === "rural"
? "روستایی"
: group === "industrial"
? "صنعتی"
: "عشایری"
? "صنعتی"
: "عشایری",
)
.join(", ") || "-"
}
@@ -145,10 +145,10 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
item?.pos_sale_type === "all"
? "بر اساس تعداد راس دام و وزن"
: item?.pos_sale_type === "weight"
? "بر اساس وزن"
: item?.pos_sale_type === "count"
? "بر اساس تعداد راس دام"
: "-"
? "بر اساس وزن"
: item?.pos_sale_type === "count"
? "بر اساس تعداد راس دام"
: "-"
}
/>
</div>
@@ -202,8 +202,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
acc[group].push(allocation);
return acc;
},
{} as Record<string, any[]>
)
{} as Record<string, any[]>,
),
) as [string, any[]][]
).map(([group, allocations]) => (
<div key={group} className="space-y-2">
@@ -215,8 +215,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
{group === "rural"
? "روستایی"
: group === "industrial"
? "صنعتی"
: "سایر"}
? "صنعتی"
: "سایر"}
</Typography>
<div className="overflow-x-auto">
<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>
</div>
<Divider />
<div>
<Typography variant="body1" sign="info" className="mb-2">
محدودیت یکبار خرید از سهیمه:{" "}
{item?.one_time_purchase_limit ? "دارد" : "ندارد"}
</Typography>
</div>
<Divider />
<div>
<Typography
variant="body2"
@@ -308,7 +315,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
<ShowStringList
showSearch={false}
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?.age_month}`
}) با سن ${opt?.age_month}`,
)}
/>
) : (
@@ -423,7 +430,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
</Typography>
</div>
</div>
)
),
)}
</div>
)}
@@ -453,7 +460,7 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
pricing_type_name: string;
name: string;
value: number;
}
},
) => {
const key = itm.pricing_type_name;
if (acc[key]) {
@@ -463,8 +470,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
}
return acc;
},
{} as Record<string, any>
)
{} as Record<string, any>,
),
).map((priceItem: any, priceIndex: number) => (
<div
key={priceIndex}
@@ -499,8 +506,8 @@ export const QuotaView: React.FC<QuotaViewProps> = ({ item }) => {
acc[key].push(itm);
return acc;
},
{} as Record<string, any[]>
)
{} as Record<string, any[]>,
),
) as [string, any[]][]
).map(([pricingTypeName, items]) => (
<div key={pricingTypeName} className="space-y-2">