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

View file

@ -52,6 +52,8 @@ public partial class AdvisorReportCreatePage : IDisposable
private ConfirmationModal ConfirmReportModal { get; set; } private ConfirmationModal ConfirmReportModal { get; set; }
private string Prompt { get; set; } = ""; private string Prompt { get; set; } = "";
private string WorkDate { get; set; } = ""; private string WorkDate { get; set; } = "";
private int currKmMonth { get; set; }
private int currKmPrivate { get; set; }
/// <summary> /// <summary>
/// OnInitialized /// OnInitialized
@ -93,6 +95,7 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.Figures.KmMorning = 0; Report.Figures.KmMorning = 0;
Report.Figures.KmEvening = 0; Report.Figures.KmEvening = 0;
Report.Figures.Distance = 0; Report.Figures.Distance = 0;
Report.Figures.DistancePrivate = 0;
Report.Figures.DistancePrivateMonth = 0; Report.Figures.DistancePrivateMonth = 0;
await GetKeyFigures(); await GetKeyFigures();
@ -123,12 +126,14 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.Figures = data.ReportData; Report.Figures = data.ReportData;
InitialValues = data.ReportData; InitialValues = data.ReportData;
Activities = data.ReportItems; Activities = data.ReportItems;
currKmMonth = data.ReportData.DistanceMonth;
currKmPrivate = data.ReportData.DistancePrivate;
if (Report.DayTypeEnum.ToLower().Contains("leave")) if (Report.DayTypeEnum.ToLower().Contains("leave"))
{ {
// ensure no distances in calculation // ensure no distances in calculation
Report.Figures.KmMorning = 0; Report.Figures.KmMorning = 0;
Report.Figures.KmEvening = 0; Report.Figures.KmEvening = 0;
Report.Figures.DistancePrivate = 0;
} }
else else
{ {
@ -147,11 +152,13 @@ public partial class AdvisorReportCreatePage : IDisposable
{ {
// Console.WriteLine($"e FieldName => {e.FieldIdentifier.FieldName}"); // Console.WriteLine($"e FieldName => {e.FieldIdentifier.FieldName}");
FormInvalid = !ReportContext.Validate(); 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(); StateHasChanged();
} }
@ -230,29 +237,22 @@ public partial class AdvisorReportCreatePage : IDisposable
Report.FromDateTime = checkIn.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); 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); 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("_workDate => {workDate}", $"{_workDate:yyyy-MM-dd}");
Logger.LogDebug("_report => {report}", JsonSerializer.Serialize(Report)); 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 // pop confirmation
// create a prompt for popup confirmation // create a prompt for popup confirmation
var warning = Report.Figures.KmEvening - Report.Figures.KmMorning > 1000 ? 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()}?"; 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 WebUserInfoView UserInfo { get; set; } = new();
private EditContext _editContext { get; set; } private EditContext _editContext { get; set; }
private UserUpdateDto _updateInfo { get; set; } = new(); private UserUpdateDto _updateInfo { get; set; } = new();
private AdminResetPasswordDto _passwords { get; set; } = new(); private ResetPasswordDto _passwords { get; set; } = new();
private EditContext _passwdContext { get; set; } private EditContext _passwdContext { get; set; }
private bool _pwInvalid { get; set; } = true; private bool _pwInvalid { get; set; } = true;
private bool Working { get; set; } = true; private bool Working { get; set; } = true;

View file

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

View file

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

View file

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

View file

@ -20,7 +20,7 @@ namespace Wonky.Entity.Views;
public class WebUserInfoView public class WebUserInfoView
{ {
[JsonPropertyName("userId")] public string UserId { get; set; } = ""; [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("countryCode")] public string CountryCode { get; set; } = "";
[JsonPropertyName("countryName")] public string CountryName { get; set; } = ""; [JsonPropertyName("countryName")] public string CountryName { get; set; } = "";
[JsonPropertyName("email")] public string Email { get; set; } = ""; [JsonPropertyName("email")] public string Email { get; set; } = "";