diff --git a/Wonky.Client/Components/AdvisorLandingComponent.razor.cs b/Wonky.Client/Components/AdvisorLandingComponent.razor.cs index 272a27d8..d50ae44b 100644 --- a/Wonky.Client/Components/AdvisorLandingComponent.razor.cs +++ b/Wonky.Client/Components/AdvisorLandingComponent.razor.cs @@ -35,7 +35,7 @@ public partial class AdvisorLandingComponent { // ############################################################## [Inject] public UserPreferenceService PreferenceService { get; set; } - [Inject] public IDrawerCabinetService DrawerCabinetService { get; set; } + [Inject] public ICabinetDrawerService CabinetDrawerService { get; set; } [Inject] public IUserInfoService UserInfo { get; set; } [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } @@ -60,7 +60,7 @@ public partial class AdvisorLandingComponent // if (firstRender) // { // var countryCode = await UserInfo.GetCountryCode(); - // var _ = await DrawerCabinetService.GetCatalogDrawer(countryCode); + // var _ = await CabinetDrawerService.GetCatalogDrawer(countryCode); // } // } } diff --git a/Wonky.Client/Components/CustomerProductLineListComponent.razor b/Wonky.Client/Components/CustomerProductLineListComponent.razor deleted file mode 100644 index deb05ca0..00000000 --- a/Wonky.Client/Components/CustomerProductLineListComponent.razor +++ /dev/null @@ -1,72 +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] -*@ - -@if (Inventory.Any()) -{ - - - - - - - - - - - - - @foreach (var line in Inventory) - { - - - - - - - - - } - -
- Dato - - Antal - - Vare - - Varenummer - - Rabat - - Pris -
- @line.DeliveryDate - - @line.Quantity - - @line.Description - - @line.Sku - - @(line.Discount)% - - @line.Price -
-} -else -{ -
Ingen data
-} \ No newline at end of file diff --git a/Wonky.Client/Components/CustomerProductLineListComponent.razor.cs b/Wonky.Client/Components/CustomerProductLineListComponent.razor.cs deleted file mode 100644 index 731c9f4c..00000000 --- a/Wonky.Client/Components/CustomerProductLineListComponent.razor.cs +++ /dev/null @@ -1,30 +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.Entity.Views; - -namespace Wonky.Client.Components; - -public partial class CustomerProductLineListComponent -{ - [Parameter] public List Inventory { get; set; } = new(); - - protected override void OnParametersSet() - { - if(Inventory.Any()) - Inventory = Inventory.OrderBy(x => x.Description).ToList(); - } -} \ No newline at end of file diff --git a/Wonky.Client/Components/PageSizeComponent.razor b/Wonky.Client/Components/PageSizeComponent.razor index 601470da..7be67f19 100644 --- a/Wonky.Client/Components/PageSizeComponent.razor +++ b/Wonky.Client/Components/PageSizeComponent.razor @@ -14,7 +14,7 @@ *@ - diff --git a/Wonky.Client/Helpers/Mapper.cs b/Wonky.Client/Helpers/Mapper.cs index 3e6320e4..b03d44bd 100644 --- a/Wonky.Client/Helpers/Mapper.cs +++ b/Wonky.Client/Helpers/Mapper.cs @@ -6,9 +6,9 @@ namespace Wonky.Client.Helpers; public class Mapper { - public static UserManagerCreateView MapCreateUser(CreateUserInputModel model) + public static ManagerNewUserDto MapCreateUser(NewUserForm model) { - return new UserManagerCreateView + return new ManagerNewUserDto { Description = model.Description, Email = model.Email, diff --git a/Wonky.Client/Helpers/VatUtils.cs b/Wonky.Client/Helpers/VatUtils.cs index 27a40c9a..da757dbd 100644 --- a/Wonky.Client/Helpers/VatUtils.cs +++ b/Wonky.Client/Helpers/VatUtils.cs @@ -90,10 +90,13 @@ public class VatUtils var vatToCheck = vatNumber; if (long.Parse(vatToCheck) == 0) return false; - switch (vatToCheck.Length) { - // if less than 10 chars validate as SSI + /* + * if less than 10 chars validate as SSI + * only the first 6 chars are known + * yyMMdd + */ case 6: return ValidateFormatSeExt(vatToCheck); case < 10: @@ -102,11 +105,16 @@ public class VatUtils vatNumber = vatNumber[..10]; break; } - // calculate check digit + /* + * calculate check digit + */ var c10 = C10(vatToCheck); - // return comparison + /* + * return comparison + */ return $"{vatToCheck[..9]}{c10}" == vatNumber; } + /// /// Calculate check digit for swedish org number @@ -115,14 +123,15 @@ public class VatUtils /// private static int C10(string orgNumber) { - // https://wiki.scn.sap.com/wiki/display/CRM/Sweden - // 12 digits 0 to 9 - // C10 = (10 – (18 + 5 + 1 + 8 + 4)MOD10 10) MOD10 - // R = S1 + S3 + S5 + S7 + S9 - // Si = int(Ci/5) + (Ci*2)MOD10) - // https://www.skatteverket.se/skatter/mervardesskattmoms/momsregistreringsnummer.4.18e1b10334ebe8bc80002649.html - // C11 C12 == 01 (De två sista siffrorna är alltid 01) - + /* + * https://wiki.scn.sap.com/wiki/display/CRM/Sweden + * 12 digits 0 to 9 + * C10 = (10 – (18 + 5 + 1 + 8 + 4)MOD10 10) MOD10 + * R = S1 + S3 + S5 + S7 + S9 + * Si = int(Ci/5) + (Ci*2)MOD10) + * https://www.skatteverket.se/skatter/mervardesskattmoms/momsregistreringsnummer.4.18e1b10334ebe8bc80002649.html + * C11 C12 == 01 (De två sista siffrorna är alltid 01) + */ var r = new[] { 0, 2, 4, 6, 8 } .Sum(m => (int)char.GetNumericValue(orgNumber[m]) / 5 + (int)char.GetNumericValue(orgNumber[m]) * 2 % 10); @@ -130,8 +139,9 @@ public class VatUtils var c10 = (10 - (r + c1) % 10) % 10; return c10; // end check digit calculation - } + + /// /// /// @@ -173,6 +183,7 @@ public class VatUtils } } + /// /// Modulus11 validator /// diff --git a/Wonky.Client/HttpRepository/ISystemUserRepository.cs b/Wonky.Client/HttpRepository/ISystemUserRepository.cs index 2ca77e3e..974ca019 100644 --- a/Wonky.Client/HttpRepository/ISystemUserRepository.cs +++ b/Wonky.Client/HttpRepository/ISystemUserRepository.cs @@ -47,7 +47,7 @@ public interface ISystemUserRepository /// /// /// - Task CreateUser(UserManagerCreateView model); + Task PostNewUser(ManagerNewUserDto model); /// /// Update User using userId and updated data diff --git a/Wonky.Client/HttpRepository/SystemUserRepository.cs b/Wonky.Client/HttpRepository/SystemUserRepository.cs index 37e66ae1..d126f126 100644 --- a/Wonky.Client/HttpRepository/SystemUserRepository.cs +++ b/Wonky.Client/HttpRepository/SystemUserRepository.cs @@ -72,7 +72,7 @@ public class SystemUserRepository : ISystemUserRepository /// /// /// - public async Task CreateUser(UserManagerCreateView model) + public async Task PostNewUser(ManagerNewUserDto model) { var result = await _client.PostAsJsonAsync($"{_api.UserManager}", model, _options); if (!result.IsSuccessStatusCode) diff --git a/Wonky.Client/Local.Services/DrawerCabinetService.cs b/Wonky.Client/Local.Services/CabinetDrawerService.cs similarity index 94% rename from Wonky.Client/Local.Services/DrawerCabinetService.cs rename to Wonky.Client/Local.Services/CabinetDrawerService.cs index 2b6ccf74..120ae9ae 100644 --- a/Wonky.Client/Local.Services/DrawerCabinetService.cs +++ b/Wonky.Client/Local.Services/CabinetDrawerService.cs @@ -5,15 +5,14 @@ using Wonky.Client.Models; namespace Wonky.Client.Local.Services; -public class DrawerCabinetService : IDrawerCabinetService +public class CabinetDrawerService : ICabinetDrawerService { private readonly JsonSerializerOptions _options = new () { PropertyNameCaseInsensitive = true }; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly ILocalStorageService _asyncStorageService; - private readonly ISyncLocalStorageService _syncStorageService; private readonly IAdvisorActivityRepository _activityRepo; private readonly IAdvisorCustomerRepository _customerRepo; private readonly IAdvisorCustomerHistoryRepository _historyRepo; @@ -24,15 +23,13 @@ public class DrawerCabinetService : IDrawerCabinetService /// /// /// - /// /// /// /// /// - public DrawerCabinetService( - ILogger logger, + public CabinetDrawerService( + ILogger logger, ILocalStorageService asyncStorageService, - ISyncLocalStorageService syncStorageService, ICountryCatalogRepository catalogRepo, IAdvisorCustomerHistoryRepository historyRepo, IAdvisorCustomerRepository customerRepo, @@ -40,7 +37,6 @@ public class DrawerCabinetService : IDrawerCabinetService { _logger = logger; _asyncStorageService = asyncStorageService; - _syncStorageService = syncStorageService; _catalogRepo = catalogRepo; _historyRepo = historyRepo; _customerRepo = customerRepo; @@ -196,10 +192,19 @@ public class DrawerCabinetService : IDrawerCabinetService if (force) { var result = await _historyRepo.GetProductInvoiceLines(companyId); + var content = result.Select(x => new HistoryFilter + { + DeliveryDate = DateTime.Parse(x.DeliveryDate), + Description = x.Description, + Discount = x.Discount, + Price = x.Price, + Quantity = x.Quantity, + Sku = x.Sku + }).ToList(); drawer = new StatisticDrawer { LastDateModified = DateTime.Today, - Content = result + Content = content }; await StoreStatisticDrawerAsync(companyId, drawer); } diff --git a/Wonky.Client/Local.Services/IDrawerCabinetService.cs b/Wonky.Client/Local.Services/ICabinetDrawerService.cs similarity index 97% rename from Wonky.Client/Local.Services/IDrawerCabinetService.cs rename to Wonky.Client/Local.Services/ICabinetDrawerService.cs index 2f1ea8c3..a3934bee 100644 --- a/Wonky.Client/Local.Services/IDrawerCabinetService.cs +++ b/Wonky.Client/Local.Services/ICabinetDrawerService.cs @@ -4,7 +4,7 @@ using Wonky.Entity.DTO; namespace Wonky.Client.Local.Services; -public interface IDrawerCabinetService +public interface ICabinetDrawerService { Task GetActivityDrawerAsync(string companyId, bool force = false); Task GetCatalogDrawerAsync(string countryCode, bool force = false); diff --git a/Wonky.Client/Local.Services/ISwedishPersonalOrgService.cs b/Wonky.Client/Local.Services/ISwedishPersonalOrgService.cs new file mode 100644 index 00000000..5e4c0f31 --- /dev/null +++ b/Wonky.Client/Local.Services/ISwedishPersonalOrgService.cs @@ -0,0 +1,8 @@ +using Wonky.Client.Models; + +namespace Wonky.Client.Local.Services; + +public interface ISwedishPersonalOrgService +{ + Task GetPersonalOrgNumber(string companyName); +} \ No newline at end of file diff --git a/Wonky.Client/Local.Services/SwedishPersonalOrgService.cs b/Wonky.Client/Local.Services/SwedishPersonalOrgService.cs new file mode 100644 index 00000000..755552bf --- /dev/null +++ b/Wonky.Client/Local.Services/SwedishPersonalOrgService.cs @@ -0,0 +1,47 @@ +using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; +using Microsoft.Extensions.Options; +using Wonky.Client.Models; +using Wonky.Entity.Configuration; +using Wonky.Entity.Views; + +namespace Wonky.Client.Local.Services; + +public class SwedishPersonalOrgService : ISwedishPersonalOrgService +{ + private readonly ILogger _logger; + private readonly HttpClient _client; + private readonly ApiConfig _api; + + + public SwedishPersonalOrgService(HttpClient client, ILogger logger, IOptions api) + { + _client = client; + _logger = logger; + _api = api.Value; + } + + + public async Task GetPersonalOrgNumber(string companyName) + { + var result = new PersonalOrgNumber + { + CompanyName = companyName, + PersonalId = "" + }; + + var response = await _client.GetAsync($"{_api.ServicesVatSe}?companyName={companyName}"); + + var content = await response.Content.ReadAsStringAsync(); + + _logger.LogDebug("response {}", content); + + if (!response.IsSuccessStatusCode) + { + return result; + } + result.PersonalId = content.Replace("\"", ""); + return result; + } +} \ No newline at end of file diff --git a/Wonky.Client/Models/HistoryFilter.cs b/Wonky.Client/Models/HistoryFilter.cs new file mode 100644 index 00000000..05bcef89 --- /dev/null +++ b/Wonky.Client/Models/HistoryFilter.cs @@ -0,0 +1,11 @@ +namespace Wonky.Client.Models; + +public class HistoryFilter +{ + public DateTime DeliveryDate { get; set; } + public string Description { get; set; } = ""; + public string Sku { get; set; } = ""; + public int Quantity { get; set; } + public decimal Price { get; set; } + public decimal Discount { get; set; } +} \ No newline at end of file diff --git a/Wonky.Client/Models/CreateUserInputModel.cs b/Wonky.Client/Models/NewUserForm.cs similarity index 98% rename from Wonky.Client/Models/CreateUserInputModel.cs rename to Wonky.Client/Models/NewUserForm.cs index 336d0405..56262ff3 100644 --- a/Wonky.Client/Models/CreateUserInputModel.cs +++ b/Wonky.Client/Models/NewUserForm.cs @@ -3,7 +3,7 @@ using Wonky.Entity.DTO; namespace Wonky.Client.Models; -public class CreateUserInputModel +public class NewUserForm { [MaxLength(128)] public string CompanyId { get; set; } = ""; diff --git a/Wonky.Client/Models/PersonalOrgNumber.cs b/Wonky.Client/Models/PersonalOrgNumber.cs new file mode 100644 index 00000000..9647cc70 --- /dev/null +++ b/Wonky.Client/Models/PersonalOrgNumber.cs @@ -0,0 +1,7 @@ +namespace Wonky.Client.Models; + +public class PersonalOrgNumber +{ + public string CompanyName { get; set; } = ""; + public string PersonalId { get; set; } = ""; +} \ No newline at end of file diff --git a/Wonky.Client/Models/StatisticDrawer.cs b/Wonky.Client/Models/StatisticDrawer.cs index 729b8e79..c7bf413c 100644 --- a/Wonky.Client/Models/StatisticDrawer.cs +++ b/Wonky.Client/Models/StatisticDrawer.cs @@ -6,5 +6,5 @@ public class StatisticDrawer { public const string Label = "Statistic"; public DateTime LastDateModified { get; set; } - public List Content { get; set; } = new(); + public List Content { get; set; } = new(); } \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor index d7935fd7..0aaa150e 100644 --- a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor +++ b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor @@ -170,10 +170,16 @@ else
-
+
+
+ @if (Activity.CountryCode.ToLower() == "se") + { + + } +
diff --git a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs index 1886269c..588eac73 100644 --- a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs +++ b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor.cs @@ -50,7 +50,8 @@ public partial class AdvisorActivityCreatePage : IDisposable [Inject] public IAdvisorSalesReportRepository ReportRepo { get; set; } [Inject] public IAdvisorCustomerHistoryRepository HistoryRepo { get; set; } [Inject] public IUserInfoService UserInfo { get; set; } - [Inject] public IDrawerCabinetService CabinetService { get; set; } + [Inject] public ICabinetDrawerService DrawerService { get; set; } + [Inject] public ISwedishPersonalOrgService OrgService { get; set; } // ############################################################# [CascadingParameter] private DraftStateProvider DraftProvider { get; set; } = new(); @@ -93,7 +94,7 @@ public partial class AdvisorActivityCreatePage : IDisposable private ActivityDrawer _activityDrawer = new(); private InventoryDrawer _inventoryDrawer = new(); private InvoiceDrawer _invoiceDrawer = new(); - + /// /// Page initialization @@ -101,8 +102,8 @@ public partial class AdvisorActivityCreatePage : IDisposable protected override async Task OnInitializedAsync() { ActivityContext = new EditContext(Activity); - ActivityContext.OnFieldChanged += HandleFieldChanged; - ActivityContext.OnValidationStateChanged += ValidationChanged; + ActivityContext.OnFieldChanged += ContextHandleFieldChanged; + ActivityContext.OnValidationStateChanged += ContextValidationChanged; Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); @@ -111,13 +112,13 @@ public partial class AdvisorActivityCreatePage : IDisposable // User Info SalesRep = await UserInfo.GetUserInfo(); - _infoDrawer = await CabinetService.GetInfoDrawerAsync(CompanyId); - _activityDrawer = await CabinetService.GetActivityDrawerAsync(CompanyId); - _inventoryDrawer = await CabinetService.GetInventoryDrawerAsync(CompanyId); - _invoiceDrawer = await CabinetService.GetInvoiceDrawerAsync(CompanyId); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); + _activityDrawer = await DrawerService.GetActivityDrawerAsync(CompanyId); + _inventoryDrawer = await DrawerService.GetInventoryDrawerAsync(CompanyId); + _invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId); Company = _infoDrawer.Content; - + if (Company.Account.StartsWith("KANVAS")) { _kanvas = true; @@ -139,11 +140,12 @@ public partial class AdvisorActivityCreatePage : IDisposable Activity.ActivityVisitEnum = Company.Account.StartsWith("NY") ? "new" : "recall"; - if (string.IsNullOrWhiteSpace(Company.Segment) && SalesRep.CountryCode.ToLower() == "dk") - { - Toaster.ShowError("Der mangler information om Segment. Ret kunde segment, gem erp data og prøv igen."); - Navigator.NavigateTo($"/advisor/customers/{CompanyId}"); - } + + // if (string.IsNullOrWhiteSpace(Company.Segment) && SalesRep.CountryCode.ToLower() == "dk") + // { + // Toaster.ShowError("Der mangler information om Segment. Ret kunde segment, gem erp data og prøv igen."); + // // Navigator.NavigateTo($"/advisor/customers/{CompanyId}"); + // } } // Populate base activity information @@ -170,8 +172,15 @@ public partial class AdvisorActivityCreatePage : IDisposable Activity.Segment = Company.Segment; Activity.EanNumber = Company.EanNumber; - // Initialize date variable + /* + * debug loggin + */ + Logger.LogDebug("company.segment = {}", Company.Segment); + Logger.LogDebug("activity.segment = {}", Activity.Segment); Logger.LogDebug("AdvisorActivityCreatePage => DateTime parser => {}", UserPreference.WorkDate); + /* + * set selected date + */ SelectedDate = string.IsNullOrWhiteSpace(UserPreference.WorkDate) ? DateTime.Now : DateTime.Parse(UserPreference.WorkDate); @@ -199,12 +208,28 @@ public partial class AdvisorActivityCreatePage : IDisposable Activity.ActivityStatusEnum = "order"; PoFormInvalid = false; } + + if (SalesRep.CountryCode.ToLower() == "se") + { + await TestOrgNumber(); + } Working = false; + StateHasChanged(); } + private async Task TestOrgNumber() + { + var result = await OrgService.GetPersonalOrgNumber(Activity.Name); + if (!string.IsNullOrWhiteSpace(result.PersonalId)) + { + // Toaster.ShowSuccess($"PersonId for {result.CompanyName} er fundet til at være {result.PersonalId}"); + Activity.VatNumber = result.PersonalId; + } + } + /// /// Show Activity Overlay /// @@ -332,7 +357,7 @@ public partial class AdvisorActivityCreatePage : IDisposable { item.Check = false; } - await CabinetService.StoreInventoryDrawerAsync(CompanyId, _inventoryDrawer); + await DrawerService.StoreInventoryDrawerAsync(CompanyId, _inventoryDrawer); await CreateActivity(); } @@ -371,7 +396,7 @@ public partial class AdvisorActivityCreatePage : IDisposable { return; } - + // working flag is raised after the following validations Logger.LogDebug("view kanvas activity => {}", JsonSerializer.Serialize(Activity)); switch (_kanvas) @@ -483,25 +508,33 @@ public partial class AdvisorActivityCreatePage : IDisposable /// /// Show Incomplete Organization Number Warning /// - private void ShowOrgWarning() + private async Task ShowOrgWarning() { if (_kanvas) { return; } - - if (OrgWarning) - { - return; - } - - OrgWarning = true; - if (Company.CountryCode.ToLower() == "se" + // if (OrgWarning) + // { + // return; + // } + // OrgWarning = true; + if (Company.CountryCode.ToLower() == "se" && Utils.StringToDigits(Activity.VatNumber).Length < 10 && Activity.ActivityStatusEnum == "order") { - Toaster.ShowWarning("Org nummer er ufuldstændig. Skal opdateres før bestilling kan sendes. "); + Toaster.ShowWarning("Org nummer er ufuldstændig. Skal opdateres før bestilling kan sendes."); + Toaster.ShowInfo("Vent mens vi soger at finde de manglende cifre ..."); + + var result = await OrgService.GetPersonalOrgNumber(Activity.Name); + + if (!string.IsNullOrWhiteSpace(result.PersonalId)) + { + Activity.VatNumber = result.PersonalId; + Toaster.ShowSuccess($"Org nummer for {result.CompanyName} er fundet at være {result.PersonalId}."); + } } + // OrgWarning = false; } @@ -571,9 +604,9 @@ public partial class AdvisorActivityCreatePage : IDisposable /// /// /// - private void HandleFieldChanged(object sender, FieldChangedEventArgs e) + private void ContextHandleFieldChanged(object sender, FieldChangedEventArgs e) { - Logger.LogDebug("ActivityNewPage => HandleFieldChanged => ActivityStatusEnum <= '{}'", + Logger.LogDebug("ActivityNewPage => ContextHandleFieldChanged => ActivityStatusEnum <= '{}'", Activity.ActivityStatusEnum); DraftProvider.Draft.DraftType = Activity.ActivityStatusEnum; if (Activity.ActivityStatusEnum == "noSale") @@ -614,7 +647,7 @@ public partial class AdvisorActivityCreatePage : IDisposable /// /// /// - private void ValidationChanged(object sender, ValidationStateChangedEventArgs e) + private void ContextValidationChanged(object sender, ValidationStateChangedEventArgs e) { if (string.IsNullOrEmpty(Activity.ActivityTypeEnum) && !ReportClosed) { @@ -627,17 +660,17 @@ public partial class AdvisorActivityCreatePage : IDisposable && Company.CountryCode.ToLower() == "se" && Utils.StringToDigits(Activity.VatNumber).Length < 10) { - ShowOrgWarning(); - PoFormInvalid = true; - return; + Toaster.ShowError("Org nummer er ufuldstændig ..."); + // ShowOrgWarning(); + // return; } PoFormInvalid = false; - ActivityContext.OnFieldChanged -= HandleFieldChanged; - ActivityContext.OnValidationStateChanged -= ValidationChanged; + ActivityContext.OnFieldChanged -= ContextHandleFieldChanged; + ActivityContext.OnValidationStateChanged -= ContextValidationChanged; ActivityContext = new EditContext(Activity); - ActivityContext.OnFieldChanged += HandleFieldChanged; - ActivityContext.OnValidationStateChanged += ValidationChanged; + ActivityContext.OnFieldChanged += ContextHandleFieldChanged; + ActivityContext.OnValidationStateChanged += ContextValidationChanged; } @@ -647,7 +680,7 @@ public partial class AdvisorActivityCreatePage : IDisposable public void Dispose() { Interceptor.DisposeEvent(); - ActivityContext.OnFieldChanged -= HandleFieldChanged; - ActivityContext.OnValidationStateChanged -= ValidationChanged; + ActivityContext.OnFieldChanged -= ContextHandleFieldChanged; + ActivityContext.OnValidationStateChanged -= ContextValidationChanged; } } \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerActivityListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerActivityListPage.razor.cs index 72c3c4e0..7b82fc82 100644 --- a/Wonky.Client/Pages/AdvisorCustomerActivityListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerActivityListPage.razor.cs @@ -32,7 +32,7 @@ public partial class AdvisorCustomerActivityListPage : IDisposable [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public IAdvisorActivityRepository AdvisorActivityRepo { get; set; } [Inject] public IAdvisorCustomerRepository CompanyRepo { get; set; } - [Inject] public IDrawerCabinetService CabinetService { get; set; } + [Inject] public ICabinetDrawerService DrawerService { get; set; } [Inject] public ILogger Logger { get; set; } // ###################################################################### @@ -58,7 +58,7 @@ public partial class AdvisorCustomerActivityListPage : IDisposable private async Task GetActivities() { Activities = new List(); - var drawer = await CabinetService.GetActivityDrawerAsync(CompanyId); + var drawer = await DrawerService.GetActivityDrawerAsync(CompanyId); if (drawer.Content.Any()) { Activities = drawer.Content diff --git a/Wonky.Client/Pages/AdvisorCustomerCreatePage.razor b/Wonky.Client/Pages/AdvisorCustomerCreatePage.razor index 3e9c7d2e..e21e8246 100644 --- a/Wonky.Client/Pages/AdvisorCustomerCreatePage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerCreatePage.razor @@ -137,7 +137,7 @@ else {
- @* placeholder *@ + @(Company.Segment = UserInfo.CountryCode.ToLower() == "no" ? "10" : "11")
} @* entity mobile *@ diff --git a/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs index 557bf478..7fb4aaef 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerInventoryListPage.razor.cs @@ -35,21 +35,25 @@ namespace Wonky.Client.Pages; public partial class AdvisorCustomerInventoryListPage : IDisposable { - // ############################################################## + /** + * Injected services + */ + [Inject] public ILogger Logger { get; set; } [Inject] public IAdvisorCustomerHistoryRepository HistoryRepo { get; set; } [Inject] public IAdvisorCustomerRepository CustomerRepo { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public IToastService Toaster { get; set; } - [Inject] public ILogger Logger { get; set; } [Inject] public ILocalStorageService Storage { get; set; } [Inject] public ICountryCatalogRepository CatalogRepo { get; set; } - [Inject] public IDrawerCabinetService CabinetService { get; set; } - - // ############################################################## + [Inject] public ICabinetDrawerService DrawerService { get; set; } + /* + * Parameters + */ [CascadingParameter] public DraftStateProvider DraftStateProvider { get; set; } = new(); [Parameter] public string CompanyId { get; set; } = ""; - - // ############################################################## + /* + * Variables + */ private readonly JsonSerializerOptions _options = new JsonSerializerOptions(JsonSerializerDefaults.Web); private CompanyDto Company { get; set; } = new(); private bool Working { get; set; } = true; @@ -63,7 +67,7 @@ public partial class AdvisorCustomerInventoryListPage : IDisposable Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - var drawer = await CabinetService.GetInfoDrawerAsync(CompanyId); + var drawer = await DrawerService.GetInfoDrawerAsync(CompanyId); Company = drawer.Content; // fetch product inventory @@ -93,7 +97,7 @@ public partial class AdvisorCustomerInventoryListPage : IDisposable private async Task FetchProductInventory() { - var drawer = await CabinetService.GetInventoryDrawerAsync(CompanyId); + var drawer = await DrawerService.GetInventoryDrawerAsync(CompanyId); if (drawer.Content.Any()) { Inventory = drawer.Content; diff --git a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor index 6e660840..3a8832c2 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor @@ -32,6 +32,7 @@ Besøg
+ } diff --git a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs index af453495..88f18d45 100644 --- a/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerInvoiceListPage.razor.cs @@ -36,7 +36,7 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public IAdvisorCustomerHistoryRepository HistoryRepo { get; set; } [Inject] public IToastService Toaster { get; set; } - [Inject] public IDrawerCabinetService CabinetService { get; set; } + [Inject] public ICabinetDrawerService DrawerService { get; set; } // ############################################################## [Parameter] public string CompanyId { get; set; } = ""; @@ -55,8 +55,8 @@ public partial class AdvisorCustomerInvoiceListPage : IDisposable Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - _infoDrawer = await CabinetService.GetInfoDrawerAsync(CompanyId); - _invoiceDrawer = await CabinetService.GetInvoiceDrawerAsync(CompanyId); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); + _invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId); _company = _infoDrawer.Content; _invoices = _invoiceDrawer.Content; diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor new file mode 100644 index 00000000..d22a1402 --- /dev/null +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor @@ -0,0 +1,99 @@ +@* 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 "/advisor/customers/{CompanyId}/statistic" + +Produktkøb @_company.Name +
+
+
+ +
+
+ + Tilbage +
+
+ +@if (DisplayList.Any()) +{ + + + + + + + + + + + + + + + + @foreach (var item in DisplayList) + { + + + + + + + + + } + +
+

Produktkøb @_company.Name

+

Dannet @DateTime.Today.ToLongDateString() (@Months md.)

+
+ Beskrivelse + + Vare Nr. + + Dato + + Antal + + Pris + + Afslag +
+ @item.Description + + @item.Sku + + @item.DeliveryDate.ToShortDateString() + + @item.Quantity + + @item.Price + + @(item.Discount)% +
+} +else +{ +
Ingen data
+} \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs new file mode 100644 index 00000000..18355a16 --- /dev/null +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Components; +using Wonky.Client.Local.Services; +using Wonky.Client.Models; +using Wonky.Entity.DTO; +using Wonky.Entity.Views; + +#pragma warning disable CS8618 + +namespace Wonky.Client.Pages; + +public partial class AdvisorCustomerStatisticPage +{ + [Inject] public ICabinetDrawerService DrawerService { get; set; } + + [Parameter] public string CompanyId { get; set; } = ""; + + private InfoDrawer _infoDrawer = new(); + private StatisticDrawer _statisticDrawer = new(); + private List DisplayList { get; set; } = new(); + private CompanyDto _company = new(); + private int Months { get; set; } + + protected override async Task OnInitializedAsync() + { + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); + _statisticDrawer = await DrawerService.GetStatisticDrawerAsync(CompanyId); + _company = _infoDrawer.Content; + if (Months == 0) + { + Months = 24; + } + FilterDisplayList(Months); + } + + private void FilterDisplayList(int months) + { + if (_statisticDrawer.Content.Any()) + { + DisplayList = _statisticDrawer.Content + .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) + .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) + .ToList(); + } + } + + private void OnSelectChanged(ChangeEventArgs e) + { + var val = e.Value?.ToString(); + var x = Convert.ToInt32(val); + if (x > 24) x = 24; + FilterDisplayList(x); + } + +} \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor index d0c4abd1..106720c9 100644 --- a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor @@ -28,87 +28,88 @@ }
-
+
@_infoDrawer.Content.Name (@_infoDrawer.Content.Account)
-
+
@if (_userInfo.CountryCode is "DK") { - Arbejdssted + Arbejdssted } - - Tilbage + Statistik + + Tilbage
// erp context - +
@* Company Name *@
- +
@* Company Attention *@
- +
@* Address 1 *@
- +
@* Address 2 *@
- +
@* Post Code *@
- +
@* City Name *@
- +
@* Email *@
- +
@* Phone *@
- +
@* Mobile *@
- +
@* Email *@
- +
- @if (!Kanvas) + @if (!_kanvas) { @* entity segment *@ @if (_userInfo.CountryCode.ToLower() == "dk") @@ -116,7 +117,7 @@
+ @bind-Value="@_infoDrawer.Content.Segment" disabled="@(_erpEditDisabled)"> @@ -145,7 +146,7 @@
@* Save erp data *@
- +
@* vat number*@
@@ -155,7 +156,7 @@ - +
@@ -165,10 +166,10 @@
@* vat lookup *@
- @switch (CountryCode) + @switch (_countryCode) { case "dk": - + break; case "no": brreg.no @@ -180,7 +181,7 @@
@* save vat number *@
- +
} @@ -190,42 +191,42 @@ @* activity buttons *@
- @if (!Kanvas) + @if (!_kanvas) { - + Enabled="@_enableLink" /> }
- @if (!Kanvas) + @if (!_kanvas) { - + Enabled="@_enableLink" /> }
- @if (!Kanvas ) + @if (!_kanvas ) { - + Enabled="@_enableLink" /> }
- + Enabled="@_enableActivity">
- @if (!Kanvas) + @if (!_kanvas) {
@* crm context - OBS note *@ @@ -252,7 +253,7 @@
-
+
Stilling
Navn
@@ -262,9 +263,9 @@
- @if (Contacts.Any()) + @if (_contacts.Any()) { - @foreach (var contact in Contacts) + @foreach (var contact in _contacts) {
@@ -289,14 +290,14 @@
- + - +
- +
@@ -315,7 +316,7 @@
- +
@if (_userInfo.CountryCode is "DK") @@ -326,13 +327,13 @@
} -@if (Working) +@if (_working) { } - + - + diff --git a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor.cs index f8a57e45..704e220b 100644 --- a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor.cs @@ -48,45 +48,46 @@ public partial class AdvisorCustomerViewEditPage : IDisposable [Inject] public ILocalStorageService Storage { get; set; } [Inject] public IUserInfoService UserInfoService { get; set; } [Inject] public IOptions? AppInfo { get; set; } - [Inject] public IDrawerCabinetService CabinetService { get; set; } + [Inject] public ICabinetDrawerService DrawerService { get; set; } // ########################################################################### [Parameter] public string CompanyId { get; set; } = ""; // ########################################################################### - private EditContext ErpContext { get; set; } - private DateTime LastVisit { get; set; } - private DateTime NextVisit { get; set; } - private VatAddress CompanyVatAddress { get; set; } = new(); - private ContactDto SelectedContact { get; set; } = new(); - private ContactDto DefaultContact { get; set; } = new(); - private ContactViewEditModal ContactViewPopup { get; set; } = new(); - private VatLookupDkModal VatLookupPopup { get; set; } = new(); - private List Contacts { get; set; } = new(); - private UserManagerEditView _userInfo = new(); - private InfoDrawer _infoDrawer = new(); + private EditContext _erpContext; + private DateTime _lastVisit; + private DateTime _nextVisit; + private VatAddress _companyVatAddress = new(); + private ContactDto _selectedContact = new(); + private ContactDto _defaultContact = new(); + private ContactViewEditModal _contactViewPopup = new(); + private VatLookupDkModal _vatLookupPopup = new(); + private List _contacts = new(); private string VatState { get; set; } = "the-ugly"; - private bool ValidVat { get; set; } - private bool HasFolded { get; set; } - private string CurrentVat { get; set; } = ""; - private string CountryCode { get; set; } = "dk"; - private string VisitState { get; set; } = "the-ugly"; - private int EnableActivity { get; set; } = 1; - private bool Working { get; set; } = true; - private bool CountryIsDk { get; set; } = true; - private bool ErpEditDisabled { get; set; } = true; - private bool VatEditDisabled { get; set; } = true; - private string ToggleButtonText { get; set; } = ""; - private bool Kanvas { get; set; } - private string InventoryLink { get; set; } = ""; - private string ActivityLink { get; set; } = ""; - private string InvoiceLink { get; set; } = ""; - private string NewActivityLink { get; set; } = ""; - private int EnableLink { get; set; } = 1; + private bool _validVat; + private bool _hasFolded; + private string _currentVat = ""; + private string _countryCode = "dk"; + private string _visitStateCss = "the-ugly"; + private int _enableActivity = 1; + private bool _working = true; + private bool _countryIsDk = true; + private bool _erpEditDisabled = true; + private bool _vatEditDisabled = true; + private string _toggleButtonText = ""; + private bool _kanvas; + private string _inventoryLink = ""; + private string _activitiesLink = ""; + private string _invoiceLink = ""; + private string _newActivityLink = ""; + private int _enableLink = 1; private ActivityDrawer _activityDrawer = new(); private InventoryDrawer _inventoryDrawer = new(); private InvoiceDrawer _invoiceDrawer = new(); private StatisticDrawer _statisticDrawer = new(); + private UserManagerEditView _userInfo = new(); + private InfoDrawer _infoDrawer = new(); + private CompanyDto _company = new(); private string _companyId = ""; protected override async Task OnInitializedAsync() { @@ -98,115 +99,126 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * default contact */ - DefaultContact = new ContactDto { CompanyId = CompanyId, ContactId = "", FirstName = "" }; + _defaultContact = new ContactDto { CompanyId = CompanyId, ContactId = "", FirstName = "" }; /* * navigation button links */ - InventoryLink = $"/advisor/customers/{CompanyId}/history/inventory"; - ActivityLink = $"/advisor/customers/{CompanyId}/activities"; - InvoiceLink = $"/advisor/customers/{CompanyId}/invoices"; - NewActivityLink = $"/advisor/customers/{CompanyId}/activities/new"; + _inventoryLink = $"/advisor/customers/{CompanyId}/history/inventory"; + _activitiesLink = $"/advisor/customers/{CompanyId}/activities"; + _invoiceLink = $"/advisor/customers/{CompanyId}/invoices"; + _newActivityLink = $"/advisor/customers/{CompanyId}/activities/new"; /* * setup form context */ - ErpContext = new EditContext(_infoDrawer.Content); + _erpContext = new EditContext(_company); /* * assign event handlers to context */ - ErpContext.OnFieldChanged += HandleFieldChanged; - ErpContext.OnValidationStateChanged += ValidationChanged!; + _erpContext.OnFieldChanged += HandleFieldChanged; + _erpContext.OnValidationStateChanged += ValidationChanged!; /* * fetch user info from local storage */ _userInfo = await UserInfoService.GetUserInfo(); - CountryCode = _userInfo.CountryCode.ToLower(); - CountryIsDk = CountryCode == "dk"; + _countryCode = _userInfo.CountryCode.ToLower(); + _countryIsDk = _countryCode == "dk"; /* * get InfoDrawer.Company from drawer */ - _infoDrawer = await CabinetService.GetInfoDrawerAsync(CompanyId); - _infoDrawer.Content = _infoDrawer.Content; + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, force:true); + _company = _infoDrawer.Content; /* - * internal EnableActivity flag + * internal _enableActivity flag */ - EnableActivity = _infoDrawer.Content.ValidVat; + _enableActivity = _company.ValidVat; /* - * if KANVAS or NY override EnableActivity + * if KANVAS or NY override _enableActivity */ - if (_infoDrawer.Content.Account.StartsWith("NY") || _infoDrawer.Content.Account.StartsWith("KANVAS") || string.IsNullOrWhiteSpace(_infoDrawer.Content.Account)) - EnableActivity = 1; - if (_infoDrawer.Content.Account.StartsWith("KANVAS")) - Kanvas = true; + if (_company.Account.StartsWith("NY") || _company.Account.StartsWith("KANVAS") || + string.IsNullOrWhiteSpace(_company.Account)) + { + _enableActivity = 1; + } + if (_company.Account.StartsWith("KANVAS")) + { + _kanvas = true; + } /* * only execute if the InfoDrawer.Company is not KANVAS */ - if (!Kanvas) + if (!_kanvas) { - Logger.LogDebug("InfoDrawer.Company => {}", JsonSerializer.Serialize(_infoDrawer.Content)); + Logger.LogDebug("_company => {}", JsonSerializer.Serialize(_company)); /* * toggle view button text */ - ToggleButtonText = _infoDrawer.Content.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning"; - CurrentVat = _infoDrawer.Content.VatNumber; - _infoDrawer.Content.CountryCode = _userInfo.CountryCode.ToLower(); + _toggleButtonText = _company.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning"; + _currentVat = _company.VatNumber; + _company.CountryCode = _userInfo.CountryCode.ToLower(); /* * visit interval init */ - if (_infoDrawer.Content.Interval == 0) - _infoDrawer.Content.Interval = 8; + if (_company.Interval == 0) + { + _company.Interval = 8; + } /* * visit date init */ - LastVisit = DateTime.Parse(_infoDrawer.Content.LastVisit); - NextVisit = DateTime.Parse(_infoDrawer.Content.NextVisit); + _lastVisit = DateTime.Parse(_company.LastVisit); + _nextVisit = DateTime.Parse(_company.NextVisit); /* * if no previous visit is registered - force last visit date to 2020 */ - if (LastVisit.Year < 2020) - LastVisit = DateTime.Parse("2020-01-01"); + if (_lastVisit.Year < 2020) + { + _lastVisit = DateTime.Parse("2020-01-01"); + } /* * set next visit according to last visit and interval */ - if (!_infoDrawer.Content.ValidDateSpan()) - NextVisit = LastVisit.AddDays(_infoDrawer.Content.Interval * 7); + if (!_company.ValidDateSpan()) + { + _nextVisit = _lastVisit.AddDays(_company.Interval * 7); + } /* * display urgency of next visit */ - VisitState = Utils.MapVisitState($"{NextVisit:yyyy-MM-dd}"); + _visitStateCss = Utils.MapVisitState($"{_nextVisit:yyyy-MM-dd}"); /* * handle InfoDrawer.Company out of business case */ - if (_infoDrawer.Content.HasFolded == 1) + if (_company.HasFolded == 1) { /* * this is only used if user has selected to show closed companies */ - HasFolded = true; + _hasFolded = true; VatState = "the-dead"; - VisitState = "the-dead"; + _visitStateCss = "the-dead"; } else { /* * vat validation flags */ - _infoDrawer.Content.ValidVat = VatUtils.ValidateFormat(_infoDrawer.Content.CountryCode, _infoDrawer.Content.VatNumber) ? 1 : 0; - ValidVat = _infoDrawer.Content.ValidVat == 1; // true/false flag set if InfoDrawer.Company has a valid vatNumber - VatState = _infoDrawer.Content.ValidVat == 1 ? "the-good" : "no-vat"; // assign css class + _company.ValidVat = VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber) ? 1 : 0; + _validVat = _company.ValidVat == 1; // true/false flag set if InfoDrawer.Company has a valid vatNumber + VatState = _company.ValidVat == 1 ? "the-good" : "no-vat"; // assign css class } /* * create search address from address */ - if (CountryIsDk) + if (_countryIsDk) { - CompanyVatAddress = PrepareVatAddress(_infoDrawer.Content); + _companyVatAddress = PrepareVatAddress(_company); } await GetContacts(CompanyId); } /* * remove loading image */ - Working = false; + _working = false; } protected override async Task OnAfterRenderAsync(bool firstRender) @@ -214,40 +226,42 @@ public partial class AdvisorCustomerViewEditPage : IDisposable if (string.IsNullOrWhiteSpace(_companyId)) { _companyId = CompanyId; - await CabinetService.GetInvoiceDrawerAsync(CompanyId, true); - await CabinetService.GetInventoryDrawerAsync(CompanyId, true); - await CabinetService.GetActivityDrawerAsync(CompanyId, true); - await CabinetService.GetStatisticDrawerAsync(CompanyId, true); + _invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId, true); + _inventoryDrawer = await DrawerService.GetInventoryDrawerAsync(CompanyId, true); + _activityDrawer = await DrawerService.GetActivityDrawerAsync(CompanyId, true); + _statisticDrawer = await DrawerService.GetStatisticDrawerAsync(CompanyId, true); } } private async Task ReloadHistory() { + _enableLink = 0; + _enableActivity = 0; + Toaster.ShowWarning("Arbejder på sagen ..."); - var newSync = await HistoryRepo.RequestErpSync(CompanyId, _infoDrawer.Content.HistorySync, false); + var newSync = await HistoryRepo.RequestErpSync(CompanyId, _company.HistorySync, false); if (!string.IsNullOrWhiteSpace(newSync)) { - _infoDrawer.Content.HistorySync = newSync; - _infoDrawer.Content = _infoDrawer.Content; - await CabinetService.StoreInfoDrawerAsync(CompanyId, _infoDrawer); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); + _invoiceDrawer = await DrawerService.GetInvoiceDrawerAsync(CompanyId, true); + _inventoryDrawer = await DrawerService.GetInventoryDrawerAsync(CompanyId, true); + _activityDrawer = await DrawerService.GetActivityDrawerAsync(CompanyId, true); + _statisticDrawer = await DrawerService.GetStatisticDrawerAsync(CompanyId, true); } - await CabinetService.GetInvoiceDrawerAsync(CompanyId, true); - await CabinetService.GetInventoryDrawerAsync(CompanyId, true); - await CabinetService.GetActivityDrawerAsync(CompanyId, true); - await CabinetService.GetStatisticDrawerAsync(CompanyId, true); - Toaster.ShowSuccess("Data er snart klar ...."); + _enableLink = 1; + _enableActivity = _company.ValidVat; } private void ToggleErpEdit() { - ErpEditDisabled = !ErpEditDisabled; + _erpEditDisabled = !_erpEditDisabled; } private void ToggleVatEdit() { - VatEditDisabled = !VatEditDisabled; + _vatEditDisabled = !_vatEditDisabled; } @@ -256,12 +270,12 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * toggle view button text */ - _infoDrawer.Content.IsHidden = _infoDrawer.Content.IsHidden == 0 ? 1 : 0; - ToggleButtonText = _infoDrawer.Content.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning"; + _company.IsHidden = _company.IsHidden == 0 ? 1 : 0; + _toggleButtonText = _company.IsHidden == 0 ? "Udelad kunde i oversigt" : "Brug Normal Visning"; /* * send update reqeust */ - await CustomerRepo.UpdateCrmData(CompanyId, _infoDrawer.Content); + await CustomerRepo.UpdateCrmData(CompanyId, _company); } @@ -270,38 +284,38 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * load contacts */ - Contacts = await ContactRepo.GetContacts(companyId); - if (Contacts.Any() && Contacts.Count > 1) + _contacts = await ContactRepo.GetContacts(companyId); + if (_contacts.Any() && _contacts.Count > 1) { - Contacts = Contacts.OrderBy(x => x.FirstName).ToList(); + _contacts = _contacts.OrderBy(x => x.FirstName).ToList(); } } private void OpenVatLookupModal() { - VatLookupPopup.Show(); + _vatLookupPopup.Show(); } private void SelectedCompanyCallback(VirkRegInfo regInfo) { - ValidVat = regInfo.States[0].State.ToLower() == "normal"; - _infoDrawer.Content.HasFolded = ValidVat ? 1 : 0; - EnableActivity = ValidVat ? 1 : 0; + _validVat = regInfo.States[0].State.ToLower() == "normal"; + _company.HasFolded = _validVat ? 1 : 0; + _enableActivity = _validVat ? 1 : 0; VatState = regInfo.States[0].State.ToLower() == "normal" ? "the-good" : "the-dead"; /* * set new properties if flagged */ if (regInfo.SyncAll) { - _infoDrawer.Content.Name = regInfo.Name; - _infoDrawer.Content.Address1 = regInfo.Address; - _infoDrawer.Content.Address2 = regInfo.CoName; - _infoDrawer.Content.ZipCode = regInfo.ZipCode; - _infoDrawer.Content.City = regInfo.City; + _company.Name = regInfo.Name; + _company.Address1 = regInfo.Address; + _company.Address2 = regInfo.CoName; + _company.ZipCode = regInfo.ZipCode; + _company.City = regInfo.City; } - _infoDrawer.Content.VatNumber = regInfo.VatNumber; + _company.VatNumber = regInfo.VatNumber; } @@ -310,11 +324,11 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * pass contact to popup */ - SelectedContact = contact; + _selectedContact = contact; /* * show the popup */ - ContactViewPopup.Show(); + _contactViewPopup.Show(); } /// @@ -323,9 +337,9 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /// private async Task WriteContactCallback(ContactDto contact) { - if (Working) + if (_working) return; - Working = true; + _working = true; /* * if ContactId is empty it is a new contact */ @@ -346,12 +360,12 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * reset default contact */ - SelectedContact = new ContactDto(); + _selectedContact = new ContactDto(); /* * reload contacts from backend */ await GetContacts(CompanyId); - Working = false; + _working = false; } /// @@ -360,9 +374,9 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /// private async Task DeleteContactCallback(string contactId) { - if (Working) + if (_working) return; - Working = true; + _working = true; /* * send delete request to backend */ @@ -370,12 +384,12 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * reset default contact */ - SelectedContact = new ContactDto(); + _selectedContact = new ContactDto(); /* * reload contacts from backend */ await GetContacts(CompanyId); - Working = false; + _working = false; } /// @@ -384,21 +398,22 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /// true/false private async Task PostCrmData() { - if (Working) + if (_working) return; - Working = true; + _working = true; Toaster.ShowInfo("Vent venligst ..."); - _infoDrawer.Content.LastVisit = $"{LastVisit:yyyy-MM-dd}"; - _infoDrawer.Content.NextVisit = $"{NextVisit:yyyy-MM-dd}"; - _infoDrawer.Content.IsHidden = 0; - var company = await CustomerRepo.UpdateCrmData(CompanyId, _infoDrawer.Content); - if (!string.IsNullOrWhiteSpace(company.CompanyId)) + _company.LastVisit = $"{_lastVisit:yyyy-MM-dd}"; + _company.NextVisit = $"{_nextVisit:yyyy-MM-dd}"; + _company.IsHidden = 0; + var result = await CustomerRepo.UpdateCrmData(CompanyId, _company); + if (!string.IsNullOrWhiteSpace(result.CompanyId)) { - await UpdateInfoDrawer(company); - StateHasChanged(); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); + _company = _infoDrawer.Content; } - Working = false; - Toaster.ClearAll(); + StateHasChanged(); + _working = false; + Toaster.ShowSuccess("Dine CRM data er opdateret."); } /// @@ -407,19 +422,20 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /// private async Task UpdateErpData() { - if (Working) + if (_working) return; - ErpEditDisabled = true; - Working = true; + _erpEditDisabled = true; + _working = true; Toaster.ShowInfo("Vent venligst ..."); - var company = await CustomerRepo.UpdateErpData(CompanyId, _infoDrawer.Content); - if (!string.IsNullOrWhiteSpace(company.CompanyId)) + var result = await CustomerRepo.UpdateErpData(CompanyId, _company); + if (!string.IsNullOrWhiteSpace(result.CompanyId)) { - await UpdateInfoDrawer(company); - StateHasChanged(); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); + _company = _infoDrawer.Content; } - Working = false; - Toaster.ClearAll(); + StateHasChanged(); + _working = false; + Toaster.ShowSuccess("ERP data er opdateret. Notifikation til kontoret er sendt."); } /// @@ -431,25 +447,26 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /* * VAT format validation */ - if (!VatUtils.ValidateFormat(_infoDrawer.Content.CountryCode, _infoDrawer.Content.VatNumber)) + if (!VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber)) { Toaster.ShowError($"Moms Nummer ugyldigt"); return; } - if (Working) + if (_working) return; - Working = true; - VatEditDisabled = true; + _working = true; + _vatEditDisabled = true; Toaster.ShowInfo("Vent venligst ..."); - var company = await CustomerRepo.UpdateCompanyVat(CompanyId, _infoDrawer.Content.VatNumber); - if (!string.IsNullOrWhiteSpace(company.CompanyId)) + var result = await CustomerRepo.UpdateCompanyVat(CompanyId, _company.VatNumber); + if (!string.IsNullOrWhiteSpace(result.CompanyId)) { - await UpdateInfoDrawer(company); - StateHasChanged(); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId, true); + _company = _infoDrawer.Content; } - Toaster.ClearAll(); - Working = false; + StateHasChanged(); + _working = false; + Toaster.ShowSuccess("Moms Nr. er opdateret."); } /// @@ -491,17 +508,14 @@ public partial class AdvisorCustomerViewEditPage : IDisposable */ return new VatAddress(); } - - - private async Task UpdateInfoDrawer(CompanyDto company) - { - _infoDrawer.Content = company; - await CabinetService.StoreInfoDrawerAsync(CompanyId, _infoDrawer); - } + + /// + /// Force enable activity + /// private void ForceActivity() { - EnableActivity = EnableActivity == 0 ? 1 : 0; + _enableActivity = _enableActivity == 0 ? 1 : 0; } /// @@ -512,18 +526,18 @@ public partial class AdvisorCustomerViewEditPage : IDisposable private void HandleFieldChanged(object? sender, FieldChangedEventArgs? e) { - NextVisit = LastVisit.AddDays(_infoDrawer.Content.Interval * 7); + _nextVisit = _lastVisit.AddDays(_company.Interval * 7); /* - * avoid nesting if by assuming ValidVat is false + * avoid nesting if by assuming _validVat is false */ - ValidVat = false; + _validVat = false; /* - * set ValidVat true if validation succeed + * set _validVat true if validation succeed */ - if (VatUtils.ValidateFormat(_infoDrawer.Content.CountryCode, _infoDrawer.Content.VatNumber)) + if (VatUtils.ValidateFormat(_company.CountryCode, _company.VatNumber)) { - ValidVat = true; - EnableActivity = 1; + _validVat = true; + _enableActivity = 1; } StateHasChanged(); @@ -536,13 +550,13 @@ public partial class AdvisorCustomerViewEditPage : IDisposable /// private void ValidationChanged(object sender, ValidationStateChangedEventArgs e) { - ErpContext.OnFieldChanged -= HandleFieldChanged; - ErpContext.OnValidationStateChanged -= ValidationChanged!; + _erpContext.OnFieldChanged -= HandleFieldChanged; + _erpContext.OnValidationStateChanged -= ValidationChanged!; - ErpContext = new EditContext(_infoDrawer.Content); + _erpContext = new EditContext(_company); - ErpContext.OnFieldChanged += HandleFieldChanged; - ErpContext.OnValidationStateChanged += ValidationChanged!; + _erpContext.OnFieldChanged += HandleFieldChanged; + _erpContext.OnValidationStateChanged += ValidationChanged!; } /// @@ -551,7 +565,7 @@ public partial class AdvisorCustomerViewEditPage : IDisposable public void Dispose() { Interceptor.DisposeEvent(); - ErpContext.OnFieldChanged -= HandleFieldChanged; - ErpContext.OnValidationStateChanged -= ValidationChanged!; + _erpContext.OnFieldChanged -= HandleFieldChanged; + _erpContext.OnValidationStateChanged -= ValidationChanged!; } } \ No newline at end of file diff --git a/Wonky.Client/Pages/SystemUserCreatePage.razor b/Wonky.Client/Pages/SystemUserCreatePage.razor index 0c8f29ec..42ea3296 100644 --- a/Wonky.Client/Pages/SystemUserCreatePage.razor +++ b/Wonky.Client/Pages/SystemUserCreatePage.razor @@ -28,59 +28,59 @@
- +
@* firstName *@
- - + +
@* lastName *@
- - + +
@* email *@
- - + +
@* phoneNumber *@
- - + +
@* salesRep *@
- - + +
@* countrycode *@
- + - +
@@ -116,12 +116,12 @@
-
+
@_company.Name - @_company.Account - @_company.Phone
-
@@ -143,14 +143,14 @@
- +
- +
@@ -165,4 +165,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/Wonky.Client/Pages/SystemUserCreatePage.razor.cs b/Wonky.Client/Pages/SystemUserCreatePage.razor.cs index 3f176d81..83bcbba5 100644 --- a/Wonky.Client/Pages/SystemUserCreatePage.razor.cs +++ b/Wonky.Client/Pages/SystemUserCreatePage.razor.cs @@ -38,8 +38,8 @@ public partial class SystemUserCreatePage : IDisposable [Inject] public IToastService Toaster { get; set; } // ############################################################# - private CreateUserInputModel CreateUserInput { get; set; } = new(); - private UserManagerCreateView CreateUserDto { get; set; } = new(); + private NewUserForm UserForm { get; set; } = new(); + private ManagerNewUserDto NewUserDto { get; set; } = new(); private EditContext FormContext { get; set; } private bool ContextInvalid { get; set; } = true; private bool Working { get; set; } = true; @@ -48,55 +48,93 @@ public partial class SystemUserCreatePage : IDisposable private RoleAssignment AssignedRoles { get; set; } = new(); private readonly JsonSerializerOptions _options = new() { PropertyNameCaseInsensitive = true }; - private bool _webShop; private CompanyDto _company = new(); private CustomerSearchOverlay SearchOverlay { get; set; } - protected override void OnParametersSet() + protected override void OnInitialized() { Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - FormContext = new EditContext(CreateUserInput); + FormContext = new EditContext(UserForm); - FormContext.OnFieldChanged += ContextHandleFieldChanged!; + FormContext.OnFieldChanged += ContextHandleFieldChanged; FormContext.OnValidationStateChanged += ContextValidationChanged; + Working = false; } - private async Task CreateUserRequest() + /// + /// Post New User To Backend + /// + private async Task PostNewUser() { - ReadOnly = true; - Working = true; - - CreateUserInput.AssignedRoles = Utils.MapSaveAssignedRoles(AssignedRoles); - CreateUserInput.EShop = _webShop; - CreateUserInput.CompanyId = !_webShop ? "" : _company.CompanyId; - + /* + * UI message + */ Toaster.ShowInfo("Sender data til server ..."); - - CreateUserDto = Mapper.MapCreateUser(CreateUserInput); - - await UserRepo.CreateUser(CreateUserDto); - + /* + * Make fields reaonly + */ + ReadOnly = true; + /* + * Raise working flag + */ + Working = true; + /* + * ensure companyId is set correct + */ + UserForm.CompanyId = !UserForm.EShop ? "" : _company.CompanyId; + /* + * Map RoleAssignment + */ + UserForm.AssignedRoles = Utils.MapSaveAssignedRoles(AssignedRoles); + /* + * Map form input to a model the backend expects + */ + NewUserDto = Mapper.MapCreateUser(UserForm); + /* + * Send Post Request + */ + await UserRepo.PostNewUser(NewUserDto); + /* + * Lower working flag + */ Working = false; + /* + * UI message + */ Toaster.ShowInfo("Bruger er oprettet ..."); } - private void ShowSearchOverlay() + /// + /// Show Company Search Overlay + /// + private void ShowCompanySearchOverlay() { SearchOverlay.Show(); } + + /// + /// Company Selected Callback + /// + /// private void OnSelectCompany(CompanyDto company) { _company = company; - CreateUserInput.CompanyId = _company.CompanyId; + UserForm.CompanyId = _company.CompanyId; SearchOverlay.Hide(); } + + /// + /// Callback Handling Context Field Changes + /// + /// + /// private void ContextHandleFieldChanged(object? sender, FieldChangedEventArgs e) { Logger.LogDebug("contextHandleFieldChanged => e.FieldIdentifier.FieldName {}", e.FieldIdentifier.FieldName); @@ -118,11 +156,11 @@ public partial class SystemUserCreatePage : IDisposable AssignedRoles.Office = false; AssignedRoles.Supervisor = false; AssignedRoles.Warehouse = false; - _webShop = true; + UserForm.EShop = true; } else { - _webShop = false; + UserForm.EShop = false; } ContextInvalid = !FormContext.Validate(); @@ -130,6 +168,11 @@ public partial class SystemUserCreatePage : IDisposable } + /// + /// Callback Handling Context Validation Changes + /// + /// + /// private void ContextValidationChanged(object? sender, ValidationStateChangedEventArgs e) { ContextInvalid = true; @@ -137,17 +180,20 @@ public partial class SystemUserCreatePage : IDisposable FormContext.OnFieldChanged -= ContextHandleFieldChanged; FormContext.OnValidationStateChanged -= ContextValidationChanged; - FormContext = new EditContext(CreateUserInput); + FormContext = new EditContext(UserForm); FormContext.OnFieldChanged += ContextHandleFieldChanged; FormContext.OnValidationStateChanged += ContextValidationChanged; } + /// + /// Dispose + /// public void Dispose() { Interceptor.DisposeEvent(); - FormContext.OnFieldChanged -= ContextHandleFieldChanged!; + FormContext.OnFieldChanged -= ContextHandleFieldChanged; FormContext.OnValidationStateChanged -= ContextValidationChanged; } } \ No newline at end of file diff --git a/Wonky.Client/Program.cs b/Wonky.Client/Program.cs index 2fcd2b14..2f620379 100644 --- a/Wonky.Client/Program.cs +++ b/Wonky.Client/Program.cs @@ -100,9 +100,11 @@ builder.Services.AddScoped(); // activity draft service builder.Services.AddScoped(); // cabinet service -builder.Services.AddScoped(); +builder.Services.AddScoped(); // storage builder.Services.AddBlazoredLocalStorage(); +// Swedisd Personal Company OrgNo Search +builder.Services.AddScoped(); // --------------------------------------- diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 1efff7d2..3b4c30d0 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,15 +1,15 @@ { "appInfo": { "name": "Wonky Online", - "version": "163.0", + "version": "168.1", "rc": true, - "sandBox": true, + "sandBox": false, "image": "grumpy-coder.png" }, "Logging": { "LogLevel": { - "Default": "Debug", - "System": "Debug", + "Default": "None", + "System": "None", "Microsoft": "Information" }, "Debug": { @@ -19,7 +19,7 @@ } }, "apiConfig": { - "baseUrl": "https://dev.innotec.dk", + "baseUrl": "https://zeta.innotec.dk", "catalog": "api/v2/catalog/country", "crmCustomers": "api/v2/crm/companies", "crmInventoryExt": "history/inventory", @@ -42,6 +42,7 @@ "servicesVatDk": "api/v2/services/virk", "serviceVatEu": "api/v2/services/vies", "servicesVatNo": "api/v2/services/brReg", + "servicesVatSe": "api/v2/services/allabolag", "servicesAuth": "v2/token", "sync": "api/v2/sync", "syncInvoice": "api/v2/sync/invoices", diff --git a/Wonky.Entity/Configuration/ApiConfig.cs b/Wonky.Entity/Configuration/ApiConfig.cs index fbd62d58..b3d0e42b 100644 --- a/Wonky.Entity/Configuration/ApiConfig.cs +++ b/Wonky.Entity/Configuration/ApiConfig.cs @@ -132,6 +132,11 @@ public class ApiConfig /// public string ServicesVatNo { get; set; } = ""; + /// + /// VAT registrar url EU + /// + public string ServicesVatSe { get; set; } = ""; + /// /// VAT registrar url EU /// diff --git a/Wonky.Entity/DTO/UserManagerCreateView.cs b/Wonky.Entity/DTO/ManagerNewUserDto.cs similarity index 98% rename from Wonky.Entity/DTO/UserManagerCreateView.cs rename to Wonky.Entity/DTO/ManagerNewUserDto.cs index 0b349336..c76d8878 100644 --- a/Wonky.Entity/DTO/UserManagerCreateView.cs +++ b/Wonky.Entity/DTO/ManagerNewUserDto.cs @@ -19,7 +19,7 @@ using System.ComponentModel.DataAnnotations; namespace Wonky.Entity.DTO; -public class UserManagerCreateView +public class ManagerNewUserDto { [MaxLength(128)] public string CompanyId { get; set; } = "";