diff --git a/lib/data/core/functions/shared_function.dart b/lib/data/core/functions/shared_function.dart index dca8c9f9..737217b4 100644 --- a/lib/data/core/functions/shared_function.dart +++ b/lib/data/core/functions/shared_function.dart @@ -1,4 +1,5 @@ import 'package:injectable/injectable.dart'; +import '../../model/leave/leave.dart'; @Injectable() class AppFunctions { @@ -19,4 +20,22 @@ class AppFunctions { return true; } } + + String getNotificationDuration( + {required double total, + required LeaveDayDuration firstLeaveDayDuration}) { + if (total <= 1) { + if (firstLeaveDayDuration == LeaveDayDuration.firstHalfLeave) { + return "First Half"; + } else if (firstLeaveDayDuration == LeaveDayDuration.secondHalfLeave) { + return "Second Half"; + } else if (firstLeaveDayDuration == LeaveDayDuration.fullLeave) { + return "Full day"; + } else { + return "$total day"; + } + } else { + return "$total days"; + } + } } diff --git a/lib/data/services/mail_notification_service.dart b/lib/data/services/mail_notification_service.dart index 23c09209..1ec4fd44 100644 --- a/lib/data/services/mail_notification_service.dart +++ b/lib/data/services/mail_notification_service.dart @@ -25,6 +25,7 @@ class NotificationService { {required String name, required String reason, required DateTime startDate, + required String duration, required DateTime endDate, required String receiver}) async { if (kDebugMode) return; @@ -36,6 +37,7 @@ class NotificationService { "date": getFormatDate(startDate: startDate, endDate: endDate), "status": LeaveStatus.pending.value, 'reason': reason, + 'duration': duration, 'receiver': receiver, })); if (response.statusCode == 200) { diff --git a/lib/ui/user/leaves/apply_leave/bloc/apply_leave_bloc.dart b/lib/ui/user/leaves/apply_leave/bloc/apply_leave_bloc.dart index 1a21b55f..3ce0cd4a 100644 --- a/lib/ui/user/leaves/apply_leave/bloc/apply_leave_bloc.dart +++ b/lib/ui/user/leaves/apply_leave/bloc/apply_leave_bloc.dart @@ -124,11 +124,15 @@ class ApplyLeaveBloc extends Bloc _userStateNotifier.currentSpace!.notificationEmail; if (notificationEmail != null) { await _notificationService.notifyHRForNewLeave( - name: _userStateNotifier.employee.name, - startDate: leaveData.startDate, - endDate: leaveData.endDate, - reason: leaveData.reason, - receiver: notificationEmail); + name: _userStateNotifier.employee.name, + startDate: leaveData.startDate, + endDate: leaveData.endDate, + reason: leaveData.reason, + receiver: notificationEmail, + duration: _appFunctions.getNotificationDuration( + total: leaveData.total, + firstLeaveDayDuration: leaveData.perDayDuration.first), + ); } emit(state.copyWith( leaveRequestStatus: Status.success, leaveId: leaveData.leaveId)); diff --git a/test/unit_test/admin/home/search_member/invite_member_bloc_test.mocks.dart b/test/unit_test/admin/home/search_member/invite_member_bloc_test.mocks.dart index 99e73598..0641475a 100644 --- a/test/unit_test/admin/home/search_member/invite_member_bloc_test.mocks.dart +++ b/test/unit_test/admin/home/search_member/invite_member_bloc_test.mocks.dart @@ -433,6 +433,7 @@ class MockNotificationService extends _i1.Mock required String? name, required String? reason, required DateTime? startDate, + required String? duration, required DateTime? endDate, required String? receiver, }) => @@ -444,6 +445,7 @@ class MockNotificationService extends _i1.Mock #name: name, #reason: reason, #startDate: startDate, + #duration: duration, #endDate: endDate, #receiver: receiver, }, diff --git a/test/unit_test/admin/leaves/application_detail/admin_leave_request_details_bloc_test.mocks.dart b/test/unit_test/admin/leaves/application_detail/admin_leave_request_details_bloc_test.mocks.dart index 90f302b2..e851c072 100644 --- a/test/unit_test/admin/leaves/application_detail/admin_leave_request_details_bloc_test.mocks.dart +++ b/test/unit_test/admin/leaves/application_detail/admin_leave_request_details_bloc_test.mocks.dart @@ -495,6 +495,7 @@ class MockNotificationService extends _i1.Mock required String? name, required String? reason, required DateTime? startDate, + required String? duration, required DateTime? endDate, required String? receiver, }) => @@ -506,6 +507,7 @@ class MockNotificationService extends _i1.Mock #name: name, #reason: reason, #startDate: startDate, + #duration: duration, #endDate: endDate, #receiver: receiver, }, diff --git a/test/unit_test/space/join_space/join_space_test.mocks.dart b/test/unit_test/space/join_space/join_space_test.mocks.dart index 9f7e341a..e26fac52 100644 --- a/test/unit_test/space/join_space/join_space_test.mocks.dart +++ b/test/unit_test/space/join_space/join_space_test.mocks.dart @@ -701,6 +701,7 @@ class MockNotificationService extends _i1.Mock required String? name, required String? reason, required DateTime? startDate, + required String? duration, required DateTime? endDate, required String? receiver, }) => @@ -712,6 +713,7 @@ class MockNotificationService extends _i1.Mock #name: name, #reason: reason, #startDate: startDate, + #duration: duration, #endDate: endDate, #receiver: receiver, }, diff --git a/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.dart b/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.dart index c8dcfca5..df58b992 100644 --- a/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.dart +++ b/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.dart @@ -348,6 +348,7 @@ void main() { receiver: 'hr@canopas.com', name: "dummy", startDate: leave.startDate, + duration: appFunctions.getNotificationDuration(total: leave.total, firstLeaveDayDuration:leave.perDayDuration.first), endDate: leave.endDate)) .thenAnswer((realInvocation) async => true); leaveRequestBloc.add(ApplyLeaveEndDateChangeEvent(endDate: futureDate)); diff --git a/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.mocks.dart b/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.mocks.dart index 27330591..a860ea78 100644 --- a/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.mocks.dart +++ b/test/unit_test/user/leaves/apply_leave/apply_leave_bloc_test.mocks.dart @@ -395,6 +395,7 @@ class MockNotificationService extends _i1.Mock required String? name, required String? reason, required DateTime? startDate, + required String? duration, required DateTime? endDate, required String? receiver, }) => @@ -406,6 +407,7 @@ class MockNotificationService extends _i1.Mock #name: name, #reason: reason, #startDate: startDate, + #duration: duration, #endDate: endDate, #receiver: receiver, },