rebuilt v.0.47.4

This commit is contained in:
Frede Hundewadt 2022-11-21 18:53:21 +01:00
parent abfa4ab132
commit b867faf609
7 changed files with 32 additions and 77 deletions

View file

@ -88,8 +88,7 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
public async Task<CompanyDto> GetCompanyById(string companyId) public async Task<CompanyDto> GetCompanyById(string companyId)
{ {
var company = await _client.GetFromJsonAsync<CompanyDto>($"{_conf.CrmCustomers}/{companyId}"); return await _client.GetFromJsonAsync<CompanyDto>($"{_conf.CrmCustomers}/{companyId}");
return company ?? new CompanyDto();
} }
/// <summary> /// <summary>
@ -135,7 +134,7 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
}; };
var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/crmData", updateModel, _options); var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/crmData", updateModel, _options);
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize<CompanyDto>(content); return JsonSerializer.Deserialize<CompanyDto>(content);
} }
/// <summary> /// <summary>
@ -161,7 +160,7 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/erpData", updateModel, _options); var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/erpData", updateModel, _options);
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize<CompanyDto>(content); return JsonSerializer.Deserialize<CompanyDto>(content);
} }
/// <summary> /// <summary>
@ -178,6 +177,6 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
}; };
var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/vat", model, _options); var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/vat", model, _options);
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
return string.IsNullOrWhiteSpace(content) ? new CompanyDto() : JsonSerializer.Deserialize<CompanyDto>(content); return JsonSerializer.Deserialize<CompanyDto>(content);
} }
} }

View file

@ -97,11 +97,12 @@
<button type="button" class="btn btn-primary" onclick="@UpdateErpData" disabled="@(Working)">Gem ERP data</button> <button type="button" class="btn btn-primary" onclick="@UpdateErpData" disabled="@(Working)">Gem ERP data</button>
</div> </div>
@* account and vat number*@ @* account *@
<label for="account" class="col-sm-1 col-form-label-sm">Konto</label> <label for="account" class="col-sm-1 col-form-label-sm">Konto</label>
<div class="col-sm-2"> <div class="col-sm-2">
<input id="account" type="text" class="form-control" readonly value="@Company.Account"/> <input id="account" type="text" class="form-control" readonly value="@Company.Account"/>
</div> </div>
@* vat number*@
<label for="vatNumber" class="col-sm-1 col-form-label-sm">Moms Nr</label> <label for="vatNumber" class="col-sm-1 col-form-label-sm">Moms Nr</label>
<div class="col-sm-4"> <div class="col-sm-4">
<div class="input-group"> <div class="input-group">
@ -112,9 +113,11 @@
<ValidationMessage For="@(() => Company.VatNumber)"></ValidationMessage> <ValidationMessage For="@(() => Company.VatNumber)"></ValidationMessage>
</div> </div>
</div> </div>
@* vat lookup *@
<div class="col-sm-2 text-end"> <div class="col-sm-2 text-end">
<button type="button" class="btn btn-primary" @onclick="CallVatLookupModal">CVR opslag</button> <button type="button" class="btn btn-primary" @onclick="CallVatLookupModal">CVR opslag</button>
</div> </div>
@* save vat number *@
<div class="col-sm-2 text-end"> <div class="col-sm-2 text-end">
<button type="button" class="btn btn-primary" @onclick="UpdateVatNumber">Gem Moms Nr</button> <button type="button" class="btn btn-primary" @onclick="UpdateVatNumber">Gem Moms Nr</button>
</div> </div>
@ -228,6 +231,6 @@ else
} }
<VatLookupDkModal VatAddress="CompanyVatAddress" EntityName="@Company.Name" VatNumber="@Company.VatNumber" <VatLookupDkModal VatAddress="CompanyVatAddress" EntityName="@Company.Name" VatNumber="@Company.VatNumber"
@ref="VatLookupPopup" OnSelectedCompany="OnSelectedCompanyCallback" /> @ref="VatLookupPopup" OnSelectedCompany="SelectCompanyCallback" />
<ContactModal ParamContact="@SelectedContact" CompanyName="@Company.Name" <ContactModal ParamContact="@SelectedContact" CompanyName="@Company.Name"
@ref="ContactPopup" OnSaveClicked="SaveContact" OnDeleteClicked="DeleteContact"/> @ref="ContactPopup" OnSaveClicked="SaveContactCallback" OnDeleteClicked="DeleteContactCallback"/>

View file

@ -13,17 +13,13 @@
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
// //
using System.CodeDom.Compiler;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Blazored.LocalStorage; using Blazored.LocalStorage;
using Blazored.Toast.Services; using Blazored.Toast.Services;
using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.DataProtection.Repositories;
using Wonky.Client.Helpers; using Wonky.Client.Helpers;
using Wonky.Client.HttpInterfaces; using Wonky.Client.HttpInterfaces;
using Wonky.Client.Models; using Wonky.Client.Models;
@ -59,19 +55,13 @@ public partial class CrmCompanyViewPage : IDisposable
private VatAddress CompanyVatAddress = new(); private VatAddress CompanyVatAddress = new();
private bool ValidVat; private bool ValidVat;
private bool HasFolded; private bool HasFolded;
private bool FormInvalid = true;
private string CurrentVat { get; set; } = ""; private string CurrentVat { get; set; } = "";
private string CountryCode { get; set; } = "dk"; private string CountryCode { get; set; } = "dk";
private string VisitState { get; set; } = "the-ugly"; private string VisitState { get; set; } = "the-ugly";
private int EnableActivity { get; set; } = 1; private int EnableActivity { get; set; } = 1;
private bool HideButtons { get; set; }
private string ActionLink { get; set; } = ""; private string ActionLink { get; set; } = "";
private bool Working { get; set; } private bool Working { get; set; }
private string BtnUpdateText { get; set; } = "Opdater";
private bool countryIsDk { get; set; } = true; private bool countryIsDk { get; set; } = true;
private int IsDirty { get; set; }
private int VatUpdated { get; set; }
private bool Loading { get; set; } = true;
private List<ContactDto> Contacts { get; set; } = new(); private List<ContactDto> Contacts { get; set; } = new();
private VatLookupDkModal VatLookupPopup { get; set; } = new(); private VatLookupDkModal VatLookupPopup { get; set; } = new();
private ContactDto SelectedContact { get; set; } = new(); private ContactDto SelectedContact { get; set; } = new();
@ -147,7 +137,7 @@ public partial class CrmCompanyViewPage : IDisposable
ContactPopup.Show(); ContactPopup.Show();
} }
private async Task SaveContact(ContactDto contact) private async Task SaveContactCallback(ContactDto contact)
{ {
Console.WriteLine(JsonSerializer.Serialize(contact)); Console.WriteLine(JsonSerializer.Serialize(contact));
@ -165,7 +155,7 @@ public partial class CrmCompanyViewPage : IDisposable
SelectedContact = new ContactDto(); SelectedContact = new ContactDto();
} }
private async Task DeleteContact(string contactId) private async Task DeleteContactCallback(string contactId)
{ {
await ContactRepo.DeleteContact(CompanyId, contactId); await ContactRepo.DeleteContact(CompanyId, contactId);
Contacts = await ContactRepo.GetContacts(CompanyId); Contacts = await ContactRepo.GetContacts(CompanyId);
@ -183,12 +173,10 @@ public partial class CrmCompanyViewPage : IDisposable
// simple validation of VAT format // simple validation of VAT format
if (!VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber)) if (!VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber))
{ {
FormInvalid = true;
ValidVat = false; ValidVat = false;
} }
else else
{ {
FormInvalid = !ErpContext.Validate();
ValidVat = true; ValidVat = true;
EnableActivity = 1; EnableActivity = 1;
} }
@ -198,14 +186,11 @@ public partial class CrmCompanyViewPage : IDisposable
private void ValidationChanged(object sender, ValidationStateChangedEventArgs e) private void ValidationChanged(object sender, ValidationStateChangedEventArgs e)
{ {
FormInvalid = false;
ErpContext.OnFieldChanged -= HandleFieldChanged; ErpContext.OnFieldChanged -= HandleFieldChanged;
ErpContext.OnValidationStateChanged -= ValidationChanged; ErpContext.OnValidationStateChanged -= ValidationChanged;
ErpContext = new EditContext(Company); ErpContext = new EditContext(Company);
FormInvalid = ErpContext.Validate();
ErpContext.OnFieldChanged += HandleFieldChanged; ErpContext.OnFieldChanged += HandleFieldChanged;
ErpContext.OnValidationStateChanged += ValidationChanged; ErpContext.OnValidationStateChanged += ValidationChanged;
} }
@ -326,8 +311,10 @@ public partial class CrmCompanyViewPage : IDisposable
/// Modal callback to update company properties /// Modal callback to update company properties
/// </summary> /// </summary>
/// <param name="regInfo"></param> /// <param name="regInfo"></param>
private void OnSelectedCompanyCallback(VirkRegInfo regInfo) private async Task SelectCompanyCallback(VirkRegInfo regInfo)
{ {
Console.WriteLine(JsonSerializer.Serialize(regInfo));
// this can be removed in favor of the new data returned from updating the VatNumber // this can be removed in favor of the new data returned from updating the VatNumber
ValidVat = regInfo.States[0].State.ToLower() == "normal"; ValidVat = regInfo.States[0].State.ToLower() == "normal";
Company.HasFolded = ValidVat ? 1 : 0; Company.HasFolded = ValidVat ? 1 : 0;
@ -342,51 +329,12 @@ public partial class CrmCompanyViewPage : IDisposable
Company.Address2 = CompanyRegInfo.CoName; Company.Address2 = CompanyRegInfo.CoName;
Company.ZipCode = CompanyRegInfo.ZipCode; Company.ZipCode = CompanyRegInfo.ZipCode;
Company.City = CompanyRegInfo.City; Company.City = CompanyRegInfo.City;
Toaster.ShowInfo("Husk at gemme firma data", "Påmindelse");
} }
else else
{ {
Company.VatNumber = CompanyRegInfo.VatNumber; Company.VatNumber = CompanyRegInfo.VatNumber;
} }
// Updated properties are returned from API // await UpdateVatNumber();
Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result;
StateHasChanged();
}
/// <summary>
/// Select company and update properties - if applicable (syncAll)
/// To be deprecated in favor of a modal window to do lookup and selection
/// </summary>
/// <param name="vatNumber">Vat Number</param>
/// <param name="syncAll">true/false to update base properties as well as vat number</param>
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;
EnableActivity = ValidVat ? 1 : 0;
VatState = CompanyRegInfo.States[0].State.ToLower() == "normal" ? "the-good" : "the-dead";
if (syncAll)
{
Company.VatNumber = CompanyRegInfo.VatNumber;
Company.Name = CompanyRegInfo.Name;
Company.Address1 = CompanyRegInfo.Address;
Company.Address2 = CompanyRegInfo.CoName;
Company.ZipCode = CompanyRegInfo.ZipCode;
Company.City = CompanyRegInfo.City;
Toaster.ShowInfo("Husk at gemme firma data", "Påmindelse");
}
else
{
Company.VatNumber = CompanyRegInfo.VatNumber;
}
// Updated properties are returned from API
Company = CompanyRepo.UpdateCompanyVat(CompanyId, Company.VatNumber).Result;
// empty list
VatInfos = new List<VirkRegInfo>();
StateHasChanged();
} }
/// <summary> /// <summary>

View file

@ -41,7 +41,7 @@ public partial class ContactModal : IDisposable
private bool DisableDelete { get; set; } private bool DisableDelete { get; set; }
private bool FormInvalid { get; set; } private bool FormInvalid { get; set; }
protected override void OnParametersSet() protected override Task OnParametersSetAsync()
{ {
Contact = new ContactDto Contact = new ContactDto
{ {
@ -52,14 +52,19 @@ public partial class ContactModal : IDisposable
JobTitle = ParamContact.JobTitle, JobTitle = ParamContact.JobTitle,
PhoneDirect = ParamContact.PhoneDirect PhoneDirect = ParamContact.PhoneDirect
}; };
return base.OnParametersSetAsync();
}
protected override Task OnInitializedAsync()
{
if (string.IsNullOrWhiteSpace(Contact.ContactId)) if (string.IsNullOrWhiteSpace(Contact.ContactId))
DisableDelete = true; DisableDelete = true;
Interceptor.RegisterEvent(); Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent(); Interceptor.RegisterBeforeSendEvent();
return base.OnInitializedAsync();
} }
private void DeleteContact() private void DeleteContact()
{ {
OnDeleteClicked.InvokeAsync(Contact.ContactId); OnDeleteClicked.InvokeAsync(Contact.ContactId);

View file

@ -47,10 +47,10 @@
<td class="align-middle">@info.Name</td> <td class="align-middle">@info.Name</td>
<td class="align-middle">@info.States[^1].State</td> <td class="align-middle">@info.States[^1].State</td>
<td class="align-middle"> <td class="align-middle">
<button class="btn btn-primary" @onclick="@(() => SelectCompany(info.VatNumber, true))">OVERFØR</button> <button type="button" class="btn btn-primary" @onclick="@(() => SelectCompany(info.VatNumber, true))">OVERFØR</button>
</td> </td>
<td class="align-middle"> <td class="align-middle">
<button class="btn btn-primary" @onclick="@(() => SelectCompany(info.VatNumber, false))">CVR/VAT</button> <button type="button" class="btn btn-primary" @onclick="@(() => SelectCompany(info.VatNumber, false))">CVR/VAT</button>
</td> </td>
</tr> </tr>
} }

View file

@ -13,6 +13,7 @@
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
// //
using System.Text.Json;
using Blazored.Toast.Services; using Blazored.Toast.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpInterceptors;
@ -42,18 +43,20 @@ public partial class VatLookupDkModal
private string _vatNumber { get; set; } = ""; private string _vatNumber { get; set; } = "";
private string _entityName { get; set; } = ""; private string _entityName { get; set; } = "";
protected override void OnParametersSet() protected override Task OnParametersSetAsync() {
{
_vatAddress = VatAddress; _vatAddress = VatAddress;
_entityName = EntityName; _entityName = EntityName;
_vatNumber = VatNumber; _vatNumber = VatNumber;
return base.OnParametersSetAsync();
} }
private async Task SelectCompany(string vatNumber, bool syncAll) private async Task SelectCompany(string vatNumber, bool syncAll)
{ {
CompanyRegInfo = VatInfos.First(x => x.VatNumber == vatNumber); CompanyRegInfo = VatInfos.First(x => x.VatNumber == vatNumber);
CompanyRegInfo.SyncAll = syncAll; CompanyRegInfo.SyncAll = syncAll;
Console.WriteLine($"SelectCompany => {JsonSerializer.Serialize(CompanyRegInfo)}");
await OnSelectedCompany.InvokeAsync(CompanyRegInfo); await OnSelectedCompany.InvokeAsync(CompanyRegInfo);
Hide();
} }
private async Task GetInfoFromAddress(VatAddress address) private async Task GetInfoFromAddress(VatAddress address)
@ -103,9 +106,6 @@ public partial class VatLookupDkModal
private void Hide() private void Hide()
{ {
VatAddress = new VatAddress();
CompanyRegInfo = new VirkRegInfo();
VatInfos = new List<VirkRegInfo>();
_modalDisplay = "none;"; _modalDisplay = "none;";
_showBackdrop = false; _showBackdrop = false;
StateHasChanged(); StateHasChanged();

View file

@ -1,7 +1,7 @@
{ {
"appInfo": { "appInfo": {
"name": "Wonky Client", "name": "Wonky Client",
"version": "0.47.1", "version": "0.47.4",
"rc": true, "rc": true,
"sandBox": false, "sandBox": false,
"image": "grumpy-coder.png" "image": "grumpy-coder.png"