From 86f2bb12fc6f7955a6499d3ce4bc804f37393517 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:50:57 +0700 Subject: [PATCH 01/37] =?UTF-8?q?[Ng=C3=A0y=20Ph=C3=A9p]=20C=E1=BA=ADp=20n?= =?UTF-8?q?h=E1=BA=ADt=20l=E1=BA=A1i=20t=C3=AAn=20c=E1=BB=99t=20cho=20b?= =?UTF-8?q?=E1=BA=A3ng=20ng=C3=A0y=20ngh=E1=BB=89=20ph=C3=A9p=20n=C4=83m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/LeaveManagementController.php | 4 ++-- BACKEND/app/Exports/LeaveManagementExport.php | 2 +- BACKEND/app/Jobs/InitializeLeaveDays.php | 6 ++--- BACKEND/app/Models/LeaveDays.php | 2 +- ...4_08_06_013033_create_leave_days_table.php | 2 +- ...ay_to_ld_day_total_in_leave_days_table.php | 22 +++++++++++++++++++ .../pages/LeaveManagement/LeaveManagement.tsx | 8 +++---- 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 BACKEND/database/migrations/2025_03_13_070714_rename_ld_day_to_ld_day_total_in_leave_days_table.php diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php index 477b056..9eff7e5 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php @@ -105,7 +105,7 @@ class LeaveManagementController extends Controller 'leaveDay' => [ 'id' => $item->id, 'ld_user_id' => $item->ld_user_id, - 'ld_day' => $item->ld_day, + 'ld_day_total' => $item->ld_day_total, 'ld_year' => $item->ld_year, 'ld_date_additional' => $item->ld_date_additional, 'ld_note' => $item->ld_note, @@ -133,7 +133,7 @@ class LeaveManagementController extends Controller $validatedData = $request->all(); $leaveDays = LeaveDays::find($validatedData['id']); - $leaveDays->ld_day = $validatedData['totalLeave']; + $leaveDays->ld_day_total = $validatedData['totalLeave']; $leaveDays->ld_date_additional = $validatedData['dayAdditional']; // Assuming you have this field to store additional days $leaveDays->ld_note = $validatedData['note']; diff --git a/BACKEND/app/Exports/LeaveManagementExport.php b/BACKEND/app/Exports/LeaveManagementExport.php index 038ade9..236ae42 100644 --- a/BACKEND/app/Exports/LeaveManagementExport.php +++ b/BACKEND/app/Exports/LeaveManagementExport.php @@ -41,7 +41,7 @@ class LeaveManagementExport implements FromArray, WithHeadings, WithStyles, With $stt = 0; foreach ($this->data as $index => $user) { $totalDayOff = 0; - $totalDayLeave = $user['leaveDay']['ld_day'] + $user['leaveDay']['ld_date_additional']; + $totalDayLeave = $user['leaveDay']['ld_day_total'] + $user['leaveDay']['ld_date_additional']; // Tính tổng ngày nghỉ theo tháng $monthlyLeaves = array_fill(1, 12, 0); diff --git a/BACKEND/app/Jobs/InitializeLeaveDays.php b/BACKEND/app/Jobs/InitializeLeaveDays.php index 3c545b5..57ec833 100644 --- a/BACKEND/app/Jobs/InitializeLeaveDays.php +++ b/BACKEND/app/Jobs/InitializeLeaveDays.php @@ -34,7 +34,7 @@ class InitializeLeaveDays implements ShouldQueue public function handle(): void { $users = User::get(); - $ld_day = 12; + $ld_day_total = 12; foreach ($users as $user) { // Kiểm tra xem dữ liệu của user này đã tồn tại cho năm hiện tại chưa $existingData = LeaveDays::where('ld_user_id', $user->id) @@ -55,7 +55,7 @@ class InitializeLeaveDays implements ShouldQueue $ld_note = ''; if ($previousYearData) { - $ld_date_additional = $previousYearData->ld_day + $previousYearData->ld_date_additional; + $ld_date_additional = $previousYearData->ld_day_total + $previousYearData->ld_date_additional; $totalLeaveDaysByMonth = Notes::join('categories', function ($join) { $join->on('notes.n_time_type', '=', 'categories.c_code') ->where('categories.c_type', 'TIME_TYPE'); @@ -82,7 +82,7 @@ class InitializeLeaveDays implements ShouldQueue // Tạo dữ liệu cho năm hiện tại LeaveDays::insert([ 'ld_user_id' => $user->id, - 'ld_day' => $ld_day, + 'ld_day_total' => $ld_day_total, 'ld_year' => $this->year, 'ld_date_additional' => $ld_date_additional, 'ld_note' => $ld_note, diff --git a/BACKEND/app/Models/LeaveDays.php b/BACKEND/app/Models/LeaveDays.php index 67b2024..8fad637 100644 --- a/BACKEND/app/Models/LeaveDays.php +++ b/BACKEND/app/Models/LeaveDays.php @@ -10,7 +10,7 @@ class LeaveDays extends Model use HasFactory; protected $fillable = [ - 'id', 'ld_user_id', 'ld_day', 'ld_year', 'ld_date_additional', 'ld_note' + 'id', 'ld_user_id', 'ld_day_total', 'ld_year', 'ld_date_additional', 'ld_note' ]; protected $table = 'leave_days'; diff --git a/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php b/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php index bb4db24..ec4db4e 100644 --- a/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php +++ b/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php @@ -14,7 +14,7 @@ return new class extends Migration Schema::create('leave_days', function (Blueprint $table) { $table->id(); $table->integer('ld_user_id'); // Giả định user_id là khóa ngoại - $table->float('ld_day'); + $table->float('ld_day_total'); $table->integer('ld_year'); $table->float('ld_date_additional')->default(0); $table->text('ld_note')->nullable(); diff --git a/BACKEND/database/migrations/2025_03_13_070714_rename_ld_day_to_ld_day_total_in_leave_days_table.php b/BACKEND/database/migrations/2025_03_13_070714_rename_ld_day_to_ld_day_total_in_leave_days_table.php new file mode 100644 index 0000000..51b4754 --- /dev/null +++ b/BACKEND/database/migrations/2025_03_13_070714_rename_ld_day_to_ld_day_total_in_leave_days_table.php @@ -0,0 +1,22 @@ +renameColumn('ld_day_total', 'ld_day_total'); + }); + } + + public function down() + { + Schema::table('leave_days', function (Blueprint $table) { + $table->renameColumn('ld_day_total', 'ld_day_total'); + }); + } +} diff --git a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx index 1a8b020..181e615 100644 --- a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx +++ b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx @@ -40,7 +40,7 @@ interface LeaveDay { id: number ld_user_id: number ld_year: number - ld_day: number + ld_day_total: number ld_date_additional: number ld_note: string created_at: string | null @@ -472,7 +472,7 @@ const LeaveManagement = () => { {data.map((user, index) => { let totalDayOff = 0 let totalDayLeave = - user.leaveDay.ld_day + user.leaveDay.ld_date_additional + user.leaveDay.ld_day_total + user.leaveDay.ld_date_additional let ld_note = user.leaveDay.ld_note return ( @@ -585,9 +585,9 @@ const LeaveManagement = () => { style={{ cursor: 'pointer' }} onClick={() => { let totalLeave = - user.leaveDay.ld_day == 0 + user.leaveDay.ld_day_total == 0 ? '' - : String(user.leaveDay.ld_day) + : String(user.leaveDay.ld_day_total) let dayAdditional = user.leaveDay.ld_date_additional == 0 ? '' From 8ce0d957b159312a7198ff22b6d56fbb732ae3d5 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:54:37 +0700 Subject: [PATCH 02/37] =?UTF-8?q?[Ng=C3=A0y=20Ph=C3=A9p]=20C=E1=BA=ADp=20n?= =?UTF-8?q?h=E1=BA=ADt=20l=E1=BA=A1i=20t=C3=AAn=20c=E1=BB=99t=20cho=20b?= =?UTF-8?q?=E1=BA=A3ng=20ng=C3=A0y=20ngh=E1=BB=89=20ph=C3=A9p=20n=C4=83m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/LeaveManagementController.php | 4 ++-- BACKEND/app/Exports/LeaveManagementExport.php | 2 +- BACKEND/app/Jobs/DeductLeaveDays.php | 8 +++---- BACKEND/app/Jobs/InitializeLeaveDays.php | 12 +++++----- BACKEND/app/Models/LeaveDays.php | 2 +- ...4_08_06_013033_create_leave_days_table.php | 2 +- ..._special_leave_day_to_leave_days_table.php | 22 +++++++++++++++++++ ..._ld_additional_day_in_leave_days_table.php | 22 +++++++++++++++++++ .../pages/LeaveManagement/LeaveManagement.tsx | 8 +++---- 9 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php create mode 100644 BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php index 9eff7e5..79c3516 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php @@ -107,7 +107,7 @@ class LeaveManagementController extends Controller 'ld_user_id' => $item->ld_user_id, 'ld_day_total' => $item->ld_day_total, 'ld_year' => $item->ld_year, - 'ld_date_additional' => $item->ld_date_additional, + 'ld_additional_day' => $item->ld_additional_day, 'ld_note' => $item->ld_note, 'created_at' => $item->created_at, 'updated_at' => $item->updated_at, @@ -134,7 +134,7 @@ class LeaveManagementController extends Controller $leaveDays = LeaveDays::find($validatedData['id']); $leaveDays->ld_day_total = $validatedData['totalLeave']; - $leaveDays->ld_date_additional = $validatedData['dayAdditional']; // Assuming you have this field to store additional days + $leaveDays->ld_additional_day = $validatedData['dayAdditional']; // Assuming you have this field to store additional days $leaveDays->ld_note = $validatedData['note']; $leaveDays->save(); diff --git a/BACKEND/app/Exports/LeaveManagementExport.php b/BACKEND/app/Exports/LeaveManagementExport.php index 236ae42..402353b 100644 --- a/BACKEND/app/Exports/LeaveManagementExport.php +++ b/BACKEND/app/Exports/LeaveManagementExport.php @@ -41,7 +41,7 @@ class LeaveManagementExport implements FromArray, WithHeadings, WithStyles, With $stt = 0; foreach ($this->data as $index => $user) { $totalDayOff = 0; - $totalDayLeave = $user['leaveDay']['ld_day_total'] + $user['leaveDay']['ld_date_additional']; + $totalDayLeave = $user['leaveDay']['ld_day_total'] + $user['leaveDay']['ld_additional_day']; // Tính tổng ngày nghỉ theo tháng $monthlyLeaves = array_fill(1, 12, 0); diff --git a/BACKEND/app/Jobs/DeductLeaveDays.php b/BACKEND/app/Jobs/DeductLeaveDays.php index 86dc3b0..2d4bd4a 100644 --- a/BACKEND/app/Jobs/DeductLeaveDays.php +++ b/BACKEND/app/Jobs/DeductLeaveDays.php @@ -36,7 +36,7 @@ class DeductLeaveDays implements ShouldQueue foreach ($users as $user) { $existingData = LeaveDays::where('ld_user_id', $user->id) ->where('ld_year', $this->year) - ->where('ld_date_additional', ">", 0) + ->where('ld_additional_day', ">", 0) ->first(); if (!$existingData) { continue; @@ -59,11 +59,11 @@ class DeductLeaveDays implements ShouldQueue if ($totalLeaveDaysByMonth) { //Nếu ngày phép thừa năm trước chưa sử dụng hết => cập nhật lại ngày đó (Ngày tồn đọng - ngày sử dụng) - if ($existingData->ld_date_additional > $totalLeaveDaysByMonth->leave_days) { + if ($existingData->ld_additional_day > $totalLeaveDaysByMonth->leave_days) { LeaveDays::where('ld_year', $this->year) ->where('ld_user_id', $user->id) ->update([ - 'ld_date_additional' => $totalLeaveDaysByMonth->leave_days, + 'ld_additional_day' => $totalLeaveDaysByMonth->leave_days, ]); } } else { @@ -71,7 +71,7 @@ class DeductLeaveDays implements ShouldQueue LeaveDays::where('ld_year', $this->year) ->where('ld_user_id', $user->id) ->update([ - 'ld_date_additional' => "0", + 'ld_additional_day' => "0", ]); } } diff --git a/BACKEND/app/Jobs/InitializeLeaveDays.php b/BACKEND/app/Jobs/InitializeLeaveDays.php index 57ec833..1d7569f 100644 --- a/BACKEND/app/Jobs/InitializeLeaveDays.php +++ b/BACKEND/app/Jobs/InitializeLeaveDays.php @@ -51,11 +51,11 @@ class InitializeLeaveDays implements ShouldQueue ->where('ld_year', $this->year - 1) ->first(); - $ld_date_additional = 0; + $ld_additional_day = 0; $ld_note = ''; if ($previousYearData) { - $ld_date_additional = $previousYearData->ld_day_total + $previousYearData->ld_date_additional; + $ld_additional_day = $previousYearData->ld_day_total + $previousYearData->ld_additional_day; $totalLeaveDaysByMonth = Notes::join('categories', function ($join) { $join->on('notes.n_time_type', '=', 'categories.c_code') ->where('categories.c_type', 'TIME_TYPE'); @@ -71,9 +71,9 @@ class InitializeLeaveDays implements ShouldQueue ->groupBy(DB::raw('notes.n_year')) ->first(); if ($totalLeaveDaysByMonth) { - $ld_date_additional = $ld_date_additional - $totalLeaveDaysByMonth->leave_days; - if ($ld_date_additional < 0) { - $ld_date_additional = 0; + $ld_additional_day = $ld_additional_day - $totalLeaveDaysByMonth->leave_days; + if ($ld_additional_day < 0) { + $ld_additional_day = 0; } } $ld_note = 'Cộng dồn ngày phép năm cũ'; @@ -84,7 +84,7 @@ class InitializeLeaveDays implements ShouldQueue 'ld_user_id' => $user->id, 'ld_day_total' => $ld_day_total, 'ld_year' => $this->year, - 'ld_date_additional' => $ld_date_additional, + 'ld_additional_day' => $ld_additional_day, 'ld_note' => $ld_note, 'created_at' => now(), 'updated_at' => now(), diff --git a/BACKEND/app/Models/LeaveDays.php b/BACKEND/app/Models/LeaveDays.php index 8fad637..a974950 100644 --- a/BACKEND/app/Models/LeaveDays.php +++ b/BACKEND/app/Models/LeaveDays.php @@ -10,7 +10,7 @@ class LeaveDays extends Model use HasFactory; protected $fillable = [ - 'id', 'ld_user_id', 'ld_day_total', 'ld_year', 'ld_date_additional', 'ld_note' + 'id', 'ld_user_id', 'ld_day_total', 'ld_year', 'ld_additional_day', 'ld_note' ]; protected $table = 'leave_days'; diff --git a/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php b/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php index ec4db4e..bb4db24 100644 --- a/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php +++ b/BACKEND/database/migrations/2024_08_06_013033_create_leave_days_table.php @@ -14,7 +14,7 @@ return new class extends Migration Schema::create('leave_days', function (Blueprint $table) { $table->id(); $table->integer('ld_user_id'); // Giả định user_id là khóa ngoại - $table->float('ld_day_total'); + $table->float('ld_day'); $table->integer('ld_year'); $table->float('ld_date_additional')->default(0); $table->text('ld_note')->nullable(); diff --git a/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php b/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php new file mode 100644 index 0000000..f419e78 --- /dev/null +++ b/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php @@ -0,0 +1,22 @@ +integer('ld_special_leave_day')->nullable(); // Adding the new field + }); + } + + public function down() + { + Schema::table('leave_days', function (Blueprint $table) { + $table->dropColumn('ld_special_leave_day'); // Dropping the field if needed + }); + } +} diff --git a/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php b/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php new file mode 100644 index 0000000..ec600f4 --- /dev/null +++ b/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php @@ -0,0 +1,22 @@ +renameColumn('ld_additional_day', 'ld_additional_day'); + }); + } + + public function down() + { + Schema::table('leave_days', function (Blueprint $table) { + $table->renameColumn('ld_additional_day', 'ld_additional_day'); + }); + } +} \ No newline at end of file diff --git a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx index 181e615..0e4d890 100644 --- a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx +++ b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx @@ -41,7 +41,7 @@ interface LeaveDay { ld_user_id: number ld_year: number ld_day_total: number - ld_date_additional: number + ld_additional_day: number ld_note: string created_at: string | null updated_at: string | null @@ -472,7 +472,7 @@ const LeaveManagement = () => { {data.map((user, index) => { let totalDayOff = 0 let totalDayLeave = - user.leaveDay.ld_day_total + user.leaveDay.ld_date_additional + user.leaveDay.ld_day_total + user.leaveDay.ld_additional_day let ld_note = user.leaveDay.ld_note return ( @@ -589,9 +589,9 @@ const LeaveManagement = () => { ? '' : String(user.leaveDay.ld_day_total) let dayAdditional = - user.leaveDay.ld_date_additional == 0 + user.leaveDay.ld_additional_day == 0 ? '' - : String(user.leaveDay.ld_date_additional) + : String(user.leaveDay.ld_additional_day) open1() setCustomAddNotes({ ...customAddNotes, From 650cfe1b13c3c3a435318add4ad355faf46ee0c1 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Thu, 13 Mar 2025 15:41:43 +0700 Subject: [PATCH 03/37] =?UTF-8?q?[Ng=C3=A0y=20Ph=C3=A9p]=20C=E1=BA=ADp=20n?= =?UTF-8?q?h=E1=BA=ADt=20lo=E1=BA=A1i=20ph=C3=A9p=20n=E1=BB=99p:=20WFH,=20?= =?UTF-8?q?Ngh=E1=BB=89=20ph=C3=A9p=20n=C4=83m,=20Ngh=E1=BB=89=20kh=C3=B4n?= =?UTF-8?q?g=20l=C6=B0=C6=A1ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...083500_update_name_in_categories_table.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 BACKEND/database/migrations/2025_03_13_083500_update_name_in_categories_table.php diff --git a/BACKEND/database/migrations/2025_03_13_083500_update_name_in_categories_table.php b/BACKEND/database/migrations/2025_03_13_083500_update_name_in_categories_table.php new file mode 100644 index 0000000..9cd370f --- /dev/null +++ b/BACKEND/database/migrations/2025_03_13_083500_update_name_in_categories_table.php @@ -0,0 +1,41 @@ +insert([ + [ + 'c_code' => 'LEAVE_WITHOUT_PAY', + 'c_name' => 'Nghỉ không hưởng lương', + 'c_type' => 'REASON', + 'c_value' => "", + 'c_active' => 1, + 'created_at' => now(), + 'updated_at' => now(), + ], + ]); + + DB::table('categories') + ->where('c_name', 'Nghỉ phép') + ->update(['c_name' => 'Nghỉ phép năm']); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + DB::table('categories') + ->where('c_name', 'Nghỉ phép năm') + ->update(['c_name' => 'Nghỉ phép']); + } +}; From 308f5a3a2ee1b550061e56ae0472ecd467f85290 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:34:54 +0700 Subject: [PATCH 04/37] =?UTF-8?q?[Ng=C3=A0y=20Ph=C3=A9p]=20Th=E1=BB=B1c=20?= =?UTF-8?q?hi=E1=BB=87n=20Job=20c=E1=BA=ADp=20nh=E1=BA=ADt=20ng=C3=A0y=20p?= =?UTF-8?q?h=C3=A9p=20b=E1=BA=A3ng=20m=E1=BB=97i=20th=C3=A1ng=20+=201=20ng?= =?UTF-8?q?=C3=A0y=20ph=C3=A9p=20cho=20m=E1=BB=97i=20user,=20th=E1=BB=9Di?= =?UTF-8?q?=20gian=2000:00=20ng=C3=A0y=201=20h=C3=A0ng=20th=C3=A1ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/AddMonthlyLeaveDaysCommand.php | 24 +++++++ .../Commands/InitializeLeaveDaysCommand.php | 5 +- BACKEND/app/Console/Kernel.php | 6 +- BACKEND/app/Jobs/AddMonthlyLeaveDays.php | 70 +++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 BACKEND/app/Console/Commands/AddMonthlyLeaveDaysCommand.php create mode 100644 BACKEND/app/Jobs/AddMonthlyLeaveDays.php diff --git a/BACKEND/app/Console/Commands/AddMonthlyLeaveDaysCommand.php b/BACKEND/app/Console/Commands/AddMonthlyLeaveDaysCommand.php new file mode 100644 index 0000000..f691d15 --- /dev/null +++ b/BACKEND/app/Console/Commands/AddMonthlyLeaveDaysCommand.php @@ -0,0 +1,24 @@ +argument('month'); + $year = $this->argument('year'); + AddMonthlyLeaveDays::dispatch($month, $year); + } +} \ No newline at end of file diff --git a/BACKEND/app/Console/Commands/InitializeLeaveDaysCommand.php b/BACKEND/app/Console/Commands/InitializeLeaveDaysCommand.php index ad0a9e9..bf74a72 100644 --- a/BACKEND/app/Console/Commands/InitializeLeaveDaysCommand.php +++ b/BACKEND/app/Console/Commands/InitializeLeaveDaysCommand.php @@ -8,7 +8,7 @@ use App\Jobs\InitializeLeaveDays; class InitializeLeaveDaysCommand extends Command { protected $signature = 'initialize:leavedays {year?}'; - protected $description = 'Initialize leave days for users'; + protected $description = 'Cấp phép năm cho tất cả người dùng'; public function __construct() { @@ -18,6 +18,7 @@ class InitializeLeaveDaysCommand extends Command public function handle() { $year = $this->argument('year'); - InitializeLeaveDays::dispatch($year); + // Không sử dụng nữa, theo rule mới + // InitializeLeaveDays::dispatch($year); } } diff --git a/BACKEND/app/Console/Kernel.php b/BACKEND/app/Console/Kernel.php index 6d56e12..d8fa86b 100755 --- a/BACKEND/app/Console/Kernel.php +++ b/BACKEND/app/Console/Kernel.php @@ -3,6 +3,7 @@ namespace App\Console; use App\Jobs\DeductLeaveDays; +use App\Jobs\AddMonthlyLeaveDays; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -24,7 +25,7 @@ class Kernel extends ConsoleKernel // ->dailyAt('18:00'); // Chạy command vào ngày 31/12 lúc 23:59:59 mỗi năm - $schedule->command('initialize:leavedays')->yearlyOn(12, 31, '23:59:59'); + // $schedule->command('initialize:leavedays')->yearlyOn(12, 31, '23:59:59'); $schedule->command('leave:deduct')->yearlyOn(3, 31, '23:59:59'); // Chạy buổi sáng lúc 12:00 @@ -32,6 +33,9 @@ class Kernel extends ConsoleKernel // Chạy buổi chiều lúc 17:30 $schedule->command('attendance:check C')->dailyAt('17:30'); + + // Chạy vào 00:01 ngày đầu tiên của mỗi tháng + $schedule->command('add:monthly-leavedays')->monthlyOn(1, '00:01'); } /** diff --git a/BACKEND/app/Jobs/AddMonthlyLeaveDays.php b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php new file mode 100644 index 0000000..3e933b7 --- /dev/null +++ b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php @@ -0,0 +1,70 @@ +month = $month ?? Carbon::now()->month; + $this->year = $year ?? Carbon::now()->year; + } + + public function handle(): void + { + $users = User::get(); + + foreach ($users as $user) { + $leaveDay = LeaveDays::where('ld_user_id', $user->id) + ->where('ld_year', $this->year) + ->first(); + + if (!$leaveDay) { + // Nếu chưa có dữ liệu năm hiện tại, tạo mới + // Số ngày phép bằng với tháng hiện tại + $leaveDay = new LeaveDays([ + 'ld_user_id' => $user->id, + 'ld_day_total' => $this->month, // Số ngày phép bằng tháng hiện tại + 'ld_year' => $this->year, + 'ld_additional_day' => 0, + 'ld_note' => 'Khởi tạo ngày phép đến tháng ' . $this->month, + 'ld_special_leave_day' => 0, + ]); + $leaveDay->save(); + } else { + // Kiểm tra nếu số ngày phép hiện tại nhỏ hơn tháng hiện tại + if ($leaveDay->ld_day_total < $this->month) { + // Cập nhật số ngày phép bằng với tháng hiện tại + $oldDays = $leaveDay->ld_day_total; + $leaveDay->ld_day_total = $this->month; + + // Xử lý ghi chú + $newNote = "Cập nhật ngày phép đến tháng " . $this->month; + if (!empty($leaveDay->ld_note)) { + // Nếu đã có ghi chú, thêm ghi chú mới vào và xuống dòng + $leaveDay->ld_note = $leaveDay->ld_note . "\n" . $newNote; + } else { + // Nếu chưa có ghi chú, gán ghi chú mới + $leaveDay->ld_note = $newNote; + } + + $leaveDay->save(); + } + } + } + } +} From af5721682b8090c5c87f7ab1a5f0edcc36f7f434 Mon Sep 17 00:00:00 2001 From: Truong Vo <41848815+vmtruong301296@users.noreply.github.com> Date: Tue, 15 Apr 2025 14:07:20 +0700 Subject: [PATCH 05/37] =?UTF-8?q?[Ng=C3=A0y=20Ph=C3=A9p]=20B=E1=BB=95=20su?= =?UTF-8?q?ng=20ch=E1=BB=A9c=20n=C4=83ng=20c=E1=BA=ADp=20nh=E1=BA=ADt=20ng?= =?UTF-8?q?=C3=A0y=20ngh=E1=BB=89=20cho=20ng=C3=A0y=20ngh=E1=BB=89=20?= =?UTF-8?q?=C4=91=E1=BA=B7t=20bi=E1=BB=87t=20(3=20ng=C3=A0y=20ngh=E1=BB=89?= =?UTF-8?q?=20=C4=91=C3=A1m=20c=C6=B0=E1=BB=9Bi)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/LeaveManagementController.php | 4 +- BACKEND/app/Jobs/AddMonthlyLeaveDays.php | 1 - ..._special_leave_day_to_leave_days_table.php | 2 +- ..._ld_additional_day_in_leave_days_table.php | 4 +- .../pages/LeaveManagement/LeaveManagement.tsx | 98 ++++++++++++++----- 5 files changed, 80 insertions(+), 29 deletions(-) diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php index 79c3516..548446a 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/LeaveManagementController.php @@ -108,6 +108,7 @@ class LeaveManagementController extends Controller 'ld_day_total' => $item->ld_day_total, 'ld_year' => $item->ld_year, 'ld_additional_day' => $item->ld_additional_day, + 'ld_special_leave_day' => $item->ld_special_leave_day, 'ld_note' => $item->ld_note, 'created_at' => $item->created_at, 'updated_at' => $item->updated_at, @@ -134,7 +135,8 @@ class LeaveManagementController extends Controller $leaveDays = LeaveDays::find($validatedData['id']); $leaveDays->ld_day_total = $validatedData['totalLeave']; - $leaveDays->ld_additional_day = $validatedData['dayAdditional']; // Assuming you have this field to store additional days + $leaveDays->ld_additional_day = $validatedData['dayAdditional']; + $leaveDays->ld_special_leave_day = $validatedData['specialLeave']; $leaveDays->ld_note = $validatedData['note']; $leaveDays->save(); diff --git a/BACKEND/app/Jobs/AddMonthlyLeaveDays.php b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php index 3e933b7..4c58b9f 100644 --- a/BACKEND/app/Jobs/AddMonthlyLeaveDays.php +++ b/BACKEND/app/Jobs/AddMonthlyLeaveDays.php @@ -61,7 +61,6 @@ class AddMonthlyLeaveDays implements ShouldQueue // Nếu chưa có ghi chú, gán ghi chú mới $leaveDay->ld_note = $newNote; } - $leaveDay->save(); } } diff --git a/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php b/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php index f419e78..863d79f 100644 --- a/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php +++ b/BACKEND/database/migrations/2025_03_13_075133_add_ld_special_leave_day_to_leave_days_table.php @@ -9,7 +9,7 @@ class AddLdSpecialLeaveDayToLeaveDaysTable extends Migration public function up() { Schema::table('leave_days', function (Blueprint $table) { - $table->integer('ld_special_leave_day')->nullable(); // Adding the new field + $table->float('ld_special_leave_day')->default(0); // Adding the new field }); } diff --git a/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php b/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php index ec600f4..b6be1ae 100644 --- a/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php +++ b/BACKEND/database/migrations/2025_03_13_075235_rename_ld_date_additional_to_ld_additional_day_in_leave_days_table.php @@ -9,14 +9,14 @@ class RenameLdDateAdditionalToLdAdditionalDayInLeaveDaysTable extends Migration public function up() { Schema::table('leave_days', function (Blueprint $table) { - $table->renameColumn('ld_additional_day', 'ld_additional_day'); + $table->renameColumn('ld_date_additional', 'ld_additional_day'); }); } public function down() { Schema::table('leave_days', function (Blueprint $table) { - $table->renameColumn('ld_additional_day', 'ld_additional_day'); + $table->renameColumn('ld_date_additional', 'ld_additional_day'); }); } } \ No newline at end of file diff --git a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx index 0e4d890..9f45755 100644 --- a/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx +++ b/FRONTEND/src/pages/LeaveManagement/LeaveManagement.tsx @@ -1,4 +1,8 @@ -import { getLeaveManagement, updateNoteLeave, exportLeaveManagement } from '@/api/Admin' +import { + getLeaveManagement, + updateNoteLeave, + exportLeaveManagement, +} from '@/api/Admin' import { update } from '@/rtk/helpers/CRUD' import { get, exportFile } from '@/rtk/helpers/apiService' import { @@ -42,6 +46,7 @@ interface LeaveDay { ld_year: number ld_day_total: number ld_additional_day: number + ld_special_leave_day: number ld_note: string created_at: string | null updated_at: string | null @@ -75,6 +80,7 @@ const LeaveManagement = () => { note: string totalLeave: string dayAdditional: string + specialLeave: string }>({ id: 0, user: { @@ -84,6 +90,7 @@ const LeaveManagement = () => { note: '', totalLeave: '', dayAdditional: '', + specialLeave: '', }) const [data, setData] = useState([]) @@ -122,6 +129,7 @@ const LeaveManagement = () => { }, totalLeave: string, dayAdditional: string, + specialLeave: string, note: string, ) => { try { @@ -132,6 +140,7 @@ const LeaveManagement = () => { users: users, totalLeave: totalLeave, dayAdditional: dayAdditional, + specialLeave: specialLeave, note: note, }, getLeaveList, @@ -237,8 +246,8 @@ const LeaveManagement = () => {
{isNewMonth &&

Month {lastmonth}

}

- - {itemDay.reason_name} ({itemDay.time_type_name}) {itemDay.day} - /{itemDay.month} + - {itemDay.reason_name} ({itemDay.time_type_name}) {itemDay.day}/ + {itemDay.month}

) @@ -249,15 +258,14 @@ const LeaveManagement = () => { try { const timestamp = moment().format('DDMMYYYY_HHmmss') const fileName = `LeaveManagement_${date.year}_${timestamp}.xlsx` - + await exportFile( exportLeaveManagement, { - year: parseInt(date.year) + year: parseInt(date.year), }, - fileName + fileName, ) - } catch (error) { console.error('Export error:', error) notifications.show({ @@ -271,9 +279,7 @@ const LeaveManagement = () => { return (
-

- Leave Management -

+

Leave Management

{ } }} label={'Total Leave'} - placeholder="Input placeholder" + placeholder="Input total leave days" /> { } }} label={'Day additional leave'} - placeholder="Input placeholder" + placeholder="Input additional leave days" + /> + { + const value = e.target.value + if (value) { + const floatValue = parseFloat(value) + if ( + /^\d*\.?\d?$/.test(value) && + floatValue >= 0 && + floatValue <= 20 + ) { + setCustomAddNotes({ + ...customAddNotes, + specialLeave: value, + }) + } + } else { + setCustomAddNotes({ + ...customAddNotes, + specialLeave: '', + }) + } + }} + label={'Day special leave'} + placeholder="Input special leave days" /> - +