From ef416b6942890794f55cf90cf8ebefc825f56591 Mon Sep 17 00:00:00 2001 From: Shruti Apte Date: Thu, 5 Dec 2024 10:15:39 +0530 Subject: [PATCH] worked on small improvements in leaves and holidays module --- .../Container/Table/TableRow.tsx | 2 +- .../TimeoffForm/DesktopTimeoffForm.tsx | 7 ++++++- .../TimeoffEntries/TimeoffForm/index.tsx | 18 ++++++++++++++++++ app/services/timeoff_entries/index_service.rb | 16 ++++++++++------ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/javascript/src/components/LeaveManagement/Container/Table/TableRow.tsx b/app/javascript/src/components/LeaveManagement/Container/Table/TableRow.tsx index f518bb5384..110a04976b 100644 --- a/app/javascript/src/components/LeaveManagement/Container/Table/TableRow.tsx +++ b/app/javascript/src/components/LeaveManagement/Container/Table/TableRow.tsx @@ -36,7 +36,7 @@ const TableRow = ({ timeoffEntry }) => { {leaveName} - {minToHHMM(duration)} + {leaveType ? minToHHMM(duration) : "-:-"} ); diff --git a/app/javascript/src/components/TimeoffEntries/TimeoffForm/DesktopTimeoffForm.tsx b/app/javascript/src/components/TimeoffEntries/TimeoffForm/DesktopTimeoffForm.tsx index ef3342372e..7e67037a16 100644 --- a/app/javascript/src/components/TimeoffEntries/TimeoffForm/DesktopTimeoffForm.tsx +++ b/app/javascript/src/components/TimeoffEntries/TimeoffForm/DesktopTimeoffForm.tsx @@ -37,6 +37,8 @@ const DesktopTimeoffForm = ({ setEditTimeoffEntryId, } = useTimesheetEntries(); + const holidayEntry = isHolidayEntry(); + return (
@@ -124,9 +126,12 @@ const DesktopTimeoffForm = ({
diff --git a/app/javascript/src/components/TimeoffEntries/TimeoffForm/index.tsx b/app/javascript/src/components/TimeoffEntries/TimeoffForm/index.tsx index 31085f786b..39784b5482 100644 --- a/app/javascript/src/components/TimeoffEntries/TimeoffForm/index.tsx +++ b/app/javascript/src/components/TimeoffEntries/TimeoffForm/index.tsx @@ -4,6 +4,7 @@ import React, { useState, useEffect } from "react"; import dayjs from "dayjs"; import { minFromHHMM, minToHHMM } from "helpers"; +import companiesApi from "apis/companies"; import timeoffEntryApi from "apis/timeoff-entry"; import { HOLIDAY_TYPES } from "constants/index"; import { useTimesheetEntries } from "context/TimesheetEntries"; @@ -49,6 +50,22 @@ const TimeoffForm = ({ isDisplayEditTimeoffEntryForm = false }) => { const [holidayOptions, setHolidayOptions] = useState([]); const [showLeavesList, setShowLeavesList] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [workingHoursPerDay, setWorkingHoursPerDay] = useState(""); + + const fetchCompanyWorkingHours = async () => { + const res = await companiesApi.index(); + + const companyDetails = res.data.company_details; + const MinutesPerDay = minFromHHMM( + (companyDetails.working_hours / companyDetails.working_days).toString() + ); + const hoursPerDay = minToHHMM(MinutesPerDay); + setWorkingHoursPerDay(hoursPerDay); + }; + + useEffect(() => { + fetchCompanyWorkingHours(); + }, []); useEffect(() => { const tempLeaveTypes = [...leaveTypes]; @@ -96,6 +113,7 @@ const TimeoffForm = ({ isDisplayEditTimeoffEntryForm = false }) => { const tempHolidayOptions = holidayList?.filter(holiday => holiday?.category === leaveTypeId) || []; setHolidayOptions([...tempHolidayOptions]); + setDuration(workingHoursPerDay); handleSuggestedHolidayBasedOnDate(tempHolidayOptions); } else { setIsShowHolidayList(false); diff --git a/app/services/timeoff_entries/index_service.rb b/app/services/timeoff_entries/index_service.rb index acddec5506..1b3077d157 100644 --- a/app/services/timeoff_entries/index_service.rb +++ b/app/services/timeoff_entries/index_service.rb @@ -24,7 +24,7 @@ def process timeoff_entries:, employees: set_employees, leave_balance: process_leave_balance, - total_timeoff_entries_duration: timeoff_entries.sum(&:duration), + total_timeoff_entries_duration: timeoff_leave_entries.sum(&:duration), optional_timeoff_entries:, national_timeoff_entries: } @@ -76,7 +76,7 @@ def calculate_leave_balance summary_object = { id: leave_type.id, - name: leave_type.name, + name: "Available #{leave_type.name}", icon: leave_type.icon, color: leave_type.color, total_leave_type_days:, @@ -106,13 +106,13 @@ def calculate_national_holiday_balance(holiday) national_holidays = { id: "national", - name: "National Holidays", + name: "Available National Holidays", icon: "national", color: "national", timeoff_entries_duration: national_timeoff_entries.sum(:duration), type: "holiday", category: "national", - label: "#{national_timeoff_entries.count} out of #{total_national_holidays}" + label: "#{total_national_holidays - national_timeoff_entries.count} out of #{total_national_holidays}" } leave_balance << national_holidays @@ -138,7 +138,7 @@ def calculate_optional_holiday_balance(holiday) optional_holidays = { id: "optional", - name: "Optional Holidays", + name: "Available Optional Holidays", icon: "optional", color: "optional", net_duration: net_days * 60 * @working_hours_per_day, @@ -146,7 +146,7 @@ def calculate_optional_holiday_balance(holiday) timeoff_entries_duration: optional_timeoff_entries.sum(:duration), type: "holiday", category: "optional", - label: "#{total_optional_entries} out of #{no_of_allowed_optional_holidays} (this #{time_period_optional_holidays.to_s.gsub("per_", "")})" + label: "#{no_of_allowed_optional_holidays - total_optional_entries} out of #{no_of_allowed_optional_holidays} (this #{time_period_optional_holidays.to_s.gsub("per_", "")})" } leave_balance << optional_holidays @@ -192,5 +192,9 @@ def working_hours_per_day current_company.working_hours.to_i / current_company.working_days.to_i end + + def timeoff_leave_entries + timeoff_entries.select { |entry| entry.leave_type_id.present? } + end end end