diff --git a/src/app/_services/tableexcel.service.ts b/src/app/_services/tableexcel.service.ts index 9c9a96e..872cf76 100644 --- a/src/app/_services/tableexcel.service.ts +++ b/src/app/_services/tableexcel.service.ts @@ -208,4 +208,73 @@ export class TableexcelService { }); this.saveAsExcelFile(excelBuffer, excelFileName); } + + public exportAsExcelFileMonitoringDetail( + json: any[], + excelFileName: string, + columns: string[], + mode: any + ): void { + const filteredJson = json.map((item) => { + const filteredItem = {}; + columns.forEach((column) => { + filteredItem[column] = item[column]; + }); + return filteredItem; + }); + + const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(filteredJson); + let columnWidths = []; + if (mode === "building") { + columnWidths = [ + { wch: 30 }, + { wch: 40 }, + { wch: 30 }, + { wch: 30 }, + { wch: 30 }, + { wch: 30 }, + ]; + } else if (mode === "floor") { + columnWidths = [ + { wch: 40 }, + { wch: 30 }, + { wch: 30 }, + { wch: 30 }, + { wch: 30 }, + ]; + } else if (mode === "room") { + columnWidths = [{ wch: 30 }, { wch: 30 }, { wch: 30 }, { wch: 30 }]; + } + + worksheet["!cols"] = columnWidths; + + let header = []; + if (mode === "building") { + header = [ + "Floor", + "Room", + "Device", + "Duration", + "Price Kwh", + "Estimation Cost", + ]; + } else if (mode === "floor") { + header = ["Room", "Device", "Duration", "Price Kwh", "Estimation Cost"]; + } else if (mode === "room") { + header = ["Device", "Duration", "Price Kwh", "Estimation Cost"]; + } + + XLSX.utils.sheet_add_aoa(worksheet, [header]); + + const workbook: XLSX.WorkBook = { + Sheets: { data: worksheet }, + SheetNames: ["data"], + }; + + const excelBuffer: any = XLSX.write(workbook, { + bookType: "xlsx", + type: "array", + }); + this.saveAsExcelFile(excelBuffer, excelFileName); + } } diff --git a/src/app/content/hemat-app/monitoring/detail/detail.component.ts b/src/app/content/hemat-app/monitoring/detail/detail.component.ts index 74b0e72..3d52cdb 100644 --- a/src/app/content/hemat-app/monitoring/detail/detail.component.ts +++ b/src/app/content/hemat-app/monitoring/detail/detail.component.ts @@ -6,6 +6,8 @@ import { CurrencyPipe } from "@angular/common"; import { LoginService } from "../../service/login.service"; import { DeviceService } from "../../service/device.service"; import { color } from "echarts"; +import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; +import { ModalExportComponent } from "../modal-export/modal-export.component"; @Component({ selector: "app-detail", @@ -66,6 +68,7 @@ export class DetailComponent { private currencyPipe: CurrencyPipe, private router: Router, private authService: LoginService, + private modalService: NgbModal, ) {} get formattedSummaryCost(): string { @@ -345,6 +348,27 @@ export class DetailComponent { onChartClick(params) { console.log(params); + const modalRef = this.modalService.open(ModalExportComponent, { + size: "xl", + centered: true, + }); + modalRef.componentInstance.dataIndex = params.dataIndex; + modalRef.componentInstance.buildingId = this.buildingId; + modalRef.componentInstance.floorId = this.floorId; + modalRef.componentInstance.roomId = this.roomId; + modalRef.componentInstance.mode = this.mode; + + modalRef.result.then( + (result) => { + if (result) { + console.log(result); + + } + }, + (reason) => { + console.log(`Dismissed: ${reason}`); + } + ); // Show popup with details // alert(`Day: ${params.name}\nKWH Consumption: ${params.value}`); diff --git a/src/app/content/hemat-app/monitoring/modal-export/modal-export.component.html b/src/app/content/hemat-app/monitoring/modal-export/modal-export.component.html index bf30cfe..783a8a3 100644 --- a/src/app/content/hemat-app/monitoring/modal-export/modal-export.component.html +++ b/src/app/content/hemat-app/monitoring/modal-export/modal-export.component.html @@ -1,9 +1,17 @@ -
Room : {{ dataRow?.roomName }}
-Category : {{ dataRow?.categoryName }}
+{{ value }}
+{{ value }}
+{{ value }}
{{ value }}
+ {{ + value.toLocaleString("id-ID", { + style: "currency", + currency: "IDR" + }) + }} +
+{{ value }}
-{{ value }}
-{{ value }}
-- {{ - value.toLocaleString("id-ID", { - style: "currency", - currency: "IDR" - }) - }} -
-