sme-pos-package 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +37 -2
- package/dist/index.mjs +17 -104
- package/dist/index.mjs.map +1 -1
- package/dist/tailwind.preset.d.mts +27 -0
- package/dist/tailwind.preset.mjs +2 -0
- package/dist/tailwind.preset.mjs.map +1 -0
- package/package.json +18 -30
- package/public/assets/images/bank-logos.png +0 -0
- package/public/assets/images/banner1.png +0 -0
- package/public/assets/images/banner2.png +0 -0
- package/public/assets/images/banner3.png +0 -0
- package/public/assets/images/banner4.png +0 -0
- package/public/assets/images/cashier.svg +9 -0
- package/public/assets/images/empty-cart.png +0 -0
- package/public/assets/images/empty-table-state.png +0 -0
- package/public/assets/images/layout-display/left-layout.png +0 -0
- package/public/assets/images/layout-display/right-layout.png +0 -0
- package/public/assets/images/modal-illustration.png +0 -0
- package/public/assets/images/order-empty-state.png +0 -0
- package/public/assets/images/order.png +0 -0
- package/public/assets/images/payment-success-label.png +0 -0
- package/public/assets/images/table-empty.png +0 -0
- package/public/assets/images/take-away.png +0 -0
- package/public/assets/lottie/loading.json +1 -0
- package/public/assets/lottie/soft_pos.json +1 -0
- package/public/assets/lottie/success.json +1 -0
- package/public/config.json +27 -0
- package/public/env.json +17 -0
- package/src/animations/success.json +9730 -0
- package/src/assets/icons/breadcrumbs-icon.tsx +85 -0
- package/src/assets/icons/cart-icon.tsx +14 -0
- package/src/assets/icons/common.tsx +270 -0
- package/src/assets/icons/customer-view-icon.tsx +20 -0
- package/src/assets/icons/dining-table.tsx +34 -0
- package/src/assets/icons/edit-line-icon.tsx +18 -0
- package/src/assets/icons/emenu-icon.tsx +39 -0
- package/src/assets/icons/file-close-line-icon.tsx +18 -0
- package/src/assets/icons/helper-icon.tsx +84 -0
- package/src/assets/icons/home-gear-line-icon.tsx +18 -0
- package/src/assets/icons/kanban-icon.tsx +16 -0
- package/src/assets/icons/loading-icon.tsx +45 -0
- package/src/assets/icons/logout-box-line-icon.tsx +18 -0
- package/src/assets/icons/order-icon.tsx +92 -0
- package/src/assets/icons/payment-icon.tsx +429 -0
- package/src/assets/icons/pincode.tsx +196 -0
- package/src/assets/icons/pos-connect-icon.tsx +67 -0
- package/src/assets/icons/pos-device-icon.tsx +52 -0
- package/src/assets/icons/pos-icon.tsx +75 -0
- package/src/assets/icons/printer-line-icon.tsx +18 -0
- package/src/assets/icons/star-icon.tsx +174 -0
- package/src/assets/icons/table-icon.tsx +77 -0
- package/src/assets/icons/user-add-line-icon.tsx +33 -0
- package/src/assets/icons/user-icon.tsx +65 -0
- package/src/components/common/button-action.tsx +46 -0
- package/src/components/common/button-icon.tsx +23 -0
- package/src/components/common/dropdown/index.tsx +79 -0
- package/src/components/common/empty-state.tsx +60 -0
- package/src/components/common/header/index.tsx +89 -0
- package/src/components/common/header/tabs.tsx +119 -0
- package/src/components/common/image.tsx +20 -0
- package/src/components/common/input/index.tsx +55 -0
- package/src/components/common/input/radio-group.tsx +75 -0
- package/src/components/common/input/text-area.tsx +28 -0
- package/src/components/common/modal/delete-confirm-modal-container.tsx +65 -0
- package/src/components/common/modal/index.ts +2 -0
- package/src/components/common/modal/modal-direction.tsx +125 -0
- package/src/components/common/modal/modal-header.tsx +37 -0
- package/src/components/common/modal/modal-wrapper.tsx +56 -0
- package/src/components/common/modal/modal-zoom.tsx +61 -0
- package/src/components/common/pagination.tsx +95 -0
- package/src/components/common/refresh-button.tsx +28 -0
- package/src/components/common/search-bar.tsx +27 -0
- package/src/components/common/search.tsx +59 -0
- package/src/components/common/skeleton.tsx +7 -0
- package/src/components/common/tabs-layout.tsx +98 -0
- package/src/components/common/use-check-session.tsx +19 -0
- package/src/components/customer-management/add-customer/add-customer-drawer.tsx +286 -0
- package/src/components/customer-management/add-customer/address-select.tsx +51 -0
- package/src/components/customer-management/choose-customer-drawer.tsx +177 -0
- package/src/components/customer-management/customer-info-drawer.tsx +166 -0
- package/src/components/customer-management/customer-no-data.tsx +18 -0
- package/src/components/emenu/emenu-qr-code.tsx +59 -0
- package/src/components/emenu/menu-link.tsx +67 -0
- package/src/components/index.ts +8 -0
- package/src/components/kanban-template/kitchen-template.tsx +60 -0
- package/src/components/kanban-template/pos-order-template.tsx +77 -0
- package/src/components/kanban-template/pos-template.tsx +170 -0
- package/src/components/kitchen-management/change-status-confirm-modal.tsx +61 -0
- package/src/components/kitchen-management/index.ts +1 -0
- package/src/components/kitchen-management/kitchen-order/index.tsx +153 -0
- package/src/components/kitchen-management/kitchen-order/line.tsx +78 -0
- package/src/components/kitchen-management/kitchen-order/state.tsx +52 -0
- package/src/components/kitchen-management/kitchen-status.tsx +69 -0
- package/src/components/kitchen-management/orders-kitchen-management.tsx +113 -0
- package/src/components/order-management/index.tsx +128 -0
- package/src/components/order-management/order-actions.tsx +46 -0
- package/src/components/order-management/order-detail/header.tsx +37 -0
- package/src/components/order-management/order-detail/index.ts +3 -0
- package/src/components/order-management/order-detail/information.tsx +96 -0
- package/src/components/order-management/order-detail/order-detail.tsx +84 -0
- package/src/components/order-management/order-detail/order-line.tsx +56 -0
- package/src/components/order-management/order-detail/summary.tsx +221 -0
- package/src/components/order-management/order-header.tsx +113 -0
- package/src/components/order-management/order-pagination.tsx +49 -0
- package/src/components/order-management/order-status.tsx +58 -0
- package/src/components/order-management/order-table.tsx +179 -0
- package/src/components/order-management/order-tabs.tsx +48 -0
- package/src/components/pos-management/add-product-from-barcode/index.tsx +97 -0
- package/src/components/pos-management/cart-content/action-line.tsx +81 -0
- package/src/components/pos-management/cart-content/cancel-order-line-modal.tsx +41 -0
- package/src/components/pos-management/cart-content/cart-item.tsx +173 -0
- package/src/components/pos-management/cart-content/cart-items.tsx +130 -0
- package/src/components/pos-management/cart-content/draft-orders/draft-order-line.tsx +67 -0
- package/src/components/pos-management/cart-content/draft-orders/index.tsx +40 -0
- package/src/components/pos-management/cart-content/edit-cart-modal.tsx +11 -0
- package/src/components/pos-management/cart-content/index.tsx +260 -0
- package/src/components/pos-management/cart-content/no-select-order.tsx +26 -0
- package/src/components/pos-management/cart-content/order-info/customer-info.tsx +53 -0
- package/src/components/pos-management/cart-content/order-info/index.tsx +109 -0
- package/src/components/pos-management/cart-content/order-total.tsx +36 -0
- package/src/components/pos-management/cart-content/orders-line.tsx +72 -0
- package/src/components/pos-management/menu-content/category-tab.tsx +38 -0
- package/src/components/pos-management/menu-content/create-order-modal.tsx +65 -0
- package/src/components/pos-management/menu-content/product-content.tsx +93 -0
- package/src/components/pos-management/menu-content/product-detail/info.tsx +28 -0
- package/src/components/pos-management/menu-content/product-detail/modal.tsx +148 -0
- package/src/components/pos-management/menu-content/product-detail/option.tsx +87 -0
- package/src/components/pos-management/menu-content/product-detail/quantity-control.tsx +155 -0
- package/src/components/pos-management/menu-content/product-detail/sale-keypad.tsx +100 -0
- package/src/components/pos-management/menu-content/product-item.tsx +65 -0
- package/src/components/pos-management/order-helper/cancel-order-confirm.tsx +43 -0
- package/src/components/pos-management/order-helper/history-call.tsx +105 -0
- package/src/components/pos-management/order-helper/order-helper-modal.tsx +116 -0
- package/src/components/pos-management/payment-content/bill/actions.tsx +46 -0
- package/src/components/pos-management/payment-content/bill/content.tsx +207 -0
- package/src/components/pos-management/payment-content/bill/index.tsx +18 -0
- package/src/components/pos-management/payment-content/card-payment/index.tsx +124 -0
- package/src/components/pos-management/payment-content/card-payment/pos-payment/pos-connect.tsx +183 -0
- package/src/components/pos-management/payment-content/card-payment/pos-payment/qr-connect.tsx +185 -0
- package/src/components/pos-management/payment-content/card-payment/waiting-for-payment-pos-modal.tsx +37 -0
- package/src/components/pos-management/payment-content/cash-payment/index.tsx +216 -0
- package/src/components/pos-management/payment-content/index.tsx +70 -0
- package/src/components/pos-management/payment-content/payment-info.tsx +67 -0
- package/src/components/pos-management/payment-content/payment-layout.tsx +16 -0
- package/src/components/pos-management/payment-content/payment-method-cards.tsx +99 -0
- package/src/components/pos-management/payment-content/qr-payment/index.tsx +118 -0
- package/src/components/pos-management/payment-content/qr-payment/qr_code.js +29 -0
- package/src/components/pos-management/payment-content/qr-payment/vietqr.js +436 -0
- package/src/components/pos-management/payment-content/session-close-modal.tsx +35 -0
- package/src/components/pos-management/payment-content/soft-pos-payment/index.tsx +48 -0
- package/src/components/pos-management/pos-helpers/back-confirm.tsx +45 -0
- package/src/components/pos-management/pos-helpers/index.tsx +135 -0
- package/src/components/pos-management/pos-helpers/layout-display-modal.tsx +99 -0
- package/src/components/pos-management/search.tsx +48 -0
- package/src/components/pos-management/table-content/filtered-tables.tsx +59 -0
- package/src/components/pos-management/table-content/floor-tabs.tsx +65 -0
- package/src/components/pos-management/table-content/index.tsx +76 -0
- package/src/components/pos-management/table-content/table-item.tsx +127 -0
- package/src/components/pos-management/table-content/tables.tsx +96 -0
- package/src/components/restaurant-management/add-floor-modal.tsx +133 -0
- package/src/components/restaurant-management/add-table-modal.tsx +198 -0
- package/src/components/restaurant-management/delete-floor-confirm-modal.tsx +42 -0
- package/src/components/restaurant-management/delete-table-confirm-modal.tsx +51 -0
- package/src/components/restaurant-management/header.tsx +22 -0
- package/src/components/restaurant-management/index.tsx +54 -0
- package/src/components/restaurant-management/left-side.tsx +51 -0
- package/src/components/restaurant-management/right-side.tsx +179 -0
- package/src/components/restaurant-management/table-empty.tsx +43 -0
- package/src/components/session-management/close-session-modal/actions.tsx +45 -0
- package/src/components/session-management/close-session-modal/close-session-confirm.tsx +157 -0
- package/src/components/session-management/close-session-modal/close-session-ticket.tsx +218 -0
- package/src/components/session-management/close-session-modal/container.tsx +25 -0
- package/src/components/session-management/close-session-modal/draft-orders-confirm.tsx +53 -0
- package/src/components/session-management/close-session-modal/draft-orders-summary.tsx +82 -0
- package/src/components/session-management/close-session-modal/draft-orders.tsx +34 -0
- package/src/components/session-management/close-session-modal/index.tsx +35 -0
- package/src/components/session-management/close-session-modal/order/index.ts +1 -0
- package/src/components/session-management/close-session-modal/order/order-line.tsx +64 -0
- package/src/components/session-management/close-session-modal/order/orders-in-draft.tsx +31 -0
- package/src/components/session-management/close-session-modal/session-summary.tsx +165 -0
- package/src/components/session-management/index.ts +1 -0
- package/src/components/session-management/open-shift/index.tsx +172 -0
- package/src/components/table-management/index.tsx +0 -0
- package/src/constants/api/index.ts +1 -0
- package/src/constants/headers.constant.tsx +24 -0
- package/src/constants/index.ts +1 -0
- package/src/constants/language.store.ts +21 -0
- package/src/constants/methods.constant.ts +10 -0
- package/src/constants/order-state.ts +8 -0
- package/src/constants/payment-color.constant.ts +26 -0
- package/src/constants/query.constant.ts +14 -0
- package/src/constants/routes.constants.ts +23 -0
- package/src/constants/template-name.constant.ts +9 -0
- package/src/hooks/bill/use-get-bill-information.ts +49 -0
- package/src/hooks/bill/use-print-bill.tsx +0 -0
- package/src/hooks/common/load-env-config.ts +98 -0
- package/src/hooks/common/use-back.ts +13 -0
- package/src/hooks/common/use-broadcast.ts +22 -0
- package/src/hooks/common/use-click-outside.ts +58 -0
- package/src/hooks/common/use-get-base64-photo.ts +71 -0
- package/src/hooks/common/use-get-query.ts +25 -0
- package/src/hooks/common/use-pos.ts +21 -0
- package/src/hooks/common/use-query-params.ts +89 -0
- package/src/hooks/common/use-speech.ts +36 -0
- package/src/hooks/customer/use-customer-provider.ts +247 -0
- package/src/hooks/floor/use-floor-provider.ts +172 -0
- package/src/hooks/kitchen/use-kitchen-provider.ts +80 -0
- package/src/hooks/order/use-get-point-reward.ts +50 -0
- package/src/hooks/order/use-loop-fetch-order.ts +30 -0
- package/src/hooks/order/use-order-items.ts +61 -0
- package/src/hooks/order/use-orders.ts +76 -0
- package/src/hooks/payment/use-payment-provider.ts +221 -0
- package/src/hooks/product/use-product-provider.ts +87 -0
- package/src/hooks/session/use-check-session.tsx +19 -0
- package/src/hooks/session/use-session-provider.ts +79 -0
- package/src/hooks/table/use-pos-table-provider.ts +193 -0
- package/src/index.css +5 -0
- package/src/index.ts +10 -0
- package/src/layouts/common.tsx +15 -0
- package/src/layouts/index.ts +4 -0
- package/src/layouts/pos-layout.tsx +33 -0
- package/src/layouts/pos-order-layout.tsx +43 -0
- package/src/layouts/sale-layout.tsx +25 -0
- package/src/locales/en.json +394 -0
- package/src/locales/vi.json +400 -0
- package/src/pages/index.ts +4 -0
- package/src/pages/login/index.tsx +128 -0
- package/src/pages/pincode/index.tsx +198 -0
- package/src/pages/pos/kitchen-management/layout.tsx +18 -0
- package/src/pages/pos/management-floor/index.tsx +7 -0
- package/src/pages/pos/management-order/index.tsx +7 -0
- package/src/pages/pos/management-order/order-detail/index.tsx +7 -0
- package/src/pages/pos/management-table/index.tsx +0 -0
- package/src/pages/pos/payment-success/index.tsx +75 -0
- package/src/provider/app-provider.tsx +56 -0
- package/src/provider/fallback/custom-error.tsx +26 -0
- package/src/provider/main-provider.tsx +41 -0
- package/src/provider/meta-provider.tsx +72 -0
- package/src/provider/modal-provider.tsx +48 -0
- package/src/provider/notification-provider.tsx +64 -0
- package/src/provider/pos-provider/close-session-provider/index.tsx +207 -0
- package/src/provider/pos-provider/customer-provider/index.tsx +30 -0
- package/src/provider/pos-provider/floor-provider/index.tsx +39 -0
- package/src/provider/pos-provider/index.ts +6 -0
- package/src/provider/pos-provider/kitchen-provider/index.tsx +30 -0
- package/src/provider/pos-provider/order-detail-provider/index.tsx +233 -0
- package/src/provider/pos-provider/order-provider/index.tsx +803 -0
- package/src/provider/pos-provider/payment-provider/index.tsx +30 -0
- package/src/provider/pos-provider/product-provider/index.tsx +30 -0
- package/src/provider/pos-provider/sale-provider/index.tsx +168 -0
- package/src/provider/pos-provider/session-provider/index.tsx +30 -0
- package/src/provider/pos-provider/socket-provider/index.tsx +118 -0
- package/src/provider/pos-provider/table-provider/index.tsx +30 -0
- package/src/provider/public-provider.tsx +104 -0
- package/src/provider/use-session-provider.ts +79 -0
- package/src/router/app-router.tsx +38 -0
- package/src/router/index.tsx +26 -0
- package/src/router/pos-route.tsx +75 -0
- package/src/router/protected-route.tsx +16 -0
- package/src/router/public-route.tsx +11 -0
- package/src/store/header/index.ts +21 -0
- package/src/store/session/index.ts +25 -0
- package/src/store/states/cart.state.ts +135 -0
- package/src/store/states/close-session.state.ts +20 -0
- package/src/store/states/customer.state.ts +19 -0
- package/src/store/states/payment.state.ts +14 -0
- package/src/styles/base.css +212 -0
- package/src/styles/common.css +65 -0
- package/src/styles/lib/tailwind.css +0 -0
- package/src/styles/lib/tailwind.theme.css +34 -0
- package/src/styles/loading.css +72 -0
- package/src/styles/main.css +5 -0
- package/src/styles/refreshing-content.css +55 -0
- package/src/styles/text.css +44 -0
- package/src/types/account.ts +61 -0
- package/src/types/branch.ts +6 -0
- package/src/types/category.ts +13 -0
- package/src/types/common.ts +4 -0
- package/src/types/customer.ts +52 -0
- package/src/types/dashboard.ts +18 -0
- package/src/types/edc.ts +37 -0
- package/src/types/export-e-invoice.ts +17 -0
- package/src/types/filter.d.ts +12 -0
- package/src/types/floor/floor.ts +16 -0
- package/src/types/floor.d.ts +36 -0
- package/src/types/index.ts +127 -0
- package/src/types/invoice.ts +32 -0
- package/src/types/modal.ts +15 -0
- package/src/types/notification.ts +12 -0
- package/src/types/order.ts +182 -0
- package/src/types/payment.ts +44 -0
- package/src/types/product/product.ts +47 -0
- package/src/types/product.ts +137 -0
- package/src/types/provider-info.d.ts +14 -0
- package/src/types/qr.d.ts +25 -0
- package/src/types/report.d.ts +43 -0
- package/src/types/sale.d.ts +68 -0
- package/src/types/search.d.ts +7 -0
- package/src/types/session.d.ts +30 -0
- package/src/types/shop-qr.d.ts +89 -0
- package/src/types/staff.d.ts +35 -0
- package/src/types/store.d.ts +25 -0
- package/src/types/table.d.ts +57 -0
- package/src/utils/close-session-ticket.tsx +129 -0
- package/src/utils/functions.ts +299 -0
- package/src/utils/i18n.ts +25 -0
- package/src/utils/pos/bill.ts +156 -0
- package/src/utils/pos/convert-order.ts +58 -0
- package/src/utils/pos/helpers.ts +48 -0
- package/src/utils/pos/session.ts +44 -0
- package/src/utils/storages/index.ts +1 -0
- package/src/utils/storages/local-storage.ts +72 -0
- package/tailwind.preset.ts +25 -0
- package/tsconfig.json +30 -0
- package/tsup.config.ts +30 -0
- package/dist/index.d.ts +0 -58
- package/dist/index.js +0 -145
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,803 @@
|
|
|
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
|
+
}
|