import { Component, OnInit } from '@angular/core'; import { BulkDiscountService } from '../../services/products/bulk-discount.service'; import { CookieService } from 'ngx-cookie-service'; import { Router } from '@angular/router'; @Component({ selector: 'app-view-bulk-discounts', templateUrl: './view-bulk-discounts.component.html', styleUrls: ['./view-bulk-discounts.component.scss'] }) export class ViewBulkDiscountsComponent implements OnInit { couponCode: any; cols: any; companyId: number; bulkDiscounts: any = []; actionType: string; searchQuery:string; constructor(private bulkDiscountService: BulkDiscountService, private cookieService: CookieService, public router: Router) { } ngOnInit() { this.companyId = +this.cookieService.get('CompanyId'); this.getTableColums(); this.getBulkDiscounts(); } getTableColums() { this.cols = [ { field: '', header: '' }, { field: 'BulkDiscountName', header: 'Bulk Discount Name' }, { field: 'DiscountTypeId', header: 'Discount' }, { field: 'ExpiryDate', header: 'Expiry Date' }, { field: 'NoUses', header: 'No.Uses' }, { field: 'Status', header: 'Status' }, { field: '', header: '' } ]; } // Get bulk discount getBulkDiscounts() { this.bulkDiscountService.GetAllBulkDiscounts(this.companyId) .subscribe(res => { this.bulkDiscounts = res console.log("Bulk discount responce", res) }, error => console.log("Error", error)) } // Copy bulk discount copyBulkDiscount(id) { this.bulkDiscountService.CopyBulkDiscount(id, this.companyId) .subscribe(res => { console.log("Copy Bulk discount responce", res) this.getBulkDiscounts(); }, error => console.log("Error", error)) } // Delete bulk discount deleteBulkDiscount(id) { this.bulkDiscountService.DeleteBulkDiscount(id, this.companyId) .subscribe(res => { this.getBulkDiscounts(); console.log("Delete Bulk discount responce", res) }, error => console.log("Error", error)) } // Route to create bulk discount component CreateBulkDiscount(){ this.router.navigate(['create/bulkDiscount']) } changeStatus(doc){ this.bulkDiscountService.SaveBulkDiscount(doc, this.companyId, this.actionType = "UPDATE") .subscribe(res => { console.log("Save coupon responce", res) }, error => { console.log("Error", error) }) } }