23 lines
900 B
JavaScript
23 lines
900 B
JavaScript
import { without } from "es-toolkit";
|
|
|
|
export default function useActiveCart() {
|
|
const posStore = usePosStore();
|
|
const { carts, cartItems, customers, activeCartId } = storeToRefs(posStore);
|
|
|
|
const activeCart = computed(() => carts.value.find((c) => c.id === activeCartId.value));
|
|
const activeCartItems = computed(() => cartItems.value.filter((ci) => ci.cart === activeCartId.value));
|
|
|
|
const customerIdsWithNoCart = computed(() => {
|
|
const cusIds = customers.value.map((c) => c.id);
|
|
const cusIdsWithCart = carts.value.filter((c) => c.customer).map((c) => c.customer);
|
|
const cusIdsWithNoCart = without(cusIds, ...cusIdsWithCart);
|
|
return cusIdsWithNoCart;
|
|
});
|
|
|
|
const subtotal = computed(() => {
|
|
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
|
});
|
|
|
|
return { activeCart, activeCartItems, customerIdsWithNoCart, subtotal };
|
|
}
|