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,76 @@
|
|
|
1
|
+
import { QUERY_KEYS } from "@constants/query.constant";
|
|
2
|
+
import { useQueryParams } from "@hooks/common/use-query-params";
|
|
3
|
+
import { useKitchen } from "@provider/pos-provider/kitchen-provider";
|
|
4
|
+
import { useProduct } from "@provider/pos-provider/product-provider";
|
|
5
|
+
import { TKitchenOrder } from "@type/order";
|
|
6
|
+
import { TAttributeLine, TProduct } from "@type/product/product";
|
|
7
|
+
import { useMemo, useState } from "react";
|
|
8
|
+
|
|
9
|
+
const useOrders = () => {
|
|
10
|
+
const { getQuery } = useQueryParams();
|
|
11
|
+
const { displayDataQueryResult } = useKitchen();
|
|
12
|
+
const { data: products } = useProduct();
|
|
13
|
+
|
|
14
|
+
const displayData = useMemo(
|
|
15
|
+
() => displayDataQueryResult?.data,
|
|
16
|
+
[displayDataQueryResult]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const kitchenOrders = useMemo(() => displayData?.orders ?? [], [displayData]);
|
|
20
|
+
|
|
21
|
+
const statusId = Number(getQuery(QUERY_KEYS.KITCHEN_ORDER_STATUS));
|
|
22
|
+
|
|
23
|
+
const [searchValue, setSearchValue] = useState("");
|
|
24
|
+
|
|
25
|
+
const onSearchChange = (value: string) => {
|
|
26
|
+
setSearchValue(value);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const kitchenOrdersFiltered = useMemo(() => {
|
|
30
|
+
const productMap = new Map<number, TProduct>(
|
|
31
|
+
products?.map((item: TProduct) => [item.id, item])
|
|
32
|
+
);
|
|
33
|
+
return kitchenOrders
|
|
34
|
+
.filter((order: TKitchenOrder) => {
|
|
35
|
+
return order.stage_id === statusId;
|
|
36
|
+
})
|
|
37
|
+
.filter((order: TKitchenOrder) => {
|
|
38
|
+
return (
|
|
39
|
+
order.pos_order_id.toString().includes(searchValue) ||
|
|
40
|
+
order.orderlines.some((orderLine: any) => {
|
|
41
|
+
return (orderLine.product_name as string)
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
.includes(searchValue.toLowerCase());
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
})
|
|
47
|
+
.map((order: TKitchenOrder) => {
|
|
48
|
+
return {
|
|
49
|
+
...order,
|
|
50
|
+
orderlines: order.orderlines.map((orderLine: any) => {
|
|
51
|
+
const saleItem = productMap.get(orderLine.product_id);
|
|
52
|
+
return {
|
|
53
|
+
...orderLine,
|
|
54
|
+
pickAttributeValue: saleItem?.attributeLines?.map(
|
|
55
|
+
(attributeLine: TAttributeLine) => {
|
|
56
|
+
return {
|
|
57
|
+
...attributeLine,
|
|
58
|
+
value_string: attributeLine.value_string.filter(
|
|
59
|
+
(val: any) => orderLine.attribute_ids.includes(val.id)
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}, [kitchenOrders, products, searchValue, statusId]);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
kitchenOrdersFiltered,
|
|
72
|
+
onSearchChange,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default useOrders;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { PublishType } from "@components/pos-management/payment-content/card-payment/pos-payment/qr-connect";
|
|
2
|
+
import { ORDER_STATE } from "@constants/order-state";
|
|
3
|
+
import { QUERY_KEYS } from "@constants/query.constant";
|
|
4
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
5
|
+
import { sessionStorageUtils } from "@fctc/widget-logic/utils";
|
|
6
|
+
import { useQueryParams } from "@hooks/common/use-query-params";
|
|
7
|
+
import { usePosAppProvider } from "@provider/app-provider";
|
|
8
|
+
import { useOrderDetail } from "@provider/pos-provider/order-detail-provider";
|
|
9
|
+
import { useOrder } from "@provider/pos-provider/order-provider";
|
|
10
|
+
import { LoadDataModel } from "@provider/pos-provider/sale-provider";
|
|
11
|
+
import { useSocketData } from "@provider/pos-provider/socket-provider";
|
|
12
|
+
import { useMutation } from "@tanstack/react-query";
|
|
13
|
+
import {
|
|
14
|
+
TCheckPaymentPayload,
|
|
15
|
+
TMakePaymentPayload,
|
|
16
|
+
TPaymentInfo,
|
|
17
|
+
} from "@type/payment";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
19
|
+
import { toast } from "react-toastify";
|
|
20
|
+
|
|
21
|
+
const usePaymentProvider = () => {
|
|
22
|
+
const {
|
|
23
|
+
useAddEntity,
|
|
24
|
+
useCheckPayment,
|
|
25
|
+
useGeneratePaymentQrInfo,
|
|
26
|
+
useUpdateOrderStatus,
|
|
27
|
+
} = useService();
|
|
28
|
+
const createEntityMutation = useAddEntity().mutateAsync;
|
|
29
|
+
const checkPaymentMutation = useCheckPayment().mutateAsync;
|
|
30
|
+
const generatePaymentQrInfoMutation = useGeneratePaymentQrInfo().mutateAsync;
|
|
31
|
+
const useUpdateOrderStatusMutation = useUpdateOrderStatus().mutateAsync;
|
|
32
|
+
const { user } = usePosAppProvider();
|
|
33
|
+
const { t } = useTranslation();
|
|
34
|
+
const { getQuery } = useQueryParams();
|
|
35
|
+
|
|
36
|
+
const { updateOrder, orders, setOrders } = useOrder();
|
|
37
|
+
const { onPaymentSuccess } = useOrderDetail();
|
|
38
|
+
const xNode = user?.userProfile?.data?.x_node;
|
|
39
|
+
const service = sessionStorageUtils.getMenuFocus().service || `wesap`;
|
|
40
|
+
const menuItemId = Number(getQuery(QUERY_KEYS.POS_ID));
|
|
41
|
+
const orderIdParam = getQuery(QUERY_KEYS.ORDER_ID);
|
|
42
|
+
const sessionIdParam = getQuery(QUERY_KEYS.SESSION_ID);
|
|
43
|
+
|
|
44
|
+
const { clientMtqq, onPublish } = useSocketData();
|
|
45
|
+
const posId = getQuery(QUERY_KEYS.POS_ID);
|
|
46
|
+
const mqttConnect = localStorage.getItem(`mttqQrConnect${posId}`) ?? "";
|
|
47
|
+
const makePayment = useMutation<[number], Error, TMakePaymentPayload>({
|
|
48
|
+
mutationFn: (payload: TMakePaymentPayload) =>
|
|
49
|
+
createEntityMutation({
|
|
50
|
+
model: LoadDataModel.POS_MAKE_PAYMENT,
|
|
51
|
+
values: {
|
|
52
|
+
config_id: menuItemId,
|
|
53
|
+
payment_method_id: payload.paymentMethodId,
|
|
54
|
+
amount: payload.amount,
|
|
55
|
+
payment_name: payload.paymentName,
|
|
56
|
+
},
|
|
57
|
+
isCreateEndpoint: true,
|
|
58
|
+
service: service ?? "",
|
|
59
|
+
xNode: xNode ?? "",
|
|
60
|
+
}) as Promise<[number]>,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const checkPayment = useMutation({
|
|
64
|
+
mutationFn: (payload: TCheckPaymentPayload) =>
|
|
65
|
+
checkPaymentMutation({
|
|
66
|
+
model: LoadDataModel.POS_MAKE_PAYMENT,
|
|
67
|
+
ids: [payload.id],
|
|
68
|
+
withContext: {
|
|
69
|
+
active_model: "pos.order",
|
|
70
|
+
active_id: payload.orderId,
|
|
71
|
+
},
|
|
72
|
+
service: service ?? "",
|
|
73
|
+
xNode: xNode ?? "",
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const payment = async (
|
|
78
|
+
payload: TMakePaymentPayload & { orderId: number }
|
|
79
|
+
) => {
|
|
80
|
+
const makePaymentRes: [number] = await makePayment.mutateAsync({
|
|
81
|
+
paymentMethodId: payload.paymentMethodId,
|
|
82
|
+
amount: payload.amount,
|
|
83
|
+
paymentName: payload.paymentName,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const checkPaymentRes: any = await checkPayment.mutateAsync({
|
|
87
|
+
id: makePaymentRes[0],
|
|
88
|
+
orderId: payload.orderId,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
success: checkPaymentRes?.type === "ir.actions.act_window_close",
|
|
93
|
+
paymentId: makePaymentRes[0],
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handlePayment = async (
|
|
98
|
+
payload: TMakePaymentPayload & {
|
|
99
|
+
orderId: number;
|
|
100
|
+
receivedAmount: number;
|
|
101
|
+
}
|
|
102
|
+
) => {
|
|
103
|
+
try {
|
|
104
|
+
const { orderId, receivedAmount, amount, paymentMethodId, paymentName } =
|
|
105
|
+
payload;
|
|
106
|
+
|
|
107
|
+
const paymentResult = await payment({
|
|
108
|
+
amount: receivedAmount,
|
|
109
|
+
orderId: Number(orderId),
|
|
110
|
+
paymentMethodId: paymentMethodId,
|
|
111
|
+
paymentName: paymentName,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (paymentResult.success) {
|
|
115
|
+
onPaymentSuccess(amount);
|
|
116
|
+
} else {
|
|
117
|
+
const res = await updateOrder.mutateAsync({
|
|
118
|
+
orderId: Number(orderId),
|
|
119
|
+
amount_return: receivedAmount - amount,
|
|
120
|
+
state: ORDER_STATE.IN_PAID,
|
|
121
|
+
});
|
|
122
|
+
if (res) {
|
|
123
|
+
onPaymentSuccess(amount);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Payment failed:", error);
|
|
128
|
+
toast.error(`${t("paymentFailedTitle")}12312`);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
// ir.actions.act_window
|
|
132
|
+
const generatePaymentQrInfo = useMutation({
|
|
133
|
+
mutationFn: ({
|
|
134
|
+
amount,
|
|
135
|
+
sessionId,
|
|
136
|
+
orderId,
|
|
137
|
+
}: {
|
|
138
|
+
amount: number;
|
|
139
|
+
sessionId?: string;
|
|
140
|
+
orderId?: string;
|
|
141
|
+
}) =>
|
|
142
|
+
generatePaymentQrInfoMutation({
|
|
143
|
+
orderId: Number(orderId || orderIdParam),
|
|
144
|
+
amount,
|
|
145
|
+
posSessionId: Number(sessionId || sessionIdParam),
|
|
146
|
+
service: "wesap",
|
|
147
|
+
xNode: xNode ?? "",
|
|
148
|
+
}) as Promise<TPaymentInfo>,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const onUpdateOrderStatus = async (orderId: number) => {
|
|
152
|
+
const res = await useUpdateOrderStatusMutation({
|
|
153
|
+
orderId: orderId,
|
|
154
|
+
state: ORDER_STATE.IN_PAID,
|
|
155
|
+
xNode: dataUser?.x_node,
|
|
156
|
+
service: "wesap",
|
|
157
|
+
});
|
|
158
|
+
if (res) {
|
|
159
|
+
setOrders(
|
|
160
|
+
orders.map((order) => {
|
|
161
|
+
if (order.id === orderId) {
|
|
162
|
+
return {
|
|
163
|
+
...order,
|
|
164
|
+
state: ORDER_STATE.IN_PAID,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return order;
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return res as Promise<{
|
|
172
|
+
name: string;
|
|
173
|
+
}>;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const onGeneratePaymentQrInfo = async (
|
|
177
|
+
amount: number,
|
|
178
|
+
sessionId?: string,
|
|
179
|
+
orderId?: string
|
|
180
|
+
) => {
|
|
181
|
+
await onUpdateOrderStatus(Number(orderId || orderIdParam));
|
|
182
|
+
const data = await generatePaymentQrInfo.mutateAsync({
|
|
183
|
+
amount,
|
|
184
|
+
sessionId,
|
|
185
|
+
orderId,
|
|
186
|
+
});
|
|
187
|
+
return data;
|
|
188
|
+
};
|
|
189
|
+
const dataUser = user?.userProfile?.data;
|
|
190
|
+
const onRequestPayment = async (amount: number) => {
|
|
191
|
+
await onUpdateOrderStatus(Number(orderIdParam));
|
|
192
|
+
const data = await onUpdateOrderStatus(Number(orderIdParam));
|
|
193
|
+
if (!clientMtqq) return;
|
|
194
|
+
onPublish(
|
|
195
|
+
mqttConnect,
|
|
196
|
+
JSON.stringify({
|
|
197
|
+
payload: {
|
|
198
|
+
orderId: data?.name,
|
|
199
|
+
amount: amount,
|
|
200
|
+
topic: mqttConnect,
|
|
201
|
+
},
|
|
202
|
+
type: PublishType.Payment,
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const onPaymentSoftPos = async (amount: number) => {
|
|
208
|
+
toast.error("Chức năng đang được phát triển");
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
handlePayment,
|
|
213
|
+
onGeneratePaymentQrInfo,
|
|
214
|
+
onRequestPayment,
|
|
215
|
+
onPaymentSoftPos,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export default usePaymentProvider;
|
|
220
|
+
|
|
221
|
+
export type usePaymentProviderType = ReturnType<typeof usePaymentProvider>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
2
|
+
import { useCartStore } from "@store/states/cart.state";
|
|
3
|
+
import {
|
|
4
|
+
TAttributeLine,
|
|
5
|
+
TAttributeLineData,
|
|
6
|
+
TAttributeValueData,
|
|
7
|
+
TProduct,
|
|
8
|
+
TProductAttribute,
|
|
9
|
+
} from "@type/product/product";
|
|
10
|
+
import { getProductIdFromKey } from "@utils/functions";
|
|
11
|
+
import { useMemo } from "react";
|
|
12
|
+
|
|
13
|
+
const useProductProvider = () => {
|
|
14
|
+
const {
|
|
15
|
+
queryResult: { isLoading },
|
|
16
|
+
getData,
|
|
17
|
+
} = useSale();
|
|
18
|
+
|
|
19
|
+
const productsData = getData(LoadDataModel.PRODUCT_PRODUCT) as TProduct[];
|
|
20
|
+
const attributesValueData = getData(
|
|
21
|
+
LoadDataModel.PRODUCT_TEMPLATE_ATTRIBUTE_VALUE
|
|
22
|
+
) as TAttributeValueData[];
|
|
23
|
+
|
|
24
|
+
const attributesLinesData = getData(
|
|
25
|
+
LoadDataModel.PRODUCT_TEMPLATE_ATTRIBUTE_LINE
|
|
26
|
+
) as TAttributeLineData[];
|
|
27
|
+
|
|
28
|
+
const productAttributes = getData(
|
|
29
|
+
LoadDataModel.PRODUCT_ATTRIBUTE
|
|
30
|
+
) as TProductAttribute[];
|
|
31
|
+
|
|
32
|
+
const { activeProduct } = useCartStore();
|
|
33
|
+
|
|
34
|
+
const taxesData = getData(LoadDataModel.ACCOUNT_TAX);
|
|
35
|
+
|
|
36
|
+
const productWithImageAndTax: TProduct[] = useMemo(() => {
|
|
37
|
+
return (
|
|
38
|
+
productsData?.map((product) => {
|
|
39
|
+
const taxes = taxesData
|
|
40
|
+
?.filter((tax: any) => product?.taxes_id?.includes(tax?.id))
|
|
41
|
+
.map((tax: any) => tax?.amount || 0);
|
|
42
|
+
const temp: TAttributeLine[] =
|
|
43
|
+
product?.attribute_line_ids?.map((attributeLineId: number) => {
|
|
44
|
+
const attribute = attributesLinesData?.find(
|
|
45
|
+
(attributeLine: any) => attributeLine.id === attributeLineId
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
id: attribute?.id ?? 0,
|
|
49
|
+
name: attribute?.display_name ?? "",
|
|
50
|
+
value_string: attributesValueData
|
|
51
|
+
?.filter(
|
|
52
|
+
(attributeValue: TAttributeValueData) =>
|
|
53
|
+
attributeValue.attribute_line_id === attributeLineId
|
|
54
|
+
)
|
|
55
|
+
?.map((attributeValue: TAttributeValueData) => {
|
|
56
|
+
return attributeValue;
|
|
57
|
+
}),
|
|
58
|
+
type:
|
|
59
|
+
productAttributes?.find((attribute: TProductAttribute) =>
|
|
60
|
+
attribute?.attributeValueIds?.includes(attributeLineId)
|
|
61
|
+
)?.display_type ?? "pills",
|
|
62
|
+
};
|
|
63
|
+
}) ?? [];
|
|
64
|
+
return {
|
|
65
|
+
...product,
|
|
66
|
+
|
|
67
|
+
tax: taxes?.reduce((acc: number, tax: number) => acc + tax, 0) || 0,
|
|
68
|
+
attributeLines: temp,
|
|
69
|
+
};
|
|
70
|
+
}) || []
|
|
71
|
+
);
|
|
72
|
+
}, [productsData, taxesData]);
|
|
73
|
+
const productData: TProduct | undefined = useMemo(() => {
|
|
74
|
+
if (!productsData || !activeProduct) return;
|
|
75
|
+
|
|
76
|
+
return productWithImageAndTax?.find(
|
|
77
|
+
(item: TProduct) =>
|
|
78
|
+
item.id.toString() === getProductIdFromKey(activeProduct.id)
|
|
79
|
+
);
|
|
80
|
+
}, [productWithImageAndTax, activeProduct]);
|
|
81
|
+
return { data: productWithImageAndTax, isLoading, productData };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default useProductProvider;
|
|
85
|
+
|
|
86
|
+
export type useProductProviderType = ReturnType<typeof useProductProvider>;
|
|
87
|
+
export const defaultProductImage = "/product-default.png";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
2
|
+
|
|
3
|
+
const useCheckSession = () => {
|
|
4
|
+
const { getData } = useSale();
|
|
5
|
+
|
|
6
|
+
const onCheckSession = async () => {
|
|
7
|
+
const currentPos = getData(LoadDataModel.POS_CONFIG)?.[0];
|
|
8
|
+
|
|
9
|
+
const isSessionOpened = currentPos.pos_session_state === "opened";
|
|
10
|
+
|
|
11
|
+
return isSessionOpened;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
onCheckSession,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default useCheckSession;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
2
|
+
import { sessionStorageUtils } from "@fctc/widget-logic/utils";
|
|
3
|
+
import { usePosAppProvider } from "@provider/app-provider";
|
|
4
|
+
import { useMutation } from "@tanstack/react-query";
|
|
5
|
+
|
|
6
|
+
const useSessionProvider = () => {
|
|
7
|
+
const { useCreateSession, useHandleClosingSession, useCreatePosConfig } =
|
|
8
|
+
useService();
|
|
9
|
+
|
|
10
|
+
const createSessionMutation = useCreateSession().mutateAsync;
|
|
11
|
+
const setOpeningCashBoxMutation = useHandleClosingSession().mutateAsync;
|
|
12
|
+
const createPosConfigMutation = useCreatePosConfig().mutateAsync;
|
|
13
|
+
|
|
14
|
+
const { user } = usePosAppProvider();
|
|
15
|
+
const dataUser = user?.userProfile?.data;
|
|
16
|
+
const service = sessionStorageUtils.getMenuFocus().service || `wesap`;
|
|
17
|
+
const xNode = dataUser?.x_node || "";
|
|
18
|
+
|
|
19
|
+
const openSession = useMutation({
|
|
20
|
+
mutationFn: async (configId: number) => {
|
|
21
|
+
return await createSessionMutation({
|
|
22
|
+
configId,
|
|
23
|
+
model: "pos.session",
|
|
24
|
+
service,
|
|
25
|
+
xNode,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const setOpeningCashBox = useMutation({
|
|
31
|
+
mutationFn: ({
|
|
32
|
+
cashBoxValue,
|
|
33
|
+
sessionId,
|
|
34
|
+
}: {
|
|
35
|
+
cashBoxValue: number;
|
|
36
|
+
sessionId: number;
|
|
37
|
+
}) => {
|
|
38
|
+
return setOpeningCashBoxMutation({
|
|
39
|
+
model: "pos.session",
|
|
40
|
+
ids: [Number(sessionId)],
|
|
41
|
+
service,
|
|
42
|
+
xNode,
|
|
43
|
+
method: "set_opening_control",
|
|
44
|
+
kwargs: {
|
|
45
|
+
cashbox_value: cashBoxValue,
|
|
46
|
+
notes: "Opening cashbox",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const createPosConfig = useMutation({
|
|
53
|
+
mutationFn: async ({
|
|
54
|
+
name,
|
|
55
|
+
modulePosRestaurant,
|
|
56
|
+
}: {
|
|
57
|
+
name: string;
|
|
58
|
+
modulePosRestaurant: string;
|
|
59
|
+
}) => {
|
|
60
|
+
return await createPosConfigMutation({
|
|
61
|
+
model: "pos.config",
|
|
62
|
+
name,
|
|
63
|
+
service,
|
|
64
|
+
xNode,
|
|
65
|
+
modulePosRestaurant,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
openSession,
|
|
72
|
+
setOpeningCashBox,
|
|
73
|
+
createPosConfig,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default useSessionProvider;
|
|
78
|
+
|
|
79
|
+
export type useSessionProviderType = ReturnType<typeof useSessionProvider>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { ORDER_STATE } from "@constants/order-state";
|
|
2
|
+
import { QUERY_KEYS } from "@constants/query.constant";
|
|
3
|
+
import { useService } from "@fctc/widget-logic/provider";
|
|
4
|
+
import usePos from "@hooks/common/use-pos";
|
|
5
|
+
import { useQueryParams } from "@hooks/common/use-query-params";
|
|
6
|
+
import { useOrder } from "@provider/pos-provider/order-provider";
|
|
7
|
+
import { LoadDataModel, useSale } from "@provider/pos-provider/sale-provider";
|
|
8
|
+
import { useMutation } from "@tanstack/react-query";
|
|
9
|
+
import { TBasicTable, TCreateTablePayload, TMapedTable } from "@type/table";
|
|
10
|
+
import { t } from "i18next";
|
|
11
|
+
import { useEffect, useMemo, useState } from "react";
|
|
12
|
+
import { toast } from "react-toastify";
|
|
13
|
+
|
|
14
|
+
const usePosTableProvider = (enabled = true) => {
|
|
15
|
+
const { useCreateEntity, useUpdateEntity } = useService();
|
|
16
|
+
const createEntityMutation = useCreateEntity().mutateAsync;
|
|
17
|
+
const updateEntityMutation = useUpdateEntity().mutateAsync;
|
|
18
|
+
const { xNode, service } = usePos();
|
|
19
|
+
const { getData } = useSale();
|
|
20
|
+
const { getQuery } = useQueryParams();
|
|
21
|
+
const [tables, setTables] = useState<TBasicTable[]>([]);
|
|
22
|
+
|
|
23
|
+
const createTable = useMutation({
|
|
24
|
+
mutationFn: (payload: TCreateTablePayload) =>
|
|
25
|
+
createEntityMutation({
|
|
26
|
+
model: LoadDataModel.RESTAURANT_TABLE,
|
|
27
|
+
args: [
|
|
28
|
+
{
|
|
29
|
+
table_number: payload.tableNumber,
|
|
30
|
+
floor_id: payload.floorId,
|
|
31
|
+
seats: payload.seats,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
service: service ?? "",
|
|
35
|
+
xNode: xNode ?? "",
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const deleteTable = useMutation({
|
|
40
|
+
mutationFn: (tableId: number) =>
|
|
41
|
+
updateEntityMutation({
|
|
42
|
+
model: LoadDataModel.RESTAURANT_TABLE,
|
|
43
|
+
domain: [["id", "=", tableId]],
|
|
44
|
+
values: {
|
|
45
|
+
active: false,
|
|
46
|
+
},
|
|
47
|
+
service: service ?? "",
|
|
48
|
+
xNode: xNode ?? "",
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const updateTable = useMutation({
|
|
53
|
+
mutationFn: (payload: {
|
|
54
|
+
tableId: number;
|
|
55
|
+
tableNumber: string;
|
|
56
|
+
seats: number;
|
|
57
|
+
}) =>
|
|
58
|
+
updateEntityMutation({
|
|
59
|
+
model: LoadDataModel.RESTAURANT_TABLE,
|
|
60
|
+
domain: [["id", "=", payload.tableId]],
|
|
61
|
+
values: {
|
|
62
|
+
table_number: payload.tableNumber,
|
|
63
|
+
seats: payload.seats,
|
|
64
|
+
},
|
|
65
|
+
service: service ?? "",
|
|
66
|
+
xNode: xNode ?? "",
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const onCreateTable = async (payload: TCreateTablePayload) => {
|
|
71
|
+
const newTable = await createTable.mutateAsync(payload);
|
|
72
|
+
if (newTable) {
|
|
73
|
+
const newTableId = (newTable as any[][])?.[0]?.[0] as number;
|
|
74
|
+
setTables([
|
|
75
|
+
...tables,
|
|
76
|
+
{
|
|
77
|
+
id: newTableId,
|
|
78
|
+
table_number: payload.tableNumber,
|
|
79
|
+
floor_id: payload.floorId,
|
|
80
|
+
seats: payload.seats,
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
toast.success("Thêm bàn thành công");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const onDeleteTable = async (tableId: number, onSuccess?: () => void) => {
|
|
88
|
+
const deleteTableId = await deleteTable.mutateAsync(tableId);
|
|
89
|
+
if (deleteTableId) {
|
|
90
|
+
setTables(tables.filter((t) => t.id !== tableId));
|
|
91
|
+
toast.success(t("deleteTableSuccess"));
|
|
92
|
+
onSuccess && onSuccess();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const onUpdateTable = async (payload: {
|
|
97
|
+
tableId: number;
|
|
98
|
+
tableNumber: string;
|
|
99
|
+
seats: number;
|
|
100
|
+
onSuccess?: () => void;
|
|
101
|
+
}) => {
|
|
102
|
+
const updateTableId = await updateTable.mutateAsync(payload);
|
|
103
|
+
if (updateTableId) {
|
|
104
|
+
setTables(
|
|
105
|
+
tables.map((table) =>
|
|
106
|
+
table.id === payload.tableId
|
|
107
|
+
? {
|
|
108
|
+
...table,
|
|
109
|
+
table_number: Number(payload.tableNumber),
|
|
110
|
+
seats: payload.seats,
|
|
111
|
+
}
|
|
112
|
+
: table
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
toast.success(t("updateTableSuccess"));
|
|
116
|
+
payload.onSuccess && payload.onSuccess();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const floorId = getQuery(QUERY_KEYS.FLOOR);
|
|
120
|
+
|
|
121
|
+
const tablesByFloor = useMemo(() => {
|
|
122
|
+
const tablesFloor = floorId
|
|
123
|
+
? tables?.filter((table) => table.floor_id === Number(floorId))
|
|
124
|
+
: [];
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
id: 0,
|
|
128
|
+
table_number: 0,
|
|
129
|
+
floor_id: 0,
|
|
130
|
+
seats: 0,
|
|
131
|
+
},
|
|
132
|
+
...tablesFloor,
|
|
133
|
+
];
|
|
134
|
+
}, [tables, floorId]);
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (enabled && getData) {
|
|
138
|
+
const tables = getData(LoadDataModel.RESTAURANT_TABLE) as TBasicTable[];
|
|
139
|
+
tables && setTables(tables);
|
|
140
|
+
}
|
|
141
|
+
}, [getData]);
|
|
142
|
+
|
|
143
|
+
const { orders } = useOrder();
|
|
144
|
+
const mapTablesWithOrder: TMapedTable[] = useMemo(() => {
|
|
145
|
+
return tablesByFloor.map((table) => {
|
|
146
|
+
const isTakeAway = table.id === 0;
|
|
147
|
+
const currentOrder = orders?.find((order) => {
|
|
148
|
+
return table.id === 0
|
|
149
|
+
? false
|
|
150
|
+
: table.id?.toString() === order.table_id?.toString() &&
|
|
151
|
+
(order.state === ORDER_STATE.NEW ||
|
|
152
|
+
order.state === ORDER_STATE.IN_PAID);
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
table: {
|
|
156
|
+
id: table.id,
|
|
157
|
+
table_number: table.table_number,
|
|
158
|
+
floor_id: table.floor_id,
|
|
159
|
+
seats: table.seats,
|
|
160
|
+
},
|
|
161
|
+
isTakeAway: isTakeAway,
|
|
162
|
+
currentOrder: currentOrder
|
|
163
|
+
? {
|
|
164
|
+
id: currentOrder?.id,
|
|
165
|
+
table_id: currentOrder?.table_id,
|
|
166
|
+
state: currentOrder?.state,
|
|
167
|
+
create_date: currentOrder?.create_date,
|
|
168
|
+
pos_reference: currentOrder?.pos_reference,
|
|
169
|
+
amount_total: currentOrder?.amount_total,
|
|
170
|
+
amount_tax: currentOrder?.amount_tax,
|
|
171
|
+
user_id: currentOrder?.user_id,
|
|
172
|
+
partner_id: currentOrder?.partner_id,
|
|
173
|
+
write_date: currentOrder?.write_date,
|
|
174
|
+
lines: currentOrder?.lines,
|
|
175
|
+
}
|
|
176
|
+
: undefined,
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}, [tablesByFloor, orders]);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
tables,
|
|
183
|
+
tablesByFloor,
|
|
184
|
+
mapTablesWithOrder,
|
|
185
|
+
onCreateTable,
|
|
186
|
+
onDeleteTable,
|
|
187
|
+
onUpdateTable,
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export default usePosTableProvider;
|
|
192
|
+
|
|
193
|
+
export type usePosTableProviderType = ReturnType<typeof usePosTableProvider>;
|
package/src/index.css
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./components";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./layouts";
|
|
4
|
+
export * from "./pages";
|
|
5
|
+
export { default as PosAppProvider } from "./provider/app-provider";
|
|
6
|
+
export { default as SocketProvider } from "./provider/pos-provider/socket-provider";
|
|
7
|
+
export { default as PublicProvider } from "./provider/public-provider";
|
|
8
|
+
export { default as AppProvider } from "./router/app-router";
|
|
9
|
+
export { default as createPOSRoutes } from "./router/pos-route";
|
|
10
|
+
import "./index.css";
|