This commit is contained in:
Frede Hundewadt 2022-06-13 10:52:14 +02:00
parent 11f2440c75
commit f4ba3ef83b
8 changed files with 140 additions and 82 deletions

View file

@ -16,5 +16,4 @@
*@ *@
<input id="search-input" type="text" class="form-control" placeholder="Søg ..." <input id="search-input" type="text" class="form-control" placeholder="Søg ..."
@bind-value="@SearchTerm" @bind-value:event="oninput" @bind-value="@SearchTerm" @bind-value:event="oninput" @onkeyup="OnSearchChanged"/>
@onkeyup="SearchChanged"/>

View file

@ -19,13 +19,22 @@ using Timer = System.Timers.Timer;
namespace Wonky.Client.Components namespace Wonky.Client.Components
{ {
public partial class SearchPhrase public partial class SearchComponent
{ {
private Timer _timer = new(); private Timer _timer = new();
private string SearchTerm { get; set; } = ""; private string? SearchTerm { get; set; }
[Parameter] public EventCallback<string> OnChanged { get; set; } [Parameter] public EventCallback<string?> OnChanged { get; set; }
[Parameter] public string? SavedSearch { get; set; }
private void SearchChanged() protected override void OnInitialized()
{
if (string.IsNullOrWhiteSpace(SavedSearch)) return;
SearchTerm = SavedSearch;
OnChanged.InvokeAsync(SearchTerm);
//SearchChanged();
}
private void OnSearchChanged()
{ {
_timer = new Timer(500); _timer = new Timer(500);
_timer.Elapsed += OnTimerElapsed; _timer.Elapsed += OnTimerElapsed;

View file

@ -19,7 +19,15 @@
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Adviser")] @attribute [Authorize(Roles = "Adviser")]
@using Wonky.Client.Components @using Wonky.Client.Components
<WorkDateComponent OnChanged="SetWorkDate"></WorkDateComponent> <div class="row">
<div class="col-md-4">
<h5 style="font-variant: small-caps">@_workDate.ToLongDateString()</h5>
</div>
<div class="col-md-3">
<WorkDateComponent OnChanged="SetWorkDate"></WorkDateComponent>
</div>
</div>
@if (DraftContext != null) @if (DraftContext != null)
{ {
<EditForm EditContext="DraftContext"> <EditForm EditContext="DraftContext">
@ -42,7 +50,7 @@
<select id="activityType" class="form-select" <select id="activityType" class="form-select"
@bind-Value="@_poDraft.ActivityTypeEnum" @bind-Value:event="oninput" @bind-Value="@_poDraft.ActivityTypeEnum" @bind-Value:event="oninput"
@onchange="CheckActivity"> @onchange="CheckActivity">
<option value="" selected disabled>- VALG -</option> <option value="">ORDRE TYPE</option>
<option value="onSite">Besøg</option> <option value="onSite">Besøg</option>
<option value="phone">Telefon</option> <option value="phone">Telefon</option>
</select> </select>
@ -51,13 +59,11 @@
<label for="statusType" class="col-md-2 col-form-label">Status</label> <label for="statusType" class="col-md-2 col-form-label">Status</label>
<div class="col-md-4"> <div class="col-md-4">
<select id="statusType" class="form-select" <select id="statusType" class="form-select"
@bind-Value="@_poDraft.ActivityStatusEnum" @bind-Value:event="oninput" @bind-Value="@_poDraft.ActivityStatusEnum" @bind-Value:event="oninput">
@onchange="CheckStatus">
<option value="noSale" selected>Ingen salg</option> <option value="noSale" selected>Ingen salg</option>
<option value="order">Bestilling</option> <option value="order">Bestilling</option>
@* <option value="quote">Tilbud</option> *@ <option value="quote">Tilbud</option>
</select> </select>
<ValidationMessage For="@(() => _poDraft.ActivityStatusEnum)"></ValidationMessage>
</div> </div>
</div> </div>
@ -133,7 +139,7 @@
<ItemSearchDropdown OnChanged="SetSearchCol"/> <ItemSearchDropdown OnChanged="SetSearchCol"/>
</div> </div>
<div class="col"> <div class="col">
<SearchPhrase OnChanged="SetSearchPhrase"/> <SearchComponent OnChanged="SetSearchPhrase"/>
</div> </div>
<div class="col"> <div class="col">
<ItemSortDropdown OnChanged="SetSortCol"/> <ItemSortDropdown OnChanged="SetSortCol"/>

View file

@ -67,6 +67,7 @@ public partial class CrmActivityCreate : IDisposable
private bool InvalidActivity { get; set; } = true; private bool InvalidActivity { get; set; } = true;
private bool InvalidCanvas { get; set; } = true; private bool InvalidCanvas { get; set; } = true;
private UserInfoView Ux { get; set; } = new(); private UserInfoView Ux { get; set; } = new();
private DateTime _workDate { get; set; } = DateTime.Now;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
@ -75,6 +76,11 @@ public partial class CrmActivityCreate : IDisposable
_prefs = await UserPrefs.GetPreferences(); _prefs = await UserPrefs.GetPreferences();
if (!string.IsNullOrWhiteSpace(_prefs.WorkDate))
_workDate = DateTime.Parse(_prefs.WorkDate);
_poDraft.ActivityDate = $"{_workDate:yyyy-MM-dd}" ;
_paging.SearchColumn = _prefs.ItemSearch ?? "name"; _paging.SearchColumn = _prefs.ItemSearch ?? "name";
_paging.PageSize = Convert.ToInt32(_prefs.PageSize); _paging.PageSize = Convert.ToInt32(_prefs.PageSize);
@ -87,7 +93,7 @@ public partial class CrmActivityCreate : IDisposable
_poDraft.CompanyId = NgCompany.CompanyId; _poDraft.CompanyId = NgCompany.CompanyId;
_poDraft.BcId = NgCompany.BcId; _poDraft.BcId = NgCompany.BcId;
_poDraft.SalesRepId = Ux.Id; _poDraft.SalesRepId = Ux.Id;
_poDraft.ActivityDate = _prefs.WorkDate;
_poDraft.ActivityStatusEnum = "noSale"; _poDraft.ActivityStatusEnum = "noSale";
_poDraft.VisitTypeEnum = NgCompany.Account is "" or "NY" ? "new" : "recall"; _poDraft.VisitTypeEnum = NgCompany.Account is "" or "NY" ? "new" : "recall";
@ -119,7 +125,7 @@ public partial class CrmActivityCreate : IDisposable
private void SetWorkDate(string workDate) private void SetWorkDate(string workDate)
{ {
_logger.LogInformation("WorkDateComponent.OnChanged() => {workDate}", workDate); _logger.LogInformation("WorkDateComponent.OnChanged(SetWorkDate(workDate)) => {workDate}", workDate);
_poDraft.ActivityDate = workDate; _poDraft.ActivityDate = workDate;
} }
@ -127,6 +133,7 @@ public partial class CrmActivityCreate : IDisposable
{ {
HideButtons = true; HideButtons = true;
_poDraft.ActivityDate = _prefs.WorkDate; _poDraft.ActivityDate = _prefs.WorkDate;
var activityType = _poDraft.ActivityTypeEnum switch var activityType = _poDraft.ActivityTypeEnum switch
{ {
"phone" => "T", "phone" => "T",
@ -165,11 +172,6 @@ public partial class CrmActivityCreate : IDisposable
{ {
InvalidActivityType = string.IsNullOrWhiteSpace(_poDraft.ActivityTypeEnum); InvalidActivityType = string.IsNullOrWhiteSpace(_poDraft.ActivityTypeEnum);
} }
private void CheckStatus()
{
InvalidStatusType = string.IsNullOrWhiteSpace(_poDraft.ActivityStatusEnum);
}
private async Task DeleteDraft() private async Task DeleteDraft()
{ {
await DraftStateProvider.DeleteDraftAsync(); await DraftStateProvider.DeleteDraftAsync();
@ -264,17 +266,18 @@ public partial class CrmActivityCreate : IDisposable
private void HandleFieldChanged(object sender, FieldChangedEventArgs e) private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{ {
InvalidCanvas = InvalidActivityType; // InvalidCanvas = InvalidActivityType;
InvalidActivity = InvalidActivityType // InvalidActivity = InvalidActivityType
|| _poFormInvalid // || _poFormInvalid
|| DraftStateProvider.Draft.Items.Count == 0 // || DraftStateProvider.Draft.Items.Count == 0
|| (_poDraft.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(_poDraft.EMail)); // || (_poDraft.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(_poDraft.EMail));
if (InvalidCanvas || InvalidActivity) // if (InvalidCanvas || InvalidActivity)
{ // {
_poFormInvalid = true; // _poFormInvalid = true;
return; // return;
} // }
_poFormInvalid = !DraftContext.Validate(); _poFormInvalid = !DraftContext.Validate();
StateHasChanged(); StateHasChanged();
} }

View file

@ -20,10 +20,6 @@
@page "/sales-report" @page "/sales-report"
<div>workDate: @_workDate</div>
<div>checkIn: @_reportDto.CheckIn</div>
<div>checkOut: @_reportDto.CheckOut</div>
<EditForm EditContext="_editContext"> <EditForm EditContext="_editContext">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
@ -67,11 +63,11 @@
{ {
<td> <td>
<InputDate class="form-control" <InputDate class="form-control"
@bind-Value="_leaveBegin" @bind-Value:event="oninput" @onchange="OnLeaveChanged"/> @bind-Value="_leaveBegin" @bind-Value:event="oninput" @onchange="OnLeaveChanged"/>
</td> </td>
<td> <td>
<InputDate class="form-control" <InputDate class="form-control"
@bind-Value="_leaveEnd" @bind-Value:event="oninput" @onchange="OnLeaveChanged"/> @bind-Value="_leaveEnd" @bind-Value:event="oninput" @onchange="OnLeaveChanged"/>
</td> </td>
} }
else else
@ -118,18 +114,18 @@
<tbody> <tbody>
<tr> <tr>
<td> <td>
<InputNumber class="form-control" @bind-Value="_reportDto.Figures.KmMorning"/> <InputNumber class="form-control" @bind-Value="_reportDto.Figures.KmMorning" disabled="@_noFigures" />
<ValidationMessage For="@(() => _reportDto.Figures.KmMorning)" /> <ValidationMessage For="@(() => _reportDto.Figures.KmMorning)" />
</td> </td>
<td> <td>
<InputNumber class="form-control" @bind-Value="_reportDto.Figures.KmEvening"/> <InputNumber class="form-control" @bind-Value="_reportDto.Figures.KmEvening" disabled="@_noFigures" />
<ValidationMessage For="@(() => _reportDto.Figures.KmEvening)" /> <ValidationMessage For="@(() => _reportDto.Figures.KmEvening)" />
</td> </td>
<td> <td>
<InputNumber class="form-control" @bind-Value="_reportDto.Figures.Distance" readonly=""/> <InputNumber class="form-control" @bind-Value="_reportDto.Figures.Distance" readonly="" />
</td> </td>
<td> <td>
<InputNumber class="form-control" @bind-Value="_reportDto.Figures.DistancePrivate"/> <InputNumber class="form-control" @bind-Value="_reportDto.Figures.DistancePrivate" disabled="@_noFigures"/>
<ValidationMessage For="@(() => _reportDto.Figures.DistancePrivate)" /> <ValidationMessage For="@(() => _reportDto.Figures.DistancePrivate)" />
</td> </td>
</tr> </tr>
@ -138,32 +134,77 @@
@if (_reportInit.Activities != null) @if (_reportInit.Activities != null)
{ {
<div class="card-list"> <table class="table">
<thead>
<tr>
<th scope="col">Besøg</th>
<th scope="col">Demo</th>
<th scope="col">Salg</th>
<th scope="col">Beløb</th>
</tr>
</thead>
<tbody>
@foreach (var activity in _reportInit.Activities) @foreach (var activity in _reportInit.Activities)
{ {
<div class="card"> <tr>
<div class="card-header"> <td>@activity.Company.Name - @activity.Company.ZipCity</td>
@activity.Company.Name - @activity.Company.ZipCity <td>@activity.Demo</td>
</div> <td>@activity.SalesResume</td>
<div class="card-body"> <td>@activity.OrderAmount</td>
<div class="row"> </tr>
<div class="col">
@activity.Demo
</div>
<div class="col">
@activity.SalesResume
</div>
<div class="col">
@activity.OrderAmount
</div>
</div>
</div>
</div>
} }
</div> <tr>
<td></td>
<td></td>
<td>Total</td>
<td>@_reportDto.Figures.TotalTurnover</td>
</tr>
</tbody>
</table>
} }
<table class="table">
<thead>
<tr>
<th></th>
<th colspan="2" scope="col">Demo @(_reportDto.Figures.NewDemoCount + _reportDto.Figures.RecallDemoCount)</th>
<th colspan="2" scope="col">Resultat</th>
<th colspan="4" scope="col">Resultat Måned</th>
</tr>
</thead>
<tbody>
<tr>
<td>*</td>
<th scope="col">Besøg</th>
<th scope="col">Demo</th>
<th scope="col">Salg</th>
<th scope="col">Beløb</th>
<th scope="col">Besøg</th>
<th scope="col">Demo</th>
<th scope="col">Salg</th>
<th scope="col">Beløb</th>
</tr>
<tr>
<th scope="row"></th>
<td>@_reportDto.Figures.NewVisitCount</td>
<td>@_reportDto.Figures.NewDemoCount</td>
<td>@_reportDto.Figures.NewSaleCount</td>
<td>@_reportDto.Figures.NewTurnover</td>
<td>@_reportDto.Figures.NewVisitCountMonth</td>
<td>@_reportDto.Figures.NewDemoCountMonth</td>
<td>@_reportDto.Figures.NewSaleCountMonth</td>
<td></td>
</tr>
</tbody>
</table>
} }
</div> </div>
</div> </div>
</EditForm> </EditForm>
<div>workDate: @_workDate</div>
<div>tsIn: @_timestampIn</div>
<div>tsOut: @_timestampOut</div>
<div>checkIn: @_reportDto.CheckIn</div>
<div>checkOut: @_reportDto.CheckOut</div>
<div>leaveBegin: @_leaveBegin</div>
<div>leaveEnd: @_leaveEnd</div>

View file

@ -36,6 +36,7 @@ public partial class SalesReport
private NgSalesReportInitDto _reportInit { get; set; } = new(); private NgSalesReportInitDto _reportInit { get; set; } = new();
private Preferences _prefs { get; set; } = new(); private Preferences _prefs { get; set; } = new();
private bool _formInvalid = true; private bool _formInvalid = true;
private bool _noFigures = true;
private DateTime _workDate { get; set; } = DateTime.Now; private DateTime _workDate { get; set; } = DateTime.Now;
private TimeOnly _timestampIn { get; set; } = new(12, 0); private TimeOnly _timestampIn { get; set; } = new(12, 0);
private TimeOnly _timestampOut { get; set; } = new(12, 0); private TimeOnly _timestampOut { get; set; } = new(12, 0);
@ -53,7 +54,9 @@ public partial class SalesReport
if (!string.IsNullOrWhiteSpace(_prefs.WorkDate)) if (!string.IsNullOrWhiteSpace(_prefs.WorkDate))
_workDate = DateTime.Parse(_prefs.WorkDate); _workDate = DateTime.Parse(_prefs.WorkDate);
_leaveBegin = DateOnly.FromDateTime(_workDate); _leaveBegin = DateOnly.FromDateTime(_workDate);
_reportDto.CheckIn = _workDate.AddHours(12);
_reportDto.CheckOut = _workDate.AddHours(12);
} }
private void HandleFieldChanged(object sender, FieldChangedEventArgs e) private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
@ -106,6 +109,7 @@ public partial class SalesReport
private async Task GetActivities() private async Task GetActivities()
{ {
_noFigures = false;
_prefs = await UserPrefs.GetPreferences(); _prefs = await UserPrefs.GetPreferences();
_reportInit = await ReportRepo.FetchReportInit(_prefs.WorkDate); _reportInit = await ReportRepo.FetchReportInit(_prefs.WorkDate);

View file

@ -8,6 +8,7 @@ public record Preferences
public string? CompanySort { get; set; } = "name"; public string? CompanySort { get; set; } = "name";
public string? ItemSearch { get; set; } = "name"; public string? ItemSearch { get; set; } = "name";
public string? ItemSort { get; set; } = "name"; public string? ItemSort { get; set; } = "name";
public string? CompanyFilterPhrase { get; set; } = "";
public string PageSize { get; set; } = "10"; public string PageSize { get; set; } = "10";
public string WorkDate { get; set; } = ""; public string WorkDate { get; set; } = "";
} }
@ -20,6 +21,17 @@ public class UserPreferenceService
_localStorageService = localStorageService; _localStorageService = localStorageService;
} }
public async Task SetCompanyFilterPhrase(string filterPhrase)
{
var preferences = await GetPreferences();
var newPreferences = preferences
with
{
CompanyFilterPhrase = filterPhrase
};
await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences);
}
public async Task SetWorkDate(DateTime workDate) public async Task SetWorkDate(DateTime workDate)
{ {
var preferences = await GetPreferences(); var preferences = await GetPreferences();
@ -28,9 +40,7 @@ public class UserPreferenceService
{ {
WorkDate = $"{workDate:yyyy-MM-dd}" WorkDate = $"{workDate:yyyy-MM-dd}"
}; };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task SetCompanySearch(string companySearch) public async Task SetCompanySearch(string companySearch)
@ -38,56 +48,42 @@ public class UserPreferenceService
var preferences = await GetPreferences(); var preferences = await GetPreferences();
var newPreferences = preferences var newPreferences = preferences
with { CompanySearch = companySearch }; with { CompanySearch = companySearch };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task SetCompanySort(string companySort) public async Task SetCompanySort(string companySort)
{ {
var preferences = await GetPreferences(); var preferences = await GetPreferences();
var newPreferences = preferences var newPreferences = preferences
with { CompanySort = companySort }; with { CompanySort = companySort };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task SetItemSearch(string itemSearch) public async Task SetItemSearch(string itemSearch)
{ {
var preferences = await GetPreferences(); var preferences = await GetPreferences();
var newPreferences = preferences var newPreferences = preferences
with { ItemSearch = itemSearch }; with { ItemSearch = itemSearch };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task SetItemSort(string itemSort) public async Task SetItemSort(string itemSort)
{ {
var preferences = await GetPreferences(); var preferences = await GetPreferences();
var newPreferences = preferences var newPreferences = preferences
with { ItemSort = itemSort }; with { ItemSort = itemSort };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task SetPageSize(string pageSize) public async Task SetPageSize(string pageSize)
{ {
var preferences = await GetPreferences(); var preferences = await GetPreferences();
var newPreferences = preferences var newPreferences = preferences
with { PageSize = pageSize }; with { PageSize = pageSize };
await _localStorageService.SetItemAsync("preferences", newPreferences); await _localStorageService.SetItemAsync("preferences", newPreferences);
OnChange?.Invoke(newPreferences); OnChange?.Invoke(newPreferences);
} }
public async Task<Preferences> GetPreferences() public async Task<Preferences> GetPreferences()

View file

@ -2,12 +2,12 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "None", "Default": "None",
"System": "Debug", "System": "Information",
"Microsoft": "Information" "Microsoft": "Information"
}, },
"Debug": { "Debug": {
"LogLevel": { "LogLevel": {
"Default": "Debug" "Default": "Information"
} }
}, },
"ActivityHttpRepository": { "ActivityHttpRepository": {
@ -18,7 +18,7 @@
}, },
"appInfo": { "appInfo": {
"name": "Wonky Client", "name": "Wonky Client",
"version": "0.6.1", "version": "0.6.2",
"isBeta": true, "isBeta": true,
"image": "grumpy-coder.png" "image": "grumpy-coder.png"
}, },