IO-3355 Job Cash Discounting

Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
Allan Carr
2025-09-04 15:16:48 -07:00
parent 7f8c82b300
commit edaeb5d77a
2 changed files with 37 additions and 78 deletions

View File

@@ -20,35 +20,27 @@ export function JobTotalsCashDiscount({ bodyshop, amountDinero }) {
const notification = useNotification();
const fetchData = useCallback(async () => {
if (amountDinero && bodyshop) {
setLoading(true);
let response;
try {
response = await axios.post("/intellipay/checkfee", {
bodyshop: { id: bodyshop.id, imexshopid: bodyshop.imexshopid, state: bodyshop.state },
amount: Dinero(amountDinero).toFormat("0.00")
});
if (!amountDinero || !bodyshop) return;
if (response?.data?.error) {
notification.open({
type: "error",
message:
response.data?.error ||
"Error encountered when contacting IntelliPay service to determine cash discounted price."
});
} else {
setFee(response.data?.fee || 0);
}
} catch (error) {
notification.open({
type: "error",
message:
error.response?.data?.error ||
"Error encountered when contacting IntelliPay service to determine cash discounted price."
});
} finally {
setLoading(false);
setLoading(true);
const errorMessage = "Error encountered when contacting IntelliPay service to determine cash discounted price.";
try {
const { id, imexshopid, state } = bodyshop;
const { data } = await axios.post("/intellipay/checkfee", {
bodyshop: { id, imexshopid, state },
amount: Dinero(amountDinero).toUnit()
});
if (data?.error) {
notification.open({ type: "error", message: data.error || errorMessage });
} else {
setFee(data?.fee ?? 0);
}
} catch (error) {
notification.open({ type: "error", message: error.response?.data?.error || errorMessage });
} finally {
setLoading(false);
}
}, [amountDinero, bodyshop, notification]);