Commit 94077098 by Nattana Chaiyamat

ตั้งค่าผู้ใช้งาน

parent 5c57a862
...@@ -181,9 +181,9 @@ ...@@ -181,9 +181,9 @@
</div> </div>
</div> </div>
<ng-container *ngIf="changePassword"> <ng-container *ngIf="changePassword">
<label class="ti-form-label mt-2rem">รหัสผ่านเก่า</label> <label class="ti-form-label mt-2rem">รหัสผ่านเก่า*</label>
<input type="password" class="ti-form-input" [(ngModel)]="userPassword.oldPassword"> <input type="password" class="ti-form-input" [(ngModel)]="userPassword.oldPassword">
<label class="ti-form-label mt-2rem">รหัสผ่านใหม่</label> <label class="ti-form-label mt-2rem">รหัสผ่านใหม่*</label>
<input type="password" class="ti-form-input" [(ngModel)]="userPassword.newPassword"> <input type="password" class="ti-form-input" [(ngModel)]="userPassword.newPassword">
</ng-container> </ng-container>
<div class="flex justify-end mt-2rem mb-1rem"> <div class="flex justify-end mt-2rem mb-1rem">
...@@ -193,8 +193,8 @@ ...@@ -193,8 +193,8 @@
ย้อนกลับ ย้อนกลับ
</button> </button>
<button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#manage-user-alert-modal" <button type="button" class="ti-btn ti-btn-success" data-hs-overlay="#manage-user-alert-modal"
[class.ti-btn-disabled]="changePassword&&!userPassword.newPassword" [class.ti-btn-disabled]="changePassword&&(!userPassword.newPassword || !userPassword.oldPassword)"
[disabled]="changePassword&&!userPassword.newPassword"> [disabled]="changePassword&&(!userPassword.newPassword||!userPassword.oldPassword)">
บันทึกข้อมูล บันทึกข้อมูล
</button> </button>
</div> </div>
......
...@@ -84,52 +84,6 @@ export class SetAPasswordComponent { ...@@ -84,52 +84,6 @@ export class SetAPasswordComponent {
newPassword: "", newPassword: "",
} }
} }
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.user.loading = true
this.fileService.upload(formData, 'mbu1').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getUserList()
} else {
this.showAlert(response.message, 'error')
this.user.loading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.user.loading = false
}
})
}
downloadFile() {
const fileName = 'IMPORT_USER.xlsx'
this.fileService.download(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')
}
})
}
updateUserPassword() { updateUserPassword() {
this.user.loading = true this.user.loading = true
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
นำเข้าข้อมูล นำเข้าข้อมูล
</button> </button>
<a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end" <a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end"
href="javascript:void(0);"> href="javascript:void(0);" (click)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์ ดาวน์โหลดตัวอย่างไฟล์
</a> </a>
</div> </div>
......
...@@ -178,7 +178,7 @@ export class UserSettingsComponent { ...@@ -178,7 +178,7 @@ export class UserSettingsComponent {
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.user.loading = true this.user.loading = true
this.fileService.upload(formData, 'mbu1').subscribe({ this.fileService.upload(formData, 'muser').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
......
<div class="w-full min-height-50px mb-10px justify-between items-center"> <div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex pr-2 pb-2rem">
<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()"
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">Select All</label>
</div>
</div>
</div>
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex pr-2"> <div class="flex pr-2">
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
data-hs-overlay="#company-registration-page-upload-modal"> data-hs-overlay="#company-registration-page-upload-modal"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
นำเข้าข้อมูล นำเข้าข้อมูล
</button> </button>
<a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end" <a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end"
href="javascript:void(0);"> href="javascript:void(0);" (click)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์ ดาวน์โหลดตัวอย่างไฟล์
</a> </a>
</div> </div>
...@@ -88,7 +107,7 @@ ...@@ -88,7 +107,7 @@
*ngFor="let item of dataListFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index"> *ngFor="let item of dataListFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center"> <td class="text-center">
<input *ngIf="item.data.code!='100'" type="checkbox" class="ti-form-checkbox cursor-pointer" <input *ngIf="item.data.code!='100'" type="checkbox" class="ti-form-checkbox cursor-pointer"
id="checkbox-{{item.data.code}}" [(ngModel)]="item.check"> id="checkbox-{{item.data.code}}" [(ngModel)]="item.check" (ngModelChange)="dataListCheck()">
<label for="checkbox-{{item.data.code}}">&nbsp;{{item.data.code}}</label> <label for="checkbox-{{item.data.code}}">&nbsp;{{item.data.code}}</label>
</td> </td>
<td>{{item.data.tdesc}}</td> <td>{{item.data.tdesc}}</td>
...@@ -164,7 +183,7 @@ ...@@ -164,7 +183,7 @@
<div class="w-full flex justify-end"> <div class="w-full flex justify-end">
<div class="absolute flex"> <div class="absolute flex">
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"> <button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" (click)="clearData()">
<svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00" <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" 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)"> transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
...@@ -189,11 +208,11 @@ ...@@ -189,11 +208,11 @@
</div> </div>
</div> </div>
<div class="ti-modal-body padding-16px pt-0 overflow-y-0"> <div class="ti-modal-body padding-16px pt-0 overflow-y-0">
<label for="input-label" class="ti-form-label mt-2rem">รหัสบริษัท *</label> <label for="input-label" class="ti-form-label mt-2rem">รหัสบริษัท*</label>
<input type="text" id="input-label" class="ti-form-input w-1/2" <input type="text" id="input-label" class="ti-form-input w-1/2"
[ngClass]="{'bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'" [ngClass]="{'bg-input-readonly':modalStatus=='edit'}" [readonly]="modalStatus=='edit'"
[(ngModel)]="dataSelect.code" [maxLength]="5"> [(ngModel)]="dataSelect.code" [maxLength]="5">
<label for="detail_th" class="ti-form-label mt-2rem">รายละเอียด (ไทย) *</label> <label for="detail_th" class="ti-form-label mt-2rem">รายละเอียด (ไทย)*</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)]="dataSelect.tdesc">
<label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียด (อังกฤษ)</label> <label for="detail_eng" class="ti-form-label mt-2rem">รายละเอียด (อังกฤษ)</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)]="dataSelect.edesc">
...@@ -207,10 +226,12 @@ ...@@ -207,10 +226,12 @@
data-hs-overlay="#company-registration-page-modal"> data-hs-overlay="#company-registration-page-modal">
ย้อนกลับ ย้อนกลับ
</button> </button>
<a class="ti-btn ti-btn-success" href="javascript:void(0);" <button type="button" class="ti-btn ti-btn-success"
data-hs-overlay="#company-registration-page-alert-modal"> data-hs-overlay="#company-registration-page-alert-modal"
[class.ti-btn-disabled]="!dataSelect.code||!dataSelect.tdesc"
[disabled]="!dataSelect.code||!dataSelect.tdesc">
บันทึกข้อมูล บันทึกข้อมูล
</a> </button>
</div> </div>
</div> </div>
</div> </div>
...@@ -291,18 +312,20 @@ ...@@ -291,18 +312,20 @@
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1> <h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2"> <div class="mt-2 p-2">
<div class="flex rounded-md"> <div class="flex rounded-md">
<input type="text" id="hs-trailing-button-add-on-with-icon" <input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
name="hs-trailing-button-add-on-with-icon" <input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10"> class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
<button aria-label="button" type="button" <button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm"> class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i> <i class="ti ti-upload"></i>
</button> </button>
</div> </div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4"> <div class="flex justify-center mt-2rem mb-1rem space-x-4">
<a class="ti-btn ti-btn-secondary" href="javascript:void(0);"> <button type="submit" class="ti-btn ti-btn-secondary"
data-hs-overlay="#position-unit-component-upload-modal" [class.ti-btn-disabled]="!selectedFile"
(click)="uploadFile()" [disabled]="!selectedFile" [disabled]="!selectedFile">
อัปโหลด อัปโหลด
</a> </button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -2,6 +2,7 @@ import { ChangeDetectorRef, Component } from '@angular/core'; ...@@ -2,6 +2,7 @@ import { ChangeDetectorRef, Component } from '@angular/core';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { CompanyModel, MyCompanyModel } from 'src/app/shared/model/company.model'; import { CompanyModel, MyCompanyModel } from 'src/app/shared/model/company.model';
import { CompanyService } from 'src/app/shared/services/company.service'; import { CompanyService } from 'src/app/shared/services/company.service';
import { FileService } from 'src/app/shared/services/file.service';
export interface DataModel { export interface DataModel {
code: string code: string
tdesc: string tdesc: string
...@@ -23,11 +24,16 @@ export class CompanyRegistrationPageComponent { ...@@ -23,11 +24,16 @@ export class CompanyRegistrationPageComponent {
dataLoading = false dataLoading = false
dataSelect: DataModel = { code: "", tdesc: "", edesc: "", address: "", contact: "" } dataSelect: DataModel = { code: "", tdesc: "", edesc: "", address: "", contact: "" }
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
constructor(private toastr: ToastrService, constructor(private toastr: ToastrService,
private companyService: CompanyService, private companyService: CompanyService,
private cdr: ChangeDetectorRef private cdr: ChangeDetectorRef,
) { private fileService: FileService) { }
}
ngOnInit(): void { ngOnInit(): void {
this.getCompanyList() this.getCompanyList()
} }
...@@ -38,6 +44,8 @@ export class CompanyRegistrationPageComponent { ...@@ -38,6 +44,8 @@ export class CompanyRegistrationPageComponent {
next: response => { next: response => {
this.dataList = response.map(x => ({ check: false, data: { code: x.companyId, tdesc: x.tdesc, edesc: x.edesc, address: x.addressText, contact: x.descOther } })) this.dataList = response.map(x => ({ check: false, data: { code: x.companyId, tdesc: x.tdesc, edesc: x.edesc, address: x.addressText, contact: x.descOther } }))
this.dataLoading = false this.dataLoading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange() this.searchChange()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
...@@ -50,6 +58,7 @@ export class CompanyRegistrationPageComponent { ...@@ -50,6 +58,7 @@ export class CompanyRegistrationPageComponent {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.dataListFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.dataListFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
} }
dataListFilter() { dataListFilter() {
return this.dataList.filter(x => { return this.dataList.filter(x => {
...@@ -82,7 +91,7 @@ export class CompanyRegistrationPageComponent { ...@@ -82,7 +91,7 @@ export class CompanyRegistrationPageComponent {
if (this.dataSelect.code) { if (this.dataSelect.code) {
body = new MyCompanyModel({ companyId: this.dataSelect.code, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, addressText: this.dataSelect.address, descOther: this.dataSelect.contact }) body = new MyCompanyModel({ companyId: this.dataSelect.code, tdesc: this.dataSelect.tdesc, edesc: this.dataSelect.edesc, addressText: this.dataSelect.address, descOther: this.dataSelect.contact })
} else { } else {
body = this.dataList.filter(x => x.check).map(x => new MyCompanyModel({ companyId: x.data.code, tdesc: x.data.tdesc, edesc: x.data.edesc, addressText: x.data.address, descOther: x.data.contact })) body = this.dataList.filter(x => x.check && x.data.code != '100').map(x => new MyCompanyModel({ companyId: x.data.code, tdesc: x.data.tdesc, edesc: x.data.edesc, addressText: x.data.address, descOther: x.data.contact }))
} }
this.companyService.delete(body).subscribe({ this.companyService.delete(body).subscribe({
next: response => { next: response => {
...@@ -105,4 +114,73 @@ export class CompanyRegistrationPageComponent { ...@@ -105,4 +114,73 @@ export class CompanyRegistrationPageComponent {
}); });
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.dataList.filter(x => {
const data = x.data
const match = data.code.includes(this.search) || data.tdesc.includes(this.search) || data.edesc.includes(this.search);
return match;
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.dataListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.dataList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
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.upload(formData, '').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getCompanyList()
} 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 = '.xlsx'
this.fileService.download(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')
}
})
}
clearData() {
if (this.modalStatus == 'add') {
this.setData()
} else {
this.setData({ code: this.dataSelect.code, tdesc: "", edesc: "", address: "", contact: "" })
}
}
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</a> </a>
</nav> </nav>
</div> </div>
<div class="mt-3 px-3rem !-mt-3 pt-50px"> <div class="mt-3 px-2rem !-mt-3 pt-50px">
<div id="underline-1" role="tabpanel" aria-labelledby="underline-item-1"> <div id="underline-1" role="tabpanel" aria-labelledby="underline-item-1">
<app-sub-employee-registration></app-sub-employee-registration> <app-sub-employee-registration></app-sub-employee-registration>
</div> </div>
......
<div class="w-full min-height-50px mb-10px justify-between items-center"> <div class="w-full min-height-50px mb-10px justify-between items-center">
<div class="flex pr-2 pb-2rem">
<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()"
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">Select All</label>
</div>
</div>
</div>
<div class="flex justify-between"> <div class="flex justify-between">
<div class="flex pr-2"> <div class="flex pr-2">
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
data-hs-overlay="#sub-employee-registration-modal-upload"> data-hs-overlay="#sub-employee-registration-modal-upload"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
นำเข้าข้อมูล นำเข้าข้อมูล
</button> </button>
<a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end" <a class="mx-2 justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px text-center text-secondary border-secondary border-b-2 align-items-end"
href="javascript:void(0);"> href="javascript:void(0);" (click)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์ ดาวน์โหลดตัวอย่างไฟล์
</a> </a>
</div> </div>
...@@ -33,13 +52,21 @@ ...@@ -33,13 +52,21 @@
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-info h-45px m-0 shadow-md"> <button class="ti-btn ti-btn-soft-danger h-45px m-0 shadow-md"
data-hs-overlay="#sub-employee-registration-alert-delete-modal"
(click)="modalType='deleteGroup';selectEmployee()">
<i class="ri-delete-bin-6-line"></i>
Delete
</button>
</div>
<div class="px-1">
<button class="ti-btn ti-btn-soft-info h-45px m-0 shadow-md">
<i class="ri-printer-line"></i> <i class="ri-printer-line"></i>
Print Print
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md"> <button class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
<i class="ti ti-book fs-l"></i> <i class="ti ti-book fs-l"></i>
Help Help
</button> </button>
...@@ -87,7 +114,7 @@ ...@@ -87,7 +114,7 @@
*ngFor="let item of employeeFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index"> *ngFor="let item of employeeFilter() | slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
<td class="text-center"> <td class="text-center">
<input type="checkbox" class="ti-form-checkbox cursor-pointer" id="checkbox-{{item.data.employeeId}}" <input type="checkbox" class="ti-form-checkbox cursor-pointer" id="checkbox-{{item.data.employeeId}}"
[(ngModel)]="item.check"> [(ngModel)]="item.check" (ngModelChange)="dataListCheck()">
<label for="checkbox-{{item.data.employeeId}}">&nbsp;{{item.data.employeeId}}</label> <label for="checkbox-{{item.data.employeeId}}">&nbsp;{{item.data.employeeId}}</label>
</td> </td>
<td>{{item.data.fname}}</td> <td>{{item.data.fname}}</td>
...@@ -357,17 +384,20 @@ ...@@ -357,17 +384,20 @@
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1> <h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2"> <div class="mt-2 p-2">
<div class="flex rounded-md"> <div class="flex rounded-md">
<input type="text" id="hs-trailing-button-add-on-with-icon" name="hs-trailing-button-add-on-with-icon" <input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md "> <input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
<button aria-label="button" type="button" class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm"> <button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i> <i class="ti ti-upload"></i>
</button> </button>
</div> </div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4"> <div class="flex justify-center mt-2rem mb-1rem space-x-4">
<a class="ti-btn ti-btn-secondary" href="javascript:void(0);"> <button type="submit" class="ti-btn ti-btn-secondary" data-hs-overlay="#position-unit-component-upload-modal"
[class.ti-btn-disabled]="!selectedFile" (click)="uploadFile()" [disabled]="!selectedFile"
[disabled]="!selectedFile">
อัปโหลด อัปโหลด
</a> </button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -12,6 +12,7 @@ import { Bu1Service } from 'src/app/shared/services/bu1.service'; ...@@ -12,6 +12,7 @@ import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { EmpGroupService } from 'src/app/shared/services/emp-group.service'; import { EmpGroupService } from 'src/app/shared/services/emp-group.service';
import { EmpTypeService } from 'src/app/shared/services/employee-type.service'; import { EmpTypeService } from 'src/app/shared/services/employee-type.service';
import { EmployeeService } from 'src/app/shared/services/employee.service'; import { EmployeeService } from 'src/app/shared/services/employee.service';
import { FileService } from 'src/app/shared/services/file.service';
import { PLService } from 'src/app/shared/services/pl.service'; import { PLService } from 'src/app/shared/services/pl.service';
import { PositionService } from 'src/app/shared/services/position.service'; import { PositionService } from 'src/app/shared/services/position.service';
import { BranchService } from 'src/app/shared/services/่branch.service'; import { BranchService } from 'src/app/shared/services/่branch.service';
...@@ -41,7 +42,7 @@ export class SubEmployeeRegistrationComponent { ...@@ -41,7 +42,7 @@ export class SubEmployeeRegistrationComponent {
currentPage = 1 currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1); page = Array.from({ length: 1 }, (_, i) => i + 1);
search = "" search = ""
modalType: 'add' | 'update' | 'delete' = 'add' modalType: 'add' | 'update' | 'delete' | 'deleteGroup' = 'add'
modal: DataModal = { modal: DataModal = {
search: "", search: "",
...@@ -49,6 +50,13 @@ export class SubEmployeeRegistrationComponent { ...@@ -49,6 +50,13 @@ export class SubEmployeeRegistrationComponent {
page: Array.from({ length: 1 }, (_, i) => i + 1) page: Array.from({ length: 1 }, (_, i) => i + 1)
} }
numDataListChecked = 0
isDataListChecked = false
isDataListCheckedAll = false
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
empGroup: { loading: boolean, dataList: EmpGroupModel[] } = { loading: false, dataList: [] } empGroup: { loading: boolean, dataList: EmpGroupModel[] } = { loading: false, dataList: [] }
bu1: { loading: boolean, dataList: Bu1Model[] } = { loading: false, dataList: [] } bu1: { loading: boolean, dataList: Bu1Model[] } = { loading: false, dataList: [] }
position: { loading: boolean, dataList: PositionModel[] } = { loading: false, dataList: [] } position: { loading: boolean, dataList: PositionModel[] } = { loading: false, dataList: [] }
...@@ -65,6 +73,7 @@ export class SubEmployeeRegistrationComponent { ...@@ -65,6 +73,7 @@ export class SubEmployeeRegistrationComponent {
private jobcodeService: JobCodeService, private jobcodeService: JobCodeService,
private branchService: BranchService, private branchService: BranchService,
private empTypeService: EmpTypeService, private empTypeService: EmpTypeService,
private fileService: FileService,
private pLService: PLService) { } private pLService: PLService) { }
ngOnInit(): void { ngOnInit(): void {
...@@ -77,6 +86,53 @@ export class SubEmployeeRegistrationComponent { ...@@ -77,6 +86,53 @@ export class SubEmployeeRegistrationComponent {
this.getEmpTypeList() this.getEmpTypeList()
this.getPlList() this.getPlList()
} }
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.employee.loading = true
this.fileService.upload(formData, '').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getEmployeeList()
} else {
this.showAlert(response.message, 'error')
this.employee.loading = false
this.cdr.detectChanges();
}
}, error: error => {
this.showAlert(error.message, 'error')
this.employee.loading = false
this.cdr.detectChanges();
}
})
}
downloadFile() {
const fileName = 'IMPORT_MPOSITION.xlsx'
this.fileService.download(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')
}
})
}
getPlList() { getPlList() {
this.pl.loading = false this.pl.loading = false
this.pLService.getList().subscribe({ this.pLService.getList().subscribe({
...@@ -225,6 +281,8 @@ export class SubEmployeeRegistrationComponent { ...@@ -225,6 +281,8 @@ export class SubEmployeeRegistrationComponent {
next: response => { next: response => {
this.employee.dataList = response.map((x: any) => ({ check: false, data: new MyEmployeeModel(x) })) this.employee.dataList = response.map((x: any) => ({ check: false, data: new MyEmployeeModel(x) }))
this.employee.loading = false this.employee.loading = false
this.isDataListCheckedAll = false
this.dataListCheckAll()
this.searchChange() this.searchChange()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
...@@ -233,10 +291,18 @@ export class SubEmployeeRegistrationComponent { ...@@ -233,10 +291,18 @@ export class SubEmployeeRegistrationComponent {
} }
}) })
} }
updateEmployeeList(type: 'add' | 'update' | 'delete') { updateEmployeeList(type: 'add' | 'update' | 'delete' | 'deleteGroup') {
let body = this.employee.select let body = this.employee.select
if (type == 'delete') { switch (type) {
body = [this.employee.select] case 'delete': {
body = [this.employee.select]
break;
}
case 'deleteGroup': {
body = this.employee.dataList.filter(x => x.check).map(x => new MyEmployeeModel(x.data))
type = 'delete'
break;
}
} }
this.employeeService[type](body).subscribe({ this.employeeService[type](body).subscribe({
next: response => { next: response => {
...@@ -254,6 +320,7 @@ export class SubEmployeeRegistrationComponent { ...@@ -254,6 +320,7 @@ export class SubEmployeeRegistrationComponent {
searchChange() { searchChange() {
this.currentPage = 1 this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.employeeFilter().length / 10) }, (_, i) => i + 1); this.page = Array.from({ length: Math.ceil(this.employeeFilter().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
} }
employeeFilter() { employeeFilter() {
return this.employee.dataList.filter(x => return this.employee.dataList.filter(x =>
...@@ -300,4 +367,22 @@ export class SubEmployeeRegistrationComponent { ...@@ -300,4 +367,22 @@ export class SubEmployeeRegistrationComponent {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}) })
} }
dataListCheckAll() {
const selectAll = this.isDataListCheckedAll;
this.employee.dataList.filter(x =>
x.data.employeeId.toLowerCase().includes(this.search.toLowerCase()) ||
x.data.fname.toLowerCase().includes(this.search.toLowerCase()) ||
x.data.lname.toLowerCase().includes(this.search.toLowerCase()) ||
x.data.position.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.data.jobCode.tdesc.toLowerCase().includes(this.search.toLowerCase())).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.employeeFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.employee.dataList.filter(x => x.check).length;
this.isDataListChecked = Boolean(this.numDataListChecked)
}
} }
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