product inventory fix sync error

This commit is contained in:
Frede Hundewadt 2022-10-24 17:28:01 +02:00
parent fb101ceaf8
commit 77fc922660
14 changed files with 62 additions and 249 deletions

View file

@ -18,24 +18,6 @@
@if (Inventory.Any())
{
<table class="table table-striped">
@*
<thead>
<tr>
<th scope="col">
Produkt
</th>
<th scope="col">
Varenr.
</th>
<th scope="col" class="text-center">
Antal
</th>
<th scope="col" class="text-center">
Historik
</th>
</tr>
</thead>
*@
<tbody>
@foreach (var product in Inventory)
{

View file

@ -29,7 +29,7 @@ public partial class ProductInventoryTableComponent
[Parameter] public List<ProductInventoryView> Inventory { get; set; } = new();
[Parameter] public string CompanyId { get; set; } = "";
[Inject] public ICatalogHttpRepository Catalog { get; set; }
// private variables
private SalesItemView SalesItem { get; set; } = new();
private string Price { get; set; } = "0";
private string Quantity { get; set; } = "1";
@ -40,35 +40,15 @@ public partial class ProductInventoryTableComponent
private async Task CallShowReorderModal(string sku)
{
// fetch item from http repo
SalesItem = await Catalog.GetSalesItemSku(sku);
ReorderModal.Show();
}
private async Task OnSelectedItem(DraftItem draftItem)
{
// add item to order draft
DraftStateProvider.Draft.Items.Add(draftItem);
await DraftStateProvider.SaveChangesAsync();
}
// private async Task AddItem(SalesItemView salesItem)
// {
// // create a new cart item
// var item = new DraftItem
// {
// Item = salesItem,
// Quantity = Convert.ToInt32(Quantity),
// Price = Convert.ToDecimal(Price, CultureInfo.InvariantCulture),
// Discount = Convert.ToDecimal(Discount, CultureInfo.InvariantCulture),
// Sas = Sas
// };
// // reset internals to initial state
// Sas = false;
// Quantity = "1";
// Price = "0";
// Discount = "0";
// // add it to the cart
// DraftStateProvider.Draft.Items.Add(item);
// // save the item using the CartStateProvider's save method
// await DraftStateProvider.SaveChangesAsync();
// }
}

View file

@ -20,8 +20,8 @@ namespace Wonky.Client.HttpInterfaces;
public interface ICrmHistoryHttpRepository
{
Task<List<ProductInventoryView>> FetchInventory(string companyId);
Task<List<ProductHistoryView>> FetchHistory(string companyId);
Task<List<ProductHistoryView>> FetchHistory(string companyId, string sku);
Task<string> UpdateProductHistory(string companyId, string syncDate);
Task<List<ProductInventoryView>?> FetchInventory(string companyId);
Task<List<ProductHistoryView>?> FetchHistory(string companyId);
Task<List<ProductHistoryView>?> FetchHistory(string companyId, string sku);
Task<string> RpcSyncErpToCrm(string companyId, string syncDate);
}

View file

@ -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
};
@ -37,16 +37,20 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
private readonly HttpClient _client;
private readonly ApiConfig _api;
public CrmHistoryHttpRepository(HttpClient client,
ILogger<CrmHistoryHttpRepository> logger,
NavigationManager navigation,
IOptions<ApiConfig> configuration)
public CrmHistoryHttpRepository(
HttpClient client, ILogger<CrmHistoryHttpRepository> logger,
NavigationManager navigation, IOptions<ApiConfig> configuration)
{
_client = client;
_logger = logger;
_navigation = navigation;
_api = configuration.Value;
}
/// <summary>
/// fetch inventory - summarized list of products
/// </summary>
/// <param name="companyId"></param>
/// <returns>List of products</returns>
public async Task<List<ProductInventoryView>> FetchInventory(string companyId)
{
var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmInventory}");
@ -56,21 +60,35 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository
: new List<ProductInventoryView>();
}
/// <summary>
/// Fetch history for all products
/// </summary>
/// <param name="companyId"></param>
/// <returns>List of products</returns>
public async Task<List<ProductHistoryView>> FetchHistory(string companyId)
{
return await _client.GetFromJsonAsync<List<ProductHistoryView>>(
$"{_api.CrmCustomers}/{companyId}/{_api.CrmProducts}");
}
/// <summary>
/// Fetch history for single product
/// </summary>
/// <param name="companyId"></param>
/// <param name="sku"></param>
/// <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.CrmProducts}/{sku}");
}
public async Task<string> UpdateProductHistory(string companyId, string syncDate = "2010-01-01")
/// <summary>
/// execute a remote procedure designed to update crm database from erp system based on a date string
/// </summary>
/// <param name="companyId"></param>
/// <param name="syncDate"></param>
/// <returns>date string</returns>
public async Task<string> RpcSyncErpToCrm(string companyId, string syncDate)
{
return await _client.GetStringAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmSync}/{syncDate}");
}

View file

@ -1,37 +0,0 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@using Wonky.Client.Components
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Advisor")]
@page "/companies/{CompanyId}/h/p/{Sku}"
<div class="card">
<div class="card-header">
<div class="row">
<div class="col">
<h3>@_company.Name</h3>
</div>
<div class="col align-content-end">
<a class="btn btn-primary" href="/companies/@_company.CompanyId/h/i">Produkter</a>
</div>
</div>
</div>
<div class="card-body">
<ProductLineTableComponent ProductHistory="_lines"></ProductLineTableComponent>
</div>
</div>

View file

@ -1,48 +0,0 @@
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
public partial class CrmCompanyHistoryItemPage : IDisposable
{
[Parameter] public string Sku { get; set; } = "";
[Parameter] public string CompanyId { get; set; } = "";
[Inject] public HttpInterceptorService _interceptor { get; set; }
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
[Inject] public ICrmCompanyHttpRepository _companyRepo { get; set; }
private List<ProductHistoryView> _lines { get; set; } = new();
private CompanyDto _company { get; set; } = new();
protected override async Task OnInitializedAsync()
{
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
_company = await _companyRepo.GetCompanyById(CompanyId);
_lines = await CrmHistoryRepo.FetchHistory(CompanyId, Sku);
_lines = _lines.OrderByDescending(x => x.DeliveryDate).ToList();
}
public void Dispose()
{
_interceptor.DisposeEvent();
}
}

View file

@ -1,37 +0,0 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@using Wonky.Client.Components
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Advisor")]
@page "/companies/{CompanyId}/h/p"
<div class="card">
<div class="card-header">
<div class="row">
<div class="col">
<h3>@_company.Name</h3>
</div>
<div class="col align-content-end">
<a class="btn btn-primary" href="/companies/@CompanyId">Kundekort</a>
</div>
</div>
</div>
<div class="card-body">
<ProductLineTableComponent ProductHistory="_lines"></ProductLineTableComponent>
</div>
</div>

View file

@ -1,47 +0,0 @@
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
public partial class CrmCompanyHistoryListPage : IDisposable
{
[Parameter] public string CompanyId { get; set; } = "";
[Inject] public HttpInterceptorService _interceptor { get; set; }
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
[Inject] public ICrmCompanyHttpRepository _companyRepo { get; set; }
private List<ProductHistoryView> _lines { get; set; } = new();
private CompanyDto _company { get; set; } = new();
protected override async Task OnInitializedAsync()
{
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
_company = await _companyRepo.GetCompanyById(CompanyId);
_lines = await CrmHistoryRepo.FetchHistory(CompanyId);
}
public void Dispose()
{
_interceptor.DisposeEvent();
}
}

View file

@ -19,21 +19,20 @@
@using Microsoft.AspNetCore.Authorization
@page "/companies/{CompanyId}/h/i"
@attribute [Authorize(Roles = "Advisor")]
@if (!Loading)
{
<div class="row">
<div class="col-6">
<h3>@Company.Name</h3>
</div>
<div class="col-6 align-content-end">
<a class="btn btn-primary" href="/companies/@Company.CompanyId">Kundekort</a>
<a class="btn btn-primary" href="/companies/@Company.CompanyId/activities/new">Besøg</a>
</div>
<div class="row pt-2 pb-2 rounded-2 bg-dark text-white">
<div class="col-6">
<h3>@Company.Name</h3>
</div>
<ProductInventoryTableComponent CompanyId="@CompanyId" Inventory="Inventory" />
}
<div class="col-6 align-content-end">
<a class="btn btn-primary" href="/companies/@Company.CompanyId">Kundekort</a>
<a class="btn btn-primary" href="/companies/@Company.CompanyId/activities/new">Besøg</a>
</div>
</div>
@if (Loading)
{
<LoaderThreeDots Loading="Loading" />
<LoaderThreeDots Loading="Loading"/>
}
else
{
<ProductInventoryTableComponent CompanyId="@CompanyId" Inventory="Inventory"/>
}

View file

@ -14,6 +14,7 @@
//
using System.Text.Json;
using Blazored.Toast.Services;
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
@ -31,25 +32,27 @@ public partial class CrmCompanyInventoryPage : IDisposable
[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; } = new();
private List<ProductInventoryView>? Inventory { get; set; } = new();
private bool Loading { get; set; } = true;
protected override async Task OnParametersSetAsync()
{
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
Company = await CompanyRepo.GetCompanyById(CompanyId);
}
protected override async Task OnInitializedAsync()
{
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
Company = await CompanyRepo.GetCompanyById(CompanyId);
await RefreshHistory();
}
private async Task RefreshHistory()
{
Toaster.ShowInfo("Varekøb opdateres ....", "Vent venligst");
await CrmHistoryRepo.RpcSyncErpToCrm(CompanyId, Company.HistorySync);
Inventory = await CrmHistoryRepo.FetchInventory(CompanyId);
Inventory = Inventory.OrderBy(x => x.Description).ToList();
Loading = false;

View file

@ -31,7 +31,7 @@ public partial class InventoryReorderModal
[Parameter] public SalesItemView SalesItem { get; set; } = new();
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
[Parameter] public EventCallback<DraftItem> OnSelected { get; set; }
private List<ProductHistoryView> History { get; set; } = new();
private List<ProductHistoryView>? History { get; set; } = new();
private DraftItem SelectedItem { get; set; } = new();
private string ProductName { get; set; } = "";
private string _modalDisplay = "";

View file

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

View file

@ -30,7 +30,7 @@ public partial class ProductHistoryModal
[Parameter] public string CompanyId { get; set; } = "";
[Parameter] public string ItemSku { get; set; } = "";
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
private List<ProductHistoryView> History { get; set; }
private List<ProductHistoryView>? History { get; set; }
private string ProductName { get; set; } = "";
private string _modalDisplay = "";
private bool _showBackdrop;

View file

@ -30,7 +30,7 @@ public partial class ProductPriceHistoryModal
[Parameter] public string CompanyId { get; set; } = "";
[Parameter] public string Sku { get; set; } = "";
[Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; }
private List<ProductHistoryView> History { get; set; }
private List<ProductHistoryView>? History { get; set; }
private string ProductName { get; set; } = "";
private string _modalDisplay = "";
private bool _showBackdrop;