@tallyui/components 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +25 -5
- package/dist/index.js +171 -16
- package/package.json +9 -9
- package/src/sale/cart.tsx +9 -3
- package/src/sale/orders-list.tsx +158 -9
- package/src/sale/tender-pane.tsx +13 -9
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { Separator as Separator$1, Label as Label$1, Tabs as Tabs$1, Dialog as D
|
|
|
11
11
|
export { TextClassContext } from '@tallyui/primitives';
|
|
12
12
|
import { StoreDay, DayRange, CatalogueView, ProductSortValue, ProductSort, ViewfinderStatus, CameraDecoder, RefundableOrderLine, EarlierRefund, OrderFilterValue, useRegisterSession, RegisterSession, MovementType, ApprovalNeeded, SwitchKind, SwitchWarnings, HandoverSlipData, AppSettings, useAppSettings, PairingPhase, PairingError, TillDisplayStatus, TillDisplayEntry, PrinterProfile, TraceAnalysis, TaxDerivation, useSale, Payment, TenderState, TenderAction, AppliedDiscount, Discount, CatalogueEntry, CatalogueViewState, CartQuantityLine, TileFields, CatalogueGridColumns, SentOrder, PosOrder, ReceiptData, OutboxState, ParkedOrderSummary, OpenSale, DisplayState, DisplayClientPhase, SalesFigures, DatePreset } from '@tallyui/pos';
|
|
13
13
|
import { ScaleOverride, ScaleVariables, ScaleStep, Pointer, TypeSetId, ThemeFontFamily, ThemeType } from '@tallyui/theme';
|
|
14
|
-
import { ProductTraits, TraitContext, VariantOptionGroup, VariantSummary, Money, CustomerTraits, CustomerAddress, Customer, CustomerInput, CustomerPatch, OrderRefundPayload, OrderFilterField, PaymentKind, woocommerceTax, ReceiptTemplate, PaymentMethodDescriptor, MoneyFormat, ProductCategory, SyncNotice, StoreSettingsChoices, StoreSettingsChoice, ConnectivityState } from '@tallyui/core';
|
|
14
|
+
import { ProductTraits, TraitContext, VariantOptionGroup, VariantSummary, Money, CustomerTraits, CustomerAddress, Customer, CustomerInput, CustomerPatch, OrderRefundPayload, OrderFilterField, PaymentKind, woocommerceTax, ReceiptTemplate, PaymentMethodDescriptor, MoneyFormat, ProductCategory, SyncNotice, SettleOutcome, StoreSettingsChoices, StoreSettingsChoice, ConnectivityState } from '@tallyui/core';
|
|
15
15
|
import { TFunction } from 'i18next';
|
|
16
16
|
|
|
17
17
|
declare const textVariants: (props?: ({
|
|
@@ -2608,9 +2608,15 @@ declare function TenderLedger({ sale, methods, closing, confirmVoid, beforeVoid,
|
|
|
2608
2608
|
}): JSX.Element | null;
|
|
2609
2609
|
|
|
2610
2610
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
2611
|
-
declare function Cart({ sale, taxLabel, canEditPrice, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal, couponDiscountMinor, orderActions, orderDiscountChips, checkout, noteSheet, tenderLedger, picker, lineEditor, lineCommit, columns, chargeTaxSwitch, emptyIcon, emptyText }: {
|
|
2611
|
+
declare function Cart({ sale, taxLabel, taxDisplay, canEditPrice, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal, couponDiscountMinor, orderActions, orderDiscountChips, checkout, noteSheet, tenderLedger, picker, lineEditor, lineCommit, columns, chargeTaxSwitch, emptyIcon, emptyText }: {
|
|
2612
2612
|
sale: ReturnType<typeof useSale>;
|
|
2613
|
-
|
|
2613
|
+
/** Names each tax row from its rate. The second argument carries the row's own tax `code` (when it has one) and `ratePpm`, so two rates with the same percentage can be told apart. */
|
|
2614
|
+
taxLabel?: (ratePpm: number, rate: {
|
|
2615
|
+
code?: string;
|
|
2616
|
+
ratePpm: number;
|
|
2617
|
+
}) => string;
|
|
2618
|
+
/** `itemized` (default): one row per rate, under `taxLabel`. `single`: one "Total Tax" row with the order's total tax, drawn only when that is not 0. */
|
|
2619
|
+
taxDisplay?: 'itemized' | 'single';
|
|
2614
2620
|
taxClasses?: ReadonlyArray<{
|
|
2615
2621
|
id: string;
|
|
2616
2622
|
label: string;
|
|
@@ -3294,8 +3300,16 @@ declare function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPr
|
|
|
3294
3300
|
* `onReopen` adds Reopen to a Needs attention row the store refused with a reopenable code (`REOPENABLE_CODES`), not yet
|
|
3295
3301
|
* reopened and with no store order: the app wires `reopenRefusedOrder`. When it refuses `coupon_carry_inexact` with a
|
|
3296
3302
|
* `toCollectMinor`, the row offers "Reopen without the coupon", which calls it again with `{ withoutCoupons: true }`.
|
|
3297
|
-
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
3298
|
-
|
|
3303
|
+
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
3304
|
+
* `onCancelOnStore` adds "Cancel order on store" to a Needs attention row whose refused sale left an unpaid order on the
|
|
3305
|
+
* store (`canCancelOnStore`, #1101), asked in a confirm dialog first: the app wires `useOrderOutbox`'s `cancelOnStore`.
|
|
3306
|
+
* A cancel still `sending` is finished with no dialog. With it, such a row offers no Retry, except an `insufficient_stock`
|
|
3307
|
+
* refusal's, which reads "Try the payment again".
|
|
3308
|
+
* `onPayRestOnStore` adds "Pay the rest on store" to a Needs attention row whose refused sale left a part-paid order on
|
|
3309
|
+
* the store (`canPayRestOnStore`, #1101 slice 3), asked in a confirm dialog naming each leg to record (no money is taken):
|
|
3310
|
+
* the app wires `useOrderOutbox`'s `payRestOnStore`. A pay still `sending` is finished with no dialog. With it, a row
|
|
3311
|
+
* with money recorded on the store offers no Retry. */
|
|
3312
|
+
declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore }: {
|
|
3299
3313
|
orders: PosOrder[];
|
|
3300
3314
|
onRetry(orderIds: string[]): Promise<number>;
|
|
3301
3315
|
formatDate?: (iso: string) => string;
|
|
@@ -3307,6 +3321,12 @@ declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, histor
|
|
|
3307
3321
|
withoutCoupons: true;
|
|
3308
3322
|
}) => Promise<void>;
|
|
3309
3323
|
onResume?: (order: PosOrder) => void;
|
|
3324
|
+
onCancelOnStore?: (order: PosOrder) => Promise<SettleOutcome | {
|
|
3325
|
+
kind: 'not_offered';
|
|
3326
|
+
}>;
|
|
3327
|
+
onPayRestOnStore?: (order: PosOrder) => Promise<SettleOutcome | {
|
|
3328
|
+
kind: 'not_offered';
|
|
3329
|
+
}>;
|
|
3310
3330
|
}): react_jsx_runtime.JSX.Element;
|
|
3311
3331
|
|
|
3312
3332
|
/** Pass `useParkedSales(drafts)`'s `parked` and `discard`, or your own parked store's list and handlers (`onPark`, `onResume`, `onDiscard`) with the same results. */
|
package/dist/index.js
CHANGED
|
@@ -10498,6 +10498,7 @@ import { Fragment as Fragment38, jsx as jsx174, jsxs as jsxs111 } from "react/js
|
|
|
10498
10498
|
function Cart({
|
|
10499
10499
|
sale,
|
|
10500
10500
|
taxLabel: taxLabel2 = (ratePpm) => `Tax ${ratePpm / 1e4}%`,
|
|
10501
|
+
taxDisplay = "itemized",
|
|
10501
10502
|
canEditPrice = false,
|
|
10502
10503
|
onPriceChange,
|
|
10503
10504
|
quickDiscounts,
|
|
@@ -10524,7 +10525,7 @@ function Cart({
|
|
|
10524
10525
|
const empty = !order.lineItems.length && !order.fees?.length && !order.shipping?.length;
|
|
10525
10526
|
const money = (amount) => ({ amount, currency: order.currency });
|
|
10526
10527
|
const { totals, fees, shipping } = buildReceiptData(order, { storeName: "" });
|
|
10527
|
-
const taxRows = totals.taxLines.map((line) => ({ label: taxLabel2(line.ratePpm), amount: money(line.amountMinor) }));
|
|
10528
|
+
const taxRows = taxDisplay === "single" ? totals.taxMinor !== 0 ? [{ label: "Total Tax", amount: money(totals.taxMinor) }] : [] : totals.taxLines.map((line) => ({ label: taxLabel2(line.ratePpm, { code: line.code, ratePpm: line.ratePpm }), amount: money(line.amountMinor) }));
|
|
10528
10529
|
const display = (lineId) => order.display.lines.find((line) => line.lineId === lineId);
|
|
10529
10530
|
const orderAmounts = order.discounts.length === 1 ? [{ discountId: order.discounts[0].id, amountMinor: order.display.orderDiscountMinor }] : [];
|
|
10530
10531
|
const [splitError, setSplitError] = useState51(null);
|
|
@@ -11010,7 +11011,8 @@ import {
|
|
|
11010
11011
|
remainderEntriesMinor,
|
|
11011
11012
|
roundedPickTarget,
|
|
11012
11013
|
tenderRounding,
|
|
11013
|
-
tillLegsTheStoreRefuses
|
|
11014
|
+
tillLegsTheStoreRefuses,
|
|
11015
|
+
writeOffLeg
|
|
11014
11016
|
} from "@tallyui/pos";
|
|
11015
11017
|
import { cn as cn113 } from "@tallyui/theme";
|
|
11016
11018
|
|
|
@@ -11158,17 +11160,19 @@ function TenderPane({ sale, state, dispatch, methods, ledger = true, back = true
|
|
|
11158
11160
|
const partPick = pick !== null && target < balance;
|
|
11159
11161
|
const rounds = sale.capabilities?.cashRounding === true && inMotionMinor(order.payments) === 0;
|
|
11160
11162
|
const pickRounding = rounds && method !== null && wireMethodOf5(method) === "cash" && method.capture.mode === "manual" && method.defaults.rounding ? method.defaults.rounding : null;
|
|
11161
|
-
const pickTarget = partPick ? roundedPickTarget(target, pickRounding) : target;
|
|
11162
|
-
const entry = state.entryDirty ? state.entryMinor : pickTarget;
|
|
11163
11163
|
const entries = remainderEntriesMinor(order);
|
|
11164
|
+
const pickTarget = partPick ? roundedPickTarget(target, pickRounding, entries) : target;
|
|
11165
|
+
const entry = state.entryDirty ? state.entryMinor : pickTarget;
|
|
11164
11166
|
const figures = partPick ? tenderRounding({ entryMinor: entry, entryDirty: state.entryDirty }, pickTarget, null) : tenderRounding(state, balance, rounds ? method : null, entries);
|
|
11167
|
+
const promoted = partPick && pickRounding !== null && pickTarget === tenderRounding(state, balance, method, entries).roundedDueMinor;
|
|
11168
|
+
const roundedFrom = promoted ? pickTarget !== balance ? balance : null : partPick ? pickTarget !== target ? target : null : figures.roundingMinor !== 0 ? balance : null;
|
|
11165
11169
|
const cashNotPayable = rounds && pick === null && method !== null && wireMethodOf5(method) === "cash" && method.capture.mode === "manual" && method.defaults.rounding && figures.roundingMinor === 0 && figures.appliedMinor < figures.roundedDueMinor ? nearestPayableCash(figures.entryMinor, method.defaults.rounding.incrementMinor) : null;
|
|
11166
11170
|
const cashWaits = sale.capabilities?.cashRounding === true && inMotionMinor(order.payments) > 0 && method !== null && wireMethodOf5(method) === "cash" && method.capture.mode === "manual" && method.defaults.rounding && (partPick ? nearestPayableCash(target, method.defaults.rounding.incrementMinor) !== null : figures.entryMinor > 0 && nearestPayableCash(Math.min(figures.entryMinor, balance - inMotionMinor(order.payments)), method.defaults.rounding.incrementMinor) !== null);
|
|
11167
|
-
const pickLimit = partPick && pickTarget !== target && (order.cashRoundings ?? []).length >= CASH_PICK_ENTRIES_MAX;
|
|
11171
|
+
const pickLimit = partPick && !promoted && pickTarget !== target && (order.cashRoundings ?? []).length >= CASH_PICK_ENTRIES_MAX;
|
|
11168
11172
|
const pickRefused = partPick && entry > 0 && (givesChange ? entry < pickTarget : entry !== pickTarget) || pick !== null && !partPick && figures.appliedMinor > 0 && figures.appliedMinor < figures.roundedDueMinor;
|
|
11169
11173
|
const zeroDue = sale.capabilities?.cashRounding === true && !partPick && figures.roundedDueMinor === 0 && figures.roundingMinor !== 0 && inMotionMinor(order.payments) === 0;
|
|
11170
|
-
const lastCounted = order
|
|
11171
|
-
const settleLimit = !partPick && sale.capabilities?.cashRounding === true && figures.roundingMinor !== 0 && (order.cashRoundings ?? []).length > CASH_PICK_ENTRIES_MAX && !(zeroDue && lastCounted !== void 0 && (order.cashRoundings ?? []).some((e) => e.paymentId === lastCounted.id));
|
|
11174
|
+
const lastCounted = writeOffLeg(order);
|
|
11175
|
+
const settleLimit = (!partPick && sale.capabilities?.cashRounding === true && figures.roundingMinor !== 0 || promoted && pickTarget !== balance) && (order.cashRoundings ?? []).length > CASH_PICK_ENTRIES_MAX && !(zeroDue && lastCounted !== void 0 && (order.cashRoundings ?? []).some((e) => e.paymentId === lastCounted.id));
|
|
11172
11176
|
const otherWay = offered.some((m) => !(wireMethodOf5(m) === "cash" && m.defaults.rounding));
|
|
11173
11177
|
const lastRounded = order.payments.filter(countsTowardPaid3).filter((leg) => leg.method === "cash" && (order.cashRoundings ?? []).some((e) => e.paymentId === leg.id)).at(-1);
|
|
11174
11178
|
const entryChange = zeroDue ? 0 : partPick ? changeMinor(figures.entryMinor, figures.appliedMinor, givesChange) : changeMinor(figures.entryMinor, Math.min(figures.appliedMinor, Math.max(0, balance - inMotionMinor(order.payments)) + figures.roundingMinor), givesChange);
|
|
@@ -11260,10 +11264,10 @@ function TenderPane({ sale, state, dispatch, methods, ledger = true, back = true
|
|
|
11260
11264
|
/* @__PURE__ */ jsx179(Text50, { testID: "tender-entry-amount", className: "font-semibold text-foreground", children: money(figures.entryMinor) }),
|
|
11261
11265
|
order.totalMinor !== balance ? ` \xB7 ${t("common.total")} ${money(order.totalMinor)}` : ""
|
|
11262
11266
|
] }),
|
|
11263
|
-
|
|
11267
|
+
roundedFrom !== null ? /* @__PURE__ */ jsx179(Text50, { className: "text-sm text-muted-foreground", children: t("pos_checkout.rounded_from", { amount: money(roundedFrom) }) }) : null
|
|
11264
11268
|
] }) : /* @__PURE__ */ jsxs116(Fragment41, { children: [
|
|
11265
11269
|
/* @__PURE__ */ jsx179(Text50, { testID: "tender-entry-amount", className: cn113("text-4xl font-bold text-foreground", !state.entryDirty && "opacity-70"), children: money(figures.entryMinor) }),
|
|
11266
|
-
|
|
11270
|
+
roundedFrom !== null ? /* @__PURE__ */ jsx179(Text50, { className: "text-sm text-muted-foreground", children: t("pos_checkout.rounded_from", { amount: money(roundedFrom) }) }) : null,
|
|
11267
11271
|
/* @__PURE__ */ jsx179(Text50, { testID: "tender-entry-hint", className: cn113("min-h-6 text-center text-sm", noChange || capped || pickRefused || cashWaits || pickLimit || settleLimit ? "text-warning-text" : "text-muted-foreground"), children: hint })
|
|
11268
11272
|
] }) }) : null,
|
|
11269
11273
|
ledger ? /* @__PURE__ */ jsx179(TenderLedger, { sale, methods, confirmVoid, beforeVoid, afterVoid }) : null,
|
|
@@ -12760,7 +12764,7 @@ function SyncStatus({ state, registerState, pluginName = "the POS plugin", pullN
|
|
|
12760
12764
|
import { useEffect as useEffect24, useId as useId4, useRef as useRef26, useState as useState57 } from "react";
|
|
12761
12765
|
import { Pressable as Pressable56, ScrollView as ScrollView23, Text as Text58, View as View118 } from "react-native";
|
|
12762
12766
|
import { useFormatMoney as useFormatMoney26, knownWarnings } from "@tallyui/core";
|
|
12763
|
-
import { extrasNotSent, isRequeueableOrder, needsAdminReasonOf as needsAdminReasonOf2, needsAttention, noteDelivery as noteDelivery2, refundDueOf, REOPENABLE_CODES, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE } from "@tallyui/pos";
|
|
12767
|
+
import { canCancelOnStore, canPayRestOnStore, extrasNotSent, isRequeueableOrder, needsAdminReasonOf as needsAdminReasonOf2, needsAttention, noteDelivery as noteDelivery2, refundDueOf, REOPENABLE_CODES, settledOnStore, storeOrderLeft, unrecordedLegs, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE } from "@tallyui/pos";
|
|
12764
12768
|
import { Fragment as Fragment48, jsx as jsx190, jsxs as jsxs126 } from "react/jsx-runtime";
|
|
12765
12769
|
var STATUS_LABEL2 = { pending: "Waiting to sync", applied: "Synced", rejected: "Not accepted" };
|
|
12766
12770
|
var FIGURE_LABELS = /* @__PURE__ */ new Map([["subtotalMinor", "Subtotal"], ["taxMinor", "Tax"], ["discountMinor", "Discount"]]);
|
|
@@ -12781,6 +12785,8 @@ var REFUSAL_SENTENCES = /* @__PURE__ */ new Map([
|
|
|
12781
12785
|
["total_mismatch", "The online store refused this sale: its total didn't match the store's. Reopen it to sell it again."]
|
|
12782
12786
|
]);
|
|
12783
12787
|
var refusalSentence = (code) => REFUSAL_SENTENCES.get(code ?? "") ?? REFUSAL_SENTENCES.get("platform_error");
|
|
12788
|
+
var GIVE_BACK = "If the money was given back, do not record it; a manager must check the order in the store's admin.";
|
|
12789
|
+
var methodLabel = (method) => method === "cash" ? "Cash" : "Card terminal";
|
|
12784
12790
|
var REOPEN_AGAIN_SENTENCE = "This order was changed in the online store after it was reopened here, so your change wasn't sent. Reopen the order and make the change again.";
|
|
12785
12791
|
function defaultFormatDate2(iso2) {
|
|
12786
12792
|
const date = new Date(iso2);
|
|
@@ -12792,11 +12798,29 @@ function OrderSyncNotices({ order, stuck, children }) {
|
|
|
12792
12798
|
const formatMoney2 = useFormatMoney26();
|
|
12793
12799
|
const stuckEntry = order.syncStatus === "pending" ? stuck?.orders.find((entry) => entry.commandId === order.commandId) : void 0;
|
|
12794
12800
|
const needsAdminReason = stuckEntry ? needsAdminReasonOf2(stuckEntry.reason) : void 0;
|
|
12795
|
-
const
|
|
12801
|
+
const left = storeOrderLeft(order);
|
|
12802
|
+
const sentence = order.syncStatus === "rejected" ? order.storeOrderId !== void 0 && ["reopen_required", "revision_conflict"].includes(order.error?.code ?? "") ? REOPEN_AGAIN_SENTENCE : refusalSentence(left && order.error?.code === "invalid_payload" ? "platform_error" : order.error?.code) : order.syncStatus === "pending" && order.error?.code === UPDATE_UNSENDABLE ? UPDATE_UNSENDABLE_MESSAGE : void 0;
|
|
12796
12803
|
const extras = extrasNotSent(order);
|
|
12804
|
+
const kind = order.storeSettlement?.kind;
|
|
12805
|
+
const settlement = order.syncStatus === "rejected" && (kind === "cancel" || kind === "pay") ? order.storeSettlement : void 0;
|
|
12806
|
+
const reference = left?.reference ?? orderReference(order);
|
|
12807
|
+
const money = (amount) => formatMoney2({ amount, currency: order.currency });
|
|
12808
|
+
const sum = (legs) => legs.reduce((total, leg) => total + leg.amountMinor, 0);
|
|
12809
|
+
const paidThere = settlement?.capturedMinor ? `: ${money(settlement.capturedMinor)} is paid there` : "";
|
|
12810
|
+
const recorded = money((left?.recordedMinor ?? 0) + sum(settlement?.payments?.filter((payment) => payment.done) ?? []));
|
|
12811
|
+
const cashTaken = sum(order.payments.filter((payment) => payment.method === "cash"));
|
|
12812
|
+
const doneMinor = sum(settlement?.payments?.filter((payment) => payment.done) ?? []);
|
|
12813
|
+
const nothing = doneMinor > 0 ? `${money(doneMinor)} was recorded from this till.` : "Nothing was recorded from this till.";
|
|
12814
|
+
const settledText = settlement?.kind === "pay" ? settlement.state === "done" ? `Order #${reference} is paid on the store.` : settlement.state === "gone" ? `Order #${reference} is not on the store any more; ${recorded} was recorded on it.` : settlement.state !== "changed" ? void 0 : settlement.storeStatus === "completed" ? `Order #${reference} is already paid on the store. ${nothing}` : `Order #${reference} changed on the store${paidThere}. ${nothing} Check it in the store's admin.` : settlement?.state === "done" ? `Order #${reference} was cancelled on the store.${cashTaken ? ` If you gave back the ${money(cashTaken)} cash taken on this till, record it as a pay-out.` : ""}` : settlement?.state === "gone" ? `Order #${reference} was removed on the store.` : settlement?.state === "changed" ? `Order #${reference} changed on the store${paidThere}. Nothing was cancelled from this till. Check it in the store's admin.` : void 0;
|
|
12815
|
+
const pay = settlement?.kind === "pay";
|
|
12816
|
+
const addedText = settlement?.state === "refused" ? pay ? `The store did not record the rest of order #${reference}: ${recorded} of ${money(order.totalMinor)} is recorded there. Check it in the store's admin.` : `The store did not cancel order #${reference}. Check it in the store's admin.` : settlement?.state === "sending" ? pay ? `Recording the rest of order #${reference} on the store is not finished.` : `Cancelling order #${reference} on the store is not finished.` : void 0;
|
|
12817
|
+
const settled = !!settlement && settledOnStore(order);
|
|
12797
12818
|
return /* @__PURE__ */ jsxs126(Fragment48, { children: [
|
|
12798
12819
|
stuckEntry ? /* @__PURE__ */ jsx190(Text58, { className: "text-destructive", children: needsAdminReason !== void 0 ? needsAdminReason === "session_closed" ? NEEDS_ADMIN_SESSION_CLOSED : NEEDS_ADMIN_SALE : `Hasn't reached the online store since ${sinceText(stuckEntry)}.` }) : null,
|
|
12799
|
-
sentence ? /* @__PURE__ */ jsx190(Text58, { className: "text-destructive", children: sentence }) : null,
|
|
12820
|
+
sentence && !settled ? /* @__PURE__ */ jsx190(Text58, { className: "text-destructive", children: sentence }) : null,
|
|
12821
|
+
settledText ? /* @__PURE__ */ jsx190(Text58, { testID: `order-settlement-${order.id}`, className: settled ? "text-foreground" : "text-destructive", children: settledText }) : null,
|
|
12822
|
+
left && !settledText ? /* @__PURE__ */ jsx190(Text58, { testID: `order-left-on-store-${order.id}`, className: "text-destructive", children: left.recordedMinor === 0 ? `Order #${left.reference} was left pending on the online store. Nothing was paid there.` : `Order #${left.reference} was left part paid on the online store: ${formatMoney2({ amount: left.recordedMinor, currency: order.currency })} of ${formatMoney2({ amount: order.totalMinor, currency: order.currency })}.` }) : null,
|
|
12823
|
+
addedText ? /* @__PURE__ */ jsx190(Text58, { testID: `order-settlement-${order.id}`, className: "text-destructive", children: addedText }) : null,
|
|
12800
12824
|
order.lateSessionId !== void 0 ? /* @__PURE__ */ jsx190(Text58, { className: "text-foreground", children: "Taken after the register closed. It is not in that register's closure." }) : null,
|
|
12801
12825
|
order.countedInClosureOf !== void 0 ? /* @__PURE__ */ jsx190(Text58, { className: "text-foreground", children: "Recorded after the register closed. Its payment is in that register's closure." }) : null,
|
|
12802
12826
|
order.localWarnings?.map((warning, index) => /* @__PURE__ */ jsx190(Text58, { className: "text-foreground", children: warning.code === "customer_omitted" ? `The customer's ${warning.field} couldn't be sent to the store, so the order isn't linked to them.` : "The terminal's payment reference couldn't be kept; the payment is recorded without it." }, index)),
|
|
@@ -12808,7 +12832,7 @@ function OrderSyncNotices({ order, stuck, children }) {
|
|
|
12808
12832
|
knownWarnings(order.warnings).filter((warning) => warning.code !== "register_session_unknown").map((warning, index) => /* @__PURE__ */ jsx190(View118, { className: "border-l-4 border-warning pl-2", children: /* @__PURE__ */ jsx190(Text58, { className: "text-foreground", children: warning.code === "insufficient_stock" ? `${warning.quantity} sold without stock: ${order.lines.find((line) => line.variantId === warning.variantId)?.name}` : warning.code === "tax_rate_mismatch" ? `Tax at ${(warning.ratePpm / 1e4).toLocaleString(void 0, { maximumFractionDigits: 4 })}%: store ${formatMoney2({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney2({ amount: warning.expectedMinor, currency: order.currency })}` : warning.code === "customer_ignored" ? `The online store didn't recognise the customer on this sale, so it was saved as a guest sale. Customer id: ${warning.customerId}.` : warning.code === "figures_mismatch" ? `The online store worked out different figures for this sale. ${warning.fields.map(({ field, tillMinor, serverMinor }) => `${FIGURE_LABELS.get(field) ?? field}: till ${formatMoney2({ amount: tillMinor, currency: order.currency })}, store ${formatMoney2({ amount: serverMinor, currency: order.currency })}.`).join(" ")}` : warning.code === "line_figures_mismatch" ? ((n) => `The online store worked out different figures for ${n === 1 ? "one line" : `${n} lines`} of this sale.`)(new Set(warning.lines.map((line) => line.lineId)).size) : warning.bridgeMinor !== void 0 ? `Store calculated ${formatMoney2({ amount: warning.serverMinor, currency: order.currency })}; a rounding line of ${warning.bridgeMinor > 0 ? "+" : ""}${formatMoney2({ amount: warning.bridgeMinor, currency: order.currency })} brought it to ${formatMoney2({ amount: warning.expectedMinor, currency: order.currency })}` : `Store total ${formatMoney2({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney2({ amount: warning.expectedMinor, currency: order.currency })}` }) }, index))
|
|
12809
12833
|
] });
|
|
12810
12834
|
}
|
|
12811
|
-
function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen, onReopen, onResume }) {
|
|
12835
|
+
function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore }) {
|
|
12812
12836
|
const formatMoney2 = useFormatMoney26();
|
|
12813
12837
|
const hintId = useId4();
|
|
12814
12838
|
const retrying = useRef26(/* @__PURE__ */ new Set());
|
|
@@ -12836,6 +12860,50 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12836
12860
|
reopening.current.delete(order.id);
|
|
12837
12861
|
}
|
|
12838
12862
|
}
|
|
12863
|
+
const cancelling = useRef26(/* @__PURE__ */ new Set());
|
|
12864
|
+
const [cancels, setCancels] = useState57(/* @__PURE__ */ new Map());
|
|
12865
|
+
const [askingCancel, setAskingCancel] = useState57(null);
|
|
12866
|
+
const setCancel = (id, state) => setCancels((current) => {
|
|
12867
|
+
const next = new Map(current);
|
|
12868
|
+
if (state) next.set(id, state);
|
|
12869
|
+
else next.delete(id);
|
|
12870
|
+
return next;
|
|
12871
|
+
});
|
|
12872
|
+
async function cancelOnStore(order) {
|
|
12873
|
+
if (!onCancelOnStore || cancelling.current.has(order.id)) return;
|
|
12874
|
+
cancelling.current.add(order.id);
|
|
12875
|
+
setCancel(order.id, "busy");
|
|
12876
|
+
try {
|
|
12877
|
+
const outcome = await onCancelOnStore(order);
|
|
12878
|
+
setCancel(order.id, outcome.kind === "retry" ? "failed" : void 0);
|
|
12879
|
+
} catch {
|
|
12880
|
+
setCancel(order.id, "failed");
|
|
12881
|
+
} finally {
|
|
12882
|
+
cancelling.current.delete(order.id);
|
|
12883
|
+
}
|
|
12884
|
+
}
|
|
12885
|
+
const paying = useRef26(/* @__PURE__ */ new Set());
|
|
12886
|
+
const [pays, setPays] = useState57(/* @__PURE__ */ new Map());
|
|
12887
|
+
const [askingPay, setAskingPay] = useState57(null);
|
|
12888
|
+
const setPay = (id, state) => setPays((current) => {
|
|
12889
|
+
const next = new Map(current);
|
|
12890
|
+
if (state) next.set(id, state);
|
|
12891
|
+
else next.delete(id);
|
|
12892
|
+
return next;
|
|
12893
|
+
});
|
|
12894
|
+
async function payRestOnStore(order) {
|
|
12895
|
+
if (!onPayRestOnStore || paying.current.has(order.id)) return;
|
|
12896
|
+
paying.current.add(order.id);
|
|
12897
|
+
setPay(order.id, "busy");
|
|
12898
|
+
try {
|
|
12899
|
+
const outcome = await onPayRestOnStore(order);
|
|
12900
|
+
setPay(order.id, outcome.kind !== "retry" ? void 0 : outcome.reason === "not_completed" ? "unfinished" : "failed");
|
|
12901
|
+
} catch {
|
|
12902
|
+
setPay(order.id, "failed");
|
|
12903
|
+
} finally {
|
|
12904
|
+
paying.current.delete(order.id);
|
|
12905
|
+
}
|
|
12906
|
+
}
|
|
12839
12907
|
const [expanded, setExpanded] = useState57(/* @__PURE__ */ new Set());
|
|
12840
12908
|
useEffect24(() => {
|
|
12841
12909
|
for (const id of retrying.current) {
|
|
@@ -12887,6 +12955,14 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12887
12955
|
const attention = section.title === "Needs attention";
|
|
12888
12956
|
const reopenable = attention && !!onReopen && order.syncStatus === "rejected" && REOPENABLE_CODES.includes(order.error?.code ?? "") && order.storeOrderId === void 0 && order.reopenedAt === void 0;
|
|
12889
12957
|
const reopenState = reopens.get(order.id);
|
|
12958
|
+
const cancellable = attention && !!onCancelOnStore && canCancelOnStore(order);
|
|
12959
|
+
const cancelState = cancels.get(order.id);
|
|
12960
|
+
const finishing = order.storeSettlement?.kind === "cancel" && order.storeSettlement.state === "sending";
|
|
12961
|
+
const left = storeOrderLeft(order);
|
|
12962
|
+
const payable = attention && !!onPayRestOnStore && canPayRestOnStore(order);
|
|
12963
|
+
const payState = pays.get(order.id);
|
|
12964
|
+
const finishingPay = order.storeSettlement?.kind === "pay" && order.storeSettlement.state === "sending";
|
|
12965
|
+
const retryLabel = onPayRestOnStore && left && left.recordedMinor > 0 ? void 0 : onCancelOnStore && left?.recordedMinor === 0 ? order.error?.code === "insufficient_stock" ? "Try the payment again" : void 0 : "Retry";
|
|
12890
12966
|
return /* @__PURE__ */ jsxs126(View118, { className: "gap-1 rounded-md border border-border bg-card p-3", children: [
|
|
12891
12967
|
/* @__PURE__ */ jsx190(Text58, { id: `${hintId}-${sectionIndex}-${order.id}`, className: "hidden", children: "Shows the items and payments of this sale" }),
|
|
12892
12968
|
/* @__PURE__ */ jsxs126(
|
|
@@ -12929,12 +13005,12 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12929
13005
|
) : null,
|
|
12930
13006
|
isExpanded ? /* @__PURE__ */ jsxs126(View118, { testID: `order-detail-${order.id}`, className: "mt-1 gap-1 border-t border-border pt-2", children: [
|
|
12931
13007
|
order.lines.map((line) => /* @__PURE__ */ jsx190(Text58, { className: "text-foreground", children: `${line.quantity} \xD7 ${line.name}` }, line.id)),
|
|
12932
|
-
order.payments.map((payment) => /* @__PURE__ */ jsx190(Text58, { className: "text-muted-foreground", children: `${payment.method
|
|
13008
|
+
order.payments.map((payment) => /* @__PURE__ */ jsx190(Text58, { className: "text-muted-foreground", children: `${methodLabel(payment.method)} ${formatMoney2({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` \xB7 ${payment.reference}` : ""}` }, payment.id)),
|
|
12933
13009
|
refundDueMinor > 0 ? /* @__PURE__ */ jsx190(Text58, { testID: `order-refund-due-${order.id}`, className: "text-foreground", children: `Refund due ${formatMoney2({ amount: refundDueMinor, currency: order.currency })}` }) : null,
|
|
12934
13010
|
order.note ? /* @__PURE__ */ jsx190(Text58, { testID: `order-note-${order.id}`, className: "text-foreground", children: `Customer note: ${order.note}` }) : null
|
|
12935
13011
|
] }) : null,
|
|
12936
13012
|
/* @__PURE__ */ jsxs126(OrderSyncNotices, { order, stuck, children: [
|
|
12937
|
-
section.title === "Needs attention" && isRequeueableOrder(order) ? /* @__PURE__ */ jsx190(Pressable56, { accessibilityRole: "button", disabled: retryingIds.has(order.id), onPress: async () => {
|
|
13013
|
+
section.title === "Needs attention" && isRequeueableOrder(order) && retryLabel ? /* @__PURE__ */ jsx190(Pressable56, { accessibilityRole: "button", disabled: retryingIds.has(order.id), onPress: async () => {
|
|
12938
13014
|
if (retrying.current.has(order.id)) return;
|
|
12939
13015
|
retrying.current.add(order.id);
|
|
12940
13016
|
setRetryingIds(new Set(retrying.current));
|
|
@@ -12942,7 +13018,39 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12942
13018
|
retrying.current.delete(order.id);
|
|
12943
13019
|
setRetryingIds(new Set(retrying.current));
|
|
12944
13020
|
}
|
|
12945
|
-
}, className: "rounded-md bg-primary px-4 py-2", children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-primary-foreground", children:
|
|
13021
|
+
}, className: "rounded-md bg-primary px-4 py-2", children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-primary-foreground", children: retryLabel }) }) : null,
|
|
13022
|
+
cancellable ? /* @__PURE__ */ jsx190(
|
|
13023
|
+
Pressable56,
|
|
13024
|
+
{
|
|
13025
|
+
accessibilityRole: "button",
|
|
13026
|
+
testID: `order-${order.id}-cancel-on-store`,
|
|
13027
|
+
disabled: cancelState === "busy",
|
|
13028
|
+
onPress: () => {
|
|
13029
|
+
if (cancelling.current.has(order.id)) return;
|
|
13030
|
+
if (finishing) void cancelOnStore(order);
|
|
13031
|
+
else setAskingCancel(order);
|
|
13032
|
+
},
|
|
13033
|
+
className: "rounded-md border border-border px-4 py-2",
|
|
13034
|
+
children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-foreground", children: cancelState === "busy" ? "Cancelling on store\u2026" : finishing ? "Finish cancelling on store" : "Cancel order on store" })
|
|
13035
|
+
}
|
|
13036
|
+
) : null,
|
|
13037
|
+
cancellable && cancelState === "failed" ? /* @__PURE__ */ jsx190(Text58, { testID: `order-${order.id}-cancel-on-store-error`, className: "text-muted-foreground", children: "Could not reach the store. Try again." }) : null,
|
|
13038
|
+
payable ? /* @__PURE__ */ jsx190(
|
|
13039
|
+
Pressable56,
|
|
13040
|
+
{
|
|
13041
|
+
accessibilityRole: "button",
|
|
13042
|
+
testID: `order-${order.id}-pay-rest-on-store`,
|
|
13043
|
+
disabled: payState === "busy",
|
|
13044
|
+
onPress: () => {
|
|
13045
|
+
if (paying.current.has(order.id)) return;
|
|
13046
|
+
if (finishingPay) void payRestOnStore(order);
|
|
13047
|
+
else setAskingPay(order);
|
|
13048
|
+
},
|
|
13049
|
+
className: "rounded-md bg-primary px-4 py-2",
|
|
13050
|
+
children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-primary-foreground", children: payState === "busy" ? "Recording on store\u2026" : finishingPay ? "Finish recording on store" : "Pay the rest on store" })
|
|
13051
|
+
}
|
|
13052
|
+
) : null,
|
|
13053
|
+
payable && (payState === "failed" || payState === "unfinished") ? /* @__PURE__ */ jsx190(Text58, { testID: `order-${order.id}-pay-rest-on-store-error`, className: "text-muted-foreground", children: payState === "unfinished" ? "The store has not finished this order yet. Try again, or check it in the store's admin." : "Could not reach the store. Try again." }) : null,
|
|
12946
13054
|
attention && order.reopenedAt !== void 0 ? /* @__PURE__ */ jsxs126(Fragment48, { children: [
|
|
12947
13055
|
/* @__PURE__ */ jsx190(Text58, { testID: `order-${order.id}-reopened`, className: "text-muted-foreground", children: "Reopened as a parked sale." }),
|
|
12948
13056
|
onResume ? /* @__PURE__ */ jsx190(
|
|
@@ -12986,6 +13094,53 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12986
13094
|
] }, order.id);
|
|
12987
13095
|
})
|
|
12988
13096
|
] }, section.title)),
|
|
13097
|
+
askingCancel ? ((reference) => /* @__PURE__ */ jsx190(
|
|
13098
|
+
ConfirmDialog,
|
|
13099
|
+
{
|
|
13100
|
+
testID: `order-${askingCancel.id}-cancel-on-store-dialog`,
|
|
13101
|
+
tone: "destructive",
|
|
13102
|
+
open: true,
|
|
13103
|
+
onOpenChange: (open) => {
|
|
13104
|
+
if (!open) setAskingCancel(null);
|
|
13105
|
+
},
|
|
13106
|
+
title: `Cancel order #${reference} on the store?`,
|
|
13107
|
+
description: `Order #${reference} is waiting on the online store with nothing paid. This cancels it there. The payments taken on this till stay as they are.`,
|
|
13108
|
+
cancelLabel: "Keep order",
|
|
13109
|
+
confirmLabel: "Cancel order on store",
|
|
13110
|
+
onConfirm: () => {
|
|
13111
|
+
setAskingCancel(null);
|
|
13112
|
+
void cancelOnStore(askingCancel);
|
|
13113
|
+
}
|
|
13114
|
+
}
|
|
13115
|
+
))(storeOrderLeft(askingCancel)?.reference ?? orderReference(askingCancel)) : null,
|
|
13116
|
+
askingPay ? ((reference, legs, stored) => /* @__PURE__ */ jsx190(
|
|
13117
|
+
ConfirmDialog,
|
|
13118
|
+
{
|
|
13119
|
+
testID: `order-${askingPay.id}-pay-rest-on-store-dialog`,
|
|
13120
|
+
tone: "default",
|
|
13121
|
+
open: true,
|
|
13122
|
+
onOpenChange: (open) => {
|
|
13123
|
+
if (!open) setAskingPay(null);
|
|
13124
|
+
},
|
|
13125
|
+
title: `Record the rest of order #${reference} on the store?`,
|
|
13126
|
+
description: [
|
|
13127
|
+
...legs.filter((_leg, index) => !(stored?.kind === "pay" && stored.payments?.length === legs.length && stored.payments[index].done)).map((leg) => `${methodLabel(leg.method)} ${formatMoney2({ amount: leg.amountMinor, currency: askingPay.currency })}, already taken on this till.`),
|
|
13128
|
+
"No money is taken now.",
|
|
13129
|
+
GIVE_BACK
|
|
13130
|
+
].join("\n"),
|
|
13131
|
+
cancelLabel: "Keep as is",
|
|
13132
|
+
confirmLabel: "Record on store",
|
|
13133
|
+
onConfirm: () => {
|
|
13134
|
+
setAskingPay(null);
|
|
13135
|
+
void payRestOnStore(askingPay);
|
|
13136
|
+
}
|
|
13137
|
+
}
|
|
13138
|
+
))(
|
|
13139
|
+
storeOrderLeft(askingPay)?.reference ?? orderReference(askingPay),
|
|
13140
|
+
// Only the legs still to record: the stored pay is index-aligned with them when the lengths match, as the outbox reuses it.
|
|
13141
|
+
unrecordedLegs(askingPay),
|
|
13142
|
+
askingPay.storeSettlement
|
|
13143
|
+
) : null,
|
|
12989
13144
|
footer
|
|
12990
13145
|
] });
|
|
12991
13146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/components",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal POS UI components for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"directory": "packages/components"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tallyui/core": "^5.
|
|
33
|
-
"@tallyui/primitives": "^5.
|
|
34
|
-
"@tallyui/theme": "^5.
|
|
32
|
+
"@tallyui/core": "^5.1.0",
|
|
33
|
+
"@tallyui/primitives": "^5.1.0",
|
|
34
|
+
"@tallyui/theme": "^5.1.0",
|
|
35
35
|
"react": ">=18",
|
|
36
36
|
"react-native": ">=0.74",
|
|
37
37
|
"react-native-svg": ">=15"
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"class-variance-authority": "^0.7.1",
|
|
41
41
|
"i18next": "^26.7.1",
|
|
42
42
|
"react-i18next": "^17.1.12",
|
|
43
|
-
"@tallyui/pos": "5.
|
|
43
|
+
"@tallyui/pos": "5.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tallyui/connector-medusa": "5.
|
|
47
|
-
"@tallyui/connector-vendure": "5.
|
|
48
|
-
"@tallyui/connector-woocommerce": "5.
|
|
49
|
-
"@tallyui/mock-api": "5.
|
|
46
|
+
"@tallyui/connector-medusa": "5.1.0",
|
|
47
|
+
"@tallyui/connector-vendure": "5.1.0",
|
|
48
|
+
"@tallyui/connector-woocommerce": "5.1.0",
|
|
49
|
+
"@tallyui/mock-api": "5.1.0",
|
|
50
50
|
"@types/react": ">=18",
|
|
51
51
|
"react": "^19.2.4",
|
|
52
52
|
"react-native-svg": "15.12.1",
|
package/src/sale/cart.tsx
CHANGED
|
@@ -20,10 +20,14 @@ import { useT } from '../i18n';
|
|
|
20
20
|
import { saleErrorText } from './sale-error-text';
|
|
21
21
|
|
|
22
22
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
23
|
-
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal = true, couponDiscountMinor, orderActions = true, orderDiscountChips = true, checkout, noteSheet, tenderLedger, picker, lineEditor = 'inline',
|
|
23
|
+
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, taxDisplay = 'itemized', canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal = true, couponDiscountMinor, orderActions = true, orderDiscountChips = true, checkout, noteSheet, tenderLedger, picker, lineEditor = 'inline',
|
|
24
24
|
lineCommit = 'apply', columns, chargeTaxSwitch = true,
|
|
25
25
|
emptyIcon = <ShoppingCartIcon size={48} />, emptyText = 'Tap a product to start a sale' }:
|
|
26
|
-
{ sale: ReturnType<typeof useSale>;
|
|
26
|
+
{ sale: ReturnType<typeof useSale>;
|
|
27
|
+
/** Names each tax row from its rate. The second argument carries the row's own tax `code` (when it has one) and `ratePpm`, so two rates with the same percentage can be told apart. */
|
|
28
|
+
taxLabel?: (ratePpm: number, rate: { code?: string; ratePpm: number }) => string;
|
|
29
|
+
/** `itemized` (default): one row per rate, under `taxLabel`. `single`: one "Total Tax" row with the order's total tax, drawn only when that is not 0. */
|
|
30
|
+
taxDisplay?: 'itemized' | 'single';
|
|
27
31
|
taxClasses?: ReadonlyArray<{ id: string; label: string }>;
|
|
28
32
|
/** Shows a Price action on each line. Pass the till's own permission; the control isn't shown without it. */
|
|
29
33
|
canEditPrice?: boolean;
|
|
@@ -94,7 +98,9 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
94
98
|
const money = (amount: number) => ({ amount, currency: order.currency });
|
|
95
99
|
// order.display's figures (TallyUI ADR-063), with its tax split by rate; never app arithmetic (medusapos ADR 0008).
|
|
96
100
|
const { totals, fees, shipping } = buildReceiptData(order, { storeName: '' });
|
|
97
|
-
const taxRows =
|
|
101
|
+
const taxRows = taxDisplay === 'single'
|
|
102
|
+
? totals.taxMinor !== 0 ? [{ label: 'Total Tax', amount: money(totals.taxMinor) }] : []
|
|
103
|
+
: totals.taxLines.map((line) => ({ label: taxLabel(line.ratePpm, { code: line.code, ratePpm: line.ratePpm }), amount: money(line.amountMinor) }));
|
|
98
104
|
// Each line before its discounts, with its own discounts' amounts. The order discounts are one figure: a single
|
|
99
105
|
// order discount's chip carries it; several keep their own labels, as no single one has a display amount.
|
|
100
106
|
const display = (lineId: string) => order.display.lines.find((line) => line.lineId === lineId)!;
|
package/src/sale/orders-list.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
|
-
import { useFormatMoney, knownWarnings } from '@tallyui/core';
|
|
4
|
-
import { extrasNotSent, isRequeueableOrder, needsAdminReasonOf, needsAttention, noteDelivery, refundDueOf, REOPENABLE_CODES, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
3
|
+
import { useFormatMoney, knownWarnings, type SettleOutcome } from '@tallyui/core';
|
|
4
|
+
import { canCancelOnStore, canPayRestOnStore, extrasNotSent, isRequeueableOrder, needsAdminReasonOf, needsAttention, noteDelivery, refundDueOf, REOPENABLE_CODES, settledOnStore, storeOrderLeft, unrecordedLegs, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
5
5
|
import { META_NOT_SENT, NOTE_NOT_SENT, orderReference, TAX_IDS_NOT_SENT } from './order-reference';
|
|
6
6
|
import { sinceText } from './since-text';
|
|
7
|
+
import { ConfirmDialog } from '../ui/confirm-dialog';
|
|
7
8
|
|
|
8
9
|
/** One order from the store's own history (ADR-052 amendment 1), mapped by the app from its platform. */
|
|
9
10
|
export type OrderHistoryRow = {
|
|
@@ -34,6 +35,9 @@ const REFUSAL_SENTENCES = new Map([
|
|
|
34
35
|
]);
|
|
35
36
|
// Any other code, or none: platform_error's sentence, as the generic fallback (approved by the Front desk, 2026-09-30).
|
|
36
37
|
const refusalSentence = (code: string | undefined) => REFUSAL_SENTENCES.get(code ?? '') ?? REFUSAL_SENTENCES.get('platform_error')!;
|
|
38
|
+
/** Pay the rest on store's dialog (#1101 slice 3): the front desk's wording until slice 4 handles money given back. */
|
|
39
|
+
const GIVE_BACK = "If the money was given back, do not record it; a manager must check the order in the store's admin.";
|
|
40
|
+
const methodLabel = (method: string) => (method === 'cash' ? 'Cash' : 'Card terminal');
|
|
37
41
|
const REOPEN_AGAIN_SENTENCE = "This order was changed in the online store after it was reopened here, so your change wasn't sent. Reopen the order and make the change again.";
|
|
38
42
|
|
|
39
43
|
/** Keeps an unparseable value as is, like medusapos's date util, since `Intl` throws on an invalid date. */
|
|
@@ -60,11 +64,46 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
60
64
|
// The order's own stuck entry: its clock and latest reason, not the earliest across all stuck orders.
|
|
61
65
|
const stuckEntry = order.syncStatus === 'pending' ? stuck?.orders.find((entry) => entry.commandId === order.commandId) : undefined;
|
|
62
66
|
const needsAdminReason = stuckEntry ? needsAdminReasonOf(stuckEntry.reason) : undefined;
|
|
67
|
+
const left = storeOrderLeft(order);
|
|
68
|
+
// #1101: the store created this order, so invalid_payload's "a form the store can't read" would be wrong.
|
|
63
69
|
const sentence = order.syncStatus === 'rejected'
|
|
64
70
|
? order.storeOrderId !== undefined && ['reopen_required', 'revision_conflict'].includes(order.error?.code ?? '')
|
|
65
|
-
? REOPEN_AGAIN_SENTENCE : refusalSentence(order.error?.code)
|
|
71
|
+
? REOPEN_AGAIN_SENTENCE : refusalSentence(left && order.error?.code === 'invalid_payload' ? 'platform_error' : order.error?.code)
|
|
66
72
|
: order.syncStatus === 'pending' && order.error?.code === UPDATE_UNSENDABLE ? UPDATE_UNSENDABLE_MESSAGE : undefined;
|
|
67
73
|
const extras = extrasNotSent(order);
|
|
74
|
+
// #1101: where the till's cancel, or pay of the rest, of the order the refused sale left on the store stands. Done, gone
|
|
75
|
+
// and changed say it in place of the "left" line; refused and sending add to it. The store's code and message never show (#269).
|
|
76
|
+
const kind = order.storeSettlement?.kind;
|
|
77
|
+
const settlement = order.syncStatus === 'rejected' && (kind === 'cancel' || kind === 'pay') ? order.storeSettlement : undefined;
|
|
78
|
+
const reference = left?.reference ?? orderReference(order);
|
|
79
|
+
const money = (amount: number) => formatMoney({ amount, currency: order.currency });
|
|
80
|
+
const sum = (legs: { amountMinor: number }[]) => legs.reduce((total, leg) => total + leg.amountMinor, 0);
|
|
81
|
+
const paidThere = settlement?.capturedMinor ? `: ${money(settlement.capturedMinor)} is paid there` : '';
|
|
82
|
+
// A pay's R: what the store had recorded at the refusal, plus each leg this till has recorded since.
|
|
83
|
+
const recorded = money((left?.recordedMinor ?? 0) + sum(settlement?.payments?.filter((payment) => payment.done) ?? []));
|
|
84
|
+
const cashTaken = sum(order.payments.filter((payment) => payment.method === 'cash'));
|
|
85
|
+
// What this till has recorded on the stored pay, on this press or an earlier one: true in every state.
|
|
86
|
+
const doneMinor = sum(settlement?.payments?.filter((payment) => payment.done) ?? []);
|
|
87
|
+
const nothing = doneMinor > 0 ? `${money(doneMinor)} was recorded from this till.` : 'Nothing was recorded from this till.';
|
|
88
|
+
const settledText = settlement?.kind === 'pay'
|
|
89
|
+
? settlement.state === 'done' ? `Order #${reference} is paid on the store.`
|
|
90
|
+
: settlement.state === 'gone' ? `Order #${reference} is not on the store any more; ${recorded} was recorded on it.`
|
|
91
|
+
: settlement.state !== 'changed' ? undefined
|
|
92
|
+
: settlement.storeStatus === 'completed' ? `Order #${reference} is already paid on the store. ${nothing}`
|
|
93
|
+
: `Order #${reference} changed on the store${paidThere}. ${nothing} Check it in the store's admin.`
|
|
94
|
+
: settlement?.state === 'done' ? `Order #${reference} was cancelled on the store.${cashTaken
|
|
95
|
+
? ` If you gave back the ${money(cashTaken)} cash taken on this till, record it as a pay-out.` : ''}`
|
|
96
|
+
: settlement?.state === 'gone' ? `Order #${reference} was removed on the store.`
|
|
97
|
+
: settlement?.state === 'changed' ? `Order #${reference} changed on the store${paidThere}. Nothing was cancelled from this till. Check it in the store's admin.`
|
|
98
|
+
: undefined;
|
|
99
|
+
const pay = settlement?.kind === 'pay';
|
|
100
|
+
const addedText = settlement?.state === 'refused' ? pay
|
|
101
|
+
? `The store did not record the rest of order #${reference}: ${recorded} of ${money(order.totalMinor)} is recorded there. Check it in the store's admin.`
|
|
102
|
+
: `The store did not cancel order #${reference}. Check it in the store's admin.`
|
|
103
|
+
: settlement?.state === 'sending' ? pay ? `Recording the rest of order #${reference} on the store is not finished.`
|
|
104
|
+
: `Cancelling order #${reference} on the store is not finished.` : undefined;
|
|
105
|
+
// A pay gone with money recorded on the store is not settled (`settledOnStore`): it stays a destructive line.
|
|
106
|
+
const settled = !!settlement && settledOnStore(order);
|
|
68
107
|
return <>
|
|
69
108
|
{stuckEntry ? <Text className="text-destructive">
|
|
70
109
|
{/* A parked sale needs a manager; other retries keep the hour as the status line has it (numeric, #245), with no reason code. */}
|
|
@@ -73,7 +112,15 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
73
112
|
: `Hasn't reached the online store since ${sinceText(stuckEntry)}.`}
|
|
74
113
|
</Text> : null}
|
|
75
114
|
{/* The code's sentence alone: the cashier sees no error code and never the store's message. */}
|
|
76
|
-
{sentence ? <Text className="text-destructive">{sentence}</Text> : null}
|
|
115
|
+
{sentence && !settled ? <Text className="text-destructive">{sentence}</Text> : null}
|
|
116
|
+
{settledText ? <Text testID={`order-settlement-${order.id}`} className={settled ? 'text-foreground' : 'text-destructive'}>{settledText}</Text> : null}
|
|
117
|
+
{/* What the store had recorded at the refusal, not the order's state now. */}
|
|
118
|
+
{left && !settledText ? <Text testID={`order-left-on-store-${order.id}`} className="text-destructive">
|
|
119
|
+
{left.recordedMinor === 0
|
|
120
|
+
? `Order #${left.reference} was left pending on the online store. Nothing was paid there.`
|
|
121
|
+
: `Order #${left.reference} was left part paid on the online store: ${formatMoney({ amount: left.recordedMinor, currency: order.currency })} of ${formatMoney({ amount: order.totalMinor, currency: order.currency })}.`}
|
|
122
|
+
</Text> : null}
|
|
123
|
+
{addedText ? <Text testID={`order-settlement-${order.id}`} className="text-destructive">{addedText}</Text> : null}
|
|
77
124
|
{/* A late sale (ADR-032) needs no Retry of its own; a rejected one still gets its Retry below. */}
|
|
78
125
|
{order.lateSessionId !== undefined ? <Text className="text-foreground">Taken after the register closed. It is not in that register's closure.</Text> : null}
|
|
79
126
|
{order.countedInClosureOf !== undefined ? <Text className="text-foreground">Recorded after the register closed. Its payment is in that register's closure.</Text> : null}
|
|
@@ -116,14 +163,24 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
116
163
|
* `onReopen` adds Reopen to a Needs attention row the store refused with a reopenable code (`REOPENABLE_CODES`), not yet
|
|
117
164
|
* reopened and with no store order: the app wires `reopenRefusedOrder`. When it refuses `coupon_carry_inexact` with a
|
|
118
165
|
* `toCollectMinor`, the row offers "Reopen without the coupon", which calls it again with `{ withoutCoupons: true }`.
|
|
119
|
-
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
120
|
-
|
|
166
|
+
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
167
|
+
* `onCancelOnStore` adds "Cancel order on store" to a Needs attention row whose refused sale left an unpaid order on the
|
|
168
|
+
* store (`canCancelOnStore`, #1101), asked in a confirm dialog first: the app wires `useOrderOutbox`'s `cancelOnStore`.
|
|
169
|
+
* A cancel still `sending` is finished with no dialog. With it, such a row offers no Retry, except an `insufficient_stock`
|
|
170
|
+
* refusal's, which reads "Try the payment again".
|
|
171
|
+
* `onPayRestOnStore` adds "Pay the rest on store" to a Needs attention row whose refused sale left a part-paid order on
|
|
172
|
+
* the store (`canPayRestOnStore`, #1101 slice 3), asked in a confirm dialog naming each leg to record (no money is taken):
|
|
173
|
+
* the app wires `useOrderOutbox`'s `payRestOnStore`. A pay still `sending` is finished with no dialog. With it, a row
|
|
174
|
+
* with money recorded on the store offers no Retry. */
|
|
175
|
+
export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore }: {
|
|
121
176
|
orders: PosOrder[]; onRetry(orderIds: string[]): Promise<number>; formatDate?: (iso: string) => string; footer?: ReactNode;
|
|
122
177
|
stuck?: OutboxState['stuck'];
|
|
123
178
|
history?: OrderHistoryRow[];
|
|
124
179
|
onOpen?: (row: PosOrder | OrderHistoryRow) => void;
|
|
125
180
|
onReopen?: (order: PosOrder, options?: { withoutCoupons: true }) => Promise<void>;
|
|
126
181
|
onResume?: (order: PosOrder) => void;
|
|
182
|
+
onCancelOnStore?: (order: PosOrder) => Promise<SettleOutcome | { kind: 'not_offered' }>;
|
|
183
|
+
onPayRestOnStore?: (order: PosOrder) => Promise<SettleOutcome | { kind: 'not_offered' }>;
|
|
127
184
|
}) {
|
|
128
185
|
const formatMoney = useFormatMoney();
|
|
129
186
|
const hintId = useId();
|
|
@@ -153,6 +210,51 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
153
210
|
reopening.current.delete(order.id);
|
|
154
211
|
}
|
|
155
212
|
}
|
|
213
|
+
/** Each row's Cancel order on store (#1101): in flight, or the last press got no answer from the store. */
|
|
214
|
+
const cancelling = useRef(new Set<string>());
|
|
215
|
+
const [cancels, setCancels] = useState(new Map<string, 'busy' | 'failed'>());
|
|
216
|
+
const [askingCancel, setAskingCancel] = useState<PosOrder | null>(null);
|
|
217
|
+
const setCancel = (id: string, state?: 'busy' | 'failed') => setCancels((current) => {
|
|
218
|
+
const next = new Map(current);
|
|
219
|
+
if (state) next.set(id, state); else next.delete(id);
|
|
220
|
+
return next;
|
|
221
|
+
});
|
|
222
|
+
async function cancelOnStore(order: PosOrder) {
|
|
223
|
+
if (!onCancelOnStore || cancelling.current.has(order.id)) return;
|
|
224
|
+
cancelling.current.add(order.id);
|
|
225
|
+
setCancel(order.id, 'busy');
|
|
226
|
+
try {
|
|
227
|
+
const outcome = await onCancelOnStore(order);
|
|
228
|
+
setCancel(order.id, outcome.kind === 'retry' ? 'failed' : undefined);
|
|
229
|
+
} catch {
|
|
230
|
+
setCancel(order.id, 'failed');
|
|
231
|
+
} finally {
|
|
232
|
+
cancelling.current.delete(order.id);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** Each row's Pay the rest on store (#1101 slice 3): in flight, the last press got no answer from the store, or the store
|
|
236
|
+
* answered that the order is not completed there yet (`not_completed`). */
|
|
237
|
+
const paying = useRef(new Set<string>());
|
|
238
|
+
const [pays, setPays] = useState(new Map<string, 'busy' | 'failed' | 'unfinished'>());
|
|
239
|
+
const [askingPay, setAskingPay] = useState<PosOrder | null>(null);
|
|
240
|
+
const setPay = (id: string, state?: 'busy' | 'failed' | 'unfinished') => setPays((current) => {
|
|
241
|
+
const next = new Map(current);
|
|
242
|
+
if (state) next.set(id, state); else next.delete(id);
|
|
243
|
+
return next;
|
|
244
|
+
});
|
|
245
|
+
async function payRestOnStore(order: PosOrder) {
|
|
246
|
+
if (!onPayRestOnStore || paying.current.has(order.id)) return;
|
|
247
|
+
paying.current.add(order.id);
|
|
248
|
+
setPay(order.id, 'busy');
|
|
249
|
+
try {
|
|
250
|
+
const outcome = await onPayRestOnStore(order);
|
|
251
|
+
setPay(order.id, outcome.kind !== 'retry' ? undefined : outcome.reason === 'not_completed' ? 'unfinished' : 'failed');
|
|
252
|
+
} catch {
|
|
253
|
+
setPay(order.id, 'failed');
|
|
254
|
+
} finally {
|
|
255
|
+
paying.current.delete(order.id);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
156
258
|
const [expanded, setExpanded] = useState(new Set<string>());
|
|
157
259
|
useEffect(() => {
|
|
158
260
|
for (const id of retrying.current) {
|
|
@@ -194,6 +296,17 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
194
296
|
const reopenable = attention && !!onReopen && order.syncStatus === 'rejected' && REOPENABLE_CODES.includes(order.error?.code ?? '')
|
|
195
297
|
&& order.storeOrderId === undefined && order.reopenedAt === undefined;
|
|
196
298
|
const reopenState = reopens.get(order.id);
|
|
299
|
+
const cancellable = attention && !!onCancelOnStore && canCancelOnStore(order);
|
|
300
|
+
const cancelState = cancels.get(order.id);
|
|
301
|
+
const finishing = order.storeSettlement?.kind === 'cancel' && order.storeSettlement.state === 'sending';
|
|
302
|
+
// #1101: with the cancel wired, an unpaid order left on the store is cancelled rather than resent, except a stock refusal.
|
|
303
|
+
const left = storeOrderLeft(order);
|
|
304
|
+
const payable = attention && !!onPayRestOnStore && canPayRestOnStore(order);
|
|
305
|
+
const payState = pays.get(order.id);
|
|
306
|
+
const finishingPay = order.storeSettlement?.kind === 'pay' && order.storeSettlement.state === 'sending';
|
|
307
|
+
// #1101 slice 3: with the pay wired, a part-paid order left on the store has its rest recorded, never resent.
|
|
308
|
+
const retryLabel = onPayRestOnStore && left && left.recordedMinor > 0 ? undefined : onCancelOnStore && left?.recordedMinor === 0
|
|
309
|
+
? order.error?.code === 'insufficient_stock' ? 'Try the payment again' : undefined : 'Retry';
|
|
197
310
|
return (
|
|
198
311
|
<View key={order.id} className="gap-1 rounded-md border border-border bg-card p-3">
|
|
199
312
|
{/* RN-web drops accessibilityHint; aria-describedby carries it on web. */}
|
|
@@ -216,7 +329,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
216
329
|
{isExpanded ? <View testID={`order-detail-${order.id}`} className="mt-1 gap-1 border-t border-border pt-2">
|
|
217
330
|
{order.lines.map((line) => <Text key={line.id} className="text-foreground">{`${line.quantity} × ${line.name}`}</Text>)}
|
|
218
331
|
{order.payments.map((payment) => <Text key={payment.id} className="text-muted-foreground">
|
|
219
|
-
{`${payment.method
|
|
332
|
+
{`${methodLabel(payment.method)} ${formatMoney({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` · ${payment.reference}` : ''}`}
|
|
220
333
|
</Text>)}
|
|
221
334
|
{refundDueMinor > 0 ? <Text testID={`order-refund-due-${order.id}`} className="text-foreground">
|
|
222
335
|
{`Refund due ${formatMoney({ amount: refundDueMinor, currency: order.currency })}`}</Text> : null}
|
|
@@ -224,7 +337,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
224
337
|
</View> : null}
|
|
225
338
|
<OrderSyncNotices order={order} stuck={stuck}>
|
|
226
339
|
{/* Retry is offered only for an order the outbox resends (isRequeueableOrder). */}
|
|
227
|
-
{section.title === 'Needs attention' && isRequeueableOrder(order)
|
|
340
|
+
{section.title === 'Needs attention' && isRequeueableOrder(order) && retryLabel
|
|
228
341
|
? <Pressable accessibilityRole="button" disabled={retryingIds.has(order.id)} onPress={async () => {
|
|
229
342
|
if (retrying.current.has(order.id)) return;
|
|
230
343
|
retrying.current.add(order.id);
|
|
@@ -234,8 +347,30 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
234
347
|
setRetryingIds(new Set(retrying.current));
|
|
235
348
|
}
|
|
236
349
|
}} className="rounded-md bg-primary px-4 py-2">
|
|
237
|
-
<Text className="text-center font-semibold text-primary-foreground">
|
|
350
|
+
<Text className="text-center font-semibold text-primary-foreground">{retryLabel}</Text>
|
|
238
351
|
</Pressable> : null}
|
|
352
|
+
{cancellable ? <Pressable accessibilityRole="button" testID={`order-${order.id}-cancel-on-store`} disabled={cancelState === 'busy'}
|
|
353
|
+
onPress={() => {
|
|
354
|
+
if (cancelling.current.has(order.id)) return;
|
|
355
|
+
if (finishing) void cancelOnStore(order); else setAskingCancel(order);
|
|
356
|
+
}} className="rounded-md border border-border px-4 py-2">
|
|
357
|
+
<Text className="text-center font-semibold text-foreground">
|
|
358
|
+
{cancelState === 'busy' ? 'Cancelling on store…' : finishing ? 'Finish cancelling on store' : 'Cancel order on store'}
|
|
359
|
+
</Text>
|
|
360
|
+
</Pressable> : null}
|
|
361
|
+
{cancellable && cancelState === 'failed' ? <Text testID={`order-${order.id}-cancel-on-store-error`} className="text-muted-foreground">
|
|
362
|
+
Could not reach the store. Try again.</Text> : null}
|
|
363
|
+
{payable ? <Pressable accessibilityRole="button" testID={`order-${order.id}-pay-rest-on-store`} disabled={payState === 'busy'}
|
|
364
|
+
onPress={() => {
|
|
365
|
+
if (paying.current.has(order.id)) return;
|
|
366
|
+
if (finishingPay) void payRestOnStore(order); else setAskingPay(order);
|
|
367
|
+
}} className="rounded-md bg-primary px-4 py-2">
|
|
368
|
+
<Text className="text-center font-semibold text-primary-foreground">
|
|
369
|
+
{payState === 'busy' ? 'Recording on store…' : finishingPay ? 'Finish recording on store' : 'Pay the rest on store'}
|
|
370
|
+
</Text>
|
|
371
|
+
</Pressable> : null}
|
|
372
|
+
{payable && (payState === 'failed' || payState === 'unfinished') ? <Text testID={`order-${order.id}-pay-rest-on-store-error`} className="text-muted-foreground">
|
|
373
|
+
{payState === 'unfinished' ? "The store has not finished this order yet. Try again, or check it in the store's admin." : 'Could not reach the store. Try again.'}</Text> : null}
|
|
239
374
|
{/* Reopen needs a reopenable code, which Retry never resends (NOT_REQUEUEABLE), so the two never show together. */}
|
|
240
375
|
{attention && order.reopenedAt !== undefined ? <>
|
|
241
376
|
<Text testID={`order-${order.id}-reopened`} className="text-muted-foreground">Reopened as a parked sale.</Text>
|
|
@@ -265,6 +400,20 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
265
400
|
})}
|
|
266
401
|
</View>
|
|
267
402
|
))}
|
|
403
|
+
{askingCancel ? ((reference) => <ConfirmDialog testID={`order-${askingCancel.id}-cancel-on-store-dialog`} tone="destructive" open
|
|
404
|
+
onOpenChange={(open) => { if (!open) setAskingCancel(null); }} title={`Cancel order #${reference} on the store?`}
|
|
405
|
+
description={`Order #${reference} is waiting on the online store with nothing paid. This cancels it there. The payments taken on this till stay as they are.`}
|
|
406
|
+
cancelLabel="Keep order" confirmLabel="Cancel order on store"
|
|
407
|
+
onConfirm={() => { setAskingCancel(null); void cancelOnStore(askingCancel); }} />)(storeOrderLeft(askingCancel)?.reference ?? orderReference(askingCancel)) : null}
|
|
408
|
+
{askingPay ? ((reference, legs, stored) => <ConfirmDialog testID={`order-${askingPay.id}-pay-rest-on-store-dialog`} tone="default" open
|
|
409
|
+
onOpenChange={(open) => { if (!open) setAskingPay(null); }} title={`Record the rest of order #${reference} on the store?`}
|
|
410
|
+
description={[...legs.filter((_leg, index) => !(stored?.kind === 'pay' && stored.payments?.length === legs.length && stored.payments[index].done))
|
|
411
|
+
.map((leg) => `${methodLabel(leg.method)} ${formatMoney({ amount: leg.amountMinor, currency: askingPay.currency })}, already taken on this till.`),
|
|
412
|
+
'No money is taken now.', GIVE_BACK].join('\n')}
|
|
413
|
+
cancelLabel="Keep as is" confirmLabel="Record on store"
|
|
414
|
+
onConfirm={() => { setAskingPay(null); void payRestOnStore(askingPay); }} />)(storeOrderLeft(askingPay)?.reference ?? orderReference(askingPay),
|
|
415
|
+
// Only the legs still to record: the stored pay is index-aligned with them when the lengths match, as the outbox reuses it.
|
|
416
|
+
unrecordedLegs(askingPay), askingPay.storeSettlement) : null}
|
|
268
417
|
{footer}
|
|
269
418
|
</ScrollView>;
|
|
270
419
|
}
|
package/src/sale/tender-pane.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { useEffect, useState, type ComponentProps, type JSX } from 'react';
|
|
|
9
9
|
import { Pressable, ScrollView, Text, TextInput, View } from 'react-native';
|
|
10
10
|
import { useFormatMoney, minorUnitDigits, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
|
|
11
11
|
import {
|
|
12
|
-
activePlan, CASH_PICK_ENTRIES_MAX, changeMinor, countsTowardPaid, evenSplitShareMinor, inMotionMinor, isInMotion, legStatus, lockedRefundDueMinor, nearestPayableCash, planLegs, quickTenderedAmounts, remainderEntriesMinor, roundedPickTarget, tenderRounding, tillLegsTheStoreRefuses,
|
|
12
|
+
activePlan, CASH_PICK_ENTRIES_MAX, changeMinor, countsTowardPaid, evenSplitShareMinor, inMotionMinor, isInMotion, legStatus, lockedRefundDueMinor, nearestPayableCash, planLegs, quickTenderedAmounts, remainderEntriesMinor, roundedPickTarget, tenderRounding, tillLegsTheStoreRefuses, writeOffLeg,
|
|
13
13
|
type TenderAction, type TenderKey, type TenderPlan, type TenderState, type useSale,
|
|
14
14
|
} from '@tallyui/pos';
|
|
15
15
|
import { cn } from '@tallyui/theme';
|
|
@@ -94,12 +94,16 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
|
|
|
94
94
|
const partPick = pick !== null && target < balance;
|
|
95
95
|
// ADR-094: the pane rounds exactly when addTender does: only on a store whose connector declares cashRounding, and only while no leg is in motion.
|
|
96
96
|
const rounds = sale.capabilities?.cashRounding === true && inMotionMinor(order.payments) === 0;
|
|
97
|
-
// ADR-094 (
|
|
97
|
+
// ADR-094 item 7 (carry): a cash part pick rounds its target less the live entries; addTender rounds the leg, the pane shows the same figure.
|
|
98
98
|
const pickRounding = rounds && method !== null && wireMethodOf(method) === 'cash' && method.capture.mode === 'manual' && method.defaults.rounding ? method.defaults.rounding : null;
|
|
99
|
-
const pickTarget = partPick ? roundedPickTarget(target, pickRounding) : target;
|
|
100
|
-
const entry = state.entryDirty ? state.entryMinor : pickTarget;
|
|
101
99
|
const entries = remainderEntriesMinor(order);
|
|
100
|
+
const pickTarget = partPick ? roundedPickTarget(target, pickRounding, entries) : target;
|
|
101
|
+
const entry = state.entryDirty ? state.entryMinor : pickTarget;
|
|
102
102
|
const figures = partPick ? tenderRounding({ entryMinor: entry, entryDirty: state.entryDirty }, pickTarget, null) : tenderRounding(state, balance, rounds ? method : null, entries);
|
|
103
|
+
// Promotion: a carried pick at the whole-settle due is taken as that settle (addTender), so it meets the settle's 16-entry cap.
|
|
104
|
+
const promoted = partPick && pickRounding !== null && pickTarget === tenderRounding(state, balance, method, entries).roundedDueMinor;
|
|
105
|
+
// "Rounded from": a pick's own goods when its amount differs from them; a settle's balance.
|
|
106
|
+
const roundedFrom = promoted ? (pickTarget !== balance ? balance : null) : partPick ? (pickTarget !== target ? target : null) : figures.roundingMinor !== 0 ? balance : null;
|
|
103
107
|
const cashNotPayable = rounds && pick === null && method !== null && wireMethodOf(method) === 'cash' && method.capture.mode === 'manual' && method.defaults.rounding
|
|
104
108
|
&& figures.roundingMinor === 0 && figures.appliedMinor < figures.roundedDueMinor
|
|
105
109
|
? nearestPayableCash(figures.entryMinor, method.defaults.rounding.incrementMinor) : null;
|
|
@@ -108,7 +112,7 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
|
|
|
108
112
|
? nearestPayableCash(target, method.defaults.rounding.incrementMinor) !== null
|
|
109
113
|
: figures.entryMinor > 0 && nearestPayableCash(Math.min(figures.entryMinor, balance - inMotionMinor(order.payments)), method.defaults.rounding.incrementMinor) !== null);
|
|
110
114
|
// order-payload-shape.ts's 16-entry cap: a pick that would add an entry is refused once the sale has CASH_PICK_ENTRIES_MAX.
|
|
111
|
-
const pickLimit = partPick && pickTarget !== target && (order.cashRoundings ?? []).length >= CASH_PICK_ENTRIES_MAX;
|
|
115
|
+
const pickLimit = partPick && !promoted && pickTarget !== target && (order.cashRoundings ?? []).length >= CASH_PICK_ENTRIES_MAX;
|
|
112
116
|
const pickRefused = (partPick && entry > 0 && (givesChange ? entry < pickTarget : entry !== pickTarget))
|
|
113
117
|
|| (pick !== null && !partPick && figures.appliedMinor > 0 && figures.appliedMinor < figures.roundedDueMinor);
|
|
114
118
|
// Row 500: judged against the due less the legs in motion, as addTender records the leg's change.
|
|
@@ -116,8 +120,8 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
|
|
|
116
120
|
const zeroDue = sale.capabilities?.cashRounding === true && !partPick && figures.roundedDueMinor === 0 && figures.roundingMinor !== 0
|
|
117
121
|
&& inMotionMinor(order.payments) === 0;
|
|
118
122
|
// The 16-entry cap as addTender applies it: a settle that adds an entry is refused at 16; a write-off onto a leg with one is not.
|
|
119
|
-
const lastCounted = order
|
|
120
|
-
const settleLimit = !partPick && sale.capabilities?.cashRounding === true && figures.roundingMinor !== 0
|
|
123
|
+
const lastCounted = writeOffLeg(order);
|
|
124
|
+
const settleLimit = ((!partPick && sale.capabilities?.cashRounding === true && figures.roundingMinor !== 0) || (promoted && pickTarget !== balance))
|
|
121
125
|
&& (order.cashRoundings ?? []).length > CASH_PICK_ENTRIES_MAX
|
|
122
126
|
&& !(zeroDue && lastCounted !== undefined && (order.cashRoundings ?? []).some((e) => e.paymentId === lastCounted.id));
|
|
123
127
|
// With no other method, a cash-only store frees an entry by voiding its latest rounded cash leg, which no later cash leg's entry blocks; offered methods are all manual capture.
|
|
@@ -224,10 +228,10 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
|
|
|
224
228
|
{changeLeads ? <>
|
|
225
229
|
<Text testID="tender-entry-hint" className="text-4xl font-bold text-success">{hint}</Text>
|
|
226
230
|
<Text testID="tender-tendered-line" className="min-h-6 text-sm text-muted-foreground">{t('pos_checkout.tendered')} <Text testID="tender-entry-amount" className="font-semibold text-foreground">{money(figures.entryMinor)}</Text>{order.totalMinor !== balance ? ` · ${t('common.total')} ${money(order.totalMinor)}` : ''}</Text>
|
|
227
|
-
{
|
|
231
|
+
{roundedFrom !== null ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(roundedFrom) })}</Text> : null}
|
|
228
232
|
</> : <>
|
|
229
233
|
<Text testID="tender-entry-amount" className={cn('text-4xl font-bold text-foreground', !state.entryDirty && 'opacity-70')}>{money(figures.entryMinor)}</Text>
|
|
230
|
-
{
|
|
234
|
+
{roundedFrom !== null ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(roundedFrom) })}</Text> : null}
|
|
231
235
|
<Text testID="tender-entry-hint" className={cn('min-h-6 text-center text-sm', noChange || capped || pickRefused || cashWaits || pickLimit || settleLimit ? 'text-warning-text' : 'text-muted-foreground')}>{hint}</Text>
|
|
232
236
|
</>}
|
|
233
237
|
</View> : null}
|