Commit 962c6075 by Nattana Chaiyamat

ประเภทพนักงาน

parent 323a6996
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { EmpTypeModel, MyEmpTypeModel } from 'src/app/shared/model/employee-type.model'; import { EmpTypeModel, MyEmpTypeModel } from 'src/app/shared/model/employee-type.model';
import { EmpTypeService } from 'src/app/shared/services/employee-type.service'; import { EmpTypeService } from 'src/app/shared/services/employee-type.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
export interface DataModel {
codeId: string
tdesc: string
edesc: string
companyId: string
}
@Component({ @Component({
selector: 'app-employee-categories', selector: 'app-employee-categories',
templateUrl: './employee-categories.component.html', templateUrl: './employee-categories.component.html',
styleUrls: ['./employee-categories.component.scss'] styleUrls: ['./employee-categories.component.scss']
}) })
export class EmployeeCategories { export class EmployeeCategories {
currentPage = 1
pageSize = 10
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = "" search = ""
modalStatus = 'add' currentModal: 'add' | 'edit' | 'delete' = 'add'
emp_typelist: { check: boolean, data: DataModel }[] = [] emp_type: { loading: boolean, select: EmpTypeModel, dataList: EmpTypeModel[] } = { loading: false, select: new MyEmpTypeModel(), dataList: [] }
emp_type: EmpTypeModel = new MyEmpTypeModel({})
dataLoading = false
dataSelect: DataModel = { codeId: "", tdesc: "", edesc: "", companyId: "" }
itemToDelete: EmpTypeModel | null = null; itemToDelete: EmpTypeModel | null = null;
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0 columns: ColumnModel[] = [{
isDataListChecked = false field: "codeId",
isDataListCheckedAll = false headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['codeId', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
}
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor(private empTypeService: EmpTypeService, constructor(private empTypeService: EmpTypeService,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
...@@ -53,7 +60,7 @@ export class EmployeeCategories { ...@@ -53,7 +60,7 @@ export class EmployeeCategories {
return return
} }
const formData = new FormData(); const formData = new FormData();
this.dataLoading = true this.emp_type.loading = true
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.fileService.uploadExcel(formData, 'employment_type').subscribe({ this.fileService.uploadExcel(formData, 'employment_type').subscribe({
next: response => { next: response => {
...@@ -62,12 +69,12 @@ export class EmployeeCategories { ...@@ -62,12 +69,12 @@ export class EmployeeCategories {
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges(); this.cdr.detectChanges();
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges(); this.cdr.detectChanges();
} }
}) })
...@@ -93,68 +100,61 @@ export class EmployeeCategories { ...@@ -93,68 +100,61 @@ export class EmployeeCategories {
} }
getEmpTypeList() { getEmpTypeList() {
this.dataLoading = true this.emp_type.loading = true
this.empTypeService.getList().subscribe({ this.empTypeService.getList().subscribe({
next: response => { next: response => {
this.emp_typelist = response.map(x => ({ check: false, data: { codeId: x.codeId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } })) this.emp_type.dataList = response.map(x => {
this.dataLoading = false this.selectedItems.data.set(x.codeId, false)
this.isDataListCheckedAll = false return new MyEmpTypeModel(x)
this.dataListCheckAll() })
this.searchChange(); this.selectedItems.key = 'codeId'
this.selectedItems.count = 0
this.emp_type.loading = false
this.cdr.detectChanges(); this.cdr.detectChanges();
}, error: error => { }, error: error => {
this.dataLoading = false this.emp_type.loading = false
console.error('Error fetching employee types:', error); console.error('Error fetching employee types:', error);
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}); });
} }
searchChange() { selectEmp_type(emp_type?: EmpTypeModel) {
this.currentPage = 1 if (emp_type) {
this.page = Array.from({ length: Math.ceil(this.emp_typeListFilter().length / 10) }, (_, i) => i + 1); this.emp_type.select = new MyEmpTypeModel(emp_type)
this.dataListCheck() } else if (this.currentModal == 'add') {
} this.emp_type.select = new MyEmpTypeModel()
emp_typeListFilter() { } else if (this.currentModal == 'edit') {
return this.emp_typelist.filter(x => { this.emp_type.select = new MyEmpTypeModel({ codeId: this.emp_type.select.codeId })
const data = x.data }
const match = data.codeId.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 || { code: "", tdesc: "", edesc: "", companyId: "" }));
} }
addEmp_type() { addEmp_type() {
const body = new MyEmpTypeModel({ codeId: this.dataSelect.codeId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) this.emp_type.loading = true
this.dataLoading = true this.empTypeService.post(this.emp_type.select).subscribe({
this.empTypeService.post(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
deleteEmp_type() { deleteEmp_type() {
let body: EmpTypeModel | EmpTypeModel[] = [] this.emp_type.loading = true
if (this.dataSelect.codeId) { const selectedKeys = Array.from(this.selectedItems.data.keys());
body = new MyEmpTypeModel({ codeId: this.dataSelect.codeId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId }) const body = this.emp_type.dataList.filter(x => selectedKeys.includes(x.codeId) && this.selectedItems.data.get(x.codeId)).map(x => new MyEmpTypeModel(x))
} else {
body = this.emp_typelist.filter(x => x.check).map(x => new MyEmpTypeModel({ codeId: x.data.codeId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }))
}
this.dataLoading = true
this.empTypeService.delete(body).subscribe({ this.empTypeService.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -162,12 +162,12 @@ export class EmployeeCategories { ...@@ -162,12 +162,12 @@ export class EmployeeCategories {
this.getEmpTypeList() this.getEmpTypeList()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.dataLoading = false this.emp_type.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
...@@ -180,35 +180,18 @@ export class EmployeeCategories { ...@@ -180,35 +180,18 @@ export class EmployeeCategories {
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.emp_typelist.filter(x => {
const data = x.data
const match = data.codeId.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.emp_typeListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.emp_typelist.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
checkPrimary() {
return this.emp_type.dataList.find(x => x.codeId == this.emp_type.select.codeId)
}
clearEmp_type(modalStatus: string) { numSelectItem() {
if (modalStatus == 'add') { const selectedKeys = Array.from(this.selectedItems.data.keys());
this.dataSelect.codeId = '' const num = this.emp_type.dataList.filter(x => selectedKeys.includes(x.codeId) && this.selectedItems.data.get(x.codeId)).length
this.dataSelect.tdesc = '' return num
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
} }
checkPrimary() { onSelectItemChange(arg: any) {
return this.emp_typelist.find(x => x.data.codeId == this.dataSelect.codeId) this.selectedItems = arg
} }
} }
...@@ -4,15 +4,6 @@ import { ToastrService } from 'ngx-toastr'; ...@@ -4,15 +4,6 @@ import { ToastrService } from 'ngx-toastr';
import { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model'; import { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import { PositionService } from 'src/app/shared/services/position.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({ @Component({
selector: 'app-position-unit', selector: 'app-position-unit',
templateUrl: './position-unit.component.html', templateUrl: './position-unit.component.html',
......
...@@ -12,11 +12,11 @@ export class MyEmpTypeModel implements EmpTypeModel { ...@@ -12,11 +12,11 @@ export class MyEmpTypeModel implements EmpTypeModel {
tdesc: string; tdesc: string;
edesc: string; edesc: string;
companyId: string; companyId: string;
constructor(data: Partial<EmpTypeModel>) { constructor(data?: Partial<EmpTypeModel>) {
this.codeId = data.codeId || "" this.codeId = data?.codeId || ""
this.tdesc = data.tdesc || "" this.tdesc = data?.tdesc || ""
this.edesc = data.edesc || "" this.edesc = data?.edesc || ""
this.companyId = data.companyId || "" this.companyId = data?.companyId || ""
} }
} }
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