refactor in bug hunt for customer product history with office login
This commit is contained in:
parent
b2989b60c6
commit
130b524bc2
9 changed files with 71 additions and 57 deletions
|
@ -18,6 +18,10 @@
|
||||||
@using Wonky.Client.Helpers;
|
@using Wonky.Client.Helpers;
|
||||||
@using Wonky.Client.OverlayOffice
|
@using Wonky.Client.OverlayOffice
|
||||||
|
|
||||||
|
@if (Working)
|
||||||
|
{
|
||||||
|
<WorkingThreeDots />
|
||||||
|
}
|
||||||
@if (CompanyList.Any())
|
@if (CompanyList.Any())
|
||||||
{
|
{
|
||||||
<div class="row mt-2 d-flex g-3">
|
<div class="row mt-2 d-flex g-3">
|
||||||
|
@ -92,7 +96,7 @@
|
||||||
</div>
|
</div>
|
||||||
<OfficeCustomerInvoiceListOverlay Company="@SelectedCompany" InvoiceList="@InvoiceList" @ref="@InvoiceListOverlay"/>
|
<OfficeCustomerInvoiceListOverlay Company="@SelectedCompany" InvoiceList="@InvoiceList" @ref="@InvoiceListOverlay"/>
|
||||||
<OfficeCustomerActivityListOverlay Company="@SelectedCompany" ActivityList="@ActivityList" @ref="@ActivityListOverlay"/>
|
<OfficeCustomerActivityListOverlay Company="@SelectedCompany" ActivityList="@ActivityList" @ref="@ActivityListOverlay"/>
|
||||||
<OfficeCustomerListInventoryOverlay Company="@SelectedCompany" Inventory="@ProductList" @ref="@InventoryListOverlay"/>
|
<OfficeCustomerListInventoryOverlay Company="@SelectedCompany" Inventory="@ProductInventory" @ref="@InventoryListOverlay"/>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
|
using System.Text.Json;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.VisualBasic.CompilerServices;
|
using Microsoft.VisualBasic.CompilerServices;
|
||||||
using Wonky.Client.Enums;
|
using Wonky.Client.Enums;
|
||||||
|
@ -21,6 +22,7 @@ using Wonky.Client.OverlayOffice;
|
||||||
using Wonky.Entity.DTO;
|
using Wonky.Entity.DTO;
|
||||||
using Wonky.Entity.Views;
|
using Wonky.Entity.Views;
|
||||||
using Wonky.Client.Helpers;
|
using Wonky.Client.Helpers;
|
||||||
|
using Wonky.Client.HttpInterceptors;
|
||||||
using Wonky.Client.HttpRepository;
|
using Wonky.Client.HttpRepository;
|
||||||
using Wonky.Client.Models;
|
using Wonky.Client.Models;
|
||||||
using Wonky.Client.Shared;
|
using Wonky.Client.Shared;
|
||||||
|
@ -30,14 +32,14 @@ using Utils = Wonky.Client.Helpers.Utils;
|
||||||
|
|
||||||
namespace Wonky.Client.Components;
|
namespace Wonky.Client.Components;
|
||||||
|
|
||||||
public partial class OfficeCountryCustomerListComponent
|
public partial class OfficeCountryCustomerListComponent : IDisposable
|
||||||
{
|
{
|
||||||
// ******************************************************
|
// ******************************************************
|
||||||
// injects
|
// injects
|
||||||
[Inject] public ICountryCustomerHistoryRepository HistoryRepo { get; set; }
|
[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 ILogger<OfficeCountryCustomerListComponent> Logger { get; set; }
|
||||||
|
[Inject] public HttpInterceptorService Interceptor { get; set; }
|
||||||
|
|
||||||
// ******************************************************
|
// ******************************************************
|
||||||
// parameters
|
// parameters
|
||||||
|
@ -56,74 +58,77 @@ public partial class OfficeCountryCustomerListComponent
|
||||||
// variables
|
// variables
|
||||||
private InvoiceListView InvoiceList { get; set; } = new();
|
private InvoiceListView InvoiceList { get; set; } = new();
|
||||||
private List<ReportItemView> ActivityList { 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();
|
private CompanyDto SelectedCompany { get; set; } = new();
|
||||||
|
|
||||||
// ******************************************************
|
private bool Working { get; set; }
|
||||||
// functions
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
Interceptor.RegisterEvent();
|
||||||
|
Interceptor.RegisterBeforeSendEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task ShowInvoiceList(string companyId)
|
private async Task ShowInvoiceList(string companyId)
|
||||||
{
|
{
|
||||||
// check for console manipulation
|
Working = true;
|
||||||
if (!Utils.Validate(ValidateType.Id, companyId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
||||||
|
|
||||||
// call erp to crm sync before requesting invoices
|
// call erp to crm sync before requesting invoices
|
||||||
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(CountryCode, companyId, SelectedCompany.HistorySync);
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(companyId, SelectedCompany.HistorySync, false);
|
||||||
InvoiceList = await HistoryRepo.GetInvoiceList(CountryCode, companyId);
|
while (string.IsNullOrEmpty(newSyncDate))
|
||||||
if (!string.IsNullOrWhiteSpace(newSyncDate))
|
|
||||||
{
|
{
|
||||||
SelectedCompany.HistorySync = newSyncDate;
|
await Task.Delay(500);
|
||||||
}
|
}
|
||||||
|
InvoiceList = await HistoryRepo.GetInvoiceList(CountryCode, companyId);
|
||||||
InvoiceListOverlay.Show();
|
InvoiceListOverlay.Show();
|
||||||
|
Working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task ShowActivityList(string companyId)
|
private async Task ShowActivityList(string companyId)
|
||||||
{
|
{
|
||||||
// check for console manipulation
|
Working = true;
|
||||||
if (!Utils.Validate(ValidateType.Id, companyId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
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();
|
ActivityListOverlay.Show();
|
||||||
|
Working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task ShowInventory(string companyId)
|
private async Task ShowInventory(string companyId)
|
||||||
{
|
{
|
||||||
// check for console manipulation
|
Working = true;
|
||||||
if (!Utils.Validate(ValidateType.Id, companyId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
||||||
// call erp to crm sync before requesting products
|
Logger.LogDebug("SelectedCompany => {}", JsonSerializer.Serialize(SelectedCompany));
|
||||||
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(CountryCode, companyId, SelectedCompany.HistorySync);
|
|
||||||
// give the script time to execute
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
if (!string.IsNullOrWhiteSpace(newSyncDate))
|
var newSyncDate = await HistoryRepo.RequestErpToCrmSync(companyId, SelectedCompany.HistorySync, true);
|
||||||
|
while (string.IsNullOrEmpty(newSyncDate))
|
||||||
{
|
{
|
||||||
|
await Task.Delay(500);
|
||||||
SelectedCompany.HistorySync = newSyncDate;
|
|
||||||
}
|
}
|
||||||
// request inventory
|
// 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
|
// show the overlay
|
||||||
InventoryListOverlay.Show();
|
InventoryListOverlay.Show();
|
||||||
|
Working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ShowOrder(string companyId)
|
private void ShowOrder(string companyId)
|
||||||
{
|
{
|
||||||
// check for console manipulation
|
|
||||||
if (!Utils.Validate(ValidateType.Id, companyId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
SelectedCompany = CompanyList.First(x => x.CompanyId == companyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Interceptor.DisposeEvent();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -126,7 +126,8 @@ public class AdvisorCustomerHistoryRepository : IAdvisorCustomerHistoryRepositor
|
||||||
|
|
||||||
public async Task<string> RequestErpSync(string companyId, string syncDate, bool force)
|
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();
|
var content = await x.Content.ReadAsStringAsync();
|
||||||
if (!x.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
if (!x.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class CountryCustomerHistoryRepository : ICountryCustomerHistoryRepositor
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
private readonly ApiConfig _api;
|
private readonly ApiConfig _api;
|
||||||
|
|
||||||
|
|
||||||
public CountryCustomerHistoryRepository(
|
public CountryCustomerHistoryRepository(
|
||||||
HttpClient client, ILogger<CountryCustomerHistoryRepository> logger,
|
HttpClient client, ILogger<CountryCustomerHistoryRepository> logger,
|
||||||
NavigationManager navigation, IOptions<ApiConfig> configuration)
|
NavigationManager navigation, IOptions<ApiConfig> configuration)
|
||||||
|
@ -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
|
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();
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
if (!response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
return content.Trim('"');
|
||||||
return content.Replace("\"", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,5 +29,5 @@ public interface ICountryCustomerHistoryRepository
|
||||||
|
|
||||||
Task<List<ProductHistoryView>> GetSkuHistory(string countryCode, string companyId, string sku);
|
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);
|
||||||
}
|
}
|
|
@ -72,11 +72,15 @@ public partial class OfficeCustomerCountryPagedListPage : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task GetProductHistory(string companyId)
|
||||||
|
{
|
||||||
|
await Task.Delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task FetchCustomers()
|
private async Task FetchCustomers()
|
||||||
{
|
{
|
||||||
Working = true;
|
Working = true;
|
||||||
var response = await CustomerRepo.GetCompaniesPaged(CountryCode, Paging);
|
var response = await CustomerRepo.GetCompaniesPaged(CountryCode, Paging);
|
||||||
Working = false;
|
|
||||||
if (response.Items.Any())
|
if (response.Items.Any())
|
||||||
{
|
{
|
||||||
Companies = response.Items;
|
Companies = response.Items;
|
||||||
|
@ -87,6 +91,7 @@ public partial class OfficeCustomerCountryPagedListPage : IDisposable
|
||||||
Companies = new List<CompanyDto>();
|
Companies = new List<CompanyDto>();
|
||||||
PageData = new MetaData();
|
PageData = new MetaData();
|
||||||
}
|
}
|
||||||
|
Working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public partial class OfficeOrderCreatePage : IDisposable
|
||||||
// initiate a sync to ensure up-to-date product history
|
// initiate a sync to ensure up-to-date product history
|
||||||
if (Company.HistorySync != today)
|
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);
|
Logger.LogDebug("OfficeOrderCreate => RequestErpToCrmSync <= {}", Company.HistorySync);
|
||||||
}
|
}
|
||||||
// fetch invoices
|
// fetch invoices
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"appInfo": {
|
"appInfo": {
|
||||||
"name": "Wonky Online",
|
"name": "Wonky Online",
|
||||||
"version": "230.0",
|
"version": "231.0",
|
||||||
"rc": true,
|
"rc": true,
|
||||||
"sandBox": true,
|
"sandBox": true,
|
||||||
"image": "grumpy-coder.png",
|
"image": "grumpy-coder.png",
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
"serviceVatDk": "api/v2/services/virk",
|
"serviceVatDk": "api/v2/services/virk",
|
||||||
"serviceVatEu": "api/v2/services/vies",
|
"serviceVatEu": "api/v2/services/vies",
|
||||||
"serviceVatNo": "api/v2/services/brReg",
|
"serviceVatNo": "api/v2/services/brReg",
|
||||||
"serviceVatSe": "api/v2/services/allabolag",
|
"serviceVatSe": "api/v2/services/allaBolag",
|
||||||
"sync": "api/v2/sync",
|
"sync": "api/v2/sync",
|
||||||
"syncInvoice": "api/v2/sync/invoices",
|
"syncInvoice": "api/v2/sync/invoices",
|
||||||
"systemDocStringUrl": "api/v2/admin/doc",
|
"systemDocStringUrl": "api/v2/admin/doc",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
body {
|
body {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
/*background-color: #eeeeee;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
.draft-expires-msg {
|
.draft-expires-msg {
|
||||||
|
|
Loading…
Reference in a new issue