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,247 @@
|
|
|
1
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
2
|
+
import useGetQuery from "@hooks/common/use-get-query";
|
|
3
|
+
|
|
4
|
+
import usePos from "@hooks/common/use-pos";
|
|
5
|
+
import { TDomainCondition } from "@provider/pos-provider/order-provider";
|
|
6
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
7
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
8
|
+
import {
|
|
9
|
+
TCustomerPayload,
|
|
10
|
+
TCustomerRes,
|
|
11
|
+
TUpdateCustomerPayload,
|
|
12
|
+
} from "@type/customer";
|
|
13
|
+
import { useMemo, useState } from "react";
|
|
14
|
+
import { useTranslation } from "react-i18next";
|
|
15
|
+
|
|
16
|
+
const useCustomerProvider = () => {
|
|
17
|
+
const { t } = useTranslation("customer");
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
useGetList,
|
|
21
|
+
useCreateEntity,
|
|
22
|
+
useUpdateEntity,
|
|
23
|
+
useGetProductImage,
|
|
24
|
+
useGetWard,
|
|
25
|
+
useGetCity,
|
|
26
|
+
useGetPartnerTitle,
|
|
27
|
+
} = useService();
|
|
28
|
+
const { getSpec } = useSale();
|
|
29
|
+
const { service, xNode } = usePos();
|
|
30
|
+
const { orderId, sessionId } = useGetQuery();
|
|
31
|
+
|
|
32
|
+
const getListMutation = useGetList().mutateAsync;
|
|
33
|
+
const getCustomerMutation = useGetProductImage().mutateAsync;
|
|
34
|
+
const createEntityMutation = useCreateEntity().mutateAsync;
|
|
35
|
+
const updateEntityMutation = useUpdateEntity().mutateAsync;
|
|
36
|
+
const getWardMutation = useGetWard().mutateAsync;
|
|
37
|
+
const getCityMutation = useGetCity().mutateAsync;
|
|
38
|
+
const getPartnerTitle = useGetPartnerTitle().mutateAsync;
|
|
39
|
+
|
|
40
|
+
const [stateId, setStateId] = useState("");
|
|
41
|
+
|
|
42
|
+
const partnerSpec = getSpec(LoadDataModel.RES_PARTNER);
|
|
43
|
+
|
|
44
|
+
const [extraDomain, setExtraDomain] = useState<TDomainCondition[]>([
|
|
45
|
+
["phone", "=", ""],
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
const queryResult = useQuery<TCustomerRes>({
|
|
49
|
+
queryKey: [
|
|
50
|
+
"get-customer",
|
|
51
|
+
service,
|
|
52
|
+
xNode,
|
|
53
|
+
sessionId,
|
|
54
|
+
extraDomain,
|
|
55
|
+
partnerSpec,
|
|
56
|
+
],
|
|
57
|
+
queryFn: () => {
|
|
58
|
+
return getListMutation({
|
|
59
|
+
model: "res.partner",
|
|
60
|
+
domain: extraDomain,
|
|
61
|
+
service: service ?? "",
|
|
62
|
+
xNode: xNode ?? "",
|
|
63
|
+
offset: 0,
|
|
64
|
+
limit: 100,
|
|
65
|
+
specification: partnerSpec,
|
|
66
|
+
}) as Promise<TCustomerRes>;
|
|
67
|
+
},
|
|
68
|
+
enabled:
|
|
69
|
+
!!service &&
|
|
70
|
+
!!xNode &&
|
|
71
|
+
!!sessionId &&
|
|
72
|
+
!!partnerSpec &&
|
|
73
|
+
!!extraDomain?.[0]?.[2],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const createCustomerMutation = useMutation({
|
|
77
|
+
mutationFn: (payload: TCustomerPayload) =>
|
|
78
|
+
createEntityMutation({
|
|
79
|
+
model: "res.partner",
|
|
80
|
+
args: [payload],
|
|
81
|
+
service: service ?? "",
|
|
82
|
+
xNode: xNode ?? "",
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const refreshListCustomer = async () => {
|
|
87
|
+
setExtraDomain([["phone", "=", ""]]);
|
|
88
|
+
await queryResult.refetch();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const createCustomer = async ({ payload }: { payload: TCustomerPayload }) => {
|
|
92
|
+
const customerId = await createCustomerMutation
|
|
93
|
+
.mutateAsync(payload)
|
|
94
|
+
.then((res) => {
|
|
95
|
+
return (res as Array<Array<number | undefined>>)[0][0];
|
|
96
|
+
});
|
|
97
|
+
if (!customerId)
|
|
98
|
+
throw new Error(t("create.add_customer_to_order.toast_error"));
|
|
99
|
+
else return customerId;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const updateCustomer = useMutation({
|
|
103
|
+
mutationFn: (payload: TUpdateCustomerPayload) =>
|
|
104
|
+
updateEntityMutation({
|
|
105
|
+
model: "res.partner",
|
|
106
|
+
domain: [["id", "=", payload.id]],
|
|
107
|
+
values: {
|
|
108
|
+
...payload,
|
|
109
|
+
},
|
|
110
|
+
service: service ?? "",
|
|
111
|
+
xNode: xNode ?? "",
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const getCustomer = useMutation({
|
|
116
|
+
mutationFn: ({ customerId }: { customerId: number }) =>
|
|
117
|
+
getCustomerMutation({
|
|
118
|
+
model: "res.partner",
|
|
119
|
+
fields: ["id", "name", "phone", "contact_address_inline", "email"],
|
|
120
|
+
limit: 10,
|
|
121
|
+
offset: 0,
|
|
122
|
+
domain: [["id", "=", customerId]],
|
|
123
|
+
service: service ?? "",
|
|
124
|
+
xNode: xNode ?? "",
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const getCityQueryResult = useQuery({
|
|
129
|
+
queryKey: ["get-city", service, xNode],
|
|
130
|
+
queryFn: () => {
|
|
131
|
+
return getCityMutation({
|
|
132
|
+
service: service ?? "",
|
|
133
|
+
xNode: xNode ?? "",
|
|
134
|
+
ids: [],
|
|
135
|
+
kwargs: {
|
|
136
|
+
count_limit: 10001,
|
|
137
|
+
domain: [["country_id", "=", 241]],
|
|
138
|
+
offset: 0,
|
|
139
|
+
order: "",
|
|
140
|
+
specification: {
|
|
141
|
+
id: {},
|
|
142
|
+
name: {},
|
|
143
|
+
display_name: {},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
enabled: !!service && !!xNode,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const cities = useMemo(() => {
|
|
152
|
+
return getCityQueryResult?.data?.records?.map((city: any) => {
|
|
153
|
+
return {
|
|
154
|
+
id: city.id,
|
|
155
|
+
name: city.name,
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
}, [getCityQueryResult?.data?.records]);
|
|
159
|
+
|
|
160
|
+
const getWardQueryResult = useQuery({
|
|
161
|
+
queryKey: ["get-ward", service, xNode, stateId],
|
|
162
|
+
queryFn: () => {
|
|
163
|
+
return getWardMutation({
|
|
164
|
+
service: service ?? "",
|
|
165
|
+
xNode: xNode ?? "",
|
|
166
|
+
kwargs: {
|
|
167
|
+
count_limit: 10001,
|
|
168
|
+
domain: [["state_id", "=", Number(stateId)]],
|
|
169
|
+
offset: 0,
|
|
170
|
+
order: "",
|
|
171
|
+
specification: {
|
|
172
|
+
id: {},
|
|
173
|
+
name: {},
|
|
174
|
+
display_name: {},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
enabled: !!service && !!xNode && !!stateId,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const wards = useMemo(() => {
|
|
183
|
+
return (
|
|
184
|
+
getWardQueryResult?.data?.records?.map((ward: any) => {
|
|
185
|
+
return {
|
|
186
|
+
id: ward.id,
|
|
187
|
+
name: ward.name,
|
|
188
|
+
};
|
|
189
|
+
}) ?? []
|
|
190
|
+
);
|
|
191
|
+
}, [getWardQueryResult?.data?.records]);
|
|
192
|
+
|
|
193
|
+
const getPartnerTitleQueryResult = useQuery({
|
|
194
|
+
queryKey: ["get-partner-title", service, xNode],
|
|
195
|
+
queryFn: () => {
|
|
196
|
+
return getPartnerTitle({
|
|
197
|
+
service: service ?? "",
|
|
198
|
+
xNode: xNode ?? "",
|
|
199
|
+
kwargs: {
|
|
200
|
+
count_limit: 10001,
|
|
201
|
+
domain: [],
|
|
202
|
+
offset: 0,
|
|
203
|
+
order: "",
|
|
204
|
+
specification: {
|
|
205
|
+
id: {},
|
|
206
|
+
name: {},
|
|
207
|
+
display_name: {},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
withContext: {
|
|
211
|
+
lang: "vi_VN",
|
|
212
|
+
tz: "Asia/Saigon",
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
enabled: !!service && !!xNode,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const partnerTitles = useMemo(() => {
|
|
220
|
+
return getPartnerTitleQueryResult?.data?.records?.map((title: any) => {
|
|
221
|
+
return {
|
|
222
|
+
id: title.id,
|
|
223
|
+
name: title.name,
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
}, [getPartnerTitleQueryResult?.data?.records]);
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
queryResult,
|
|
230
|
+
updateCustomer,
|
|
231
|
+
createCustomer,
|
|
232
|
+
setExtraDomain,
|
|
233
|
+
refreshListCustomer,
|
|
234
|
+
extraDomain,
|
|
235
|
+
orderId,
|
|
236
|
+
getCustomer,
|
|
237
|
+
cities,
|
|
238
|
+
wards,
|
|
239
|
+
partnerTitles,
|
|
240
|
+
stateId,
|
|
241
|
+
setStateId,
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export default useCustomerProvider;
|
|
246
|
+
|
|
247
|
+
export type useCustomerProviderType = ReturnType<typeof useCustomerProvider>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
2
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
3
|
+
import { usePosTable } from "@provider/pos-provider/table-provider";
|
|
4
|
+
import { useMutation } from "@tanstack/react-query";
|
|
5
|
+
import { TFloor, TTableId } from "@type/floor/floor";
|
|
6
|
+
import { isObjectEmpty } from "@utils/functions";
|
|
7
|
+
import { t } from "i18next";
|
|
8
|
+
import { useEffect, useMemo, useState } from "react";
|
|
9
|
+
import { toast } from "react-toastify";
|
|
10
|
+
const useFloorProvider = ({
|
|
11
|
+
service,
|
|
12
|
+
xNode,
|
|
13
|
+
enabled = true,
|
|
14
|
+
posConfigId,
|
|
15
|
+
}: {
|
|
16
|
+
service: string;
|
|
17
|
+
xNode: string;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
posConfigId: number;
|
|
20
|
+
}) => {
|
|
21
|
+
const { useCreateEntity, useUpdateEntity } = useService();
|
|
22
|
+
const createEntityMutation = useCreateEntity().mutateAsync;
|
|
23
|
+
const updateEntityMutation = useUpdateEntity().mutateAsync;
|
|
24
|
+
const { tables } = usePosTable();
|
|
25
|
+
const createFloor = useMutation({
|
|
26
|
+
mutationFn: ({ name }: { name: string }) => {
|
|
27
|
+
return createEntityMutation({
|
|
28
|
+
model: LoadDataModel.RESTAURANT_FLOOR,
|
|
29
|
+
args: [
|
|
30
|
+
{
|
|
31
|
+
name,
|
|
32
|
+
pos_config_ids: [posConfigId],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
service: service ?? "",
|
|
36
|
+
xNode: xNode ?? "",
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const updateFloor = useMutation({
|
|
42
|
+
mutationFn: (payload: { floorId: number; name: string }) =>
|
|
43
|
+
updateEntityMutation({
|
|
44
|
+
model: LoadDataModel.RESTAURANT_FLOOR,
|
|
45
|
+
domain: [["id", "=", payload.floorId]],
|
|
46
|
+
values: {
|
|
47
|
+
name: payload.name,
|
|
48
|
+
},
|
|
49
|
+
service: service ?? "",
|
|
50
|
+
xNode: xNode ?? "",
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const deleteFloor = useMutation({
|
|
55
|
+
mutationFn: ({ floorId }: { floorId: number }) =>
|
|
56
|
+
updateEntityMutation({
|
|
57
|
+
model: LoadDataModel.RESTAURANT_FLOOR,
|
|
58
|
+
domain: [["id", "=", floorId]],
|
|
59
|
+
values: {
|
|
60
|
+
active: false,
|
|
61
|
+
},
|
|
62
|
+
service: service ?? "",
|
|
63
|
+
xNode: xNode ?? "",
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const [floors, setFloors] = useState<TFloor[]>([]);
|
|
68
|
+
const { getData } = useSale();
|
|
69
|
+
|
|
70
|
+
const mapFloors = useMemo(() => {
|
|
71
|
+
return floors.map((floor) => {
|
|
72
|
+
const tableIds: TTableId[] = tables
|
|
73
|
+
?.filter((table) => table.floor_id === floor.id)
|
|
74
|
+
?.map((table) => {
|
|
75
|
+
return {
|
|
76
|
+
id: table.id,
|
|
77
|
+
table_number: table.table_number,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return { ...floor, table_ids: tableIds };
|
|
81
|
+
});
|
|
82
|
+
}, [floors]);
|
|
83
|
+
|
|
84
|
+
const onCreateFloor = async (name: string, onSuccess?: () => void) => {
|
|
85
|
+
try {
|
|
86
|
+
const newFloor = await createFloor.mutateAsync({ name });
|
|
87
|
+
if (newFloor) {
|
|
88
|
+
const newFloorId = (newFloor as any[][])?.[0]?.[0] as number;
|
|
89
|
+
setFloors([
|
|
90
|
+
...floors,
|
|
91
|
+
{ id: newFloorId, name, table_ids: [], pos_config_ids: [] },
|
|
92
|
+
]);
|
|
93
|
+
toast.success("Tạo tầng thành công"); //TODO
|
|
94
|
+
onSuccess && onSuccess();
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error("Create floor error:", error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const onUpdateFloor = async (
|
|
102
|
+
floorId: number,
|
|
103
|
+
name: string,
|
|
104
|
+
onSuccess?: () => void
|
|
105
|
+
) => {
|
|
106
|
+
try {
|
|
107
|
+
const updatedFloor = await updateFloor.mutateAsync({ floorId, name });
|
|
108
|
+
if (updatedFloor) {
|
|
109
|
+
setFloors(
|
|
110
|
+
floors.map((floor) => {
|
|
111
|
+
if (floor.id === floorId) {
|
|
112
|
+
return { ...floor, name };
|
|
113
|
+
}
|
|
114
|
+
return floor;
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
toast.success("Chỉnh sửa tầng thành công"); //TODO
|
|
118
|
+
onSuccess && onSuccess();
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Update floor error:", error);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const onDeleteFloor = async (floorId: number, onSuccess?: () => void) => {
|
|
126
|
+
try {
|
|
127
|
+
const deletedFloor = await deleteFloor.mutateAsync({ floorId });
|
|
128
|
+
if (deletedFloor) {
|
|
129
|
+
setFloors(floors.filter((floor) => floor.id !== floorId));
|
|
130
|
+
toast.success(t("deleteFloorSuccess"));
|
|
131
|
+
onSuccess && onSuccess();
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("Delete floor error:", error);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const tableOfOrder = (tableId: number | false, orderId: number) => {
|
|
139
|
+
const mapTable = tables.find((table) => table.id === tableId);
|
|
140
|
+
const mapFloor = mapFloors.find((floor) =>
|
|
141
|
+
floor.table_ids?.some((table) => table.id === mapTable?.id)
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
fullName: `${
|
|
145
|
+
mapFloor
|
|
146
|
+
? `${mapFloor?.name} - Bàn ${mapTable?.table_number}`
|
|
147
|
+
: `Mang đi`
|
|
148
|
+
} `,
|
|
149
|
+
floorId: mapFloor?.id ?? floors[0]?.id,
|
|
150
|
+
tableId: mapTable?.id,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (getData && enabled) {
|
|
156
|
+
const floors = getData(LoadDataModel.RESTAURANT_FLOOR) as TFloor[];
|
|
157
|
+
floors && !isObjectEmpty(floors ?? {}) && setFloors(floors);
|
|
158
|
+
}
|
|
159
|
+
}, [getData]);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
floors: mapFloors,
|
|
163
|
+
onCreateFloor,
|
|
164
|
+
onUpdateFloor,
|
|
165
|
+
onDeleteFloor,
|
|
166
|
+
tableOfOrder,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export default useFloorProvider;
|
|
171
|
+
|
|
172
|
+
export type useFloorProviderType = ReturnType<typeof useFloorProvider>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
2
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
3
|
+
|
|
4
|
+
import useGetQuery from "@hooks/common/use-get-query";
|
|
5
|
+
import usePos from "@hooks/common/use-pos";
|
|
6
|
+
import { usePosAppProvider } from "@provider/app-provider";
|
|
7
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
8
|
+
import { TChangeOrderStatusPayload } from "@type/order";
|
|
9
|
+
import { useEffect, useMemo, useState } from "react";
|
|
10
|
+
import { useParams } from "react-router-dom";
|
|
11
|
+
|
|
12
|
+
const useKitchenProvider = () => {
|
|
13
|
+
const { useGetPreparationDisplayData, useChangeOrderPreparationState } =
|
|
14
|
+
useService();
|
|
15
|
+
|
|
16
|
+
const getPreparationDisplayDataMutation =
|
|
17
|
+
useGetPreparationDisplayData().mutateAsync;
|
|
18
|
+
const changeOrderPreparationStateMutation =
|
|
19
|
+
useChangeOrderPreparationState().mutateAsync;
|
|
20
|
+
const [mapKitchenWithPOS, setMapKitchenWithPOS] = useState<any>(null);
|
|
21
|
+
const params = useParams();
|
|
22
|
+
const { service, xNode } = usePos();
|
|
23
|
+
const { posId } = useGetQuery();
|
|
24
|
+
|
|
25
|
+
const { getData } = useSale();
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setMapKitchenWithPOS(
|
|
29
|
+
getData(LoadDataModel.POS_PREPARATION_DISPLAY_DISPLAY)
|
|
30
|
+
);
|
|
31
|
+
}, [getData]);
|
|
32
|
+
|
|
33
|
+
const isPosMapKitchen = useMemo(() => {
|
|
34
|
+
return !!mapKitchenWithPOS;
|
|
35
|
+
}, [mapKitchenWithPOS, posId]);
|
|
36
|
+
|
|
37
|
+
const kitchenId = posId ? mapKitchenWithPOS?.id : Number(params.kitchenId);
|
|
38
|
+
const { user } = usePosAppProvider();
|
|
39
|
+
const displayDataQueryResult = useQuery<any>({
|
|
40
|
+
queryKey: ["get-display-data", service, xNode, kitchenId],
|
|
41
|
+
queryFn: () => {
|
|
42
|
+
return getPreparationDisplayDataMutation({
|
|
43
|
+
ids: kitchenId,
|
|
44
|
+
service: service ?? "",
|
|
45
|
+
xNode: xNode ?? "",
|
|
46
|
+
withContext: {
|
|
47
|
+
uid: user?.userProfile?.data?.sub,
|
|
48
|
+
lang: "vi_VN",
|
|
49
|
+
tz: "Asia/Saigon",
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
enabled: !!service && !!xNode && !!kitchenId,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const changeOrderPreparationState = useMutation({
|
|
57
|
+
mutationFn: (payload: TChangeOrderStatusPayload) => {
|
|
58
|
+
return changeOrderPreparationStateMutation({
|
|
59
|
+
orderId: payload.orderId,
|
|
60
|
+
service: service ?? "",
|
|
61
|
+
xNode: xNode ?? "",
|
|
62
|
+
stageId: payload.stageId,
|
|
63
|
+
preparationDisplayId: payload.preparationDisplayId,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
displayDataQueryResult,
|
|
70
|
+
displayDataRefresh: displayDataQueryResult.refetch,
|
|
71
|
+
changeOrderPreparationState,
|
|
72
|
+
isPosMapKitchen,
|
|
73
|
+
mapKitchenWithPOS,
|
|
74
|
+
setMapKitchenWithPOS,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default useKitchenProvider;
|
|
79
|
+
|
|
80
|
+
export type useKitchenProviderType = ReturnType<typeof useKitchenProvider>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useSale, LoadDataModel } from "@provider/pos-provider/sale-provider";
|
|
3
|
+
import { isObjectEmpty } from "@utils/functions";
|
|
4
|
+
|
|
5
|
+
const useGetPointReward = ({
|
|
6
|
+
totalAmountWithoutTax,
|
|
7
|
+
}: {
|
|
8
|
+
totalAmountWithoutTax: number;
|
|
9
|
+
}) => {
|
|
10
|
+
const saleData = useSale();
|
|
11
|
+
|
|
12
|
+
const loyaltyProgram = useMemo(() => {
|
|
13
|
+
if (!saleData) return;
|
|
14
|
+
|
|
15
|
+
return saleData.getData(LoadDataModel.LOYALTY_PROGRAM);
|
|
16
|
+
}, [saleData]);
|
|
17
|
+
|
|
18
|
+
const loyaltyRule = useMemo(() => {
|
|
19
|
+
if (!saleData) return;
|
|
20
|
+
|
|
21
|
+
return saleData.getData(LoadDataModel.LOYALTY_RULE);
|
|
22
|
+
}, [saleData]);
|
|
23
|
+
|
|
24
|
+
const rewardId = useMemo(() => {
|
|
25
|
+
if (!loyaltyProgram) return;
|
|
26
|
+
|
|
27
|
+
return loyaltyProgram?.[0]?.reward_ids[0];
|
|
28
|
+
}, [loyaltyProgram]);
|
|
29
|
+
|
|
30
|
+
const amount = useMemo(() => {
|
|
31
|
+
if (!loyaltyRule || isObjectEmpty(loyaltyRule)) return;
|
|
32
|
+
const ruleMatched = loyaltyRule.find((rule: any) => rule.id === rewardId);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
minimumAmount: ruleMatched.minimum_amount,
|
|
36
|
+
rewardPointAmount: ruleMatched.reward_point_amount,
|
|
37
|
+
};
|
|
38
|
+
}, [loyaltyRule, rewardId]);
|
|
39
|
+
|
|
40
|
+
const pointReward =
|
|
41
|
+
amount?.minimumAmount && amount?.rewardPointAmount
|
|
42
|
+
? Math.floor(totalAmountWithoutTax * amount.rewardPointAmount)
|
|
43
|
+
: 0;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
pointReward,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default useGetPointReward;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ORDER_STATE } from "@constants/order-state";
|
|
2
|
+
import { useOrder } from "@provider/pos-provider/order-provider";
|
|
3
|
+
import { useSale } from "@provider/pos-provider/sale-provider";
|
|
4
|
+
import { useEffect, useMemo } from "react";
|
|
5
|
+
|
|
6
|
+
const useLoopFetchOrder = () => {
|
|
7
|
+
const { orderDetailById, onPaymentSuccess } = useOrder();
|
|
8
|
+
const { queryResult } = useSale();
|
|
9
|
+
|
|
10
|
+
const orderState = useMemo(() => {
|
|
11
|
+
return orderDetailById?.state;
|
|
12
|
+
}, [orderDetailById]);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const interval = setInterval(() => {
|
|
16
|
+
if (
|
|
17
|
+
orderState === ORDER_STATE.IN_PAID ||
|
|
18
|
+
orderState === ORDER_STATE.NEW
|
|
19
|
+
) {
|
|
20
|
+
queryResult.refetch();
|
|
21
|
+
}
|
|
22
|
+
}, 3000);
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
clearInterval(interval);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default useLoopFetchOrder;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useOrder } from "@provider/pos-provider/order-provider";
|
|
2
|
+
import { useProduct } from "@provider/pos-provider/product-provider";
|
|
3
|
+
import { useSale } from "@provider/pos-provider/sale-provider";
|
|
4
|
+
import { useQuery } from "@tanstack/react-query";
|
|
5
|
+
import { OrderDetailItemType } from "@type/index";
|
|
6
|
+
import { TProduct } from "@type/product/product";
|
|
7
|
+
import { useMemo } from "react";
|
|
8
|
+
|
|
9
|
+
export const useOrderItems = () => {
|
|
10
|
+
const { getOrderLine, orderDetailById } = useOrder();
|
|
11
|
+
const { data: products, isLoading } = useProduct();
|
|
12
|
+
const {
|
|
13
|
+
queryResult: { data: saleData },
|
|
14
|
+
} = useSale();
|
|
15
|
+
|
|
16
|
+
const lines = useMemo(() => orderDetailById?.lines, [orderDetailById]);
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
data: orderLines,
|
|
20
|
+
isLoading: orderLinesLoading,
|
|
21
|
+
refetch,
|
|
22
|
+
} = useQuery<any>({
|
|
23
|
+
queryKey: ["orderItems", lines, products],
|
|
24
|
+
queryFn: () => getOrderLine.mutateAsync(lines as number[]),
|
|
25
|
+
enabled: !!lines && !!products,
|
|
26
|
+
});
|
|
27
|
+
const items: OrderDetailItemType[] = useMemo(() => {
|
|
28
|
+
const productMap = new Map<number, TProduct>(
|
|
29
|
+
products?.map((item: TProduct) => [item.id, item])
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
orderLines?.map((item: any) => {
|
|
34
|
+
const saleItem = productMap.get(item.product_id);
|
|
35
|
+
const res: OrderDetailItemType = {
|
|
36
|
+
id: item.product_id,
|
|
37
|
+
name: saleItem?.name || item.name || "Sản phẩm",
|
|
38
|
+
quantity: item.qty,
|
|
39
|
+
price: item.price_unit,
|
|
40
|
+
image: saleItem?.image_128 || "",
|
|
41
|
+
unitPrice: item.price_unit,
|
|
42
|
+
subTotal: item.price_subtotal,
|
|
43
|
+
inchTotal: item.price_subtotal_incl,
|
|
44
|
+
taxesId: item.tax_ids,
|
|
45
|
+
lineId: item.id,
|
|
46
|
+
tax: saleItem?.tax || 0,
|
|
47
|
+
attributeValueIds: item.attribute_value_ids,
|
|
48
|
+
};
|
|
49
|
+
return res;
|
|
50
|
+
}) || []
|
|
51
|
+
);
|
|
52
|
+
}, [orderLines, products]);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
items,
|
|
56
|
+
isLoading: orderLinesLoading || isLoading,
|
|
57
|
+
// staffName: saleData?.["res.users"]?.data,
|
|
58
|
+
customerName: saleData?.["res.partner"]?.data,
|
|
59
|
+
refetchOrderLines: refetch,
|
|
60
|
+
};
|
|
61
|
+
};
|