@pisell/pisellos 0.10.15 → 0.10.17

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.
Files changed (331) hide show
  1. package/dist/core/index.js +6 -9
  2. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.d.ts +5 -2
  10. package/dist/modules/OpenData/index.js +27 -14
  11. package/dist/modules/OpenData/types.d.ts +42 -0
  12. package/dist/modules/OpenData/types.js +7 -1
  13. package/dist/modules/OpenData/utils.d.ts +15 -1
  14. package/dist/modules/OpenData/utils.js +85 -0
  15. package/dist/modules/Order/index.d.ts +4 -2
  16. package/dist/modules/Order/index.js +131 -123
  17. package/dist/modules/Order/types.d.ts +8 -1
  18. package/dist/modules/Order/types.js +1 -0
  19. package/dist/modules/Order/utils.js +7 -1
  20. package/dist/modules/Payment/index.js +97 -162
  21. package/dist/modules/Product/types.d.ts +2 -0
  22. package/dist/modules/ProductList/index.js +96 -74
  23. package/dist/modules/Rules/index.js +12 -12
  24. package/dist/modules/SalesSummary/index.js +6 -4
  25. package/dist/modules/Schedule/index.js +0 -1
  26. package/dist/modules/Schedule/utils.js +0 -1
  27. package/dist/modules/Step/index.js +0 -1
  28. package/dist/plugins/request.js +1 -4
  29. package/dist/plugins/window.js +2 -6
  30. package/dist/server/index.d.ts +11 -0
  31. package/dist/server/index.js +977 -641
  32. package/dist/server/modules/menu/index.js +32 -41
  33. package/dist/server/modules/order/index.d.ts +8 -0
  34. package/dist/server/modules/order/index.js +253 -219
  35. package/dist/server/modules/products/index.js +24 -42
  36. package/dist/server/modules/quotation/index.js +29 -38
  37. package/dist/server/modules/resource/index.js +3 -4
  38. package/dist/server/modules/schedule/index.js +27 -35
  39. package/dist/server/utils/product.js +0 -1
  40. package/dist/server/utils/small-ticket.d.ts +9 -1
  41. package/dist/server/utils/small-ticket.js +117 -43
  42. package/dist/solution/BaseSales/index.d.ts +7 -0
  43. package/dist/solution/BaseSales/index.js +350 -215
  44. package/dist/solution/BaseSales/types.d.ts +2 -0
  45. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  46. package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +7 -1
  49. package/dist/solution/BaseSales/utils.js +6 -3
  50. package/dist/solution/BookingByStep/index.d.ts +2 -2
  51. package/dist/solution/BookingByStep/index.js +7 -59
  52. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  53. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  54. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  55. package/dist/solution/BookingTicket/index.d.ts +14 -19
  56. package/dist/solution/BookingTicket/index.js +553 -433
  57. package/dist/solution/BookingTicket/utils/addProductDecision.js +3 -1
  58. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  59. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  60. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  61. package/dist/solution/BuyTickets/index.js +9 -12
  62. package/dist/solution/Checkout/index.js +177 -252
  63. package/dist/solution/Checkout/utils/index.js +4 -16
  64. package/dist/solution/RegisterAndLogin/index.js +30 -76
  65. package/dist/solution/Sales/index.d.ts +20 -4
  66. package/dist/solution/Sales/index.js +348 -75
  67. package/dist/solution/Sales/types.d.ts +10 -0
  68. package/dist/solution/ScanOrder/index.js +50 -60
  69. package/dist/solution/ScanOrder/types.d.ts +2 -0
  70. package/dist/solution/ScanOrder/utils.js +6 -3
  71. package/dist/solution/ShopDiscount/index.js +2 -7
  72. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  73. package/dist/solution/UnifiedBookingSales/index.js +495 -422
  74. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
  75. package/dist/solution/VenueBooking/index.js +45 -55
  76. package/dist/utils/task.js +15 -18
  77. package/dist/utils/watch.js +0 -1
  78. package/lib/apis/picoding.js +2 -0
  79. package/lib/core/index.js +131 -131
  80. package/lib/effects/index.js +46 -57
  81. package/lib/index.js +82 -49
  82. package/lib/model/index.js +14 -21
  83. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  84. package/lib/model/strategy/adapter/dataVariant/evaluator.js +209 -315
  85. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  86. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  87. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  88. package/lib/model/strategy/adapter/index.js +100 -64
  89. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  90. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  91. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  92. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  93. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  94. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  95. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  96. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  97. package/lib/model/strategy/adapter/promotion/index.js +1 -51
  98. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  99. package/lib/model/strategy/adapter/type.js +4 -16
  100. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  101. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  102. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  103. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  104. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  105. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  106. package/lib/model/strategy/engine.js +270 -168
  107. package/lib/model/strategy/index.js +49 -34
  108. package/lib/model/strategy/strategy-example.js +243 -239
  109. package/lib/model/strategy/type.js +100 -40
  110. package/lib/modules/Account/index.js +39 -53
  111. package/lib/modules/Account/types.js +20 -33
  112. package/lib/modules/AccountList/index.js +116 -154
  113. package/lib/modules/AccountList/types.js +30 -31
  114. package/lib/modules/AccountList/utils.js +18 -30
  115. package/lib/modules/BaseModule.js +23 -42
  116. package/lib/modules/BookingContext/index.js +158 -136
  117. package/lib/modules/BookingContext/types.js +46 -32
  118. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  119. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  120. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  121. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  122. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  123. package/lib/modules/BookingContext/utils/index.js +124 -41
  124. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  125. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  126. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  127. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  128. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  129. package/lib/modules/BookingContext/utils/resources.js +209 -167
  130. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  131. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  132. package/lib/modules/Cart/index.js +170 -124
  133. package/lib/modules/Cart/types.js +46 -51
  134. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  135. package/lib/modules/Cart/utils/cartDate.js +56 -61
  136. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  137. package/lib/modules/Cart/utils/cartNote.js +27 -32
  138. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  139. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  140. package/lib/modules/Cart/utils/cartResource.js +70 -78
  141. package/lib/modules/Cart/utils/changePrice.js +22 -50
  142. package/lib/modules/Cart/utils/index.js +106 -48
  143. package/lib/modules/Customer/constants.js +13 -34
  144. package/lib/modules/Customer/index.js +235 -172
  145. package/lib/modules/Customer/types.js +38 -35
  146. package/lib/modules/Date/index.js +116 -115
  147. package/lib/modules/Date/types.js +16 -28
  148. package/lib/modules/Date/utils.js +174 -123
  149. package/lib/modules/Discount/index.js +133 -143
  150. package/lib/modules/Discount/types.js +9 -31
  151. package/lib/modules/Guests/index.js +30 -56
  152. package/lib/modules/Guests/types.js +23 -33
  153. package/lib/modules/Holder/index.js +209 -189
  154. package/lib/modules/Holder/types.js +4 -16
  155. package/lib/modules/Holder/utils.js +20 -49
  156. package/lib/modules/OpenData/index.d.ts +5 -2
  157. package/lib/modules/OpenData/index.js +119 -78
  158. package/lib/modules/OpenData/types.d.ts +42 -0
  159. package/lib/modules/OpenData/types.js +12 -16
  160. package/lib/modules/OpenData/utils.d.ts +15 -1
  161. package/lib/modules/OpenData/utils.js +129 -78
  162. package/lib/modules/Order/index.d.ts +4 -2
  163. package/lib/modules/Order/index.js +1843 -2251
  164. package/lib/modules/Order/payment-utils.js +77 -120
  165. package/lib/modules/Order/types.d.ts +8 -1
  166. package/lib/modules/Order/types.js +88 -35
  167. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  168. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  169. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  170. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  171. package/lib/modules/Order/utils/virtualSettlement.js +120 -171
  172. package/lib/modules/Order/utils.js +834 -668
  173. package/lib/modules/Payment/cash.js +20 -33
  174. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  175. package/lib/modules/Payment/eftpos.js +16 -30
  176. package/lib/modules/Payment/index.js +532 -399
  177. package/lib/modules/Payment/mx51.js +1 -0
  178. package/lib/modules/Payment/types.js +230 -108
  179. package/lib/modules/Payment/utils.js +52 -51
  180. package/lib/modules/Payment/walletpass.js +485 -660
  181. package/lib/modules/Product/index.js +51 -46
  182. package/lib/modules/Product/types.d.ts +2 -0
  183. package/lib/modules/Product/types.js +4 -16
  184. package/lib/modules/Product/utils.js +32 -33
  185. package/lib/modules/ProductList/index.js +141 -161
  186. package/lib/modules/ProductList/types.js +9 -31
  187. package/lib/modules/Quotation/index.js +66 -100
  188. package/lib/modules/Quotation/types.js +4 -16
  189. package/lib/modules/Resource/index.js +27 -59
  190. package/lib/modules/Resource/types.js +22 -32
  191. package/lib/modules/Resource/utils.js +30 -38
  192. package/lib/modules/ResourcePlanner/index.js +25 -23
  193. package/lib/modules/ResourcePlanner/localClock.js +54 -119
  194. package/lib/modules/ResourcePlanner/planner.js +591 -772
  195. package/lib/modules/ResourcePlanner/types.js +10 -29
  196. package/lib/modules/Rules/index.js +1224 -963
  197. package/lib/modules/Rules/types.js +17 -40
  198. package/lib/modules/SalesSummary/index.js +80 -89
  199. package/lib/modules/SalesSummary/types.js +4 -16
  200. package/lib/modules/SalesSummary/utils.js +359 -442
  201. package/lib/modules/ScanOrderLogger/index.js +59 -79
  202. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  203. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  204. package/lib/modules/ScanOrderLogger/types.js +4 -16
  205. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  206. package/lib/modules/Schedule/index.js +100 -114
  207. package/lib/modules/Schedule/type.js +4 -16
  208. package/lib/modules/Schedule/types.js +4 -16
  209. package/lib/modules/Schedule/utils.js +433 -291
  210. package/lib/modules/Step/index.js +40 -52
  211. package/lib/modules/Step/tyeps.js +4 -16
  212. package/lib/modules/Summary/index.js +66 -71
  213. package/lib/modules/Summary/types.js +4 -16
  214. package/lib/modules/Summary/utils.js +773 -418
  215. package/lib/modules/SurchargeList/index.js +46 -60
  216. package/lib/modules/SurchargeList/types.js +4 -16
  217. package/lib/modules/index.js +245 -63
  218. package/lib/plugins/app.js +4 -16
  219. package/lib/plugins/index.js +36 -25
  220. package/lib/plugins/request.js +137 -126
  221. package/lib/plugins/shopStore.js +4 -16
  222. package/lib/plugins/user.js +4 -16
  223. package/lib/plugins/window.js +171 -179
  224. package/lib/server/index.d.ts +11 -0
  225. package/lib/server/index.js +3432 -2757
  226. package/lib/server/modules/floor-plan/index.js +102 -123
  227. package/lib/server/modules/floor-plan/types.js +15 -30
  228. package/lib/server/modules/index.js +106 -68
  229. package/lib/server/modules/menu/index.js +146 -122
  230. package/lib/server/modules/menu/types.js +18 -31
  231. package/lib/server/modules/order/index.d.ts +8 -0
  232. package/lib/server/modules/order/index.js +781 -956
  233. package/lib/server/modules/order/types.js +122 -33
  234. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  235. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  236. package/lib/server/modules/payment/index.js +59 -83
  237. package/lib/server/modules/payment/types.js +4 -16
  238. package/lib/server/modules/products/index.js +575 -459
  239. package/lib/server/modules/products/types.js +44 -34
  240. package/lib/server/modules/quotation/index.js +137 -172
  241. package/lib/server/modules/quotation/types.js +21 -31
  242. package/lib/server/modules/resource/index.js +213 -184
  243. package/lib/server/modules/resource/types.js +42 -33
  244. package/lib/server/modules/schedule/index.js +135 -123
  245. package/lib/server/modules/schedule/types.js +14 -21
  246. package/lib/server/modules/schedule/utils.js +334 -163
  247. package/lib/server/types.js +4 -16
  248. package/lib/server/utils/index.js +25 -23
  249. package/lib/server/utils/product.js +196 -139
  250. package/lib/server/utils/schedule.js +34 -41
  251. package/lib/server/utils/small-ticket.d.ts +9 -1
  252. package/lib/server/utils/small-ticket.js +565 -470
  253. package/lib/server/utils/time.js +40 -49
  254. package/lib/solution/BaseSales/index.d.ts +7 -0
  255. package/lib/solution/BaseSales/index.js +1385 -1503
  256. package/lib/solution/BaseSales/types.d.ts +2 -0
  257. package/lib/solution/BaseSales/types.js +42 -38
  258. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  259. package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
  260. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  261. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  262. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  263. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +138 -180
  264. package/lib/solution/BaseSales/utils.js +161 -143
  265. package/lib/solution/BookingByStep/index.d.ts +2 -2
  266. package/lib/solution/BookingByStep/index.js +1527 -1340
  267. package/lib/solution/BookingByStep/types.js +40 -99
  268. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  269. package/lib/solution/BookingByStep/utils/products.js +42 -52
  270. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  271. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  272. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  273. package/lib/solution/BookingTicket/index.d.ts +14 -19
  274. package/lib/solution/BookingTicket/index.js +663 -526
  275. package/lib/solution/BookingTicket/types.js +99 -77
  276. package/lib/solution/BookingTicket/utils/addProductDecision.js +229 -190
  277. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  278. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  279. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  280. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  281. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  282. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  283. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  284. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  285. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  286. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  287. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  288. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  289. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  290. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  291. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  292. package/lib/solution/BuyTickets/index.js +67 -70
  293. package/lib/solution/BuyTickets/types.js +22 -38
  294. package/lib/solution/Checkout/index.js +1451 -1158
  295. package/lib/solution/Checkout/types.js +91 -61
  296. package/lib/solution/Checkout/utils/index.js +228 -156
  297. package/lib/solution/PlaceOrder/index.js +55 -0
  298. package/lib/solution/RegisterAndLogin/config.js +493 -460
  299. package/lib/solution/RegisterAndLogin/index.js +633 -630
  300. package/lib/solution/RegisterAndLogin/types.js +189 -76
  301. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  302. package/lib/solution/Sales/index.d.ts +20 -4
  303. package/lib/solution/Sales/index.js +502 -330
  304. package/lib/solution/Sales/types.d.ts +10 -0
  305. package/lib/solution/Sales/types.js +27 -33
  306. package/lib/solution/ScanOrder/index.js +822 -852
  307. package/lib/solution/ScanOrder/types.d.ts +2 -0
  308. package/lib/solution/ScanOrder/types.js +33 -34
  309. package/lib/solution/ScanOrder/utils.js +412 -374
  310. package/lib/solution/ShopDiscount/index.js +226 -232
  311. package/lib/solution/ShopDiscount/types.js +15 -37
  312. package/lib/solution/ShopDiscount/utils.js +300 -172
  313. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  314. package/lib/solution/UnifiedBookingSales/index.js +1087 -1222
  315. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
  316. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
  317. package/lib/solution/UnifiedBookingSales/types.js +10 -32
  318. package/lib/solution/VenueBooking/index.js +811 -879
  319. package/lib/solution/VenueBooking/types.js +19 -39
  320. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  321. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  322. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  323. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  324. package/lib/solution/VenueBooking/utils.js +130 -67
  325. package/lib/solution/index.js +124 -41
  326. package/lib/store/createStore.js +32 -29
  327. package/lib/types/index.js +4 -16
  328. package/lib/utils/payment-number.js +26 -46
  329. package/lib/utils/task.js +36 -36
  330. package/lib/utils/watch.js +81 -47
  331. package/package.json +2 -1
@@ -1,119 +1,92 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
28
2
 
29
- // src/server/utils/small-ticket.ts
30
- var small_ticket_exports = {};
31
- __export(small_ticket_exports, {
32
- buildSmallTicketData: () => buildSmallTicketData,
33
- hasSmallTicketData: () => hasSmallTicketData
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
34
5
  });
35
- module.exports = __toCommonJS(small_ticket_exports);
36
- var import_dayjs = __toESM(require("dayjs"));
37
- var import_decimal = __toESM(require("decimal.js"));
38
- var DEFAULT_LOCALES = ["en", "zh_CN"];
39
- var LABELS = {
6
+ exports.buildSmallTicketData = buildSmallTicketData;
7
+ exports.hasSmallTicketData = hasSmallTicketData;
8
+ var _dayjs = _interopRequireDefault(require("dayjs"));
9
+ var _decimal = _interopRequireDefault(require("decimal.js"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const DEFAULT_LOCALES = ['en', 'zh_CN'];
12
+ const LABELS = {
40
13
  en: {
41
- contactName: "Contact name",
42
- contactMobile: "Contact Mobile",
43
- email: "email",
44
- dineIn: "Dine-in",
45
- takeAway: "Take away",
46
- delivery: "Delivery",
47
- pickUp: "Pick-up",
48
- shopService: "Dine-in",
49
- pickUpTime: "Pick-up time",
50
- asap: "ASAP",
51
- cash: "Cash",
52
- eftpos: "Eftpos",
53
- wallet: "Wallet",
54
- giftCard: "Gift card",
55
- remainingAmount: "Remaining amount",
56
- redeemPoints: "Redeem points",
57
- remainingPoints: "Remaining points",
58
- table: "Table",
59
- orderDiscount: "Order discount",
60
- manualDiscount: "Manual discount",
61
- payProcessingFee: "Pay processing fee",
62
- rounding: "Rounding",
63
- gross: "Gross",
64
- tare: "Tare"
14
+ contactName: 'Contact name',
15
+ contactMobile: 'Contact Mobile',
16
+ email: 'email',
17
+ dineIn: 'Dine-in',
18
+ takeAway: 'Take away',
19
+ delivery: 'Delivery',
20
+ pickUp: 'Pick-up',
21
+ shopService: 'Dine-in',
22
+ pickUpTime: 'Pick-up time',
23
+ asap: 'ASAP',
24
+ cash: 'Cash',
25
+ eftpos: 'Eftpos',
26
+ wallet: 'Wallet',
27
+ giftCard: 'Gift card',
28
+ remainingAmount: 'Remaining amount',
29
+ redeemPoints: 'Redeem points',
30
+ remainingPoints: 'Remaining points',
31
+ table: 'Table',
32
+ orderDiscount: 'Order discount',
33
+ manualDiscount: 'Manual discount',
34
+ payProcessingFee: 'Pay processing fee',
35
+ rounding: 'Rounding',
36
+ gross: 'Gross',
37
+ tare: 'Tare'
65
38
  },
66
39
  zh_CN: {
67
- contactName: "联系人姓名",
68
- contactMobile: "联系电话",
69
- email: "邮箱",
70
- dineIn: "堂食",
71
- takeAway: "外带",
72
- delivery: "配送",
73
- pickUp: "自提",
74
- shopService: "堂食",
75
- pickUpTime: "取餐时间",
76
- asap: "尽快",
77
- cash: "现金支付",
78
- eftpos: "刷卡支付",
79
- wallet: "钱包支付",
80
- giftCard: "礼品卡",
81
- remainingAmount: "剩余金额",
82
- redeemPoints: "本次使用积分",
83
- remainingPoints: "剩余积分",
84
- table: "桌台",
85
- orderDiscount: "整单折扣",
86
- manualDiscount: "手动折扣",
87
- payProcessingFee: "支付手续费",
88
- rounding: "抹零",
89
- gross: "重量",
90
- tare: "去皮"
40
+ contactName: '联系人姓名',
41
+ contactMobile: '联系电话',
42
+ email: '邮箱',
43
+ dineIn: '堂食',
44
+ takeAway: '外带',
45
+ delivery: '配送',
46
+ pickUp: '自提',
47
+ shopService: '堂食',
48
+ pickUpTime: '取餐时间',
49
+ asap: '尽快',
50
+ cash: '现金支付',
51
+ eftpos: '刷卡支付',
52
+ wallet: '钱包支付',
53
+ giftCard: '礼品卡',
54
+ remainingAmount: '剩余金额',
55
+ redeemPoints: '本次使用积分',
56
+ remainingPoints: '剩余积分',
57
+ table: '桌台',
58
+ orderDiscount: '整单折扣',
59
+ manualDiscount: '手动折扣',
60
+ payProcessingFee: '支付手续费',
61
+ rounding: '抹零',
62
+ gross: '重量',
63
+ tare: '去皮'
91
64
  },
92
65
  zh_HK: {
93
- contactName: "聯絡人姓名",
94
- contactMobile: "聯絡電話",
95
- email: "電郵",
96
- dineIn: "堂食",
97
- takeAway: "外帶",
98
- delivery: "配送",
99
- pickUp: "自取",
100
- shopService: "堂食",
101
- pickUpTime: "取餐時間",
102
- asap: "盡快",
103
- cash: "現金支付",
104
- eftpos: "刷卡支付",
105
- wallet: "錢包支付",
106
- giftCard: "禮品卡",
107
- remainingAmount: "剩餘金額",
108
- redeemPoints: "本次使用積分",
109
- remainingPoints: "剩餘積分",
110
- table: "桌台",
111
- orderDiscount: "整單折扣",
112
- manualDiscount: "手動折扣",
113
- payProcessingFee: "支付手續費",
114
- rounding: "抹零",
115
- gross: "重量",
116
- tare: "去皮"
66
+ contactName: '聯絡人姓名',
67
+ contactMobile: '聯絡電話',
68
+ email: '電郵',
69
+ dineIn: '堂食',
70
+ takeAway: '外帶',
71
+ delivery: '配送',
72
+ pickUp: '自取',
73
+ shopService: '堂食',
74
+ pickUpTime: '取餐時間',
75
+ asap: '盡快',
76
+ cash: '現金支付',
77
+ eftpos: '刷卡支付',
78
+ wallet: '錢包支付',
79
+ giftCard: '禮品卡',
80
+ remainingAmount: '剩餘金額',
81
+ redeemPoints: '本次使用積分',
82
+ remainingPoints: '剩餘積分',
83
+ table: '桌台',
84
+ orderDiscount: '整單折扣',
85
+ manualDiscount: '手動折扣',
86
+ payProcessingFee: '支付手續費',
87
+ rounding: '抹零',
88
+ gross: '重量',
89
+ tare: '去皮'
117
90
  }
118
91
  };
119
92
  function buildSmallTicketData(params) {
@@ -122,27 +95,57 @@ function buildSmallTicketData(params) {
122
95
  const locales = resolveLocales(shopInfo, params.locales);
123
96
  const productMap = params.productMap || {};
124
97
  return locales.reduce((data, locale) => {
125
- data[locale] = buildLocaleData({ order, shopInfo, locale, productMap });
98
+ data[locale] = buildLocaleData({
99
+ order,
100
+ shopInfo,
101
+ locale,
102
+ productMap
103
+ });
126
104
  return data;
127
105
  }, {});
128
106
  }
129
107
  function hasSmallTicketData(value) {
130
- return !!value && typeof value === "object" && Object.keys(value).length > 0;
108
+ return !!value && typeof value === 'object' && Object.keys(value).length > 0;
131
109
  }
132
110
  function buildLocaleData(params) {
133
- const { order, shopInfo, locale, productMap } = params;
111
+ const {
112
+ order,
113
+ shopInfo,
114
+ locale,
115
+ productMap
116
+ } = params;
134
117
  const products = buildProducts(order, locale, productMap);
135
118
  const summary = getSummary(order);
136
119
  const currencySymbol = getCurrencySymbol(order, shopInfo);
137
120
  return {
138
- base_data: buildBaseData({ order, shopInfo, locale }),
121
+ base_data: buildBaseData({
122
+ order,
123
+ shopInfo,
124
+ locale
125
+ }),
139
126
  products,
140
- fees: buildFees({ order, shopInfo, locale, products, summary, currencySymbol }),
127
+ fees: buildFees({
128
+ order,
129
+ shopInfo,
130
+ locale,
131
+ products,
132
+ summary,
133
+ currencySymbol
134
+ }),
141
135
  customer: buildCustomer(order, locale),
142
136
  appointment: buildAppointment(order, locale),
143
137
  // delivery: buildDelivery(order, locale),
144
138
  resources: buildResources(order, locale),
145
- payment_data: buildPaymentData({ order, locale, currencySymbol }),
139
+ payment_data: buildPaymentData({
140
+ order,
141
+ locale,
142
+ currencySymbol
143
+ }),
144
+ wallets: buildWallets({
145
+ order,
146
+ locale,
147
+ currencySymbol
148
+ }),
146
149
  tickets: Array.isArray(order.tickets) ? order.tickets : [],
147
150
  source_shop: [],
148
151
  refund_data: [],
@@ -150,11 +153,12 @@ function buildLocaleData(params) {
150
153
  };
151
154
  }
152
155
  function buildBaseData(params) {
153
- var _a;
154
- const { order, shopInfo, locale } = params;
155
- const orderNumber = stringify(
156
- order.buzzer || order.shop_full_order_number
157
- );
156
+ const {
157
+ order,
158
+ shopInfo,
159
+ locale
160
+ } = params;
161
+ const orderNumber = stringify(order.buzzer || order.shop_full_order_number);
158
162
  return {
159
163
  shop_name: stringify(shopInfo.name || order.shop_name),
160
164
  note: stringify(order.note),
@@ -162,21 +166,28 @@ function buildBaseData(params) {
162
166
  order_number: orderNumber,
163
167
  shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
164
168
  shop_phone: stringify(shopInfo.phone || order.shop_phone),
165
- shop_address: stringify(shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
169
+ shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
166
170
  original_payment_status: stringify(order.payment_status),
167
171
  is_repeat: 0,
168
- buzzer: stringify(order.buzzer || order.pickup_number || ((_a = order.metadata) == null ? void 0 : _a.buzzer)),
172
+ buzzer: stringify(order.buzzer || order.pickup_number || order.metadata?.buzzer),
169
173
  order_no: orderNumber,
170
- order_time: formatDateTime(order.created_at || order.sales_time || /* @__PURE__ */ new Date(), locale)
174
+ order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale),
175
+ ...(isPresentId(order.updated_at) ? {
176
+ updated_at: formatDateTime(order.updated_at, locale)
177
+ } : {})
171
178
  };
172
179
  }
173
180
  function buildProducts(order, locale, productMap) {
174
181
  const products = Array.isArray(order.products) ? order.products : [];
175
- return products.map((product) => {
182
+ return products.map(product => {
176
183
  const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
177
184
  const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
178
185
  const sellingPrice = product.selling_price ?? product.payment_price ?? product.price ?? originalPrice;
179
- const productTitle = resolveProductTitle({ product, productMap, locale });
186
+ const productTitle = resolveProductTitle({
187
+ product,
188
+ productMap,
189
+ locale
190
+ });
180
191
  const parentProduct = resolveProductFromMap(product.product_id ?? product.id, productMap);
181
192
  const currencySymbol = getCurrencySymbol(order, null);
182
193
  const options = normalizeProductOptions({
@@ -192,7 +203,13 @@ function buildProducts(order, locale, productMap) {
192
203
  currencySymbol,
193
204
  parentProduct
194
205
  });
195
- const resolvedVariant = resolveProductVariantText({ product, parentProduct, locale });
206
+ const resolvedVariant = resolveProductVariantText({
207
+ product,
208
+ parentProduct,
209
+ locale
210
+ });
211
+ const productUid = firstPresentValue(product.metadata?.unique_identification_number, product.unique_identification_number);
212
+ const bookingUid = firstPresentValue(product.booking_uid, product.metadata?.booking_uid);
196
213
  const extensionList = buildProductExtensionList({
197
214
  product,
198
215
  locale,
@@ -205,20 +222,39 @@ function buildProducts(order, locale, productMap) {
205
222
  product_quantity: quantity,
206
223
  selling_price: formatMoney(sellingPrice, currencySymbol),
207
224
  original_price: formatMoney(originalPrice, currencySymbol),
208
- total_original_price: formatMoney(new import_decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
225
+ total_original_price: formatMoney(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
209
226
  extension_list: extensionList,
210
- ...options.length ? { options } : {},
211
- ...resolvedVariant ? { variant: resolvedVariant } : {},
212
- ...Array.isArray(product.combinations) ? { combinations: product.combinations } : combinations.length ? { combinations } : {}
227
+ ...(isPresentId(productUid) ? {
228
+ product_uid: productUid
229
+ } : {}),
230
+ ...(isPresentId(bookingUid) ? {
231
+ booking_uid: bookingUid
232
+ } : {}),
233
+ ...(options.length ? {
234
+ options
235
+ } : {}),
236
+ ...(resolvedVariant ? {
237
+ variant: resolvedVariant
238
+ } : {}),
239
+ ...(Array.isArray(product.combinations) ? {
240
+ combinations: product.combinations
241
+ } : combinations.length ? {
242
+ combinations
243
+ } : {})
213
244
  };
214
245
  });
215
246
  }
216
247
  function normalizeProductDiscounts(params) {
217
- const { product, locale, currencySymbol, quantity } = params;
218
- return normalizeArray(product.discount_list).map((discount) => {
248
+ const {
249
+ product,
250
+ locale,
251
+ currencySymbol,
252
+ quantity
253
+ } = params;
254
+ return normalizeArray(product.discount_list).map(discount => {
219
255
  const title = resolveDiscountTitleWithPercent(discount, locale);
220
256
  const amount = discount.amount ?? discount.value ?? discount.discount_amount;
221
- const formattedAmount = formatNegativeMoney(new import_decimal.default(toMoneyNumber(amount)).mul(quantity), currencySymbol);
257
+ const formattedAmount = formatNegativeMoney(new _decimal.default(toMoneyNumber(amount)).mul(quantity), currencySymbol);
222
258
  return {
223
259
  item: title,
224
260
  value: formattedAmount
@@ -226,35 +262,54 @@ function normalizeProductDiscounts(params) {
226
262
  });
227
263
  }
228
264
  function buildProductExtensionList(params) {
229
- const { product, locale, currencySymbol, quantity, originalPrice } = params;
230
- const discountList = normalizeProductDiscounts({ product, locale, currencySymbol, quantity });
231
- const extensionList = [
232
- ...buildProductOpenWeightRows({ product, locale, currencySymbol }),
233
- ...quantity > 1 ? [{
234
- item: buildProductQuantityPriceText({ quantity, currencySymbol, price: originalPrice }),
235
- value: ""
236
- }] : []
237
- ];
265
+ const {
266
+ product,
267
+ locale,
268
+ currencySymbol,
269
+ quantity,
270
+ originalPrice
271
+ } = params;
272
+ const discountList = normalizeProductDiscounts({
273
+ product,
274
+ locale,
275
+ currencySymbol,
276
+ quantity
277
+ });
278
+ const extensionList = [...buildProductOpenWeightRows({
279
+ product,
280
+ locale,
281
+ currencySymbol
282
+ }), ...(quantity > 1 ? [{
283
+ item: buildProductQuantityPriceText({
284
+ quantity,
285
+ currencySymbol,
286
+ price: originalPrice
287
+ }),
288
+ value: ''
289
+ }] : [])];
238
290
  const productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list);
239
291
  return [...productExtensionList, ...discountList];
240
292
  }
241
293
  function buildProductOpenWeightRows(params) {
242
- const { product, locale, currencySymbol } = params;
294
+ const {
295
+ product,
296
+ locale,
297
+ currencySymbol
298
+ } = params;
243
299
  const productSku = product.product_sku || {};
244
- if (productSku.open_sold_weight != 1)
245
- return [];
246
- const unit = productSku.unit ?? "";
247
- const manualFlag = productSku.weight_source === "manual" ? "(M) " : "";
300
+ if (productSku.open_sold_weight != 1) return [];
301
+ const unit = productSku.unit ?? '';
302
+ const manualFlag = productSku.weight_source === 'manual' ? '(M) ' : '';
248
303
  const hasTare = toNumber(productSku.tare_weight, 0) > 0;
249
304
  const rows = [];
250
305
  if (hasTare) {
251
306
  rows.push({
252
- item: `${manualFlag}${label(locale, "gross")}: ${productSku.weight ?? 0}${unit}`,
253
- value: ""
307
+ item: `${manualFlag}${label(locale, 'gross')}: ${productSku.weight ?? 0}${unit}`,
308
+ value: ''
254
309
  });
255
310
  rows.push({
256
- item: `${label(locale, "tare")}: ${productSku.tare_weight}${unit}`,
257
- value: ""
311
+ item: `${label(locale, 'tare')}: ${productSku.tare_weight}${unit}`,
312
+ value: ''
258
313
  });
259
314
  }
260
315
  const netWeight = productSku.net_weight ?? 0;
@@ -262,71 +317,87 @@ function buildProductOpenWeightRows(params) {
262
317
  const netItem = `${netWeight} ${unit} NET @ ${currencySymbol}${unitPrice}/${unit}`;
263
318
  rows.push({
264
319
  item: hasTare ? netItem : `${manualFlag}${netItem}`,
265
- value: ""
320
+ value: ''
266
321
  });
267
322
  return rows;
268
323
  }
269
324
  function buildProductQuantityPriceText(params) {
270
- const { quantity, currencySymbol, price } = params;
325
+ const {
326
+ quantity,
327
+ currencySymbol,
328
+ price
329
+ } = params;
271
330
  return `${quantity} @ ${currencySymbol}${stringify(price)} EACH`;
272
331
  }
273
332
  function resolveDiscountTitleWithPercent(discount, locale) {
274
- var _a, _b;
275
333
  const title = resolveDiscountTitle(discount, locale);
276
- const percentRaw = (_a = discount.discount) == null ? void 0 : _a.percent;
277
- const cardType = ((_b = discount.discount) == null ? void 0 : _b.discount_card_type) ?? "percent";
278
- const percent = percentRaw !== void 0 && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
279
- if (percentRaw === void 0 || percentRaw === null)
280
- return title;
281
- if (cardType !== "percent")
282
- return title;
283
- if (Number.isNaN(percent))
284
- return title;
334
+ const percentRaw = discount.discount?.percent;
335
+ const cardType = discount.discount?.discount_card_type ?? 'percent';
336
+ const percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
337
+ if (percentRaw === undefined || percentRaw === null) return title;
338
+ if (cardType !== 'percent') return title;
339
+ if (Number.isNaN(percent)) return title;
285
340
  return `${title} (${percent}%)`;
286
341
  }
287
342
  function resolveDiscountTitle(discount, locale) {
288
- var _a, _b, _c;
289
- const title = getLocalizedValue(
290
- ((_a = discount.discount) == null ? void 0 : _a.name) ?? ((_b = discount.discount) == null ? void 0 : _b.title) ?? ((_c = discount.discount) == null ? void 0 : _c.message) ?? discount.name ?? discount.title ?? discount.message,
291
- locale
292
- );
293
- if (title)
294
- return title;
295
- if (discount.type === "product")
296
- return label(locale, "manualDiscount");
297
- return "";
343
+ const title = getLocalizedValue(discount.discount?.name ?? discount.discount?.title ?? discount.discount?.message ?? discount.name ?? discount.title ?? discount.message, locale);
344
+ if (title) return title;
345
+ if (discount.type === 'product') return label(locale, 'manualDiscount');
346
+ return '';
298
347
  }
299
348
  function resolveProductTitle(params) {
300
- const { product, productMap, locale } = params;
349
+ const {
350
+ product,
351
+ productMap,
352
+ locale
353
+ } = params;
301
354
  const ownTitle = getProductTitleSource(product, locale);
302
- if (ownTitle)
303
- return ownTitle;
355
+ if (ownTitle) return ownTitle;
304
356
  const productId = product.product_id ?? product.id;
305
357
  const fallbackProduct = resolveProductFromMap(productId, productMap);
306
- if (!fallbackProduct)
307
- return ownTitle || "";
358
+ if (!fallbackProduct) return ownTitle || '';
308
359
  return getProductTitleSource(fallbackProduct, locale);
309
360
  }
310
361
  function normalizeProductOptions(params) {
311
- var _a;
312
- const { product, locale, currencySymbol, parentProduct } = params;
313
- const rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_a = product.product_sku) == null ? void 0 : _a.option) ? product.product_sku.option : [];
314
- return rawOptions.map((option) => {
362
+ const {
363
+ product,
364
+ locale,
365
+ currencySymbol,
366
+ parentProduct
367
+ } = params;
368
+ const rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray(product.product_sku?.option) ? product.product_sku.option : [];
369
+ return rawOptions.map(option => {
315
370
  const price = option.original_price ?? option.add_price ?? option.price;
316
371
  const value = option.value ?? option.option ?? option.item;
317
- const name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({ option, parentProduct, locale });
372
+ const name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
373
+ option,
374
+ parentProduct,
375
+ locale
376
+ });
318
377
  return {
319
378
  name,
320
- ...option.num !== void 0 || option.quantity !== void 0 ? { num: toNumber(option.num ?? option.quantity, 1) } : {},
321
- ...price !== void 0 && price !== null && price !== "" ? { price: formatMoney(price, currencySymbol) } : {},
322
- ...value !== void 0 && value !== null && value !== "" ? { value: getLocalizedValue(value, locale) } : {}
379
+ ...(option.num !== undefined || option.quantity !== undefined ? {
380
+ num: toNumber(option.num ?? option.quantity, 1)
381
+ } : {}),
382
+ ...(price !== undefined && price !== null && price !== '' ? {
383
+ price: formatMoney(price, currencySymbol)
384
+ } : {}),
385
+ ...(value !== undefined && value !== null && value !== '' ? {
386
+ value: getLocalizedValue(value, locale)
387
+ } : {})
323
388
  };
324
389
  });
325
390
  }
326
391
  function normalizeProductCombinations(params) {
327
- const { product, productMap, locale, currencySymbol, parentProduct } = params;
392
+ const {
393
+ product,
394
+ productMap,
395
+ locale,
396
+ currencySymbol,
397
+ parentProduct
398
+ } = params;
328
399
  const bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
329
- return bundles.map((bundle) => {
400
+ return bundles.map(bundle => {
330
401
  const combinationsOptions = normalizeProductOptions({
331
402
  product: {},
332
403
  locale,
@@ -350,44 +421,47 @@ function normalizeProductCombinations(params) {
350
421
  });
351
422
  }
352
423
  function resolveBundleProductTitle(params) {
353
- const { bundle, productMap, locale, parentProduct } = params;
424
+ const {
425
+ bundle,
426
+ productMap,
427
+ locale,
428
+ parentProduct
429
+ } = params;
354
430
  const ownTitle = getProductTitleSource(bundle, locale);
355
- if (ownTitle)
356
- return ownTitle;
357
- const parentBundleItem = resolveBundleItemFromParentProduct({ bundle, parentProduct });
358
- const parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : "";
359
- if (parentBundleTitle)
360
- return parentBundleTitle;
431
+ if (ownTitle) return ownTitle;
432
+ const parentBundleItem = resolveBundleItemFromParentProduct({
433
+ bundle,
434
+ parentProduct
435
+ });
436
+ const parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
437
+ if (parentBundleTitle) return parentBundleTitle;
361
438
  const productId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? bundle.id;
362
439
  const fallbackProduct = resolveProductFromMap(productId, productMap);
363
- if (!fallbackProduct)
364
- return "";
440
+ if (!fallbackProduct) return '';
365
441
  return getProductTitleSource(fallbackProduct, locale);
366
442
  }
367
443
  function resolveProductFromMap(productId, productMap) {
368
- if (productId === void 0 || productId === null || productId === "")
369
- return null;
444
+ if (productId === undefined || productId === null || productId === '') return null;
370
445
  return productMap[productId] || productMap[String(productId)] || null;
371
446
  }
372
447
  function resolveProductVariantText(params) {
373
- const { product, parentProduct, locale } = params;
374
- if (product.variant)
375
- return getLocalizedValue(product.variant, locale);
376
- if (!parentProduct)
377
- return "";
448
+ const {
449
+ product,
450
+ parentProduct,
451
+ locale
452
+ } = params;
453
+ if (product.variant) return getLocalizedValue(product.variant, locale);
454
+ if (!parentProduct) return '';
378
455
  const productVariantId = product.product_variant_id ?? product.variant_id;
379
- if (!isNonZeroId(productVariantId))
380
- return "";
381
- const matchedVariant = normalizeArray(parentProduct.variant).find((variant) => isSameId(variant.id, productVariantId));
382
- if (!matchedVariant)
383
- return "";
456
+ if (!isNonZeroId(productVariantId)) return '';
457
+ const matchedVariant = normalizeArray(parentProduct.variant).find(variant => isSameId(variant.id, productVariantId));
458
+ if (!matchedVariant) return '';
384
459
  const resolvedFromSkuKey = resolveVariantTextFromSkuKey({
385
460
  skuKey: matchedVariant.sku_key,
386
461
  parentProduct,
387
462
  locale
388
463
  });
389
- if (resolvedFromSkuKey)
390
- return resolvedFromSkuKey;
464
+ if (resolvedFromSkuKey) return resolvedFromSkuKey;
391
465
  return resolveVariantTextFromNameMap({
392
466
  nameMap: matchedVariant.name || matchedVariant.title,
393
467
  parentProduct,
@@ -396,86 +470,71 @@ function resolveProductVariantText(params) {
396
470
  }
397
471
  function resolveVariantTextFromSkuKey(params) {
398
472
  const skuKey = stringify(params.skuKey);
399
- if (!skuKey)
400
- return "";
401
- return skuKey.split("_").map((item) => {
402
- const [groupPositionId, itemPositionId] = item.split(":");
473
+ if (!skuKey) return '';
474
+ return skuKey.split('_').map(item => {
475
+ const [groupPositionId, itemPositionId] = item.split(':');
403
476
  return resolveVariantTextItem({
404
477
  parentProduct: params.parentProduct,
405
478
  groupPositionId,
406
479
  itemPositionId,
407
480
  locale: params.locale
408
481
  });
409
- }).filter(Boolean).join(",");
482
+ }).filter(Boolean).join(',');
410
483
  }
411
484
  function resolveVariantTextFromNameMap(params) {
412
- if (!params.nameMap || typeof params.nameMap !== "object")
413
- return "";
485
+ if (!params.nameMap || typeof params.nameMap !== 'object') return '';
414
486
  return Object.entries(params.nameMap).map(([groupPositionId, value]) => {
415
487
  const group = resolveVariantGroup(params.parentProduct, groupPositionId);
416
- if (!group)
417
- return "";
488
+ if (!group) return '';
418
489
  const groupName = getLocalizedValue(group.name, params.locale);
419
490
  const itemName = getLocalizedValue(value, params.locale);
420
- if (!groupName || !itemName)
421
- return "";
491
+ if (!groupName || !itemName) return '';
422
492
  return `${groupName}:${itemName}`;
423
- }).filter(Boolean).join(",");
493
+ }).filter(Boolean).join(',');
424
494
  }
425
495
  function resolveVariantTextItem(params) {
426
496
  const group = resolveVariantGroup(params.parentProduct, params.groupPositionId);
427
497
  const item = resolveVariantItem(group, params.itemPositionId);
428
- if (!group || !item)
429
- return "";
498
+ if (!group || !item) return '';
430
499
  const groupName = getLocalizedValue(group.name, params.locale);
431
500
  const itemName = getLocalizedValue(item.name, params.locale);
432
- if (!groupName || !itemName)
433
- return "";
501
+ if (!groupName || !itemName) return '';
434
502
  return `${groupName}:${itemName}`;
435
503
  }
436
504
  function resolveVariantGroup(parentProduct, groupPositionId) {
437
- return normalizeArray(parentProduct.variant_group).find(
438
- (group) => isSameId(group.position_id, groupPositionId) || isSameId(group.id, groupPositionId)
439
- ) || null;
505
+ return normalizeArray(parentProduct.variant_group).find(group => isSameId(group.position_id, groupPositionId) || isSameId(group.id, groupPositionId)) || null;
440
506
  }
441
507
  function resolveVariantItem(group, itemPositionId) {
442
- if (!group)
443
- return null;
444
- return normalizeArray(group.variant_item).find(
445
- (item) => isSameId(item.position_id, itemPositionId) || isSameId(item.id, itemPositionId)
446
- ) || null;
508
+ if (!group) return null;
509
+ return normalizeArray(group.variant_item).find(item => isSameId(item.position_id, itemPositionId) || isSameId(item.id, itemPositionId)) || null;
447
510
  }
448
511
  function getProductTitleSource(source, locale) {
449
- if (!source || typeof source !== "object")
450
- return "";
512
+ if (!source || typeof source !== 'object') return '';
451
513
  return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
452
514
  }
453
515
  function resolveTitleValue(value, locale) {
454
- if (value === void 0 || value === null)
455
- return "";
456
- if (typeof value !== "object")
457
- return stringify(value);
458
- const dashedLocale = locale.replace("_", "-");
459
- const underscoredLocale = locale.replace("-", "_");
460
- return stringify(
461
- value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? ""
462
- );
516
+ if (value === undefined || value === null) return '';
517
+ if (typeof value !== 'object') return stringify(value);
518
+ const dashedLocale = locale.replace('_', '-');
519
+ const underscoredLocale = locale.replace('-', '_');
520
+ return stringify(value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? '');
463
521
  }
464
522
  function resolveOptionTitleFromParentProduct(params) {
465
- const { option, parentProduct, locale } = params;
466
- if (!parentProduct)
467
- return "";
523
+ const {
524
+ option,
525
+ parentProduct,
526
+ locale
527
+ } = params;
528
+ if (!parentProduct) return '';
468
529
  const optionItems = flattenOptionItems(parentProduct);
469
- const matchedOption = optionItems.find((item) => isOptionItemMatch(option, item));
530
+ const matchedOption = optionItems.find(item => isOptionItemMatch(option, item));
470
531
  return getProductTitleSource(matchedOption, locale);
471
532
  }
472
533
  function flattenOptionItems(parentProduct) {
473
534
  const optionGroups = Array.isArray(parentProduct.option_group) ? parentProduct.option_group : [];
474
- return optionGroups.flatMap((group) => {
475
- const items = normalizeArray(
476
- group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item
477
- );
478
- return items.map((item) => ({
535
+ return optionGroups.flatMap(group => {
536
+ const items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
537
+ return items.map(item => ({
479
538
  ...item,
480
539
  option_group_id: item.option_group_id ?? group.id ?? group.option_group_id
481
540
  }));
@@ -484,8 +543,7 @@ function flattenOptionItems(parentProduct) {
484
543
  function isOptionItemMatch(option, item) {
485
544
  const optionItemId = option.option_group_item_id ?? option.product_option_item_id ?? option.id;
486
545
  const itemId = item.option_group_item_id ?? item.product_option_item_id ?? item.id;
487
- if (!isSameId(optionItemId, itemId))
488
- return false;
546
+ if (!isSameId(optionItemId, itemId)) return false;
489
547
  const optionGroupId = option.option_group_id ?? option.group_id;
490
548
  const itemGroupId = item.option_group_id ?? item.group_id;
491
549
  if (isPresentId(optionGroupId) && isPresentId(itemGroupId)) {
@@ -494,86 +552,86 @@ function isOptionItemMatch(option, item) {
494
552
  return true;
495
553
  }
496
554
  function resolveBundleItemFromParentProduct(params) {
497
- const { bundle, parentProduct } = params;
498
- if (!parentProduct)
499
- return null;
555
+ const {
556
+ bundle,
557
+ parentProduct
558
+ } = params;
559
+ if (!parentProduct) return null;
500
560
  const bundleItems = flattenBundleItems(parentProduct);
501
561
  const bundleVariantId = bundle.bundle_variant_id ?? bundle.variant_id ?? bundle.product_variant_id;
502
562
  if (isNonZeroId(bundleVariantId)) {
503
- const matchedByVariant = bundleItems.find(
504
- (item) => isSameId(item.bundle_variant_id ?? item.variant_id ?? item.product_variant_id, bundleVariantId)
505
- );
506
- if (matchedByVariant)
507
- return matchedByVariant;
563
+ const matchedByVariant = bundleItems.find(item => isSameId(item.bundle_variant_id ?? item.variant_id ?? item.product_variant_id, bundleVariantId));
564
+ if (matchedByVariant) return matchedByVariant;
508
565
  }
509
566
  const bundleId = bundle.bundle_id ?? bundle.id;
510
567
  if (isPresentId(bundleId)) {
511
- const matchedByBundleId = bundleItems.find((item) => isSameId(item.id ?? item.bundle_id, bundleId));
512
- if (matchedByBundleId)
513
- return matchedByBundleId;
568
+ const matchedByBundleId = bundleItems.find(item => isSameId(item.id ?? item.bundle_id, bundleId));
569
+ if (matchedByBundleId) return matchedByBundleId;
514
570
  }
515
571
  const bundleGroupId = bundle.bundle_group_id ?? bundle.group_id;
516
572
  const bundleProductId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id;
517
573
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
518
- const matchedByGroupAndProduct = bundleItems.find(
519
- (item) => isSameId(item.group_id ?? item.bundle_group_id, bundleGroupId) && isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId)
520
- );
521
- if (matchedByGroupAndProduct)
522
- return matchedByGroupAndProduct;
574
+ const matchedByGroupAndProduct = bundleItems.find(item => isSameId(item.group_id ?? item.bundle_group_id, bundleGroupId) && isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId));
575
+ if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
523
576
  }
524
577
  if (isPresentId(bundleProductId)) {
525
- return bundleItems.find(
526
- (item) => isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId)
527
- ) || null;
578
+ return bundleItems.find(item => isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId)) || null;
528
579
  }
529
580
  return null;
530
581
  }
531
582
  function flattenBundleItems(parentProduct) {
532
583
  const bundleGroups = Array.isArray(parentProduct.bundle_group) ? parentProduct.bundle_group : [];
533
- return bundleGroups.flatMap((group) => {
584
+ return bundleGroups.flatMap(group => {
534
585
  const items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
535
- return items.map((item) => ({
586
+ return items.map(item => ({
536
587
  ...item,
537
588
  group_id: item.group_id ?? group.id ?? group.group_id
538
589
  }));
539
590
  });
540
591
  }
541
592
  function isNonZeroId(value) {
542
- return isPresentId(value) && String(value) !== "0";
593
+ return isPresentId(value) && String(value) !== '0';
543
594
  }
544
595
  function isPresentId(value) {
545
- return value !== void 0 && value !== null && value !== "";
596
+ return value !== undefined && value !== null && value !== '';
597
+ }
598
+ function firstPresentValue(...values) {
599
+ return values.find(value => isPresentId(value));
546
600
  }
547
601
  function isSameId(left, right) {
548
- if (!isPresentId(left) || !isPresentId(right))
549
- return false;
602
+ if (!isPresentId(left) || !isPresentId(right)) return false;
550
603
  return String(left) === String(right);
551
604
  }
552
605
  function buildOptionTitleSuffix(options) {
553
- const text = options.map((option) => {
606
+ const text = options.map(option => {
554
607
  const name = stringify(option.name).trim();
555
- if (!name)
556
- return "";
608
+ if (!name) return '';
557
609
  const quantity = option.num ?? 1;
558
610
  return `${name} x ${quantity}`;
559
- }).filter(Boolean).join(", ");
560
- return text ? `(${text})` : "";
611
+ }).filter(Boolean).join(', ');
612
+ return text ? `(${text})` : '';
561
613
  }
562
614
  function formatBundlePrice(bundle, currencySymbol) {
563
615
  const value = bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0;
564
- const amount = new import_decimal.default(toMoneyNumber(value));
565
- const isNegative = bundle.price_type === "markdown";
566
- if (isNegative)
567
- return `-${currencySymbol}${amount.abs().toFixed(2)}`;
616
+ const amount = new _decimal.default(toMoneyNumber(value));
617
+ // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
618
+ const isNegative = bundle.price_type === 'markdown';
619
+ if (isNegative) return `-${currencySymbol}${amount.abs().toFixed(2)}`;
568
620
  return formatMoney(amount, currencySymbol);
569
621
  }
570
622
  function buildFees(params) {
571
- const { order, shopInfo, locale, products, summary, currencySymbol } = params;
623
+ const {
624
+ order,
625
+ shopInfo,
626
+ locale,
627
+ products,
628
+ summary,
629
+ currencySymbol
630
+ } = params;
572
631
  const fees = [];
573
632
  for (const surcharge of normalizeArray(order.surcharges || summary.surcharges)) {
574
633
  const value = surcharge.amount ?? surcharge.value ?? surcharge.total_amount;
575
- if (!isNonZero(value))
576
- continue;
634
+ if (!isNonZero(value)) continue;
577
635
  fees.push({
578
636
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
579
637
  value: formatMoney(value, currencySymbol)
@@ -582,7 +640,7 @@ function buildFees(params) {
582
640
  const discountAmount = order.shop_discount ?? summary.discount_amount ?? order.discount_amount;
583
641
  if (isNonZero(discountAmount)) {
584
642
  fees.push({
585
- item: label(locale, "orderDiscount"),
643
+ item: label(locale, 'orderDiscount'),
586
644
  value: formatNegativeMoney(discountAmount, currencySymbol)
587
645
  });
588
646
  }
@@ -596,126 +654,207 @@ function buildFees(params) {
596
654
  const roundingAmount = summary.rounding_amount || order.rounding_amount;
597
655
  if (isNonZero(roundingAmount)) {
598
656
  fees.push({
599
- item: label(locale, "rounding"),
657
+ item: label(locale, 'rounding'),
600
658
  value: formatMoney(roundingAmount, currencySymbol)
601
659
  });
602
660
  }
603
661
  const payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
604
662
  if (isNonZero(payProcessingFee)) {
605
663
  fees.push({
606
- item: label(locale, "payProcessingFee"),
664
+ item: label(locale, 'payProcessingFee'),
607
665
  value: formatMoney(payProcessingFee, currencySymbol)
608
666
  });
609
667
  }
610
668
  const productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
611
- const productOriginalAmount = summary.product_original_amount ?? order.product_original_amount ?? productExpectAmount;
612
- const totalSavingsAmount = new import_decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
669
+ const productOriginalAmount = firstPresentValue(summary.product_original_amount, order.product_original_amount) ?? calculateProductOriginalAmount(order);
670
+ const totalSavingsAmount = new _decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
613
671
  return {
614
672
  fees,
615
673
  countFee: {
616
674
  total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
675
+ original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
617
676
  product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
618
677
  expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
619
- product_quantity: toNumber(
620
- summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0),
621
- 0
622
- ),
678
+ product_quantity: toNumber(summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0), 0),
623
679
  has_pay: formatMoney(calculateReceiptPaidAmount(order, summary), currencySymbol),
624
- payment_method: "",
680
+ payment_method: '',
625
681
  tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
626
682
  total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol),
627
- ...isNonZero(roundingAmount) ? { rounding_amount: formatMoney(roundingAmount, currencySymbol) } : {},
628
- ...isNonZero(totalSavingsAmount) ? { order_total_discount: formatMoney(totalSavingsAmount, currencySymbol) } : {},
629
- ...isNonZero(payProcessingFee) ? { pay_processing_fee: formatMoney(payProcessingFee, currencySymbol) } : {},
630
- ...isNonZero(taxFee) ? { tax_fee: formatMoney(taxFee, currencySymbol) } : {}
683
+ ...(isNonZero(roundingAmount) ? {
684
+ rounding_amount: formatMoney(roundingAmount, currencySymbol)
685
+ } : {}),
686
+ ...(isNonZero(totalSavingsAmount) ? {
687
+ order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
688
+ } : {}),
689
+ ...(isNonZero(payProcessingFee) ? {
690
+ pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
691
+ } : {}),
692
+ ...(isNonZero(taxFee) ? {
693
+ tax_fee: formatMoney(taxFee, currencySymbol)
694
+ } : {})
631
695
  }
632
696
  };
633
697
  }
698
+ function calculateProductOriginalAmount(order) {
699
+ return normalizeArray(order.products).reduce((total, product) => {
700
+ const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
701
+ const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
702
+ return total.plus(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity));
703
+ }, new _decimal.default(0));
704
+ }
634
705
  function buildCustomer(order, locale) {
635
- var _a, _b, _c, _d;
636
- return [
637
- { item: label(locale, "contactName"), value: normalizeCustomerDisplayValue(order.customer_name || ((_a = order.customer) == null ? void 0 : _a.name) || ((_b = order.customer) == null ? void 0 : _b.display_name)) },
638
- { item: label(locale, "contactMobile"), value: stringify(order.phone || ((_c = order.customer) == null ? void 0 : _c.phone)) },
639
- { item: label(locale, "email"), value: stringify(order.email || ((_d = order.customer) == null ? void 0 : _d.email)) }
640
- ];
706
+ return [{
707
+ item: label(locale, 'contactName'),
708
+ value: normalizeCustomerDisplayValue(order.customer_name || order.customer?.name || order.customer?.display_name)
709
+ }, {
710
+ item: label(locale, 'contactMobile'),
711
+ value: stringify(order.phone || order.customer?.phone)
712
+ }, {
713
+ item: label(locale, 'email'),
714
+ value: stringify(order.email || order.customer?.email)
715
+ }];
641
716
  }
642
717
  function normalizeCustomerDisplayValue(value) {
643
718
  const text = stringify(value).trim();
644
- if (!text)
645
- return "Walk-In";
646
- if (text.toLowerCase() === "select a customer")
647
- return "Walk-In";
719
+ if (!text) return 'Walk-In';
720
+ if (text.toLowerCase() === 'select a customer') return 'Walk-In';
648
721
  return text;
649
722
  }
723
+ function buildDelivery(order, locale) {
724
+ const serviceType = stringify(order.metadata?.service_type || order.service_type || order.delivery_type);
725
+ if (!serviceType) return [];
726
+ const serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
727
+ const items = [{
728
+ item: '',
729
+ value: label(locale, serviceTypeLabelKey),
730
+ size: 2,
731
+ align: 'left'
732
+ }];
733
+ if (serviceType === 'shop_server' || serviceType === 'shop_service') {
734
+ items.push({
735
+ item: label(locale, 'pickUpTime'),
736
+ value: label(locale, 'asap')
737
+ });
738
+ }
739
+ return items;
740
+ }
650
741
  function buildAppointment(order, locale) {
651
- var _a, _b, _c, _d;
652
- const tableName = order.table_name || ((_a = order.metadata) == null ? void 0 : _a.table_name) || ((_c = (_b = order.metadata) == null ? void 0 : _b.table) == null ? void 0 : _c.name) || ((_d = order.form_data) == null ? void 0 : _d.table_name);
653
- if (!tableName)
654
- return [];
655
- return [
656
- {
657
- item: label(locale, "table"),
658
- value: getLocalizedValue(tableName, locale)
659
- }
660
- ];
742
+ const bookings = normalizeArray(order.bookings);
743
+ if (bookings.length) {
744
+ return bookings.map(booking => {
745
+ const snapshot = {
746
+ ...booking
747
+ };
748
+ delete snapshot.product_uid;
749
+ delete snapshot.booking_uid;
750
+ const productUid = firstPresentValue(booking.product_uid, booking.metadata?.product_uid);
751
+ const bookingUid = firstPresentValue(booking.metadata?.unique_identification_number, booking.booking_uid);
752
+ return {
753
+ ...snapshot,
754
+ ...(isPresentId(productUid) ? {
755
+ product_uid: productUid
756
+ } : {}),
757
+ ...(isPresentId(bookingUid) ? {
758
+ booking_uid: bookingUid
759
+ } : {})
760
+ };
761
+ });
762
+ }
763
+ const tableName = order.table_name || order.metadata?.table_name || order.metadata?.table?.name || order.form_data?.table_name;
764
+ if (!tableName) return [];
765
+ return [{
766
+ item: label(locale, 'table'),
767
+ value: getLocalizedValue(tableName, locale)
768
+ }];
661
769
  }
662
770
  function buildResources(order, locale) {
663
- return normalizeArray(order.resources || order.resource_list).map((resource) => ({
664
- id: resource.id || resource.resource_id || "",
665
- code: "",
771
+ return normalizeArray(order.resources || order.resource_list).map(resource => ({
772
+ id: resource.id || resource.resource_id || '',
773
+ code: '',
666
774
  title: getLocalizedValue(resource.title || resource.name, locale),
667
- form_title: getLocalizedValue(resource.form_title || resource.type || "", locale)
775
+ form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
668
776
  }));
669
777
  }
670
778
  function buildPaymentData(params) {
671
779
  const payments = normalizeArray(params.order.payments);
672
- return payments.filter((payment) => isPrintablePayment(payment)).map((payment) => {
673
- var _a;
674
- const items = [
675
- {
676
- item: paymentMethodName(payment, params.locale),
677
- value: formatMoney(payment.amount ?? payment.origin_amount, params.currencySymbol)
678
- }
679
- ];
680
- const fundRecord = getFundRecord(payment);
681
- if (fundRecord) {
682
- items.push(...buildFundRecordPaymentItems({ payment, fundRecord, locale: params.locale, currencySymbol: params.currencySymbol }));
683
- } else {
684
- const remainingAmount = payment.remaining_amount ?? payment.balance ?? ((_a = payment.metadata) == null ? void 0 : _a.remaining_amount);
685
- if (remainingAmount !== void 0 && remainingAmount !== null) {
686
- items.push({
687
- item: label(params.locale, "remainingAmount"),
688
- value: formatMoney(remainingAmount, params.currencySymbol)
689
- });
690
- }
780
+ return payments.filter(payment => isPrintablePayment(payment)).map(payment => buildPaymentItems({
781
+ payment,
782
+ locale: params.locale,
783
+ currencySymbol: params.currencySymbol,
784
+ includeFundRecordBalance: false
785
+ }));
786
+ }
787
+ function buildWallets(params) {
788
+ return normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment)).map(payment => buildPaymentItems({
789
+ payment,
790
+ locale: params.locale,
791
+ currencySymbol: params.currencySymbol,
792
+ includeFundRecordBalance: true
793
+ }));
794
+ }
795
+ function buildPaymentItems(params) {
796
+ const {
797
+ payment,
798
+ locale,
799
+ currencySymbol,
800
+ includeFundRecordBalance
801
+ } = params;
802
+ const items = [{
803
+ item: paymentMethodName(payment, locale),
804
+ value: formatMoney(payment.amount ?? payment.origin_amount, currencySymbol)
805
+ }];
806
+ const fundRecord = getFundRecord(payment);
807
+ if (fundRecord) {
808
+ items.push(...buildFundRecordPaymentItems({
809
+ payment,
810
+ fundRecord,
811
+ locale,
812
+ currencySymbol,
813
+ includeBalance: includeFundRecordBalance
814
+ }));
815
+ } else {
816
+ const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
817
+ if (remainingAmount !== undefined && remainingAmount !== null) {
818
+ items.push({
819
+ item: label(locale, 'remainingAmount'),
820
+ value: formatMoney(remainingAmount, currencySymbol)
821
+ });
691
822
  }
692
- items.push({
693
- item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || /* @__PURE__ */ new Date(), params.locale),
694
- value: ""
695
- });
696
- return items;
823
+ }
824
+ items.push({
825
+ item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
826
+ value: ''
697
827
  });
828
+ return items;
698
829
  }
699
830
  function buildFundRecordPaymentItems(params) {
700
- const { payment, fundRecord, locale, currencySymbol } = params;
831
+ const {
832
+ payment,
833
+ fundRecord,
834
+ locale,
835
+ currencySymbol,
836
+ includeBalance
837
+ } = params;
701
838
  const items = [];
702
839
  const usingBeforeValue = fundRecord.using_before_value;
703
840
  const usingAfterValue = fundRecord.using_after_value;
704
- if (isPointCardPayment(payment) && usingBeforeValue !== void 0 && usingAfterValue !== void 0) {
705
- const usedPoints = new import_decimal.default(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
841
+ if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
842
+ const usedPoints = new _decimal.default(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
706
843
  items.push({
707
- item: label(locale, "redeemPoints"),
844
+ item: label(locale, 'redeemPoints'),
708
845
  value: trimDecimal(usedPoints)
709
846
  });
710
- items.push({
711
- item: label(locale, "remainingPoints"),
712
- value: trimDecimal(new import_decimal.default(toMoneyNumber(usingAfterValue)))
713
- });
847
+ if (includeBalance) {
848
+ items.push({
849
+ item: label(locale, 'remainingPoints'),
850
+ value: trimDecimal(new _decimal.default(toMoneyNumber(usingAfterValue)))
851
+ });
852
+ }
714
853
  return items;
715
854
  }
716
- if (usingAfterValue !== void 0 && usingAfterValue !== null) {
855
+ if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
717
856
  items.push({
718
- item: label(locale, "remainingAmount"),
857
+ item: label(locale, 'remainingAmount'),
719
858
  value: formatMoney(usingAfterValue, currencySymbol)
720
859
  });
721
860
  }
@@ -723,169 +862,131 @@ function buildFundRecordPaymentItems(params) {
723
862
  }
724
863
  function getFundRecord(payment) {
725
864
  const fundRecord = payment.fund_record;
726
- if (!fundRecord || typeof fundRecord !== "object" || Array.isArray(fundRecord))
727
- return null;
728
- if (!fundRecord.voucher_id && !fundRecord.code)
729
- return null;
865
+ if (!fundRecord || typeof fundRecord !== 'object' || Array.isArray(fundRecord)) return null;
866
+ if (!fundRecord.voucher_id && !fundRecord.code) return null;
730
867
  return fundRecord;
731
868
  }
732
869
  function isPointCardPayment(payment) {
733
- var _a;
734
870
  const code = stringify(payment.code || payment.payment_method).toUpperCase();
735
- const type = stringify(payment.type || ((_a = payment.fund_record) == null ? void 0 : _a.tag)).toLowerCase();
736
- return code === "POINTCARD" || type === "point_card";
871
+ const type = stringify(payment.type || payment.fund_record?.tag).toLowerCase();
872
+ return code === 'POINTCARD' || type === 'point_card';
737
873
  }
738
874
  function maskMachineCode(code) {
739
875
  const text = stringify(code);
740
- if (text.length <= 6)
741
- return text;
876
+ if (text.length <= 6) return text;
742
877
  return `${text.slice(0, 2)}**${text.slice(-4)}`;
743
878
  }
744
879
  function trimDecimal(value) {
745
- return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, "");
880
+ return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
746
881
  }
747
882
  function getFundRecordPaymentName(payment, locale) {
748
883
  const fundRecord = getFundRecord(payment);
749
- if (!fundRecord)
750
- return "";
884
+ if (!fundRecord) return '';
751
885
  const name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
752
886
  const code = maskMachineCode(fundRecord.code);
753
- if (!name && !code)
754
- return "";
755
- if (!code)
756
- return name;
757
- const fallbackName = getLocalizedValue(
758
- payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code,
759
- locale
760
- );
887
+ if (!name && !code) return '';
888
+ if (!code) return name;
889
+ const fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
761
890
  return `${name || fallbackName}(${code})`;
762
891
  }
763
892
  function appendMachineCodeToName(name, payment) {
764
893
  const fundRecord = getFundRecord(payment);
765
- if (!(fundRecord == null ? void 0 : fundRecord.code))
766
- return name;
894
+ if (!fundRecord?.code) return name;
767
895
  return `${name}(${maskMachineCode(fundRecord.code)})`;
768
896
  }
769
897
  function paymentMethodName(payment, locale) {
770
898
  const fundRecordName = getFundRecordPaymentName(payment, locale);
771
- if (fundRecordName)
772
- return fundRecordName;
899
+ if (fundRecordName) return fundRecordName;
773
900
  const raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
774
- if (raw)
775
- return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
901
+ if (raw) return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
776
902
  const code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
777
- if (code.includes("cash"))
778
- return label(locale, "cash");
779
- if (code.includes("eftpos") || code.includes("card"))
780
- return label(locale, "eftpos");
781
- if (code.includes("wallet"))
782
- return label(locale, "wallet");
783
- if (code.includes("gift"))
784
- return label(locale, "giftCard");
903
+ if (code.includes('cash')) return label(locale, 'cash');
904
+ if (code.includes('eftpos') || code.includes('card')) return label(locale, 'eftpos');
905
+ if (code.includes('wallet')) return label(locale, 'wallet');
906
+ if (code.includes('gift')) return label(locale, 'giftCard');
785
907
  return stringify(payment.code || payment.type || payment.payment_method || payment.method);
786
908
  }
787
909
  function getSummary(order) {
788
- return order.summary && typeof order.summary === "object" ? order.summary : order;
910
+ return order.summary && typeof order.summary === 'object' ? order.summary : order;
789
911
  }
790
912
  function getCurrencySymbol(order, shopInfo) {
791
- return stringify(order.currency_symbol || (shopInfo == null ? void 0 : shopInfo.currency_symbol) || order.shop_symbol || "$") || "$";
913
+ return stringify(order.currency_symbol || shopInfo?.currency_symbol || order.shop_symbol || '$') || '$';
792
914
  }
793
915
  function resolveLocales(shopInfo, locales) {
794
- const preferred = [
795
- ...locales || [],
796
- shopInfo.primary_locale,
797
- ...DEFAULT_LOCALES
798
- ].filter(Boolean);
916
+ const preferred = [...(locales || []), shopInfo.primary_locale, ...DEFAULT_LOCALES].filter(Boolean);
799
917
  return Array.from(new Set(preferred.map(normalizeLocaleKey)));
800
918
  }
801
919
  function normalizeLocaleKey(locale) {
802
- return locale.replace("-", "_");
920
+ return locale.replace('-', '_');
803
921
  }
804
922
  function label(locale, key) {
805
- var _a;
806
- return ((_a = LABELS[locale]) == null ? void 0 : _a[key]) || LABELS.en[key] || key;
923
+ return LABELS[locale]?.[key] || LABELS.en[key] || key;
807
924
  }
808
925
  function getLocalizedValue(value, locale) {
809
- if (value === void 0 || value === null)
810
- return "";
811
- if (typeof value !== "object")
812
- return stringify(value);
813
- const dashedLocale = locale.replace("_", "-");
814
- const underscoredLocale = locale.replace("-", "_");
815
- return stringify(
816
- value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? value.default ?? value.en ?? ""
817
- );
926
+ if (value === undefined || value === null) return '';
927
+ if (typeof value !== 'object') return stringify(value);
928
+ const dashedLocale = locale.replace('_', '-');
929
+ const underscoredLocale = locale.replace('-', '_');
930
+ return stringify(value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? value.default ?? value.en ?? '');
931
+ }
932
+ function serviceTypeToLabelKey(serviceType) {
933
+ const normalized = serviceType.toLowerCase();
934
+ if (normalized.includes('take')) return 'takeAway';
935
+ if (normalized.includes('delivery')) return 'delivery';
936
+ if (normalized.includes('pick')) return 'pickUp';
937
+ if (normalized.includes('shop')) return 'shopService';
938
+ return 'dineIn';
818
939
  }
819
940
  function buildShopAddress(shopInfo) {
820
- return [
821
- shopInfo.address_street,
822
- shopInfo.address_detail,
823
- shopInfo.city,
824
- shopInfo.province,
825
- shopInfo.country,
826
- shopInfo.zip
827
- ].filter(Boolean).join(", ");
941
+ return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
828
942
  }
829
943
  function formatDateTime(value, locale) {
830
- const date = (0, import_dayjs.default)(value);
831
- if (!date.isValid())
832
- return stringify(value);
833
- if (locale === "en")
834
- return date.format("HH:mm:ss DD/MM/YYYY");
835
- return date.format("YYYY/MM/DD HH:mm:ss");
944
+ const date = (0, _dayjs.default)(value);
945
+ if (!date.isValid()) return stringify(value);
946
+ if (locale === 'en') return date.format('HH:mm:ss DD/MM/YYYY');
947
+ return date.format('YYYY/MM/DD HH:mm:ss');
836
948
  }
837
949
  function formatMoney(value, currencySymbol) {
838
- if (value instanceof import_decimal.default)
839
- return `${currencySymbol}${value.toFixed(2)}`;
840
- if (typeof value === "string" && value.trim().startsWith(currencySymbol))
841
- return value;
842
- const amount = new import_decimal.default(toMoneyNumber(value));
950
+ if (value instanceof _decimal.default) return `${currencySymbol}${value.toFixed(2)}`;
951
+ if (typeof value === 'string' && value.trim().startsWith(currencySymbol)) return value;
952
+ const amount = new _decimal.default(toMoneyNumber(value));
843
953
  return `${currencySymbol}${amount.toFixed(2)}`;
844
954
  }
845
955
  function formatNegativeMoney(value, currencySymbol) {
846
- const amount = new import_decimal.default(toMoneyNumber(value)).abs();
956
+ const amount = new _decimal.default(toMoneyNumber(value)).abs();
847
957
  return `-${currencySymbol}${amount.toFixed(2)}`;
848
958
  }
849
959
  function calculateReceiptPaidAmount(order, summary) {
850
960
  const paidAmount = sumPayments(order.payments);
851
- const payProcessingFee = new import_decimal.default(
852
- toMoneyNumber(summary.pay_service_charge_amount ?? order.pay_service_charge_amount)
853
- );
854
- if (payProcessingFee.lte(0))
855
- return paidAmount;
856
- const totalAmount = new import_decimal.default(toMoneyNumber(summary.total_amount ?? order.total_amount));
857
- if (totalAmount.gt(0) && paidAmount.gte(totalAmount))
858
- return paidAmount;
961
+ const payProcessingFee = new _decimal.default(toMoneyNumber(summary.pay_service_charge_amount ?? order.pay_service_charge_amount));
962
+ if (payProcessingFee.lte(0)) return paidAmount;
963
+ const totalAmount = new _decimal.default(toMoneyNumber(summary.total_amount ?? order.total_amount));
964
+ if (totalAmount.gt(0) && paidAmount.gte(totalAmount)) return paidAmount;
859
965
  const paidAmountWithFee = paidAmount.plus(payProcessingFee);
860
- if (totalAmount.gt(0) && paidAmountWithFee.gt(totalAmount))
861
- return totalAmount;
966
+ if (totalAmount.gt(0) && paidAmountWithFee.gt(totalAmount)) return totalAmount;
862
967
  return paidAmountWithFee;
863
968
  }
864
969
  function sumPayments(payments) {
865
- return normalizeArray(payments).filter((payment) => isPrintablePayment(payment)).reduce((sum, payment) => {
970
+ return normalizeArray(payments).filter(payment => isPrintablePayment(payment)).reduce((sum, payment) => {
866
971
  return sum.plus(toMoneyNumber(payment.amount ?? payment.origin_amount));
867
- }, new import_decimal.default(0));
972
+ }, new _decimal.default(0));
868
973
  }
869
974
  function isPrintablePayment(payment) {
870
975
  const status = stringify(payment.status).toLowerCase();
871
- if (!status)
872
- return true;
873
- return ["paid", "success", "succeeded", "completed"].includes(status);
976
+ if (!status) return true;
977
+ return ['paid', 'success', 'succeeded', 'completed'].includes(status);
874
978
  }
875
979
  function normalizeArray(value) {
876
980
  return Array.isArray(value) ? value : [];
877
981
  }
878
982
  function isNonZero(value) {
879
- return !new import_decimal.default(toMoneyNumber(value)).isZero();
983
+ return !new _decimal.default(toMoneyNumber(value)).isZero();
880
984
  }
881
985
  function toMoneyNumber(value) {
882
- if (value instanceof import_decimal.default)
883
- return value.toString();
884
- if (typeof value === "number")
885
- return Number.isFinite(value) ? value : 0;
886
- if (typeof value !== "string")
887
- return 0;
888
- const normalized = value.replace(/[^\d.-]/g, "");
986
+ if (value instanceof _decimal.default) return value.toString();
987
+ if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
988
+ if (typeof value !== 'string') return 0;
989
+ const normalized = value.replace(/[^\d.-]/g, '');
889
990
  return normalized || 0;
890
991
  }
891
992
  function toNumber(value, fallback) {
@@ -893,12 +994,6 @@ function toNumber(value, fallback) {
893
994
  return Number.isFinite(numberValue) ? numberValue : fallback;
894
995
  }
895
996
  function stringify(value) {
896
- if (value === void 0 || value === null)
897
- return "";
997
+ if (value === undefined || value === null) return '';
898
998
  return String(value);
899
- }
900
- // Annotate the CommonJS export names for ESM import in node:
901
- 0 && (module.exports = {
902
- buildSmallTicketData,
903
- hasSmallTicketData
904
- });
999
+ }