Merge pull request #1197 from Tria-plc/freight_feature/usermanagement

keep cents in CBE bills and prices
This commit is contained in:
marshal
2026-08-08 23:59:15 +03:00
committed by GitHub
3 changed files with 21 additions and 9 deletions

View File

@@ -64,6 +64,7 @@ import {
} from "@/pages/bookings/booking-display"; } from "@/pages/bookings/booking-display";
import { InitiateBookingButton } from "@/components/customer-actions/ContractCustomerAction"; import { InitiateBookingButton } from "@/components/customer-actions/ContractCustomerAction";
import { formatRateUnit } from "./new-contract-form/unit-rates"; import { formatRateUnit } from "./new-contract-form/unit-rates";
import { formatAmount } from "./new-shipment-form/total";
import { bookingDocNoun } from "@/pages/bookings/clearance/bookingNextAction"; import { bookingDocNoun } from "@/pages/bookings/clearance/bookingNextAction";
import { getContractBookingAction } from "./contract-booking-action"; import { getContractBookingAction } from "./contract-booking-action";
import { closedWindowMessage, hasOpenWindow } from "./booking-window"; import { closedWindowMessage, hasOpenWindow } from "./booking-window";
@@ -719,7 +720,7 @@ export default function ContractDetailPage() {
)} )}
</Box> </Box>
<Text fz={14} fw={700} style={{ color: GREEN }}> <Text fz={14} fw={700} style={{ color: GREEN }}>
{(item.unitPrice ?? 0).toLocaleString()} {pricing.currency}{" "} {formatAmount(item.unitPrice)} {pricing.currency}{" "}
<Text span fz={12} fw={600} c="dimmed"> <Text span fz={12} fw={600} c="dimmed">
/ {formatRateUnit(item.unit)} / {formatRateUnit(item.unit)}
</Text> </Text>
@@ -1336,9 +1337,7 @@ export default function ContractDetailPage() {
whiteSpace: "nowrap", whiteSpace: "nowrap",
}} }}
> >
{amount > 0 {amount > 0 ? `ETB ${formatAmount(amount)}` : "—"}
? `ETB ${amount.toLocaleString()}`
: "—"}
</Text> </Text>
</Table.Td> </Table.Td>
</Table.Tr> </Table.Tr>

View File

@@ -75,7 +75,7 @@ import {
createShipmentFormSchema, createShipmentFormSchema,
initialShipmentFormValues, initialShipmentFormValues,
} from "./new-shipment-form/schema"; } from "./new-shipment-form/schema";
import { computeShipmentTotal } from "./new-shipment-form/total"; import { computeShipmentTotal, formatAmount } from "./new-shipment-form/total";
import { import {
downloadContainerImportTemplate, downloadContainerImportTemplate,
parseContainerExcel, parseContainerExcel,
@@ -1014,7 +1014,7 @@ function PriceConfirmModal({
))} ))}
<Text fz="xs" c="#9A5B00" mt={2}> <Text fz="xs" c="#9A5B00" mt={2}>
{overweightSurchargeAmount > 0 {overweightSurchargeAmount > 0
? `An overweight surcharge of ${overweightSurchargeAmount.toLocaleString()} ${ ? `An overweight surcharge of ${formatAmount(overweightSurchargeAmount)} ${
validation?.currency ?? total?.currency ?? "" validation?.currency ?? total?.currency ?? ""
} applies (included in the total below). You can still submit, or go back and adjust weights.` } applies (included in the total below). You can still submit, or go back and adjust weights.`
: "An overweight surcharge applies. You can still submit, or go back and adjust weights."} : "An overweight surcharge applies. You can still submit, or go back and adjust weights."}
@@ -1038,7 +1038,7 @@ function PriceConfirmModal({
</Text> </Text>
<Text fz="xs" c="dimmed"> <Text fz="xs" c="dimmed">
{line.quantity.toLocaleString()} ×{" "} {line.quantity.toLocaleString()} ×{" "}
{line.unitPrice.toLocaleString()} {total.currency} ·{" "} {formatAmount(line.unitPrice)} {total.currency} ·{" "}
{formatRateUnit(line.unit)} {formatRateUnit(line.unit)}
</Text> </Text>
</Box> </Box>
@@ -1048,7 +1048,7 @@ function PriceConfirmModal({
c="#10202F" c="#10202F"
style={{ whiteSpace: "nowrap" }} style={{ whiteSpace: "nowrap" }}
> >
{line.amount.toLocaleString()} {total.currency} {formatAmount(line.amount)} {total.currency}
</Text> </Text>
</Group> </Group>
))} ))}
@@ -1070,7 +1070,7 @@ function PriceConfirmModal({
Total Total
</Text> </Text>
<Text fw={800} fz={28} c="#10202F"> <Text fw={800} fz={28} c="#10202F">
{total.total.toLocaleString()}{" "} {formatAmount(total.total)}{" "}
<Text span fz={16} fw={700} c="edr-muted"> <Text span fz={16} fw={700} c="edr-muted">
{total.currency} {total.currency}
</Text> </Text>

View File

@@ -15,6 +15,19 @@ export interface ShipmentTotal {
total: number; total: number;
} }
/**
* Money always prints its cents. Bare toLocaleString() defaults to
* maximumFractionDigits: 0, which rounded the total away from the line items it
* sums (118,171.21 shown as 118,171) — and the customer is billed the exact
* amount, so the shown figure must match to the cent.
*/
export function formatAmount(amount: number | string | null | undefined) {
return Number(amount ?? 0).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
}
/** /**
* Quantity a bulk rate bills, in ITS OWN unit. PER_ITEM cargo carries both * Quantity a bulk rate bills, in ITS OWN unit. PER_ITEM cargo carries both
* figures — the item count prices the booking, the tonnage sizes the wagons — * figures — the item count prices the booking, the tonnage sizes the wagons —