Skip to content

Commit

Permalink
Retter opp faktureringsgrad. Fixes #460
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsve committed Apr 25, 2024
1 parent 5174d57 commit be4834a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
15 changes: 11 additions & 4 deletions backend/Api/StaffingController/ReadModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
.Select(grouping => new DetailedBooking(
new BookingDetails(grouping.First().Engagement.Name, BookingType.Booking,
grouping.First().Engagement.Customer.Name,
grouping.Key, grouping.First().Engagement.IsBillable),
grouping.Key, false, grouping.First().Engagement.IsBillable),
weekSet.Select(week =>
new WeeklyHours(
week.ToSortableInt(), grouping
Expand All @@ -116,7 +116,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
.Select(grouping => new DetailedBooking(
new BookingDetails(grouping.First().Engagement.Name, BookingType.Offer,
grouping.First().Engagement.Customer.Name,
grouping.Key, grouping.First().Engagement.IsBillable),
grouping.Key, false, grouping.First().Engagement.IsBillable),
weekSet.Select(week =>
new WeeklyHours(
week.ToSortableInt(),
Expand All @@ -132,7 +132,8 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
.Select(grouping => new DetailedBooking(
new BookingDetails(grouping.Key, BookingType.PlannedAbsence,
grouping.Key,
grouping.First().Absence.Id), //Empty projectName as PlannedAbsence does not have a project
grouping.First().Absence.Id,//Empty projectName as PlannedAbsence does not have a project
grouping.First().Absence.ExcludeFromBillRate),
weekSet.Select(week =>
new WeeklyHours(
week.ToSortableInt(),
Expand All @@ -141,6 +142,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
absence.Week.Equals(week))
.Sum(absence => absence.Hours)
)).ToList()

));


Expand Down Expand Up @@ -190,6 +192,11 @@ private static BookedHoursPerWeek GetBookedHours(Week week, IEnumerable<Detailed
var totalAbsence = DetailedBooking.GetTotalHoursPrBookingTypeAndWeek(detailedBookingsArray,
BookingType.PlannedAbsence,
week);

var totalExludableAbsence = detailedBookingsArray
.Where(s => s.BookingDetails.Type == BookingType.PlannedAbsence && s.BookingDetails.ExcludeFromBilling )
.Select(wh => wh.TotalHoursForWeek(week))
.Sum();

var totalVacations = DetailedBooking.GetTotalHoursPrBookingTypeAndWeek(detailedBookingsArray,
BookingType.Vacation,
Expand All @@ -209,7 +216,7 @@ private static BookedHoursPerWeek GetBookedHours(Week week, IEnumerable<Detailed
week.WeekNumber,
week.ToSortableInt(),
GetDatesForWeek(week),
new WeeklyBookingReadModel(totalBillable, totalOffered, totalAbsence, totalSellableTime,
new WeeklyBookingReadModel(totalBillable, totalOffered, totalAbsence, totalExludableAbsence, totalSellableTime,
totalHolidayHours, totalVacations,
totalOverbooked)
);
Expand Down
4 changes: 3 additions & 1 deletion backend/Api/StaffingController/StaffingReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public record DetailedBooking(
[property: Required] BookingDetails BookingDetails,
[property: Required] List<WeeklyHours> Hours)
{
private double TotalHoursForWeek(Week week)
public double TotalHoursForWeek(Week week)
{
return Hours.Where(weeklySum => weeklySum.Week == week.ToSortableInt()).Sum(weeklyHours => weeklyHours.Hours);
}
Expand All @@ -78,6 +78,7 @@ public record WeeklyBookingReadModel(
[property: Required] double TotalBillable,
[property: Required] double TotalOffered,
[property: Required] double TotalPlannedAbsences,
[property: Required] double TotalExludableAbsence,
[property: Required] double TotalSellableTime,
[property: Required] double TotalHolidayHours,
[property: Required] double TotalVacationHours,
Expand All @@ -88,6 +89,7 @@ public record BookingDetails(
[property: Required] BookingType Type,
[property: Required] string CustomerName,
[property: Required] int ProjectId,
[property: Required] bool ExcludeFromBilling = false,
[property: Required] bool IsBillable = false);

public record WeeklyHours([property: Required] int Week, [property: Required] double Hours);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export interface WeeklyBookingReadModel {
totalVacationHours: number;
/** @format double */
totalOverbooking: number;
totalExludableAbsence: number;
}

export interface WeeklyHours {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/staffingReports/ReportContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import IconActionButton from "@/components/Buttons/IconActionButton";
import { Filter } from "react-feather";
import ActiveFilters from "@/components/ActiveFilters";
import WeekSelection from "@/components/WeekSelection";
import { useSimpleConsultantsFilter } from "@/hooks/staffing/useConsultantsFilter";

export function ReportContent() {
const [isSideBarOpen, setIsSidebarOpen] = useState<boolean>(false);
const { filteredConsultants } = useSimpleConsultantsFilter();

return (
<>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/hooks/staffing/useConsultantsFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,19 @@ function setWeeklyInvoiceRate(
numWorkHours: number,
) {
const weeklyInvoiceRate = new Map<number, number>();


weeklyTotalBillable.forEach((totalBillable, weekNumber) => {
let totalAvailableWeekHours = 0;

filteredConsultants.forEach((consultant) => {
consultant.bookings.forEach((booking) => {
debugger
if (booking.weekNumber === weekNumber) {
let consultantAvailableWeekHours =
numWorkHours -
booking.bookingModel.totalHolidayHours -
booking.bookingModel.totalPlannedAbsences -
booking.bookingModel.totalExludableAbsence -
booking.bookingModel.totalVacationHours;

totalAvailableWeekHours += consultantAvailableWeekHours;
Expand Down

0 comments on commit be4834a

Please sign in to comment.