@pisell/pisellos 2.3.104 → 2.3.106

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.
@@ -22,6 +22,8 @@ const LABELS = {
22
22
  pickUpTime: 'Pick-up time',
23
23
  asap: 'ASAP',
24
24
  cash: 'Cash',
25
+ cashReceived: 'Cash received',
26
+ changeDue: 'Change due',
25
27
  eftpos: 'Eftpos',
26
28
  wallet: 'Wallet',
27
29
  giftCard: 'Gift card',
@@ -49,6 +51,8 @@ const LABELS = {
49
51
  pickUpTime: '取餐时间',
50
52
  asap: '尽快',
51
53
  cash: '现金支付',
54
+ cashReceived: '收取现金',
55
+ changeDue: '找零',
52
56
  eftpos: '刷卡支付',
53
57
  wallet: '钱包支付',
54
58
  giftCard: '礼品卡',
@@ -76,6 +80,8 @@ const LABELS = {
76
80
  pickUpTime: '取餐時間',
77
81
  asap: '盡快',
78
82
  cash: '現金支付',
83
+ cashReceived: '收取現金',
84
+ changeDue: '找零',
79
85
  eftpos: '刷卡支付',
80
86
  wallet: '錢包支付',
81
87
  giftCard: '禮品卡',
@@ -90,6 +96,14 @@ const LABELS = {
90
96
  rounding: '抹零',
91
97
  gross: '重量',
92
98
  tare: '去皮'
99
+ },
100
+ ja: {
101
+ cashReceived: 'お預かり',
102
+ changeDue: 'お釣り'
103
+ },
104
+ pt: {
105
+ cashReceived: 'Dinheiro recebido',
106
+ changeDue: 'Troco'
93
107
  }
94
108
  };
95
109
  function buildSmallTicketData(params) {
@@ -169,7 +183,7 @@ function buildBaseData(params) {
169
183
  order_number: orderNumber,
170
184
  shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
171
185
  shop_phone: stringify(shopInfo.phone || order.shop_phone),
172
- shop_address: stringify(shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
186
+ shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
173
187
  original_payment_status: stringify(order.payment_status),
174
188
  is_repeat: 0,
175
189
  buzzer: stringify(order.buzzer || order.pickup_number || order.metadata?.buzzer),
@@ -807,6 +821,11 @@ function buildPaymentItems(params) {
807
821
  item: paymentMethodName(payment, locale),
808
822
  value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
809
823
  }];
824
+ items.push(...buildCashChangePaymentItems({
825
+ payment,
826
+ locale,
827
+ currencySymbol
828
+ }));
810
829
  if (serviceFee.gt(0)) {
811
830
  items.push({
812
831
  item: label(locale, 'surchargeIncluded'),
@@ -848,6 +867,36 @@ function resolveReceiptPaymentAmount(payment, serviceFee) {
848
867
  const originAmount = new _decimal.default(toMoneyNumber(payment.origin_amount));
849
868
  return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
850
869
  }
870
+ function buildCashChangePaymentItems(params) {
871
+ const {
872
+ payment,
873
+ locale,
874
+ currencySymbol
875
+ } = params;
876
+ if (!shouldDisplayCashChange(payment)) return [];
877
+ return [{
878
+ item: label(locale, 'cashReceived'),
879
+ value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
880
+ }, {
881
+ item: label(locale, 'changeDue'),
882
+ value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
883
+ }];
884
+ }
885
+ function shouldDisplayCashChange(payment) {
886
+ if (stringify(payment.status).toLowerCase() !== 'paid') return false;
887
+ const paymentMethod = stringify(payment.code ?? payment.payment_method).toUpperCase();
888
+ if (paymentMethod !== 'CASHMANUAL') return false;
889
+ const actualPaidAmount = payment.metadata?.actual_paid_amount;
890
+ const changeGivenAmount = payment.metadata?.change_given_amount;
891
+ if (!isNumericAmount(actualPaidAmount) || !isNumericAmount(changeGivenAmount)) return false;
892
+ return new _decimal.default(changeGivenAmount).toDecimalPlaces(2).gt(0);
893
+ }
894
+ function isNumericAmount(value) {
895
+ if (typeof value === 'number') return Number.isFinite(value);
896
+ if (typeof value !== 'string') return false;
897
+ const normalized = value.trim();
898
+ return normalized !== '' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(normalized);
899
+ }
851
900
  function buildFundRecordPaymentItems(params) {
852
901
  const {
853
902
  payment,
@@ -130,8 +130,8 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
130
130
  */
131
131
  clearSessionStorageOrderSnapshot(): void;
132
132
  /**
133
- * Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
134
- * 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
133
+ * H5/Kiosk 不能把已收款订单留在本地等待重试,必须直接等待云端 checkout。
134
+ * 其它平台保持 WebPOS/POS 的本地待同步任务;显式 true 仍可强制使用本地任务。
135
135
  */
136
136
  protected shouldUseCheckoutSyncTask(): boolean;
137
137
  /** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
@@ -655,6 +655,22 @@ function normalizeResource(raw, fixedOffsetMinutes = (0, _localClock.captureRunt
655
655
  const id = raw.resourceId ?? raw.resource_id ?? raw.id;
656
656
  if (id === undefined || id === null || id === '') return null;
657
657
  const rawWindows = raw.windows || raw.times || [];
658
+ const rawExcludedWindows = raw.excludedWindows || raw.excluded_windows || [];
659
+ const normalizeWindows = windows => (Array.isArray(windows) ? windows : []).flatMap(window => {
660
+ const range = normalizeAvailabilityLocalDateTimeRange({
661
+ startAt: window.startAt || window.start_at || window.start,
662
+ endAt: window.endAt || window.end_at || window.end,
663
+ fixedOffsetMinutes,
664
+ rollOverEnd: true
665
+ });
666
+ if (!range) return [];
667
+ return [{
668
+ startAt: range.startAt,
669
+ endAt: range.endAt,
670
+ source: window.source,
671
+ raw: window
672
+ }];
673
+ });
658
674
  return {
659
675
  id,
660
676
  formId: raw.formId ?? raw.form_id ?? raw.resource_form_id,
@@ -662,21 +678,8 @@ function normalizeResource(raw, fixedOffsetMinutes = (0, _localClock.captureRunt
662
678
  code: raw.code,
663
679
  resourceType: normalizeResourceType(raw.type || raw.resourceType),
664
680
  capacity: Math.max(1, Number(raw.capacity || raw.max_capacity || 1) || 1),
665
- windows: (Array.isArray(rawWindows) ? rawWindows : []).flatMap(window => {
666
- const range = normalizeAvailabilityLocalDateTimeRange({
667
- startAt: window.startAt || window.start_at || window.start,
668
- endAt: window.endAt || window.end_at || window.end,
669
- fixedOffsetMinutes,
670
- rollOverEnd: true
671
- });
672
- if (!range) return [];
673
- return [{
674
- startAt: range.startAt,
675
- endAt: range.endAt,
676
- source: window.source,
677
- raw: window
678
- }];
679
- }),
681
+ windows: normalizeWindows(rawWindows),
682
+ excludedWindows: normalizeWindows(rawExcludedWindows),
680
683
  raw
681
684
  };
682
685
  }
@@ -695,6 +698,17 @@ function dateRangeDays(dateRange) {
695
698
  }
696
699
  return dates;
697
700
  }
701
+ function getExcludedScheduleDateOverrideTimePoints(date, schedule) {
702
+ if (!schedule.repeat_rule?.excluded_date?.length) return [];
703
+ if ((0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(date, [schedule]).length > 0) return [];
704
+ return (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(date, [{
705
+ ...schedule,
706
+ repeat_rule: {
707
+ ...schedule.repeat_rule,
708
+ excluded_date: []
709
+ }
710
+ }]);
711
+ }
698
712
  function normalizeResourceOccupancy(rawEvent, resourceId, source = 'remote', fixedOffsetMinutes = (0, _localClock.captureRuntimeOffsetMinutes)()) {
699
713
  const range = normalizeAvailabilityLocalDateTimeRange({
700
714
  startAt: rawEvent.start_at ?? rawEvent.startAt ?? rawEvent.start_time ?? rawEvent.startTime,
@@ -787,7 +801,26 @@ function buildAvailabilityResourcesFromV2(params) {
787
801
  }
788
802
  }];
789
803
  })));
804
+ const excludedWindows = dates.flatMap(date => schedules.flatMap(schedule => getExcludedScheduleDateOverrideTimePoints(date, schedule).flatMap(slot => {
805
+ const range = normalizeAvailabilityLocalDateTimeRange({
806
+ startAt: slot.start_at,
807
+ endAt: slot.end_at,
808
+ fixedOffsetMinutes,
809
+ rollOverEnd: true
810
+ });
811
+ if (!range) return [];
812
+ return [{
813
+ startAt: range.startAt,
814
+ endAt: range.endAt,
815
+ source: `resource_schedule_excluded:${schedule.id}`,
816
+ raw: {
817
+ scheduleId: schedule.id,
818
+ excludedDate: date
819
+ }
820
+ }];
821
+ })));
790
822
  resource.windows = materializedWindows.length > 0 ? materializedWindows : explicitWindows;
823
+ resource.excludedWindows = [...(resource.excludedWindows || []), ...excludedWindows];
791
824
  if (resource.windows.length === 0 && missingScheduleIds.length > 0) {
792
825
  resource.windows = buildResourceWindowFallbackTimes({
793
826
  raw,
@@ -962,7 +995,7 @@ function buildBookingFromAvailabilitySelection(params) {
962
995
  const endScalar = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(bookingEndAt));
963
996
  const scheduleId = candidate.primaryScheduleRef?.scheduleId ?? assignments.find(assignment => assignment.scheduleId != null)?.scheduleId;
964
997
  const timeSlotId = candidate.primaryScheduleRef?.timeSlotId ?? assignments.find(assignment => assignment.timeSlotId != null)?.timeSlotId;
965
- if (product.kind === 'session' && scheduleId == null) {
998
+ if (product.kind === 'session' && candidate.source === 'session_schedule' && scheduleId == null) {
966
999
  throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', 'session 候选缺少真实 schedule identity', {
967
1000
  productId: product.id,
968
1001
  candidateKey: candidate.key,
@@ -978,7 +1011,9 @@ function buildBookingFromAvailabilitySelection(params) {
978
1011
  end_time: bookingEndAt.slice(11, 16),
979
1012
  duration: Math.max(1, Math.trunc((endScalar - startScalar) / (60 * 1000))),
980
1013
  like_status: 'common',
981
- schedule_id: scheduleId ?? 0,
1014
+ ...(product.kind === 'session' && candidate.source === 'duration_window' ? {} : {
1015
+ schedule_id: scheduleId ?? 0
1016
+ }),
982
1017
  ...(normalizedHolder ? {
983
1018
  holder: normalizedHolder
984
1019
  } : {}),
@@ -1026,7 +1061,7 @@ function buildBookingFromAvailabilitySelection(params) {
1026
1061
  }
1027
1062
  };
1028
1063
  }
1029
- const POS_OVERRIDABLE_AVAILABILITY_CONFLICT_CODES = new Set(['past', 'booking_cutoff', 'resource_full', 'resource_unavailable', 'resource_capacity_exceeded',
1064
+ const POS_OVERRIDABLE_AVAILABILITY_CONFLICT_CODES = new Set(['past', 'booking_cutoff', 'schedule_excluded_date', 'resource_full', 'resource_unavailable', 'resource_capacity_exceeded',
1030
1065
  // A required group whose selected resource is outside its window is surfaced
1031
1066
  // as missing_resource at group level. Structural validation below still
1032
1067
  // rejects a genuinely missing selection.
@@ -1548,12 +1583,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1548
1583
  }
1549
1584
 
1550
1585
  /**
1551
- * Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
1552
- * 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
1586
+ * H5/Kiosk 不能把已收款订单留在本地等待重试,必须直接等待云端 checkout。
1587
+ * 其它平台保持 WebPOS/POS 的本地待同步任务;显式 true 仍可强制使用本地任务。
1553
1588
  */
1554
1589
  shouldUseCheckoutSyncTask() {
1555
1590
  const configured = this.otherParams?.checkoutSyncTaskEnabled;
1556
- return typeof configured === 'boolean' ? configured : false;
1591
+ if (configured === true) return true;
1592
+ const platform = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform);
1593
+ return platform !== 'h5' && platform !== 'kiosk';
1557
1594
  }
1558
1595
 
1559
1596
  /** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
@@ -2236,11 +2273,31 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2236
2273
  source: `operating_schedule:${descriptor.scheduleIds.map(String).join(',')}`
2237
2274
  }] : [];
2238
2275
  }));
2276
+ const excludedWindows = dateRangeDays(params.dateRange).flatMap(date => schedules.flatMap(schedule => getExcludedScheduleDateOverrideTimePoints(date, schedule).flatMap(slot => {
2277
+ const range = normalizeAvailabilityLocalDateTimeRange({
2278
+ startAt: slot.start_at,
2279
+ endAt: slot.end_at,
2280
+ fixedOffsetMinutes: this.getAvailabilityRuntimeOffsetMinutes(),
2281
+ rollOverEnd: true
2282
+ });
2283
+ return range ? [{
2284
+ startAt: range.startAt,
2285
+ endAt: range.endAt,
2286
+ source: `operating_schedule_excluded:${schedule.id}`,
2287
+ raw: {
2288
+ scheduleId: schedule.id,
2289
+ excludedDate: date
2290
+ }
2291
+ }] : [];
2292
+ })));
2239
2293
  return {
2240
2294
  source: descriptor.source,
2241
2295
  scheduleIds: [...descriptor.scheduleIds],
2242
2296
  missingScheduleIds,
2243
- windows
2297
+ windows,
2298
+ ...(excludedWindows.length > 0 ? {
2299
+ excludedWindows
2300
+ } : {})
2244
2301
  };
2245
2302
  }
2246
2303
  async loadAvailabilityProducts(params) {
@@ -2929,14 +2986,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2929
2986
  projectionEntry
2930
2987
  } = await this.ensureAvailabilityContextProjection(contextId, 'get_product_time_ranges');
2931
2988
  const contextVersion = context.activeVersion;
2932
- const allowOutsideOperatingHoursForRequestedStartTimes = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos' && Object.values(request.durationStartTimesByProductId || {}).some(startTimes => Array.isArray(startTimes) && startTimes.length > 0);
2989
+ const isPosAvailabilityRequest = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos';
2990
+ const allowOutsideOperatingHoursForRequestedStartTimes = isPosAvailabilityRequest && Object.values(request.durationStartTimesByProductId || {}).some(startTimes => Array.isArray(startTimes) && startTimes.length > 0);
2933
2991
  return (0, _ResourcePlanner.getProductTimeRanges)(projectionEntry.projection, {
2934
2992
  ...request,
2935
2993
  ...(allowOutsideOperatingHoursForRequestedStartTimes ? {
2936
2994
  allowOutsideOperatingHoursForRequestedStartTimes: true
2937
2995
  } : {})
2938
2996
  }, {
2939
- evaluatedAt: this.getAvailabilityRuntimeDateTime()
2997
+ evaluatedAt: this.getAvailabilityRuntimeDateTime(),
2998
+ useExactDurationCandidateMinute: isPosAvailabilityRequest,
2999
+ allowSessionCustomRanges: isPosAvailabilityRequest,
3000
+ allowExcludedScheduleDateOverride: isPosAvailabilityRequest
2940
3001
  }).map(group => ({
2941
3002
  ...group,
2942
3003
  ranges: group.ranges.map(candidate => this.decorateAvailabilityCandidate(context.contextId, contextVersion, candidate))
@@ -2951,7 +3012,11 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2951
3012
  refreshed
2952
3013
  } = await this.ensureAvailabilityContextProjection(contextId, 'query_booking_availability');
2953
3014
  this.assertContextualQueryFreshness(context, request);
2954
- const result = (0, _ResourcePlanner.queryAvailabilityProjection)(projectionEntry.projection, request);
3015
+ const isPosAvailabilityRequest = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos';
3016
+ const result = (0, _ResourcePlanner.queryAvailabilityProjection)(projectionEntry.projection, request, {
3017
+ useExactDurationCandidateMinute: isPosAvailabilityRequest,
3018
+ allowExcludedScheduleDateOverride: isPosAvailabilityRequest
3019
+ });
2955
3020
  const contextVersion = context.activeVersion;
2956
3021
  const contextualResult = result.target === 'time' ? {
2957
3022
  ...result,
@@ -3207,6 +3272,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
3207
3272
  } : {})
3208
3273
  } : {})
3209
3274
  } : {})
3275
+ }, {
3276
+ useExactDurationCandidateMinute: allowPosAvailabilityOverride,
3277
+ allowSessionCustomRanges: allowPosAvailabilityOverride,
3278
+ allowExcludedScheduleDateOverride: allowPosAvailabilityOverride
3210
3279
  }).flatMap(group => group.ranges);
3211
3280
  const refreshedCandidateBase = refreshedRanges.find(candidate => candidate.startAt === params.candidate.startAt && candidate.endAt === params.candidate.endAt && candidate.bookingStartAt === params.candidate.bookingStartAt && candidate.bookingEndAt === params.candidate.bookingEndAt);
3212
3281
  if (!refreshedCandidateBase) {
@@ -3227,6 +3296,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
3227
3296
  requirementSelections: params.requirementSelections,
3228
3297
  partySize,
3229
3298
  bookingCount
3299
+ }, {
3300
+ useExactDurationCandidateMinute: allowPosAvailabilityOverride,
3301
+ allowExcludedScheduleDateOverride: allowPosAvailabilityOverride
3230
3302
  });
3231
3303
  if (allowPosAvailabilityOverride && !validation.ok && validation.conflicts.every(conflict => POS_OVERRIDABLE_AVAILABILITY_CONFLICT_CODES.has(conflict.code))) {
3232
3304
  const forced = buildPosForcedAvailabilityAssignments({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.104",
4
+ "version": "2.3.106",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",