From abfa4ab1325d93b6dd898bfd9f9460dd44152fd2 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Mon, 21 Nov 2022 15:22:28 +0100 Subject: [PATCH] finalize endpoint split - v.0.47.1 - api v.2.22.325.1408 --- .../Components/VatAddressInputComponent.razor | 27 +- .../VatAddressInputComponent.razor.cs | 21 +- .../VatCompanyNameInputComponent.razor | 17 +- .../VatCompanyNameInputComponent.razor.cs | 19 +- .../Components/VatNumberInputComponent.razor | 19 +- .../VatNumberInputComponent.razor.cs | 23 +- .../ICrmCompanyHttpRepository.cs | 39 +- .../CrmCompanyHttpRepository.cs | 40 +- .../Pages/CrmActivityNewPage.razor.cs | 22 +- Wonky.Client/Pages/CrmCompanyViewPage.razor | 376 ++++++++---------- .../Pages/CrmCompanyViewPage.razor.cs | 150 +++---- Wonky.Client/Shared/ContactModal.razor.cs | 7 +- Wonky.Client/Shared/VatLookupDkModal.razor | 10 +- Wonky.Client/Shared/VatLookupDkModal.razor.cs | 55 ++- Wonky.Client/wwwroot/appsettings.json | 4 +- Wonky.Entity/DTO/UpdateCrmDto.cs | 13 + Wonky.Entity/DTO/UpdateErpDto.cs | 16 + 17 files changed, 444 insertions(+), 414 deletions(-) create mode 100644 Wonky.Entity/DTO/UpdateCrmDto.cs create mode 100644 Wonky.Entity/DTO/UpdateErpDto.cs diff --git a/Wonky.Client/Components/VatAddressInputComponent.razor b/Wonky.Client/Components/VatAddressInputComponent.razor index 90b99462..2057fe70 100644 --- a/Wonky.Client/Components/VatAddressInputComponent.razor +++ b/Wonky.Client/Components/VatAddressInputComponent.razor @@ -15,27 +15,26 @@ // *@ - + -
- -
- +
+ +
+
-
- + +
+
-
- + +
+
-
- +
+
\ No newline at end of file diff --git a/Wonky.Client/Components/VatAddressInputComponent.razor.cs b/Wonky.Client/Components/VatAddressInputComponent.razor.cs index 1879ccc3..a137e226 100644 --- a/Wonky.Client/Components/VatAddressInputComponent.razor.cs +++ b/Wonky.Client/Components/VatAddressInputComponent.razor.cs @@ -19,31 +19,20 @@ using Microsoft.AspNetCore.Components.Forms; using Wonky.Client.Models; namespace Wonky.Client.Components; -public partial class VatAddressInputComponent : IDisposable +public partial class VatAddressInputComponent { [Parameter] public VatAddress Address { get; set; } private EditContext _editContext { get; set; } - private bool _formInvalid = true; + private VatAddress _address { get; set; } [Parameter] public EventCallback OnValidSubmit { get; set; } - protected override void OnInitialized() + protected override void OnParametersSet() { - _editContext = new EditContext(Address); - _editContext.OnFieldChanged += HandleFieldChanged; + _address = Address; + _editContext = new EditContext(_address); } - private async Task SubmitForm() { await OnValidSubmit.InvokeAsync(Address); } - private void HandleFieldChanged(object? sender, FieldChangedEventArgs e) - { - _formInvalid = !_editContext.Validate(); - StateHasChanged(); - } - - public void Dispose() - { - _editContext.OnFieldChanged -= HandleFieldChanged; - } } \ No newline at end of file diff --git a/Wonky.Client/Components/VatCompanyNameInputComponent.razor b/Wonky.Client/Components/VatCompanyNameInputComponent.razor index 091635ba..2176fc38 100644 --- a/Wonky.Client/Components/VatCompanyNameInputComponent.razor +++ b/Wonky.Client/Components/VatCompanyNameInputComponent.razor @@ -15,17 +15,16 @@ // *@ - + -
- -
- - +
+ +
+ +
-
- +
+
\ No newline at end of file diff --git a/Wonky.Client/Components/VatCompanyNameInputComponent.razor.cs b/Wonky.Client/Components/VatCompanyNameInputComponent.razor.cs index a638f01d..06046779 100644 --- a/Wonky.Client/Components/VatCompanyNameInputComponent.razor.cs +++ b/Wonky.Client/Components/VatCompanyNameInputComponent.razor.cs @@ -19,29 +19,18 @@ using Microsoft.AspNetCore.Components.Forms; using Wonky.Client.Models; namespace Wonky.Client.Components; -public partial class VatCompanyNameInputComponent : IDisposable +public partial class VatCompanyNameInputComponent { [Parameter] public string CompanyName { get; set; } = ""; - private EditContext _editName { get; set; } - private bool _formInvalid = true; + [Required(ErrorMessage = "Navn kan ikke være tomt")] private string _companyName { get; set; } = ""; [Parameter] public EventCallback OnValidSubmit { get; set; } - protected override void OnInitialized() + protected override void OnParametersSet() { - _editName = new EditContext(CompanyName); - _editName.OnFieldChanged += HandleFieldChanged; + _companyName = CompanyName; } private async Task SubmitForm() { await OnValidSubmit.InvokeAsync(CompanyName); } - private void HandleFieldChanged(object? sender, FieldChangedEventArgs e) - { - _formInvalid = !_editName.Validate(); - StateHasChanged(); - } - public void Dispose() - { - _editName!.OnFieldChanged -= HandleFieldChanged; - } } \ No newline at end of file diff --git a/Wonky.Client/Components/VatNumberInputComponent.razor b/Wonky.Client/Components/VatNumberInputComponent.razor index fbbe119e..0bde2839 100644 --- a/Wonky.Client/Components/VatNumberInputComponent.razor +++ b/Wonky.Client/Components/VatNumberInputComponent.razor @@ -15,18 +15,17 @@ // *@ - + -
-
CVR/ORG
-
- - +
+
CVR/ORG
+
+ +
-
-
- +
+
+
\ No newline at end of file diff --git a/Wonky.Client/Components/VatNumberInputComponent.razor.cs b/Wonky.Client/Components/VatNumberInputComponent.razor.cs index af72c5ad..e1451abb 100644 --- a/Wonky.Client/Components/VatNumberInputComponent.razor.cs +++ b/Wonky.Client/Components/VatNumberInputComponent.razor.cs @@ -19,29 +19,20 @@ using Microsoft.AspNetCore.Components.Forms; using Wonky.Client.Models; namespace Wonky.Client.Components; -public partial class VatNumberInputComponent : IDisposable +public partial class VatNumberInputComponent { [Parameter] public string VatNumber { get; set; } = ""; - private EditContext _editVatNumber { get; set; } - private bool _formInvalid = true; - + [Required(ErrorMessage = "Moms Nummer skal angives")][MinLength(8, ErrorMessage = "Mindst 8 tegn")] private string _vatNumber { get; set; } = ""; + [Parameter] public EventCallback OnValidSubmit { get; set; } - protected override void OnInitialized() + + protected override void OnParametersSet() { - _editVatNumber = new EditContext(VatNumber); - _editVatNumber.OnFieldChanged += HandleFieldChanged; + _vatNumber = VatNumber; } + private async Task SubmitForm() { await OnValidSubmit.InvokeAsync(VatNumber); } - private void HandleFieldChanged(object? sender, FieldChangedEventArgs e) - { - _formInvalid = !_editVatNumber!.Validate(); - StateHasChanged(); - } - public void Dispose() - { - _editVatNumber!.OnFieldChanged -= HandleFieldChanged; - } } \ No newline at end of file diff --git a/Wonky.Client/HttpInterfaces/ICrmCompanyHttpRepository.cs b/Wonky.Client/HttpInterfaces/ICrmCompanyHttpRepository.cs index 4292d62e..4c90faab 100644 --- a/Wonky.Client/HttpInterfaces/ICrmCompanyHttpRepository.cs +++ b/Wonky.Client/HttpInterfaces/ICrmCompanyHttpRepository.cs @@ -21,12 +21,49 @@ namespace Wonky.Client.HttpInterfaces; public interface ICrmCompanyHttpRepository { + /// + /// Get a list of CRM entities + /// + /// + /// A paged response defined by pagingParameters Task> GetCompanies(CompanyPagingParams pagingParameters); + /// + /// Get CRM entity by Id + /// + /// + /// A CRM Company entity Task GetCompanyById(string companyId); + /// + /// Create new CRM entity + /// + /// + /// The Id of the entity Task CreateCompany(CompanyDto model); - Task UpdateCompany(string companyId, CompanyDto model); + /// + /// Delete the CRM entity + /// + /// + /// true/false to define success Task DeleteCompany(string companyId); + /// + /// Update CRM entity properties + /// + /// + /// + /// A CRM Company entity Task UpdateCrmData(string companyId, CompanyDto model); + /// + /// Update ERP entity properties + /// + /// + /// + /// A CRM Company entity Task UpdateErpData(string companyId, CompanyDto model); + /// + /// Update Entity Vat Number + /// + /// + /// + /// A CRM Company entity Task UpdateCompanyVat(string companyId, string vatNumber); } \ No newline at end of file diff --git a/Wonky.Client/HttpRepository/CrmCompanyHttpRepository.cs b/Wonky.Client/HttpRepository/CrmCompanyHttpRepository.cs index 53699839..d77f0b00 100644 --- a/Wonky.Client/HttpRepository/CrmCompanyHttpRepository.cs +++ b/Wonky.Client/HttpRepository/CrmCompanyHttpRepository.cs @@ -104,19 +104,6 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository var result = JsonSerializer.Deserialize(content, _options); return result.CompanyId; } - - /// - /// Update company card - /// - /// - /// - /// - public async Task UpdateCompany(string companyId, CompanyDto model) - { - var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}", model); - var content = await response.Content.ReadAsStringAsync(); - return response.IsSuccessStatusCode; - } /// /// Delete company @@ -137,7 +124,16 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository /// public async Task UpdateCrmData(string companyId, CompanyDto model) { - var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/crmData", model, _options); + var updateModel = new UpdateCrmDto + { + Interval = model.Interval, + Note = model.Note, + CrmNotes = model.CrmNotes, + IsHidden = model.IsHidden, + LastVisit = model.LastVisit, + NextVisit = model.NextVisit + }; + var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/crmData", updateModel, _options); var content = await response.Content.ReadAsStringAsync(); return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize(content); } @@ -150,7 +146,20 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository /// public async Task UpdateErpData(string companyId, CompanyDto model) { - var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/erpData", model, _options); + var updateModel = new UpdateErpDto + { + Address1 = model.Address1, + Address2 = model.Address2, + Attention = model.Attention, + City = model.City, + Email = model.Email, + Mobile = model.Mobile, + Name = model.Name, + Phone = model.Phone, + ZipCode = model.ZipCode + }; + + var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/erpData", updateModel, _options); var content = await response.Content.ReadAsStringAsync(); return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize(content); } @@ -171,5 +180,4 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository var content = await response.Content.ReadAsStringAsync(); return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize(content); } - } \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmActivityNewPage.razor.cs b/Wonky.Client/Pages/CrmActivityNewPage.razor.cs index e3118b1c..40656e64 100644 --- a/Wonky.Client/Pages/CrmActivityNewPage.razor.cs +++ b/Wonky.Client/Pages/CrmActivityNewPage.razor.cs @@ -213,10 +213,13 @@ public partial class CrmActivityNewPage : IDisposable /// private async Task CreateActivity() { + // disable submit button to avoid multiple clicks + PoFormInvalid = true; if (string.IsNullOrWhiteSpace(Activity.Address1)) { Toast.ShowError("Kunde adresse er ufuldstændig."); + PoFormInvalid = false; return; } @@ -224,27 +227,24 @@ public partial class CrmActivityNewPage : IDisposable { if (DraftStateProvider.Draft.Items.Count == 0) { - Toast.ShowError("Ved bestilling skal der angives et eller flere varenumre."); + Toast.ShowError("Ved bestilling skal der være en eller flere linjer i kladden."); + PoFormInvalid = false; return; } - - if (string.IsNullOrWhiteSpace(Activity.Phone)) + if (Company.Account is "NY" or "" && string.IsNullOrWhiteSpace(Activity.Phone)) { Toast.ShowError("Ved bestilling til ny kunde skal telefon nummer angives."); + PoFormInvalid = false; return; } } - - PoFormInvalid = true; // reset selected item SelectedItem = new SalesItemView(); // check if phone number need to be updated if (OldPhone != Activity.Phone) { Company.Phone = Activity.Phone; - // update company phone record - Logger.LogDebug("CrmNewActivityPage => \n New Phone Number \n {}", Activity.Phone); - await CompanyRepo.UpdateCompany(Company.CompanyId, Company); + await CompanyRepo.UpdateErpData(Company.CompanyId, Company); } // begin assembling activity Activity.ActivityDate = $"{SelectedDate:yyyy-MM-dd}"; @@ -284,10 +284,10 @@ public partial class CrmActivityNewPage : IDisposable // show result message if (result.IsSuccess) { - Toast.ShowSuccess($"{result.Message}", "RESULTAT"); - await DraftStateProvider.DeleteDraftAsync(); + Toast.ShowSuccess($"{result.Message}", + DraftStateProvider.Draft.Items.Count == 0 ? "Besøg er oprettet" : "Bestilling er oprettet"); + await DeleteDraft(); Navigator.NavigateTo($"/companies"); - return; } PoFormInvalid = false; diff --git a/Wonky.Client/Pages/CrmCompanyViewPage.razor b/Wonky.Client/Pages/CrmCompanyViewPage.razor index 046a10e0..f5c5ffcb 100644 --- a/Wonky.Client/Pages/CrmCompanyViewPage.razor +++ b/Wonky.Client/Pages/CrmCompanyViewPage.razor @@ -32,238 +32,202 @@

@Company.Name

- - -
- -
- - -
- -
- - -
+ // erp context + + +
+ @* Company Name *@ + +
+ + +
+ @* Company Attention *@ + +
+ + +
+ @* Address 1 *@ + +
+ + +
+ @* Address 2 *@ + +
+ + +
+ @* Post Code *@ + +
+ + +
+ @* City Name *@ + +
+ + +
+ @* Phone *@ + +
+ + +
+ @* Mobile *@ + +
+ + +
+ @* Email *@ + +
+ + +
+
+ +
+
+
-
- -
- - -
- -
- - + @* account and vat number*@ + +
+ +
+ +
+
+ + + + +
- -
- -
- - -
- -
- - -
+
+
- -
- -
- - -
- -
- - -
+
+
+
-
- -
- - -
+
+ @* activity buttons *@ +
+ - - - -
- - @* vat context *@ - -
- -
-
- - - - - -
-
- -
- -
+
+ Besøg
- - @* erp context *@ - -
- -
- @if (string.IsNullOrWhiteSpace(Company.Note)) - { - - } - else - { - - } - -
+ - -
- -
-
- - - - -
-
- -
- -
- -
- - -
+
+ +
+
-
- -
-
-
-
-
Stilling
-
Navn
-
Direkte
-
- -
+
+ @* crm context - OBS note *@ +
+ +
+ @if (string.IsNullOrWhiteSpace(Company.Note)) + { + + } + else + { + + } + +
+ @* Save CRM data button *@ +
+ +
+
+ @* crm context - contacts *@ +
+ +
+
+
+
+
Stilling
+
Navn
+
Direkte
+
+
- @if (Contacts.Any()) +
+ @if (Contacts.Any()) + { + @foreach (var contact in Contacts) { - @foreach (var contact in Contacts) - { -
-
-
@contact.JobTitle
-
@contact.FirstName @contact.LastName
-
@contact.PhoneDirect
-
- -
+
+
+
@contact.JobTitle
+
@contact.FirstName @contact.LastName
+
@contact.PhoneDirect
+
+
- } +
} -
-
- -
- -
-
- -
-
- Faktura -
-
- Besøg -
-
- Produkter -
-
- - @if (Company.HasFolded == 1) - { - }
-
- - +
+ +
+ +
+
+ @* crm context - dates and interval *@ +
+ +
+
+ + + +
+ +
+ +
+ +
+ + +
+
- - @if (Dk) - { -
-

CVR adresse kontrol

-
- - @if (VatInfos.Any()) - { - - - - - - - - - - - - @foreach (var info in VatInfos) - { - - - - - - - - } - -
CVR ORGNavnStatus
@info.VatNumber@info.Name@info.States[^1].State - - - -
- } -
-
- } } else { } - - \ No newline at end of file + + \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs b/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs index 633c8aa2..199ed752 100644 --- a/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs +++ b/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs @@ -51,7 +51,6 @@ public partial class CrmCompanyViewPage : IDisposable private readonly JsonSerializerOptions _options = new () { PropertyNameCaseInsensitive = true }; private CompanyDto Company { get; set; } = new(); private EditContext ErpContext { get; set; } - private EditContext CrmContext { get; set; } private List VatInfos { get; set; } = new(); private VirkRegInfo CompanyRegInfo { get; set; } = new(); private DateTime LastVisit { get; set; } @@ -61,15 +60,15 @@ public partial class CrmCompanyViewPage : IDisposable private bool ValidVat; private bool HasFolded; private bool FormInvalid = true; - private string CurrentOrgVat; - private string CountryCode = "dk"; - private string VisitState = "the-ugly"; - private int EnableActivity = 1; - private bool HideButtons = false; - private string ActionLink = ""; - private bool Working; - private string BtnUpdateText = "Opdater"; - private bool Dk { get; set; } = true; + 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 HideButtons { get; set; } + private string ActionLink { get; set; } = ""; + private bool Working { get; set; } + private string BtnUpdateText { get; set; } = "Opdater"; + private bool countryIsDk { get; set; } = true; private int IsDirty { get; set; } private int VatUpdated { get; set; } private bool Loading { get; set; } = true; @@ -84,20 +83,20 @@ public partial class CrmCompanyViewPage : IDisposable DefaultContact = new ContactDto { CompanyId = CompanyId, ContactId = "", FirstName = ""}; var ux = await Storage.GetItemAsync("_xu"); CountryCode = ux.CountryCode; - Dk = ux.CountryCode.ToLower() == "dk"; + countryIsDk = ux.CountryCode.ToLower() == "dk"; Company = await CompanyRepo.GetCompanyById(CompanyId); Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); - // Company = await _companyRepo.GetCompanyById(CompanyId); - CurrentOrgVat = Company.VatNumber; + CurrentVat = Company.VatNumber; Company.CountryCode = ux.CountryCode.ToLower(); + // internal flag EnableActivity = Company.ValidVat; // override if canvas which has account property as empty string or "NY" if (Company.Account == "NY" || string.IsNullOrWhiteSpace(Company.Account)) EnableActivity = 1; - if (Dk) + if (countryIsDk) CompanyVatAddress = PrepareVatAddress(Company); if (Company.Interval == 0) @@ -116,25 +115,23 @@ public partial class CrmCompanyViewPage : IDisposable ActionLink = $"/companies/{CompanyId}/activities/new"; // used when drawing visit button if(Company.HasFolded == 1) { - // this is only used if user has selected to show all customers + // this is only used if user has selected to show closed companies HasFolded = true; VatState = "the-dead"; VisitState = "the-dead"; } else { - // simple format validation if CRM indicates invalid vatNumber - if (Company.ValidVat == 0 && !string.IsNullOrWhiteSpace(Company.VatNumber)) - Company.ValidVat = VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber) ? 1 : 0; - // flags - ValidVat = Company.ValidVat == 1; // flag set if company has a valid vatNumber + // valid vat enum + Company.ValidVat = VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber) ? 1 : 0; + // valid vat flag + ValidVat = Company.ValidVat == 1; // true/false flag set if company has a valid vatNumber + // vat state css class VatState = Company.ValidVat == 1 ? "the-good" : "no-vat"; // assign css class } ErpContext = new EditContext(Company); ErpContext.OnFieldChanged += HandleFieldChanged; ErpContext.OnValidationStateChanged += ValidationChanged; - - await SyncCompanyHistory(); Contacts = await ContactRepo.GetContacts(CompanyId); } @@ -195,8 +192,6 @@ public partial class CrmCompanyViewPage : IDisposable ValidVat = true; EnableActivity = 1; } - if(VatUpdated == 0 && e.FieldIdentifier.FieldName != "Note" && e.FieldIdentifier.FieldName != "CrmNotes") - IsDirty = 1; StateHasChanged(); } @@ -215,66 +210,60 @@ public partial class CrmCompanyViewPage : IDisposable ErpContext.OnValidationStateChanged += ValidationChanged; } - private async Task UpdateCrmData() + /// + /// Update CRM data ( + /// + /// true/false + private async Task UpdateCrmData() { Toaster.ShowInfo("Vent venligst ...", "Opdaterer CRM data"); - - Working = true; - Company.LastVisit = $"{LastVisit:yyyy-MM-dd}"; Company.NextVisit = $"{NextVisit:yyyy-MM-dd}"; Company.IsHidden = 0; - - Company = await CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber); - StateHasChanged(); - return true; + var result = await CompanyRepo.UpdateCrmData(CompanyId, Company); + if (!string.IsNullOrWhiteSpace(result.Name)) + { + Company = result; + } } - private async Task UpdateErpData() + /// + /// Update ERP data + /// + /// + private async Task UpdateErpData() { - Working = true; - Toaster.ShowInfo("Vent venligst ...", "Opdaterer Erp data"); - Company = await CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber); - StateHasChanged(); - - Working = false; - return true; + var result = await CompanyRepo.UpdateErpData(CompanyId, Company); + if (!string.IsNullOrWhiteSpace(result.Name)) + { + Company = result; + } } - private async Task UpdateVatNumber() + /// + /// Update Vat Number + /// + /// true/false + private async Task UpdateVatNumber() { // simple format validation if CRM indicates invalid vatNumber if (!VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber)) { - Toaster.ShowError($"CVR/VAT/ORG nummer mangler eller er ugyldig."); - StateHasChanged(); - return false; + Toaster.ShowError($"Moms Nummer ugyldigt"); } - Working = true; - Toaster.ShowInfo("Vent venligst ...", "Opdaterer Moms Nr"); - Company = await CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber); - StateHasChanged(); - - Working = false; - return true; - } - - private async Task SubmitUpdate() - { - if (!await UpdateCrmData()) + var result = await CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber); + if (!string.IsNullOrWhiteSpace(result.Name)) { - Toaster.ShowError("CRM data opdatering fejlede."); - return; - } - - if (!await UpdateErpData()) - { - Toaster.ShowError("ERP data opdatering fejlede."); + Company = result; } } + /// + /// Get vat info from known address + /// + /// private async Task GetInfoFromAddress(VatAddress address) { Toaster.ShowInfo("Vent for adresse info ..."); @@ -291,6 +280,11 @@ public partial class CrmCompanyViewPage : IDisposable } } + /// + /// Prepare vat address from company model + /// + /// + /// private static VatAddress PrepareVatAddress(CompanyDto model) { var digits = "1234567890".ToCharArray(); @@ -320,13 +314,21 @@ public partial class CrmCompanyViewPage : IDisposable return new VatAddress(); } + /// + /// Show Vat Lookup modal + /// private void CallVatLookupModal() { VatLookupPopup.Show(); } - private void OnSelectedCompany(VirkRegInfo regInfo) + /// + /// Modal callback to update company properties + /// + /// + private void OnSelectedCompanyCallback(VirkRegInfo regInfo) { + // this can be removed in favor of the new data returned from updating the VatNumber ValidVat = regInfo.States[0].State.ToLower() == "normal"; Company.HasFolded = ValidVat ? 1 : 0; EnableActivity = ValidVat ? 1 : 0; @@ -340,18 +342,26 @@ public partial class CrmCompanyViewPage : IDisposable Company.Address2 = CompanyRegInfo.CoName; Company.ZipCode = CompanyRegInfo.ZipCode; Company.City = CompanyRegInfo.City; - IsDirty = 1; + Toaster.ShowInfo("Husk at gemme firma data", "Påmindelse"); } else { Company.VatNumber = CompanyRegInfo.VatNumber; - Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result; } + // Updated properties are returned from API + Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result; StateHasChanged(); } + /// + /// Select company and update properties - if applicable (syncAll) + /// To be deprecated in favor of a modal window to do lookup and selection + /// + /// Vat Number + /// true/false to update base properties as well as vat number private void SelectCompany(string vatNumber, bool syncAll) { + // this can be reomved in f CompanyRegInfo = (from x in VatInfos where x.VatNumber == vatNumber select x).First(); ValidVat = CompanyRegInfo.States[0].State.ToLower() == "normal"; Company.HasFolded = ValidVat ? 1 : 0; @@ -366,18 +376,22 @@ public partial class CrmCompanyViewPage : IDisposable Company.Address2 = CompanyRegInfo.CoName; Company.ZipCode = CompanyRegInfo.ZipCode; Company.City = CompanyRegInfo.City; - IsDirty = 1; + Toaster.ShowInfo("Husk at gemme firma data", "Påmindelse"); } else { Company.VatNumber = CompanyRegInfo.VatNumber; - Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result; } + // Updated properties are returned from API + Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result; // empty list VatInfos = new List(); StateHasChanged(); } + /// + /// Dispose + /// public void Dispose() { Interceptor.DisposeEvent(); diff --git a/Wonky.Client/Shared/ContactModal.razor.cs b/Wonky.Client/Shared/ContactModal.razor.cs index 88a14045..af25833c 100644 --- a/Wonky.Client/Shared/ContactModal.razor.cs +++ b/Wonky.Client/Shared/ContactModal.razor.cs @@ -55,14 +55,11 @@ public partial class ContactModal : IDisposable if (string.IsNullOrWhiteSpace(Contact.ContactId)) DisableDelete = true; - } - - protected override void OnInitialized() - { + Interceptor.RegisterEvent(); Interceptor.RegisterBeforeSendEvent(); } - + private void DeleteContact() { OnDeleteClicked.InvokeAsync(Contact.ContactId); diff --git a/Wonky.Client/Shared/VatLookupDkModal.razor b/Wonky.Client/Shared/VatLookupDkModal.razor index defff5ca..717e4f44 100644 --- a/Wonky.Client/Shared/VatLookupDkModal.razor +++ b/Wonky.Client/Shared/VatLookupDkModal.razor @@ -24,10 +24,10 @@