This commit is contained in:
Frede Hundewadt 2022-05-29 10:36:12 +02:00
parent 8cc2f1ee2e
commit c61f330e50
5 changed files with 82 additions and 14 deletions

View file

@ -17,7 +17,7 @@
<span class="version">@Name</span> <span class="version">@Version</span>@if(IsBeta){<span class="version">-beta</span>} <span class="version">@Name</span> <span class="version">@Version</span>@if(IsBeta){<span class="version">-beta</span>}
@code @code
{ {
private const string Version = "0.2.42"; private const string Version = "0.2.43";
private const string Name = "wwo"; private const string Name = "wwo";
private const bool IsBeta = true; private const bool IsBeta = true;
} }

View file

@ -85,6 +85,7 @@ public partial class CrmActivityCreate : IDisposable
DraftContext = new EditContext(_poDraft); DraftContext = new EditContext(_poDraft);
DraftContext.OnFieldChanged += HandleFieldChanged; DraftContext.OnFieldChanged += HandleFieldChanged;
DraftContext.OnValidationStateChanged += ValidationChanged;
// set up identification // set up identification
_poDraft.SalesHeadId = ""; _poDraft.SalesHeadId = "";

View file

@ -20,9 +20,9 @@
@page "/sales-report" @page "/sales-report"
<h3>Dagsrapport</h3> <h3>Dagsrapport</h3>
<EditForm EditContext="_editContext"> <EditForm EditContext="_editContext">
<hr/>
<div class="row mb-1"> <div class="row mb-1">
<label for="dayType" class="col-md-2 col-form-label">Dag</label> <label for="dayType" class="col-md-1 col-form-label">Dag</label>
<div class="col-md-4"> <div class="col-md-4">
<select id="dayType" class="form-select" @bind-Value="_reportDto.DayTypeEnum" @bind-Value:event="oninput" @onchange="CheckDayType"> <select id="dayType" class="form-select" @bind-Value="_reportDto.DayTypeEnum" @bind-Value:event="oninput" @onchange="CheckDayType">
<option value="" selected>"IKKE VALGT"</option> <option value="" selected>"IKKE VALGT"</option>
@ -36,17 +36,45 @@
</select> </select>
<ValidationMessage For="@(() => _reportDto.DayTypeEnum)"></ValidationMessage> <ValidationMessage For="@(() => _reportDto.DayTypeEnum)"></ValidationMessage>
</div> </div>
<label for="reportDate" class="col-md-2 col-form-label">Dato</label> <label for="reportDate" class="col-md-1 col-form-label">Dato</label>
<div class="col-md-4"> <div class="col-md-4">
<InputDate id="reportDate" class="form-control" @bind-Value="@(_reportDate)"/> <InputDate id="reportDate" class="form-control" @bind-Value="@(_reportDate)"/>
<button class="btn btn-info" @onclick="GetActivities">Hent aktiviteter</button> </div>
<div class="col-md-2">
<button type="button" class="btn btn-info" @onclick="GetActivities">Hent</button>
</div>
</div>
<hr/>
<h5>Km regnskab</h5>
<div class="row mb-1">
<label for="kmMorning" class="col-md-1 col-form-label">Morgen</label>
<div class="col-md-2">
<InputNumber id="kmMorning" class="form-control" @bind-Value="_reportDto.KmMorning"/>
<ValidationMessage For="@(() => _reportDto.KmMorning)"></ValidationMessage>
</div>
<label for="kmEvening" class="col-md-1 col-form-label">Aften</label>
<div class="col-md-2">
<InputNumber id="kmEvening" class="form-control" @bind-Value="_reportDto.KmEvening"/>
<ValidationMessage For="@(() => _reportDto.KmEvening)"></ValidationMessage>
</div>
<label for="distance" class="col-md-1 col-form-label">Afstand</label>
<div class="col-md-2">
<InputNumber id="distance" class="form-control" @bind-Value="_reportDto.Distance"/>
<ValidationMessage For="@(() => _reportDto.Distance)"></ValidationMessage>
</div>
<label for="kmPrivate" class="col-md-1 col-form-label">Privat</label>
<div class="col-md-2">
<InputNumber id="kmPrivate" class="form-control" @bind-Value="_reportDto.DistancePrivate"/>
<ValidationMessage For="@(() => _reportDto.DistancePrivate)"></ValidationMessage>
</div> </div>
</div> </div>
</EditForm> </EditForm>
<hr/>
<h5>Besøg</h5>
@if (Activities != null) @if (Activities != null)
{ {
<div class="row"> <div class="card-list">
@foreach (var activity in Activities) @foreach (var activity in Activities)
{ {
<div class="card"> <div class="card">

View file

@ -32,20 +32,57 @@ public partial class SalesReport
private DateTime _reportDate; private DateTime _reportDate;
private EditContext _editContext { get; set; } private EditContext _editContext { get; set; }
private SalesReportDto _reportDto = new(); private SalesReportDto _reportDto = new();
private Preferences _prefs { get; set; } = new();
private bool _formInvalid = true;
private List<ReportActivity>? Activities { get; set; } = new(); private List<ReportActivity>? Activities { get; set; } = new();
protected override void OnInitialized() protected override async Task OnInitializedAsync()
{ {
_reportDate = DateTime.Now; Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
_editContext = new EditContext(_reportDate); _editContext = new EditContext(_reportDate);
_editContext.OnFieldChanged += HandleFieldChanged;
_editContext.OnValidationStateChanged += ValidationChanged;
_prefs = await UserPrefs.GetPreferences();
_reportDate = string.IsNullOrWhiteSpace(_prefs.WorkDate)
? DateTime.Now
: DateTime.Parse(_prefs.WorkDate);
await UserPrefs.SetWorkDate(_reportDate).ConfigureAwait(true);
} }
private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{
_formInvalid = !_editContext.Validate();
StateHasChanged();
}
private void ValidationChanged(object sender, ValidationStateChangedEventArgs e)
{
_formInvalid = false;
_editContext.OnFieldChanged -= HandleFieldChanged;
_editContext = new EditContext(_reportDto);
_editContext.OnFieldChanged += HandleFieldChanged;
_editContext.OnValidationStateChanged += ValidationChanged;
}
private void CheckDayType() private void CheckDayType()
{ {
} }
private async Task GetActivities() private async Task GetActivities()
{ {
Activities = await ActivityRepo.GetActivities($"{_reportDate:yyyy-MM-dd}").ConfigureAwait(true); Activities = null;
await UserPrefs.SetWorkDate(_reportDate).ConfigureAwait(true);
Activities = await ActivityRepo
.GetActivities($"{_reportDate:yyyy-MM-dd}")
.ConfigureAwait(true);
}
public void Dispose()
{
Interceptor.DisposeEvent();
_editContext.OnFieldChanged -= HandleFieldChanged;
_editContext.OnValidationStateChanged -= ValidationChanged;
} }
} }

View file

@ -1,13 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO; namespace Wonky.Entity.DTO;
public class SalesReportDto public class SalesReportDto
{ {
public string ActivityDate { get; set; } = ""; [Required(ErrorMessage = "Dato skal angives")] public string ActivityDate { get; set; } = "";
public string DayTypeEnum { get; set; } = ""; [Required(ErrorMessage = "Dagtype skal angives")]public string DayTypeEnum { get; set; } = "";
public string Comment { get; set; } = ""; [MaxLength(128, ErrorMessage = "Du kan højst bruge 128 tegn")]public string Comment { get; set; } = "";
// //
public long KmStart { get; set; } public long KmMorning { get; set; }
public long KmFinished { get; set; } public long KmEvening { get; set; }
public int Distance { get; set; } public int Distance { get; set; }
public int DistancePrivate { get; set; } public int DistancePrivate { get; set; }
// //