hotfix/2026-02-02 - Parts order manual discounting box
This commit is contained in:
@@ -1,94 +1,121 @@
|
|||||||
import { DownOutlined } from "@ant-design/icons";
|
import { DownOutlined } from "@ant-design/icons";
|
||||||
import { Dropdown, InputNumber, Space } from "antd";
|
import { Button, Divider, Dropdown, InputNumber, Space, theme } from "antd";
|
||||||
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
|
|
||||||
|
const DISCOUNT_PRESETS = [5, 10, 15, 20, 25, 40];
|
||||||
|
|
||||||
export default function PartsOrderModalPriceChange({ form, field }) {
|
export default function PartsOrderModalPriceChange({ form, field }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const menu = {
|
const { token } = theme.useToken();
|
||||||
items: [
|
|
||||||
{
|
|
||||||
key: "5",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "5%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "10",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "10%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "15",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "15%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "20",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "20%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "25",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "25%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "40",
|
|
||||||
label: t("parts_orders.labels.discount", { percent: "40%" })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "custom",
|
|
||||||
label: (
|
|
||||||
<Space.Compact>
|
|
||||||
<InputNumber
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
onKeyUp={(e) => {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
const values = form.getFieldsValue();
|
|
||||||
const { parts_order_lines } = values;
|
|
||||||
|
|
||||||
form.setFieldsValue({
|
const [open, setOpen] = useState(false);
|
||||||
parts_order_lines: {
|
const [customPercent, setCustomPercent] = useState(0);
|
||||||
data: parts_order_lines.data.map((p, idx) => {
|
|
||||||
if (idx !== field.name) return p;
|
const applyDiscountPercent = (percent) => {
|
||||||
console.log(p, e.target.value, (p.act_price || 0) * ((100 - (e.target.value || 0)) / 100));
|
const pct = Number(percent) || 0;
|
||||||
return {
|
|
||||||
...p,
|
const values = form.getFieldsValue();
|
||||||
act_price: (p.act_price || 0) * ((100 - (e.target.value || 0)) / 100)
|
const parts_order_lines = values?.parts_order_lines;
|
||||||
};
|
const data = Array.isArray(parts_order_lines?.data) ? parts_order_lines.data : [];
|
||||||
})
|
if (!data.length) return;
|
||||||
}
|
|
||||||
});
|
form.setFieldsValue({
|
||||||
e.target.value = 0;
|
parts_order_lines: {
|
||||||
}
|
data: data.map((p, idx) => {
|
||||||
}}
|
if (idx !== field.name) return p;
|
||||||
min={0}
|
return {
|
||||||
max={100}
|
...p,
|
||||||
/>
|
act_price: (p.act_price || 0) * ((100 - pct) / 100)
|
||||||
<span style={{ padding: "0 11px", backgroundColor: "#fafafa", border: "1px solid #d9d9d9", borderLeft: 0 }}>%</span>
|
};
|
||||||
</Space.Compact>
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
],
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyCustom = () => {
|
||||||
|
logImEXEvent("parts_order_manual_discount", {});
|
||||||
|
applyDiscountPercent(customPercent);
|
||||||
|
setCustomPercent(0);
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const menu = {
|
||||||
|
// Kill the menu “card” styling so our wrapper becomes the single card.
|
||||||
|
style: {
|
||||||
|
background: "transparent",
|
||||||
|
boxShadow: "none"
|
||||||
|
},
|
||||||
|
items: DISCOUNT_PRESETS.map((pct) => ({
|
||||||
|
key: String(pct),
|
||||||
|
label: t("parts_orders.labels.discount", { percent: `${pct}%` })
|
||||||
|
})),
|
||||||
onClick: ({ key }) => {
|
onClick: ({ key }) => {
|
||||||
logImEXEvent("parts_order_manual_discount", {});
|
logImEXEvent("parts_order_manual_discount", {});
|
||||||
if (key === "custom") return;
|
applyDiscountPercent(key);
|
||||||
const values = form.getFieldsValue();
|
setOpen(false);
|
||||||
const { parts_order_lines } = values;
|
|
||||||
form.setFieldsValue({
|
|
||||||
parts_order_lines: {
|
|
||||||
data: parts_order_lines.data.map((p, idx) => {
|
|
||||||
if (idx !== field.name) return p;
|
|
||||||
return {
|
|
||||||
...p,
|
|
||||||
act_price: (p.act_price || 0) * ((100 - key) / 100)
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown menu={menu} trigger="click">
|
<Dropdown
|
||||||
|
menu={menu}
|
||||||
|
trigger={["click"]}
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(nextOpen) => setOpen(nextOpen)}
|
||||||
|
getPopupContainer={(triggerNode) => triggerNode?.parentElement ?? document.body}
|
||||||
|
popupRender={(menus) => (
|
||||||
|
<div
|
||||||
|
// This makes the whole dropdown (menu + footer) look like one panel in both light/dark.
|
||||||
|
style={{
|
||||||
|
background: token.colorBgElevated,
|
||||||
|
borderRadius: token.borderRadiusLG,
|
||||||
|
boxShadow: token.boxShadowSecondary,
|
||||||
|
overflow: "hidden",
|
||||||
|
minWidth: 180
|
||||||
|
}}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onKeyDown={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{menus}
|
||||||
|
|
||||||
|
<Divider style={{ margin: 0 }} />
|
||||||
|
|
||||||
|
<div style={{ padding: token.paddingXS }}>
|
||||||
|
<Space.Compact style={{ width: "100%" }}>
|
||||||
|
<InputNumber
|
||||||
|
value={customPercent}
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
precision={0}
|
||||||
|
controls={false}
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
formatter={(v) => (v === null || v === undefined ? "" : `${v}%`)}
|
||||||
|
parser={(v) =>
|
||||||
|
String(v ?? "")
|
||||||
|
.replace("%", "")
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
onChange={(v) => setCustomPercent(v ?? 0)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
applyCustom();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button type="primary" onClick={applyCustom}>
|
||||||
|
{t("general.labels.apply")}
|
||||||
|
</Button>
|
||||||
|
</Space.Compact>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
>
|
||||||
<Space>
|
<Space>
|
||||||
%
|
% <DownOutlined />
|
||||||
<DownOutlined />
|
|
||||||
</Space>
|
</Space>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1288,6 +1288,7 @@
|
|||||||
"vehicle": "Vehicle"
|
"vehicle": "Vehicle"
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"apply": "Apply",
|
||||||
"actions": "Actions",
|
"actions": "Actions",
|
||||||
"areyousure": "Are you sure?",
|
"areyousure": "Are you sure?",
|
||||||
"barcode": "Barcode",
|
"barcode": "Barcode",
|
||||||
|
|||||||
@@ -1288,6 +1288,7 @@
|
|||||||
"vehicle": ""
|
"vehicle": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"apply": "",
|
||||||
"actions": "Comportamiento",
|
"actions": "Comportamiento",
|
||||||
"areyousure": "",
|
"areyousure": "",
|
||||||
"barcode": "código de barras",
|
"barcode": "código de barras",
|
||||||
|
|||||||
@@ -1288,6 +1288,7 @@
|
|||||||
"vehicle": ""
|
"vehicle": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"apply": "",
|
||||||
"actions": "actes",
|
"actions": "actes",
|
||||||
"areyousure": "",
|
"areyousure": "",
|
||||||
"barcode": "code à barre",
|
"barcode": "code à barre",
|
||||||
|
|||||||
Reference in New Issue
Block a user