From 77fc922660f065c37302af517d34ee65a71686c8 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Mon, 24 Oct 2022 17:28:01 +0200 Subject: [PATCH] product inventory fix sync error --- .../ProductInventoryTableComponent.razor | 18 ------- .../ProductInventoryTableComponent.razor.cs | 26 ++-------- .../ICrmHistoryHttpRepository.cs | 8 ++-- .../CrmHistoryHttpRepository.cs | 36 ++++++++++---- .../Pages/CrmCompanyHistoryItemPage.razor | 37 -------------- .../Pages/CrmCompanyHistoryItemPage.razor.cs | 48 ------------------- .../Pages/CrmCompanyHistoryListPage.razor | 37 -------------- .../Pages/CrmCompanyHistoryListPage.razor.cs | 47 ------------------ .../Pages/CrmCompanyInventoryPage.razor | 27 +++++------ .../Pages/CrmCompanyInventoryPage.razor.cs | 19 ++++---- .../Shared/InventoryReorderModal.razor.cs | 2 +- Wonky.Client/Shared/MainLayout.razor | 2 +- .../Shared/ProductHistoryModal.razor.cs | 2 +- .../Shared/ProductPriceHistoryModal.razor.cs | 2 +- 14 files changed, 62 insertions(+), 249 deletions(-) delete mode 100644 Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor delete mode 100644 Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor.cs delete mode 100644 Wonky.Client/Pages/CrmCompanyHistoryListPage.razor delete mode 100644 Wonky.Client/Pages/CrmCompanyHistoryListPage.razor.cs diff --git a/Wonky.Client/Components/ProductInventoryTableComponent.razor b/Wonky.Client/Components/ProductInventoryTableComponent.razor index 5d2ccf09..b23694c4 100644 --- a/Wonky.Client/Components/ProductInventoryTableComponent.razor +++ b/Wonky.Client/Components/ProductInventoryTableComponent.razor @@ -18,24 +18,6 @@ @if (Inventory.Any()) { - @* - - - - - - - - - *@ @foreach (var product in Inventory) { diff --git a/Wonky.Client/Components/ProductInventoryTableComponent.razor.cs b/Wonky.Client/Components/ProductInventoryTableComponent.razor.cs index f5ff928a..e137a71d 100644 --- a/Wonky.Client/Components/ProductInventoryTableComponent.razor.cs +++ b/Wonky.Client/Components/ProductInventoryTableComponent.razor.cs @@ -29,7 +29,7 @@ public partial class ProductInventoryTableComponent [Parameter] public List 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(); - // } } \ No newline at end of file diff --git a/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs b/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs index 95d432b0..61e3ef80 100644 --- a/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs +++ b/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs @@ -20,8 +20,8 @@ namespace Wonky.Client.HttpInterfaces; public interface ICrmHistoryHttpRepository { - Task> FetchInventory(string companyId); - Task> FetchHistory(string companyId); - Task> FetchHistory(string companyId, string sku); - Task UpdateProductHistory(string companyId, string syncDate); + Task?> FetchInventory(string companyId); + Task?> FetchHistory(string companyId); + Task?> FetchHistory(string companyId, string sku); + Task RpcSyncErpToCrm(string companyId, string syncDate); } \ No newline at end of file diff --git a/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs b/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs index da8190cd..60cbd1e3 100644 --- a/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs +++ b/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs @@ -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 logger, - NavigationManager navigation, - IOptions configuration) + public CrmHistoryHttpRepository( + HttpClient client, ILogger logger, + NavigationManager navigation, IOptions configuration) { _client = client; _logger = logger; _navigation = navigation; _api = configuration.Value; } + /// + /// fetch inventory - summarized list of products + /// + /// + /// List of products public async Task> FetchInventory(string companyId) { var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmInventory}"); @@ -56,21 +60,35 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository : new List(); } - + /// + /// Fetch history for all products + /// + /// + /// List of products public async Task> FetchHistory(string companyId) { return await _client.GetFromJsonAsync>( $"{_api.CrmCustomers}/{companyId}/{_api.CrmProducts}"); } - + /// + /// Fetch history for single product + /// + /// + /// + /// list of products public async Task> FetchHistory(string companyId, string sku) { return await _client.GetFromJsonAsync>( $"{_api.CrmCustomers}/{companyId}/{_api.CrmProducts}/{sku}"); } - - public async Task UpdateProductHistory(string companyId, string syncDate = "2010-01-01") + /// + /// execute a remote procedure designed to update crm database from erp system based on a date string + /// + /// + /// + /// date string + public async Task RpcSyncErpToCrm(string companyId, string syncDate) { return await _client.GetStringAsync($"{_api.CrmCustomers}/{companyId}/{_api.CrmSync}/{syncDate}"); } diff --git a/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor b/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor deleted file mode 100644 index 233aee09..00000000 --- a/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor +++ /dev/null @@ -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}" - -
-
-
-
-

@_company.Name

-
-
- Produkter -
-
-
-
- -
-
diff --git a/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor.cs b/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor.cs deleted file mode 100644 index 5a19dd1e..00000000 --- a/Wonky.Client/Pages/CrmCompanyHistoryItemPage.razor.cs +++ /dev/null @@ -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 _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(); - } -} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor b/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor deleted file mode 100644 index 03fdb74a..00000000 --- a/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor +++ /dev/null @@ -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" - -
-
-
-
-

@_company.Name

-
-
- Kundekort -
-
-
-
- -
-
diff --git a/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor.cs b/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor.cs deleted file mode 100644 index ffea9edd..00000000 --- a/Wonky.Client/Pages/CrmCompanyHistoryListPage.razor.cs +++ /dev/null @@ -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 _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(); - } -} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor index e03fd8d4..535b8756 100644 --- a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor +++ b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor @@ -19,21 +19,20 @@ @using Microsoft.AspNetCore.Authorization @page "/companies/{CompanyId}/h/i" @attribute [Authorize(Roles = "Advisor")] -@if (!Loading) -{ -
-
-

@Company.Name

-
- +
+
+

@Company.Name

- -} + +
@if (Loading) { - + } - +else +{ + +} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs index 4a1f6c2c..69f6975a 100644 --- a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs +++ b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs @@ -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 Logger { get; set; } private CompanyDto Company { get; set; } = new(); - private List Inventory { get; set; } = new(); + private List? 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; diff --git a/Wonky.Client/Shared/InventoryReorderModal.razor.cs b/Wonky.Client/Shared/InventoryReorderModal.razor.cs index 1a96cfb2..1f1f55ce 100644 --- a/Wonky.Client/Shared/InventoryReorderModal.razor.cs +++ b/Wonky.Client/Shared/InventoryReorderModal.razor.cs @@ -31,7 +31,7 @@ public partial class InventoryReorderModal [Parameter] public SalesItemView SalesItem { get; set; } = new(); [Inject] public ICrmHistoryHttpRepository CrmHistoryRepo { get; set; } [Parameter] public EventCallback OnSelected { get; set; } - private List History { get; set; } = new(); + private List? History { get; set; } = new(); private DraftItem SelectedItem { get; set; } = new(); private string ProductName { get; set; } = ""; private string _modalDisplay = ""; diff --git a/Wonky.Client/Shared/MainLayout.razor b/Wonky.Client/Shared/MainLayout.razor index 7115255a..bb572576 100644 --- a/Wonky.Client/Shared/MainLayout.razor +++ b/Wonky.Client/Shared/MainLayout.razor @@ -32,6 +32,6 @@
@Body
- +
diff --git a/Wonky.Client/Shared/ProductHistoryModal.razor.cs b/Wonky.Client/Shared/ProductHistoryModal.razor.cs index 2351b56f..e4bf2793 100644 --- a/Wonky.Client/Shared/ProductHistoryModal.razor.cs +++ b/Wonky.Client/Shared/ProductHistoryModal.razor.cs @@ -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 History { get; set; } + private List? History { get; set; } private string ProductName { get; set; } = ""; private string _modalDisplay = ""; private bool _showBackdrop; diff --git a/Wonky.Client/Shared/ProductPriceHistoryModal.razor.cs b/Wonky.Client/Shared/ProductPriceHistoryModal.razor.cs index a3a3b596..6c8b4059 100644 --- a/Wonky.Client/Shared/ProductPriceHistoryModal.razor.cs +++ b/Wonky.Client/Shared/ProductPriceHistoryModal.razor.cs @@ -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 History { get; set; } + private List? History { get; set; } private string ProductName { get; set; } = ""; private string _modalDisplay = ""; private bool _showBackdrop;
- Produkt - - Varenr. - - Antal - - Historik -