refactored rpc history update
This commit is contained in:
parent
8485b17c26
commit
d2d28be3bc
10 changed files with 49 additions and 44 deletions
|
@ -6,9 +6,9 @@ namespace Wonky.Client.Components;
|
|||
|
||||
public partial class InvoiceTableComponent
|
||||
{
|
||||
[Parameter] public List<InvoiceListItemView> InvoiceList { get; set; } = new();
|
||||
[Parameter] public string CompanyId { get; set; } = "";
|
||||
private InvoiceViewModal InvoiceView { get; set; }
|
||||
[Parameter] public List<InvoiceListItemView> InvoiceList { get; set; } = new();
|
||||
private InvoiceViewModal InvoiceView { get; set; } = new();
|
||||
private string InvoiceId { get; set; } = "";
|
||||
private void ShowInvoice(string invoiceId)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Wonky.Client.HttpRepository;
|
|||
|
||||
public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
||||
{
|
||||
private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
|
||||
private readonly JsonSerializerOptions _options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
@ -46,6 +46,7 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
|||
_navigation = navigation;
|
||||
_api = configuration.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fetch a list of invoices for CompanyId
|
||||
/// </summary>
|
||||
|
@ -80,12 +81,14 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
|||
public async Task<List<ProductInventoryView>> FetchInventory(string companyId)
|
||||
{
|
||||
var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmInventoryExt}");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return new List<ProductInventoryView>();
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return response.IsSuccessStatusCode
|
||||
? JsonSerializer.Deserialize<List<ProductInventoryView>>(content, _options)
|
||||
: new List<ProductInventoryView>();
|
||||
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new List<ProductInventoryView>()
|
||||
: JsonSerializer.Deserialize<List<ProductInventoryView>>(content, _options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetch history for all products
|
||||
/// </summary>
|
||||
|
@ -93,10 +96,15 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
|||
/// <returns>List of products</returns>
|
||||
public async Task<List<ProductHistoryView>> FetchHistory(string companyId)
|
||||
{
|
||||
return await _client.GetFromJsonAsync<List<ProductHistoryView>>(
|
||||
$"{_api.CrmCustomers}/{companyId}/{_api.CrmProductExt}", _options);
|
||||
|
||||
var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmProductExt}");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return new List<ProductHistoryView>();
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new List<ProductHistoryView>()
|
||||
: JsonSerializer.Deserialize<List<ProductHistoryView>>(content, _options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetch history for single product
|
||||
/// </summary>
|
||||
|
@ -105,8 +113,13 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
|||
/// <returns>list of products</returns>
|
||||
public async Task<List<ProductHistoryView>> FetchHistory(string companyId, string sku)
|
||||
{
|
||||
return await _client.GetFromJsonAsync<List<ProductHistoryView>>(
|
||||
$"{_api.CrmCustomers}/{companyId}/{_api.CrmProductExt}/{sku}", _options);
|
||||
var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmProductExt}/{sku}");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return new List<ProductHistoryView>();
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return string.IsNullOrWhiteSpace(content)
|
||||
? new List<ProductHistoryView>()
|
||||
: JsonSerializer.Deserialize<List<ProductHistoryView>>(content, _options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -117,7 +130,7 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
|
|||
/// <returns>date string</returns>
|
||||
public async Task<string> ErpInvoiceToCrmRpc(string companyId, string syncDate)
|
||||
{
|
||||
var x =await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmRpcSyncExt}/{syncDate}");
|
||||
var x = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmRpcSyncExt}/{syncDate}");
|
||||
if (!x.IsSuccessStatusCode)
|
||||
return "";
|
||||
var content = await x.Content.ReadAsStringAsync();
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
</div>
|
||||
<ProductInventoryTableComponent CompanyId="@CompanyId" ProductList="Inventory"/>
|
||||
|
||||
|
||||
@if (Working)
|
||||
{
|
||||
<WorkingThreeDots />
|
||||
|
|
|
@ -28,22 +28,24 @@ namespace Wonky.Client.Pages;
|
|||
public partial class CrmCompanyInventoryPage : IDisposable
|
||||
{
|
||||
[Parameter] public string CompanyId { get; set; } = "";
|
||||
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
|
||||
[Inject] public ICrmHistoryHttpRepository HistoryRepo { get; set; }
|
||||
[Inject] public ICrmCompanyHttpRepository CompanyRepo { get; set; }
|
||||
[Inject] public HttpInterceptorService Interceptor { get; set; }
|
||||
[Inject] public IToastService Toaster { get; set; }
|
||||
[Inject] public ILogger<CrmCompanyInventoryPage> Logger { get; set; }
|
||||
private CompanyDto Company { get; set; } = new();
|
||||
private List<ProductInventoryView>? Inventory { get; set; }
|
||||
private List<ProductInventoryView> Inventory { get; set; } = new();
|
||||
private bool Working { get; set; } = true;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Interceptor.RegisterEvent();
|
||||
Interceptor.RegisterBeforeSendEvent();
|
||||
|
||||
Company = await CompanyRepo.GetCompanyById(CompanyId);
|
||||
|
||||
var _ = await HistoryRepo.ErpInvoiceToCrmRpc(CompanyId, Company.HistorySync);
|
||||
|
||||
await FetchInventory();
|
||||
Working = false;
|
||||
}
|
||||
|
@ -51,12 +53,9 @@ public partial class CrmCompanyInventoryPage : IDisposable
|
|||
private async Task FetchInventory()
|
||||
{
|
||||
Working = true;
|
||||
Toaster.ShowInfo("Arbejder på sagen ...", "Vent venligst");
|
||||
Inventory = await CrmHistoryRepo.FetchInventory(CompanyId);
|
||||
if(Inventory.Any())
|
||||
Inventory = Inventory.OrderBy(x => x.Description).ToList();
|
||||
Inventory = await HistoryRepo.FetchInventory(CompanyId);
|
||||
Inventory = Inventory.Any() ? Inventory.OrderBy(x => x.Description).ToList() : new List<ProductInventoryView>();
|
||||
Working = false;
|
||||
Toaster.ClearAll();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -16,18 +16,19 @@ public partial class CrmCompanyInvoiceListPage : IDisposable
|
|||
[Inject] public HttpInterceptorService Interceptor { get; set; }
|
||||
[Inject] public ICrmHistoryHttpRepository HistoryRepo { get; set; }
|
||||
[Inject] public IToastService Toaster { get; set; }
|
||||
|
||||
private InvoiceListView History { get; set; } = new();
|
||||
private CompanyDto Company { get; set; } = new();
|
||||
private bool Working { get; set; } = true;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Interceptor.RegisterEvent();
|
||||
Interceptor.RegisterBeforeSendEvent();
|
||||
|
||||
Company = await CompanyRepo.GetCompanyById(CompanyId);
|
||||
|
||||
var _ = await HistoryRepo.ErpInvoiceToCrmRpc(CompanyId, Company.HistorySync);
|
||||
|
||||
History = await HistoryRepo.FetchInvoiceList(CompanyId);
|
||||
|
||||
Working = false;
|
||||
|
|
|
@ -137,7 +137,6 @@ public partial class CrmCompanyViewPage : IDisposable
|
|||
if (CountryIsDk)
|
||||
CompanyVatAddress = PrepareVatAddress(Company);
|
||||
|
||||
|
||||
await FetchContacts(CompanyId);
|
||||
|
||||
// remove loading image
|
||||
|
|
|
@ -299,7 +299,6 @@
|
|||
</EditForm>
|
||||
<ConfirmationModal BodyMessage="@Prompt" OnOkClicked="ConfirmSaveCallback" @ref="ConfirmReportModal"/>
|
||||
|
||||
|
||||
@if (Working)
|
||||
{
|
||||
<WorkingThreeDots />
|
||||
|
|
|
@ -14,20 +14,15 @@
|
|||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using Blazored.Toast.Services;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Wonky.Client.HttpInterceptors;
|
||||
using Wonky.Client.HttpInterfaces;
|
||||
using Wonky.Client.HttpRepository;
|
||||
using Wonky.Client.Services;
|
||||
using Wonky.Client.Shared;
|
||||
using Wonky.Entity.DTO;
|
||||
using Wonky.Entity.Models;
|
||||
using Wonky.Entity.Views;
|
||||
|
||||
namespace Wonky.Client.Pages;
|
||||
|
@ -86,7 +81,6 @@ public partial class CrmReportNewPage : IDisposable
|
|||
Report.Figures.KmEvening = 0;
|
||||
Report.Figures.Distance = 0;
|
||||
Report.Figures.DistancePrivateMonth = 0;
|
||||
await GetKeyFigures();
|
||||
Working = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,14 +37,13 @@ public partial class InvoiceViewModal : IDisposable
|
|||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
Console.WriteLine($"CompanyId => {CompanyId}");
|
||||
Console.WriteLine($"InvoiceId => {InvoiceId}");
|
||||
Interceptor.RegisterEvent();
|
||||
Interceptor.RegisterBeforeSendEvent();
|
||||
|
||||
Console.WriteLine("Getting invoice");
|
||||
if (!string.IsNullOrWhiteSpace(InvoiceId))
|
||||
{
|
||||
Invoice = await HistoryRepo.FetchInvoice(CompanyId, InvoiceId);
|
||||
Console.WriteLine($"Invoice => {JsonSerializer.Serialize(Invoice)}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"appInfo": {
|
||||
"name": "Wonky Client",
|
||||
"version": "0.79.1",
|
||||
"version": "0.81.1",
|
||||
"rc": true,
|
||||
"sandBox": false,
|
||||
"image": "grumpy-coder.png"
|
||||
},
|
||||
"apiConfig": {
|
||||
"baseUrl": "https://dev.innotec.dk",
|
||||
"baseUrl": "https://zeta.innotec.dk",
|
||||
"catalog": "api/v2/catalog",
|
||||
"crmCustomers": "api/v2/crm/companies",
|
||||
"crmInventoryExt": "history/inventory",
|
||||
|
|
Loading…
Reference in a new issue