From 168c19386dbe39e1718ce2c98f21771272c5e642 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:16:43 +0530 Subject: [PATCH] feat: add coupon code modal --- src/pages/POS/POS.vue | 163 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 19 deletions(-) diff --git a/src/pages/POS/POS.vue b/src/pages/POS/POS.vue index a0a2855d..153626c8 100644 --- a/src/pages/POS/POS.vue +++ b/src/pages/POS/POS.vue @@ -36,6 +36,11 @@ @toggle-modal="toggleModal" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + Coupon Code + + + {{ appliedCouponsCount }} + + @@ -430,10 +556,16 @@ import { validateSinv, } from 'src/utils/pos'; import Barcode from 'src/components/Controls/Barcode.vue'; -import { getAddedLPWithGrandTotal, getPricingRule } from 'models/helpers'; +import { + getAddedLPWithGrandTotal, + getPricingRule, + removeFreeItems, +} from 'models/helpers'; import LoyaltyProgramModal from './LoyaltyprogramModal.vue'; import AlertModal from './AlertModal.vue'; import SavedInvoiceModal from './SavedInvoiceModal.vue'; +import CouponCodeModal from './CouponCodeModal.vue'; +import { AppliedCouponCodes } from 'models/baseModels/AppliedCouponCodes/AppliedCouponCodes'; export default defineComponent({ name: 'POS', @@ -451,6 +583,7 @@ export default defineComponent({ PaymentModal, LoyaltyProgramModal, SavedInvoiceModal, + CouponCodeModal, SelectedItemTable, Barcode, }, @@ -463,6 +596,8 @@ export default defineComponent({ itemQtyMap: computed(() => this.itemQtyMap), itemSerialNumbers: computed(() => this.itemSerialNumbers), sinvDoc: computed(() => this.sinvDoc), + appliedCoupons: computed(() => this.sinvDoc.coupons), + coupons: computed(() => this.coupons), totalTaxedAmount: computed(() => this.totalTaxedAmount), transferAmount: computed(() => this.transferAmount), transferClearanceDate: computed(() => this.transferClearanceDate), @@ -479,6 +614,8 @@ export default defineComponent({ openPaymentModal: false, openLoyaltyProgramModal: false, openSavedInvoiceModal: false, + openCouponCodeModal: false, + openAppliedCouponsModal: false, openShiftCloseModal: false, openShiftOpenModal: false, openRouteToInvoiceListModal: false, @@ -495,6 +632,9 @@ export default defineComponent({ appliedLoyaltyPoints: 0, loyaltyProgram: '' as string, + appliedCoupons: [] as AppliedCouponCodes[], + appliedCouponsCount: 0, + defaultCustomer: undefined as string | undefined, itemSearchTerm: '', transferRefNo: undefined as string | undefined, @@ -505,6 +645,7 @@ export default defineComponent({ itemSerialNumbers: {} as ItemSerialNumbers, paymentDoc: {} as Payment, sinvDoc: {} as SalesInvoice, + coupons: {} as AppliedCouponCodes, }; }, computed: { @@ -543,6 +684,7 @@ export default defineComponent({ deep: true, }, }, + async mounted() { await this.setItems(); }, @@ -691,23 +833,6 @@ export default defineComponent({ setTransferRefNo(ref: string) { this.transferRefNo = ref; }, - removeFreeItems() { - if (!this.sinvDoc || !this.sinvDoc.items) { - return; - } - - if (!!this.sinvDoc.isPricingRuleApplied) { - return; - } - - for (const item of this.sinvDoc.items) { - if (item.isFreeItem) { - this.sinvDoc.items = this.sinvDoc.items?.filter( - (invoiceItem) => invoiceItem.name !== item.name - ); - } - } - }, async addItem(item: POSItem | Item | undefined) { // eslint-disable-next-line @typescript-eslint/no-floating-promises @@ -940,7 +1065,7 @@ export default defineComponent({ if (!hasPricingRules || !hasPricingRules.length) { this.sinvDoc.pricingRuleDetail = undefined; this.sinvDoc.isPricingRuleApplied = false; - this.removeFreeItems(); + removeFreeItems(this.sinvDoc as SalesInvoice); return; }