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