Commit 0739bfd3 by Nattana Chaiyamat

รายงาน Excel

parent 1b24c5f5
......@@ -53,6 +53,7 @@ import { ReportPms1Component } from '../report-component/report-pms/report-pms-1
import { ReportPms2Component } from '../report-component/report-pms/report-pms-2/report-pms-2.component';
import { ReportPms3Component } from '../report-component/report-pms/report-pms-3/report-pms-3.component';
import { EssProfileComponent } from '../ess-profile/ess-profile.component';
import { ExcelReportComponent } from '../excel-report/excel-report.component';
......@@ -117,7 +118,8 @@ const routes: Routes = [
{ path: "admin/report-com-3", title: 'report-com-3', component: ReportCom3Component },
{ path: "admin/report-pms-1", title: 'report-pms-1', component: ReportPms1Component },
{ path: "admin/report-pms-2", title: 'report-pms-2', component: ReportPms2Component },
{ path: "admin/report-pms-3", title: 'report-pms-3', component: ReportPms3Component }
{ path: "admin/report-pms-3", title: 'report-pms-3', component: ReportPms3Component },
{ path: "admin/excel-export/:id", title: 'รายงาน Excel', component: ExcelReportComponent }
]
}
];
......
......@@ -187,6 +187,7 @@ import { ReportPms1Component } from '../report-component/report-pms/report-pms-1
import { ReportPms2Component } from '../report-component/report-pms/report-pms-2/report-pms-2.component';
import { ReportPms3Component } from '../report-component/report-pms/report-pms-3/report-pms-3.component';
import { EssProfileComponent } from '../ess-profile/ess-profile.component';
import { ExcelReportComponent } from '../excel-report/excel-report.component';
export const MY_DATE_FORMATS = {
parse: {
......@@ -330,7 +331,8 @@ export class CustomDateAdapter extends NativeDateAdapter {
ReportPms1Component,
ReportPms2Component,
ReportPms3Component,
EssProfileComponent
EssProfileComponent,
ExcelReportComponent
],
imports: [
CommonModule,
......@@ -406,6 +408,7 @@ export class CustomDateAdapter extends NativeDateAdapter {
EmpStatusService,
ConfigPermissionService,
TokenService,
{
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptor,
......
<app-page-header [pathTitle]="pathTitle"></app-page-header>
<div class="bg-card-white">
</div>
<div class="block-main-content">
<div class="font-size-18px font-weight-700 pt-1.5rem text-primary px-2rem">
รายงาน Excel
</div>
<div class="page pt-0.75rem">
<div class="mt-3 px-2rem !-mt-3 pt-50px">
<div class="page px-rem">
<div class="flex justify-center" *ngIf="loading">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1" role="status"
aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</div>
<ng-container *ngIf="!loading">
<ng-container *ngFor="let item of variableSheet; let i=index">
<div class="grid grid-cols-12 gap-x-6 mb-2">
<label class="col-span-4 ti-form-label text-primary mt-2 align-center text-right">
{{item.label}}
</label>
<div class="col-span-8 md:col-span-4" [class.ti-pagination]="item.type=='radio'">
<ng-container *ngIf="item.type=='text'">
<input type="text" class="ti-form-input h-16" [(ngModel)]="item.value">
</ng-container>
<ng-container *ngIf="item.type=='list'">
<select class="ti-form-select h-16" [(ngModel)]="item.value">
<option *ngFor="let list of item.option" [value]="list.value">
{{list.text}}
</option>
</select>
</ng-container>
<ng-container *ngIf="item.type=='radio'">
<div class="grid grid-cols-6 gap-2 h-16">
<ng-container *ngFor="let radioItem of item.option;let i = index">
<div class="grid col-span-3 grid-cols-6 gap-2">
<div class="col-span-1 ti-pagination ">
<input type="checkbox" class="ti-form-checkbox" [id]="'radioItem'+i"
[class.pointer-events-none]="item.value==radioItem.value"
[name]="'radioItem'+item.label"
(change)="item.value=radioItem.value"
[checked]="item.value==radioItem.value">
</div>
<div class="col-span-5 ti-pagination ">
<label [for]="'radioItem'+i" class="text-sm text-gray-500"
[class.pointer-events-none]="item.value==radioItem.value">
{{radioItem.text}}
</label>
</div>
</div>
</ng-container>
</div>
</ng-container>
<ng-container *ngIf="item.type=='help'">
<div class="relative flex rounded-md">
<input type="text" class="ti-form-input h-16" readonly
[(ngModel)]="item.value.tdesc">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
<button type="button" class="flex items-center text-red-500"
(click)="item.value.tdesc=''" style="font-size: 17px;">
<i class=" ti ti-circle-x cursor-pointer"></i>
</button>
<button type="button"
class="flex items-center text-gray-500 dark:text-white/70"
(click)="openModal(item)"
style="margin-right: 0px;margin-left: 21px;font-size: 17px;">
<i class="ri-search-line cursor-pointer text-gray"></i>
</button>
</div>
</div>
</ng-container>
<ng-container *ngIf="item.type=='calendar'">
<mat-form-field>
<input matInput [matDatepicker]="matDate" type="text" readonly
class="ti-form-input rounded-l-none focus:z-10 flatpickr-input !text-gray-500 !bg-white"
[(ngModel)]="select[item.key]"
(ngModelChange)="matDateChange(select,item.key, select[item.key]);">
<div
class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 space-x-2">
<button type="button" class="flex items-center text-red-500"
(click)="select[item.key]=''" style="font-size: 17px;">
<i class=" ti ti-circle-x cursor-pointer"></i>
</button>
</div>
<mat-datepicker-toggle matSuffix [for]="matDate"></mat-datepicker-toggle>
<mat-datepicker #matDate></mat-datepicker>
</mat-form-field>
</ng-container>
</div>
</div>
</ng-container>
</ng-container>
<ng-container *ngIf="variableSheet.length&&!loadingExcel">
<div class="flex justify-center mb-1rem space-x-4">
<button type="submit" class="ti-btn ti-btn-secondary" [class.ti-btn-disabled]="loadingExcel"
(click)="dowloadExcelReport()" [disabled]="loadingExcel">
พิมพ์
</button>
</div>
</ng-container>
{{variableSheet.length}}
{{loadingExcel}}
<ng-container *ngIf="variableSheet.length&&loadingExcel">
<div class="flex justify-center">
<div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1" role="status"
aria-label="loading">
<span class="sr-only">Loading...</span>
</div>
</div>
</ng-container>
</div>
</div>
</div>
</div>
<ng-template #excelReportModal let-modal>
<h3 mat-dialog-title>
{{modalDetail.text.cardHead}}
</h3>
<mat-dialog-content>
<div class="flex justify-end pb-1rem">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" id="hs-leading-icon" name="hs-leading-icon"
class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="searchModal" (ngModelChange)="currentPage=1">
<div
class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
<i class="ri-search-line text-gray"></i>
</div>
</div>
</div>
</div>
<div class="page px-rem">
<div class="overflow-auto table-bordered rounded-t-md">
<div class="overflow-auto shadow-md rounded-t-md">
<table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
<thead>
<tr>
<ng-container
*ngFor="let item of modalDetail.text.tableHead; let f = first; let l = last; let i = index">
<th scope="col"
class=" px-10px py-10px bg-soft-secondary text-primary !text-center">
<span class="font-size-12px font-weight-700">{{ item }}</span>
<div class="absolute top-1/2 transform -translate-y-1/2 right-0">
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="!valueDetailFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="valueDetailFilter().length">
<tr *ngFor="let item of valueDetailFilter() | slice:((currentPage-1) * pageSize) : (((currentPage-1) * pageSize) + pageSize);let i = index"
class="cursor-pointer" (click)="selectData(item);closeDialog()">
<td class="text-center">
{{item.id}}
</td>
<td>{{item.tdesc}}</td>
<td>{{item.edesc}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<app-pagination [totalItems]="valueDetailFilter().length" [pageSize]="pageSize"
(pageChange)="currentPage = $event"
(pageSizeChange)="pageSize = $event;currentPage = 1"></app-pagination>
</div>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button type="button" mat-button [mat-dialog-close]
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
ย้อนกลับ
</button>
</mat-dialog-actions>
</ng-template>
\ No newline at end of file
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
import { ExcelReportService } from 'src/app/shared/services/excel-report.service';
export interface ModalDetail {
text: { cardHead: string, search: string[], tableHead: string[] }
}
@Component({
selector: 'app-excel-report',
templateUrl: './excel-report.component.html',
styleUrls: ['./excel-report.component.scss']
})
export class ExcelReportComponent implements OnInit {
changeDate = new Date();
select: any = {}
excelReport?: any
variableSheet: any = []
loading = false
loadingExcel = false
valueDetail = []
modalDetail: ModalDetail = {
text: {
cardHead: '',
search: [],
tableHead: []
}
}
keySelect = ""
searchModal = ""
pageSize: number = 10
page: number = 1
currentPage: number = 1
dialogRef: any
@ViewChild("excelReportModal") excelReportModal: any;
pathTitle = ['รายงาน Excel', 'รายงาน Excel 1']
excelReportServiceSub?: Subscription
constructor(private route: ActivatedRoute,
private excelReportService: ExcelReportService,
private cdr: ChangeDetectorRef,
private dialog: MatDialog,
) {
}
ngOnInit(): void {
this.excelReportServiceSub?.unsubscribe()
this.loadingExcel = false
this.cdr.detectChanges()
this.route.paramMap.subscribe(params => {
const rawId = params.get('id');
if (rawId) {
const [id, queryString] = rawId.split('?');
const params = new URLSearchParams(queryString);
const template = params.get('template');
const name = params.get('name');
this.getDataExcelReport(template || '', name || '')
}
});
}
ngOnDestroy(): void {
this.excelReportServiceSub?.unsubscribe()
this.loadingExcel = false
this.cdr.detectChanges()
}
getDataExcelReport(templateId: string, fileName: string) {
this.loading = true
this.excelReport = undefined
this.variableSheet = []
this.valueDetail = []
this.loadingExcel = false
this.excelReportService.getTemplateFile(templateId, fileName).subscribe((res: any) => {
this.excelReport = res
this.pathTitle = ['รายงาน Excel', this.excelReport.itemId + '.' + this.excelReport.tdesc]
if (this.excelReport.param) {
Object.entries(this.excelReport.param.variableSheet).forEach(([key, value]) => {
const data = value as any
if (data.type == 'text') {
this.variableSheet.push({
...data, value: data.valueDefault || '', key: key
})
} else if (data.type == 'list') {
this.variableSheet.push({
...data, value: data.valueDefault || '', key: key, option: data.option.split('customize|')[1].split(',').map((x: any) => {
const [value, text] = x.split('#')
return { value: value || '', text: text || '' }
})
})
} else if (data.type == 'radio') {
this.variableSheet.push({
...data, value: data.valueDefault || '', key: key, option: data.option.split('customize|')[1].split(',').map((x: any) => {
const [value, text] = x.split('#')
return { value: value || '', text: text || '' }
})
})
} else if (data.type == 'help') {
this.variableSheet.push({ ...data, value: data.valueDefault ? { id: data.valueDefault, tdesc: data.valueDefault, edesc: data.valueDefault } : { id: "", tdesc: "", edesc: "" }, key: key })
} else if (data.type == 'calendar') {
this.variableSheet.push({ ...data, value: data.valueDefault || '', key: key })
const [d, m, y] = data.valueDefault ? data.valueDefault.split('-').map(Number) : [null, null, null]
this.select[key] = y ? new Date(y, m - 1, d) : null
}
})
}
this.loading = false
this.cdr.detectChanges()
}, error => {
this.loading = false
})
}
matDateChange(target: { [key: string]: any }, field: string, dateIso: string) {
target[field] = this.toYYYYMMDD(dateIso)
}
toYYYYMMDD(dateInput?: string | null): string {
if (!dateInput) return "";
const parsedDate = new Date(dateInput);
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
};
const formattedDate = parsedDate.toLocaleDateString('en-GB', options);
const [day, month, year] = formattedDate.split('/');
return `${year}-${month}-${day}`;
}
openModal(data: any) {
this.searchModal = ''
this.page = 1
this.pageSize = 10
this.valueDetail = data.valueDetail.map((x: any) => ({ id: x.id || '', tdesc: x.tdesc || '', edesc: x.edesc || '' }))
this.keySelect = data.key
this.modalDetail = {
text: {
cardHead: "Table " + data.table,
search: ["Table " + data.table],
tableHead: ['ID', 'detailTH', 'detailENG']
}
}
this.dialogRef = this.dialog.open(this.excelReportModal, {
width: '1000px',
disableClose: false,
});
}
closeDialog() {
this.dialogRef.close()
}
valueDetailFilter(): any[] {
return this.valueDetail.filter((item: any) =>
item.id.toLowerCase().includes(this.searchModal.toLowerCase()) ||
item.tdesc.toLowerCase().includes(this.searchModal.toLowerCase()) ||
item.edesc.toLowerCase().includes(this.searchModal.toLowerCase())
)
}
selectData(data: any) {
const item = this.variableSheet.find((i: any) => i.key === this.keySelect);
if (item) item.value = data;
this.cdr.detectChanges()
}
dowloadExcelReport() {
this.loadingExcel = true
const fileName = this.excelReport.param.excelFile
const param = this.excelReport.param.variableName
const data = this.variableSheet.map((item: any) => {
if (item.type == 'help') {
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.toDateStringOnly(this.select[item.key])
}
return ""
}).join('|')
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);
const url = window.URL.createObjectURL(res);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
this.loadingExcel = false
this.cdr.detectChanges()
}, (err) => {
this.loadingExcel = false
this.cdr.detectChanges()
})
}
toDateStringOnly(input: string | Date): string {
const date = new Date(input);
if (isNaN(date.getTime())) return ''; // ถ้าไม่ใช่วันจริง คืนค่าว่าง
const year = date.getFullYear();
const month = `${date.getMonth() + 1}`.padStart(2, '0');
const day = `${date.getDate()}`.padStart(2, '0');
return `${year}-${month}-${day}`;
}
}
......@@ -8,6 +8,8 @@ import { ConfigPermissionService } from '../../services/config-permission.servic
import { ConfigPermissionModel, MenuBodyModel, MyConfigPermissionModel } from '../../model/config-permission.model';
import { TokenService } from '../../services/token.service';
import { ViewportScroller } from '@angular/common';
import { ExcelReportService } from '../../services/excel-report.service';
import { MyTemplateFileMiniModel } from '../../model/template-file-mini.model';
@Component({
selector: 'app-sidebar',
......@@ -82,7 +84,8 @@ export class SidebarComponent {
private configPermissionService: ConfigPermissionService,
private cdr: ChangeDetectorRef,
private tokenService: TokenService,
private viewScroller: ViewportScroller
private viewScroller: ViewportScroller,
private excelReportService: ExcelReportService
) {
this.screenWidth = window.innerWidth;
this.user_level = this.tokenService.getUser()?.user_level
......@@ -198,12 +201,39 @@ export class SidebarComponent {
} else {
this.menuitemsSubscribe$ = this.navServices.items.subscribe((items) => {
if (!this.previousUrl.includes('/admin/') && !this.previousUrl.includes('/dashboard')) {
this.menuItems = this.navServices.getAdminMenu();
this.menuItems = this.navServices.getAdminMenu()
this.ParentActive()
this.excelReportService.getTemplateFileLists().subscribe({
next: response => {
const submenuExcel = response.map((e, i) => ({
id: 'mExport' + i,
path: 'admin/excel-export/' + e.itemId + "?template=" + e.templateId + "&name=" + e.fileName,
title: e.itemId + '.' + e.tdesc,
type: 'link', show: true
}))
if (submenuExcel.length) {
this.menuItems.push({
title: 'รายงาน Excel',
type: 'sub',
selected: false,
active: false,
path: '',
id: 'm7',
show: true,
icon: 'assets/img/icons-menu/Report.png',
children: submenuExcel
})
}
}
})
}
});
}
}
addMenu() {
}
getConfigPermissionByUserLevel() {
this.configPermission.loading = true
this.configPermissionService.getByUserLevel(this.user_level!).subscribe({
......
import { environment } from "src/environments/environment"
export interface ExcelPortalModel {
approveBy: string
approveDate: string
approveTime: string
dbSupport: string
downloadDate: string
downloadTime: string
dwTime: number
engDesc: string
engName: string
excelId: string
fileData: string
fileType: string
group: ExcelPortalGroupModel
isDataGrid: number
isPivot: number
link1: string
referId: string
remark: string
tags: ExcelPortalTagsModel[]
thDesc: string
thName: string
thumbnail: string
uploadBy: string
uploadDate: string
uploadTime: string
}
export class MyExcelPortalModel implements ExcelPortalModel {
approveBy: string
approveDate: string
approveTime: string
dbSupport: string
downloadDate: string
downloadTime: string
dwTime: number
engDesc: string
engName: string
excelId: string
fileData: string
fileType: string
group: ExcelPortalGroupModel
isDataGrid: number
isPivot: number
link1: string
referId: string
remark: string
tags: ExcelPortalTagsModel[]
thDesc: string
thName: string
thumbnail: string
uploadBy: string
uploadDate: string
uploadTime: string
constructor(data?: Partial<ExcelPortalModel>) {
this.approveBy = data?.approveBy || ''
this.approveDate = data?.approveDate || ''
this.approveTime = data?.approveTime || ''
this.dbSupport = data?.dbSupport || ''
this.downloadDate = data?.downloadDate || ''
this.downloadTime = data?.downloadTime || ''
this.dwTime = data?.dwTime ?? 0
this.engDesc = data?.engDesc || ''
this.engName = data?.engName || ''
this.excelId = data?.excelId || ''
this.fileData = data?.fileData || ''
this.fileType = data?.fileType || ''
this.group = new MyExcelPortalGroupModel(data?.group || {})
this.isDataGrid = data?.isDataGrid ?? 0
this.isPivot = data?.isPivot ?? 0
this.link1 = data?.link1 || ''
this.referId = data?.referId || ''
this.remark = data?.remark || ''
this.tags = data?.tags?.map(e => new MyExcelPortalTagsModel(e)) || []
this.thDesc = data?.thDesc || ''
this.thName = data?.thName || ''
this.thumbnail = data?.thumbnail || ''
this.uploadBy = data?.uploadBy || ''
this.uploadDate = data?.uploadDate || ''
this.uploadTime = data?.uploadTime || ''
}
getImg() {
return this.thumbnail ? environment.baseUrl + "files/image/" + this.thumbnail : ''
}
}
export interface ExcelPortalGroupModel {
engName: string
groupId: string
groupType: number
thName: string
}
export class MyExcelPortalGroupModel implements ExcelPortalGroupModel {
engName: string
groupId: string
groupType: number
thName: string
constructor(data?: Partial<ExcelPortalGroupModel>) {
this.engName = data?.engName || ''
this.groupId = data?.groupId || ''
this.groupType = data?.groupType ?? 0
this.thName = data?.thName || ''
}
}
export interface ExcelPortalTagsModel {
display: string
value: string
}
export class MyExcelPortalTagsModel implements ExcelPortalTagsModel {
display: string
value: string
constructor(data?: Partial<ExcelPortalTagsModel>) {
this.display = data?.display || ''
this.value = data?.value || ''
}
}
\ No newline at end of file
export interface ModuleModel {
code: string
tdesc: string
edesc: string
}
export class MyModuleModel implements ModuleModel {
code: string
tdesc: string
edesc: string
constructor(data?: Partial<ModuleModel>) {
this.code = data?.code || ''
this.tdesc = data?.tdesc || ''
this.edesc = data?.edesc || ''
}
}
\ No newline at end of file
export interface TemplateFileMiniModel {
edesc: string
fileName: string
itemId: string
module: string
tdesc: string
templateId: string
}
export class MyTemplateFileMiniModel implements TemplateFileMiniModel {
edesc: string
fileName: string
itemId: string
module: string
tdesc: string
templateId: string
constructor(data?: Partial<TemplateFileMiniModel>) {
this.edesc = data?.edesc || ''
this.fileName = data?.fileName || ''
this.itemId = data?.itemId || ''
this.module = data?.module || ''
this.tdesc = data?.tdesc || ''
this.templateId = data?.templateId || ''
}
}
export interface PrefixModel {
edesc: string
prefixId: string
tdesc: string
}
export class MyPrefixModel implements PrefixModel {
edesc: string
prefixId: string
tdesc: string
constructor(data?: Partial<PrefixModel>) {
this.edesc = data?.edesc || ''
this.prefixId = data?.prefixId || ''
this.tdesc = data?.tdesc || ''
}
}
export interface CreateByModel {
efname: string
elname: string
email: string
employeeId: string
engFullName: string
fname: string
lname: string
picture: string
prefix: PrefixModel
sex: string
thFullName: string
}
export class MyCreateByModel implements CreateByModel {
efname: string
elname: string
email: string
employeeId: string
engFullName: string
fname: string
lname: string
picture: string
prefix: PrefixModel
sex: string
thFullName: string
constructor(data?: Partial<CreateByModel>) {
this.efname = data?.efname || ''
this.elname = data?.elname || ''
this.email = data?.email || ''
this.employeeId = data?.employeeId || ''
this.engFullName = data?.engFullName || ''
this.fname = data?.fname || ''
this.lname = data?.lname || ''
this.picture = data?.picture || ''
this.prefix = new MyPrefixModel(data?.prefix)
this.sex = data?.sex || ''
this.thFullName = data?.thFullName || ''
}
}
export interface TemplateFileModel {
createDate: string
edesc: string
fileName: string
isDataGrid: string
isPivot: string
isShare: string
itemId: string
menuActive: string
module: string
page: string
param: any | null
portalId: string
realFileName: string
realFileNameOld: string
tdesc: string
templateId: string
uponMenu: string
fileData: string
fileType: string
}
export class MyTemplateFileModel implements TemplateFileModel {
createDate: string
edesc: string
fileName: string
isDataGrid: string
isPivot: string
isShare: string
itemId: string
menuActive: string
module: string
page: string
param: any | null
portalId: string
realFileName: string
realFileNameOld: string
tdesc: string
templateId: string
uponMenu: string
fileData: string
fileType: string
constructor(data?: Partial<TemplateFileModel>) {
this.createDate = data?.createDate || ''
this.edesc = data?.edesc || ''
this.fileName = data?.fileName || ''
this.isDataGrid = data?.isDataGrid || '0'
this.isPivot = data?.isPivot || '0'
this.isShare = data?.isShare || '0'
this.itemId = data?.itemId || ''
this.menuActive = data?.menuActive || ''
this.module = data?.module || ''
this.page = data?.page || ''
this.param = data?.param
this.portalId = data?.portalId || ''
this.realFileName = data?.realFileName || ''
this.realFileNameOld = data?.realFileNameOld || ''
this.tdesc = data?.tdesc || ''
this.templateId = data?.templateId || ''
this.uponMenu = data?.uponMenu || ''
this.fileData = data?.fileData || ''
this.fileType = data?.fileType || ''
}
}
export interface TemplateModel {
templateId: string
tname: string
ename: string
tdesc: string
edesc: string
module: string
templateFile: TemplateFileModel[]
}
export class MyTemplateModel implements TemplateModel {
templateId: string
tname: string
ename: string
tdesc: string
edesc: string
module: string
templateFile: TemplateFileModel[]
constructor(data?: Partial<TemplateModel>) {
this.templateId = data?.templateId || ''
this.tname = data?.tname || ''
this.ename = data?.ename || ''
this.tdesc = data?.tdesc || ''
this.edesc = data?.edesc || ''
this.module = data?.module || ''
this.templateFile = data?.templateFile?.map(x => new MyTemplateFileModel(x)) || []
}
}
\ No newline at end of file
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { TemplateFileModel, TemplateModel } from '../model/template.model';
import { ModuleModel } from '../model/module.model';
import { ExcelPortalModel, ExcelPortalGroupModel, ExcelPortalTagsModel } from '../model/excel-portal.model';
import { AlertModel } from '../model/alert.model';
import { TemplateFileMiniModel } from '../model/template-file-mini.model';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class ExcelReportService {
constructor(private http: HttpClient,
) { }
getExcelList(): Observable<TemplateModel[]> {
return this.http.get<TemplateModel[]>(environment.baseUrl + "/template/lists?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47")
}
getModuleList(): Observable<ModuleModel[]> {
return this.http.get<ModuleModel[]>(environment.baseUrl + "/template/lists/module?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47")
}
getExcelPortalList(): Observable<ExcelPortalModel[]> {
return this.http.get<ExcelPortalModel[]>(environment.baseUrl + "/excel-center/content/lists")
}
getExcelPortalgGroupList(): Observable<ExcelPortalGroupModel[]> {
return this.http.get<ExcelPortalGroupModel[]>(environment.baseUrl + "/portal-group/lists")
}
getExcelPortalTagsList(): Observable<ExcelPortalTagsModel[]> {
return this.http.get<ExcelPortalTagsModel[]>(environment.baseUrl + "/tag/lists")
}
postTemplate(body: {
templateId: string,
tname: string,
ename: string,
tdesc: string,
edesc: string,
module: string
}) {
return this.http.post(environment.baseUrl + "/template?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", body)
}
deleteTemplate(body: TemplateModel): Observable<AlertModel> {
let option = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: body
}
return this.http.delete<AlertModel>(environment.baseUrl + "/template?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", option)
}
postTemplateFile(body: TemplateFileModel): Observable<AlertModel> {
return this.http.post<AlertModel>(environment.baseUrl + "/template-file?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", body)
}
deleteTemplateFile(body: TemplateFileModel): Observable<AlertModel> {
let option = {
headers: new HttpHeaders({
"Content-Type": "application/json",
}),
body: body
}
return this.http.delete<AlertModel>(environment.baseUrl + "/template-file?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", option)
}
downloadTemplateFile(fileName: string) {
return this.http.get(environment.baseUrl + "/template-file/download/excel/" + fileName + "?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", { responseType: 'blob' })
}
printExcelReport(body: {
fileName: string,
paramObj: string
}) {
return this.http.post(environment.baseUrl + "/template-file/export-to-excel?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47", body, { responseType: 'blob' })
}
getTemplateFile(templateid: string, filename: string): Observable<AlertModel> {
return this.http.get<AlertModel>(environment.baseUrl + "/template-file/" + templateid + "/" + filename + "?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47",)
}
getTemplateFileLists(): Observable<TemplateFileMiniModel[]> {
return this.http.get<TemplateFileMiniModel[]>(environment.baseUrl + "/template-file/menuitem/mini/lists?companyid=eb2f4f30-edaf-11ee-a69a-c7680edc0e47",)
}
}
\ No newline at end of file
......@@ -243,7 +243,7 @@ export class NavService implements OnDestroy {
{ id: 'm65', path: 'admin/report-pms-2', title: 'รายงาน PMS 2', type: 'link', show: true },
{ id: 'm66', path: 'admin/report-pms-3', title: 'รายงาน PMS 3', type: 'link', show: true },
],
},
}
]
}
// Array
......
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