refactor in bug hunt for customer product history with office login

This commit is contained in:
Frede Hundewadt 2023-09-07 07:58:05 +02:00
parent b2989b60c6
commit 130b524bc2
9 changed files with 71 additions and 57 deletions

View file

@ -18,6 +18,10 @@
@using Wonky.Client.Helpers;
@using Wonky.Client.OverlayOffice
@if (Working)
{
<WorkingThreeDots />
}
@if (CompanyList.Any())
{
<div class="row mt-2 d-flex g-3">
@ -92,9 +96,9 @@
</div>
<OfficeCustomerInvoiceListOverlay Company="@SelectedCompany" InvoiceList="@InvoiceList" @ref="@InvoiceListOverlay"/>
<OfficeCustomerActivityListOverlay Company="@SelectedCompany" ActivityList="@ActivityList" @ref="@ActivityListOverlay"/>
<OfficeCustomerListInventoryOverlay Company="@SelectedCompany" Inventory="@ProductList" @ref="@InventoryListOverlay"/>
<OfficeCustomerListInventoryOverlay Company="@SelectedCompany" Inventory="@ProductInventory" @ref="@InventoryListOverlay"/>
}
else
{
<div>Ingen data</div>
}
}

View file

@ -14,6 +14,7 @@
//
using System.Reflection.Metadata.Ecma335;
using System.Text.Json;
using Microsoft.AspNetCore.Components;
using Microsoft.VisualBasic.CompilerServices;
using Wonky.Client.Enums;
@ -21,6 +22,7 @@ using Wonky.Client.OverlayOffice;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
using Wonky.Client.Helpers;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Client.Models;
using Wonky.Client.Shared;
@ -30,14 +32,14 @@ using Utils = Wonky.Client.Helpers.Utils;
namespace Wonky.Client.Components;
public partial class OfficeCountryCustomerListComponent
public partial class OfficeCountryCustomerListComponent : IDisposable
{
// ******************************************************
// injects
[Inject] public ICountryCustomerHistoryRepository HistoryRepo { get; set; }
[Inject] public ICountryCustomerActivityRepository CustomerActivityRepo { get; set; }
[Inject] public ICountryCustomerActivityRepository ActivityRepo { get; set; }
[Inject] public ILogger<OfficeCountryCustomerListComponent> Logger { get; set; }
[Inject] public HttpInterceptorService Interceptor { get; set; }
// ******************************************************
// parameters
@ -51,79 +53,82 @@ public partial class OfficeCountryCustomerListComponent
private OfficeCustomerInvoiceListOverlay InvoiceListOverlay { get; set; } = new();
private OfficeCustomerActivityListOverlay ActivityListOverlay { get; set; } = new();
private OfficeCustomerListInventoryOverlay InventoryListOverlay { get; set; } = new();
// ******************************************************
// variables
private InvoiceListView InvoiceList { get; set; } = new();
private List<ReportItemView> ActivityList { get; set; } = new();
private List<ProductInventoryItemView> ProductList { get; set; } = new();
private List<ProductInventoryItemView> ProductInventory { get; set; } = new();
private CompanyDto SelectedCompany { get; set; } = new();
// ******************************************************
// functions
private bool Working { get; set; }
protected override void OnInitialized()
{
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
}
private async Task ShowInvoiceList(string companyId)
{
// check for console manipulation
if (!Utils.Validate(ValidateType.Id, companyId))
{
return;
}
Working = true;
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
// call erp to crm sync before requesting invoices
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(CountryCode, companyId, SelectedCompany.HistorySync);
await Task.Delay(500);
InvoiceList = await HistoryRepo.GetInvoiceList(CountryCode, companyId);
if (!string.IsNullOrWhiteSpace(newSyncDate))
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(companyId, SelectedCompany.HistorySync, false);
while (string.IsNullOrEmpty(newSyncDate))
{
SelectedCompany.HistorySync = newSyncDate;
await Task.Delay(500);
}
InvoiceList = await HistoryRepo.GetInvoiceList(CountryCode, companyId);
InvoiceListOverlay.Show();
Working = false;
}
private async Task ShowActivityList(string companyId)
{
// check for console manipulation
if (!Utils.Validate(ValidateType.Id, companyId))
{
return;
}
Working = true;
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
ActivityList = await CustomerActivityRepo.GetActivityList(companyId);
await Task.Delay(500);
ActivityList = await ActivityRepo.GetActivityList(companyId);
await Task.Delay(500);
ActivityListOverlay.Show();
Working = false;
}
private async Task ShowInventory(string companyId)
{
// check for console manipulation
if (!Utils.Validate(ValidateType.Id, companyId))
{
return;
}
Working = true;
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
// call erp to crm sync before requesting products
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(CountryCode, companyId, SelectedCompany.HistorySync);
// give the script time to execute
Logger.LogDebug("SelectedCompany => {}", JsonSerializer.Serialize(SelectedCompany));
await Task.Delay(500);
if (!string.IsNullOrWhiteSpace(newSyncDate))
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(companyId, SelectedCompany.HistorySync, true);
while (string.IsNullOrEmpty(newSyncDate))
{
SelectedCompany.HistorySync = newSyncDate;
await Task.Delay(500);
}
// request inventory
ProductList = await HistoryRepo.GetInventory(SelectedCompany.CountryCode, SelectedCompany.CompanyId);
await Task.Delay(500);
ProductInventory = await HistoryRepo.GetInventory(SelectedCompany.CountryCode, SelectedCompany.CompanyId);
await Task.Delay(500);
Logger.LogDebug("ProductInventory => {}", JsonSerializer.Serialize(ProductInventory));
// show the overlay
InventoryListOverlay.Show();
Working = false;
}
private void ShowOrder(string companyId)
{
// check for console manipulation
if (!Utils.Validate(ValidateType.Id, companyId))
{
return;
}
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
}
public void Dispose()
{
Interceptor.DisposeEvent();
}
}

View file

@ -126,7 +126,8 @@ public class AdvisorCustomerHistoryRepository : IAdvisorCustomerHistoryRepositor
public async Task<string> RequestErpSync(string companyId, string syncDate, bool force)
{
var x = await _client.GetAsync($"{_api.SyncInvoice}/{companyId}/{syncDate}?force={force}");
var x = await _client
.GetAsync($"{_api.SyncInvoice}/{companyId}/{syncDate}/?force={force}");
var content = await x.Content.ReadAsStringAsync();
if (!x.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
{

View file

@ -33,7 +33,8 @@ public class CountryCustomerHistoryRepository : ICountryCustomerHistoryRepositor
private ILogger<CountryCustomerHistoryRepository> _logger;
private readonly HttpClient _client;
private readonly ApiConfig _api;
public CountryCustomerHistoryRepository(
HttpClient client, ILogger<CountryCustomerHistoryRepository> logger,
NavigationManager navigation, IOptions<ApiConfig> configuration)
@ -43,7 +44,7 @@ public class CountryCustomerHistoryRepository : ICountryCustomerHistoryRepositor
_navigation = navigation;
_api = configuration.Value;
}
public async Task<InvoiceListView> GetInvoiceList(string countryCode, string companyId)
{
@ -130,18 +131,15 @@ public class CountryCustomerHistoryRepository : ICountryCustomerHistoryRepositor
}
public async Task<string> RequestErpToCrmSync(string countryCode, string companyId, string syncDate)
public async Task<string> RequestErpToCrmSync(string companyId, string syncDate, bool force)
{
var response = await _client
.GetAsync($"{_api.OfficeCustomers}/{countryCode}/{companyId}/{_api.SyncInvoice}/{syncDate}");
.GetAsync($"{_api.SyncInvoice}/{companyId}/{syncDate}/?force={force}");
var content = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
{
return string.Empty;
}
return content.Replace("\"", "");
return content.Trim('"');
}
}

View file

@ -29,5 +29,5 @@ public interface ICountryCustomerHistoryRepository
Task<List<ProductHistoryView>> GetSkuHistory(string countryCode, string companyId, string sku);
Task<string> RequestErpToCrmSync(string countryCode, string companyId, string syncDate);
Task<string> RequestErpToCrmSync(string companyId, string syncDate, bool force);
}

View file

@ -71,12 +71,16 @@ public partial class OfficeCustomerCountryPagedListPage : IDisposable
Working = false;
}
private async Task GetProductHistory(string companyId)
{
await Task.Delay(1);
}
private async Task FetchCustomers()
{
Working = true;
var response = await CustomerRepo.GetCompaniesPaged(CountryCode, Paging);
Working = false;
if (response.Items.Any())
{
Companies = response.Items;
@ -87,6 +91,7 @@ public partial class OfficeCustomerCountryPagedListPage : IDisposable
Companies = new List<CompanyDto>();
PageData = new MetaData();
}
Working = false;
}

View file

@ -111,7 +111,7 @@ public partial class OfficeOrderCreatePage : IDisposable
// initiate a sync to ensure up-to-date product history
if (Company.HistorySync != today)
{
Company.HistorySync = await HistoryRepo.RequestErpToCrmSync(CountryCode, CompanyId, Company.HistorySync);
Company.HistorySync = await HistoryRepo.RequestErpToCrmSync(CompanyId, Company.HistorySync, false);
Logger.LogDebug("OfficeOrderCreate => RequestErpToCrmSync <= {}", Company.HistorySync);
}
// fetch invoices

View file

@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Online",
"version": "230.0",
"version": "231.0",
"rc": true,
"sandBox": true,
"image": "grumpy-coder.png",
@ -42,7 +42,7 @@
"serviceVatDk": "api/v2/services/virk",
"serviceVatEu": "api/v2/services/vies",
"serviceVatNo": "api/v2/services/brReg",
"serviceVatSe": "api/v2/services/allabolag",
"serviceVatSe": "api/v2/services/allaBolag",
"sync": "api/v2/sync",
"syncInvoice": "api/v2/sync/invoices",
"systemDocStringUrl": "api/v2/admin/doc",

View file

@ -1,5 +1,6 @@
body {
font-size: 16px;
/*background-color: #eeeeee;*/
}
.draft-expires-msg {