Files
mirror-cathay/src/app/pages/appraisal/2nd-time/pdf/appraisal-2nd-time-pdf.component.ts
2023-10-10 03:58:47 +07:00

95 lines
2.3 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { BaseListComponent } from "../../../../@common/base/base-list.component";
import { lastValueFrom } from "rxjs";
import { MatDialog } from "@angular/material/dialog";
import { AppService } from "../../../../app.service";
import { API } from "../../../../@config/app";
import { Router } from "@angular/router";
import { DomSanitizer } from "@angular/platform-browser";
@Component({
selector: "app-appraisal-1st-time-index",
templateUrl: "./appraisal-2nd-time-pdf.component.html",
styleUrls: []
})
export class Appraisal2ndTimePdfComponent extends BaseListComponent implements OnInit {
pageTitle = "ใบเสนอราคา";
apiUrl: string = API.quotation;
api: any = API;
dataView: any;
pdfView: any;
constructor(
private dialog: MatDialog,
private router: Router,
public appService: AppService,
private sanitizer: DomSanitizer
) {
super();
}
async ngOnInit() {
await this.getData();
}
onAction(id?: any) {
if (id) return this.router.navigate(["/pages/appraisal/1st-time/do", "update", id]);
return this.router.navigate(["/pages/appraisal/1st-time/do", "create"]);
}
async getData($event?: any) {
try {
const data = {
doc_no: "string",
product_code: "string",
customer_name: "string",
phone_no: "string",
installment_start_date: "string",
picture: "string",
price: 0,
seller_deposit: 0,
cmfs_deposit: 0,
total_balance: 0,
installment: 0,
packing: 0,
luxury_handbag_authentication: 0,
bankfee_insurance_storage: 0,
transfer_amount: 0,
data: [
{
due_date: "string",
principle: 0,
interest_total: 0,
bank_fee: 0,
total_payment: 0,
principle_total: 0
}
],
total1: 0,
total2: 0,
total3: 0,
total4: 0
}
this.dataView = await lastValueFrom(this.appService.post(`${this.api.quotationReport}/pdf`, data, { responseType: 'arraybuffer' }));
const url = URL.createObjectURL(new Blob([this.dataView], { type: 'application/pdf' }));
this.pdfView = this.sanitizer.bypassSecurityTrustResourceUrl(url);
} catch (e) {
console.log(e);
}
}
}