@tallyui/components 5.1.0 → 5.2.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 +6 -1
- package/dist/index.js +109 -12
- package/package.json +9 -9
- package/src/order/refund-form.tsx +9 -1
- package/src/sale/orders-list.tsx +72 -12
package/dist/index.d.ts
CHANGED
|
@@ -3301,6 +3301,7 @@ declare function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPr
|
|
|
3301
3301
|
* reopened and with no store order: the app wires `reopenRefusedOrder`. When it refuses `coupon_carry_inexact` with a
|
|
3302
3302
|
* `toCollectMinor`, the row offers "Reopen without the coupon", which calls it again with `{ withoutCoupons: true }`.
|
|
3303
3303
|
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
3304
|
+
* `openSessionId` must match the session of every till payment to offer or finish either store cancellation action.
|
|
3304
3305
|
* `onCancelOnStore` adds "Cancel order on store" to a Needs attention row whose refused sale left an unpaid order on the
|
|
3305
3306
|
* store (`canCancelOnStore`, #1101), asked in a confirm dialog first: the app wires `useOrderOutbox`'s `cancelOnStore`.
|
|
3306
3307
|
* A cancel still `sending` is finished with no dialog. With it, such a row offers no Retry, except an `insufficient_stock`
|
|
@@ -3309,7 +3310,7 @@ declare function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPr
|
|
|
3309
3310
|
* the store (`canPayRestOnStore`, #1101 slice 3), asked in a confirm dialog naming each leg to record (no money is taken):
|
|
3310
3311
|
* the app wires `useOrderOutbox`'s `payRestOnStore`. A pay still `sending` is finished with no dialog. With it, a row
|
|
3311
3312
|
* with money recorded on the store offers no Retry. */
|
|
3312
|
-
declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore }: {
|
|
3313
|
+
declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore, onReverseOnStore, openSessionId }: {
|
|
3313
3314
|
orders: PosOrder[];
|
|
3314
3315
|
onRetry(orderIds: string[]): Promise<number>;
|
|
3315
3316
|
formatDate?: (iso: string) => string;
|
|
@@ -3321,12 +3322,16 @@ declare function OrdersList({ orders, onRetry, formatDate, footer, stuck, histor
|
|
|
3321
3322
|
withoutCoupons: true;
|
|
3322
3323
|
}) => Promise<void>;
|
|
3323
3324
|
onResume?: (order: PosOrder) => void;
|
|
3325
|
+
openSessionId?: string;
|
|
3324
3326
|
onCancelOnStore?: (order: PosOrder) => Promise<SettleOutcome | {
|
|
3325
3327
|
kind: 'not_offered';
|
|
3326
3328
|
}>;
|
|
3327
3329
|
onPayRestOnStore?: (order: PosOrder) => Promise<SettleOutcome | {
|
|
3328
3330
|
kind: 'not_offered';
|
|
3329
3331
|
}>;
|
|
3332
|
+
onReverseOnStore?: (order: PosOrder) => Promise<SettleOutcome | {
|
|
3333
|
+
kind: 'not_offered';
|
|
3334
|
+
}>;
|
|
3330
3335
|
}): react_jsx_runtime.JSX.Element;
|
|
3331
3336
|
|
|
3332
3337
|
/** 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
|
@@ -6256,7 +6256,7 @@ function OrderDetail({
|
|
|
6256
6256
|
// src/order/refund-form.tsx
|
|
6257
6257
|
import { useRef as useRef15, useState as useState31 } from "react";
|
|
6258
6258
|
import { Pressable as Pressable34, ScrollView as ScrollView13, View as View71 } from "react-native";
|
|
6259
|
-
import { useFormatMoney as useFormatMoney8, useMoneyFormat as useMoneyFormat3 } from "@tallyui/core";
|
|
6259
|
+
import { useFormatMoney as useFormatMoney8, useMoneyFormat as useMoneyFormat3, useOptionalConnector } from "@tallyui/core";
|
|
6260
6260
|
import { priceRefund, refundableLines } from "@tallyui/pos";
|
|
6261
6261
|
|
|
6262
6262
|
// src/lib/error-text.ts
|
|
@@ -6395,6 +6395,7 @@ function RefundForm({
|
|
|
6395
6395
|
}) {
|
|
6396
6396
|
const formatMoney2 = useFormatMoney8();
|
|
6397
6397
|
const format2 = useMoneyFormat3();
|
|
6398
|
+
const lineTotalsShrinkOnReturn = useOptionalConnector()?.lineTotalsShrinkOnReturn === true;
|
|
6398
6399
|
const [quantities, setQuantities] = useState31({});
|
|
6399
6400
|
const [restock, setRestock] = useState31({});
|
|
6400
6401
|
const [shippingText, setShippingText] = useState31("");
|
|
@@ -6412,6 +6413,11 @@ function RefundForm({
|
|
|
6412
6413
|
quantity: Math.min(quantities[orderLineId] ?? 0, refundableQuantity),
|
|
6413
6414
|
restock: restock[orderLineId] ?? defaultRestock
|
|
6414
6415
|
})).filter(({ quantity }) => quantity > 0);
|
|
6416
|
+
const missingSoldFigures = lineTotalsShrinkOnReturn && request.find(({ orderLineId, quantity }) => {
|
|
6417
|
+
const index = lines.findIndex((line2) => line2.id === orderLineId);
|
|
6418
|
+
const line = lines[index];
|
|
6419
|
+
return (line.soldTotalMinor === void 0 || line.soldTaxMinor === void 0) && (quantity < line.quantity || available[index].refundedQuantity > 0);
|
|
6420
|
+
});
|
|
6415
6421
|
const priced = priceRefund(lines, refunds, request);
|
|
6416
6422
|
const emptiesLines = priced.lines.length > 0 && available.every(({ orderLineId, refundableQuantity }) => (request.find((line) => line.orderLineId === orderLineId)?.quantity ?? 0) === refundableQuantity);
|
|
6417
6423
|
const roundingShareMinor = emptiesLines ? cashRoundingMinor : 0;
|
|
@@ -6420,7 +6426,7 @@ function RefundForm({
|
|
|
6420
6426
|
const totalMinor = typeof shippingMinor === "number" && typeof adjustmentMinor === "number" ? priced.totalMinor + shippingMinor + adjustmentMinor + roundingShareMinor : void 0;
|
|
6421
6427
|
const destination = originalMethod?.available ? picked ?? "original_method" : "cash";
|
|
6422
6428
|
const cashStep = destination === "cash" && Number.isInteger(cashIncrementMinor) && cashIncrementMinor > 1 && typeof totalMinor === "number" && totalMinor > 0 && totalMinor % cashIncrementMinor !== 0;
|
|
6423
|
-
const invalid = typeof shippingMinor === "string" ? shippingMinor : typeof adjustmentMinor === "string" ? adjustmentMinor : shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.` : priced.lines.length === 0 && shippingMinor === 0 && adjustmentMinor === 0 ? "Choose something to refund." : totalMinor <= 0 ? "The refund total must be more than 0." : totalMinor > orderTotalMinor - refundedMinor ? `You can refund at most ${fmt(orderTotalMinor - refundedMinor)}.` : reason.trim() === "" ? "Enter a reason." : null;
|
|
6429
|
+
const invalid = typeof shippingMinor === "string" ? shippingMinor : typeof adjustmentMinor === "string" ? adjustmentMinor : missingSoldFigures ? `Update the store's plugin to refund part of ${lines.find((line) => line.id === missingSoldFigures.orderLineId).name}.` : shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.` : priced.lines.length === 0 && shippingMinor === 0 && adjustmentMinor === 0 ? "Choose something to refund." : totalMinor <= 0 ? "The refund total must be more than 0." : totalMinor > orderTotalMinor - refundedMinor ? `You can refund at most ${fmt(orderTotalMinor - refundedMinor)}.` : reason.trim() === "" ? "Enter a reason." : null;
|
|
6424
6430
|
const disabled = !!invalid || online === false || busy;
|
|
6425
6431
|
const confirm = async () => {
|
|
6426
6432
|
if (invalid || online === false || busyRef.current) return;
|
|
@@ -12764,7 +12770,7 @@ function SyncStatus({ state, registerState, pluginName = "the POS plugin", pullN
|
|
|
12764
12770
|
import { useEffect as useEffect24, useId as useId4, useRef as useRef26, useState as useState57 } from "react";
|
|
12765
12771
|
import { Pressable as Pressable56, ScrollView as ScrollView23, Text as Text58, View as View118 } from "react-native";
|
|
12766
12772
|
import { useFormatMoney as useFormatMoney26, knownWarnings } from "@tallyui/core";
|
|
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";
|
|
12773
|
+
import { canCancelOnStore, canPayRestOnStore, canReverseOnStore, extrasNotSent, isRequeueableOrder, needsAdminReasonOf as needsAdminReasonOf2, needsAttention, noteDelivery as noteDelivery2, refundDueOf, REOPENABLE_CODES, settledOnStore, storeOrderLeft, TILL_SESSION_CLOSED, tillPayments, unrecordedLegs, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE } from "@tallyui/pos";
|
|
12768
12774
|
import { Fragment as Fragment48, jsx as jsx190, jsxs as jsxs126 } from "react/jsx-runtime";
|
|
12769
12775
|
var STATUS_LABEL2 = { pending: "Waiting to sync", applied: "Synced", rejected: "Not accepted" };
|
|
12770
12776
|
var FIGURE_LABELS = /* @__PURE__ */ new Map([["subtotalMinor", "Subtotal"], ["taxMinor", "Tax"], ["discountMinor", "Discount"]]);
|
|
@@ -12786,6 +12792,11 @@ var REFUSAL_SENTENCES = /* @__PURE__ */ new Map([
|
|
|
12786
12792
|
]);
|
|
12787
12793
|
var refusalSentence = (code) => REFUSAL_SENTENCES.get(code ?? "") ?? REFUSAL_SENTENCES.get("platform_error");
|
|
12788
12794
|
var GIVE_BACK = "If the money was given back, do not record it; a manager must check the order in the store's admin.";
|
|
12795
|
+
var GIVE_BACK_INSTEAD = "If the money was given back, use Give back and cancel instead.";
|
|
12796
|
+
var GIVE = "Give back any of this you have not already given back.";
|
|
12797
|
+
var CLOSED_SESSION_NOTICE = "Taken in a session that has closed: a manager must settle this sale in the store's admin.";
|
|
12798
|
+
var legLabel = (method) => method === "cash" ? "Cash" : "Card";
|
|
12799
|
+
var legWording = (method, amount) => `${legLabel(method)} ${amount}: ${method === "cash" ? "hand it back from the drawer" : "give it back on the card terminal"}`;
|
|
12789
12800
|
var methodLabel = (method) => method === "cash" ? "Cash" : "Card terminal";
|
|
12790
12801
|
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.";
|
|
12791
12802
|
function defaultFormatDate2(iso2) {
|
|
@@ -12802,18 +12813,38 @@ function OrderSyncNotices({ order, stuck, children }) {
|
|
|
12802
12813
|
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;
|
|
12803
12814
|
const extras = extrasNotSent(order);
|
|
12804
12815
|
const kind = order.storeSettlement?.kind;
|
|
12805
|
-
const settlement = order.syncStatus === "rejected" && (kind === "cancel" || kind === "pay") ? order.storeSettlement : void 0;
|
|
12816
|
+
const settlement = order.syncStatus === "rejected" && (kind === "cancel" || kind === "pay" || kind === "reverse" && order.storeSettlement?.legs?.length) ? order.storeSettlement : void 0;
|
|
12806
12817
|
const reference = left?.reference ?? orderReference(order);
|
|
12807
12818
|
const money = (amount) => formatMoney2({ amount, currency: order.currency });
|
|
12808
12819
|
const sum = (legs) => legs.reduce((total, leg) => total + leg.amountMinor, 0);
|
|
12809
12820
|
const paidThere = settlement?.capturedMinor ? `: ${money(settlement.capturedMinor)} is paid there` : "";
|
|
12810
12821
|
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
12822
|
const doneMinor = sum(settlement?.payments?.filter((payment) => payment.done) ?? []);
|
|
12813
12823
|
const nothing = doneMinor > 0 ? `${money(doneMinor)} was recorded from this till.` : "Nothing was recorded from this till.";
|
|
12814
|
-
|
|
12824
|
+
let 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.${order.payments.length || kind === "reverse" ? ` The till took: ${order.payments.map((leg) => legWording(leg.method, money(leg.amountMinor))).join("; ")}. ${GIVE}` : ""}` : 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
12825
|
const pay = settlement?.kind === "pay";
|
|
12816
|
-
|
|
12826
|
+
let 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;
|
|
12827
|
+
if (settlement?.kind === "reverse" && settlement.state !== "done" && settlement.legs) {
|
|
12828
|
+
const legs = settlement.legs.flatMap((leg) => {
|
|
12829
|
+
const payment = order.payments.find(({ id }) => id === leg.paymentId);
|
|
12830
|
+
return payment ? [{ ...payment, done: leg.done }] : [];
|
|
12831
|
+
});
|
|
12832
|
+
const taken = legs.filter((leg) => leg.done).map((leg) => legWording(leg.method, money(leg.amountMinor))).join("; ");
|
|
12833
|
+
const still = legs.filter((leg) => !leg.done).map((leg) => `${legLabel(leg.method)} ${money(leg.amountMinor)}`).join("; ");
|
|
12834
|
+
const hasDone = settlement.legs.some((leg) => leg.done);
|
|
12835
|
+
const subject = `Order #${reference}`;
|
|
12836
|
+
settledText = void 0;
|
|
12837
|
+
addedText = void 0;
|
|
12838
|
+
if (settlement.state === "gone") settledText = `${subject} is not on the store any more.${taken ? ` The store had taken off: ${taken}. ${GIVE}` : ""} Check it in the store's admin.`;
|
|
12839
|
+
else if (settlement.state === "sending") addedText = `Cancelling order #${reference} on the store is not finished.${taken ? ` The store has taken off: ${taken}. ${GIVE}` : ""}${still ? ` Not confirmed taken off yet: ${still}. Keep that until this till shows the order cancelled.` : ""}`;
|
|
12840
|
+
else if (hasDone) addedText = `${subject} was not cancelled on the store.${taken ? ` The store has taken off: ${taken}. ${GIVE}` : ""}${still ? ` Still paid there: ${still}. Keep that; a manager must check it in the store's admin.` : ""}`;
|
|
12841
|
+
else if (settlement.state === "refused") addedText = `The store did not cancel order #${reference}. Check it in the store's admin.`;
|
|
12842
|
+
else settledText = `${subject} changed on the store${paidThere}. Nothing was taken off it or cancelled from this till. Check it in the store's admin.`;
|
|
12843
|
+
}
|
|
12844
|
+
if ((kind === "cancel" || kind === "reverse") && order.storeSettlement?.code === TILL_SESSION_CLOSED) {
|
|
12845
|
+
settledText = void 0;
|
|
12846
|
+
addedText = CLOSED_SESSION_NOTICE;
|
|
12847
|
+
}
|
|
12817
12848
|
const settled = !!settlement && settledOnStore(order);
|
|
12818
12849
|
return /* @__PURE__ */ jsxs126(Fragment48, { children: [
|
|
12819
12850
|
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,
|
|
@@ -12832,7 +12863,7 @@ function OrderSyncNotices({ order, stuck, children }) {
|
|
|
12832
12863
|
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))
|
|
12833
12864
|
] });
|
|
12834
12865
|
}
|
|
12835
|
-
function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore }) {
|
|
12866
|
+
function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore, onReverseOnStore, openSessionId }) {
|
|
12836
12867
|
const formatMoney2 = useFormatMoney26();
|
|
12837
12868
|
const hintId = useId4();
|
|
12838
12869
|
const retrying = useRef26(/* @__PURE__ */ new Set());
|
|
@@ -12904,6 +12935,29 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12904
12935
|
paying.current.delete(order.id);
|
|
12905
12936
|
}
|
|
12906
12937
|
}
|
|
12938
|
+
const reversing = useRef26(/* @__PURE__ */ new Set());
|
|
12939
|
+
const [reverses, setReverses] = useState57(/* @__PURE__ */ new Map());
|
|
12940
|
+
const [askingReverse, setAskingReverse] = useState57(null);
|
|
12941
|
+
async function reverseOnStore(order) {
|
|
12942
|
+
if (!onReverseOnStore || reversing.current.has(order.id)) return;
|
|
12943
|
+
reversing.current.add(order.id);
|
|
12944
|
+
setReverses((current) => new Map(current).set(order.id, "busy"));
|
|
12945
|
+
let failed = false;
|
|
12946
|
+
try {
|
|
12947
|
+
failed = (await onReverseOnStore(order)).kind === "retry";
|
|
12948
|
+
} catch {
|
|
12949
|
+
failed = true;
|
|
12950
|
+
} finally {
|
|
12951
|
+
reversing.current.delete(order.id);
|
|
12952
|
+
setReverses((current) => {
|
|
12953
|
+
const next = new Map(current);
|
|
12954
|
+
if (failed) next.set(order.id, "failed");
|
|
12955
|
+
else next.delete(order.id);
|
|
12956
|
+
return next;
|
|
12957
|
+
});
|
|
12958
|
+
}
|
|
12959
|
+
}
|
|
12960
|
+
const inOpenSession = (order) => openSessionId !== void 0 && tillPayments(order.payments).every((payment) => (payment.sessionId ?? order.sessionId) === openSessionId);
|
|
12907
12961
|
const [expanded, setExpanded] = useState57(/* @__PURE__ */ new Set());
|
|
12908
12962
|
useEffect24(() => {
|
|
12909
12963
|
for (const id of retrying.current) {
|
|
@@ -12955,14 +13009,18 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
12955
13009
|
const attention = section.title === "Needs attention";
|
|
12956
13010
|
const reopenable = attention && !!onReopen && order.syncStatus === "rejected" && REOPENABLE_CODES.includes(order.error?.code ?? "") && order.storeOrderId === void 0 && order.reopenedAt === void 0;
|
|
12957
13011
|
const reopenState = reopens.get(order.id);
|
|
12958
|
-
const
|
|
13012
|
+
const cancelOffered = attention && !!onCancelOnStore && canCancelOnStore(order);
|
|
12959
13013
|
const cancelState = cancels.get(order.id);
|
|
12960
13014
|
const finishing = order.storeSettlement?.kind === "cancel" && order.storeSettlement.state === "sending";
|
|
12961
13015
|
const left = storeOrderLeft(order);
|
|
12962
13016
|
const payable = attention && !!onPayRestOnStore && canPayRestOnStore(order);
|
|
12963
13017
|
const payState = pays.get(order.id);
|
|
12964
13018
|
const finishingPay = order.storeSettlement?.kind === "pay" && order.storeSettlement.state === "sending";
|
|
12965
|
-
const
|
|
13019
|
+
const reverseOffered = attention && !!onReverseOnStore && canReverseOnStore(order);
|
|
13020
|
+
const closedSession = (cancelOffered || reverseOffered) && !inOpenSession(order);
|
|
13021
|
+
const cancellable = cancelOffered && !closedSession, reversible = reverseOffered && !closedSession;
|
|
13022
|
+
const reverseState = reverses.get(order.id), finishingReverse = order.storeSettlement?.kind === "reverse" && order.storeSettlement.state === "sending";
|
|
13023
|
+
const retryLabel = (onPayRestOnStore || onReverseOnStore) && left && left.recordedMinor > 0 ? void 0 : onCancelOnStore && left?.recordedMinor === 0 ? order.error?.code === "insufficient_stock" ? "Try the payment again" : void 0 : "Retry";
|
|
12966
13024
|
return /* @__PURE__ */ jsxs126(View118, { className: "gap-1 rounded-md border border-border bg-card p-3", children: [
|
|
12967
13025
|
/* @__PURE__ */ jsx190(Text58, { id: `${hintId}-${sectionIndex}-${order.id}`, className: "hidden", children: "Shows the items and payments of this sale" }),
|
|
12968
13026
|
/* @__PURE__ */ jsxs126(
|
|
@@ -13019,6 +13077,7 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
13019
13077
|
setRetryingIds(new Set(retrying.current));
|
|
13020
13078
|
}
|
|
13021
13079
|
}, className: "rounded-md bg-primary px-4 py-2", children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-primary-foreground", children: retryLabel }) }) : null,
|
|
13080
|
+
closedSession ? /* @__PURE__ */ jsx190(Text58, { className: "text-muted-foreground", children: CLOSED_SESSION_NOTICE }) : null,
|
|
13022
13081
|
cancellable ? /* @__PURE__ */ jsx190(
|
|
13023
13082
|
Pressable56,
|
|
13024
13083
|
{
|
|
@@ -13051,6 +13110,21 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
13051
13110
|
}
|
|
13052
13111
|
) : null,
|
|
13053
13112
|
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,
|
|
13113
|
+
reversible ? /* @__PURE__ */ jsx190(
|
|
13114
|
+
Pressable56,
|
|
13115
|
+
{
|
|
13116
|
+
accessibilityRole: "button",
|
|
13117
|
+
testID: `order-${order.id}-reverse-on-store`,
|
|
13118
|
+
disabled: reverseState === "busy",
|
|
13119
|
+
onPress: () => {
|
|
13120
|
+
if (finishingReverse) void reverseOnStore(order);
|
|
13121
|
+
else setAskingReverse(order);
|
|
13122
|
+
},
|
|
13123
|
+
className: "rounded-md border border-border px-4 py-2",
|
|
13124
|
+
children: /* @__PURE__ */ jsx190(Text58, { className: "text-center font-semibold text-foreground", children: reverseState === "busy" ? "Cancelling on store\u2026" : finishingReverse ? "Finish cancelling on store" : "Give back and cancel" })
|
|
13125
|
+
}
|
|
13126
|
+
) : null,
|
|
13127
|
+
reversible && reverseState === "failed" ? /* @__PURE__ */ jsx190(Text58, { testID: `order-${order.id}-reverse-on-store-error`, className: "text-muted-foreground", children: "Could not reach the store. Try again." }) : null,
|
|
13054
13128
|
attention && order.reopenedAt !== void 0 ? /* @__PURE__ */ jsxs126(Fragment48, { children: [
|
|
13055
13129
|
/* @__PURE__ */ jsx190(Text58, { testID: `order-${order.id}-reopened`, className: "text-muted-foreground", children: "Reopened as a parked sale." }),
|
|
13056
13130
|
onResume ? /* @__PURE__ */ jsx190(
|
|
@@ -13094,7 +13168,7 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
13094
13168
|
] }, order.id);
|
|
13095
13169
|
})
|
|
13096
13170
|
] }, section.title)),
|
|
13097
|
-
askingCancel ? ((reference) => /* @__PURE__ */ jsx190(
|
|
13171
|
+
askingCancel && inOpenSession(askingCancel) ? ((reference) => /* @__PURE__ */ jsx190(
|
|
13098
13172
|
ConfirmDialog,
|
|
13099
13173
|
{
|
|
13100
13174
|
testID: `order-${askingCancel.id}-cancel-on-store-dialog`,
|
|
@@ -13126,7 +13200,7 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
13126
13200
|
description: [
|
|
13127
13201
|
...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
13202
|
"No money is taken now.",
|
|
13129
|
-
GIVE_BACK
|
|
13203
|
+
onReverseOnStore && canReverseOnStore(askingPay) && inOpenSession(askingPay) ? GIVE_BACK_INSTEAD : GIVE_BACK
|
|
13130
13204
|
].join("\n"),
|
|
13131
13205
|
cancelLabel: "Keep as is",
|
|
13132
13206
|
confirmLabel: "Record on store",
|
|
@@ -13141,6 +13215,29 @@ function OrdersList({ orders, onRetry, formatDate = defaultFormatDate2, footer,
|
|
|
13141
13215
|
unrecordedLegs(askingPay),
|
|
13142
13216
|
askingPay.storeSettlement
|
|
13143
13217
|
) : null,
|
|
13218
|
+
askingReverse && inOpenSession(askingReverse) ? /* @__PURE__ */ jsx190(
|
|
13219
|
+
ConfirmDialog,
|
|
13220
|
+
{
|
|
13221
|
+
testID: `order-${askingReverse.id}-reverse-on-store-dialog`,
|
|
13222
|
+
tone: "destructive",
|
|
13223
|
+
open: true,
|
|
13224
|
+
onOpenChange: (open) => {
|
|
13225
|
+
if (!open) setAskingReverse(null);
|
|
13226
|
+
},
|
|
13227
|
+
title: `Give the money back and cancel order #${storeOrderLeft(askingReverse)?.reference ?? orderReference(askingReverse)}?`,
|
|
13228
|
+
description: [
|
|
13229
|
+
...askingReverse.payments.map((leg) => `${legWording(leg.method, formatMoney2({ amount: leg.amountMinor, currency: askingReverse.currency }))}.`),
|
|
13230
|
+
"The store stops counting the payments it recorded and cancels the order.",
|
|
13231
|
+
"Hand the money back once this till shows the order cancelled. If you already gave it back, go ahead."
|
|
13232
|
+
].join("\n"),
|
|
13233
|
+
cancelLabel: "Keep order",
|
|
13234
|
+
confirmLabel: "Give back and cancel",
|
|
13235
|
+
onConfirm: () => {
|
|
13236
|
+
setAskingReverse(null);
|
|
13237
|
+
void reverseOnStore(askingReverse);
|
|
13238
|
+
}
|
|
13239
|
+
}
|
|
13240
|
+
) : null,
|
|
13144
13241
|
footer
|
|
13145
13242
|
] });
|
|
13146
13243
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/components",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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.2.0",
|
|
33
|
+
"@tallyui/primitives": "^5.2.0",
|
|
34
|
+
"@tallyui/theme": "^5.2.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.2.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.2.0",
|
|
47
|
+
"@tallyui/connector-vendure": "5.2.0",
|
|
48
|
+
"@tallyui/connector-woocommerce": "5.2.0",
|
|
49
|
+
"@tallyui/mock-api": "5.2.0",
|
|
50
50
|
"@types/react": ">=18",
|
|
51
51
|
"react": "^19.2.4",
|
|
52
52
|
"react-native-svg": "15.12.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useState, type JSX } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
-
import { useFormatMoney, useMoneyFormat, type MoneyFormat, type OrderRefundPayload } from '@tallyui/core';
|
|
3
|
+
import { useFormatMoney, useMoneyFormat, useOptionalConnector, type MoneyFormat, type OrderRefundPayload } from '@tallyui/core';
|
|
4
4
|
import { priceRefund, refundableLines, type EarlierRefund, type RefundableOrderLine } from '@tallyui/pos';
|
|
5
5
|
import { QuantityStepper } from '../input/quantity-stepper';
|
|
6
6
|
import { errorText } from '../lib/error-text';
|
|
@@ -62,6 +62,7 @@ export function RefundForm({
|
|
|
62
62
|
}: RefundFormProps): JSX.Element {
|
|
63
63
|
const formatMoney = useFormatMoney();
|
|
64
64
|
const format = useMoneyFormat();
|
|
65
|
+
const lineTotalsShrinkOnReturn = useOptionalConnector()?.lineTotalsShrinkOnReturn === true;
|
|
65
66
|
const [quantities, setQuantities] = useState<Record<string, number>>({});
|
|
66
67
|
const [restock, setRestock] = useState<Record<string, boolean>>({});
|
|
67
68
|
const [shippingText, setShippingText] = useState('');
|
|
@@ -79,6 +80,12 @@ export function RefundForm({
|
|
|
79
80
|
quantity: Math.min(quantities[orderLineId] ?? 0, refundableQuantity),
|
|
80
81
|
restock: restock[orderLineId] ?? defaultRestock,
|
|
81
82
|
})).filter(({ quantity }) => quantity > 0);
|
|
83
|
+
const missingSoldFigures = lineTotalsShrinkOnReturn && request.find(({ orderLineId, quantity }) => {
|
|
84
|
+
const index = lines.findIndex((line) => line.id === orderLineId);
|
|
85
|
+
const line = lines[index];
|
|
86
|
+
return (line.soldTotalMinor === undefined || line.soldTaxMinor === undefined)
|
|
87
|
+
&& (quantity < line.quantity || available[index].refundedQuantity > 0);
|
|
88
|
+
});
|
|
82
89
|
const priced = priceRefund(lines, refunds, request);
|
|
83
90
|
const emptiesLines = priced.lines.length > 0 && available.every(({ orderLineId, refundableQuantity }) => (request.find((line) => line.orderLineId === orderLineId)?.quantity ?? 0) === refundableQuantity);
|
|
84
91
|
const roundingShareMinor = emptiesLines ? cashRoundingMinor : 0;
|
|
@@ -90,6 +97,7 @@ export function RefundForm({
|
|
|
90
97
|
const cashStep = destination === 'cash' && Number.isInteger(cashIncrementMinor) && cashIncrementMinor! > 1 && typeof totalMinor === 'number' && totalMinor > 0 && totalMinor % cashIncrementMinor! !== 0;
|
|
91
98
|
const invalid = typeof shippingMinor === 'string' ? shippingMinor
|
|
92
99
|
: typeof adjustmentMinor === 'string' ? adjustmentMinor
|
|
100
|
+
: missingSoldFigures ? `Update the store's plugin to refund part of ${lines.find((line) => line.id === missingSoldFigures.orderLineId)!.name}.`
|
|
93
101
|
: shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.`
|
|
94
102
|
: priced.lines.length === 0 && shippingMinor === 0 && adjustmentMinor === 0 ? 'Choose something to refund.'
|
|
95
103
|
: totalMinor! <= 0 ? 'The refund total must be more than 0.'
|
package/src/sale/orders-list.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
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';
|
|
4
|
+
import { canCancelOnStore, canPayRestOnStore, canReverseOnStore, extrasNotSent, isRequeueableOrder, needsAdminReasonOf, needsAttention, noteDelivery, refundDueOf, REOPENABLE_CODES, settledOnStore, storeOrderLeft, TILL_SESSION_CLOSED, tillPayments, 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
7
|
import { ConfirmDialog } from '../ui/confirm-dialog';
|
|
@@ -37,6 +37,11 @@ const REFUSAL_SENTENCES = new Map([
|
|
|
37
37
|
const refusalSentence = (code: string | undefined) => REFUSAL_SENTENCES.get(code ?? '') ?? REFUSAL_SENTENCES.get('platform_error')!;
|
|
38
38
|
/** Pay the rest on store's dialog (#1101 slice 3): the front desk's wording until slice 4 handles money given back. */
|
|
39
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 GIVE_BACK_INSTEAD = 'If the money was given back, use Give back and cancel instead.';
|
|
41
|
+
const GIVE = 'Give back any of this you have not already given back.';
|
|
42
|
+
const CLOSED_SESSION_NOTICE = "Taken in a session that has closed: a manager must settle this sale in the store's admin.";
|
|
43
|
+
const legLabel = (method: string) => (method === 'cash' ? 'Cash' : 'Card');
|
|
44
|
+
const legWording = (method: string, amount: string | undefined) => `${legLabel(method)} ${amount}: ${method === 'cash' ? 'hand it back from the drawer' : 'give it back on the card terminal'}`;
|
|
40
45
|
const methodLabel = (method: string) => (method === 'cash' ? 'Cash' : 'Card terminal');
|
|
41
46
|
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.";
|
|
42
47
|
|
|
@@ -74,34 +79,51 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
74
79
|
// #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
80
|
// 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
81
|
const kind = order.storeSettlement?.kind;
|
|
77
|
-
const settlement = order.syncStatus === 'rejected' && (kind === 'cancel' || kind === 'pay') ? order.storeSettlement : undefined;
|
|
82
|
+
const settlement = order.syncStatus === 'rejected' && (kind === 'cancel' || kind === 'pay' || (kind === 'reverse' && order.storeSettlement?.legs?.length)) ? order.storeSettlement : undefined;
|
|
78
83
|
const reference = left?.reference ?? orderReference(order);
|
|
79
84
|
const money = (amount: number) => formatMoney({ amount, currency: order.currency });
|
|
80
85
|
const sum = (legs: { amountMinor: number }[]) => legs.reduce((total, leg) => total + leg.amountMinor, 0);
|
|
81
86
|
const paidThere = settlement?.capturedMinor ? `: ${money(settlement.capturedMinor)} is paid there` : '';
|
|
82
87
|
// A pay's R: what the store had recorded at the refusal, plus each leg this till has recorded since.
|
|
83
88
|
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
89
|
// What this till has recorded on the stored pay, on this press or an earlier one: true in every state.
|
|
86
90
|
const doneMinor = sum(settlement?.payments?.filter((payment) => payment.done) ?? []);
|
|
87
91
|
const nothing = doneMinor > 0 ? `${money(doneMinor)} was recorded from this till.` : 'Nothing was recorded from this till.';
|
|
88
|
-
|
|
92
|
+
let settledText = settlement?.kind === 'pay'
|
|
89
93
|
? settlement.state === 'done' ? `Order #${reference} is paid on the store.`
|
|
90
94
|
: settlement.state === 'gone' ? `Order #${reference} is not on the store any more; ${recorded} was recorded on it.`
|
|
91
95
|
: settlement.state !== 'changed' ? undefined
|
|
92
96
|
: settlement.storeStatus === 'completed' ? `Order #${reference} is already paid on the store. ${nothing}`
|
|
93
97
|
: `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.${
|
|
95
|
-
? `
|
|
98
|
+
: settlement?.state === 'done' ? `Order #${reference} was cancelled on the store.${order.payments.length || kind === 'reverse'
|
|
99
|
+
? ` The till took: ${order.payments.map((leg) => legWording(leg.method, money(leg.amountMinor))).join('; ')}. ${GIVE}` : ''}`
|
|
96
100
|
: settlement?.state === 'gone' ? `Order #${reference} was removed on the store.`
|
|
97
101
|
: settlement?.state === 'changed' ? `Order #${reference} changed on the store${paidThere}. Nothing was cancelled from this till. Check it in the store's admin.`
|
|
98
102
|
: undefined;
|
|
99
103
|
const pay = settlement?.kind === 'pay';
|
|
100
|
-
|
|
104
|
+
let addedText = settlement?.state === 'refused' ? pay
|
|
101
105
|
? `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
106
|
: `The store did not cancel order #${reference}. Check it in the store's admin.`
|
|
103
107
|
: settlement?.state === 'sending' ? pay ? `Recording the rest of order #${reference} on the store is not finished.`
|
|
104
108
|
: `Cancelling order #${reference} on the store is not finished.` : undefined;
|
|
109
|
+
if (settlement?.kind === 'reverse' && settlement.state !== 'done' && settlement.legs) {
|
|
110
|
+
const legs = settlement.legs.flatMap((leg) => {
|
|
111
|
+
const payment = order.payments.find(({ id }) => id === leg.paymentId);
|
|
112
|
+
return payment ? [{ ...payment, done: leg.done }] : [];
|
|
113
|
+
});
|
|
114
|
+
const taken = legs.filter((leg) => leg.done).map((leg) => legWording(leg.method, money(leg.amountMinor))).join('; ');
|
|
115
|
+
const still = legs.filter((leg) => !leg.done).map((leg) => `${legLabel(leg.method)} ${money(leg.amountMinor)}`).join('; ');
|
|
116
|
+
const hasDone = settlement.legs.some((leg) => leg.done);
|
|
117
|
+
const subject = `Order #${reference}`;
|
|
118
|
+
settledText = undefined;
|
|
119
|
+
addedText = undefined;
|
|
120
|
+
if (settlement.state === 'gone') settledText = `${subject} is not on the store any more.${taken ? ` The store had taken off: ${taken}. ${GIVE}` : ''} Check it in the store's admin.`;
|
|
121
|
+
else if (settlement.state === 'sending') addedText = `Cancelling order #${reference} on the store is not finished.${taken ? ` The store has taken off: ${taken}. ${GIVE}` : ''}${still ? ` Not confirmed taken off yet: ${still}. Keep that until this till shows the order cancelled.` : ''}`;
|
|
122
|
+
else if (hasDone) addedText = `${subject} was not cancelled on the store.${taken ? ` The store has taken off: ${taken}. ${GIVE}` : ''}${still ? ` Still paid there: ${still}. Keep that; a manager must check it in the store's admin.` : ''}`;
|
|
123
|
+
else if (settlement.state === 'refused') addedText = `The store did not cancel order #${reference}. Check it in the store's admin.`;
|
|
124
|
+
else settledText = `${subject} changed on the store${paidThere}. Nothing was taken off it or cancelled from this till. Check it in the store's admin.`;
|
|
125
|
+
}
|
|
126
|
+
if ((kind === 'cancel' || kind === 'reverse') && order.storeSettlement?.code === TILL_SESSION_CLOSED) { settledText = undefined; addedText = CLOSED_SESSION_NOTICE; }
|
|
105
127
|
// A pay gone with money recorded on the store is not settled (`settledOnStore`): it stays a destructive line.
|
|
106
128
|
const settled = !!settlement && settledOnStore(order);
|
|
107
129
|
return <>
|
|
@@ -164,6 +186,7 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
164
186
|
* reopened and with no store order: the app wires `reopenRefusedOrder`. When it refuses `coupon_carry_inexact` with a
|
|
165
187
|
* `toCollectMinor`, the row offers "Reopen without the coupon", which calls it again with `{ withoutCoupons: true }`.
|
|
166
188
|
* `onResume` adds Resume to a reopened row; the app resumes the parked sale, whose draft id is the order's id.
|
|
189
|
+
* `openSessionId` must match the session of every till payment to offer or finish either store cancellation action.
|
|
167
190
|
* `onCancelOnStore` adds "Cancel order on store" to a Needs attention row whose refused sale left an unpaid order on the
|
|
168
191
|
* store (`canCancelOnStore`, #1101), asked in a confirm dialog first: the app wires `useOrderOutbox`'s `cancelOnStore`.
|
|
169
192
|
* A cancel still `sending` is finished with no dialog. With it, such a row offers no Retry, except an `insufficient_stock`
|
|
@@ -172,15 +195,17 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
172
195
|
* the store (`canPayRestOnStore`, #1101 slice 3), asked in a confirm dialog naming each leg to record (no money is taken):
|
|
173
196
|
* the app wires `useOrderOutbox`'s `payRestOnStore`. A pay still `sending` is finished with no dialog. With it, a row
|
|
174
197
|
* 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 }: {
|
|
198
|
+
export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, footer, stuck, history, onOpen, onReopen, onResume, onCancelOnStore, onPayRestOnStore, onReverseOnStore, openSessionId }: {
|
|
176
199
|
orders: PosOrder[]; onRetry(orderIds: string[]): Promise<number>; formatDate?: (iso: string) => string; footer?: ReactNode;
|
|
177
200
|
stuck?: OutboxState['stuck'];
|
|
178
201
|
history?: OrderHistoryRow[];
|
|
179
202
|
onOpen?: (row: PosOrder | OrderHistoryRow) => void;
|
|
180
203
|
onReopen?: (order: PosOrder, options?: { withoutCoupons: true }) => Promise<void>;
|
|
181
204
|
onResume?: (order: PosOrder) => void;
|
|
205
|
+
openSessionId?: string;
|
|
182
206
|
onCancelOnStore?: (order: PosOrder) => Promise<SettleOutcome | { kind: 'not_offered' }>;
|
|
183
207
|
onPayRestOnStore?: (order: PosOrder) => Promise<SettleOutcome | { kind: 'not_offered' }>;
|
|
208
|
+
onReverseOnStore?: (order: PosOrder) => Promise<SettleOutcome | { kind: 'not_offered' }>;
|
|
184
209
|
}) {
|
|
185
210
|
const formatMoney = useFormatMoney();
|
|
186
211
|
const hintId = useId();
|
|
@@ -255,6 +280,26 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
255
280
|
paying.current.delete(order.id);
|
|
256
281
|
}
|
|
257
282
|
}
|
|
283
|
+
const reversing = useRef(new Set<string>());
|
|
284
|
+
const [reverses, setReverses] = useState(new Map<string, 'busy' | 'failed'>());
|
|
285
|
+
const [askingReverse, setAskingReverse] = useState<PosOrder | null>(null);
|
|
286
|
+
async function reverseOnStore(order: PosOrder) {
|
|
287
|
+
if (!onReverseOnStore || reversing.current.has(order.id)) return;
|
|
288
|
+
reversing.current.add(order.id);
|
|
289
|
+
setReverses((current) => new Map(current).set(order.id, 'busy'));
|
|
290
|
+
let failed = false;
|
|
291
|
+
try {
|
|
292
|
+
failed = (await onReverseOnStore(order)).kind === 'retry';
|
|
293
|
+
} catch { failed = true; } finally {
|
|
294
|
+
reversing.current.delete(order.id);
|
|
295
|
+
setReverses((current) => {
|
|
296
|
+
const next = new Map(current);
|
|
297
|
+
if (failed) next.set(order.id, 'failed'); else next.delete(order.id);
|
|
298
|
+
return next;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const inOpenSession = (order: PosOrder) => openSessionId !== undefined && tillPayments(order.payments).every((payment) => (payment.sessionId ?? order.sessionId) === openSessionId);
|
|
258
303
|
const [expanded, setExpanded] = useState(new Set<string>());
|
|
259
304
|
useEffect(() => {
|
|
260
305
|
for (const id of retrying.current) {
|
|
@@ -296,7 +341,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
296
341
|
const reopenable = attention && !!onReopen && order.syncStatus === 'rejected' && REOPENABLE_CODES.includes(order.error?.code ?? '')
|
|
297
342
|
&& order.storeOrderId === undefined && order.reopenedAt === undefined;
|
|
298
343
|
const reopenState = reopens.get(order.id);
|
|
299
|
-
const
|
|
344
|
+
const cancelOffered = attention && !!onCancelOnStore && canCancelOnStore(order);
|
|
300
345
|
const cancelState = cancels.get(order.id);
|
|
301
346
|
const finishing = order.storeSettlement?.kind === 'cancel' && order.storeSettlement.state === 'sending';
|
|
302
347
|
// #1101: with the cancel wired, an unpaid order left on the store is cancelled rather than resent, except a stock refusal.
|
|
@@ -305,7 +350,11 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
305
350
|
const payState = pays.get(order.id);
|
|
306
351
|
const finishingPay = order.storeSettlement?.kind === 'pay' && order.storeSettlement.state === 'sending';
|
|
307
352
|
// #1101 slice 3: with the pay wired, a part-paid order left on the store has its rest recorded, never resent.
|
|
308
|
-
const
|
|
353
|
+
const reverseOffered = attention && !!onReverseOnStore && canReverseOnStore(order);
|
|
354
|
+
const closedSession = (cancelOffered || reverseOffered) && !inOpenSession(order);
|
|
355
|
+
const cancellable = cancelOffered && !closedSession, reversible = reverseOffered && !closedSession;
|
|
356
|
+
const reverseState = reverses.get(order.id), finishingReverse = order.storeSettlement?.kind === 'reverse' && order.storeSettlement.state === 'sending';
|
|
357
|
+
const retryLabel = (onPayRestOnStore || onReverseOnStore) && left && left.recordedMinor > 0 ? undefined : onCancelOnStore && left?.recordedMinor === 0
|
|
309
358
|
? order.error?.code === 'insufficient_stock' ? 'Try the payment again' : undefined : 'Retry';
|
|
310
359
|
return (
|
|
311
360
|
<View key={order.id} className="gap-1 rounded-md border border-border bg-card p-3">
|
|
@@ -349,6 +398,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
349
398
|
}} className="rounded-md bg-primary px-4 py-2">
|
|
350
399
|
<Text className="text-center font-semibold text-primary-foreground">{retryLabel}</Text>
|
|
351
400
|
</Pressable> : null}
|
|
401
|
+
{closedSession ? <Text className="text-muted-foreground">{CLOSED_SESSION_NOTICE}</Text> : null}
|
|
352
402
|
{cancellable ? <Pressable accessibilityRole="button" testID={`order-${order.id}-cancel-on-store`} disabled={cancelState === 'busy'}
|
|
353
403
|
onPress={() => {
|
|
354
404
|
if (cancelling.current.has(order.id)) return;
|
|
@@ -371,6 +421,11 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
371
421
|
</Pressable> : null}
|
|
372
422
|
{payable && (payState === 'failed' || payState === 'unfinished') ? <Text testID={`order-${order.id}-pay-rest-on-store-error`} className="text-muted-foreground">
|
|
373
423
|
{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}
|
|
424
|
+
{reversible ? <Pressable accessibilityRole="button" testID={`order-${order.id}-reverse-on-store`} disabled={reverseState === 'busy'}
|
|
425
|
+
onPress={() => { if (finishingReverse) void reverseOnStore(order); else setAskingReverse(order); }} className="rounded-md border border-border px-4 py-2">
|
|
426
|
+
<Text className="text-center font-semibold text-foreground">{reverseState === 'busy' ? 'Cancelling on store…' : finishingReverse ? 'Finish cancelling on store' : 'Give back and cancel'}</Text>
|
|
427
|
+
</Pressable> : null}
|
|
428
|
+
{reversible && reverseState === 'failed' ? <Text testID={`order-${order.id}-reverse-on-store-error`} className="text-muted-foreground">Could not reach the store. Try again.</Text> : null}
|
|
374
429
|
{/* Reopen needs a reopenable code, which Retry never resends (NOT_REQUEUEABLE), so the two never show together. */}
|
|
375
430
|
{attention && order.reopenedAt !== undefined ? <>
|
|
376
431
|
<Text testID={`order-${order.id}-reopened`} className="text-muted-foreground">Reopened as a parked sale.</Text>
|
|
@@ -400,7 +455,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
400
455
|
})}
|
|
401
456
|
</View>
|
|
402
457
|
))}
|
|
403
|
-
{askingCancel ? ((reference) => <ConfirmDialog testID={`order-${askingCancel.id}-cancel-on-store-dialog`} tone="destructive" open
|
|
458
|
+
{askingCancel && inOpenSession(askingCancel) ? ((reference) => <ConfirmDialog testID={`order-${askingCancel.id}-cancel-on-store-dialog`} tone="destructive" open
|
|
404
459
|
onOpenChange={(open) => { if (!open) setAskingCancel(null); }} title={`Cancel order #${reference} on the store?`}
|
|
405
460
|
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
461
|
cancelLabel="Keep order" confirmLabel="Cancel order on store"
|
|
@@ -409,11 +464,16 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
409
464
|
onOpenChange={(open) => { if (!open) setAskingPay(null); }} title={`Record the rest of order #${reference} on the store?`}
|
|
410
465
|
description={[...legs.filter((_leg, index) => !(stored?.kind === 'pay' && stored.payments?.length === legs.length && stored.payments[index].done))
|
|
411
466
|
.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')}
|
|
467
|
+
'No money is taken now.', onReverseOnStore && canReverseOnStore(askingPay) && inOpenSession(askingPay) ? GIVE_BACK_INSTEAD : GIVE_BACK].join('\n')}
|
|
413
468
|
cancelLabel="Keep as is" confirmLabel="Record on store"
|
|
414
469
|
onConfirm={() => { setAskingPay(null); void payRestOnStore(askingPay); }} />)(storeOrderLeft(askingPay)?.reference ?? orderReference(askingPay),
|
|
415
470
|
// Only the legs still to record: the stored pay is index-aligned with them when the lengths match, as the outbox reuses it.
|
|
416
471
|
unrecordedLegs(askingPay), askingPay.storeSettlement) : null}
|
|
472
|
+
{askingReverse && inOpenSession(askingReverse) ? <ConfirmDialog testID={`order-${askingReverse.id}-reverse-on-store-dialog`} tone="destructive" open
|
|
473
|
+
onOpenChange={(open) => { if (!open) setAskingReverse(null); }} title={`Give the money back and cancel order #${storeOrderLeft(askingReverse)?.reference ?? orderReference(askingReverse)}?`}
|
|
474
|
+
description={[...askingReverse.payments.map((leg) => `${legWording(leg.method, formatMoney({ amount: leg.amountMinor, currency: askingReverse.currency }))}.`),
|
|
475
|
+
'The store stops counting the payments it recorded and cancels the order.', 'Hand the money back once this till shows the order cancelled. If you already gave it back, go ahead.'].join('\n')}
|
|
476
|
+
cancelLabel="Keep order" confirmLabel="Give back and cancel" onConfirm={() => { setAskingReverse(null); void reverseOnStore(askingReverse); }} /> : null}
|
|
417
477
|
{footer}
|
|
418
478
|
</ScrollView>;
|
|
419
479
|
}
|