fixed weird issue with changing report date - minor cosmetics

This commit is contained in:
Frede Hundewadt 2022-12-22 17:58:00 +01:00
parent e85f1c909e
commit 72e5fd5b42
9 changed files with 111 additions and 120 deletions

View file

@ -70,11 +70,11 @@ public partial class WorkDateComponent : IDisposable
/// <param name="e"></param>
private async Task OnDateChanged(ChangeEventArgs e)
{
var x = DateTime.TryParse(e.Value.ToString(), out var val);
var x = DateTime.TryParse(e.Value.ToString(), out var setDate);
if (x)
{
await Prefs.SetWorkDate(val);
await OnChangedCallback.InvokeAsync($"{val:yyyy-MM-dd}");
await Prefs.SetWorkDate(setDate);
await OnChangedCallback.InvokeAsync($"{setDate:yyyy-MM-dd}");
}
}

View file

@ -21,23 +21,22 @@
@page "/sales-reports/view/{ReportDate}"
@attribute [Authorize(Roles = "Advisor,Admin,Supervisor")]
<div class="report-main">
<div class="row bg-dark text-white rounded-2 mb-2 py-2 align-items-center d-print-none">
<div class="col-sm-6">
<WorkDateComponent OnChangedCallback="GetReport"/>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-warning" @onclick="() => Print(PTarget.Report)"><i class="bi-printer"></i> Rapport</button>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-success" @onclick="() => Print(PTarget.Order)"><i class="bi-printer"></i> Ordrer</button>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-primary" type="button" onclick="window.print();"><i class="bi-printer"></i> Print</button>
</div>
<div class="row bg-dark text-white rounded-2 mb-2 py-2 align-items-center d-print-none">
<div class="col-sm-6">
<WorkDateComponent OnChangedCallback="FetchReport"/>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-warning" @onclick="() => Print(PTarget.Report)"><i class="bi-printer"></i> Rapport</button>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-success" @onclick="() => Print(PTarget.Order)"><i class="bi-printer"></i> Ordrer</button>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-primary" type="button" onclick="window.print();"><i class="bi-printer"></i> Print</button>
</div>
</div>
<div class="report-main">
@if (!string.IsNullOrWhiteSpace(Report.ReportData.DayTypeEnum))
{
<PageTitle>@Report.ReportData.Name</PageTitle>
@ -63,16 +62,10 @@
}
</div>
@if (Items.Any())
@if (Activities.Any())
{
@foreach (var item in Items)
@foreach (var item in Activities)
{
<ReportItemComponent ReportItem="@item"></ReportItemComponent>
}
}
@if (Working)
{
<WorkingThreeDots/>
}

View file

@ -15,31 +15,31 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.Models;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
public partial class CrmReportViewPage
public partial class CrmReportViewPage : IDisposable
{
[Parameter] public string ReportDate { get; set; }
[Inject] public ICrmReportHttpRepository ReportRepo { get; set; }
[Inject] public NavigationManager Navigator { get; set; }
[Inject] public ILocalStorageService Storage { get; set; }
[Inject] public HttpInterceptorService Interceptor { get; set; }
private ReportView Report { get; set; } = new();
private List<ReportItemView> Items { get; set; } = new ();
private List<ReportItemView> Activities { get; set; } = new ();
private bool Working { get; set; } = true;
private UserInfoView UserInfo { get; set; } = new();
private string ReturnUrl { get; set; } = "";
protected override async Task OnInitializedAsync()
protected override async Task OnParametersSetAsync()
{
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
UserInfo = await Storage.GetItemAsync<UserInfoView>("_xu");
if (!string.IsNullOrWhiteSpace(ReportDate))
{
await GetReport(ReportDate);
}
Working = false;
await FetchReport(ReportDate);
}
private void Print(PTarget target)
@ -62,18 +62,22 @@ public partial class CrmReportViewPage
}
}
private async Task GetReport(string workDate)
private async Task FetchReport(string workDate)
{
Working = true;
Report = new ReportView();
Items = new List<ReportItemView>();
if(workDate != ReportDate)
Navigator.NavigateTo($"/sales-reports/view/{workDate}");
Report = await ReportRepo.GetReport(workDate);
Items = Report.ReportItems.Where(x => x.Lines.Any()).ToList();
Working = true;
Report = new ReportView();
Activities = new List<ReportItemView>();
Report = await ReportRepo.GetReport(workDate);
Activities = Report.ReportItems.Where(x => x.Lines.Any()).ToList();
await Storage.SetItemAsync($"{UserInfo.Id}-{Report.ReportData.ReportDate}", Report);
Working = false;
}
public void Dispose()
{
Interceptor.DisposeEvent();
}
}

View file

@ -46,6 +46,7 @@ public partial class OfficeReportListPage : IDisposable
var reports = await ReportRepo.GetReports(UserId);
if (reports.Any())
ActivityReports = reports.OrderByDescending(x => x.ReportDate).ToList();
Working = false;
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>

View file

@ -21,9 +21,9 @@
@page "/office/users/advisors/{CountryCode}/{UserId}/reports/{ReportDate}"
@attribute [Authorize(Roles = "Admin")]
<div class="row mb-3 g-1 d-print-none">
<div class="row pt-2 pb-2 mb-3 rounded-2 d-print-none bg-dark text-white">
<div class="col-sm-6">
<WorkDateComponent OnChangedCallback="FetchReport" />
<WorkDateComponent OnChangedCallback="FetchUserReport"/>
</div>
<div class="col-sm-2 d-grid">
<button class="btn btn-warning" @onclick="() => Print(PTarget.Report)"><i class="bi-printer"></i> Rapport</button>
@ -36,49 +36,38 @@
</div>
</div>
@if (ThisTarget is PTarget.Report or PTarget.All)
{
<div class="report-main d-print-grid">
@if (!string.IsNullOrWhiteSpace(Report.ReportData.DayTypeEnum))
{
<PageTitle>@Report.ReportData.Name</PageTitle>
<div class="row">
<div class="col text-center align-content-center">
<h3>@Report.ReportData.Name</h3>
</div>
</div>
<div class="row">
<div class="w-75">
<ReportSummaryComponent ReportData="Report.ReportData" />
</div>
<div class="w-25">
<ReportDistanceLedgerComponent ReportData="Report.ReportData" />
</div>
</div>
<OfficeActivityTableComponent ActivityList="Report.ReportItems" />
<ReportActivityLedgerComponent ReportData="Report.ReportData" />
}
else
{
<div class="row">
<div class="col">Ingen data</div>
</div>
}
</div>
}
@if (ThisTarget is PTarget.Order or PTarget.All)
{
if (Activities.Any())
<div class="report-main d-print-grid">
@if (!string.IsNullOrWhiteSpace(Report.ReportData.DayTypeEnum))
{
foreach (var item in Activities.Where(item => item.StatusTypeEnum.ToLower() == "order" && item.ProcessStatusEnum.ToLower() == "none"))
{
<ReportItemComponent ReportItem="@item"></ReportItemComponent>
}
<PageTitle>@Report.ReportData.Name</PageTitle>
<div class="row">
<div class="col text-center align-content-center">
<h3>@Report.ReportData.Name</h3>
</div>
</div>
<div class="row">
<div class="w-75">
<ReportSummaryComponent ReportData="Report.ReportData"/>
</div>
<div class="w-25">
<ReportDistanceLedgerComponent ReportData="Report.ReportData"/>
</div>
</div>
<OfficeActivityTableComponent ActivityList="Report.ReportItems"/>
<ReportActivityLedgerComponent ReportData="Report.ReportData"/>
}
else
{
<div class="row">
<div class="col">Ingen rapport data</div>
</div>
}
</div>
@if (Activities.Any())
{
foreach (var item in Activities.Where(item => item.StatusTypeEnum.ToLower() == "order" && item.ProcessStatusEnum.ToLower() == "none"))
{
<ReportItemComponent ReportItem="@item"></ReportItemComponent>
}
}
@if (Working)
{
<WorkingThreeDots/>
}

View file

@ -76,58 +76,56 @@ public partial class OfficeReportViewPage : IDisposable
{
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
await Task.Delay(100);
await FetchReport(ReportDate);
Working = false;
await FetchUserReport(ReportDate);
}
private void Print(PTarget target)
{
if (target == PTarget.Order)
var returnUrl = new Uri(Navigator.Uri).AbsolutePath;
switch (target)
{
Navigator.NavigateTo($"/print/orders/{CountryCode}/{UserId}/{ReportDate}?returnUrl={Navigator.Uri}");
return;
case PTarget.Order:
Navigator.NavigateTo($"/print/orders/{CountryCode}/{UserId}/{ReportDate}?returnUrl={returnUrl}");
break;
case PTarget.Report:
Navigator.NavigateTo($"/print/report/{CountryCode}/{UserId}/{ReportDate}?returnUrl={returnUrl}");
break;
case PTarget.None:
break;
case PTarget.All:
break;
default:
throw new ArgumentOutOfRangeException(nameof(target), target, null);
}
Navigator.NavigateTo($"/print/report/{CountryCode}/{UserId}/{ReportDate}?returnUrl={Navigator.Uri}");
}
/// <summary>
/// Work date component event handler
/// </summary>
/// <param name="workDate"></param>
private async Task FetchReport(string workDate)
private async Task FetchUserReport(string workDate)
{
var returnUrl = new Uri(Navigator.Uri).AbsolutePath;
if (workDate != ReportDate)
{
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{workDate}?returnUrl={returnUrl}");
Navigator.NavigateTo($"/office/users/advisors/{CountryCode}/{UserId}/reports/{workDate}");
Working = false;
return;
}
Working = true;
Report = new ReportView();
Activities = new List<ReportItemView>();
Report = await FetchUserReport(UserId, workDate);
// fetch
Report = await ReportRepo.GetReport(UserId, workDate);
// assign activities
Activities = Report.ReportItems.Where(x => x.Lines.Any()).ToList();
// write to storage
await Storage.SetItemAsync($"{UserId}-{ReportDate}", Report);
// hide indicator
Working = false;
}
/// <summary>
/// Get report for user with entity Id for work date
/// </summary>
/// <param name="userId"></param>
/// <param name="workDate"></param>
/// <returns></returns>
private async Task<ReportView> FetchUserReport(string userId, string workDate)
{
Working = true;
var x = Report = await ReportRepo.GetReport(userId, workDate);
Working = false;
return x;
}
public void Dispose()
{
Interceptor.DisposeEvent();

View file

@ -21,8 +21,11 @@
@attribute [Authorize(Roles = "Admin,Advisor")]
<div class="row mb-3 d-print-none">
<div class="col-sm-12 d-grid">
<button class="btn btn-primary" type="button" @onclick="Print">Print</button>
<div class="col-sm-6 d-grid">
<a class="btn btn-info" href="@ReturnUrl"><i class="bi-back"></i> Tilbage</a>
</div>
<div class="col-sm-6 d-grid">
<button class="btn btn-primary" type="button" @onclick="Print"><i class="bi-printer"></i> Print</button>
</div>
</div>

View file

@ -21,8 +21,11 @@
@attribute [Authorize(Roles = "Admin,Advisor")]
<div class="row mb-3 d-print-none">
<div class="col-sm-12 d-grid">
<button class="btn btn-primary" type="button" @onclick="Print">Print</button>
<div class="col-sm-6 d-grid">
<a class="btn btn-info" href="@ReturnUrl"><i class="bi-back"></i> Tilbage</a>
</div>
<div class="col-sm-6 d-grid">
<button class="btn btn-primary" type="button" @onclick="Print"><i class="bi-printer"></i> Print</button>
</div>
</div>

View file

@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Client",
"version": "0.87.3",
"version": "0.87.4",
"rc": true,
"sandBox": false,
"image": "grumpy-coder.png"
@ -34,7 +34,7 @@
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
},