Commit f9d19f91 by Nattana Chaiyamat

ระดับพนักงาน (JL)

parent 962c6075
......@@ -101,6 +101,7 @@ export class EmployeeCategories {
getEmpTypeList() {
this.emp_type.loading = true
this.selectedItems.data.clear()
this.empTypeService.getList().subscribe({
next: response => {
this.emp_type.dataList = response.map(x => {
......@@ -113,7 +114,6 @@ export class EmployeeCategories {
this.cdr.detectChanges();
}, error: error => {
this.emp_type.loading = false
console.error('Error fetching employee types:', error);
this.cdr.detectChanges()
}
});
......
<div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex justify-between">
<div class="flex">
<div class="flex items-center">
<input type="checkbox" class="ti-form-checkbox pointer-events-none" id="hs-default-checkbox"
[(ngModel)]="isDataListChecked">
<label for="hs-default-checkbox" class="text-sm text-gray-500 mx-2 pointer-events-none">
{{numDataListChecked}} Selected</label>
</div>
<div class="mx-1 flex items-center">
<button (click)="isDataListCheckedAll = !isDataListCheckedAll;dataListCheckAll()" id='check-boxall'
class="focus:ring-2 focus:ring-primary rounded-sm flex item-center">
<i class="fs-l transition-all duration-200"
[ngClass]="{'ri-checkbox-multiple-line text-gray-500': !isDataListCheckedAll, 'ri-checkbox-multiple-fill text-primary': isDataListCheckedAll}"></i>
</button>
<label class="text-sm text-gray-500 ml-2" for="check-boxall">Select All</label>
</div>
</div>
<div class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="search" (ngModelChange)="searchChange()">
<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 class="flex justify-end">
<div class="px-1">
<div class="relative shadow-md">
<input type="text" class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " placeholder="Search by No. or Name"
[(ngModel)]="search">
<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 class="px-1">
<button type="button"
class=" h-45px ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-10 m-0 shadow-md"
data-hs-overlay="#employee-level-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ti ti-file-plus"></i>
import
</button>
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
data-hs-overlay="#employee-level-page-modal" (click)="modalStatus='add';setData()">
<i class="ri-add-line"></i>
Add
</button>
</div>
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
data-hs-overlay="#employee-level-page-alert-modal" (click)="modalStatus='deleteGroup';setData()">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-20px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
<div class="px-1">
<button type="button"
class=" h-45px ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-10 m-0 shadow-md"
data-hs-overlay="#employee-level-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ti ti-file-plus"></i>
import
</button>
</div>
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
data-hs-overlay="#employee-level-page-modal" (click)="currentModal='add';selectPl()">
<i class="ri-add-line"></i>
Add
</button>
</div>
<div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
data-hs-overlay="#employee-level-page-alert-modal" (click)="currentModal='delete';selectPl()">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</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 ['','รหัสระดับพนักงาน','รายละเอียด(ไทย) ','รายละเอียด(อังกฤษ)','การจัดการ']; let f = first; let l = last; let i = index">
<th scope="col" class="relative 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" *ngIf="!l&&!f">
<i class="ti ti-dots-vertical fs-l"></i>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody *ngIf="dataLoading">
<tr>
<td class="text-center" colspan="100%">
<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>
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&!plListFilter().length">
<tr>
<td class="text-center" colspan="100%">
ไม่พบข้อมูล
</td>
</tr>
</tbody>
<tbody *ngIf="!dataLoading&&plListFilter().length">
<tr
*ngFor="let item of plListFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer" id="checkbox-{{item.data.plId}}"
[(ngModel)]="item.check" (ngModelChange)="dataListCheck()">
</td>
<td class="text-center">
<label for="checkbox-{{item.data.plId}}">&nbsp;{{item.data.plId}}</label>
</td>
<td>{{item.data.tdesc}}</td>
<td>{{item.data.edesc}}</td>
<td class="flex justify-center">
<i class="ti ti-edit cursor-pointer i-gray fs-l px-1" (click)="modalStatus='edit';setData(item.data)"
data-hs-overlay="#employee-level-page-modal"></i>
<!-- <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
(click)="modalStatus='delete';setData(item.data)"
data-hs-overlay="#employee-level-page-alert-modal"></i> -->
</td>
</tr>
</tbody>
</table>
</div>
</div>
<app-pagination [totalItems]="plListFilter().length" [pageSize]="pageSize" (pageChange)="currentPage = $event"
(pageSizeChange)="pageSize = $event;currentPage = 1"></app-pagination>
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="pl.dataList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#employee-level-page-modal"
(sendSelectData)="currentModal='edit';selectPl($event)" (sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution>
</div>
......@@ -129,7 +49,7 @@
<div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header">
<h3 class="text-xxl font-bold text-primary">
{{modalStatus=='add'?'เพิ่มข้อมูลระดับพนักงาน(JL)':'แก้ไขข้อมูลระดับพนักงาน(JL)'}}
{{currentModal=='add'?'เพิ่มข้อมูลระดับพนักงาน(JL)':'แก้ไขข้อมูลระดับพนักงาน(JL)'}}
</h3>
<div class="flex justify-end">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
......@@ -142,7 +62,7 @@
<div class="ti-modal-center">
<div class="flex justify-end" style="padding-right: 1rem;">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" (click)="clearPl(modalStatus)">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" (click)="selectPl()">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00"
xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84"
transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
......@@ -158,31 +78,26 @@
Clear
</button>
</div>
<!-- <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i>
Help
</button>
</div> -->
</div>
</div>
<div class="ti-modal-body" style="margin-top: 40px;">
<label for="input-label" class="ti-form-label">รหัสระดับพนักงาน(JL)
<span class="text-danger">
*
<ng-container *ngIf="modalStatus=='add'&&checkPrimary()">
<ng-container *ngIf="currentModal=='add'&&checkPrimary()">
รหัสระดับพนักงาน(JL)ซ้ำ
</ng-container>
</span>
</label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[class.!border-red]="modalStatus=='add'&&checkPrimary()" [ngClass]="{'bg-input-readonly':modalStatus=='edit'}"
[readonly]="modalStatus=='edit'" [(ngModel)]="dataSelect.plId">
[class.!border-red]="currentModal=='add'&&checkPrimary()"
[ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="pl.select.plId">
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียดระดับพนักงาน(JL) (ไทย)<span
class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="dataSelect.tdesc">
<input type="text" id="detail_th" class="ti-form-input h-16" [(ngModel)]="pl.select.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียดระดับพนักงาน(JL) (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="dataSelect.edesc">
<input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="pl.select.edesc">
<div class="flex justify-end mt-2rem mb-1rem space-x-4">
<button type="button"
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"
......@@ -190,8 +105,8 @@
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#employee-level-page-alert-modal"
[class.ti-btn-disabled]="!dataSelect.plId||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())"
[disabled]="!dataSelect.plId||!dataSelect.tdesc||(modalStatus=='add'&&checkPrimary())">
[class.ti-btn-disabled]="!pl.select.plId||!pl.select.tdesc||(currentModal=='add'&&checkPrimary())"
[disabled]="!pl.select.plId||!pl.select.tdesc||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</div>
......@@ -244,14 +159,14 @@
แจ้งเตือน
</h3>
<div class="flex justify-end">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#employee-level-page-modal">
<span class="sr-only">Close</span>
<i class="ti ti-circle-x fs-xxl"></i>
</button>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="currentModal=='delete'">
<button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
data-hs-overlay="#employee-level-page-alert-modal">
<span class="sr-only">Close</span>
......@@ -262,21 +177,21 @@
</div>
<div class="ti-modal-body ">
<p class="mt-1 text-gray-800 dark:text-white/70">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
ยืนยันการบันทึกข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="numDataListChecked">
<ng-container *ngIf="currentModal=='delete'">
<ng-container *ngIf="numSelectItem()">
ยืนยันการลบข้อมูลหรือไม่
</ng-container>
<ng-container *ngIf="!numDataListChecked">
<ng-container *ngIf="!numSelectItem()">
เลือกข้อมูลที่ต้องการลบ
</ng-container>
</ng-container>
</p>
<div class="flex justify-end mt-2rem mb-1rem">
<ng-container *ngIf="modalStatus=='add'||modalStatus=='edit'">
<ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
<button type="button"
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"
data-hs-overlay="#employee-level-page-modal">
......@@ -287,14 +202,14 @@
บันทึกข้อมูล
</a>
</ng-container>
<ng-container *ngIf="modalStatus=='delete'||modalStatus=='deleteGroup'">
<ng-container *ngIf="currentModal=='delete'">
<button type="button"
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"
data-hs-overlay="#employee-level-page-alert-modal">
ย้อนกลับ
</button>
<a class="ti-btn ti-btn-danger" href="javascript:void(0);"
data-hs-overlay="#employee-level-page-alert-modal" (click)="deletePL()" *ngIf="numDataListChecked">
data-hs-overlay="#employee-level-page-alert-modal" (click)="deletePL()" *ngIf="numSelectItem()">
ลบข้อมูล
</a>
</ng-container>
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model';
import { FileService } from 'src/app/shared/services/file.service';
import { PLService } from 'src/app/shared/services/pl.service';
export interface DataModel {
plId: string
tdesc: string
edesc: string
companyId: string
}
@Component({
selector: 'app-employee-level',
templateUrl: './employee-level.component.html',
styleUrls: ['./employee-level.component.scss']
})
export class EmployeeLevel implements OnInit {
currentPage = 1
pageSize = 10
page = Array.from({ length: 1 }, (_, i) => i + 1);
search = ""
modalStatus = 'add'
plList: { check: boolean, data: DataModel }[] = []
pl: PLModel = new MyPLModel({})
dataLoading = false
dataSelect: DataModel = { plId: "", tdesc: "", edesc: "", companyId: "" }
itemToDelete: PLModel | null = null;
currentModal: 'add' | 'edit' | 'delete' = 'add'
pl: { loading: boolean, select: PLModel, dataList: PLModel[] } = { loading: false, select: new MyPLModel(), dataList: [] }
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
columns: ColumnModel[] = [{
field: "plId",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['plId', '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 plService: PLService,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
......@@ -56,7 +63,7 @@ export class EmployeeLevel implements OnInit {
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.dataLoading = true
this.pl.loading = true
this.fileService.uploadExcel(formData, 'pl').subscribe({
next: response => {
if (response.success) {
......@@ -64,12 +71,12 @@ export class EmployeeLevel implements OnInit {
this.getPLList()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.pl.loading = false
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.pl.loading = false
this.cdr.detectChanges()
}
})
......@@ -95,71 +102,59 @@ export class EmployeeLevel implements OnInit {
}
getPLList() {
this.dataLoading = true
this.pl.loading = true
this.selectedItems.data.clear()
this.plService.getList().subscribe({
next: response => {
this.plList = response.map(x => ({ check: false, data: { plId: x.plId, tdesc: x.tdesc, edesc: x.edesc, companyId: x.companyId } }))
this.dataLoading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange();
this.pl.dataList = response.map(x => {
this.selectedItems.data.set(x.plId, false)
return new MyPLModel(x)
})
this.selectedItems.key = 'plId'
this.selectedItems.count = 0
this.pl.loading = false
this.cdr.detectChanges();
}, error: error => {
this.dataLoading = false
console.error('Error fetching employee types:', error);
this.pl.loading = false
this.cdr.detectChanges()
}
});
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.plListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck();
this.cdr.detectChanges()
}
plListFilter() {
return this.plList.filter(x => {
const data = x.data
const match = data.plId.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 || { plId: "", tdesc: "", edesc: "", companyId: "" }));
selectPl(pl?: PLModel) {
if (pl) {
this.pl.select = new MyPLModel(pl)
} else if (this.currentModal == 'add') {
this.pl.select = new MyPLModel()
} else if (this.currentModal == 'edit') {
this.pl.select = new MyPLModel({ plId: this.pl.select.plId })
}
}
addPL() {
const body = new MyPLModel({ plId: this.dataSelect.plId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId })
this.dataLoading = true
this.plService.post(body).subscribe({
this.pl.loading = true
this.plService.post(this.pl.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getPLList()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = true
this.pl.loading = true
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = true
this.pl.loading = true
this.cdr.detectChanges()
}
})
}
deletePL() {
let body: PLModel | PLModel[] = []
if (this.dataSelect.plId) {
body = new MyPLModel({ plId: this.dataSelect.plId, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, companyId: this.dataSelect.companyId })
} else {
body = this.plList.filter(x => x.check).map(x => new MyPLModel({ plId: x.data.plId, tdesc: x.data.tdesc, edesc: x.data.edesc, companyId: x.data.companyId }))
}
this.dataLoading = true
this.pl.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.pl.dataList.filter(x => selectedKeys.includes(x.plId) && this.selectedItems.data.get(x.plId)).map(x => new MyPLModel(x))
this.plService.delete(body).subscribe({
next: response => {
if (response.success) {
......@@ -167,12 +162,12 @@ export class EmployeeLevel implements OnInit {
this.getPLList()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = true
this.pl.loading = true
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = true
this.pl.loading = true
this.cdr.detectChanges()
}
})
......@@ -185,36 +180,18 @@ export class EmployeeLevel implements OnInit {
});
}
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.plList.filter(x => {
const data = x.data
const match = data.plId.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.plListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.plList.filter(x => x.check).length
this.isDataListChecked = Boolean(this.numDataListChecked)
}
clearPl(modalStatus: string) {
if (modalStatus == 'add') {
this.dataSelect.plId = ''
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
} else if (modalStatus == 'edit') {
this.dataSelect.tdesc = ''
this.dataSelect.edesc = ''
}
checkPrimary() {
return this.pl.dataList.find(x => x.plId == this.pl.select.plId)
}
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.pl.dataList.filter(x => selectedKeys.includes(x.plId) && this.selectedItems.data.get(x.plId)).length
return num
}
checkPrimary() {
return this.plList.find(x => x.data.plId == this.dataSelect.plId)
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
}
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