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)
{
var company = await _client.GetFromJsonAsync<CompanyDto>($"{_conf.CrmCustomers}/{companyId}");
return company ?? new CompanyDto();
return await _client.GetFromJsonAsync<CompanyDto>($"{_conf.CrmCustomers}/{companyId}");
}
/// <summary>
@ -135,7 +134,7 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
};
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<CompanyDto>(content);
return JsonSerializer.Deserialize<CompanyDto>(content);
}
/// <summary>
@ -161,7 +160,7 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
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<CompanyDto>(content);
return JsonSerializer.Deserialize<CompanyDto>(content);
}
/// <summary>
@ -178,6 +177,6 @@ public class CrmCompanyHttpRepository : ICrmCompanyHttpRepository
};
var response = await _client.PutAsJsonAsync($"{_conf.CrmCustomers}/{companyId}/vat", model, _options);
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>
</div>
@* account and vat number*@
@* account *@
<label for="account" class="col-sm-1 col-form-label-sm">Konto</label>
<div class="col-sm-2">
<input id="account" type="text" class="form-control" readonly value="@Company.Account"/>
</div>
@* vat number*@
<label for="vatNumber" class="col-sm-1 col-form-label-sm">Moms Nr</label>
<div class="col-sm-4">
<div class="input-group">
@ -112,9 +113,11 @@
<ValidationMessage For="@(() => Company.VatNumber)"></ValidationMessage>
</div>
</div>
@* vat lookup *@
<div class="col-sm-2 text-end">
<button type="button" class="btn btn-primary" @onclick="CallVatLookupModal">CVR opslag</button>
</div>
@* save vat number *@
<div class="col-sm-2 text-end">
<button type="button" class="btn btn-primary" @onclick="UpdateVatNumber">Gem Moms Nr</button>
</div>
@ -228,6 +231,6 @@ else
}
<VatLookupDkModal VatAddress="CompanyVatAddress" EntityName="@Company.Name" VatNumber="@Company.VatNumber"
@ref="VatLookupPopup" OnSelectedCompany="OnSelectedCompanyCallback" />
@ref="VatLookupPopup" OnSelectedCompany="SelectCompanyCallback" />
<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]
//
using System.CodeDom.Compiler;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using Blazored.LocalStorage;
using Blazored.Toast.Services;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.DataProtection.Repositories;
using Wonky.Client.Helpers;
using Wonky.Client.HttpInterfaces;
using Wonky.Client.Models;
@ -59,19 +55,13 @@ public partial class CrmCompanyViewPage : IDisposable
private VatAddress CompanyVatAddress = new();
private bool ValidVat;
private bool HasFolded;
private bool FormInvalid = 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;
private List<ContactDto> Contacts { get; set; } = new();
private VatLookupDkModal VatLookupPopup { get; set; } = new();
private ContactDto SelectedContact { get; set; } = new();
@ -147,7 +137,7 @@ public partial class CrmCompanyViewPage : IDisposable
ContactPopup.Show();
}
private async Task SaveContact(ContactDto contact)
private async Task SaveContactCallback(ContactDto contact)
{
Console.WriteLine(JsonSerializer.Serialize(contact));
@ -165,7 +155,7 @@ public partial class CrmCompanyViewPage : IDisposable
SelectedContact = new ContactDto();
}
private async Task DeleteContact(string contactId)
private async Task DeleteContactCallback(string contactId)
{
await ContactRepo.DeleteContact(CompanyId, contactId);
Contacts = await ContactRepo.GetContacts(CompanyId);
@ -183,12 +173,10 @@ public partial class CrmCompanyViewPage : IDisposable
// simple validation of VAT format
if (!VatUtils.ValidateFormat(Company.CountryCode, Company.VatNumber))
{
FormInvalid = true;
ValidVat = false;
}
else
{
FormInvalid = !ErpContext.Validate();
ValidVat = true;
EnableActivity = 1;
}
@ -198,14 +186,11 @@ public partial class CrmCompanyViewPage : IDisposable
private void ValidationChanged(object sender, ValidationStateChangedEventArgs e)
{
FormInvalid = false;
ErpContext.OnFieldChanged -= HandleFieldChanged;
ErpContext.OnValidationStateChanged -= ValidationChanged;
ErpContext = new EditContext(Company);
FormInvalid = ErpContext.Validate();
ErpContext.OnFieldChanged += HandleFieldChanged;
ErpContext.OnValidationStateChanged += ValidationChanged;
}
@ -326,8 +311,10 @@ public partial class CrmCompanyViewPage : IDisposable
/// Modal callback to update company properties
/// </summary>
/// <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
ValidVat = regInfo.States[0].State.ToLower() == "normal";
Company.HasFolded = ValidVat ? 1 : 0;
@ -342,51 +329,12 @@ public partial class CrmCompanyViewPage : IDisposable
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;
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();
// await UpdateVatNumber();
}
/// <summary>

View file

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

View file

@ -47,10 +47,10 @@
<td class="align-middle">@info.Name</td>
<td class="align-middle">@info.States[^1].State</td>
<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 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>
</tr>
}

View file

@ -13,6 +13,7 @@
// 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 Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
@ -42,18 +43,20 @@ public partial class VatLookupDkModal
private string _vatNumber { get; set; } = "";
private string _entityName { get; set; } = "";
protected override void OnParametersSet()
{
protected override Task OnParametersSetAsync() {
_vatAddress = VatAddress;
_entityName = EntityName;
_vatNumber = VatNumber;
return base.OnParametersSetAsync();
}
private async Task SelectCompany(string vatNumber, bool syncAll)
{
CompanyRegInfo = VatInfos.First(x => x.VatNumber == vatNumber);
CompanyRegInfo.SyncAll = syncAll;
Console.WriteLine($"SelectCompany => {JsonSerializer.Serialize(CompanyRegInfo)}");
await OnSelectedCompany.InvokeAsync(CompanyRegInfo);
Hide();
}
private async Task GetInfoFromAddress(VatAddress address)
@ -103,9 +106,6 @@ public partial class VatLookupDkModal
private void Hide()
{
VatAddress = new VatAddress();
CompanyRegInfo = new VirkRegInfo();
VatInfos = new List<VirkRegInfo>();
_modalDisplay = "none;";
_showBackdrop = false;
StateHasChanged();

View file

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