@tallyui/pos 3.11.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(
@@ -977,6 +981,7 @@ function createOrderBuilder(options) {
977
981
  variantId,
978
982
  name: input.name,
979
983
  ...input.attributes && Object.keys(input.attributes).length ? { attributes: { ...input.attributes } } : {},
984
+ ...input.anyAttributes?.length ? { anyAttributes: [...input.anyAttributes] } : {},
980
985
  sku: input.sku ?? "",
981
986
  imageUrl: input.imageUrl,
982
987
  unitPriceMinor: unitPrice.amount,
@@ -1216,18 +1221,18 @@ function cutText(text2, max) {
1216
1221
  }
1217
1222
  function netDiscountMinor(line, pricesIncludeTax) {
1218
1223
  if (!(line.taxInclusive ?? pricesIncludeTax) || line.discountMinor === 0) return line.discountMinor;
1219
- const ratePpm = line.taxLines.reduce((sum, tax) => sum + tax.ratePpm, 0);
1220
- 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);
1221
1226
  const taxBefore = taxMicros(line.unitPriceMinor * line.quantity, ratePpm, true);
1222
1227
  return roundMicrosToMinor(BigInt(line.discountMinor) * MICROS_PER_MINOR - taxBefore + taxAfter);
1223
1228
  }
1224
1229
  function contentVersion(order) {
1225
- if (order.coupons?.length) return 6;
1230
+ if (order.coupons?.length || order.lines.some((line) => line.anyAttributes?.length)) return 6;
1226
1231
  if (order.fees?.length || order.shipping?.length || order.lines.some((line) => line.custom)) return 5;
1227
- 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;
1228
1233
  }
1229
1234
  function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1230
- const grossMinor = order.lines.reduce((sum, line) => sum + line.discountMinor, 0);
1235
+ const grossMinor = order.lines.reduce((sum2, line) => sum2 + line.discountMinor, 0);
1231
1236
  const content = contentVersion(order);
1232
1237
  const cap = options?.maxVersion === void 0 ? order.sentVersion : Math.min(options.maxVersion, order.sentVersion ?? options.maxVersion);
1233
1238
  if (content === 5 && cap !== void 0 && cap < 5) throw new UnsupportedOrderVersionError(5, cap);
@@ -1235,7 +1240,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1235
1240
  if (grossMinor > 0 && cap !== void 0 && cap < 2) throw new UnsupportedOrderVersionError(2, cap);
1236
1241
  const version = content === 3 && cap !== void 0 && cap >= 4 ? 4 : Math.min(content, cap ?? content);
1237
1242
  const lineDiscounts = order.lines.map((line) => version >= 4 ? netDiscountMinor(line, order.pricesIncludeTax) : line.discountMinor);
1238
- const discountMinor = lineDiscounts.reduce((sum, discount) => sum + discount, 0);
1243
+ const discountMinor = lineDiscounts.reduce((sum2, discount) => sum2 + discount, 0);
1239
1244
  const email = order.customer?.email;
1240
1245
  const id2 = order.customer?.id;
1241
1246
  const customerId = typeof id2 === "string" && id2.length > 0 && id2.length <= 64 ? id2 : void 0;
@@ -1262,7 +1267,8 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1262
1267
  ...line.taxInclusive !== void 0 ? { taxInclusive: line.taxInclusive } : {},
1263
1268
  ...lineDiscounts[i] > 0 ? { discountMinor: lineDiscounts[i] } : {},
1264
1269
  ...version === 6 && line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
1265
- ...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] } : {}
1266
1272
  })),
1267
1273
  ...version >= 5 && order.fees?.length ? { fees: order.fees.map((fee) => ({
1268
1274
  clientFeeId: fee.id,
@@ -1281,7 +1287,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1281
1287
  ...charge.taxClass !== void 0 ? { taxClass: charge.taxClass } : {},
1282
1288
  taxMinor: roundMicrosToMinor(BigInt(charge.taxMicros))
1283
1289
  })) } : {},
1284
- ...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 }) => ({
1285
1291
  code,
1286
1292
  couponId,
1287
1293
  discountMinor: discountMinor2,
@@ -1309,7 +1315,7 @@ function toOrderCreateEnvelope(order, deviceId, attempt2 = 1, options) {
1309
1315
  })),
1310
1316
  ...version >= 5 && order.display.fees ? { fees: order.display.fees.map(({ id: id3, amountMinor }) => ({ clientFeeId: id3, amountMinor })) } : {},
1311
1317
  ...version >= 5 && order.display.shipping ? { shipping: order.display.shipping.map(({ id: id3, amountMinor }) => ({ clientShippingId: id3, amountMinor })) } : {},
1312
- ...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 })) } : {}
1313
1319
  },
1314
1320
  taxByRate: order.taxByRate.map(({ ratePpm, code, netMinor, amountMinor, grossMinor: grossMinor2 }) => ({
1315
1321
  ratePpm,
@@ -1375,6 +1381,7 @@ function restoreOrderDraft(saved, options) {
1375
1381
  variantId: line.variantId,
1376
1382
  name: line.name,
1377
1383
  ...line.attributes !== void 0 ? { attributes: line.attributes } : {},
1384
+ ...line.anyAttributes !== void 0 ? { anyAttributes: line.anyAttributes } : {},
1378
1385
  sku: line.sku,
1379
1386
  imageUrl: line.imageUrl,
1380
1387
  unitPrice: { amount: line.unitPriceMinor, currency, taxInclusive: line.taxInclusive },
@@ -1504,7 +1511,7 @@ function buildReceiptData(order, config) {
1504
1511
  ({ label: label2, code, ratePpm, amountMinor }) => ({ label: label2, code, ratePpm, amountMinor })
1505
1512
  );
1506
1513
  let taxSoFar = order.lineItems.reduce(
1507
- (sum, li) => li.taxInclusive || li.priceTaxModeConverted ? sum : sum + BigInt(li.taxMicros),
1514
+ (sum2, li) => li.taxInclusive || li.priceTaxModeConverted ? sum2 : sum2 + BigInt(li.taxMicros),
1508
1515
  0n
1509
1516
  );
1510
1517
  const lineTotals = order.lineItems.map((li) => {
@@ -1584,6 +1591,140 @@ function buildReceiptData(order, config) {
1584
1591
  };
1585
1592
  }
1586
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
+
1587
1728
  // src/product/search-products.ts
1588
1729
  function searchProducts(docs, term, traits) {
1589
1730
  const query = term.trim().toLowerCase();
@@ -1774,7 +1915,7 @@ function uuidv7(now, randomBytes) {
1774
1915
  }
1775
1916
 
1776
1917
  // src/pos-order/finalize.ts
1777
- import { minorUnitDigits as minorUnitDigits2 } from "@tallyui/core";
1918
+ import { minorUnitDigits as minorUnitDigits3 } from "@tallyui/core";
1778
1919
 
1779
1920
  // src/outbox/logger.ts
1780
1921
  var outboxLogger = createLogger("outbox");
@@ -1873,6 +2014,9 @@ function finalizeOrder(order, options = {}) {
1873
2014
  if (order.coupons?.length && (options.capabilities?.orderCreate ?? 1) < 6) {
1874
2015
  throw new Error("finalize: coupons need the store to accept order.create version 6; update the store's TallyUI plugin");
1875
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
+ }
1876
2020
  if (!order.lineItems.length) throw new Error("finalize: no lines");
1877
2021
  if (order.discountMinor < 0 || order.lineItems.some((line) => line.discountMinor < 0) || order.discounts.some((d) => d.amountMinor < 0)) {
1878
2022
  throw new Error("finalize: negative discount");
@@ -1888,7 +2032,7 @@ function finalizeOrder(order, options = {}) {
1888
2032
  }
1889
2033
  if (order.paidMinor < order.totalMinor) throw new Error("finalize: underpaid");
1890
2034
  let change = order.paidMinor - order.totalMinor;
1891
- 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);
1892
2036
  if (change > cash) throw new Error("finalize: change exceeds cash");
1893
2037
  const v3 = (options.capabilities?.orderCreate ?? 1) >= 3;
1894
2038
  const references = [
@@ -1926,6 +2070,7 @@ function finalizeOrder(order, options = {}) {
1926
2070
  quantity: line.quantity,
1927
2071
  unitPriceMinor: line.unitPriceMinor,
1928
2072
  ...line.attributes && Object.keys(line.attributes).length ? { attributes: { ...line.attributes } } : {},
2073
+ ...line.anyAttributes?.length ? { anyAttributes: [...line.anyAttributes] } : {},
1929
2074
  ...line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
1930
2075
  discountMinor: line.discountMinor,
1931
2076
  netMinor: line.netMinor,
@@ -1961,7 +2106,7 @@ function finalizeOrder(order, options = {}) {
1961
2106
  payment.amountMinor -= payment.changeMinor;
1962
2107
  change -= payment.changeMinor;
1963
2108
  }
1964
- if (payments.reduce((sum, p) => sum + p.amountMinor, 0) !== order.totalMinor) {
2109
+ if (payments.reduce((sum2, p) => sum2 + p.amountMinor, 0) !== order.totalMinor) {
1965
2110
  throw new Error("finalize: payments do not reconcile");
1966
2111
  }
1967
2112
  let display;
@@ -1972,7 +2117,7 @@ function finalizeOrder(order, options = {}) {
1972
2117
  }
1973
2118
  display = {
1974
2119
  currency: order.currency,
1975
- exponent: minorUnitDigits2(order.currency),
2120
+ exponent: minorUnitDigits3(order.currency),
1976
2121
  ...order.display,
1977
2122
  ...fees?.length ? { fees: order.display.fees.map((row, i) => ({ ...row, id: fees[i].id })) } : {},
1978
2123
  ...shipping?.length ? { shipping: order.display.shipping.map((row, i) => ({ ...row, id: shipping[i].id })) } : {},
@@ -1997,7 +2142,7 @@ function finalizeOrder(order, options = {}) {
1997
2142
  if (display.totalMinor !== order.totalMinor || display.taxMinor !== order.taxMinor || display.taxInclusive !== order.pricesIncludeTax) {
1998
2143
  throw new Error("finalize: display does not match the order");
1999
2144
  }
2000
- if (taxByRate.reduce((sum, rate) => sum + rate.amountMinor, 0) !== order.taxMinor) {
2145
+ if (taxByRate.reduce((sum2, rate) => sum2 + rate.amountMinor, 0) !== order.taxMinor) {
2001
2146
  throw new Error("finalize: tax by rate does not sum to the order tax");
2002
2147
  }
2003
2148
  }
@@ -2040,7 +2185,7 @@ function finalizeOrder(order, options = {}) {
2040
2185
  import { addRxPlugin } from "rxdb";
2041
2186
  import { RxDBMigrationSchemaPlugin } from "rxdb/plugins/migration-schema";
2042
2187
  var posOrderSchema = {
2043
- version: 9,
2188
+ version: 10,
2044
2189
  primaryKey: "id",
2045
2190
  type: "object",
2046
2191
  additionalProperties: false,
@@ -2088,6 +2233,7 @@ var posOrderSchema = {
2088
2233
  discountMinor: { type: "integer" },
2089
2234
  netMinor: { type: "integer" },
2090
2235
  attributes: { type: "object", additionalProperties: { type: "string" } },
2236
+ anyAttributes: { type: "array", items: { type: "string", minLength: 1, maxLength: 255 } },
2091
2237
  regularUnitPriceMinor: { type: "integer" },
2092
2238
  netMicros: { type: "string", pattern: "^-?[0-9]{1,24}$", maxLength: 25 },
2093
2239
  taxLines: { type: "array", items: {
@@ -2264,7 +2410,7 @@ function posOrderCollection() {
2264
2410
  };
2265
2411
  return {
2266
2412
  schema: posOrderSchema,
2267
- 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 }
2268
2414
  };
2269
2415
  }
2270
2416
 
@@ -2775,7 +2921,7 @@ var validAmount = (value, exponent) => /^(?:\d+\.?\d*|\.\d+)$/.test(value) && Nu
2775
2921
  var countVariance = (countedMinor, expectedMinor) => countedMinor - expectedMinor;
2776
2922
  var overThreshold = (variance, thresholdMinor) => thresholdMinor != null && Math.abs(variance) > thresholdMinor;
2777
2923
  var closeNeedsApproval = (countedCashMinor, expectedCashMinor, thresholdMinor) => overThreshold(countVariance(countedCashMinor, expectedCashMinor), thresholdMinor);
2778
- 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);
2779
2925
  function varianceText(variance, exponent, format2, t) {
2780
2926
  if (!variance) return t("register.exact");
2781
2927
  return `${format2(Math.abs(variance) / 10 ** exponent)} ${t(variance < 0 ? "register.short" : "register.over")}`;
@@ -3075,7 +3221,7 @@ async function writeClosure({
3075
3221
  refunds
3076
3222
  });
3077
3223
  const counts = { cash: counted, ...otherTenders };
3078
- const sum = (values) => values.reduce((total, value) => total + value, 0);
3224
+ const sum2 = (values) => values.reduce((total, value) => total + value, 0);
3079
3225
  const payment_methods = {};
3080
3226
  for (const row2 of rows) {
3081
3227
  const method = row2.kind === "cash" ? "cash" : row2.method_id;
@@ -3120,12 +3266,12 @@ async function writeClosure({
3120
3266
  variance: Object.fromEntries(
3121
3267
  Object.entries(counts).map(([method, value]) => [method, countVariance(value, till_expected[method] ?? 0)])
3122
3268
  ),
3123
- period_sales_total_minor: sum(rows.map((row2) => row2.amountMinor)),
3124
- 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))),
3125
3271
  perpetual_sales_total_minor: 0,
3126
3272
  perpetual_refunds_total_minor: 0,
3127
3273
  unsynced_count: unsynced.length,
3128
- 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))),
3129
3275
  software_version: softwareVersion,
3130
3276
  printed_at: null,
3131
3277
  print_count: 0,
@@ -3223,6 +3369,7 @@ async function reopenRefusedOrder(orderId, deps) {
3223
3369
  unitPrice: { amount: line.unitPriceMinor, currency: order.currency, taxInclusive: line.taxInclusive },
3224
3370
  ...line.regularUnitPriceMinor !== void 0 ? { regularUnitPriceMinor: line.regularUnitPriceMinor } : {},
3225
3371
  ...line.attributes !== void 0 ? { attributes: line.attributes } : {},
3372
+ ...line.anyAttributes !== void 0 ? { anyAttributes: line.anyAttributes } : {},
3226
3373
  quantity: line.quantity,
3227
3374
  taxRates: line.taxLines.map(({ code, ratePpm }) => ({ code, ratePpm })),
3228
3375
  ...line.custom ? { custom: true, taxClass: line.custom.taxClass, taxStatus: line.custom.taxStatus } : { taxClass: deps.taxClassOf?.(line.productId, line.variantId) ?? "standard", taxStatus: line.taxStatus }
@@ -4527,7 +4674,17 @@ var CartError = class extends Error {
4527
4674
  };
4528
4675
  function addEntryToCart(builder, entry, traits, currency) {
4529
4676
  const { product, variant } = entry;
4530
- 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 }));
4531
4688
  if (existing) {
4532
4689
  builder.updateQuantity(existing.id, existing.quantity + 1);
4533
4690
  return existing.id;
@@ -4540,7 +4697,8 @@ function addEntryToCart(builder, entry, traits, currency) {
4540
4697
  productId: traits.getId(product),
4541
4698
  variantId: variant.id,
4542
4699
  name,
4543
- ...variant.options && Object.keys(variant.options).length ? { attributes: variant.options } : {},
4700
+ ...Object.keys(attributes).length ? { attributes } : {},
4701
+ ...anyAttributes.length ? { anyAttributes } : {},
4544
4702
  sku: variant.sku ?? "",
4545
4703
  imageUrl: traits.getImageUrl?.(product),
4546
4704
  unitPrice,
@@ -5137,10 +5295,10 @@ __export(woocommerce_exports, {
5137
5295
  });
5138
5296
 
5139
5297
  // src/sale/woocommerce/discount-codes.ts
5140
- import { minorUnitDigits as minorUnitDigits4, woocommerceCoupons as woocommerceCoupons3 } from "@tallyui/core";
5298
+ import { minorUnitDigits as minorUnitDigits5, woocommerceCoupons as woocommerceCoupons3 } from "@tallyui/core";
5141
5299
 
5142
5300
  // src/sale/woocommerce/coupons.ts
5143
- import { minorUnitDigits as minorUnitDigits3 } from "@tallyui/core";
5301
+ import { minorUnitDigits as minorUnitDigits4 } from "@tallyui/core";
5144
5302
  function couponRefusal(code, rejection) {
5145
5303
  switch (rejection.code) {
5146
5304
  case "already_applied":
@@ -5168,7 +5326,7 @@ function couponRefusal(code, rejection) {
5168
5326
  }
5169
5327
  }
5170
5328
  function couponLineItems(lines, currency, categories) {
5171
- const digits = minorUnitDigits3(currency), factor = 10 ** digits;
5329
+ const digits = minorUnitDigits4(currency), factor = 10 ** digits;
5172
5330
  return lines.flatMap((line, lineIndex) => {
5173
5331
  if (line.unitPriceMinor < 0) return [];
5174
5332
  const id2 = Number(line.productId), product_id = !line.custom && Number.isSafeInteger(id2) && id2 >= 0 ? id2 : 0;
@@ -5204,7 +5362,7 @@ function createDiscountCodes(source) {
5204
5362
  lineItems: couponLineItems(snapshot.lineItems, snapshot.currency, sale.categories),
5205
5363
  appliedCoupons: [...sale.accepted.keys()],
5206
5364
  appliedCouponsWithIndividualUse: [...sale.accepted].filter(([, value]) => value.individual_use).map(([key]) => key),
5207
- cartSubtotal: snapshot.display.subtotalMinor / 10 ** minorUnitDigits4(snapshot.currency),
5365
+ cartSubtotal: snapshot.display.subtotalMinor / 10 ** minorUnitDigits5(snapshot.currency),
5208
5366
  customerEmail: snapshot.customer?.email ?? "",
5209
5367
  customerId: wooCustomerId(snapshot.customer),
5210
5368
  now: Date.now()
@@ -6550,7 +6708,7 @@ function tenderReducer(state, action) {
6550
6708
  };
6551
6709
  case "tender-recorded": {
6552
6710
  const linesPaidBy = { ...state.linesPaidBy };
6553
- 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) {
6554
6712
  for (const id2 of state.plan.lineIds) {
6555
6713
  linesPaidBy[id2] ??= [...new Set(action.rowsSinceFrom.map((row) => row.title))];
6556
6714
  }
@@ -6646,7 +6804,7 @@ function activePlan(plan, taken, balanceMinor) {
6646
6804
  function planLegs(plan, rowsSinceFrom, balanceMinor) {
6647
6805
  const taken = rowsSinceFrom.length;
6648
6806
  const legs = rowsSinceFrom.map((row) => ({ ...row, state: "done" }));
6649
- const groupPaid = rowsSinceFrom.reduce((sum, row) => sum + row.minor, 0);
6807
+ const groupPaid = rowsSinceFrom.reduce((sum2, row) => sum2 + row.minor, 0);
6650
6808
  const groupLeft = plan.kind === "items" ? Math.min(balanceMinor, Math.max(0, plan.firstMinor - groupPaid)) : balanceMinor;
6651
6809
  const rest = plan.kind === "items" && groupLeft === 0;
6652
6810
  const ways = plan.kind === "fixed" ? 2 : Math.max(plan.ways, taken + 1);
@@ -6755,6 +6913,8 @@ export {
6755
6913
  bindRegister,
6756
6914
  buildClosureDocument,
6757
6915
  buildReceiptData,
6916
+ buildReceiptDataFromPosOrder,
6917
+ buildReceiptDataFromStoreOrder,
6758
6918
  buildXReportDocument,
6759
6919
  callbackSink,
6760
6920
  cashMovementSchema,