Skip to content

Commit

Permalink
revert Week changes (#565)
Browse files Browse the repository at this point in the history
Chesterton's Fence strikes again!
  • Loading branch information
trulshj authored Jan 7, 2025
1 parent 4848915 commit 7352ba7
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 114 deletions.
14 changes: 8 additions & 6 deletions backend/Api/StaffingController/ReadModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
grouping.First().Engagement.Agreements.Select(a => (DateTime?)a.EndDate).DefaultIfEmpty(null).Max()),
weekSet.Select(week =>
new WeeklyHours(
week, grouping
week.ToSortableInt(), grouping
.Where(staffing => staffing.Week.Equals(week))
.Sum(staffing => staffing.Hours))
).ToList()
Expand All @@ -120,7 +120,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
grouping.First().Engagement.Agreements.Select(a => (DateTime?)a.EndDate).DefaultIfEmpty(null).Max()),
weekSet.Select(week =>
new WeeklyHours(
week,
week.ToSortableInt(),
grouping
.Where(staffing =>
staffing.Week.Equals(week))
Expand All @@ -137,7 +137,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
grouping.First().Absence.ExcludeFromBillRate),
weekSet.Select(week =>
new WeeklyHours(
week,
week.ToSortableInt(),
grouping
.Where(absence =>
absence.Week.Equals(week))
Expand All @@ -155,7 +155,7 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
if (vacationsInSet.Count > 0)
{
var vacationsPrWeek = weekSet.Select(week => new WeeklyHours(
week,
week.ToSortableInt(),
vacationsInSet.Count(vacation => week.ContainsDate(vacation.Date)) *
consultant.Department.Organization.HoursPerWorkday
)).ToList();
Expand Down Expand Up @@ -206,7 +206,7 @@ private static List<WeeklyHours> GetNonEmploymentHoursNotStartedOrQuit(DateOnly
: GetNonEmployedHoursForWeekWhenStarting(date, week, isTargetWeek, consultant);

return new WeeklyHours(
week, Math.Min(hoursOutsideEmployment, maxWorkHoursForWeek)
week.ToSortableInt(), Math.Min(hoursOutsideEmployment, maxWorkHoursForWeek)
);
})
.ToList();
Expand Down Expand Up @@ -297,7 +297,9 @@ private static BookedHoursPerWeek GetBookedHours(Week week, IEnumerable<Detailed
Math.Max(bookedTime - hoursPrWorkDay * 5, 0);

return new BookedHoursPerWeek(
week,
week.Year,
week.WeekNumber,
week.ToSortableInt(),
GetDatesForWeek(week),
new WeeklyBookingReadModel(totalBillable, totalOffered, totalAbsence, totalExcludableAbsence,
totalSellableTime,
Expand Down
8 changes: 5 additions & 3 deletions backend/Api/StaffingController/StaffingReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public CompetenceReadModel(Competence competence)
}

public record BookedHoursPerWeek(
Week Week,
int Year,
int WeekNumber,
int SortableWeek,
string DateString,
WeeklyBookingReadModel BookingModel);

Expand All @@ -64,7 +66,7 @@ public record DetailedBooking(
{
public double TotalHoursForWeek(Week week)
{
return Hours.Where(weeklySum => weeklySum.Week == week).Sum(weeklyHours => weeklyHours.Hours);
return Hours.Where(weeklySum => weeklySum.Week == week.ToSortableInt()).Sum(weeklyHours => weeklyHours.Hours);
}

internal static double GetTotalHoursPrBookingTypeAndWeek(IEnumerable<DetailedBooking> list, BookingType type,
Expand Down Expand Up @@ -98,7 +100,7 @@ public record BookingDetails(
bool IsBillable = false,
DateTime? EndDateAgreement = null);

public record WeeklyHours(Week Week, double Hours);
public record WeeklyHours(int Week, double Hours);

public enum BookingType
{
Expand Down
3 changes: 3 additions & 0 deletions backend/Core/Weeks/Week.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ private bool DateIsInWeek(DateOnly day)

public static bool operator ==(Week left, Week right)
{
if (ReferenceEquals(left, right)) return true;
if (ReferenceEquals(left, null)) return false;
if (ReferenceEquals(right, null)) return false;
return left.Year == right.Year && left.WeekNumber == right.WeekNumber;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/mockdata/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MockWeeklyBookingReadModel: WeeklyBookingReadModel = {
totalBillable: 0,
totalOffered: 0,
totalVacationHours: 0,
totalExludableAbsence: 0,
totalExcludableAbsence: 0,
totalNotStartedOrQuit: 0,
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export interface WeeklyBookingReadModel {
/** @format double */
totalOverbooking: number;
/** @format double */
totalExludableAbsence: number;
totalExcludableAbsence: number;
/** @format double */
totalNotStartedOrQuit: number;
}
Expand Down
203 changes: 101 additions & 102 deletions frontend/src/components/FilteredConsultantsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,113 +18,112 @@ export default function StaffingTable() {
} = useConsultantsFilter();

const { weekSpan } = useContext(FilteredContext).activeFilters;
console.log(filteredConsultants);

return (
<>
<table
className={`w-full ${
weekSpan > 23
? "min-w-[1400px]"
: weekSpan > 11
? "min-w-[850px]"
: "min-w-[700px]"
} table-fixed`}
>
<colgroup>
<col span={1} className="w-14" />
<col span={1} className="w-[190px]" />
{filteredConsultants
.at(0)
?.bookings.map((_, index) => <col key={index} span={1} />)}
</colgroup>
<thead>
<tr className="sticky -top-6 bg-white z-10">
<th colSpan={2} className="pt-3 pl-2 -left-2 relative bg-white">
<div className="flex flex-row gap-3 pb-4 items-center">
<p className="normal-medium ">Konsulenter</p>
<p className="text-primary small-medium rounded-full bg-secondary/30 px-2 py-1">
{filteredConsultants?.length}
</p>
</div>
</th>
{filteredConsultants.at(0)?.bookings?.map((booking) => (
<th key={booking.weekNumber} className=" px-2 py-1 pt-3 ">
<div className="flex flex-col gap-1">
{isCurrentWeek(booking.weekNumber, booking.year) ? (
<div className="flex flex-row gap-2 items-center justify-end">
{booking.bookingModel.totalHolidayHours > 0 && (
<InfoPill
text={booking.bookingModel.totalHolidayHours.toLocaleString(
"nb-No",
{
maximumFractionDigits: 1,
minimumFractionDigits: 0,
},
)}
icon={<Calendar size="12" />}
colors={"bg-holiday text-holiday_darker w-fit"}
variant={weekSpan < 24 ? "wide" : "medium"}
/>
)}
<div className="h-2 w-2 rounded-full bg-primary" />

<p className="normal-medium text-right">
{booking.weekNumber}
</p>
</div>
) : (
<div
className={`flex justify-end ${
weekSpan >= 26
? "min-h-[30px] flex-col mb-2 gap-[1px] items-end"
: "flex-row gap-2"
}`}
>
{booking.bookingModel.totalHolidayHours > 0 && (
<InfoPill
text={booking.bookingModel.totalHolidayHours.toLocaleString(
"nb-No",
{
maximumFractionDigits: 1,
minimumFractionDigits: 0,
},
)}
icon={<Calendar size="12" />}
colors={"bg-holiday text-holiday_darker w-fit"}
variant={weekSpan < 24 ? "wide" : "medium"}
/>
)}
<p className="normal text-right">{booking.weekNumber}</p>
</div>
)}
<table
className={`w-full ${
weekSpan > 23
? "min-w-[1400px]"
: weekSpan > 11
? "min-w-[850px]"
: "min-w-[700px]"
} table-fixed`}
>
<colgroup>
<col span={1} className="w-14" />
<col span={1} className="w-[190px]" />
{filteredConsultants
.at(0)
?.bookings.map((_, index) => <col key={index} span={1} />)}
</colgroup>
<thead>
<tr className="sticky -top-6 bg-white z-10">
<th colSpan={2} className="pt-3 pl-2 -left-2 relative bg-white">
<div className="flex flex-row gap-3 pb-4 items-center">
<p className="normal-medium ">Konsulenter</p>
<p className="text-primary small-medium rounded-full bg-secondary/30 px-2 py-1">
{filteredConsultants?.length}
</p>
</div>
</th>
{filteredConsultants.at(0)?.bookings?.map((booking) => (
<th key={booking.weekNumber} className=" px-2 py-1 pt-3 ">
<div className="flex flex-col gap-1">
{isCurrentWeek(booking.weekNumber, booking.year) ? (
<div className="flex flex-row gap-2 items-center justify-end">
{booking.bookingModel.totalHolidayHours > 0 && (
<InfoPill
text={booking.bookingModel.totalHolidayHours.toLocaleString(
"nb-No",
{
maximumFractionDigits: 1,
minimumFractionDigits: 0,
},
)}
icon={<Calendar size="12" />}
colors={"bg-holiday text-holiday_darker w-fit"}
variant={weekSpan < 24 ? "wide" : "medium"}
/>
)}
<div className="h-2 w-2 rounded-full bg-primary" />

<p
className={`xsmall text-black/75 text-right ${
weekSpan >= 26 && "hidden"
<p className="normal-medium text-right">
{booking.weekNumber}
</p>
</div>
) : (
<div
className={`flex justify-end ${
weekSpan >= 26
? "min-h-[30px] flex-col mb-2 gap-[1px] items-end"
: "flex-row gap-2"
}`}
>
{booking.dateString}
</p>
</div>
</th>
))}
</tr>
</thead>
<tbody>
{filteredConsultants.map((consultant) => (
<ConsultantRows
key={consultant.id}
consultant={consultant}
numWorkHours={numWorkHours}
/>
{booking.bookingModel.totalHolidayHours > 0 && (
<InfoPill
text={booking.bookingModel.totalHolidayHours.toLocaleString(
"nb-No",
{
maximumFractionDigits: 1,
minimumFractionDigits: 0,
},
)}
icon={<Calendar size="12" />}
colors={"bg-holiday text-holiday_darker w-fit"}
variant={weekSpan < 24 ? "wide" : "medium"}
/>
)}
<p className="normal text-right">{booking.weekNumber}</p>
</div>
)}

<p
className={`xsmall text-black/75 text-right ${
weekSpan >= 26 && "hidden"
}`}
>
{booking.dateString}
</p>
</div>
</th>
))}
</tbody>
<StaffingSums
weeklyTotalBillable={weeklyTotalBillable}
weeklyTotalBillableAndOffered={weeklyTotalBillableAndOffered}
weeklyInvoiceRates={weeklyInvoiceRates}
/>
</table>
</>
</tr>
</thead>
<tbody>
{filteredConsultants.map((consultant) => (
<ConsultantRows
key={consultant.id}
consultant={consultant}
numWorkHours={numWorkHours}
/>
))}
</tbody>
<StaffingSums
weeklyTotalBillable={weeklyTotalBillable}
weeklyTotalBillableAndOffered={weeklyTotalBillableAndOffered}
weeklyInvoiceRates={weeklyInvoiceRates}
/>
</table>
);
}
2 changes: 1 addition & 1 deletion frontend/src/hooks/staffing/useConsultantsFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function setWeeklyInvoiceRate(
let consultantAvailableWeekHours =
numWorkHours -
booking.bookingModel.totalHolidayHours -
booking.bookingModel.totalExludableAbsence -
booking.bookingModel.totalExcludableAbsence -
booking.bookingModel.totalNotStartedOrQuit -
booking.bookingModel.totalVacationHours;

Expand Down

0 comments on commit 7352ba7

Please sign in to comment.