bug-fix: report distance calculation

This commit is contained in:
Frede Hundewadt 2023-02-01 09:49:03 +01:00
parent 41c80c223c
commit deee0797e9
7 changed files with 55 additions and 29 deletions

View file

@ -64,13 +64,13 @@
</td>
@if (Report.DayTypeEnum.ToLower().Contains("leave"))
{
Report.Figures.KmMorning = 0;
<td>
<InputDate class="form-control" @bind-Value="BeginLeave"/>
</td>
<td>
<InputDate class="form-control" @bind-Value="EndLeave"/>
</td>
Report.Figures.KmMorning = 0;
}
else
{
@ -135,7 +135,8 @@
<tr class="bg-black opacity-75 text-white">
<th scope="col">Km aften</th>
<th scope="col">Km morgen</th>
<th scope="col">Km privat</th>
<th scope="col">Km dag</th>
<th scope="col">Km måned</th>
</tr>
</thead>
<tbody>
@ -148,10 +149,34 @@
<InputNumber class="form-control" @bind-Value="@Report.Figures.KmMorning"
disabled="@(NoFigures)"/>
</td>
<td>
<InputNumber class="form-control" @bind-Value="@Report.Figures.Distance"
disabled />
</td>
<td>
<InputNumber class="form-control" @bind-Value="@Report.Figures.DistanceMonth"
disabled />
</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr class="bg-black opacity-75 text-white">
<th scope="col">Km privat</th>
<th scope="col">Km privat måned</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<InputNumber class="form-control" @bind-Value="@Report.Figures.DistancePrivate"
disabled="@(NoFigures)"/>
</td>
<td>
<InputNumber class="form-control" @bind-Value="@Report.Figures.DistancePrivateMonth"
disabled />
</td>
</tr>
</tbody>
</table>

View file

@ -52,7 +52,9 @@ public partial class AdvisorReportCreatePage : IDisposable
private ConfirmationModal ConfirmReportModal { get; set; }
private string Prompt { get; set; } = "";
private string WorkDate { get; set; } = "";
private int currKmMonth { get; set; }
private int currKmPrivate { get; set; }
/// <summary>
/// OnInitialized
/// </summary>
@ -93,6 +95,7 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.Figures.KmMorning = 0;
Report.Figures.KmEvening = 0;
Report.Figures.Distance = 0;
Report.Figures.DistancePrivate = 0;
Report.Figures.DistancePrivateMonth = 0;
await GetKeyFigures();
@ -123,12 +126,14 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.Figures = data.ReportData;
InitialValues = data.ReportData;
Activities = data.ReportItems;
currKmMonth = data.ReportData.DistanceMonth;
currKmPrivate = data.ReportData.DistancePrivate;
if (Report.DayTypeEnum.ToLower().Contains("leave"))
{
// ensure no distances in calculation
Report.Figures.KmMorning = 0;
Report.Figures.KmEvening = 0;
Report.Figures.DistancePrivate = 0;
}
else
{
@ -147,11 +152,13 @@ public partial class AdvisorReportCreatePage : IDisposable
{
// Console.WriteLine($"e FieldName => {e.FieldIdentifier.FieldName}");
FormInvalid = !ReportContext.Validate();
if (Report.Figures.KmEvening - Report.Figures.KmMorning > 1000)
Report.Figures.Distance = Report.Figures.KmEvening - Report.Figures.KmMorning;
Report.Figures.DistanceMonth = Report.Figures.Distance + currKmMonth;
Report.Figures.DistancePrivateMonth = Report.Figures.DistancePrivate + currKmPrivate;
if (Report.Figures.Distance is > 1000 or < 0)
{
Toaster.ShowError($"KM tal '{Report.Figures.KmEvening - Report.Figures.KmMorning}'. Er du sikker på at det er rigtigt?", "KM tal");
Toaster.ShowError($"Kørte km for rapporten er '{Report.Figures.Distance}'. Er du sikker på at det er rigtigt?", "KM tal");
}
StateHasChanged();
}
@ -230,29 +237,22 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.FromDateTime = checkIn.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
Report.ToDateTime = checkOut.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
if (Report.DayTypeEnum.ToLower().Contains("leave"))
{
// ensure no distances in calculation
Report.Figures.KmEvening = 0;
Report.Figures.KmMorning = 0;
}
else
{
// calculate distance
Report.Figures.Distance = Report.Figures.KmEvening - Report.Figures.KmMorning;
// add distance to distance month
Report.Figures.DistanceMonth += Report.Figures.Distance;
// add private distance to month
Report.Figures.DistancePrivateMonth += Report.Figures.DistancePrivate;
}
Logger.LogDebug("_workDate => {workDate}", $"{_workDate:yyyy-MM-dd}");
Logger.LogDebug("_report => {report}", JsonSerializer.Serialize(Report));
if (Report.DayTypeEnum is "leave" or "sickLeave")
{
// reset distance calculation
Report.Figures.KmEvening = 0;
Report.Figures.KmMorning = 0;
Report.Figures.DistanceMonth = currKmMonth;
Report.Figures.DistancePrivateMonth = currKmPrivate;
}
// pop confirmation
// create a prompt for popup confirmation
var warning = Report.Figures.KmEvening - Report.Figures.KmMorning > 1000 ?
$"KM tal '{Report.Figures.KmEvening - Report.Figures.KmMorning}'. Er du sikker på at det er rigtigt?<br/>" : "";
$"Kørte km for rapporten er '{Report.Figures.KmEvening - Report.Figures.KmMorning}'. Er du sikker på at det er rigtigt?<br/>" : "";
Prompt = $"{warning}<br/>Gem rapport for {_workDate.ToLongDateString()}?";

View file

@ -38,7 +38,7 @@ public partial class OfficeUserAdvisorViewEditPage : IDisposable
private WebUserInfoView UserInfo { get; set; } = new();
private EditContext _editContext { get; set; }
private UserUpdateDto _updateInfo { get; set; } = new();
private AdminResetPasswordDto _passwords { get; set; } = new();
private ResetPasswordDto _passwords { get; set; } = new();
private EditContext _passwdContext { get; set; }
private bool _pwInvalid { get; set; } = true;
private bool Working { get; set; } = true;

View file

@ -32,6 +32,6 @@
<div class="content d-none d-print-block">
@Body
</div>
<BlazoredToasts Position="ToastPosition.BottomRight" Timeout="10" />
<BlazoredToasts Position="ToastPosition.BottomRight" Timeout="10" />
</main>
</div>

View file

@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Online",
"version": "0.110.1",
"version": "0.112.1",
"rc": true,
"sandBox": false,
"image": "grumpy-coder.png"
@ -28,6 +28,7 @@
"crmActivities": "api/v2/crm/advisors/activities",
"crmTasks": "api/v2/crm/advisors/tasks",
"crmWorkplaceExt": "workplaces",
"managers": "api/v2/managers/users",
"officeBase": "api/v2/office",
"officeAdvisors": "api/v2/office/users/advisors",
"officeCustomers": "api/v2/office/customers",

View file

@ -17,7 +17,7 @@ using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
public class AdminResetPasswordDto
public class ResetPasswordDto
{
/// <summary>
/// New password

View file

@ -20,7 +20,7 @@ namespace Wonky.Entity.Views;
public class WebUserInfoView
{
[JsonPropertyName("userId")] public string UserId { get; set; } = "";
[JsonPropertyName("advisor")] public string Advisor { get; set; } = "";
[JsonPropertyName("salesRep")] public string Advisor { get; set; } = "";
[JsonPropertyName("countryCode")] public string CountryCode { get; set; } = "";
[JsonPropertyName("countryName")] public string CountryName { get; set; } = "";
[JsonPropertyName("email")] public string Email { get; set; } = "";