8000 Small changes: leaves and holidays module by Shruti-Apte · Pull Request #1938 · saeloun/miru-web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Small changes: leaves and holidays module #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const TableRow = ({ timeoffEntry }) => {
<span>{leaveName}</span>
</td>
<td className="flex w-1/3 flex-col whitespace-nowrap pb-2.5 text-right text-base lg:mt-0 lg:table-cell lg:w-3/12 lg:items-center lg:pl-8">
{minToHHMM(duration)}
{leaveType ? minToHHMM(duration) : "-:-"}
</td>
</tr>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const DesktopTimeoffForm = ({
setEditTimeoffEntryId,
} = useTimesheetEntries();

const holidayEntry = isHolidayEntry();

return (
<div className="mt-10 hidden min-h-24 justify-between rounded-lg p-4 shadow-2xl lg:flex">
<div className="w-1/2">
Expand Down Expand Up @@ -124,9 +126,12 @@ const DesktopTimeoffForm = ({
</div>
</div>
<TimeInput
className="h-8 w-20 rounded-sm bg-miru-gray-100 p-1 text-sm placeholder:text-miru-gray-1000"
disabled={holidayEntry}
initTime={duration}
name="timeInput"
className={`h-8 w-20 rounded-sm bg-miru-gray-100 p-1 text-sm placeholder:text-miru-gray-1000 ${
holidayEntry && "text-miru-dark-purple-200"
}`}
>
/>
</div>
Expand Down
18 changes: 18 additions & 0 deletions app/javascript/src/components/TimeoffEntries/TimeoffForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -49,6 +50,22 @@ const TimeoffForm = ({ isDisplayEditTimeoffEntryForm = false }) => {
const [holidayOptions, setHolidayOptions] = useState([]);
const [showLeavesList, setShowLeavesList] = useState<boolean>(false);
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false);
const [workingHoursPerDay, setWorkingHoursPerDay] = useState<string>("");

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];
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions app/services/timeoff_entries/index_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
Expand Down Expand Up @@ -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:,
Expand Down Expand Up @@ -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
Expand All @@ -138,15 +138,15 @@ 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,
net_days:,
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
Expand Down Expand Up @@ -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
Loading
0