Commit 723b6570 by Nattana Chaiyamat

การจัดการข้อมูลองค์กร

ทะเบียนประเภทวัน
ข้อมูลประเภทวัน
parent 0ed3b851
import { ChangeDetectorRef, Component } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { PositionModel, MyPositionModel } from 'src/app/shared/model/position.model';
import { FileService } from 'src/app/shared/services/file.service';
import { PositionService } from 'src/app/shared/services/position.service';
export interface DataModel {
positionId: string
tdesc: string
edesc: string
consolidate: string
shortName: string
companyId: string
}
@Component({
selector: 'app-day-type-registry',
templateUrl: './day-type-registry.component.html',
styleUrls: ['./day-type-registry.component.scss']
})
export class DayTypeRegistryComponent {
pathTitle = ['การจัดการข้อมูลองค์กร', 'ทะเบียนประเภทวัน', 'ข้อมูลประเภทวัน']
currentPage = 1
selectedItems: string[] = [];
search = ""
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
modalStatus = 'add'
page = Array.from({ length: 1 }, (_, i) => i + 1);
positionList: { check: boolean, data: DataModel }[] = []
position: PositionModel = new MyPositionModel({})
dataLoading = false
dataSelect: DataModel = { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" }
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
constructor(
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
) { }
ngOnInit(): void {
this.getPositionList()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
}
uploadFile() {
if (!this.selectedFile) {
alert('กรุณาเลือกไฟล์ก่อนอัปโหลด')
return
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.dataLoading = true
this.fileService.uploadExcel(formData, 'mposition').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getPositionList()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges();
}
})
}
downloadFile() {
const fileName = 'IMPORT_MPOSITION.xlsx'
this.fileService.downloadTemplate(fileName).subscribe({
next: response => {
const url = window.URL.createObjectURL(response);
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);
}, error: error => {
this.showAlert(error.message, 'error')
}
})
}
getPositionList() {
this.dataLoading = false
// this.dataLoading = true
// this.positionService.getList().subscribe({
// next: response => {
// this.positionList = response.map(x => new MyPositionModel(x)).map(x => ({ check: false, data: { positionId: x.positionId, tdesc: x.tdesc, edesc: x.edesc, consolidate: x.consolidate, shortName: x.shortName, companyId: x.companyId } }))
// this.dataLoading = false
// this.isDataListCheckedAll = false
// this.dataListCheckAll()
// this.searchChange()
// this.cdr.detectChanges();
// }, error: error => {
// this.dataLoading = false
// console.error('Error fetching employee types:', error);
// this.cdr.detectChanges()
// }
// })
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.positionListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
positionListFilter() {
return this.positionList.filter(x => {
const data = x.data
const match = data.positionId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
});
}
setData(data?: DataModel) {
this.dataSelect = JSON.parse(JSON.stringify(data || { positionId: "", tdesc: "", edesc: "", consolidate: "", shortName: "", companyId: "" }));
}
addPosition() {
const body = new MyPositionModel({ positionId: this.dataSelect.positionId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, consolidate: this.dataSelect.consolidate, shortName: this.dataSelect.shortName, companyId: this.dataSelect.companyId })
this.dataLoading = true
// this.positionService.post(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getPositionList()
// } else {
// this.showAlert(response.message, 'error')
// this.dataLoading = false
// this.cdr.detectChanges()
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.dataLoading = false
// this.cdr.detectChanges()
// }
// })
}
deletePosition() {
let body: PositionModel | PositionModel[] = []
if (this.dataSelect.positionId) {
body = new MyPositionModel({ positionId: this.dataSelect.positionId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, consolidate: this.dataSelect.consolidate, shortName: this.dataSelect.shortName, companyId: this.dataSelect.companyId })
} else {
body = this.positionList.filter(x => x.check).map(x => new MyPositionModel({ positionId: x.data.positionId, tdesc: x.data.tdesc, edesc: x.data.edesc, consolidate: x.data.consolidate, shortName: x.data.shortName, companyId: x.data.companyId }))
}
this.dataLoading = true
// this.positionService.delete(body).subscribe({
// next: response => {
// if (response.success) {
// this.showAlert(response.message, 'success')
// this.getPositionList()
// } else {
// this.showAlert(response.message, 'error')
// this.dataLoading = false
// this.cdr.detectChanges()
// }
// }, error: error => {
// this.showAlert(error.message, 'error')
// this.dataLoading = false
// this.cdr.detectChanges()
// }
// })
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.positionList.filter(x => {
const data = x.data
const match = data.positionId.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.positionListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.positionList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearPosition(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.positionId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
}
}
......@@ -40,6 +40,7 @@ import { SettingPerformanceEvalutionComponent } from '../performance-management-
import { SelfEvaluationComponent } from '../performance-evaluation/self-evaluation/self-evaluation.component';
import { IdpEvalutionComponent } from '../performance-evaluation/idp-evaluation/idp-evalution.component';
import { PmsGradeRegistrationComponent } from '../performance-management-evaluation/pms-grade-registration/pms-pms-grade-registration.component';
import { DayTypeRegistryComponent } from '../company-components/day-type-registry/day-type-registry.component';
......@@ -87,7 +88,8 @@ const routes: Routes = [
{ path: "grade-registration", title: 'ทะเบียนเกรด', component: GradeRegistrationComponent },
{ path: "grade-registration-sub", title: 'ทะเบียนเกรด', component: PmsGradeRegistrationComponent },
{ path: "setting-performance-evalution", title: 'การตั้งค่า', component: SettingPerformanceEvalutionComponent },
{ path: "self-evaluation", title: 'ประเมินตนเอง', component: SelfEvaluationComponent }
{ path: "self-evaluation", title: 'ประเมินตนเอง', component: SelfEvaluationComponent },
{ path: "day-type-registry", title: 'ประเมินตนเอง', component: DayTypeRegistryComponent }
]
}
];
......
......@@ -151,6 +151,7 @@ import { PmsSubGradeRegistrationComponent } from '../performance-management-eval
import { PmsGroupGradeComponent } from '../performance-management-evaluation/pms-grade-registration/pms-grade-management/pms-group-grade/pms-group-grade.component';
import { EvaluationAssessmentService } from 'src/app/shared/services/evaluation-assessment.service';
import { AppraisalService } from 'src/app/shared/services/appraisal.service';
import { DayTypeRegistryComponent } from '../company-components/day-type-registry/day-type-registry.component';
export const MY_DATE_FORMATS = {
parse: {
......@@ -273,7 +274,8 @@ export class CustomDateAdapter extends NativeDateAdapter {
PmsGradeRegistrationComponent,
PmsGradeManagementComponent,
PmsGroupGradeComponent,
PmsSubGradeRegistrationComponent
PmsSubGradeRegistrationComponent,
DayTypeRegistryComponent
],
imports: [
CommonModule,
......
......@@ -106,6 +106,7 @@ export class NavService implements OnDestroy {
{ path: '/company-registration', title: 'ทะเบียนบริษัท', type: 'link' },
{ path: '/job-description', title: 'ข้อมูลลักษณะงาน', type: 'link' },
{ path: '/employee-registration', title: 'ทะเบียนพนักงาน', type: 'link' },
{ path: '/day-type-registry', title: 'ทะเบียนประเภทวัน', type: 'link' },
{ path: '/account-settings', title: 'ตั้งค่าชื่อผู้ใช้', type: 'link' },
],
},
......
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