{ "version": 3, "sources": ["src/app/shared/components/coupon-card/service/coupon.service.ts", "src/app/shared/components/coupon-card/coupon-card.component.ts", "src/app/shared/components/coupon-card/coupon-card.component.html"], "sourcesContent": ["import { PromoCodeService } from 'src/app/proxy/services';\r\nimport { TosterService } from '../../../services/toster.service';\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class CouponService {\r\n constructor(\r\n private TosterService: TosterService,\r\n private PromoCodeService: PromoCodeService\r\n ) {}\r\n\r\n applyCouponToDiscount(\r\n code: string,\r\n bookingInfo: any,\r\n onSuccess: (updatedBookingInfo: any, discountInfo: any) => void\r\n ): void {\r\n console.log(code, bookingInfo);\r\n\r\n if (!bookingInfo) {\r\n this.TosterService.customToast('Booking information is invalid', 'error');\r\n return;\r\n }\r\n let discountInfo = {};\r\n this.PromoCodeService.getByName(code).subscribe({\r\n next: (res) => {\r\n discountInfo = res;\r\n if (!res.discountAmount || !res.discountAmountIn) {\r\n this.TosterService.customToast('Invalid coupon data', 'error');\r\n return;\r\n }\r\n\r\n let updatedBookingInfo = { ...bookingInfo };\r\n\r\n switch (res.discountAmountIn) {\r\n case 1: // Fixed discount\r\n if (bookingInfo.totalAppointmentFee < res.discountAmount) {\r\n this.TosterService.customToast(\r\n 'Discount amount exceeds the total appointment fee!',\r\n 'error'\r\n );\r\n return;\r\n }\r\n\r\n updatedBookingInfo.totalAppointmentFee =\r\n bookingInfo.totalAppointmentFee - res.discountAmount;\r\n\r\n this.TosterService.customToast(\r\n `Coupon applied! Discount: ${res.discountAmount}`,\r\n 'success'\r\n );\r\n break;\r\n\r\n case 2: // Percentage discount\r\n const percentageDiscount =\r\n (bookingInfo.totalAppointmentFee * res.discountAmount) / 100;\r\n\r\n if (bookingInfo.totalAppointmentFee < percentageDiscount) {\r\n this.TosterService.customToast(\r\n 'Discount exceeds the total appointment fee!',\r\n 'error'\r\n );\r\n return;\r\n }\r\n\r\n updatedBookingInfo.totalAppointmentFee =\r\n bookingInfo.totalAppointmentFee - percentageDiscount;\r\n\r\n this.TosterService.customToast(\r\n `Coupon applied! Discount: ${res.discountAmount}%`,\r\n 'success'\r\n );\r\n break;\r\n\r\n default:\r\n this.TosterService.customToast('Invalid discount type', 'error');\r\n return;\r\n }\r\n\r\n // Ensure totalAppointmentFee doesn't drop below 0\r\n if (updatedBookingInfo.totalAppointmentFee < 0) {\r\n updatedBookingInfo.totalAppointmentFee = 0;\r\n }\r\n\r\n // Call the success callback\r\n onSuccess(updatedBookingInfo, discountInfo);\r\n },\r\n error: (err) => {\r\n console.log('Error applying coupon:', err);\r\n this.TosterService.customToast(\r\n 'Failed to apply coupon. Please try again.',\r\n 'error'\r\n );\r\n },\r\n });\r\n }\r\n}\r\n", "import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';\r\nimport { AppointmentInputDto } from 'src/app/proxy/dto-models';\r\nimport { PromoCodeInputDto } from 'src/app/proxy/input-dto';\r\nimport { CouponService } from './service/coupon.service';\r\n\r\n@Component({\r\n selector: 'app-coupon-card',\r\n standalone: true,\r\n imports: [],\r\n templateUrl: './coupon-card.component.html',\r\n styleUrl: './coupon-card.component.scss',\r\n})\r\nexport class CouponCardComponent implements OnChanges {\r\n previousTotalFee: number = 0;\r\n disableApplyButton: boolean = false;\r\n @Input() bookingInfo: AppointmentInputDto = {} as AppointmentInputDto;\r\n discount!: PromoCodeInputDto;\r\n constructor(private CouponService: CouponService) {}\r\n ngOnChanges(changes: SimpleChanges): void {\r\n if (changes['bookingInfo'] && changes['bookingInfo'].currentValue) {\r\n this.previousTotalFee =\r\n changes['bookingInfo'].currentValue.totalAppointmentFee;\r\n }\r\n }\r\n applyCoupon(coupon: string) {\r\n this.CouponService.applyCouponToDiscount(\r\n coupon,\r\n this.bookingInfo,\r\n (updatedBookingInfo: any, discountInfo: PromoCodeInputDto) => {\r\n this.bookingInfo = updatedBookingInfo;\r\n this.discount = discountInfo;\r\n this.disableApplyButton = true;\r\n console.log('Updated Booking Info:', this.bookingInfo);\r\n }\r\n );\r\n }\r\n}\r\n", "@if (bookingInfo && (bookingInfo.totalAppointmentFee == 0 ||\r\nbookingInfo.totalAppointmentFee)) { @if (bookingInfo.totalAppointmentFee !== 0)\r\n{\r\n