diff --git a/app/components/pos/CartItem.vue b/app/components/pos/CartItem.vue
index 2a8a97b..981440b 100644
--- a/app/components/pos/CartItem.vue
+++ b/app/components/pos/CartItem.vue
@@ -2,6 +2,7 @@
const props = defineProps({
cartItem: Object,
deleteable: Boolean,
+ invalid: Boolean,
});
const { $deleteapi, $formatNum, $snackbar } = useNuxtApp();
const { getCarts } = inject("pos");
@@ -30,7 +31,12 @@ async function removeFromCart() {
-
+ IMEI sản phẩm
+ {{ cartItem.imei__imei }}
+ không có sẵn
+
diff --git a/app/components/pos/ConfirmOrder.vue b/app/components/pos/ConfirmOrder.vue
index 32f40ba..bb74f1e 100644
--- a/app/components/pos/ConfirmOrder.vue
+++ b/app/components/pos/ConfirmOrder.vue
@@ -4,10 +4,13 @@ import usePlaceOrder from "~/components/pos/composables/usePlaceOrder";
const id = "confirmOrderModal";
const emit = defineEmits(["close"]);
-const { activeCart, activeCartItems, orderInfo, fullAddress, getCarts, subtotal, total } = inject("pos");
+const { activeCart, activeCartItems, invalidCartItems, orderInfo, fullAddress, getCarts, subtotal, total } =
+ inject("pos");
+
const { isPending, showVietQRModal, placeOrder, testReturnPage } = usePlaceOrder({
activeCart,
activeCartItems,
+ invalidCartItems,
orderInfo,
fullAddress,
subtotal,
@@ -56,6 +59,7 @@ const { isPending, showVietQRModal, placeOrder, testReturnPage } = usePlaceOrder
v-for="cartItem in activeCartItems"
:key="cartItem.id"
:cartItem="cartItem"
+ :invalid="invalidCartItems.find((ci) => ci.id === cartItem.id)"
/>
prev + curr.imei__variant__price, 0);
});
- return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal };
+ const invalidCartItems = ref([]);
+
+ watch(activeCartId, () => {
+ invalidCartItems.value = [];
+ });
+ return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal, invalidCartItems };
}
diff --git a/app/components/pos/composables/usePlaceOrder.js b/app/components/pos/composables/usePlaceOrder.js
index 44f85f1..b6b0252 100644
--- a/app/components/pos/composables/usePlaceOrder.js
+++ b/app/components/pos/composables/usePlaceOrder.js
@@ -1,6 +1,7 @@
export default function usePlaceOrder({
activeCart,
activeCartItems,
+ invalidCartItems,
orderInfo,
fullAddress,
subtotal,
@@ -16,6 +17,22 @@ export default function usePlaceOrder({
const payment_record = ref();
const showVietQRModal = ref();
+ async function checkImeiAvai() {
+ const imeisSold = await $getdata("IMEI_Sold");
+ const invalidImeis = [];
+
+ for (const cartItem of activeCartItems.value) {
+ if (imeisSold.find((sold) => sold.imei === cartItem.imei__imei)) {
+ invalidImeis.push(cartItem);
+ }
+ }
+
+ return {
+ allAvailable: invalidImeis.length === 0,
+ invalidImeis,
+ };
+ }
+
/**
* Create a record in `invoice` as `pending`
*/
@@ -193,6 +210,14 @@ export default function usePlaceOrder({
}
async function placeOrder() {
+ const { allAvailable, invalidImeis } = await checkImeiAvai();
+ if (!allAvailable) {
+ invalidCartItems.value = invalidImeis;
+ console.error("IMEIs not available", invalidImeis);
+ $snackbar("Một số IMEI đã được bán, vui lòng kiểm tra lại", "Error");
+ return;
+ }
+
await createOrder();
if (orderInfo.value.paymentMethod.code === "CASH") {
diff --git a/app/components/snackbar/Error.vue b/app/components/snackbar/Error.vue
index 119ff8f..d498ab8 100644
--- a/app/components/snackbar/Error.vue
+++ b/app/components/snackbar/Error.vue
@@ -9,7 +9,7 @@