diff --git a/Wonky.Client/Components/AdvisorLandingComponent.razor.cs b/Wonky.Client/Components/AdvisorLandingComponent.razor.cs index 13952e31..10bc7766 100644 --- a/Wonky.Client/Components/AdvisorLandingComponent.razor.cs +++ b/Wonky.Client/Components/AdvisorLandingComponent.razor.cs @@ -37,7 +37,7 @@ public partial class AdvisorLandingComponent [Inject] public UserPreferenceService PreferenceService { get; set; } [Inject] public ICabinetDrawerService CabinetDrawerService { get; set; } [Inject] public IUserInfoService UserInfo { get; set; } - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } // ############################################################## diff --git a/Wonky.Client/HttpRepository/CountryCatalogRepository.cs b/Wonky.Client/HttpRepository/CountryPriceCatalogRepository.cs similarity index 86% rename from Wonky.Client/HttpRepository/CountryCatalogRepository.cs rename to Wonky.Client/HttpRepository/CountryPriceCatalogRepository.cs index e1e7346e..241fb6a2 100644 --- a/Wonky.Client/HttpRepository/CountryCatalogRepository.cs +++ b/Wonky.Client/HttpRepository/CountryPriceCatalogRepository.cs @@ -26,7 +26,7 @@ using Wonky.Entity.Views; namespace Wonky.Client.HttpRepository; -public class CountryCatalogRepository : ICountryCatalogRepository +public class CountryPriceCatalogRepository : ICountryPriceCatalogRepository { private readonly JsonSerializerOptions _options = new JsonSerializerOptions { @@ -34,12 +34,12 @@ public class CountryCatalogRepository : ICountryCatalogRepository }; private readonly NavigationManager _navigation; - private ILogger _logger; + private ILogger _logger; private readonly HttpClient _client; private readonly ApiConfig _api; - public CountryCatalogRepository(HttpClient client, - ILogger logger, + public CountryPriceCatalogRepository(HttpClient client, + ILogger logger, NavigationManager navigation, IOptions configuration) { _client = client; @@ -57,7 +57,7 @@ public class CountryCatalogRepository : ICountryCatalogRepository public async Task> GetPriceList(string countryCode) { var result = await _client.GetFromJsonAsync>( - $"{_api.Catalog}/{countryCode}", _options); + $"{_api.CountryPriceCatalog}/{countryCode}", _options); return result ?? new List(); } @@ -80,7 +80,7 @@ public class CountryCatalogRepository : ICountryCatalogRepository ["selectGroup"] = pager.SelectGroup == "0" ? "" : pager.SelectGroup }; - var endpoint = WebUtils.QueryHelper($"{_api.Catalog}/{countryCode}/page", queryDictionary); + var endpoint = WebUtils.QueryHelper($"{_api.CountryPriceCatalog}/{countryCode}/page", queryDictionary); var response = await _client.GetAsync(endpoint); if (!response.IsSuccessStatusCode) @@ -111,7 +111,7 @@ public class CountryCatalogRepository : ICountryCatalogRepository /// public async Task GetSalesItemSku(string countryCode, string sku) { - var salesItem = await _client.GetFromJsonAsync($"{_api.Catalog}/{countryCode}/sku/{sku}"); + var salesItem = await _client.GetFromJsonAsync($"{_api.CountryPriceCatalog}/{countryCode}/sku/{sku}"); return salesItem ?? new SalesItemView(); } @@ -124,7 +124,7 @@ public class CountryCatalogRepository : ICountryCatalogRepository public async Task GetProductDetailView(string salesItemId) { var detailView = await _client - .GetFromJsonAsync($"{_api.Catalog}/{salesItemId}"); + .GetFromJsonAsync($"{_api.CountryPriceCatalog}/{salesItemId}"); return detailView ?? new ProductDetailView(); } @@ -137,7 +137,7 @@ public class CountryCatalogRepository : ICountryCatalogRepository public async Task GetVariantDetailView(string variantId) { var detailView = await _client - .GetFromJsonAsync($"{_api.Catalog}/variant/{variantId}"); + .GetFromJsonAsync($"{_api.CountryPriceCatalog}/variant/{variantId}"); return detailView ?? new ProductDetailView(); } } \ No newline at end of file diff --git a/Wonky.Client/HttpRepository/CountryProductCatalogRepository.cs b/Wonky.Client/HttpRepository/CountryProductCatalogRepository.cs new file mode 100644 index 00000000..1c2dcbc0 --- /dev/null +++ b/Wonky.Client/HttpRepository/CountryProductCatalogRepository.cs @@ -0,0 +1,143 @@ +// 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 System.Net.Http.Json; +using System.Text; +using System.Text.Json; +using Wonky.Client.Features; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Options; +using Wonky.Client.Helpers; +using Wonky.Entity.Configuration; +using Wonky.Entity.Requests; +using Wonky.Entity.Views; + +namespace Wonky.Client.HttpRepository; + +public class CountryProductCatalogRepository : ICountryProductCatalogRepository +{ + private readonly JsonSerializerOptions _options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }; + + private readonly NavigationManager _navigation; + private ILogger _logger; + private readonly HttpClient _client; + private readonly ApiConfig _api; + + public CountryProductCatalogRepository(HttpClient client, + ILogger logger, + NavigationManager navigation, IOptions configuration) + { + _client = client; + _logger = logger; + _navigation = navigation; + _api = configuration.Value; + } + + + /// + /// Complete catalog for print country + /// + /// + /// + public async Task> GetProductList(string countryCode) + { + var result = await _client.GetFromJsonAsync>( + $"{_api:CountryProductCatalog}/{countryCode}", _options); + return result ?? new List(); + } + + + /// + /// Get a paged sales item list + /// + /// + /// + /// + public async Task> GetProductItemsPaged(string countryCode, CatalogPager pager) + { + var queryDictionary = new Dictionary + { + ["pageNumber"] = pager.PageNumber.ToString(), + ["pageSize"] = pager.PageSize.ToString(), + ["orderBy"] = pager.OrderBy, + ["searchColumn"] = pager.SearchColumn, + ["searchTerm"] = pager.SearchTerm, + ["selectGroup"] = pager.SelectGroup == "0" ? "" : pager.SelectGroup + }; + + var endpoint = WebUtils.QueryHelper($"{_api:CountryProductCatalog}/{countryCode}/page", queryDictionary); + var response = await _client.GetAsync(endpoint); + + if (!response.IsSuccessStatusCode) + { + return new PagingResponse + { + Items = new List(), + MetaData = new MetaData() + }; + } + var content = await response.Content.ReadAsStringAsync(); + + var pagingResponse = new PagingResponse + { + Items = JsonSerializer.Deserialize>(content, _options), + MetaData = JsonSerializer.Deserialize( + response.Headers.GetValues("X-Pagination").First(), _options) + }; + return pagingResponse; + } + + + /// + /// Overload Get sales item by sku and country code + /// + /// + /// + /// + public async Task GetProductItemSku(string countryCode, string sku) + { + var salesItem = await _client.GetFromJsonAsync($"{_api:CountryProductCatalog}/{countryCode}/sku/{sku}"); + return salesItem ?? new ProductItemView(); + } + + + /// + /// Get sales item by id + /// + /// + /// + public async Task GetProductDetailView(string salesItemId) + { + var detailView = await _client + .GetFromJsonAsync($"{_api:CountryProductCatalog}/{salesItemId}"); + return detailView ?? new ProductDetailView(); + } + + + /// + /// Get sales item by variant id + /// + /// + /// + public async Task GetVariantDetailView(string variantId) + { + var detailView = await _client + .GetFromJsonAsync($"{_api:CountryProductCatalog}/variant/{variantId}"); + return detailView ?? new ProductDetailView(); + } +} \ No newline at end of file diff --git a/Wonky.Client/HttpRepository/ExternalProductRepository.cs b/Wonky.Client/HttpRepository/ExternalProductRepository.cs index abf67546..841c7d21 100644 --- a/Wonky.Client/HttpRepository/ExternalProductRepository.cs +++ b/Wonky.Client/HttpRepository/ExternalProductRepository.cs @@ -35,4 +35,6 @@ public class ExternalProductRepository : IExternalProductRepository .GetFromJsonAsync>(_api.PublicProducts, _options); return result ?? new List(); } + + } \ No newline at end of file diff --git a/Wonky.Client/HttpRepository/ICountryCatalogRepository.cs b/Wonky.Client/HttpRepository/ICountryPriceCatalogRepository.cs similarity index 95% rename from Wonky.Client/HttpRepository/ICountryCatalogRepository.cs rename to Wonky.Client/HttpRepository/ICountryPriceCatalogRepository.cs index 366ca6b3..af9a2170 100644 --- a/Wonky.Client/HttpRepository/ICountryCatalogRepository.cs +++ b/Wonky.Client/HttpRepository/ICountryPriceCatalogRepository.cs @@ -20,9 +20,9 @@ using Wonky.Entity.Views; namespace Wonky.Client.HttpRepository; /// -/// Interface Catalog Http repository +/// Interface CountryPriceCatalog Http repository /// -public interface ICountryCatalogRepository +public interface ICountryPriceCatalogRepository { /// /// Complete catalog for print country diff --git a/Wonky.Client/HttpRepository/ICountryProductCatalogRepository.cs b/Wonky.Client/HttpRepository/ICountryProductCatalogRepository.cs new file mode 100644 index 00000000..b58e465c --- /dev/null +++ b/Wonky.Client/HttpRepository/ICountryProductCatalogRepository.cs @@ -0,0 +1,67 @@ +// 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.Features; +using Wonky.Entity.Requests; +using Wonky.Entity.Views; + +namespace Wonky.Client.HttpRepository; + +/// +/// Interface CountryPriceCatalog Http repository +/// +public interface ICountryProductCatalogRepository +{ + /// + /// Complete catalog for print country + /// + /// + /// + Task> GetProductList(string countryCode); + + + /// + /// Get a paged sales item list + /// + /// + /// + /// + Task> GetProductItemsPaged(string countryCode, CatalogPager pager); + + + /// + /// Overload Get sales item by sku and country code + /// + /// + /// + /// + Task GetProductItemSku(string countryCode, string sku); + + + /// + /// Get sales item by id + /// + /// + /// + Task GetProductDetailView(string salesItemId); + + + /// + /// Get sales item by variant id + /// + /// + /// + Task GetVariantDetailView(string variantId); +} \ No newline at end of file diff --git a/Wonky.Client/Local.Services/CabinetDrawerService.cs b/Wonky.Client/Local.Services/CabinetDrawerService.cs index ef101ce1..c9dac0b8 100644 --- a/Wonky.Client/Local.Services/CabinetDrawerService.cs +++ b/Wonky.Client/Local.Services/CabinetDrawerService.cs @@ -17,19 +17,19 @@ public class CabinetDrawerService : ICabinetDrawerService private readonly IAdvisorActivityRepository _activityRepo; private readonly IAdvisorCustomerRepository _customerRepo; private readonly IAdvisorCustomerHistoryRepository _historyRepo; - private readonly ICountryCatalogRepository _catalogRepo; + private readonly ICountryPriceCatalogRepository _priceCatalogRepo; public CabinetDrawerService( ILogger logger, ILocalStorageService asyncStorageService, - ICountryCatalogRepository catalogRepo, + ICountryPriceCatalogRepository priceCatalogRepo, IAdvisorCustomerHistoryRepository historyRepo, IAdvisorCustomerRepository customerRepo, IAdvisorActivityRepository activityRepo) { _logger = logger; _asyncStorageService = asyncStorageService; - _catalogRepo = catalogRepo; + _priceCatalogRepo = priceCatalogRepo; _historyRepo = historyRepo; _customerRepo = customerRepo; _activityRepo = activityRepo; @@ -60,7 +60,7 @@ public class CabinetDrawerService : ICabinetDrawerService if (drawer == null) force = true; if (!force) return drawer ?? new CatalogDrawer(); - var result = await _catalogRepo.GetPriceList(countryCode); + var result = await _priceCatalogRepo.GetPriceList(countryCode); drawer = new CatalogDrawer { LastDateModified = DateTime.Today, diff --git a/Wonky.Client/Models/CatalogDrawer.cs b/Wonky.Client/Models/CatalogDrawer.cs index 4fa637b4..c8d6f40e 100644 --- a/Wonky.Client/Models/CatalogDrawer.cs +++ b/Wonky.Client/Models/CatalogDrawer.cs @@ -4,7 +4,7 @@ namespace Wonky.Client.Models; public class CatalogDrawer { - public const string Label = "Catalog"; + public const string Label = "CountryPriceCatalog"; public DateTime LastDateModified { get; set; } public List Content { get; set; } = new(); } \ No newline at end of file diff --git a/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor b/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor new file mode 100644 index 00000000..0f29c2ba --- /dev/null +++ b/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor @@ -0,0 +1,66 @@ +@* 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] +*@ + + +@if (_showBackdrop) +{ + +} \ No newline at end of file diff --git a/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor.cs b/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor.cs new file mode 100644 index 00000000..294667ec --- /dev/null +++ b/Wonky.Client/OverlayB2B/B2BGetOrderQuantityOverlay.razor.cs @@ -0,0 +1,77 @@ +// 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.HttpRepository; +using Wonky.Client.Models; +using Wonky.Entity.Views; + +#pragma warning disable CS8618 + +namespace Wonky.Client.OverlayB2B; + +public partial class B2BGetOrderQuantityOverlay +{ + // ############################################################## + [Inject] public IB2BRepository HistoryRepo { get; set; } + + // ############################################################## + [Parameter] public string ProductName { get; set; } = ""; + [Parameter] public ItemSelect SelectedItem { get; set; } = new(); + [Parameter] public EventCallback OnSelected { get; set; } + [Parameter] public List ProductHistory { get; set; } = new(); + // ############################################################## + + private string _modalDisplay = ""; + private bool _showBackdrop; + private int _qty = 1; + private ItemSelect _selectedItem = new(); + + + protected override void OnParametersSet() + { + _selectedItem = SelectedItem; + if (!string.IsNullOrWhiteSpace(_selectedItem.Quantity)) + { + _qty = int.Parse(_selectedItem.Quantity); + } + } + + + private async Task SubmitItem() + { + Console.WriteLine($"_qty => {_qty}"); + _selectedItem.Quantity = $"{_qty}"; + await OnSelected.InvokeAsync(_selectedItem); + Hide(); + } + + + public void Show() + { + _modalDisplay = "block;"; + _showBackdrop = true; + // StateHasChanged(); + } + + + private void Hide() + { + _modalDisplay = "none;"; + _showBackdrop = false; + // StateHasChanged(); + } +} \ No newline at end of file diff --git a/Wonky.Client/OverlayB2B/B2BProductPriceHistoryOverlay.razor.cs b/Wonky.Client/OverlayB2B/B2BProductPriceHistoryOverlay.razor.cs index 085db820..76bbd3bc 100644 --- a/Wonky.Client/OverlayB2B/B2BProductPriceHistoryOverlay.razor.cs +++ b/Wonky.Client/OverlayB2B/B2BProductPriceHistoryOverlay.razor.cs @@ -32,7 +32,7 @@ public partial class B2BProductPriceHistoryOverlay [Parameter] public string Sku { get; set; } = ""; // ############################################################## - private List? ProductHistory { get; set; } + private List ProductHistory { get; set; } = new(); private string ProductName { get; set; } = ""; private string _modalDisplay = ""; private bool _showBackdrop; @@ -43,7 +43,7 @@ public partial class B2BProductPriceHistoryOverlay return; ProductHistory = await HistoryRepo.GetCustomerProductHistory(CompanyId, Sku); - if (ProductHistory.Any()) + if (ProductHistory.Count > 0) { ProductName = ProductHistory[0].Description; } diff --git a/Wonky.Client/OverlayCustomer/CustomerInventoryListOverlay.razor.cs b/Wonky.Client/OverlayCustomer/CustomerInventoryListOverlay.razor.cs index 8ff39e66..041b8be9 100644 --- a/Wonky.Client/OverlayCustomer/CustomerInventoryListOverlay.razor.cs +++ b/Wonky.Client/OverlayCustomer/CustomerInventoryListOverlay.razor.cs @@ -30,7 +30,7 @@ public partial class CustomerInventoryListOverlay : IDisposable */ [Inject] public ILogger Logger { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } /* * Parameters */ @@ -81,7 +81,7 @@ public partial class CustomerInventoryListOverlay : IDisposable /// private async Task OnReorderCallback(string sku) { - SalesItem = await CatalogRepo.GetSalesItemSku(CountryCode.ToLower(), sku); + SalesItem = await PriceCatalogRepo.GetSalesItemSku(CountryCode.ToLower(), sku); ReorderOverlay.Show(); } diff --git a/Wonky.Client/OverlayOffice/OfficeCustomerOrderInventoryListOverlay.razor.cs b/Wonky.Client/OverlayOffice/OfficeCustomerOrderInventoryListOverlay.razor.cs index 0a12c58a..0ced4cc1 100644 --- a/Wonky.Client/OverlayOffice/OfficeCustomerOrderInventoryListOverlay.razor.cs +++ b/Wonky.Client/OverlayOffice/OfficeCustomerOrderInventoryListOverlay.razor.cs @@ -28,7 +28,7 @@ public partial class OfficeCustomerOrderInventoryListOverlay : IDisposable { // ############################################################## [Inject] public HttpInterceptorService Interceptor { get; set; } - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } [Inject] public ILogger Logger { get; set; } // ############################################################## @@ -59,7 +59,7 @@ public partial class OfficeCustomerOrderInventoryListOverlay : IDisposable private async Task OnReorderCallback(string sku) { - SalesItem = await CatalogRepo.GetSalesItemSku(Company.CountryCode.ToLower(), sku); + SalesItem = await PriceCatalogRepo.GetSalesItemSku(Company.CountryCode.ToLower(), sku); ReorderOverlay.Show(); } diff --git a/Wonky.Client/OverlayOrderCreate/CatalogPagedOverlay.razor.cs b/Wonky.Client/OverlayOrderCreate/CatalogPagedOverlay.razor.cs index a8fe0a12..bc1c8210 100644 --- a/Wonky.Client/OverlayOrderCreate/CatalogPagedOverlay.razor.cs +++ b/Wonky.Client/OverlayOrderCreate/CatalogPagedOverlay.razor.cs @@ -30,7 +30,7 @@ namespace Wonky.Client.OverlayOrderCreate; public partial class CatalogPagedOverlay : IDisposable { // ############################################################## - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public UserPreferenceService PreferenceService { get; set; } [Inject] public ILogger Logger { get; set; } @@ -64,7 +64,7 @@ public partial class CatalogPagedOverlay : IDisposable private async Task GetSalesItems() { - var pagingResponse = await CatalogRepo.GetSalesItemsPaged(CountryCode, _pager); + var pagingResponse = await PriceCatalogRepo.GetSalesItemsPaged(CountryCode, _pager); Items = pagingResponse.Items!; PageData = pagingResponse.MetaData; Logger.LogDebug("PriceCatalogOverlay => Items <= {}", JsonSerializer.Serialize(Items)); diff --git a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs index d6fdb49b..a7dc56a2 100644 --- a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs +++ b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs @@ -44,7 +44,7 @@ public partial class AdvisorActivityCreatePage : IDisposable [Inject] public IToastService Toaster { get; set; } [Inject] public NavigationManager Navigator { get; set; } [Inject] public ILocalStorageService Storage { get; set; } - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } [Inject] public IAdvisorCustomerRepository CompanyRepo { get; set; } [Inject] public IAdvisorActivityRepository ActivityRepo { get; set; } [Inject] public IAdvisorSalesReportRepository ReportRepo { get; set; } @@ -325,7 +325,7 @@ public partial class AdvisorActivityCreatePage : IDisposable { return; } - _selectedItem = await CatalogRepo.GetSalesItemSku(_company.CountryCode, selectedItem.ItemNo); + _selectedItem = await PriceCatalogRepo.GetSalesItemSku(_company.CountryCode, selectedItem.ItemNo); ShowItem = true; Price = selectedItem.Rate; Quantity = selectedItem.Quantity; diff --git a/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs index 2bb5bd29..5ba82ab4 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs @@ -44,7 +44,7 @@ public partial class AdvisorCustomerInventoryListPage : IDisposable [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public IToastService Toaster { get; set; } [Inject] public ILocalStorageService Storage { get; set; } - [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalogRepo { get; set; } [Inject] public ICabinetDrawerService DrawerService { get; set; } /* * Parameters @@ -80,7 +80,7 @@ public partial class AdvisorCustomerInventoryListPage : IDisposable private async Task OnReorderCallback(string sku) { // fetch item from http repo - SalesItem = await CatalogRepo.GetSalesItemSku(Company.CountryCode.ToLower(), sku); + SalesItem = await PriceCatalogRepo.GetSalesItemSku(Company.CountryCode.ToLower(), sku); ReorderOverlay.Show(); } diff --git a/Wonky.Client/Pages/BusinessCustomerLandingPage.razor b/Wonky.Client/Pages/BusinessCustomerLandingPage.razor index ce173163..a7979973 100644 --- a/Wonky.Client/Pages/BusinessCustomerLandingPage.razor +++ b/Wonky.Client/Pages/BusinessCustomerLandingPage.razor @@ -110,7 +110,6 @@ Sidste køb Forbrug - @@ -121,17 +120,12 @@ @product.Quantity - - - Historik - -
@@ -141,7 +135,11 @@ } - + @* *@ + } else { diff --git a/Wonky.Client/Pages/BusinessCustomerLandingPage.razor.cs b/Wonky.Client/Pages/BusinessCustomerLandingPage.razor.cs index 0640faa5..eaf48d51 100644 --- a/Wonky.Client/Pages/BusinessCustomerLandingPage.razor.cs +++ b/Wonky.Client/Pages/BusinessCustomerLandingPage.razor.cs @@ -19,14 +19,11 @@ public partial class BusinessCustomerLandingPage : IDisposable // ############################################################## [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public IB2BRepository B2BRepo { get; set; } - - [Inject] - public ICountryCatalogRepository Catalog { get; set; } + [Inject] public ICountryProductCatalogRepository ProductCatalog { get; set; } [Inject] private IOptions Config { get; set; } // ############################################################## [CascadingParameter] private DraftStateProvider DraftProvider { get; set; } = new(); - [Parameter] public string CountryCode { get; set; } = ""; [Parameter] public string CompanyId { get; set; } = ""; @@ -39,8 +36,10 @@ public partial class BusinessCustomerLandingPage : IDisposable private B2BProductPriceHistoryOverlay PriceHistoryOverlay { get; set; } private string _price = "0"; private string _quantity = "1"; + private string _productName = ""; private ItemSelect _selectedItem = new(); private string _sku = ""; + private B2BGetOrderQuantityOverlay GetQuantity { get; set; } protected override async Task OnInitializedAsync() @@ -51,41 +50,85 @@ public partial class BusinessCustomerLandingPage : IDisposable _businessInfo = await B2BRepo.GetBusinessInfo(CompanyId); _advisorInfo = await B2BRepo.GetAdvisorInfo(CompanyId); _productInventory = await B2BRepo.GetCustomerInventory(CompanyId); - if (_productInventory.Any()) + if (_productInventory.Count > 0) { _productInventory = _productInventory .OrderByDescending(x => x.Quantity) .ToList(); } + + DraftProvider.Draft.DraftId = CompanyId; + await DraftProvider.SaveChangesAsync(); } - private async Task AddItemToOrder(string sku) + private async Task RemoveItem(string sku) { - var item = await Catalog.GetSalesItemSku(CountryCode, sku); - var history = await B2BRepo.GetCustomerProductHistory(CompanyId, sku); - var line = history - .OrderByDescending(x => x.DeliveryDate) - .Where(x => x.Price != 0).Take(1).ToList()[0]; - DraftProvider.Draft.DraftId = CompanyId; - DraftProvider.Draft.Items.Add( - new DraftItem() + var draftItem = DraftProvider.Draft.Items.Where(x => x.Item.Sku == sku).ToList()[0]; + DraftProvider.Draft.Items.Remove(draftItem); + await DraftProvider.SaveChangesAsync(); + } + + + private async Task ShowAddQuantity(string sku) + { + _productHistory = await B2BRepo.GetCustomerProductHistory(CompanyId, sku); + _productName = _productHistory[0].Description; + _selectedItem = new ItemSelect + { + ItemNo = sku, + Quantity = $"{_productHistory[0].Quantity}", + Rate = $"{_productHistory[0].Price}", + }; + GetQuantity.Show(); + } + + + private async Task AddItemToOrder(ItemSelect selectedItem) + { + var draftItem = DraftProvider.Draft.Items.FirstOrDefault(x => x.Item.Sku == selectedItem.ItemNo); + if (draftItem is not null) + { + draftItem.Quantity += int.Parse(selectedItem.Quantity); + } + else + { + var pItem = await ProductCatalog.GetProductItemSku(CountryCode, selectedItem.ItemNo); + var item = new SalesItemView { - Price = line.Price, - Quantity = line.Quantity, - Discount = 0, - Sas = false, - Item = item - }); + Sku = pItem.Sku, + Discontinued = pItem.Discontinued, + Location = pItem.Location, + Name = pItem.Name, + BoxSize = pItem.BoxSize, + OnDemand = pItem.OnDemand, + PictureLink = pItem.PictureLink, + ProductGroup = pItem.ProductGroup, + ShortName = pItem.ShortName, + VariantId = pItem.VariantId, + SalesItemId = pItem.SalesItemId, + Rates = new List(), + }; + DraftProvider.Draft.Items.Add( + new DraftItem + { + Price = decimal.Parse(selectedItem.Rate), + Quantity = int.Parse(selectedItem.Quantity), + Discount = 0, + Sas = false, + Item = item + }); + } + await DraftProvider.SaveChangesAsync(); } - private void ShowProductHistoryOverlay(string sku) - { - _sku = sku; - PriceHistoryOverlay.Show(); - } + // private void ShowProductHistoryOverlay(string sku) + // { + // _sku = sku; + // PriceHistoryOverlay.Show(); + // } // private async Task PriceCatalogOverlayCallback(ItemSelect selectedItem) @@ -95,7 +138,7 @@ public partial class BusinessCustomerLandingPage : IDisposable // { // return; // } - // _selectedItem = await CatalogRepo.GetSalesItemSku(_company.CountryCode, selectedItem.ItemNo); + // _selectedItem = await PriceCatalogRepo.GetSalesItemSku(_company.CountryCode, selectedItem.ItemNo); // ShowItem = true; // Price = selectedItem.Rate; // Quantity = selectedItem.Quantity; @@ -103,18 +146,6 @@ public partial class BusinessCustomerLandingPage : IDisposable // } - private void PriceHistoryOverlayCallback(decimal price) - { - if (price == 0) - { - return; - } - - _price = price.ToString("N2", CultureInfo.InvariantCulture); - StateHasChanged(); - } - - public void Dispose() { Interceptor.DisposeEvent(); diff --git a/Wonky.Client/Pages/BusinessOrderViewPage.razor.cs b/Wonky.Client/Pages/BusinessOrderViewPage.razor.cs index cd84d192..7fe9628b 100644 --- a/Wonky.Client/Pages/BusinessOrderViewPage.razor.cs +++ b/Wonky.Client/Pages/BusinessOrderViewPage.razor.cs @@ -19,7 +19,7 @@ public partial class BusinessOrderViewPage [Inject] public IB2BRepository B2BRepo { get; set; } [Inject] - public ICountryCatalogRepository Catalog { get; set; } + public ICountryPriceCatalogRepository PriceCatalog { get; set; } [Inject] private IOptions Config { get; set; } // ############################################################## diff --git a/Wonky.Client/Pages/CatalogCountryPagedListPage.razor.cs b/Wonky.Client/Pages/CatalogCountryPagedListPage.razor.cs index a61caca3..3fa8245a 100644 --- a/Wonky.Client/Pages/CatalogCountryPagedListPage.razor.cs +++ b/Wonky.Client/Pages/CatalogCountryPagedListPage.razor.cs @@ -32,7 +32,7 @@ public partial class CatalogCountryPagedListPage : IDisposable { // ############################################################## [Inject] public ILocalStorageService Storage { get; set; } - [Inject] public ICountryCatalogRepository Catalog { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalog { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public UserPreferenceService PreferenceService { get; set; } [Inject] public ILogger Logger { get; set; } @@ -85,7 +85,7 @@ public partial class CatalogCountryPagedListPage : IDisposable if (Working) return; Working = true; - var page = await Catalog.GetSalesItemsPaged(CountryCode, Paging); + var page = await PriceCatalog.GetSalesItemsPaged(CountryCode, Paging); Items = page.Items!; PageData = page.MetaData!; Working = false; diff --git a/Wonky.Client/Pages/CatalogCountryPrintPage.razor.cs b/Wonky.Client/Pages/CatalogCountryPrintPage.razor.cs index 2a5038c0..bf0378e9 100644 --- a/Wonky.Client/Pages/CatalogCountryPrintPage.razor.cs +++ b/Wonky.Client/Pages/CatalogCountryPrintPage.razor.cs @@ -26,7 +26,7 @@ namespace Wonky.Client.Pages; public partial class CatalogCountryPrintPage : IDisposable { [Inject] public ILocalStorageService Storage { get; set; } - [Inject] public ICountryCatalogRepository Catalog { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalog { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Parameter] public string CountryCode { get; set; } = ""; private List Items { get; set; } = new(); @@ -37,7 +37,7 @@ public partial class CatalogCountryPrintPage : IDisposable { Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - Items = await Catalog.GetPriceList(CountryCode); + Items = await PriceCatalog.GetPriceList(CountryCode); CountryName = Utils.CountryName(CountryCode); Working = false; } diff --git a/Wonky.Client/Pages/CatalogProductDetailPage.razor.cs b/Wonky.Client/Pages/CatalogProductDetailPage.razor.cs index 35aa9287..3f85b72a 100644 --- a/Wonky.Client/Pages/CatalogProductDetailPage.razor.cs +++ b/Wonky.Client/Pages/CatalogProductDetailPage.razor.cs @@ -11,7 +11,7 @@ public partial class CatalogProductDetailPage { // ############################################################## [Inject] public HttpInterceptorService Interceptor { get; set; } - [Inject] public ICountryCatalogRepository Catalog { get; set; } + [Inject] public ICountryPriceCatalogRepository PriceCatalog { get; set; } // ############################################################## [Parameter] public string SalesItemId { get; set; } = ""; @@ -26,7 +26,7 @@ public partial class CatalogProductDetailPage Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - _item = await Catalog.GetProductDetailView(SalesItemId); + _item = await PriceCatalog.GetProductDetailView(SalesItemId); _working = false; } } \ No newline at end of file diff --git a/Wonky.Client/Pages/OfficeOrderCreatePage.razor b/Wonky.Client/Pages/OfficeOrderCreatePage.razor index 1f470af5..92f01909 100644 --- a/Wonky.Client/Pages/OfficeOrderCreatePage.razor +++ b/Wonky.Client/Pages/OfficeOrderCreatePage.razor @@ -174,7 +174,7 @@ @($"{DraftProvider.Draft.Total:N2}") @* - ***************** Product Catalog overlay ***************************** + ***************** Product CountryPricePriceCatalog overlay ***************************** *@