confirmation dialog for office printing orders - set process accepted

This commit is contained in:
Frede Hundewadt 2023-01-16 15:07:59 +01:00
parent 7a99f8c6b1
commit d9f4e71470
11 changed files with 85 additions and 30 deletions

View file

@ -13,6 +13,7 @@
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
// //
using Wonky.Entity.DTO;
using Wonky.Entity.Views; using Wonky.Entity.Views;
namespace Wonky.Client.HttpInterfaces; namespace Wonky.Client.HttpInterfaces;
@ -20,7 +21,7 @@ namespace Wonky.Client.HttpInterfaces;
/// <summary> /// <summary>
/// Interface for processing orders in warehouse /// Interface for processing orders in warehouse
/// </summary> /// </summary>
public interface IWarehouseRepository public interface IOrderProcessRepository
{ {
/// <summary> /// <summary>
/// Get warehouse order list by date /// Get warehouse order list by date
@ -47,7 +48,7 @@ public interface IWarehouseRepository
/// <summary> /// <summary>
/// Update Order status setting new process status /// Update Order status setting new process status
/// </summary> /// </summary>
/// <param name="process"></param> /// <param name="processState"></param>
/// <returns></returns> /// <returns></returns>
Task UpdateWarehouseOrderStatus(WarehouseProcess process); Task UpdateWarehouseOrderStatus(OrderProcessState processState);
} }

View file

@ -19,11 +19,12 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Wonky.Client.HttpInterfaces; using Wonky.Client.HttpInterfaces;
using Wonky.Entity.Configuration; using Wonky.Entity.Configuration;
using Wonky.Entity.DTO;
using Wonky.Entity.Views; using Wonky.Entity.Views;
namespace Wonky.Client.HttpRepository; namespace Wonky.Client.HttpRepository;
public class WarehouseRepository : IWarehouseRepository public class OrderProcessRepository : IOrderProcessRepository
{ {
private readonly JsonSerializerOptions? _options = new JsonSerializerOptions private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
{ {
@ -31,12 +32,12 @@ public class WarehouseRepository : IWarehouseRepository
}; };
private readonly NavigationManager _navigation; private readonly NavigationManager _navigation;
private ILogger<WarehouseRepository> _logger; private ILogger<OrderProcessRepository> _logger;
private readonly HttpClient _client; private readonly HttpClient _client;
private readonly ApiConfig _api; private readonly ApiConfig _api;
public WarehouseRepository(HttpClient client, public OrderProcessRepository(HttpClient client,
ILogger<WarehouseRepository> logger, ILogger<OrderProcessRepository> logger,
NavigationManager navigation, NavigationManager navigation,
IOptions<ApiConfig> configuration) IOptions<ApiConfig> configuration)
{ {
@ -81,11 +82,11 @@ public class WarehouseRepository : IWarehouseRepository
/// <summary> /// <summary>
/// Update Order status setting new process status /// Update Order status setting new process status
/// </summary> /// </summary>
/// <param name="process"></param> /// <param name="processState"></param>
/// <returns></returns> /// <returns></returns>
public async Task UpdateWarehouseOrderStatus(WarehouseProcess process) public async Task UpdateWarehouseOrderStatus(OrderProcessState processState)
{ {
_logger.LogDebug("process => {}", JsonSerializer.Serialize(process, _options)); _logger.LogDebug("process => {}", JsonSerializer.Serialize(processState, _options));
await _client.PutAsJsonAsync($"{_api.Warehouse}/{process.OrderId}", process, _options); await _client.PutAsJsonAsync($"{_api.Warehouse}/{processState.OrderId}", processState, _options);
} }
} }

View file

@ -7,5 +7,6 @@ public enum PStatus
Packed, Packed,
Shipped, Shipped,
All, All,
Express Express,
Accepted
} }

View file

@ -25,6 +25,9 @@
<a class="btn btn-info" href="@ReturnUrl"><i class="bi-back"></i> Tilbage</a> <a class="btn btn-info" href="@ReturnUrl"><i class="bi-back"></i> Tilbage</a>
</div> </div>
<div class="col-sm-6 d-grid"> <div class="col-sm-6 d-grid">
<AuthorizeView Roles="Admin,Office">
<button class="btn btn-primary" type="button" @onclick="ShowConfirmationModal"><i class="bi-printer"></i> Udskriv</button>
</AuthorizeView>
<button class="btn btn-primary" type="button" @onclick="Print"><i class="bi-printer"></i> Udskriv</button> <button class="btn btn-primary" type="button" @onclick="Print"><i class="bi-printer"></i> Udskriv</button>
</div> </div>
</div> </div>
@ -44,3 +47,5 @@ else
</div> </div>
</div> </div>
} }
<ConfirmationModal BodyMessage="@BodyMessage" OnOkClicked="OnOkCallBack" OnCancelClicked="OnCancelCallback" />

View file

@ -17,6 +17,10 @@ using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Wonky.Client.Helpers; using Wonky.Client.Helpers;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.Models;
using Wonky.Client.Shared;
using Wonky.Entity.DTO;
using Wonky.Entity.Views; using Wonky.Entity.Views;
namespace Wonky.Client.Pages; namespace Wonky.Client.Pages;
@ -28,12 +32,15 @@ public partial class ReportPrintOrderPage
[Parameter] public string ReportDate { get; set; } = ""; [Parameter] public string ReportDate { get; set; } = "";
[Inject] public ILocalStorageService Storage { get; set; } [Inject] public ILocalStorageService Storage { get; set; }
[Inject] public NavigationManager Navigator { get; set; } [Inject] public NavigationManager Navigator { get; set; }
[Inject] public IOrderProcessRepository ProcessRepo { get; set; }
[Inject] private IJSRuntime JSRuntime { get; set; } [Inject] private IJSRuntime JSRuntime { get; set; }
[Inject] public ILogger<ReportPrintOrderPage> Logger { get; set; } [Inject] public ILogger<ReportPrintOrderPage> Logger { get; set; }
private ReportView Report { get; set; } = new(); private ReportView Report { get; set; } = new();
private List<ReportItemView> Items { get; set; } = new(); private List<ReportItemView> Items { get; set; } = new();
private IJSObjectReference JsModule { get; set; } private IJSObjectReference JsModule { get; set; }
private string ReturnUrl { get; set; } = ""; private string ReturnUrl { get; set; } = "";
private ConfirmationModal ConfirmAccepted { get; set; }
private string BodyMessage { get; set; } = "";
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (firstRender) if (firstRender)
@ -53,6 +60,31 @@ public partial class ReportPrintOrderPage
Items = Report.ReportItems; Items = Report.ReportItems;
} }
private void ShowConfirmationModal()
{
BodyMessage = "<p>Vil du sætte ordrestatus til accepteret i CRM?</p><p>Dette sikrer at ordrelisten kun udskrives en gang.</p>";
ConfirmAccepted.Show();
}
private async Task OnOkCallBack()
{
foreach (var process in Report.ReportItems.Select(item => new OrderProcessState
{
OrderId = item.ActivityId,
ProcessStatusEnum = Utils.EnumToString(PStatus.Accepted)
}))
{
await ProcessRepo.UpdateWarehouseOrderStatus(process);
}
await Print();
}
private async Task OnCancelCallback()
{
await Print();
}
private async Task Print() private async Task Print()
{ {
await JsModule.InvokeVoidAsync("printInvoke"); await JsModule.InvokeVoidAsync("printInvoke");

View file

@ -3,6 +3,7 @@ using Wonky.Client.Helpers;
using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpInterfaces; using Wonky.Client.HttpInterfaces;
using Wonky.Client.Models; using Wonky.Client.Models;
using Wonky.Entity.DTO;
using Wonky.Entity.Views; using Wonky.Entity.Views;
namespace Wonky.Client.Pages; namespace Wonky.Client.Pages;
@ -12,7 +13,7 @@ public partial class WarehouseOrderListPage : IDisposable
[Parameter] public string Status { get; set; } = "none"; [Parameter] public string Status { get; set; } = "none";
[Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; }
[Inject] public IWarehouseRepository WarehouseRepo { get; set; } [Inject] public IOrderProcessRepository OrderProcessRepo { get; set; }
[Inject] public NavigationManager Navigator { get; set; } [Inject] public NavigationManager Navigator { get; set; }
private List<WarehouseOrderView> OrderList { get; set; } private List<WarehouseOrderView> OrderList { get; set; }
private bool Working { get; set; } = true; private bool Working { get; set; } = true;
@ -66,12 +67,12 @@ public partial class WarehouseOrderListPage : IDisposable
Working = true; Working = true;
var order = OrderList.First(x => x.OrderId == orderId); var order = OrderList.First(x => x.OrderId == orderId);
order.ProcessStatusEnum = "packed"; order.ProcessStatusEnum = "packed";
var process = new WarehouseProcess var process = new OrderProcessState
{ {
OrderId = order.OrderId, OrderId = order.OrderId,
ProcessStatusEnum = "packed" ProcessStatusEnum = "packed"
}; };
await WarehouseRepo.UpdateWarehouseOrderStatus(process); await OrderProcessRepo.UpdateWarehouseOrderStatus(process);
OrderList.Remove(order); OrderList.Remove(order);
Working = false; Working = false;
} }
@ -84,12 +85,12 @@ public partial class WarehouseOrderListPage : IDisposable
foreach (var order in OrderList.Where(order => order.ProcessStatusEnum.ToLower() == "packed")) foreach (var order in OrderList.Where(order => order.ProcessStatusEnum.ToLower() == "packed"))
{ {
order.ProcessStatusEnum = "shipped"; order.ProcessStatusEnum = "shipped";
var process = new WarehouseProcess var process = new OrderProcessState
{ {
OrderId = order.OrderId, OrderId = order.OrderId,
ProcessStatusEnum = "shipped" ProcessStatusEnum = "shipped"
}; };
await WarehouseRepo.UpdateWarehouseOrderStatus(process); await OrderProcessRepo.UpdateWarehouseOrderStatus(process);
} }
Working = false; Working = false;
} }
@ -97,7 +98,7 @@ public partial class WarehouseOrderListPage : IDisposable
private async Task<List<WarehouseOrderView>> FetchOrders(string status) private async Task<List<WarehouseOrderView>> FetchOrders(string status)
{ {
Working = true; Working = true;
var orderList = await WarehouseRepo.GetWarehouseOrderListByStatus(status.ToLower()); var orderList = await OrderProcessRepo.GetWarehouseOrderListByStatus(status.ToLower());
if(orderList.Any(x => x.Express)) if(orderList.Any(x => x.Express))
orderList = orderList.OrderByDescending(x => x.Express).ToList(); orderList = orderList.OrderByDescending(x => x.Express).ToList();
Working = false; Working = false;

View file

@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpInterfaces; using Wonky.Client.HttpInterfaces;
using Wonky.Client.HttpRepository; using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views; using Wonky.Entity.Views;
namespace Wonky.Client.Pages; namespace Wonky.Client.Pages;
@ -29,7 +30,7 @@ public partial class WarehouseOrderViewPage : IDisposable
{ {
[Parameter] public string OrderId { get; set; } = ""; [Parameter] public string OrderId { get; set; } = "";
[Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; }
[Inject] public IWarehouseRepository WarehouseRepo { get; set; } [Inject] public IOrderProcessRepository OrderProcessRepo { get; set; }
[Inject] public NavigationManager Navigator { get; set; } [Inject] public NavigationManager Navigator { get; set; }
[Inject] public IToastService Toast { get; set; } [Inject] public IToastService Toast { get; set; }
[Inject] public ILogger<WarehouseOrderViewPage> Logger { get; set; } [Inject] public ILogger<WarehouseOrderViewPage> Logger { get; set; }
@ -42,7 +43,7 @@ public partial class WarehouseOrderViewPage : IDisposable
Interceptor.RegisterEvent(); Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent(); Interceptor.RegisterBeforeSendEvent();
if (!string.IsNullOrWhiteSpace(OrderId)) if (!string.IsNullOrWhiteSpace(OrderId))
Order = await WarehouseRepo.GetWarehouseOrder(OrderId); Order = await OrderProcessRepo.GetWarehouseOrder(OrderId);
Logger.LogDebug("Warehouse OrderView =>\n{}", JsonSerializer.Serialize(Order)); Logger.LogDebug("Warehouse OrderView =>\n{}", JsonSerializer.Serialize(Order));
Working = false; Working = false;
@ -54,12 +55,12 @@ public partial class WarehouseOrderViewPage : IDisposable
return; return;
Working = true; Working = true;
var process = new WarehouseProcess var process = new OrderProcessState
{ {
OrderId = Order.OrderId, OrderId = Order.OrderId,
ProcessStatusEnum = "picked" ProcessStatusEnum = "picked"
}; };
await WarehouseRepo.UpdateWarehouseOrderStatus(process); await OrderProcessRepo.UpdateWarehouseOrderStatus(process);
Navigator.NavigateTo("/warehouse/orders/none"); Navigator.NavigateTo("/warehouse/orders/none");
} }
@ -68,12 +69,12 @@ public partial class WarehouseOrderViewPage : IDisposable
if (Working) if (Working)
return; return;
Working = true; Working = true;
var process = new WarehouseProcess var process = new OrderProcessState
{ {
OrderId = Order.OrderId, OrderId = Order.OrderId,
ProcessStatusEnum = "packed" ProcessStatusEnum = "packed"
}; };
await WarehouseRepo.UpdateWarehouseOrderStatus(process); await OrderProcessRepo.UpdateWarehouseOrderStatus(process);
Navigator.NavigateTo("/warehouse/orders/picked"); Navigator.NavigateTo("/warehouse/orders/picked");
} }
@ -82,12 +83,12 @@ public partial class WarehouseOrderViewPage : IDisposable
if (Working) if (Working)
return; return;
Working = true; Working = true;
var process = new WarehouseProcess var process = new OrderProcessState
{ {
OrderId = Order.OrderId, OrderId = Order.OrderId,
ProcessStatusEnum = "shipped" ProcessStatusEnum = "shipped"
}; };
await WarehouseRepo.UpdateWarehouseOrderStatus(process); await OrderProcessRepo.UpdateWarehouseOrderStatus(process);
Navigator.NavigateTo("/warehouse/orders/none"); Navigator.NavigateTo("/warehouse/orders/none");
} }

View file

@ -68,7 +68,7 @@ builder.Services.AddScoped<ICountryCustomerRepository, CountryCustomerRepository
builder.Services.AddScoped<ICountryReportRepository, CountryReportRepository>(); builder.Services.AddScoped<ICountryReportRepository, CountryReportRepository>();
builder.Services.AddScoped<ISystemUserRepository, SystemUserRepository>(); builder.Services.AddScoped<ISystemUserRepository, SystemUserRepository>();
// warehouse repository // warehouse repository
builder.Services.AddScoped<IWarehouseRepository, WarehouseRepository>(); builder.Services.AddScoped<IOrderProcessRepository, OrderProcessRepository>();
// mail service // mail service
builder.Services.AddScoped<ISystemSendMailService, SystemSendMailService>(); builder.Services.AddScoped<ISystemSendMailService, SystemSendMailService>();
// interceptor // interceptor

View file

@ -27,7 +27,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @onclick="Hide">Afbryd</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @onclick="Hide">Afbryd</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" @onclick="() => OnOkClicked.InvokeAsync()">OK</button> <button type="button" class="btn btn-primary" data-bs-dismiss="modal" @onclick="OkSelected">OK</button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -23,6 +23,19 @@ public partial class ConfirmationModal
private bool _showBackdrop; private bool _showBackdrop;
[Parameter] public string BodyMessage { get; set; } = ""; [Parameter] public string BodyMessage { get; set; } = "";
[Parameter] public EventCallback OnOkClicked { get; set; } [Parameter] public EventCallback OnOkClicked { get; set; }
[Parameter] public EventCallback? OnCancelClicked { get; set; }
private void OkSelected()
{
OnOkClicked.InvokeAsync();
Hide();
}
private void CancelSelected()
{
OnCancelClicked?.InvokeAsync();
Hide();
}
public void Show() public void Show()
{ {

View file

@ -14,9 +14,9 @@
// //
namespace Wonky.Entity.Views; namespace Wonky.Entity.DTO;
public class WarehouseProcess public class OrderProcessState
{ {
/// <summary> /// <summary>
/// Entity id /// Entity id