[init] init version
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { ChangeDetectorRef, Component, OnInit } from "@angular/core";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
import { AppService } from "../../../../app.service";
|
||||
import { API, STORAGE } from "../../../../@config/app";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { DomSanitizer } from "@angular/platform-browser";
|
||||
import { BaseFormComponent } from "../../../../@common/base/base-form.component";
|
||||
import { IQuotation } from "../../../../@common/interface/Quotation";
|
||||
import { format, parseISO } from "date-fns";
|
||||
|
||||
@Component({
|
||||
selector: "app-appraisal-1st-time-index",
|
||||
templateUrl: "./appraisal-1st-time-pdf.component.html",
|
||||
styleUrls: []
|
||||
})
|
||||
export class Appraisal1stTimePdfComponent extends BaseFormComponent implements OnInit {
|
||||
|
||||
pageTitle = "ใบเสนอราคา";
|
||||
apiUrl: string = API.quotation;
|
||||
api: any = API;
|
||||
dataView: any;
|
||||
pdfView: any;
|
||||
|
||||
|
||||
constructor(
|
||||
public activatedRoute: ActivatedRoute,
|
||||
public router: Router,
|
||||
public changeDetectorRef: ChangeDetectorRef,
|
||||
public appService: AppService,
|
||||
private sanitizer: DomSanitizer
|
||||
) {
|
||||
super();
|
||||
|
||||
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.activatedRoute.params.subscribe(async params => {
|
||||
this.ids = params["id"];
|
||||
await this.getData();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async getData() {
|
||||
try {
|
||||
const quotation : IQuotation = await lastValueFrom(this.appService.get(`${this.api.quotation}/getById/${this.ids}`));
|
||||
const startDate = quotation.startDate ? format(parseISO(quotation.startDate), "dd/MM/yyyy") : null;
|
||||
const customerPrefix = quotation.customerPrefix ? quotation.customerPrefix : '';
|
||||
const customerName = quotation.customerId ? `${quotation.customer?.prefix} ${quotation.customer?.firstName} ${quotation.customer?.lastName}` :
|
||||
`${customerPrefix} ${quotation.customerFirstName} ${quotation.customerLastName}`;
|
||||
|
||||
const data = {
|
||||
doc_no: quotation.quotationNo,
|
||||
product_code: quotation.productNo,
|
||||
type_code: quotation.typeCode,
|
||||
customer_name: customerName,
|
||||
phone_no: quotation.customerPhone,
|
||||
installment_start_date: startDate,
|
||||
picture: `${STORAGE.products}/${quotation.coverImage}`,
|
||||
price: Number(quotation.price),
|
||||
seller_deposit: Number(quotation.sellerDeposit),
|
||||
cmfs_deposit: Number(quotation.cmfsDeposit),
|
||||
total_balance: Number(quotation.principalBalanceTotal),
|
||||
installment: Number(quotation.wantToInstallmentTerm),
|
||||
packing: Number(quotation.plusPacking),
|
||||
luxury_handbag_authentication: Number(quotation.plusLuxuryHandbag),
|
||||
bankfee_insurance_storage: Number(quotation.plusBankFee),
|
||||
transfer_amount: Number(quotation.transferSummary),
|
||||
discount: Number(quotation.discount),
|
||||
data: [],
|
||||
total1: 0,
|
||||
total2: 0,
|
||||
total3: 0,
|
||||
total4: 0
|
||||
}
|
||||
const quotationDetail: any = [];
|
||||
quotation.quotationDetail?.map(item => {
|
||||
const dueDate = item.dueDate ? format(parseISO(item.dueDate), "dd/MM/yyyy") : null;
|
||||
const map = {
|
||||
due_date: dueDate,
|
||||
principle: Number(item.principle),
|
||||
interest_total: Number(item.interestTotal),
|
||||
bank_fee: Number(item.fee),
|
||||
total_payment: Number(item.totalPayment),
|
||||
principle_total: Number(item.principleTotal)
|
||||
}
|
||||
quotationDetail.push(map);
|
||||
})
|
||||
|
||||
data.data = quotationDetail;
|
||||
|
||||
const pdf = await lastValueFrom(this.appService.post(`${this.api.quotationReport}/pdf`, data, { responseType: "arraybuffer" }));
|
||||
const url = URL.createObjectURL(new Blob([pdf], { type: "application/pdf" }));
|
||||
this.pdfView = this.sanitizer.bypassSecurityTrustResourceUrl(url);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user