320 lines
13 KiB
Text
320 lines
13 KiB
Text
@page "/summary"
|
|
@page "/summary/{YearMonth}"
|
|
@attribute [Authorize]
|
|
@rendermode InteractiveServer
|
|
|
|
@using System.Globalization
|
|
@inject global::WorkTracker.Services.WorkDays.IWorkDayService WorkDayService
|
|
|
|
<PageTitle>Monthly Summary</PageTitle>
|
|
|
|
<h1>Monthly Summary</h1>
|
|
|
|
<div class="d-flex align-items-center gap-2 mb-3">
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="PreviousMonth">« Prev</button>
|
|
<h2 class="h5 mb-0">@currentMonth.ToString("MMMM yyyy")</h2>
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="NextMonth">Next »</button>
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input id="include-preview" type="checkbox" class="form-check-input" checked="@includePreview" @onchange="OnIncludePreviewChanged" />
|
|
<label class="form-check-label" for="include-preview">Include preview work units in totals</label>
|
|
</div>
|
|
|
|
<div class="btn-group mb-3" role="group" aria-label="Summary view selector">
|
|
<button type="button" class="btn @(viewMode == SummaryViewMode.Cards ? "btn-primary" : "btn-outline-primary")" @onclick="() => SetViewMode(SummaryViewMode.Cards)">Cards</button>
|
|
<button type="button" class="btn @(viewMode == SummaryViewMode.Timesheet ? "btn-primary" : "btn-outline-primary")" @onclick="() => SetViewMode(SummaryViewMode.Timesheet)">Timesheet</button>
|
|
</div>
|
|
|
|
@if (loading)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else if (viewMode == SummaryViewMode.Cards && summary is not null)
|
|
{
|
|
<div class="row g-3">
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Working Days</div>
|
|
<div class="fs-3 fw-bold">@summary.TotalWorkingDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Counted Work Units</div>
|
|
<div class="fs-3 fw-bold">@summary.CountedWorkUnits</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Total Worked Hours</div>
|
|
<div class="fs-3 fw-bold">@FormatHours(summary.TotalWorkedHours)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Preview Hours</div>
|
|
<div class="fs-3 fw-bold">@FormatHours(summary.TotalPreviewWorkedHours)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Preview Units</div>
|
|
<div class="fs-3 fw-bold">@summary.PreviewWorkUnits</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Hours Off</div>
|
|
<div class="fs-3 fw-bold">@FormatHours(summary.TotalHoursOff)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100 border-success">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Gross Income</div>
|
|
<div class="fs-3 fw-bold text-success">€@summary.TotalGrossIncome.ToString("N2")</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100 border-primary">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Net Income</div>
|
|
<div class="fs-3 fw-bold text-primary">€@summary.TotalNetIncome.ToString("N2")</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Office Days</div>
|
|
<div class="fs-3 fw-bold">@summary.OfficeDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Home Days</div>
|
|
<div class="fs-3 fw-bold">@summary.HomeDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Holidays</div>
|
|
<div class="fs-3 fw-bold">@summary.HolidayDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Closure Days</div>
|
|
<div class="fs-3 fw-bold">@summary.ClosureDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Days Off</div>
|
|
<div class="fs-3 fw-bold">@summary.DaysOff</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-4 col-xl-3">
|
|
<div class="card text-center h-100">
|
|
<div class="card-body">
|
|
<div class="text-muted small">Sick Days</div>
|
|
<div class="fs-3 fw-bold">@summary.SickDays</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
else if (viewMode == SummaryViewMode.Timesheet && timesheet is not null)
|
|
{
|
|
<div class="timesheet-summary-card card border-0 shadow-sm">
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-sm align-middle mb-0 timesheet-summary-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="timesheet-summary-sticky-column">Categoria</th>
|
|
@for (var i = 0; i < timesheet.Days.Count; i++)
|
|
{
|
|
var day = timesheet.Days[i];
|
|
<th class="text-center timesheet-summary-day-header @GetDayColumnClass(day) @GetDayPopupClass(i, timesheet.Days.Count)">
|
|
<div>@day.Date.Day</div>
|
|
<div class="small text-muted">@GetDayHeader(day.Date)</div>
|
|
<div class="timesheet-summary-day-popup">
|
|
<div class="fw-semibold mb-2">@day.Date.ToString("dddd d MMMM", ItalianCulture)</div>
|
|
@if (day.WorkUnitSummaries.Count == 0 && day.EventSummaries.Count == 0)
|
|
{
|
|
<div class="small text-muted">Nessun elemento registrato.</div>
|
|
}
|
|
else
|
|
{
|
|
@foreach (var workUnit in day.WorkUnitSummaries)
|
|
{
|
|
<div class="timesheet-summary-day-popup-item">@workUnit</div>
|
|
}
|
|
|
|
@foreach (var calendarEvent in day.EventSummaries)
|
|
{
|
|
<div class="timesheet-summary-day-popup-item timesheet-summary-day-popup-item-event">@calendarEvent</div>
|
|
}
|
|
}
|
|
</div>
|
|
</th>
|
|
}
|
|
<th class="text-center timesheet-summary-total-column">Totale</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var row in timesheet.Rows)
|
|
{
|
|
<tr>
|
|
<th scope="row" class="timesheet-summary-sticky-column">@row.Label</th>
|
|
@for (var i = 0; i < row.DailyValues.Count; i++)
|
|
{
|
|
<td class="text-center @GetDayColumnClass(timesheet.Days[i])">@FormatTimesheetValue(row.DailyValues[i], row.ValueFormat)</td>
|
|
}
|
|
<td class="text-center fw-semibold timesheet-summary-total-column">@FormatTimesheetValue(row.Total, row.ValueFormat)</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string? YearMonth { get; set; }
|
|
|
|
private static readonly CultureInfo ItalianCulture = CultureInfo.GetCultureInfo("it-IT");
|
|
|
|
private DateOnly currentMonth;
|
|
private bool loading = true;
|
|
private bool includePreview;
|
|
private global::WorkTracker.Domain.MonthlySummaryModel? summary;
|
|
private global::WorkTracker.Domain.MonthlyTimesheetModel? timesheet;
|
|
private SummaryViewMode viewMode = SummaryViewMode.Timesheet;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (!string.IsNullOrEmpty(YearMonth) && DateTime.TryParseExact(YearMonth, "yyyy-MM", null, System.Globalization.DateTimeStyles.None, out var parsed))
|
|
{
|
|
currentMonth = new DateOnly(parsed.Year, parsed.Month, 1);
|
|
}
|
|
else
|
|
{
|
|
currentMonth = new DateOnly(DateTime.Today.Year, DateTime.Today.Month, 1);
|
|
}
|
|
|
|
await LoadSummary();
|
|
}
|
|
|
|
private async Task OnIncludePreviewChanged(ChangeEventArgs e)
|
|
{
|
|
includePreview = e.Value is bool value && value;
|
|
await LoadSummary();
|
|
}
|
|
|
|
private async Task LoadSummary()
|
|
{
|
|
loading = true;
|
|
summary = await WorkDayService.GetMonthlySummaryAsync(currentMonth.Year, currentMonth.Month, includePreview);
|
|
timesheet = await WorkDayService.GetMonthlyTimesheetAsync(currentMonth.Year, currentMonth.Month, includePreview);
|
|
loading = false;
|
|
}
|
|
|
|
private async Task PreviousMonth()
|
|
{
|
|
currentMonth = currentMonth.AddMonths(-1);
|
|
await LoadSummary();
|
|
}
|
|
|
|
private async Task NextMonth()
|
|
{
|
|
currentMonth = currentMonth.AddMonths(1);
|
|
await LoadSummary();
|
|
}
|
|
|
|
private void SetViewMode(SummaryViewMode mode)
|
|
{
|
|
viewMode = mode;
|
|
}
|
|
|
|
private static string GetDayHeader(DateOnly date)
|
|
{
|
|
return ItalianCulture.TextInfo.ToTitleCase(date.ToString("ddd", ItalianCulture));
|
|
}
|
|
|
|
private static string GetDayColumnClass(global::WorkTracker.Domain.MonthlyTimesheetDayModel day)
|
|
{
|
|
if (day.IsWeekend || day.IsHoliday)
|
|
{
|
|
return "timesheet-summary-day-danger";
|
|
}
|
|
|
|
return day.IsClosure ? "timesheet-summary-day-closure" : string.Empty;
|
|
}
|
|
|
|
private static string GetDayPopupClass(int index, int totalDays)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
return "timesheet-summary-day-popup-left";
|
|
}
|
|
|
|
return index >= totalDays - 2 ? "timesheet-summary-day-popup-right" : string.Empty;
|
|
}
|
|
|
|
private static string FormatTimesheetValue(decimal? value, global::WorkTracker.Domain.MonthlyTimesheetValueFormat valueFormat)
|
|
{
|
|
if (!value.HasValue || value.Value <= 0m)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
return valueFormat == global::WorkTracker.Domain.MonthlyTimesheetValueFormat.Days
|
|
? value.Value.ToString("0.##", ItalianCulture)
|
|
: FormatDecimalHours(value.Value);
|
|
}
|
|
|
|
private static string FormatDecimalHours(decimal value)
|
|
{
|
|
return value.ToString("0.##", ItalianCulture);
|
|
}
|
|
|
|
private static string FormatHours(decimal value)
|
|
{
|
|
var totalMinutes = (int)Math.Round(value * 60m, MidpointRounding.AwayFromZero);
|
|
var hours = totalMinutes / 60;
|
|
var minutes = totalMinutes % 60;
|
|
return $"{hours:00}:{minutes:00}";
|
|
}
|
|
|
|
private enum SummaryViewMode
|
|
{
|
|
Cards,
|
|
Timesheet
|
|
}
|
|
}
|