update existing company from registry (vat number or address)

This commit is contained in:
Frede Hundewadt 2022-03-18 17:23:24 +01:00
parent ad580c5f0d
commit 7bbb1529dd
5 changed files with 195 additions and 84 deletions

View file

@ -2,7 +2,7 @@ namespace Wonky.Client;
public class AppId
{
public string Version { get; set; } = "0.2.4";
public string Version { get; set; } = "0.2.6";
public string Name { get; set; } = "Wonky Online";
public bool IsBeta { get; set; } = false;

View file

@ -22,7 +22,6 @@
@foreach (var company in Companies)
{
<div class="row p-2 mb-1 border-bottom">
<div class="col-sm-1"><RegStateVatNumber VatNumber="@company.VatNumber" /></div>
<div class="col-sm-4">@company.Name</div>
<div class="col-sm-2">@company.Account</div>
<div class="col-sm-4">@company.City</div>

View file

@ -17,96 +17,139 @@
@page "/company/{account}/update"
@using Microsoft.AspNetCore.Authorization
@using Wonky.Client.Components
@using Microsoft.AspNetCore.Components
@attribute [Authorize(Roles = "Adviser")]
@using Wonky.Client.Components
@if (_companyDto != null)
{
<div class="card">
<div class="card-body">
<EditForm EditContext="_editContext" OnValidSubmit="Update" class="card card-body bg-light mt-5">
<DataAnnotationsValidator/>
<div class="form-group row mb-2">
<label for="name" class="col-md-2 col-form-label">Firmanavn</label>
<div class="col-md-10">
<InputText id="name" class="form-control" @bind-Value="_companyDto.Name"/>
<ValidationMessage For="@(() => _companyDto.Name)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-2">
<label for="address1" class="col-md-2 col-form-label">Adresse</label>
<div class="col-md-10">
<InputText id="address1" class="form-control" @bind-Value="_companyDto.Address1"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="address2" class="col-md-2 col-form-label">Adresse</label>
<div class="col-md-10">
<InputText id="address2" class="form-control" @bind-Value="_companyDto.Address2"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="zipCode" class="col-md-2 col-form-label">Postnr</label>
<div class="col-md-10">
<InputText id="zipCode" class="form-control" @bind-Value="_companyDto.ZipCode"/>
<ValidationMessage For="@(() => _companyDto.ZipCode)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-2">
<label for="city" class="col-md-2 col-form-label">Bynavn</label>
<div class="col-md-10">
<InputText id="city" class="form-control" @bind-Value="_companyDto.City"/>
<ValidationMessage For="@(() => _companyDto.City)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-2">
<label for="vatNumber" class="col-md-2 col-form-label">CVR/ORG</label>
<div class="col-md-10">
<InputText id="vatNumber" class="form-control" @bind-Value="_companyDto.VatNumber"/>
<ValidationMessage For="@(() => _companyDto.VatNumber)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-2">
<label for="phone" class="col-md-2 col-form-label">Telefon nummer</label>
<div class="col-md-10">
<InputText id="phone" class="form-control" @bind-Value="_companyDto.Phone"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="mobile" class="col-md-2 col-form-label">Mobil nummer</label>
<div class="col-md-10">
<InputText id="mobile" class="form-control" @bind-Value="_companyDto.Mobile"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="email" class="col-md-2 col-form-label">Email</label>
<div class="col-md-10">
<InputText id="email" class="form-control" @bind-Value="_companyDto.Email"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="attention" class="col-md-2 col-form-label">Attention</label>
<div class="col-md-10">
<InputText id="attention" class="form-control" @bind-Value="_companyDto.Attention"/>
</div>
</div>
<div class="row mb-2">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-success" disabled="@_formInvalid">GEM</button>
</div>
</div>
</EditForm>
<div class="row mb-2">
<div class="col">
<VatNumberInputComponent OnValidSubmit="GetInfoFromVat" />
</div>
</div>
<div class="card-footer">
<div class="row align-content-end">
<div class="col align-items-end">
<a class="btn btn-primary" href="/companies">Tilbage</a>
<div class="row mb-2">
<div class="col">
<VatAddressInputComponent OnValidSubmit="GetInfoFromAddress" />
@if (VInfos.Any())
{
@foreach (var info in VInfos)
{
<div class="row">
<div class="col">
@info.VatNumber
</div>
<div class="col">
@info.Name
</div>
<div class="col">
@info.States[^1].State
</div>
<div class="col">
<button class="btn btn-primary" @onclick="@(() => SelectCompany(info.VatNumber))">OVERFØR</button>
</div>
</div>
}
}
</div>
</div>
<div class="card">
<div class="card-body">
<EditForm EditContext="_editContext" OnValidSubmit="Update" class="card card-body bg-light mt-5">
<DataAnnotationsValidator/>
<div class="form-group row mb-2">
<label for="name" class="col-md-2 col-form-label">Firmanavn</label>
<div class="col-md-10">
<InputText id="name" class="form-control" @bind-Value="_companyDto.Name"/>
<ValidationMessage For="@(() => _companyDto.Name)" />
</div>
</div>
<div class="form-group row mb-2">
<label for="address1" class="col-md-2 col-form-label">Adresse</label>
<div class="col-md-10">
<InputText id="address1" class="form-control" @bind-Value="_companyDto.Address1"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="address2" class="col-md-2 col-form-label">Adresse</label>
<div class="col-md-10">
<InputText id="address2" class="form-control" @bind-Value="_companyDto.Address2"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="zipCode" class="col-md-2 col-form-label">Postnr</label>
<div class="col-md-10">
<InputText id="zipCode" class="form-control" @bind-Value="_companyDto.ZipCode"/>
<ValidationMessage For="@(() => _companyDto.ZipCode)" />
</div>
</div>
<div class="form-group row mb-2">
<label for="city" class="col-md-2 col-form-label">Bynavn</label>
<div class="col-md-10">
<InputText id="city" class="form-control" @bind-Value="_companyDto.City"/>
<ValidationMessage For="@(() => _companyDto.City)"></ValidationMessage>
</div>
</div>
<div class="form-group row mb-2">
<label for="vatNumber" class="col-md-2 col-form-label">CVR/ORG</label>
<div class="col-md-10">
<InputText id="vatNumber" class="form-control" @bind-Value="_companyDto.VatNumber"/>
<ValidationMessage For="@(() => _companyDto.VatNumber)" />
</div>
</div>
<div class="form-group row mb-2">
<label for="phone" class="col-md-2 col-form-label">Telefon nummer</label>
<div class="col-md-10">
<InputText id="phone" class="form-control" @bind-Value="_companyDto.Phone"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="mobile" class="col-md-2 col-form-label">Mobil nummer</label>
<div class="col-md-10">
<InputText id="mobile" class="form-control" @bind-Value="_companyDto.Mobile"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="email" class="col-md-2 col-form-label">Email</label>
<div class="col-md-10">
<InputText id="email" class="form-control" @bind-Value="_companyDto.Email"/>
</div>
</div>
<div class="form-group row mb-2">
<label for="attention" class="col-md-2 col-form-label">Attention</label>
<div class="col-md-10">
<InputText id="attention" class="form-control" @bind-Value="_companyDto.Attention" />
</div>
</div>
<div class="form-group">
<label for="lastVisit" class="col-form-label">Sidste besøg</label>
<input type="date" id="lastVisit" class="form-control" value="@LastVisit"
@onchange="@(e => LastVisitChanged(DateTime.Parse(e.Value.ToString())))"/>
</div>
<div class="form-group">
<label for="nextVisit" class="col-form-label">Næste besøg</label>
<input type="date" id="nextVisit" class="form-control" value="@NextVisit"
@onchange="@(e => NextVisitChanged(DateTime.Parse(e.Value.ToString())))"/>
</div>
<div class="form-group">
<label for="interval">Interval</label>
<InputNumber id="interval" class="form-control" @bind-Value="_companyDto.Interval" />
</div>
<div class="row mb-2">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-success" disabled="@_formInvalid">GEM</button>
</div>
</div>
</EditForm>
</div>
<div class="card-footer">
<div class="row align-content-end">
<div class="col align-items-end">
<a class="btn btn-primary" href="/companies">Tilbage</a>
</div>
</div>
</div>
</div>
</div>
}
else
{

View file

@ -14,6 +14,7 @@
//
using System;
using System.Globalization;
using System.Threading.Tasks;
using Blazored.Toast.Services;
using Wonky.Client.HttpInterceptors;
@ -21,7 +22,11 @@ using Wonky.Client.HttpRepository;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.Logging;
using Wonky.Client.Models;
using Wonky.Client.Services;
using Wonky.Entity.DTO;
using Wonky.Entity.Models;
using Wonky.Entity.Requests;
namespace Wonky.Client.Pages;
@ -30,17 +35,23 @@ public partial class CompanyUpdate : IDisposable
private CompanyDto _companyDto;
private EditContext _editContext;
private bool _formInvalid = true;
private DateTime LastVisit { get; set; }
private DateTime NextVisit { get; set; }
private List<VirkRegInfo> VInfos { get; set; }
private VirkRegInfo _virkRegInfo { get; set; } = new();
[Inject] public ICompanyHttpRepository CompanyRepo { get; set; }
[Inject] public HttpInterceptorService Interceptor { get; set; }
[Inject] public IToastService ToastService { get; set; }
[Inject] public ILogger<CompanyCreate> Logger { get; set; }
[Inject] public NavigationManager Navigation { get; set; }
[Inject] public VirkRegistryService VirkRegistryService { get; set; }
[Parameter] public string Account { get; set; } = null!;
protected override async Task OnInitializedAsync()
{
_companyDto = await CompanyRepo.GetCompanyByAccount(Account);
LastVisit = DateTime.Parse(_companyDto.LastVisit);
NextVisit = DateTime.Parse(_companyDto.NextVisit);
_editContext = new EditContext(_companyDto);
_editContext.OnFieldChanged += HandleFieldChanged!;
Interceptor.RegisterEvent();
@ -49,10 +60,67 @@ public partial class CompanyUpdate : IDisposable
private async Task Update()
{
// todo convert date input to ISO string
await CompanyRepo.UpdateCompany(_companyDto);
ToastService.ShowSuccess($"Godt så. Firma '{_companyDto!.Name}' er opdateret.");
Navigation.NavigateTo($"/company/{_companyDto.CompanyId}");
}
private async Task GetInfoFromAddress(VatAddress address)
{
VInfos = await VirkRegistryService.QueryVirkRegistry(
new VirkParams
{
StreetName = address.StreetName,
HouseNumber = address.HouseNumber,
ZipCode = address.ZipCode
});
if (!VInfos.Any())
{
ToastService.ShowError($"Ingen virksomheder fundet.");
}
}
private async Task GetInfoFromVat(string vatNumber)
{
var result = await VirkRegistryService
.QueryVirkRegistry(new VirkParams {VatNumber = vatNumber});
if (!result.Any())
{
ToastService.ShowError($"Firma med CVR '{vatNumber}' findes ikke.");
return;
}
ToastService.ShowSuccess($"Data for '{vatNumber}' er hentet.");
_virkRegInfo = result[0];
_companyDto.Name = _virkRegInfo.Name;
_companyDto.Address1 = _virkRegInfo.CoName;
_companyDto.Address2 = _virkRegInfo.Address;
_companyDto.ZipCode = _virkRegInfo.ZipCode;
_companyDto.City = _virkRegInfo.City;
_companyDto.VatNumber = _virkRegInfo.VatNumber;
}
private void SelectCompany(string vatNumber)
{
_virkRegInfo = (from x in VInfos where x.VatNumber == vatNumber select x).First();
_companyDto.Name = _virkRegInfo.Name;
_companyDto.Address1 = _virkRegInfo.CoName;
_companyDto.Address2 = _virkRegInfo.Address;
_companyDto.ZipCode = _virkRegInfo.ZipCode;
_companyDto.City = _virkRegInfo.City;
_companyDto.VatNumber = _virkRegInfo.VatNumber;
}
private void LastVisitChanged(DateTime lastDate)
{
}
private void NextVisitChanged(DateTime nextDate)
{
}
private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{
_formInvalid = !_editContext!.Validate();

View file

@ -37,6 +37,7 @@ public partial class DraftDocument : IDisposable
}
private async Task GetSalesItems()
{
_paging.PageSize = 5;
var response = await ItemRepo.GetSalesItemsPaged(_paging);
SalesItems = response.Items!;
_meta = response.MetaData;