Commit 0b2fd967 by Nattana Chaiyamat

รายงาน Excel

parent e5815db4
......@@ -4,6 +4,7 @@ import { NgbDate, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ExcelReportService } from 'src/app/service/excel-report.service';
import * as FileSaver from 'file-saver';
import { IDataOptions } from '@syncfusion/ej2-angular-pivotview';
import { Subscription } from 'rxjs';
export interface ModalDetail {
text: { cardHead: string, search: string[], tableHead: string[] }
......@@ -33,6 +34,7 @@ export class ExcelReportComponent implements OnInit {
page = 1
pageSize = 10
excelReportServiceSub?: Subscription
constructor(private route: ActivatedRoute,
private ngbModal: NgbModal,
private excelReportService: ExcelReportService,
......@@ -54,6 +56,8 @@ export class ExcelReportComponent implements OnInit {
});
}
getDataExcelReport(templateId: string, fileName: string) {
this.excelReportServiceSub?.unsubscribe()
this.loadingExcel = false
this.loading = true
this.excelReport = undefined
this.variableSheet = []
......@@ -111,6 +115,16 @@ export class ExcelReportComponent implements OnInit {
}
}
ngbtoDate(date?: NgbDate) {
if (date) {
const day = String(date.day).padStart(2, '0');
const month = String(date.month).padStart(2, '0');
const year = date.year;
return `${year}-${month}-${day}`
}
return ''
}
openModal(data: any, modal: any) {
this.searchModal = ''
this.page = 1
......@@ -146,13 +160,20 @@ export class ExcelReportComponent implements OnInit {
const param = this.excelReport.param.variableName
const data = this.variableSheet.map((item: any) => {
if (item.type == 'help') {
return "__" + item.key + "=" + item.value.id
} else if (item.type == 'calendar' || item.type == 'list' || item.type == 'radio' || item.type == 'text') {
return "__" + item.key + "=" + item.value
return "__" + item.key + "=" + this.select[item.key].id
} else if (item.type == 'list' || item.type == 'radio' || item.type == 'text') {
return "__" + item.key + "=" + this.select[item.key]
} else if (item.type == 'calendar') {
return "__" + item.key + "=" + this.ngbtoDate(this.select[item.key])
}
return ""
}).join('|')
this.excelReportService.downloadTemplateFile(fileName).subscribe((res: any) => {
const body = {
fileName: fileName,
paramObj: data
}
this.excelReportServiceSub?.unsubscribe()
this.excelReportServiceSub = this.excelReportService.printExcelReport(body).subscribe((res: any) => {
const blob = new Blob([res], { type: 'application/octet-stream' });
FileSaver.saveAs(blob, fileName);
this.loadingExcel = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment