import { Component, OnInit } from '@angular/core'; import { InvoicesService } from '../../../services/invoices.service'; import { Subject } from 'rxjs'; import { ToastrService } from 'ngx-toastr'; import { BsModalService, BsModalRef } from 'ngx-bootstrap'; import { AlertModalComponent } from '../../common/alert-modal/alert-modal.component'; @Component({ selector: 'app-invoice-payments', templateUrl: './invoice-payments.component.html', styleUrls: ['./invoice-payments.component.css'] }) export class InvoicePaymentsComponent implements OnInit { tableData: any[]; dtOptions: DataTables.Settings = {}; dtTrigger: Subject = new Subject(); singleRowSelected: boolean selectedPaymentId: number bsModalRef: BsModalRef; alertConfirm: boolean; constructor(private invoiceService: InvoicesService,private modalService: BsModalService, private toastr: ToastrService,) { } ngOnInit(): void { this.loadData(); } /* @purpose: load the data into the table */ loadData() { this.invoiceService.getAllInvoicePayments().subscribe((result: { status: string, message: string, data }) => { this.tableData = result.data; for(let i=0;i { this.alertConfirm = res; if (this.alertConfirm) { this.invoiceService.deleteTheInvoicePayment(this.selectedPaymentId).subscribe((result: { status: string, message: string, data }) => { if (result.status === 'success') { var table = $('#customerPaymentsGrid').DataTable(); table.destroy(); this.loadData(); this.toastr.success('Selected payment is deleted'); } }, (error) => { var table = $('#customerPaymentsGrid').DataTable(); table.destroy(); this.loadData(); this.toastr.error('Selected payment cannot be deleted.'); }, ); } }); } }