@tallyui/pos 3.10.0 → 3.12.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.js CHANGED
@@ -144,13 +144,13 @@ function woocommerceLine(amountMinor, rates, inclusive, currency, roundAtSubtota
144
144
  }
145
145
  function lineAmounts(net, taxes, taxLines, dp, roundAtSubtotal, pricesIncludeTax) {
146
146
  const factor = 10 ** dp;
147
- const tax = taxes.reduce((sum, rate) => sum + (roundAtSubtotal ? rate.total : woocommerceTax.roundTaxTotal(rate.total, dp, pricesIncludeTax)), 0);
147
+ const tax = taxes.reduce((sum2, rate) => sum2 + (roundAtSubtotal ? rate.total : woocommerceTax.roundTaxTotal(rate.total, dp, pricesIncludeTax)), 0);
148
148
  return {
149
149
  netMinor: Math.round(woocommerceTax.roundHalfUp(net, dp) * factor),
150
150
  netMicros: String(Math.round(net * factor * 1e6)),
151
151
  totalMinor: Math.round(woocommerceTax.roundHalfUp(net + tax, dp) * factor),
152
152
  taxLines,
153
- taxMicros: taxLines.reduce((sum, rate) => sum + BigInt(rate.taxMicros), 0n).toString()
153
+ taxMicros: taxLines.reduce((sum2, rate) => sum2 + BigInt(rate.taxMicros), 0n).toString()
154
154
  };
155
155
  }
156
156
  function woocommerceCouponReplay(lines, codes, context, getTaxRates, currency, roundAtSubtotal, pricesIncludeTax) {
@@ -163,7 +163,7 @@ function woocommerceCouponReplay(lines, codes, context, getTaxRates, currency, r
163
163
  const amount = (Number(tax2.taxMicros) / (factor * 1e6)).toFixed(6);
164
164
  return { id: tax2.rateId, subtotal: amount, total: amount };
165
165
  });
166
- const tax = taxes.reduce((sum, row) => sum + Number(row.total), 0).toFixed(6);
166
+ const tax = taxes.reduce((sum2, row) => sum2 + Number(row.total), 0).toFixed(6);
167
167
  return {
168
168
  product_id: !line.custom && Number.isSafeInteger(productId) && productId >= 0 ? productId : 0,
169
169
  ...Number.isSafeInteger(variationId) && variationId >= 0 ? { variation_id: variationId } : {},
@@ -220,9 +220,9 @@ function woocommerceCouponReplay(lines, codes, context, getTaxRates, currency, r
220
220
  function woocommerceTotals(lines, fees, shipping, currency, roundAtSubtotal, inclusive) {
221
221
  const dp = minorUnitDigits(currency), factor = 10 ** dp;
222
222
  const net = (line) => Number(line.netMicros) / (factor * 1e6);
223
- const productNet = lines.reduce((sum, line) => sum + (roundAtSubtotal ? net(line) : woocommerceTax.roundHalfUp(net(line), dp)), 0);
224
- const amount = productNet + fees.reduce((sum, line) => sum + net(line), 0) + shipping.reduce((sum, line) => sum + woocommerceTax.roundHalfUp(net(line), dp), 0);
225
- const taxes = (items) => woocommerceTax.roundHalfUp(items.reduce((sum, line) => line.taxLines.reduce((sum2, tax2) => sum2 + (roundAtSubtotal ? Number(tax2.taxMicros) / (factor * 1e6) : woocommerceTax.roundTaxTotal(Number(tax2.taxMicros) / (factor * 1e6), dp, inclusive)), sum), 0), woocommerceTax.getRoundingPrecision(dp));
223
+ const productNet = lines.reduce((sum2, line) => sum2 + (roundAtSubtotal ? net(line) : woocommerceTax.roundHalfUp(net(line), dp)), 0);
224
+ const amount = productNet + fees.reduce((sum2, line) => sum2 + net(line), 0) + shipping.reduce((sum2, line) => sum2 + woocommerceTax.roundHalfUp(net(line), dp), 0);
225
+ const taxes = (items) => woocommerceTax.roundHalfUp(items.reduce((sum2, line) => line.taxLines.reduce((sum3, tax2) => sum3 + (roundAtSubtotal ? Number(tax2.taxMicros) / (factor * 1e6) : woocommerceTax.roundTaxTotal(Number(tax2.taxMicros) / (factor * 1e6), dp, inclusive)), sum2), 0), woocommerceTax.getRoundingPrecision(dp));
226
226
  const tax = woocommerceTax.roundHalfUp(taxes([...lines, ...fees]) + taxes(shipping), 6);
227
227
  return {
228
228
  subtotalMinor: Math.round(woocommerceTax.roundHalfUp(productNet, dp) * factor),
@@ -253,7 +253,7 @@ function woocommerceTaxByRate(lines, roundAtSubtotal, taxLabels, orderTaxMinor)
253
253
  amountMinor: woocommerceTax.roundTaxTotal(woocommerceTax.roundHalfUp(amount, 6), 0, inclusive)
254
254
  }));
255
255
  if (orderTaxMinor !== void 0 && rows.length) {
256
- const residue = orderTaxMinor - rows.reduce((sum, row) => sum + row.amountMinor, 0);
256
+ const residue = orderTaxMinor - rows.reduce((sum2, row) => sum2 + row.amountMinor, 0);
257
257
  const bound = Math.floor(rows.length / 2) + 1;
258
258
  if (Math.abs(residue) > bound) throw new Error(`woocommerce tax by rate: residue ${residue} exceeds its bound ${bound} (ADR-076)`);
259
259
  rows[rows.length - 1].amountMinor += residue;
@@ -343,7 +343,7 @@ function roundedTaxByRate(lines, rounding) {
343
343
  const items = lines.flatMap((line) => (line.discountMinor ?? 0) > 0 ? [{ ...line, netMinor: line.netMinor + line.discountMinor }, { ...line, netMinor: -line.discountMinor }] : [line]);
344
344
  for (const line of items) {
345
345
  const net = BigInt(line.netMinor);
346
- const ratePpm = BigInt(line.taxLines.reduce((sum, tax) => sum + tax.ratePpm, 0));
346
+ const ratePpm = BigInt(line.taxLines.reduce((sum2, tax) => sum2 + tax.ratePpm, 0));
347
347
  const base = line.taxInclusive ? roundRatio(net * MICROS_PER_MINOR, MICROS_PER_MINOR + ratePpm, mode) : net;
348
348
  const lineTax = line.taxInclusive ? net - base : roundRatio(net * ratePpm, MICROS_PER_MINOR, mode);
349
349
  let left = lineTax;
@@ -360,7 +360,7 @@ function roundedTaxByRate(lines, rounding) {
360
360
  // per_rate_group_items: round(Σ net × r) once per group, and the order's tax is their sum (:35-49, :56).
361
361
  granularity === "per_rate_group_items" ? roundRatio(row.netMinor * BigInt(row.ratePpm), MICROS_PER_MINOR, mode) : row.amountMinor
362
362
  ) }));
363
- return { baseMinor: Number(baseMinor), taxMinor: rows.reduce((sum, row) => sum + row.amountMinor, 0), rates: rows };
363
+ return { baseMinor: Number(baseMinor), taxMinor: rows.reduce((sum2, row) => sum2 + row.amountMinor, 0), rates: rows };
364
364
  }
365
365
  function taxLinesByRate(lines, orderTaxMinor, taxLabels, rounding) {
366
366
  if (rounding?.granularity === "woocommerce" && lines.every((line) => line.netMicros !== void 0)) return woocommerceTaxByRate(lines, rounding.roundAtSubtotal, taxLabels, orderTaxMinor);
@@ -369,7 +369,7 @@ function taxLinesByRate(lines, orderTaxMinor, taxLabels, rounding) {
369
369
  if (rounded) return rounded.rates.map(({ code, ratePpm, netMinor, amountMinor }) => ({ label: label(ratePpm), code, ratePpm, netMinor, amountMinor }));
370
370
  const byRate = /* @__PURE__ */ new Map();
371
371
  for (const line of lines) {
372
- const lineTaxMicros = line.taxLines.reduce((sum, tax) => sum + BigInt(tax.taxMicros), 0n);
372
+ const lineTaxMicros = line.taxLines.reduce((sum2, tax) => sum2 + BigInt(tax.taxMicros), 0n);
373
373
  const base = line.taxInclusive ? line.netMinor - roundMicrosToMinor(lineTaxMicros) : line.netMinor;
374
374
  for (const tax of line.taxLines) {
375
375
  const key = JSON.stringify([tax.code ?? "", tax.ratePpm]);
@@ -389,7 +389,7 @@ function taxLinesByRate(lines, orderTaxMinor, taxLabels, rounding) {
389
389
  remainder: micros - floor * MICROS_PER_MINOR
390
390
  };
391
391
  });
392
- const leftover = orderTaxMinor - groups.reduce((sum, group) => sum + group.line.amountMinor, 0);
392
+ const leftover = orderTaxMinor - groups.reduce((sum2, group) => sum2 + group.line.amountMinor, 0);
393
393
  const ranked = [...groups].sort((a, b) => a.remainder === b.remainder ? b.line.ratePpm - a.line.ratePpm : a.remainder > b.remainder ? -1 : 1);
394
394
  for (const group of ranked.slice(0, leftover)) group.line.amountMinor += 1;
395
395
  return groups.map((group) => group.line);
@@ -638,13 +638,13 @@ function allocateOrderDiscount(lineAmountsMinor, totalMinor) {
638
638
  throw new RangeError("Amounts must be safe integers and the discount non-negative");
639
639
  }
640
640
  const weights = lineAmountsMinor.map((amount) => BigInt(Math.max(0, amount)));
641
- const weightTotal = weights.reduce((sum, weight) => sum + weight, 0n);
641
+ const weightTotal = weights.reduce((sum2, weight) => sum2 + weight, 0n);
642
642
  const total = BigInt(totalMinor);
643
643
  if (total > weightTotal) throw new RangeError("Order discount exceeds the lines it applies to");
644
644
  if (total === 0n) return weights.map(() => 0);
645
645
  const shares = weights.map((weight) => total * weight / weightTotal);
646
646
  const remainders = weights.map((weight) => total * weight % weightTotal);
647
- let leftover = total - shares.reduce((sum, share) => sum + share, 0n);
647
+ let leftover = total - shares.reduce((sum2, share) => sum2 + share, 0n);
648
648
  const ranked = remainders.map((_, index) => index).sort((a, b) => remainders[a] === remainders[b] ? a - b : remainders[a] > remainders[b] ? -1 : 1);
649
649
  for (const index of ranked) {
650
650
  if (leftover === 0n) break;
@@ -667,16 +667,16 @@ function sumLines(lines, rounding) {
667
667
  const rounded = roundedTaxByRate(lines, rounding);
668
668
  if (rounded) return { subtotalMinor: rounded.baseMinor, taxMinor: rounded.taxMinor, totalMinor: Math.max(0, rounded.baseMinor + rounded.taxMinor) };
669
669
  const mode = rounding?.granularity === "per_order" ? rounding.mode : void 0;
670
- const netMinor = lines.reduce((sum, li) => sum + li.netMinor, 0);
671
- const lineTaxMicros = lines.reduce((sum, li) => sum + BigInt(li.taxMicros), 0n);
672
- const exclusiveTaxMicros = lines.reduce((sum, li) => li.taxInclusive ? sum : sum + BigInt(li.taxMicros), 0n);
670
+ const netMinor = lines.reduce((sum2, li) => sum2 + li.netMinor, 0);
671
+ const lineTaxMicros = lines.reduce((sum2, li) => sum2 + BigInt(li.taxMicros), 0n);
672
+ const exclusiveTaxMicros = lines.reduce((sum2, li) => li.taxInclusive ? sum2 : sum2 + BigInt(li.taxMicros), 0n);
673
673
  const taxMinor = roundMicrosToMinor(lineTaxMicros, mode);
674
674
  const linesTotal = netMinor + roundMicrosToMinor(exclusiveTaxMicros, mode);
675
675
  return { subtotalMinor: linesTotal - taxMinor, taxMinor, totalMinor: Math.max(0, linesTotal) };
676
676
  }
677
677
  function toDisplayMode(line, amountMinor, displayInclusive) {
678
678
  if (line.taxInclusive === displayInclusive) return amountMinor;
679
- const ratePpm = line.taxLines.reduce((sum, tax) => sum + tax.ratePpm, 0);
679
+ const ratePpm = line.taxLines.reduce((sum2, tax) => sum2 + tax.ratePpm, 0);
680
680
  const taxMinor = roundMicrosToMinor(taxMicros(amountMinor, ratePpm, line.taxInclusive));
681
681
  return line.taxInclusive ? amountMinor - taxMinor : amountMinor + taxMinor;
682
682
  }
@@ -684,6 +684,10 @@ function assertDisplayResidue(residue, convertedLines, conversions) {
684
684
  const bound = convertedLines === 0 ? 0 : Math.floor(conversions / 2) + 1;
685
685
  if (Math.abs(residue) > bound) throw new Error(`Display residue ${residue} exceeds its bound of ${bound} (ADR-063)`);
686
686
  }
687
+ function samePicks(a, b) {
688
+ const names = a.anyAttributes ?? [], other = b.anyAttributes ?? [];
689
+ return names.length === other.length && names.every((name, i) => name === other[i] && a.attributes?.[name] === b.attributes?.[name]);
690
+ }
687
691
  function regularUnitPriceMinor(resolved) {
688
692
  return resolved.was === void 0 ? resolved.current.amount : resolved.was.taxInclusive === resolved.current.taxInclusive ? resolved.was.amount : void 0;
689
693
  }
@@ -717,7 +721,7 @@ function createOrderBuilder(options) {
717
721
  remaining -= amountMinor;
718
722
  return { ...d, amountMinor };
719
723
  });
720
- const lineDiscountMinor = Math.min(grossMinor, recalcedDiscounts.reduce((sum, d) => sum + d.amountMinor, 0));
724
+ const lineDiscountMinor = Math.min(grossMinor, recalcedDiscounts.reduce((sum2, d) => sum2 + d.amountMinor, 0));
721
725
  const discountMinor = lineDiscountMinor + orderDiscountMinor;
722
726
  const netMinor = grossMinor - discountMinor;
723
727
  if (woo) return {
@@ -727,7 +731,7 @@ function createOrderBuilder(options) {
727
731
  orderDiscountMinor,
728
732
  ...wooLine(netMinor, line.taxClass, line.taxInclusive, line.taxStatus === "none")
729
733
  };
730
- const combinedRate = line.taxLines.reduce((sum, tax) => sum + tax.ratePpm, 0);
734
+ const combinedRate = line.taxLines.reduce((sum2, tax) => sum2 + tax.ratePpm, 0);
731
735
  const inclusiveTax = line.taxInclusive ? taxMicros(netMinor, combinedRate, true) : 0n;
732
736
  let allocatedTax = 0n;
733
737
  const taxLines = line.taxLines.map((tax, index) => {
@@ -754,14 +758,14 @@ function createOrderBuilder(options) {
754
758
  }
755
759
  function buildOrder() {
756
760
  const lineAmounts2 = lineItems.map((li) => woo ? li.unitPriceMinor * li.quantity - li.discountMinor : li.netMinor);
757
- const base = lineAmounts2.reduce((sum, amount) => sum + Math.max(0, amount), 0);
761
+ const base = lineAmounts2.reduce((sum2, amount) => sum2 + Math.max(0, amount), 0);
758
762
  let remaining = base;
759
763
  const recalcedOrderDiscounts = orderDiscounts.map((d) => {
760
764
  const amountMinor = Math.min(remaining, computeDiscountAmount(d, d.type === "percentage" ? base : remaining));
761
765
  remaining -= amountMinor;
762
766
  return { ...d, amountMinor };
763
767
  });
764
- const shares = allocateOrderDiscount(lineAmounts2, recalcedOrderDiscounts.reduce((sum, d) => sum + d.amountMinor, 0));
768
+ const shares = allocateOrderDiscount(lineAmounts2, recalcedOrderDiscounts.reduce((sum2, d) => sum2 + d.amountMinor, 0));
765
769
  const displaySourceLines = lineItems.map((li, index) => recalculateLine(li, shares[index]));
766
770
  const replay = woo && couponCodes.length ? woocommerceCouponReplay(
767
771
  displaySourceLines,
@@ -780,14 +784,14 @@ function createOrderBuilder(options) {
780
784
  const taxedLines = [...lines, ...charges.map((charge) => ({
781
785
  ...charge,
782
786
  taxInclusive: taxContext.pricesIncludeTax,
783
- taxMicros: charge.taxLines.reduce((sum, tax) => sum + BigInt(tax.taxMicros), 0n).toString()
787
+ taxMicros: charge.taxLines.reduce((sum2, tax) => sum2 + BigInt(tax.taxMicros), 0n).toString()
784
788
  }))];
785
789
  const { taxMinor, totalMinor } = wooTotals ?? sumLines(taxedLines, taxContext.rounding);
786
790
  if (taxContext.rounding?.granularity === "per_rate_group_items" && taxedLines.some((li) => li.taxInclusive) && !perRateGroupWarned.has(taxContext)) {
787
791
  perRateGroupWarned.add(taxContext);
788
792
  taxLogger.warn("per_rate_group_items with inclusive lines: using per_order figures until the display has a rounding row (#287, #310)");
789
793
  }
790
- const discountMinor = lines.reduce((sum, li) => sum + li.discountMinor, 0);
794
+ const discountMinor = lines.reduce((sum2, li) => sum2 + li.discountMinor, 0);
791
795
  const taxInclusive = taxContext.pricesIncludeTax;
792
796
  const figures = displaySourceLines.map((li) => {
793
797
  const returned = li.unitPriceMinor < 0;
@@ -798,26 +802,26 @@ function createOrderBuilder(options) {
798
802
  }));
799
803
  const shareMinor = displayAmount(li, li.orderDiscountMinor);
800
804
  const remainingMinor = woo ? taxInclusive ? li.totalMinor : li.netMinor : toDisplayMode(li, li.netMinor, taxInclusive);
801
- const amountMinor = !woo && li.taxInclusive === taxInclusive && !returned ? li.unitPriceMinor * li.quantity : discounts.reduce((sum, d) => sum + d.amountMinor, remainingMinor + shareMinor);
805
+ const amountMinor = !woo && li.taxInclusive === taxInclusive && !returned ? li.unitPriceMinor * li.quantity : discounts.reduce((sum2, d) => sum2 + d.amountMinor, remainingMinor + shareMinor);
802
806
  return { line: { lineId: li.id, amountMinor, discounts }, shareMinor, remainingMinor, returned };
803
807
  });
804
808
  const displayLines = figures.map((f) => f.line);
805
- const orderDiscountDisplay = figures.reduce((sum, f) => sum + f.shareMinor, 0);
809
+ const orderDiscountDisplay = figures.reduce((sum2, f) => sum2 + f.shareMinor, 0);
806
810
  const displayCoupons = replay?.coupons.map(({ code, discountMinor: discountMinor2, discountTaxMinor }) => ({ code, amountMinor: discountMinor2 + (taxInclusive ? discountTaxMinor : 0) }));
807
811
  const displayDiscount = displayLines.reduce(
808
- (sum, line) => line.discounts.reduce((lineSum, d) => lineSum + d.amountMinor, sum),
812
+ (sum2, line) => line.discounts.reduce((lineSum, d) => lineSum + d.amountMinor, sum2),
809
813
  orderDiscountDisplay
810
- ) + (displayCoupons?.reduce((sum, row) => sum + row.amountMinor, 0) ?? 0);
814
+ ) + (displayCoupons?.reduce((sum2, row) => sum2 + row.amountMinor, 0) ?? 0);
811
815
  const chargeRows = (items) => items.map(({ id: id2, name, amountMinor, netMinor, totalMinor: totalMinor2 }) => ({ id: id2, name, amountMinor: woo ? taxInclusive ? totalMinor2 : netMinor : amountMinor }));
812
816
  const displayFees = chargeRows(fees), displayShipping = chargeRows(shipping);
813
- let displaySubtotal = (taxInclusive ? totalMinor : totalMinor - taxMinor) + displayDiscount - [...displayFees, ...displayShipping].reduce((sum, charge) => sum + charge.amountMinor, 0);
814
- let residue = displaySubtotal - displayLines.reduce((sum, line) => sum + line.amountMinor, 0);
817
+ let displaySubtotal = (taxInclusive ? totalMinor : totalMinor - taxMinor) + displayDiscount - [...displayFees, ...displayShipping].reduce((sum2, charge) => sum2 + charge.amountMinor, 0);
818
+ let residue = displaySubtotal - displayLines.reduce((sum2, line) => sum2 + line.amountMinor, 0);
815
819
  if (woo) {
816
820
  const charge = displayShipping.at(-1) ?? displayFees.at(-1);
817
821
  const last = charge ?? displayLines.at(-1);
818
822
  if (last) last.amountMinor += residue;
819
823
  if (charge) displaySubtotal -= residue;
820
- residue = displaySubtotal - displayLines.reduce((sum, line) => sum + line.amountMinor, 0);
824
+ residue = displaySubtotal - displayLines.reduce((sum2, line) => sum2 + line.amountMinor, 0);
821
825
  }
822
826
  const converted = displaySourceLines.flatMap((li, index) => li.taxInclusive === taxInclusive ? [] : [index]);
823
827
  const conversions = converted.reduce((count, index) => count + [
@@ -839,7 +843,7 @@ function createOrderBuilder(options) {
839
843
  for (const { line, shareMinor, returned } of figures) {
840
844
  if (returned && line.discounts.length > 0) throw new Error(`Return line ${line.lineId} shows discount rows (ADR-063)`);
841
845
  if (returned || woo) continue;
842
- const rows = line.discounts.reduce((sum, d) => sum + d.amountMinor, 0);
846
+ const rows = line.discounts.reduce((sum2, d) => sum2 + d.amountMinor, 0);
843
847
  if (shareMinor < 0 || line.discounts.some((d) => d.amountMinor < 0) || line.amountMinor < rows + shareMinor) {
844
848
  throw new Error(`Display line ${line.lineId} shows ${line.amountMinor}, less than its rows ${rows} and share ${shareMinor} (ADR-063)`);
845
849
  }
@@ -856,7 +860,7 @@ function createOrderBuilder(options) {
856
860
  ...fees.length ? { fees: displayFees } : {},
857
861
  ...shipping.length ? { shipping: displayShipping } : {}
858
862
  };
859
- const paidMinor = payments.reduce((sum, p) => sum + p.amountMinor, 0);
863
+ const paidMinor = payments.reduce((sum2, p) => sum2 + p.amountMinor, 0);
860
864
  const balanceDueMinor = Math.max(0, totalMinor - paidMinor);
861
865
  const changeDueMinor = Math.max(0, paidMinor - totalMinor);
862
866
  return {
@@ -958,7 +962,7 @@ function createOrderBuilder(options) {
958
962
  const taxRates = woo ? wooLine(unitPrice.amount * quantity, input.taxClass, unitPrice.taxInclusive ?? taxContext.pricesIncludeTax, input.taxStatus === "none").taxLines : input.taxStatus === "none" ? [{ ...code !== void 0 ? { code } : {}, ratePpm: 0 }] : input.taxRates ?? [{ ...code !== void 0 ? { code } : {}, ratePpm: taxContext.getTaxRatePpm(input.taxClass) }];
959
963
  const taxInclusive = unitPrice.taxInclusive ?? taxContext.pricesIncludeTax;
960
964
  const existing = lineItems.find(
961
- (li) => !input.custom && !li.custom && li.productId === productId && li.variantId === variantId && li.taxInclusive === taxInclusive && (!woo || li.taxClass === input.taxClass && li.taxStatus === "none" === (input.taxStatus === "none")) && li.regularUnitPriceMinor === input.regularUnitPriceMinor && li.unitPriceMinor === unitPrice.amount && li.taxLines.length === taxRates.length && li.taxLines.every((tax, index) => tax.code === taxRates[index].code && tax.ratePpm === taxRates[index].ratePpm)
965
+ (li) => !input.custom && !li.custom && li.productId === productId && li.variantId === variantId && li.taxInclusive === taxInclusive && (!woo || li.taxClass === input.taxClass && li.taxStatus === "none" === (input.taxStatus === "none")) && li.regularUnitPriceMinor === input.regularUnitPriceMinor && samePicks(li, input) && li.unitPriceMinor === unitPrice.amount && li.taxLines.length === taxRates.length && li.taxLines.every((tax, index) => tax.code === taxRates[index].code && tax.ratePpm === taxRates[index].ratePpm)
962
966
  );
963
967
  if (existing) {
964
968
  lineItems = lineItems.map(
@@ -976,6 +980,8 @@ function createOrderBuilder(options) {
976
980
  ...input.taxStatus === "none" ? { taxStatus: "none" } : {},
977
981
  variantId,
978
982
  name: input.name,
983
+ ...input.attributes && Object.keys(input.attributes).length ? { attributes: { ...input.attributes } } : {},
984
+ ...input.anyAttributes?.length ? { anyAttributes: [...input.anyAttributes] } : {},
979
985
  sku: input.sku ?? "",
980
986
  imageUrl: input.imageUrl,
981
987
  unitPriceMinor: unitPrice.amount,
@@ -1215,18 +1221,18 @@ function cutText(text2, max) {
1215
1221
  }
1216
1222
  function netDiscountMinor(line, pricesIncludeTax) {
1217
1223
  if (!(line.taxInclusive ?? pricesIncludeTax) || line.discountMinor === 0) return line.discountMinor;
1218
- const ratePpm = line.taxLines.reduce((sum, tax) => sum + tax.ratePpm, 0);
1219
- const taxAfter = line.taxLines.reduce((sum, tax) => sum + BigInt(tax.taxMicros), 0n);
1224
+ const ratePpm = line.taxLines.reduce((sum2, tax) => sum2 + tax.ratePpm, 0);
1225
+ const taxAfter = line.taxLines.reduce((sum2, tax) => sum2 + BigInt(tax.taxMicros), 0n);
1220
1226
  const taxBefore = taxMicros(line.unitPriceMinor * line.quantity, ratePpm, true);
1221
1227
  return roundMicrosToMinor(BigInt(line.discountMinor) * MICROS_PER_MINOR - taxBefore + taxAfter);
1222
1228
  }
1223
1229
  function contentVersion(order) {
1224
- if (order.coupons?.length) return 6;
1230
+ if (order.coupons?.length || order.lines.some((line) => line.anyAttributes?.length)) return 6;
1225
1231
  if (order.fees?.length || order.shipping?.length || order.lines.some((line) => line.custom)) return 5;
1226
- return order.display && order.taxByRate ? 3 : order.lines.reduce((sum, line) => sum + line.discountMinor, 0) > 0 ? 2 : 1;
1232
+ return order.display && order.taxByRate ? 3 : order.lines.reduce((sum2, line) => sum2 + line.discountMinor, 0) > 0 ? 2 : 1;
1227
1233
  }
1228
1234
  function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1229
- const grossMinor = order.lines.reduce((sum, line) => sum + line.discountMinor, 0);
1235
+ const grossMinor = order.lines.reduce((sum2, line) => sum2 + line.discountMinor, 0);
1230
1236
  const content = contentVersion(order);
1231
1237
  const cap = options?.maxVersion === void 0 ? order.sentVersion : Math.min(options.maxVersion, order.sentVersion ?? options.maxVersion);
1232
1238
  if (content === 5 && cap !== void 0 && cap < 5) throw new UnsupportedOrderVersionError(5, cap);
@@ -1234,7 +1240,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1234
1240
  if (grossMinor > 0 && cap !== void 0 && cap < 2) throw new UnsupportedOrderVersionError(2, cap);
1235
1241
  const version = content === 3 && cap !== void 0 && cap >= 4 ? 4 : Math.min(content, cap ?? content);
1236
1242
  const lineDiscounts = order.lines.map((line) => version >= 4 ? netDiscountMinor(line, order.pricesIncludeTax) : line.discountMinor);
1237
- const discountMinor = lineDiscounts.reduce((sum, discount) => sum + discount, 0);
1243
+ const discountMinor = lineDiscounts.reduce((sum2, discount) => sum2 + discount, 0);
1238
1244
  const email = order.customer?.email;
1239
1245
  const id2 = order.customer?.id;
1240
1246
  const customerId = typeof id2 === "string" && id2.length > 0 && id2.length <= 64 ? id2 : void 0;
@@ -1261,7 +1267,8 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1261
1267
  ...line.taxInclusive !== void 0 ? { taxInclusive: line.taxInclusive } : {},
1262
1268
  ...lineDiscounts[i] > 0 ? { discountMinor: lineDiscounts[i] } : {},
1263
1269
  ...version === 6 && line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
1264
- ...version === 6 && line.attributes && Object.keys(line.attributes).length ? { attributes: { ...line.attributes } } : {}
1270
+ ...version === 6 && line.attributes && Object.keys(line.attributes).length ? { attributes: { ...line.attributes } } : {},
1271
+ ...version === 6 && line.anyAttributes?.length ? { anyAttributes: [...line.anyAttributes] } : {}
1265
1272
  })),
1266
1273
  ...version >= 5 && order.fees?.length ? { fees: order.fees.map((fee) => ({
1267
1274
  clientFeeId: fee.id,
@@ -1280,7 +1287,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1280
1287
  ...charge.taxClass !== void 0 ? { taxClass: charge.taxClass } : {},
1281
1288
  taxMinor: roundMicrosToMinor(BigInt(charge.taxMicros))
1282
1289
  })) } : {},
1283
- ...version === 6 ? { coupons: order.coupons.map(({ code, couponId, discountMinor: discountMinor2, discountTaxMinor }) => ({
1290
+ ...version === 6 && order.coupons?.length ? { coupons: order.coupons.map(({ code, couponId, discountMinor: discountMinor2, discountTaxMinor }) => ({
1284
1291
  code,
1285
1292
  couponId,
1286
1293
  discountMinor: discountMinor2,
@@ -1308,7 +1315,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1308
1315
  })),
1309
1316
  ...version >= 5 && order.display.fees ? { fees: order.display.fees.map(({ id: id3, amountMinor }) => ({ clientFeeId: id3, amountMinor })) } : {},
1310
1317
  ...version >= 5 && order.display.shipping ? { shipping: order.display.shipping.map(({ id: id3, amountMinor }) => ({ clientShippingId: id3, amountMinor })) } : {},
1311
- ...version === 6 && order.display.coupons ? { coupons: order.display.coupons.map(({ code, amountMinor }) => ({ code, amountMinor })) } : {}
1318
+ ...version === 6 && order.coupons?.length && order.display.coupons ? { coupons: order.display.coupons.map(({ code, amountMinor }) => ({ code, amountMinor })) } : {}
1312
1319
  },
1313
1320
  taxByRate: order.taxByRate.map(({ ratePpm, code, netMinor, amountMinor, grossMinor: grossMinor2 }) => ({
1314
1321
  ratePpm,
@@ -1373,6 +1380,8 @@ function restoreOrderDraft(saved, options) {
1373
1380
  ...taxContext.rounding?.granularity === "woocommerce" ? { taxClass: line.taxClass } : {},
1374
1381
  variantId: line.variantId,
1375
1382
  name: line.name,
1383
+ ...line.attributes !== void 0 ? { attributes: line.attributes } : {},
1384
+ ...line.anyAttributes !== void 0 ? { anyAttributes: line.anyAttributes } : {},
1376
1385
  sku: line.sku,
1377
1386
  imageUrl: line.imageUrl,
1378
1387
  unitPrice: { amount: line.unitPriceMinor, currency, taxInclusive: line.taxInclusive },
@@ -1502,7 +1511,7 @@ function buildReceiptData(order, config) {
1502
1511
  ({ label: label2, code, ratePpm, amountMinor }) => ({ label: label2, code, ratePpm, amountMinor })
1503
1512
  );
1504
1513
  let taxSoFar = order.lineItems.reduce(
1505
- (sum, li) => li.taxInclusive || li.priceTaxModeConverted ? sum : sum + BigInt(li.taxMicros),
1514
+ (sum2, li) => li.taxInclusive || li.priceTaxModeConverted ? sum2 : sum2 + BigInt(li.taxMicros),
1506
1515
  0n
1507
1516
  );
1508
1517
  const lineTotals = order.lineItems.map((li) => {
@@ -1543,6 +1552,7 @@ function buildReceiptData(order, config) {
1543
1552
  },
1544
1553
  lineItems: order.lineItems.map((li, index) => ({
1545
1554
  name: li.name,
1555
+ ...li.attributes && Object.keys(li.attributes).length ? { attributes: { ...li.attributes } } : {},
1546
1556
  sku: li.sku,
1547
1557
  quantity: li.quantity,
1548
1558
  unitPriceMinor: li.unitPriceMinor,
@@ -1581,6 +1591,140 @@ function buildReceiptData(order, config) {
1581
1591
  };
1582
1592
  }
1583
1593
 
1594
+ // src/receipt/reprint.ts
1595
+ import { minorUnitDigits as minorUnitDigits2, woocommerceTax as woocommerceTax4 } from "@tallyui/core";
1596
+ function reprintBlocks(config, customer) {
1597
+ const name = customer?.name || customer?.email;
1598
+ return {
1599
+ schemaVersion: RECEIPT_SCHEMA_VERSION,
1600
+ software: { name: "WCPOS", plugin_version: "", app_version: "", app_build: "", platform: "", ...config.software },
1601
+ register: { id: config.register ?? "", name: config.registerName ?? "" },
1602
+ fiscal: { document_type: "sale", is_reprint: true, reprint_count: 1, qr_payload: "", ...config.fiscal },
1603
+ header: {
1604
+ storeName: config.storeName,
1605
+ storeAddress: config.storeAddress,
1606
+ cashier: config.cashier,
1607
+ ...name ? { customer: name } : {},
1608
+ register: config.register
1609
+ }
1610
+ };
1611
+ }
1612
+ var sum = (amounts) => amounts.reduce((total, amount) => total + amount, 0);
1613
+ function buildReceiptDataFromPosOrder(order, config) {
1614
+ const { header, ...blocks } = reprintBlocks(config, order.customer);
1615
+ const { display, taxRounding: rounding } = order;
1616
+ const dp = minorUnitDigits2(order.currency), factor = 10 ** dp;
1617
+ const wooGrossMinor = (line, roundAtSubtotal) => {
1618
+ const tax = line.taxLines.reduce((sum2, row) => sum2 + (roundAtSubtotal ? Number(row.taxMicros) / (factor * 1e6) : woocommerceTax4.roundTaxTotal(Number(row.taxMicros) / (factor * 1e6), dp, order.pricesIncludeTax)), 0);
1619
+ return Math.round(woocommerceTax4.roundHalfUp(Number(line.netMicros) / (factor * 1e6) + tax, dp) * factor);
1620
+ };
1621
+ const lineTaxMicros = (line) => line.taxLines.reduce((total, row) => total + BigInt(row.taxMicros), 0n);
1622
+ let taxSoFar = order.pricesIncludeTax ? 0n : order.lines.reduce((total, line) => line.taxInclusive === void 0 ? total + lineTaxMicros(line) : total, 0n);
1623
+ const lineTotals = order.lines.map((line) => {
1624
+ if (rounding.granularity === "woocommerce" && line.netMicros !== void 0) return order.pricesIncludeTax ? wooGrossMinor(line, rounding.roundAtSubtotal) : line.netMinor;
1625
+ if (line.taxInclusive === void 0) return line.netMinor;
1626
+ const share = roundMicrosToMinor(taxSoFar + lineTaxMicros(line)) - roundMicrosToMinor(taxSoFar);
1627
+ taxSoFar += lineTaxMicros(line);
1628
+ return line.taxInclusive ? line.netMinor - share : line.netMinor + share;
1629
+ });
1630
+ const lineItems = order.lines.map((line, index) => {
1631
+ const displayLine = display?.lines.find((row) => row.lineId === line.id);
1632
+ const displayAmountMinor = display ? displayLine?.amountMinor ?? 0 : line.taxInclusive !== void 0 ? lineTotals[index] + line.discountMinor : line.unitPriceMinor * line.quantity;
1633
+ const displayDiscounts = display ? (displayLine?.discounts ?? []).map((d) => ({ label: d.label ?? "Discount", amountMinor: d.amountMinor })) : line.discountMinor > 0 ? [{ label: "Discount", amountMinor: line.discountMinor }] : [];
1634
+ return {
1635
+ name: line.name,
1636
+ ...line.attributes && Object.keys(line.attributes).length ? { attributes: { ...line.attributes } } : {},
1637
+ sku: line.sku,
1638
+ quantity: line.quantity,
1639
+ unitPriceMinor: line.unitPriceMinor,
1640
+ lineTotalMinor: lineTotals[index],
1641
+ ...line.discountMinor > 0 ? { discountMinor: line.discountMinor } : {},
1642
+ displayAmountMinor,
1643
+ displayDiscounts
1644
+ };
1645
+ });
1646
+ const taxedLines = [
1647
+ ...order.lines.map((line) => ({ ...line, taxInclusive: order.taxRounding.granularity === "woocommerce" && line.netMicros !== void 0 ? order.pricesIncludeTax : line.taxInclusive ?? order.pricesIncludeTax })),
1648
+ ...[...order.fees ?? [], ...order.shipping ?? []].map((charge) => ({ ...charge, taxInclusive: order.pricesIncludeTax }))
1649
+ ];
1650
+ const taxLines = order.taxByRate ? order.taxByRate.map((row) => ({
1651
+ label: config.taxLabels?.[row.ratePpm] ?? row.label ?? `Tax ${row.ratePpm / 1e4}%`,
1652
+ code: row.code,
1653
+ ratePpm: row.ratePpm,
1654
+ amountMinor: row.amountMinor
1655
+ })) : taxLinesByRate(taxedLines, order.taxMinor, config.taxLabels, order.taxRounding).map(({ label, code, ratePpm, amountMinor }) => ({ label, code, ratePpm, amountMinor }));
1656
+ const charges = (rows) => (rows ?? []).map(({ name, amountMinor }) => ({ name, amountMinor }));
1657
+ return {
1658
+ ...blocks,
1659
+ header: { ...header, orderNumber: order.serverRefs?.displayId ?? order.id, date: order.createdAt },
1660
+ lineItems,
1661
+ discounts: display && display.orderDiscountMinor > 0 ? [{ label: "Order discount", amountMinor: display.orderDiscountMinor }] : [],
1662
+ fees: charges(display ? display.fees : order.fees),
1663
+ shipping: charges(display ? display.shipping : order.shipping),
1664
+ orderDiscountMinor: display ? display.orderDiscountMinor : 0,
1665
+ totals: display ? {
1666
+ taxInclusive: display.taxInclusive,
1667
+ subtotalMinor: display.subtotalMinor,
1668
+ discountMinor: display.discountMinor,
1669
+ taxLines,
1670
+ taxMinor: display.taxMinor,
1671
+ totalMinor: display.totalMinor
1672
+ } : {
1673
+ taxInclusive: order.pricesIncludeTax,
1674
+ subtotalMinor: sum(lineItems.map((line) => line.displayAmountMinor)),
1675
+ discountMinor: sum(order.lines.map((line) => line.discountMinor)),
1676
+ taxLines,
1677
+ taxMinor: order.taxMinor,
1678
+ totalMinor: order.totalMinor
1679
+ },
1680
+ payments: order.payments.map((p) => ({ method: p.method, amountMinor: p.tenderedMinor ?? p.amountMinor, reference: p.reference })),
1681
+ changeDueMinor: sum(order.payments.map((p) => p.changeMinor ?? 0)),
1682
+ footer: { note: order.note || void 0, barcode: order.id },
1683
+ currency: order.currency
1684
+ };
1685
+ }
1686
+ function buildReceiptDataFromStoreOrder(order, config) {
1687
+ const { header, ...blocks } = reprintBlocks(config, order.customer);
1688
+ const gross = (net, tax) => order.pricesIncludeTax ? net + tax : net;
1689
+ const lineItems = order.lines.map((line) => {
1690
+ const displayAmountMinor = gross(line.subtotalMinor, line.subtotalTaxMinor);
1691
+ const lineTotalMinor = gross(line.totalMinor, line.taxMinor);
1692
+ const discount = displayAmountMinor - lineTotalMinor;
1693
+ return {
1694
+ name: line.name,
1695
+ sku: line.sku ?? "",
1696
+ quantity: line.quantity,
1697
+ unitPriceMinor: line.quantity === 0 ? 0 : Math.round(displayAmountMinor / line.quantity),
1698
+ lineTotalMinor,
1699
+ ...discount > 0 ? { discountMinor: discount } : {},
1700
+ displayAmountMinor,
1701
+ displayDiscounts: discount > 0 ? [{ label: "Discount", amountMinor: discount }] : []
1702
+ };
1703
+ });
1704
+ const charges = (rows) => rows.map(({ name, totalMinor, taxMinor }) => ({ name, amountMinor: gross(totalMinor, taxMinor) }));
1705
+ return {
1706
+ ...blocks,
1707
+ header: { ...header, orderNumber: order.reference, date: order.placedAt },
1708
+ lineItems,
1709
+ discounts: order.coupons.map(({ code, discountMinor, discountTaxMinor }) => ({ label: code, amountMinor: gross(discountMinor, discountTaxMinor) })),
1710
+ fees: charges(order.fees),
1711
+ shipping: charges(order.shipping),
1712
+ orderDiscountMinor: 0,
1713
+ totals: {
1714
+ taxInclusive: order.pricesIncludeTax,
1715
+ subtotalMinor: sum(lineItems.map((line) => line.displayAmountMinor)),
1716
+ discountMinor: sum(lineItems.map((line) => line.discountMinor ?? 0)),
1717
+ taxLines: order.taxLines.map(({ label, code, ratePpm, amountMinor }) => ({ label, ...code !== void 0 ? { code } : {}, ratePpm, amountMinor })),
1718
+ taxMinor: order.taxMinor,
1719
+ totalMinor: order.totalMinor
1720
+ },
1721
+ payments: order.payments.map((p) => ({ method: p.kind ?? p.title ?? p.method, amountMinor: p.amountMinor })),
1722
+ changeDueMinor: 0,
1723
+ footer: { barcode: order.reference },
1724
+ currency: order.currency
1725
+ };
1726
+ }
1727
+
1584
1728
  // src/product/search-products.ts
1585
1729
  function searchProducts(docs, term, traits) {
1586
1730
  const query = term.trim().toLowerCase();
@@ -1771,7 +1915,7 @@ function uuidv7(now, randomBytes) {
1771
1915
  }
1772
1916
 
1773
1917
  // src/pos-order/finalize.ts
1774
- import { minorUnitDigits as minorUnitDigits2 } from "@tallyui/core";
1918
+ import { minorUnitDigits as minorUnitDigits3 } from "@tallyui/core";
1775
1919
 
1776
1920
  // src/outbox/logger.ts
1777
1921
  var outboxLogger = createLogger("outbox");
@@ -1870,6 +2014,9 @@ function finalizeOrder(order, options = {}) {
1870
2014
  if (order.coupons?.length && (options.capabilities?.orderCreate ?? 1) < 6) {
1871
2015
  throw new Error("finalize: coupons need the store to accept order.create version 6; update the store's TallyUI plugin");
1872
2016
  }
2017
+ if (order.lineItems.some((line) => line.anyAttributes?.length) && (options.capabilities?.orderCreate ?? 1) < 6) {
2018
+ throw new Error("finalize: picked options need the store to accept order.create version 6; update the store's TallyUI plugin");
2019
+ }
1873
2020
  if (!order.lineItems.length) throw new Error("finalize: no lines");
1874
2021
  if (order.discountMinor < 0 || order.lineItems.some((line) => line.discountMinor < 0) || order.discounts.some((d) => d.amountMinor < 0)) {
1875
2022
  throw new Error("finalize: negative discount");
@@ -1885,7 +2032,7 @@ function finalizeOrder(order, options = {}) {
1885
2032
  }
1886
2033
  if (order.paidMinor < order.totalMinor) throw new Error("finalize: underpaid");
1887
2034
  let change = order.paidMinor - order.totalMinor;
1888
- const cash = order.payments.reduce((sum, p) => sum + (p.method === "cash" ? p.amountMinor : 0), 0);
2035
+ const cash = order.payments.reduce((sum2, p) => sum2 + (p.method === "cash" ? p.amountMinor : 0), 0);
1889
2036
  if (change > cash) throw new Error("finalize: change exceeds cash");
1890
2037
  const v3 = (options.capabilities?.orderCreate ?? 1) >= 3;
1891
2038
  const references = [
@@ -1922,6 +2069,8 @@ function finalizeOrder(order, options = {}) {
1922
2069
  sku: line.sku,
1923
2070
  quantity: line.quantity,
1924
2071
  unitPriceMinor: line.unitPriceMinor,
2072
+ ...line.attributes && Object.keys(line.attributes).length ? { attributes: { ...line.attributes } } : {},
2073
+ ...line.anyAttributes?.length ? { anyAttributes: [...line.anyAttributes] } : {},
1925
2074
  ...line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
1926
2075
  discountMinor: line.discountMinor,
1927
2076
  netMinor: line.netMinor,
@@ -1957,7 +2106,7 @@ function finalizeOrder(order, options = {}) {
1957
2106
  payment.amountMinor -= payment.changeMinor;
1958
2107
  change -= payment.changeMinor;
1959
2108
  }
1960
- if (payments.reduce((sum, p) => sum + p.amountMinor, 0) !== order.totalMinor) {
2109
+ if (payments.reduce((sum2, p) => sum2 + p.amountMinor, 0) !== order.totalMinor) {
1961
2110
  throw new Error("finalize: payments do not reconcile");
1962
2111
  }
1963
2112
  let display;
@@ -1968,7 +2117,7 @@ function finalizeOrder(order, options = {}) {
1968
2117
  }
1969
2118
  display = {
1970
2119
  currency: order.currency,
1971
- exponent: minorUnitDigits2(order.currency),
2120
+ exponent: minorUnitDigits3(order.currency),
1972
2121
  ...order.display,
1973
2122
  ...fees?.length ? { fees: order.display.fees.map((row, i) => ({ ...row, id: fees[i].id })) } : {},
1974
2123
  ...shipping?.length ? { shipping: order.display.shipping.map((row, i) => ({ ...row, id: shipping[i].id })) } : {},
@@ -1993,7 +2142,7 @@ function finalizeOrder(order, options = {}) {
1993
2142
  if (display.totalMinor !== order.totalMinor || display.taxMinor !== order.taxMinor || display.taxInclusive !== order.pricesIncludeTax) {
1994
2143
  throw new Error("finalize: display does not match the order");
1995
2144
  }
1996
- if (taxByRate.reduce((sum, rate) => sum + rate.amountMinor, 0) !== order.taxMinor) {
2145
+ if (taxByRate.reduce((sum2, rate) => sum2 + rate.amountMinor, 0) !== order.taxMinor) {
1997
2146
  throw new Error("finalize: tax by rate does not sum to the order tax");
1998
2147
  }
1999
2148
  }
@@ -2036,7 +2185,7 @@ function finalizeOrder(order, options = {}) {
2036
2185
  import { addRxPlugin } from "rxdb";
2037
2186
  import { RxDBMigrationSchemaPlugin } from "rxdb/plugins/migration-schema";
2038
2187
  var posOrderSchema = {
2039
- version: 9,
2188
+ version: 10,
2040
2189
  primaryKey: "id",
2041
2190
  type: "object",
2042
2191
  additionalProperties: false,
@@ -2084,6 +2233,7 @@ var posOrderSchema = {
2084
2233
  discountMinor: { type: "integer" },
2085
2234
  netMinor: { type: "integer" },
2086
2235
  attributes: { type: "object", additionalProperties: { type: "string" } },
2236
+ anyAttributes: { type: "array", items: { type: "string", minLength: 1, maxLength: 255 } },
2087
2237
  regularUnitPriceMinor: { type: "integer" },
2088
2238
  netMicros: { type: "string", pattern: "^-?[0-9]{1,24}$", maxLength: 25 },
2089
2239
  taxLines: { type: "array", items: {
@@ -2260,7 +2410,7 @@ function posOrderCollection() {
2260
2410
  };
2261
2411
  return {
2262
2412
  schema: posOrderSchema,
2263
- migrationStrategies: { 1: identity2, 2: identity2, 3: identity2, 4: identity2, 5: recordSent, 6: recordRounding, 7: identity2, 8: identity2, 9: identity2 }
2413
+ migrationStrategies: { 1: identity2, 2: identity2, 3: identity2, 4: identity2, 5: recordSent, 6: recordRounding, 7: identity2, 8: identity2, 9: identity2, 10: identity2 }
2264
2414
  };
2265
2415
  }
2266
2416
 
@@ -2771,7 +2921,7 @@ var validAmount = (value, exponent) => /^(?:\d+\.?\d*|\.\d+)$/.test(value) && Nu
2771
2921
  var countVariance = (countedMinor, expectedMinor) => countedMinor - expectedMinor;
2772
2922
  var overThreshold = (variance, thresholdMinor) => thresholdMinor != null && Math.abs(variance) > thresholdMinor;
2773
2923
  var closeNeedsApproval = (countedCashMinor, expectedCashMinor, thresholdMinor) => overThreshold(countVariance(countedCashMinor, expectedCashMinor), thresholdMinor);
2774
- var denominationTotal = (pieces) => Object.entries(pieces).reduce((sum, [value, count]) => sum + Number(value) * count, 0);
2924
+ var denominationTotal = (pieces) => Object.entries(pieces).reduce((sum2, [value, count]) => sum2 + Number(value) * count, 0);
2775
2925
  function varianceText(variance, exponent, format2, t) {
2776
2926
  if (!variance) return t("register.exact");
2777
2927
  return `${format2(Math.abs(variance) / 10 ** exponent)} ${t(variance < 0 ? "register.short" : "register.over")}`;
@@ -3071,7 +3221,7 @@ async function writeClosure({
3071
3221
  refunds
3072
3222
  });
3073
3223
  const counts = { cash: counted, ...otherTenders };
3074
- const sum = (values) => values.reduce((total, value) => total + value, 0);
3224
+ const sum2 = (values) => values.reduce((total, value) => total + value, 0);
3075
3225
  const payment_methods = {};
3076
3226
  for (const row2 of rows) {
3077
3227
  const method = row2.kind === "cash" ? "cash" : row2.method_id;
@@ -3116,12 +3266,12 @@ async function writeClosure({
3116
3266
  variance: Object.fromEntries(
3117
3267
  Object.entries(counts).map(([method, value]) => [method, countVariance(value, till_expected[method] ?? 0)])
3118
3268
  ),
3119
- period_sales_total_minor: sum(rows.map((row2) => row2.amountMinor)),
3120
- period_refunds_total_minor: sum(countedRefunds.flatMap((refund) => refundAmounts(refund).map(([, amount]) => amount))),
3269
+ period_sales_total_minor: sum2(rows.map((row2) => row2.amountMinor)),
3270
+ period_refunds_total_minor: sum2(countedRefunds.flatMap((refund) => refundAmounts(refund).map(([, amount]) => amount))),
3121
3271
  perpetual_sales_total_minor: 0,
3122
3272
  perpetual_refunds_total_minor: 0,
3123
3273
  unsynced_count: unsynced.length,
3124
- unsynced_total_minor: sum(unsynced.flatMap((order) => order.payments.map((payment) => payment.amountMinor))),
3274
+ unsynced_total_minor: sum2(unsynced.flatMap((order) => order.payments.map((payment) => payment.amountMinor))),
3125
3275
  software_version: softwareVersion,
3126
3276
  printed_at: null,
3127
3277
  print_count: 0,
@@ -3218,6 +3368,8 @@ async function reopenRefusedOrder(orderId, deps) {
3218
3368
  sku: line.sku,
3219
3369
  unitPrice: { amount: line.unitPriceMinor, currency: order.currency, taxInclusive: line.taxInclusive },
3220
3370
  ...line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
3371
+ ...line.attributes !== void 0 ? { attributes: line.attributes } : {},
3372
+ ...line.anyAttributes !== void 0 ? { anyAttributes: line.anyAttributes } : {},
3221
3373
  quantity: line.quantity,
3222
3374
  taxRates: line.taxLines.map(({ code, ratePpm }) => ({ code, ratePpm })),
3223
3375
  ...line.custom ? { custom: true, taxClass: line.custom.taxClass, taxStatus: line.custom.taxStatus } : { taxClass: deps.taxClassOf?.(line.productId, line.variantId) ?? "standard", taxStatus: line.taxStatus }
@@ -4522,7 +4674,17 @@ var CartError = class extends Error {
4522
4674
  };
4523
4675
  function addEntryToCart(builder, entry, traits, currency) {
4524
4676
  const { product, variant } = entry;
4525
- const existing = builder.getSnapshot().lineItems.find((line) => line.variantId === variant.id);
4677
+ const picks = entry.picks ?? {};
4678
+ const groups = Object.keys(picks).length ? traits.getVariantOptions?.(product) ?? [] : [];
4679
+ const position = (name2) => groups.findIndex((group) => group.id === void 0 && group.name === name2);
4680
+ for (const [name2, value] of Object.entries(picks)) {
4681
+ const group = groups[position(name2)];
4682
+ if (!group || Object.keys(variant.options ?? {}).includes(name2)) throw new CartError(`${name2} is not an option to choose for this item`);
4683
+ if (typeof value !== "string" || !value || !group.values.includes(value)) throw new CartError(`${value} is not a choice for ${name2}`);
4684
+ }
4685
+ const anyAttributes = Object.keys(picks).sort((a, b) => position(a) - position(b));
4686
+ const attributes = { ...variant.options, ...Object.fromEntries(anyAttributes.map((name2) => [name2, picks[name2]])) };
4687
+ const existing = builder.getSnapshot().lineItems.find((line) => line.variantId === variant.id && samePicks(line, { anyAttributes, attributes }));
4526
4688
  if (existing) {
4527
4689
  builder.updateQuantity(existing.id, existing.quantity + 1);
4528
4690
  return existing.id;
@@ -4535,6 +4697,8 @@ function addEntryToCart(builder, entry, traits, currency) {
4535
4697
  productId: traits.getId(product),
4536
4698
  variantId: variant.id,
4537
4699
  name,
4700
+ ...Object.keys(attributes).length ? { attributes } : {},
4701
+ ...anyAttributes.length ? { anyAttributes } : {},
4538
4702
  sku: variant.sku ?? "",
4539
4703
  imageUrl: traits.getImageUrl?.(product),
4540
4704
  unitPrice,
@@ -5131,10 +5295,10 @@ __export(woocommerce_exports, {
5131
5295
  });
5132
5296
 
5133
5297
  // src/sale/woocommerce/discount-codes.ts
5134
- import { minorUnitDigits as minorUnitDigits4, woocommerceCoupons as woocommerceCoupons3 } from "@tallyui/core";
5298
+ import { minorUnitDigits as minorUnitDigits5, woocommerceCoupons as woocommerceCoupons3 } from "@tallyui/core";
5135
5299
 
5136
5300
  // src/sale/woocommerce/coupons.ts
5137
- import { minorUnitDigits as minorUnitDigits3 } from "@tallyui/core";
5301
+ import { minorUnitDigits as minorUnitDigits4 } from "@tallyui/core";
5138
5302
  function couponRefusal(code, rejection) {
5139
5303
  switch (rejection.code) {
5140
5304
  case "already_applied":
@@ -5162,7 +5326,7 @@ function couponRefusal(code, rejection) {
5162
5326
  }
5163
5327
  }
5164
5328
  function couponLineItems(lines, currency, categories) {
5165
- const digits = minorUnitDigits3(currency), factor = 10 ** digits;
5329
+ const digits = minorUnitDigits4(currency), factor = 10 ** digits;
5166
5330
  return lines.flatMap((line, lineIndex) => {
5167
5331
  if (line.unitPriceMinor < 0) return [];
5168
5332
  const id2 = Number(line.productId), product_id = !line.custom && Number.isSafeInteger(id2) && id2 >= 0 ? id2 : 0;
@@ -5198,7 +5362,7 @@ function createDiscountCodes(source) {
5198
5362
  lineItems: couponLineItems(snapshot.lineItems, snapshot.currency, sale.categories),
5199
5363
  appliedCoupons: [...sale.accepted.keys()],
5200
5364
  appliedCouponsWithIndividualUse: [...sale.accepted].filter(([, value]) => value.individual_use).map(([key]) => key),
5201
- cartSubtotal: snapshot.display.subtotalMinor / 10 ** minorUnitDigits4(snapshot.currency),
5365
+ cartSubtotal: snapshot.display.subtotalMinor / 10 ** minorUnitDigits5(snapshot.currency),
5202
5366
  customerEmail: snapshot.customer?.email ?? "",
5203
5367
  customerId: wooCustomerId(snapshot.customer),
5204
5368
  now: Date.now()
@@ -6544,7 +6708,7 @@ function tenderReducer(state, action) {
6544
6708
  };
6545
6709
  case "tender-recorded": {
6546
6710
  const linesPaidBy = { ...state.linesPaidBy };
6547
- if (state.plan?.kind === "items" && action.rowsSinceFrom.reduce((sum, row) => sum + row.amountMinor, 0) >= state.plan.firstMinor) {
6711
+ if (state.plan?.kind === "items" && action.rowsSinceFrom.reduce((sum2, row) => sum2 + row.amountMinor, 0) >= state.plan.firstMinor) {
6548
6712
  for (const id2 of state.plan.lineIds) {
6549
6713
  linesPaidBy[id2] ??= [...new Set(action.rowsSinceFrom.map((row) => row.title))];
6550
6714
  }
@@ -6640,7 +6804,7 @@ function activePlan(plan, taken, balanceMinor) {
6640
6804
  function planLegs(plan, rowsSinceFrom, balanceMinor) {
6641
6805
  const taken = rowsSinceFrom.length;
6642
6806
  const legs = rowsSinceFrom.map((row) => ({ ...row, state: "done" }));
6643
- const groupPaid = rowsSinceFrom.reduce((sum, row) => sum + row.minor, 0);
6807
+ const groupPaid = rowsSinceFrom.reduce((sum2, row) => sum2 + row.minor, 0);
6644
6808
  const groupLeft = plan.kind === "items" ? Math.min(balanceMinor, Math.max(0, plan.firstMinor - groupPaid)) : balanceMinor;
6645
6809
  const rest = plan.kind === "items" && groupLeft === 0;
6646
6810
  const ways = plan.kind === "fixed" ? 2 : Math.max(plan.ways, taken + 1);
@@ -6749,6 +6913,8 @@ export {
6749
6913
  bindRegister,
6750
6914
  buildClosureDocument,
6751
6915
  buildReceiptData,
6916
+ buildReceiptDataFromPosOrder,
6917
+ buildReceiptDataFromStoreOrder,
6752
6918
  buildXReportDocument,
6753
6919
  callbackSink,
6754
6920
  cashMovementSchema,