sme-pos-package 1.0.14 → 1.0.15

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 (314) hide show
  1. package/dist/index.d.mts +1 -1
  2. package/dist/index.mjs +1 -0
  3. package/package.json +4 -1
  4. package/dist/index.css.map +0 -1
  5. package/dist/index.mjs.map +0 -1
  6. package/dist/tailwind.preset.mjs.map +0 -1
  7. package/public/assets/images/bank-logos.png +0 -0
  8. package/public/assets/images/banner1.png +0 -0
  9. package/public/assets/images/banner2.png +0 -0
  10. package/public/assets/images/banner3.png +0 -0
  11. package/public/assets/images/banner4.png +0 -0
  12. package/public/assets/images/cashier.svg +0 -9
  13. package/public/assets/images/empty-cart.png +0 -0
  14. package/public/assets/images/empty-table-state.png +0 -0
  15. package/public/assets/images/layout-display/left-layout.png +0 -0
  16. package/public/assets/images/layout-display/right-layout.png +0 -0
  17. package/public/assets/images/modal-illustration.png +0 -0
  18. package/public/assets/images/order-empty-state.png +0 -0
  19. package/public/assets/images/order.png +0 -0
  20. package/public/assets/images/payment-success-label.png +0 -0
  21. package/public/assets/images/table-empty.png +0 -0
  22. package/public/assets/images/take-away.png +0 -0
  23. package/public/assets/lottie/loading.json +0 -1
  24. package/public/assets/lottie/soft_pos.json +0 -1
  25. package/public/assets/lottie/success.json +0 -1
  26. package/public/config.json +0 -27
  27. package/public/env.json +0 -17
  28. package/src/animations/success.json +0 -9730
  29. package/src/assets/icons/breadcrumbs-icon.tsx +0 -85
  30. package/src/assets/icons/cart-icon.tsx +0 -14
  31. package/src/assets/icons/common.tsx +0 -270
  32. package/src/assets/icons/customer-view-icon.tsx +0 -20
  33. package/src/assets/icons/dining-table.tsx +0 -34
  34. package/src/assets/icons/edit-line-icon.tsx +0 -18
  35. package/src/assets/icons/emenu-icon.tsx +0 -39
  36. package/src/assets/icons/file-close-line-icon.tsx +0 -18
  37. package/src/assets/icons/helper-icon.tsx +0 -84
  38. package/src/assets/icons/home-gear-line-icon.tsx +0 -18
  39. package/src/assets/icons/kanban-icon.tsx +0 -16
  40. package/src/assets/icons/loading-icon.tsx +0 -45
  41. package/src/assets/icons/logout-box-line-icon.tsx +0 -18
  42. package/src/assets/icons/order-icon.tsx +0 -92
  43. package/src/assets/icons/payment-icon.tsx +0 -429
  44. package/src/assets/icons/pincode.tsx +0 -196
  45. package/src/assets/icons/pos-connect-icon.tsx +0 -67
  46. package/src/assets/icons/pos-device-icon.tsx +0 -52
  47. package/src/assets/icons/pos-icon.tsx +0 -75
  48. package/src/assets/icons/printer-line-icon.tsx +0 -18
  49. package/src/assets/icons/star-icon.tsx +0 -174
  50. package/src/assets/icons/table-icon.tsx +0 -77
  51. package/src/assets/icons/user-add-line-icon.tsx +0 -33
  52. package/src/assets/icons/user-icon.tsx +0 -65
  53. package/src/components/common/button-action.tsx +0 -46
  54. package/src/components/common/button-icon.tsx +0 -23
  55. package/src/components/common/dropdown/index.tsx +0 -79
  56. package/src/components/common/empty-state.tsx +0 -60
  57. package/src/components/common/header/index.tsx +0 -89
  58. package/src/components/common/header/tabs.tsx +0 -119
  59. package/src/components/common/image.tsx +0 -20
  60. package/src/components/common/input/index.tsx +0 -55
  61. package/src/components/common/input/radio-group.tsx +0 -75
  62. package/src/components/common/input/text-area.tsx +0 -28
  63. package/src/components/common/modal/delete-confirm-modal-container.tsx +0 -65
  64. package/src/components/common/modal/index.ts +0 -2
  65. package/src/components/common/modal/modal-direction.tsx +0 -125
  66. package/src/components/common/modal/modal-header.tsx +0 -37
  67. package/src/components/common/modal/modal-wrapper.tsx +0 -56
  68. package/src/components/common/modal/modal-zoom.tsx +0 -61
  69. package/src/components/common/pagination.tsx +0 -95
  70. package/src/components/common/refresh-button.tsx +0 -28
  71. package/src/components/common/search-bar.tsx +0 -27
  72. package/src/components/common/search.tsx +0 -59
  73. package/src/components/common/skeleton.tsx +0 -7
  74. package/src/components/common/tabs-layout.tsx +0 -98
  75. package/src/components/common/use-check-session.tsx +0 -19
  76. package/src/components/customer-management/add-customer/add-customer-drawer.tsx +0 -286
  77. package/src/components/customer-management/add-customer/address-select.tsx +0 -51
  78. package/src/components/customer-management/choose-customer-drawer.tsx +0 -177
  79. package/src/components/customer-management/customer-info-drawer.tsx +0 -166
  80. package/src/components/customer-management/customer-no-data.tsx +0 -18
  81. package/src/components/emenu/emenu-qr-code.tsx +0 -59
  82. package/src/components/emenu/menu-link.tsx +0 -67
  83. package/src/components/index.ts +0 -8
  84. package/src/components/kanban-template/kitchen-template.tsx +0 -60
  85. package/src/components/kanban-template/pos-order-template.tsx +0 -77
  86. package/src/components/kanban-template/pos-template.tsx +0 -170
  87. package/src/components/kitchen-management/change-status-confirm-modal.tsx +0 -61
  88. package/src/components/kitchen-management/index.ts +0 -1
  89. package/src/components/kitchen-management/kitchen-order/index.tsx +0 -153
  90. package/src/components/kitchen-management/kitchen-order/line.tsx +0 -78
  91. package/src/components/kitchen-management/kitchen-order/state.tsx +0 -52
  92. package/src/components/kitchen-management/kitchen-status.tsx +0 -69
  93. package/src/components/kitchen-management/orders-kitchen-management.tsx +0 -113
  94. package/src/components/order-management/index.tsx +0 -128
  95. package/src/components/order-management/order-actions.tsx +0 -46
  96. package/src/components/order-management/order-detail/header.tsx +0 -37
  97. package/src/components/order-management/order-detail/index.ts +0 -3
  98. package/src/components/order-management/order-detail/information.tsx +0 -96
  99. package/src/components/order-management/order-detail/order-detail.tsx +0 -84
  100. package/src/components/order-management/order-detail/order-line.tsx +0 -56
  101. package/src/components/order-management/order-detail/summary.tsx +0 -221
  102. package/src/components/order-management/order-header.tsx +0 -113
  103. package/src/components/order-management/order-pagination.tsx +0 -49
  104. package/src/components/order-management/order-status.tsx +0 -58
  105. package/src/components/order-management/order-table.tsx +0 -179
  106. package/src/components/order-management/order-tabs.tsx +0 -48
  107. package/src/components/pos-management/add-product-from-barcode/index.tsx +0 -97
  108. package/src/components/pos-management/cart-content/action-line.tsx +0 -81
  109. package/src/components/pos-management/cart-content/cancel-order-line-modal.tsx +0 -41
  110. package/src/components/pos-management/cart-content/cart-item.tsx +0 -173
  111. package/src/components/pos-management/cart-content/cart-items.tsx +0 -130
  112. package/src/components/pos-management/cart-content/draft-orders/draft-order-line.tsx +0 -67
  113. package/src/components/pos-management/cart-content/draft-orders/index.tsx +0 -40
  114. package/src/components/pos-management/cart-content/edit-cart-modal.tsx +0 -11
  115. package/src/components/pos-management/cart-content/index.tsx +0 -260
  116. package/src/components/pos-management/cart-content/no-select-order.tsx +0 -26
  117. package/src/components/pos-management/cart-content/order-info/customer-info.tsx +0 -53
  118. package/src/components/pos-management/cart-content/order-info/index.tsx +0 -109
  119. package/src/components/pos-management/cart-content/order-total.tsx +0 -36
  120. package/src/components/pos-management/cart-content/orders-line.tsx +0 -72
  121. package/src/components/pos-management/menu-content/category-tab.tsx +0 -38
  122. package/src/components/pos-management/menu-content/create-order-modal.tsx +0 -65
  123. package/src/components/pos-management/menu-content/product-content.tsx +0 -93
  124. package/src/components/pos-management/menu-content/product-detail/info.tsx +0 -28
  125. package/src/components/pos-management/menu-content/product-detail/modal.tsx +0 -148
  126. package/src/components/pos-management/menu-content/product-detail/option.tsx +0 -87
  127. package/src/components/pos-management/menu-content/product-detail/quantity-control.tsx +0 -155
  128. package/src/components/pos-management/menu-content/product-detail/sale-keypad.tsx +0 -100
  129. package/src/components/pos-management/menu-content/product-item.tsx +0 -65
  130. package/src/components/pos-management/order-helper/cancel-order-confirm.tsx +0 -43
  131. package/src/components/pos-management/order-helper/history-call.tsx +0 -105
  132. package/src/components/pos-management/order-helper/order-helper-modal.tsx +0 -116
  133. package/src/components/pos-management/payment-content/bill/actions.tsx +0 -46
  134. package/src/components/pos-management/payment-content/bill/content.tsx +0 -207
  135. package/src/components/pos-management/payment-content/bill/index.tsx +0 -18
  136. package/src/components/pos-management/payment-content/card-payment/index.tsx +0 -124
  137. package/src/components/pos-management/payment-content/card-payment/pos-payment/pos-connect.tsx +0 -183
  138. package/src/components/pos-management/payment-content/card-payment/pos-payment/qr-connect.tsx +0 -185
  139. package/src/components/pos-management/payment-content/card-payment/waiting-for-payment-pos-modal.tsx +0 -37
  140. package/src/components/pos-management/payment-content/cash-payment/index.tsx +0 -216
  141. package/src/components/pos-management/payment-content/index.tsx +0 -70
  142. package/src/components/pos-management/payment-content/payment-info.tsx +0 -67
  143. package/src/components/pos-management/payment-content/payment-layout.tsx +0 -16
  144. package/src/components/pos-management/payment-content/payment-method-cards.tsx +0 -99
  145. package/src/components/pos-management/payment-content/qr-payment/index.tsx +0 -118
  146. package/src/components/pos-management/payment-content/qr-payment/qr_code.js +0 -29
  147. package/src/components/pos-management/payment-content/qr-payment/vietqr.js +0 -436
  148. package/src/components/pos-management/payment-content/session-close-modal.tsx +0 -35
  149. package/src/components/pos-management/payment-content/soft-pos-payment/index.tsx +0 -48
  150. package/src/components/pos-management/pos-helpers/back-confirm.tsx +0 -45
  151. package/src/components/pos-management/pos-helpers/index.tsx +0 -135
  152. package/src/components/pos-management/pos-helpers/layout-display-modal.tsx +0 -99
  153. package/src/components/pos-management/search.tsx +0 -48
  154. package/src/components/pos-management/table-content/filtered-tables.tsx +0 -59
  155. package/src/components/pos-management/table-content/floor-tabs.tsx +0 -65
  156. package/src/components/pos-management/table-content/index.tsx +0 -76
  157. package/src/components/pos-management/table-content/table-item.tsx +0 -127
  158. package/src/components/pos-management/table-content/tables.tsx +0 -96
  159. package/src/components/restaurant-management/add-floor-modal.tsx +0 -133
  160. package/src/components/restaurant-management/add-table-modal.tsx +0 -198
  161. package/src/components/restaurant-management/delete-floor-confirm-modal.tsx +0 -42
  162. package/src/components/restaurant-management/delete-table-confirm-modal.tsx +0 -51
  163. package/src/components/restaurant-management/header.tsx +0 -22
  164. package/src/components/restaurant-management/index.tsx +0 -54
  165. package/src/components/restaurant-management/left-side.tsx +0 -51
  166. package/src/components/restaurant-management/right-side.tsx +0 -179
  167. package/src/components/restaurant-management/table-empty.tsx +0 -43
  168. package/src/components/session-management/close-session-modal/actions.tsx +0 -45
  169. package/src/components/session-management/close-session-modal/close-session-confirm.tsx +0 -157
  170. package/src/components/session-management/close-session-modal/close-session-ticket.tsx +0 -218
  171. package/src/components/session-management/close-session-modal/container.tsx +0 -25
  172. package/src/components/session-management/close-session-modal/draft-orders-confirm.tsx +0 -53
  173. package/src/components/session-management/close-session-modal/draft-orders-summary.tsx +0 -82
  174. package/src/components/session-management/close-session-modal/draft-orders.tsx +0 -34
  175. package/src/components/session-management/close-session-modal/index.tsx +0 -35
  176. package/src/components/session-management/close-session-modal/order/index.ts +0 -1
  177. package/src/components/session-management/close-session-modal/order/order-line.tsx +0 -64
  178. package/src/components/session-management/close-session-modal/order/orders-in-draft.tsx +0 -31
  179. package/src/components/session-management/close-session-modal/session-summary.tsx +0 -165
  180. package/src/components/session-management/index.ts +0 -1
  181. package/src/components/session-management/open-shift/index.tsx +0 -172
  182. package/src/components/table-management/index.tsx +0 -0
  183. package/src/constants/api/index.ts +0 -1
  184. package/src/constants/headers.constant.tsx +0 -24
  185. package/src/constants/index.ts +0 -1
  186. package/src/constants/language.store.ts +0 -21
  187. package/src/constants/methods.constant.ts +0 -10
  188. package/src/constants/order-state.ts +0 -8
  189. package/src/constants/payment-color.constant.ts +0 -26
  190. package/src/constants/query.constant.ts +0 -14
  191. package/src/constants/routes.constants.ts +0 -23
  192. package/src/constants/template-name.constant.ts +0 -9
  193. package/src/hooks/bill/use-get-bill-information.ts +0 -49
  194. package/src/hooks/bill/use-print-bill.tsx +0 -0
  195. package/src/hooks/common/load-env-config.ts +0 -98
  196. package/src/hooks/common/use-back.ts +0 -13
  197. package/src/hooks/common/use-broadcast.ts +0 -22
  198. package/src/hooks/common/use-click-outside.ts +0 -58
  199. package/src/hooks/common/use-get-base64-photo.ts +0 -71
  200. package/src/hooks/common/use-get-query.ts +0 -25
  201. package/src/hooks/common/use-pos.ts +0 -21
  202. package/src/hooks/common/use-query-params.ts +0 -89
  203. package/src/hooks/common/use-speech.ts +0 -36
  204. package/src/hooks/customer/use-customer-provider.ts +0 -247
  205. package/src/hooks/floor/use-floor-provider.ts +0 -172
  206. package/src/hooks/kitchen/use-kitchen-provider.ts +0 -80
  207. package/src/hooks/order/use-get-point-reward.ts +0 -50
  208. package/src/hooks/order/use-loop-fetch-order.ts +0 -30
  209. package/src/hooks/order/use-order-items.ts +0 -61
  210. package/src/hooks/order/use-orders.ts +0 -76
  211. package/src/hooks/payment/use-payment-provider.ts +0 -221
  212. package/src/hooks/product/use-product-provider.ts +0 -87
  213. package/src/hooks/session/use-check-session.tsx +0 -19
  214. package/src/hooks/session/use-session-provider.ts +0 -79
  215. package/src/hooks/table/use-pos-table-provider.ts +0 -193
  216. package/src/index.css +0 -5
  217. package/src/index.ts +0 -13
  218. package/src/layouts/common.tsx +0 -15
  219. package/src/layouts/index.ts +0 -4
  220. package/src/layouts/pos-layout.tsx +0 -33
  221. package/src/layouts/pos-order-layout.tsx +0 -43
  222. package/src/layouts/sale-layout.tsx +0 -25
  223. package/src/locales/en.json +0 -394
  224. package/src/locales/vi.json +0 -400
  225. package/src/pages/index.ts +0 -4
  226. package/src/pages/login/index.tsx +0 -128
  227. package/src/pages/pincode/index.tsx +0 -198
  228. package/src/pages/pos/kitchen-management/layout.tsx +0 -18
  229. package/src/pages/pos/management-floor/index.tsx +0 -7
  230. package/src/pages/pos/management-order/index.tsx +0 -7
  231. package/src/pages/pos/management-order/order-detail/index.tsx +0 -7
  232. package/src/pages/pos/management-table/index.tsx +0 -0
  233. package/src/pages/pos/payment-success/index.tsx +0 -75
  234. package/src/provider/app-provider.tsx +0 -56
  235. package/src/provider/fallback/custom-error.tsx +0 -26
  236. package/src/provider/main-provider.tsx +0 -41
  237. package/src/provider/meta-provider.tsx +0 -72
  238. package/src/provider/modal-provider.tsx +0 -48
  239. package/src/provider/notification-provider.tsx +0 -64
  240. package/src/provider/pos-provider/close-session-provider/index.tsx +0 -207
  241. package/src/provider/pos-provider/customer-provider/index.tsx +0 -30
  242. package/src/provider/pos-provider/floor-provider/index.tsx +0 -39
  243. package/src/provider/pos-provider/index.ts +0 -6
  244. package/src/provider/pos-provider/kitchen-provider/index.tsx +0 -30
  245. package/src/provider/pos-provider/order-detail-provider/index.tsx +0 -233
  246. package/src/provider/pos-provider/order-provider/index.tsx +0 -803
  247. package/src/provider/pos-provider/payment-provider/index.tsx +0 -30
  248. package/src/provider/pos-provider/product-provider/index.tsx +0 -30
  249. package/src/provider/pos-provider/sale-provider/index.tsx +0 -168
  250. package/src/provider/pos-provider/session-provider/index.tsx +0 -30
  251. package/src/provider/pos-provider/socket-provider/index.tsx +0 -118
  252. package/src/provider/pos-provider/table-provider/index.tsx +0 -30
  253. package/src/provider/public-provider.tsx +0 -104
  254. package/src/provider/use-session-provider.ts +0 -79
  255. package/src/router/app-router.tsx +0 -38
  256. package/src/router/index.tsx +0 -26
  257. package/src/router/pos-route.tsx +0 -75
  258. package/src/router/protected-route.tsx +0 -16
  259. package/src/router/public-route.tsx +0 -11
  260. package/src/store/header/index.ts +0 -21
  261. package/src/store/session/index.ts +0 -25
  262. package/src/store/states/cart.state.ts +0 -135
  263. package/src/store/states/close-session.state.ts +0 -20
  264. package/src/store/states/customer.state.ts +0 -19
  265. package/src/store/states/payment.state.ts +0 -14
  266. package/src/styles/base.css +0 -212
  267. package/src/styles/common.css +0 -65
  268. package/src/styles/lib/tailwind.css +0 -0
  269. package/src/styles/lib/tailwind.theme.css +0 -34
  270. package/src/styles/loading.css +0 -72
  271. package/src/styles/main.css +0 -5
  272. package/src/styles/refreshing-content.css +0 -55
  273. package/src/styles/text.css +0 -44
  274. package/src/types/account.ts +0 -61
  275. package/src/types/branch.ts +0 -6
  276. package/src/types/category.ts +0 -13
  277. package/src/types/common.ts +0 -4
  278. package/src/types/customer.ts +0 -52
  279. package/src/types/dashboard.ts +0 -18
  280. package/src/types/edc.ts +0 -37
  281. package/src/types/export-e-invoice.ts +0 -17
  282. package/src/types/filter.d.ts +0 -12
  283. package/src/types/floor/floor.ts +0 -16
  284. package/src/types/floor.d.ts +0 -36
  285. package/src/types/index.ts +0 -127
  286. package/src/types/invoice.ts +0 -32
  287. package/src/types/modal.ts +0 -15
  288. package/src/types/notification.ts +0 -12
  289. package/src/types/order.ts +0 -182
  290. package/src/types/payment.ts +0 -44
  291. package/src/types/product/product.ts +0 -47
  292. package/src/types/product.ts +0 -137
  293. package/src/types/provider-info.d.ts +0 -14
  294. package/src/types/qr.d.ts +0 -25
  295. package/src/types/report.d.ts +0 -43
  296. package/src/types/sale.d.ts +0 -68
  297. package/src/types/search.d.ts +0 -7
  298. package/src/types/session.d.ts +0 -30
  299. package/src/types/shop-qr.d.ts +0 -89
  300. package/src/types/staff.d.ts +0 -35
  301. package/src/types/store.d.ts +0 -25
  302. package/src/types/table.d.ts +0 -57
  303. package/src/utils/close-session-ticket.tsx +0 -129
  304. package/src/utils/functions.ts +0 -299
  305. package/src/utils/i18n.ts +0 -25
  306. package/src/utils/pos/bill.ts +0 -156
  307. package/src/utils/pos/convert-order.ts +0 -58
  308. package/src/utils/pos/helpers.ts +0 -48
  309. package/src/utils/pos/session.ts +0 -44
  310. package/src/utils/storages/index.ts +0 -1
  311. package/src/utils/storages/local-storage.ts +0 -72
  312. package/tailwind.preset.ts +0 -25
  313. package/tsconfig.json +0 -30
  314. package/tsup.config.ts +0 -30
@@ -1,803 +0,0 @@
1
- import { FIND_PARTNER_CODE } from "@constants/api";
2
- import { METHOD } from "@constants/methods.constant";
3
- import { ORDER_STATE } from "@constants/order-state";
4
- import { QUERY_KEYS } from "@constants/query.constant";
5
- import { useService } from "@fctc/widget-logic/provider";
6
- import { sessionStorageUtils } from "@fctc/widget-logic/utils";
7
- import { useQueryParams } from "@hooks/common/use-query-params";
8
- import { useSpeech } from "@hooks/common/use-speech";
9
- import { usePosAppProvider } from "@provider/app-provider";
10
- import { CartItemType, useCartStore } from "@store/states/cart.state";
11
- import { useMutation } from "@tanstack/react-query";
12
- import { TBasicCustomer, TCustomer } from "@type/customer";
13
- import { ApiOrder, TBasicOrder, TOrderPayload } from "@type/order";
14
- import {
15
- TAddProductToOrderPayload,
16
- TOnUpdateOrderLineQuantity,
17
- TRemoveProductPayload,
18
- TUpdateOrderPayload,
19
- TUpdateOrderTotalAmount,
20
- } from "@type/product";
21
- import { TAttributeLine, TProduct } from "@type/product/product";
22
- import {
23
- add7Hours,
24
- cleanObject,
25
- generatePosReference,
26
- getKey,
27
- isObjectEmpty,
28
- makeTaxIds,
29
- } from "@utils/functions";
30
- import { convertOrders } from "@utils/pos/convert-order";
31
- import { t } from "i18next";
32
- import {
33
- createContext,
34
- useCallback,
35
- useContext,
36
- useEffect,
37
- useMemo,
38
- useState,
39
- } from "react";
40
- import { useNavigate, useSearchParams } from "react-router-dom";
41
- import { toast } from "react-toastify";
42
- import { useKitchen } from "../kitchen-provider";
43
- import { LoadDataModel, useSale } from "../sale-provider";
44
- import POSPath from "@constants/routes.constants";
45
-
46
- export type useOrderProviderType = ReturnType<typeof useOrderProvider>;
47
-
48
- const ReactContext = createContext<useOrderProviderType>(
49
- {} as useOrderProviderType
50
- );
51
-
52
- export const OrderProvider = ({ children }: { children: React.ReactNode }) => {
53
- return (
54
- <ReactContext.Provider value={useOrderProvider()}>
55
- {children}
56
- </ReactContext.Provider>
57
- );
58
- };
59
-
60
- export type TDomainCondition = [string, string, any];
61
-
62
- const useOrderProvider = ({
63
- enabled = true,
64
- }: {
65
- enabled?: boolean;
66
- } = {}) => {
67
- const {
68
- useCreateEntity,
69
- useUpdateEntity,
70
- useGetOrderLine,
71
- useDeleteEntity,
72
- useAddEntity,
73
- useProcessOrder,
74
- useGetCurrentUser,
75
- } = useService();
76
- const createEntityMutation = useCreateEntity().mutateAsync;
77
- const getOrderLineMutation = useGetOrderLine().mutateAsync;
78
- const updateEntityMutation = useUpdateEntity().mutateAsync;
79
- const deleteEntityMutation = useDeleteEntity().mutateAsync;
80
- const addEntityMutation = useAddEntity().mutateAsync;
81
- const processOrderMutation = useProcessOrder().mutateAsync;
82
- const getCurrentUserMutation = useGetCurrentUser().mutateAsync;
83
-
84
- const { getSpec, getData } = useSale();
85
- const { user } = usePosAppProvider();
86
- const xNode = user?.userProfile?.data?.x_node;
87
- const service = sessionStorageUtils.getMenuFocus().service || `wesap`;
88
- const [searchParams] = useSearchParams();
89
- const sessionId = searchParams.get(QUERY_KEYS.SESSION_ID);
90
- const orderId = searchParams.get(QUERY_KEYS.ORDER_ID);
91
- const [extraDomain, setExtraDomain] = useState<TDomainCondition[]>([
92
- ["session_id", "=", Number(sessionId)],
93
- ]);
94
- const { removeParam, formatQuery } = useQueryParams();
95
- const { setMapKitchenWithPOS, isPosMapKitchen } = useKitchen();
96
- const orderLineSpec = getSpec(LoadDataModel.POS_ORDER_LINE);
97
- const users = getData(LoadDataModel.RES_USERS);
98
- const walkInCustomer = useMemo(() => {
99
- return getData(LoadDataModel.RES_PARTNER)?.find(
100
- (user: TBasicCustomer) => user.code === FIND_PARTNER_CODE
101
- );
102
- }, [users]);
103
-
104
- const { updateMultipleQuery } = useQueryParams();
105
- const [orders, setOrders] = useState<TBasicOrder[]>([]);
106
-
107
- useEffect(() => {
108
- const ordersData = getData(LoadDataModel.POS_ORDER) as ApiOrder[];
109
- if (ordersData && !isObjectEmpty(ordersData)) {
110
- setOrders(convertOrders(ordersData));
111
- }
112
- }, [getData]);
113
-
114
- const orderDetailById = useMemo(() => {
115
- if (orderId) {
116
- return orders.find((order) => order.id === Number(orderId));
117
- }
118
- }, [orders, orderId]);
119
-
120
- const draftOrders = useMemo(() => {
121
- return orders.filter(
122
- (order) =>
123
- order.state === ORDER_STATE.NEW || order.state === ORDER_STATE.IN_PAID
124
- );
125
- }, [orders]);
126
-
127
- const createOrderMutate = useMutation({
128
- mutationFn: useCallback(
129
- (payload: TOrderPayload) =>
130
- createEntityMutation({
131
- model: LoadDataModel.POS_ORDER,
132
- args: [
133
- cleanObject({
134
- session_id: payload.sessionId,
135
- pos_reference: payload.posReference,
136
- amount_tax: payload.amountTax,
137
- amount_total: payload.amountTotal,
138
- amount_paid: payload.amountPaid,
139
- amount_return: payload.amountReturn,
140
- table_id: payload.tableId,
141
- partner_id: payload.partnerId,
142
- }),
143
- ],
144
- service: service ?? "",
145
- xNode: xNode ?? "",
146
- }),
147
- [createEntityMutation, service, xNode]
148
- ),
149
- });
150
-
151
- const { cartItems, dec, remove, add, clear, activeProduct } = useCartStore();
152
-
153
- const posSessionData = getData(LoadDataModel.POS_SESSION);
154
-
155
- const posReference = useMemo(() => {
156
- const data = posSessionData?.[0];
157
- const length = orders?.length || 0;
158
- if (
159
- data === undefined ||
160
- data?.id === undefined ||
161
- data?.login_number === undefined
162
- ) {
163
- return undefined;
164
- }
165
- return generatePosReference({
166
- posId: data.id,
167
- loginNum: data.login_number,
168
- orderLength: length,
169
- });
170
- }, [posSessionData, orders]);
171
-
172
- const handleCreateOrder = async (tableId?: number) => {
173
- clear();
174
- try {
175
- let payload: any = {
176
- sessionId: Number(sessionId),
177
- posReference,
178
- amountTax: 0,
179
- amountTotal: 0,
180
- amountPaid: 0,
181
- amountReturn: 0,
182
- partnerId: walkInCustomer.id,
183
- };
184
- if (tableId) {
185
- payload = {
186
- ...payload,
187
- tableId,
188
- };
189
- }
190
- const order = await createOrderMutate.mutateAsync(payload);
191
- if (order) {
192
- const orderId = (order as []).flat()[0] as number;
193
- const time = add7Hours(new Date());
194
- setOrders([
195
- {
196
- id: orderId,
197
- table_id: tableId ?? false,
198
- state: ORDER_STATE.NEW,
199
- lines: [],
200
- create_date: time,
201
- pos_reference: posReference ?? "",
202
- amount_total: 0,
203
- amount_tax: 0,
204
- user_id: user?.id,
205
- partner_id: walkInCustomer.id,
206
- write_date: time,
207
- },
208
- ...orders,
209
- ]);
210
- }
211
- return order;
212
- } catch (error) {
213
- toast.error("Tạo đơn hàng không thành công");
214
- console.error(error);
215
- }
216
- };
217
-
218
- const handleCancelOrder = async (onSuccess?: () => void) => {
219
- try {
220
- const res = (await cancelOrder.mutateAsync([Number(orderId)])) as {
221
- [LoadDataModel.POS_ORDER]: any;
222
- };
223
- if (res?.[LoadDataModel.POS_ORDER]?.[0]?.id) {
224
- removeParam([QUERY_KEYS.ORDER_ID, QUERY_KEYS.TABLE_ID]);
225
- setOrders(
226
- orders.filter(
227
- (order) =>
228
- order.id !== Number(res?.[LoadDataModel.POS_ORDER]?.[0]?.id)
229
- )
230
- );
231
- onSuccess && onSuccess();
232
- }
233
- } catch (error) {
234
- console.error(error);
235
- toast.error("Huỷ đơn hàng không thành công");
236
- }
237
- };
238
-
239
- const [loadingChangeQty, setLoadingChangeQty] = useState(false);
240
-
241
- const addProductToOrder = useMutation<
242
- [number],
243
- Error,
244
- TAddProductToOrderPayload
245
- >({
246
- mutationFn: (payload: TAddProductToOrderPayload) =>
247
- addEntityMutation({
248
- model: LoadDataModel.POS_ORDER_LINE,
249
- values: {
250
- order_id: payload.orderId,
251
- product_id: payload.productId,
252
- qty: payload.qty,
253
- price_subtotal: payload.priceSubtotal,
254
- price_subtotal_incl: payload.priceSubtotalIncl,
255
- price_unit: payload.priceUnit,
256
- tax_ids: [makeTaxIds(payload.taxIds)],
257
- uuid: `${payload.productId}-${payload.attribute_value_ids
258
- ?.map((item) => item)
259
- .join("-")}`,
260
- attribute_value_ids: payload.attribute_value_ids
261
- ? [[6, 0, payload.attribute_value_ids]]
262
- : [],
263
- },
264
- isCreateEndpoint: true,
265
- service: service ?? "",
266
- xNode: xNode ?? "",
267
- }) as Promise<[number]>,
268
- });
269
-
270
- const updateOrderTotalAmount = useMutation({
271
- mutationFn: (payload: TUpdateOrderTotalAmount) =>
272
- updateEntityMutation({
273
- model: LoadDataModel.POS_ORDER,
274
- domain: [["id", "=", payload.orderId]],
275
- values: {
276
- amount_tax: payload.amountTax,
277
- amount_total: payload.amountTotal,
278
- note: payload.note,
279
- },
280
- service: service ?? "",
281
- xNode: xNode ?? "",
282
- }),
283
- });
284
-
285
- const addProduct = async (
286
- payload: TAddProductToOrderPayload & {
287
- amountTax: number;
288
- amountTotal: number;
289
- }
290
- ) => {
291
- try {
292
- setLoadingChangeQty(true);
293
- const addProductToOrderRes = await addProductToOrder.mutateAsync({
294
- orderId: payload.orderId,
295
- productId: payload.productId,
296
- qty: payload.qty,
297
- priceUnit: payload.priceUnit,
298
- priceSubtotal: payload.priceSubtotal,
299
- priceSubtotalIncl: payload.priceSubtotalIncl,
300
- taxIds: payload.taxIds,
301
- attribute_value_ids: payload.attribute_value_ids,
302
- note: payload.note,
303
- });
304
-
305
- onUpdateOrderTotalAmount({
306
- orderId: payload.orderId,
307
- amountTax: payload.amountTax,
308
- amountTotal: payload.amountTotal,
309
- note: payload?.note,
310
- });
311
- return addProductToOrderRes;
312
- } catch (err) {
313
- console.error("add product failed", err);
314
- } finally {
315
- setLoadingChangeQty(false);
316
- }
317
- };
318
-
319
- const getOrderLine = useMutation({
320
- mutationFn: useCallback(
321
- (ids: number[]) =>
322
- getOrderLineMutation({
323
- model: LoadDataModel.POS_ORDER_LINE,
324
- ids,
325
- specification: {
326
- ...orderLineSpec,
327
- },
328
- service: service ?? "",
329
- xNode: xNode ?? "",
330
- }),
331
- [getOrderLineMutation, orderLineSpec, service, xNode]
332
- ),
333
- });
334
-
335
- const updateOrder = useMutation({
336
- mutationFn: useCallback(
337
- (payload: TUpdateOrderPayload) =>
338
- updateEntityMutation({
339
- model: LoadDataModel.POS_ORDER,
340
- domain: [["id", "=", payload.orderId]],
341
- values: cleanObject({
342
- state: payload.state,
343
- table_id: payload.tableId,
344
- partner_id: payload.partnerId,
345
- amount_return: payload.amount_return,
346
- }),
347
- service: service ?? "",
348
- xNode: xNode ?? "",
349
- }),
350
- [updateEntityMutation, service, xNode]
351
- ),
352
- });
353
-
354
- const cancelOrder = useMutation({
355
- mutationFn: useCallback(
356
- (ids: number[]) =>
357
- deleteEntityMutation({
358
- model: LoadDataModel.POS_ORDER,
359
- ids,
360
- service: service ?? "",
361
- xNode: xNode ?? "",
362
- method: METHOD.ACTION_POS_ORDER_CANCEL,
363
- }),
364
- [deleteEntityMutation, service, xNode]
365
- ),
366
- });
367
-
368
- const deleteProductFromOrder = useMutation({
369
- mutationFn: useCallback(
370
- (lineIds: number[]) =>
371
- deleteEntityMutation({
372
- model: LoadDataModel.POS_ORDER_LINE,
373
- ids: lineIds,
374
- service: service ?? "",
375
- xNode: xNode ?? "",
376
- method: METHOD.UNLINK,
377
- }),
378
- [deleteEntityMutation, service, xNode]
379
- ),
380
- });
381
-
382
- const onUpdateLineOrderQuantity = useMutation({
383
- mutationFn: useCallback(
384
- (payload: TOnUpdateOrderLineQuantity) =>
385
- updateEntityMutation({
386
- model: LoadDataModel.POS_ORDER_LINE,
387
- domain: [["id", "=", payload.orderLineId]],
388
- values: {
389
- order_id: payload.orderId,
390
- qty: payload.qty,
391
- price_subtotal: payload.priceSubtotal,
392
- price_subtotal_incl: payload.priceSubtotalIncl,
393
- attribute_value_ids: payload.attributeValueIds,
394
- },
395
- service: service ?? "",
396
- xNode: xNode ?? "",
397
- }),
398
- [updateEntityMutation, service, xNode]
399
- ),
400
- });
401
-
402
- const onProductQuantityChange = async (
403
- payload: TOnUpdateOrderLineQuantity & {
404
- amountTax: number;
405
- amountTotal: number;
406
- note?: string;
407
- }
408
- ) => {
409
- try {
410
- setLoadingChangeQty(true);
411
- await onUpdateLineOrderQuantity.mutateAsync(payload);
412
-
413
- onUpdateOrderTotalAmount({
414
- orderId: payload.orderId,
415
- amountTax: payload.amountTax,
416
- amountTotal: payload.amountTotal,
417
- note: payload?.note,
418
- });
419
- } catch (err) {
420
- console.error("on product change quantity failed", err);
421
- } finally {
422
- setLoadingChangeQty(false);
423
- }
424
- };
425
-
426
- const onUpdateOrderTotalAmount = async (payload: {
427
- orderId: number;
428
- amountTax: number;
429
- amountTotal: number;
430
- note?: string;
431
- }) => {
432
- const res = await updateOrderTotalAmount.mutateAsync({
433
- orderId: payload.orderId,
434
- amountTax: payload.amountTax,
435
- amountTotal: payload.amountTotal,
436
- note: payload?.note,
437
- });
438
- res &&
439
- setOrders(
440
- orders.map((order) => {
441
- if (order.id === payload.orderId) {
442
- return {
443
- ...order,
444
- amount_tax: payload.amountTax,
445
- amount_total: payload.amountTotal,
446
- };
447
- }
448
- return order;
449
- })
450
- );
451
- };
452
-
453
- const onRemoveProduct = async (product: TProduct) => {
454
- const productKey = activeProduct.isFromCart
455
- ? product.productCartKey ?? getKey(product)
456
- : getKey(product);
457
- const lineId = cartItems[productKey]?.lineId;
458
- if (!lineId) {
459
- console.error("lineId not found");
460
- return;
461
- }
462
-
463
- const { total, totalIncl } = getTotal({
464
- ...cartItems,
465
- [productKey]: {
466
- ...cartItems?.[getKey(product)],
467
- product: product,
468
- qty: 0,
469
- },
470
- });
471
- await removeProduct({
472
- orderId: Number(orderId),
473
- amountTax: totalIncl - total,
474
- amountTotal: totalIncl,
475
- lineIds: lineId,
476
- });
477
- remove(productKey);
478
- return;
479
- };
480
-
481
- const changeProductQty = async ({ ...props }: CartItemType) => {
482
- const { product, qty } = props;
483
- const currentQty = cartItems[getKey(product)]?.qty || 0;
484
- const productKey =
485
- activeProduct.isFromCart && product.productCartKey
486
- ? product.productCartKey
487
- : getKey(product);
488
- const exist = cartItems?.[productKey];
489
- const totalProductPrice = getTotalProductPrice(product);
490
-
491
- const onGetPrice = (qty: number) => {
492
- const { total, totalIncl } = getTotal({
493
- ...cartItems,
494
- [productKey]: {
495
- ...cartItems?.[getKey(product)],
496
- product: product,
497
- qty: qty,
498
- },
499
- });
500
- return {
501
- total,
502
- totalIncl,
503
- };
504
- };
505
- const onAdd = async () => {
506
- const { total, totalIncl } = onGetPrice(qty);
507
- return await addProduct({
508
- orderId: Number(orderId),
509
- productId: product.id,
510
- qty,
511
- amountTax: totalIncl - total,
512
- amountTotal: totalIncl,
513
- priceUnit: product.lst_price,
514
- priceSubtotal: totalProductPrice * qty,
515
- priceSubtotalIncl:
516
- Number((totalProductPrice * (1 + product.tax * 0.01)).toFixed(2)) *
517
- qty,
518
- taxIds: product.taxes_id,
519
- attribute_value_ids: product.attributeValueIds || [],
520
- });
521
- };
522
-
523
- if (!activeProduct.isFromCart && qty == 0) return;
524
- if (exist) {
525
- const lineId = cartItems[productKey]?.lineId || props?.lineId;
526
- if (!lineId) {
527
- console.error("lineId not found");
528
- return;
529
- }
530
-
531
- const onChange = async () => {
532
- const realQty =
533
- qty == -1
534
- ? currentQty - 1
535
- : activeProduct.isFromCart
536
- ? qty
537
- : currentQty + qty;
538
-
539
- const { total, totalIncl } = onGetPrice(realQty);
540
-
541
- await onProductQuantityChange({
542
- orderId: Number(orderId),
543
- orderLineId: lineId[0],
544
- qty: realQty,
545
- priceSubtotal: totalProductPrice * realQty,
546
- priceSubtotalIncl:
547
- Number((totalProductPrice * (1 + product.tax * 0.01)).toFixed(2)) *
548
- realQty,
549
- amountTax: totalIncl - total,
550
- amountTotal: totalIncl,
551
- attributeValueIds: product.attributeValueIds,
552
- note: props?.note,
553
- });
554
- if (product.productCartKey !== getKey(product)) {
555
- product.productCartKey && remove(product.productCartKey);
556
- add({
557
- product: { ...product, productCartKey: getKey(product) },
558
- qty: realQty - currentQty,
559
- lineId: [lineId[0]],
560
- });
561
- } else
562
- add({
563
- product,
564
- qty: realQty - currentQty,
565
- lineId: [lineId[0]],
566
- });
567
-
568
- return;
569
- };
570
-
571
- const onDec = async () => {
572
- await deleteProductFromOrder.mutateAsync(lineId);
573
- const res = await onAdd();
574
- if (!res) return;
575
- if (product.productCartKey !== getKey(product)) {
576
- product.productCartKey && remove(product.productCartKey);
577
- dec(getKey(product), qty, res);
578
- } else {
579
- dec(productKey, currentQty - qty, res);
580
- }
581
- return;
582
- };
583
-
584
- const onRemove = async () => {
585
- const { total, totalIncl } = onGetPrice(0);
586
- await removeProduct({
587
- orderId: Number(orderId),
588
- amountTax: totalIncl - total,
589
- amountTotal: totalIncl,
590
- lineIds: lineId,
591
- });
592
- remove(productKey);
593
- return;
594
- };
595
-
596
- if (activeProduct.isFromCart && qty === 0) onRemove();
597
- else if (activeProduct.isFromCart && qty < currentQty) onDec();
598
- else onChange();
599
-
600
- //remove
601
- } else {
602
- const res = await onAdd();
603
- res &&
604
- add({
605
- product,
606
- qty,
607
- lineId: [res?.[0]],
608
- });
609
- }
610
- };
611
-
612
- const removeProduct = async (payload: TRemoveProductPayload) => {
613
- try {
614
- await deleteProductFromOrder.mutateAsync(payload.lineIds);
615
-
616
- onUpdateOrderTotalAmount({
617
- orderId: payload.orderId,
618
- amountTax: payload.amountTax,
619
- amountTotal: payload.amountTotal,
620
- });
621
- } catch (err) {
622
- console.error("remove product failed", err);
623
- }
624
- };
625
-
626
- const onUpdateCustomer = async ({
627
- customer,
628
- onSuccess,
629
- }: {
630
- customer: TCustomer;
631
- onSuccess?: () => void;
632
- }) => {
633
- if (!orderId) return;
634
-
635
- await updateOrder.mutateAsync({
636
- orderId: Number(orderId),
637
- partnerId: customer.id,
638
- });
639
- setOrders(
640
- orders.map((order) => {
641
- if (order.id === Number(orderId)) {
642
- return {
643
- ...order,
644
- partner_id: customer.id,
645
- };
646
- }
647
- return order;
648
- })
649
- );
650
- onSuccess && onSuccess();
651
- };
652
-
653
- const onRemoveCustomer = async () => {
654
- if (!orderId) return;
655
-
656
- await updateOrder.mutateAsync({
657
- orderId: Number(orderId),
658
- partnerId: 0,
659
- });
660
- setOrders(
661
- orders.map((order) => {
662
- if (order.id === Number(orderId)) {
663
- return {
664
- ...order,
665
- partner_id: walkInCustomer.id,
666
- };
667
- }
668
- return order;
669
- })
670
- );
671
- };
672
-
673
- const partnerIdQueryResult = getData(LoadDataModel.RES_PARTNER);
674
-
675
- const onProcessOrder = useMutation({
676
- mutationFn: async (orderId: number) => {
677
- return await processOrderMutation({
678
- orderId,
679
- service: service ?? "",
680
- xNode: xNode ?? "",
681
- });
682
- },
683
- });
684
-
685
- const onCallDish = async () => {
686
- if (!orderId || !isPosMapKitchen) return;
687
- try {
688
- await onProcessOrder.mutateAsync(Number(orderId));
689
- // props is new order line
690
- setMapKitchenWithPOS(null);
691
- // refetchDisplayDataResult();
692
- toast.success(t("callDishSuccess"));
693
- } catch (error: any) {
694
- toast.error(error);
695
- }
696
- };
697
- const { speak } = useSpeech();
698
- const navigate = useNavigate();
699
- const onPaymentSuccess = (total: number) => {
700
- console.log("onPaymentSuccess");
701
- speak(`Thanh toán thành công, ${total} đồng`);
702
- navigate({
703
- pathname: POSPath.SUCCESS,
704
- search: `?${formatQuery([
705
- QUERY_KEYS.POS_ID,
706
- QUERY_KEYS.SESSION_ID,
707
- QUERY_KEYS.ORDER_ID,
708
- ])}`,
709
- });
710
- };
711
-
712
- const onGetCurrentUser = async ({ userId }: { userId: number }) => {
713
- const oauthId = await users?.find((user: any) => user.id === userId)
714
- ?.oauth_uid;
715
-
716
- const userMatched = await getCurrentUserMutation({
717
- service: "mms",
718
- xNode: xNode ?? "",
719
- oauthUid: oauthId ?? "Chưa xác định",
720
- });
721
-
722
- return userMatched?.name ?? "Chưa xác định";
723
- };
724
-
725
- return {
726
- onProcessOrder,
727
- handleCreateOrder,
728
- getOrderLine,
729
- updateOrder,
730
- cancelOrder,
731
- changeProductQty,
732
- loadingChangeQty,
733
- partnerIdQueryResult,
734
- setExtraDomain,
735
- extraDomain,
736
- onCallDish,
737
- onPaymentSuccess,
738
- onRemoveProduct,
739
- onGetCurrentUser,
740
- orders,
741
- setOrders,
742
- draftOrders,
743
- orderDetailById,
744
- handleCancelOrder,
745
- onUpdateCustomer,
746
- onRemoveCustomer,
747
- };
748
- };
749
- export default useOrderProvider;
750
- export const useOrder = () => {
751
- const context = useContext(ReactContext);
752
-
753
- if (!context) {
754
- throw new Error("useOrder must be used within a OrderProvider");
755
- }
756
-
757
- return context;
758
- };
759
- export function getTotalProductPrice(product: TProduct) {
760
- const totalAttributesValue =
761
- product.pickAttributeValue?.reduce(
762
- (acc: number, attributeValue: TAttributeLine) => {
763
- return (
764
- acc +
765
- attributeValue.value_string.reduce(
766
- (total: number, item: any) => total + item.price_extra,
767
- 0
768
- )
769
- );
770
- },
771
- 0
772
- ) ?? 0;
773
- return totalAttributesValue + product.lst_price;
774
- }
775
-
776
- function getTotal(items: Record<string, CartItemType>) {
777
- const totalIncl = Object.values(items).reduce(
778
- (acc: number, item: CartItemType) => {
779
- return (
780
- acc +
781
- Number(
782
- (
783
- getTotalProductPrice(item.product) *
784
- (1 + item.product.tax * 0.01)
785
- ).toFixed(2)
786
- ) *
787
- item.qty
788
- );
789
- },
790
- 0
791
- );
792
- const total = Object.values(items).reduce(
793
- (acc: number, item: CartItemType) => {
794
- return acc + getTotalProductPrice(item.product) * item.qty;
795
- },
796
- 0
797
- );
798
-
799
- return {
800
- totalIncl,
801
- total,
802
- };
803
- }