Controllo p.Iva
This commit is contained in:
@@ -24,6 +24,7 @@ public class LocalDbService
|
||||
_connection.CreateTableAsync<StbActivityType>();
|
||||
_connection.CreateTableAsync<StbUser>();
|
||||
_connection.CreateTableAsync<VtbTipi>();
|
||||
_connection.CreateTableAsync<Nazioni>();
|
||||
}
|
||||
|
||||
public async Task ResetSettingsDb()
|
||||
@@ -34,11 +35,13 @@ public class LocalDbService
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_activity_type;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_user;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS vtb_tipi;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS nazioni;");
|
||||
|
||||
await _connection.CreateTableAsync<StbActivityResult>();
|
||||
await _connection.CreateTableAsync<StbActivityType>();
|
||||
await _connection.CreateTableAsync<StbUser>();
|
||||
await _connection.CreateTableAsync<VtbTipi>();
|
||||
await _connection.CreateTableAsync<Nazioni>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -85,5 +85,8 @@ public class SyncDbService(IIntegryApiService integryApiService, LocalDbService
|
||||
|
||||
if (!settingsResponse.VtbTipi.IsNullOrEmpty())
|
||||
await localDb.InsertAll(settingsResponse.VtbTipi!);
|
||||
|
||||
if (!settingsResponse.Nazioni.IsNullOrEmpty())
|
||||
await localDb.InsertAll(settingsResponse.Nazioni!);
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@
|
||||
</MessageContent>
|
||||
<YesButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error"
|
||||
StartIcon="@Icons.Material.Filled.Check">
|
||||
StartIcon="@Icons.Material.Rounded.Check">
|
||||
Cancella
|
||||
</MudButton>
|
||||
</YesButton>
|
||||
@@ -161,7 +161,7 @@
|
||||
</MessageContent>
|
||||
<YesButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.DeleteForever">
|
||||
StartIcon="@Icons.Material.Rounded.DeleteForever">
|
||||
Crea
|
||||
</MudButton>
|
||||
</YesButton>
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
Class="customIcon-select"
|
||||
Lines="1"
|
||||
@bind-Value="ContactModel.PartIva"
|
||||
@bind-Value:after="OnAfterChangeValue"
|
||||
DebounceInterval="500"
|
||||
OnDebounceIntervalElapsed="OnAfterChangeValue"/>
|
||||
@bind-Value:after="OnAfterChangePIva"/>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
@@ -151,16 +149,21 @@
|
||||
<div class="form-container">
|
||||
<span class="disable-full-width">Nazione</span>
|
||||
|
||||
<MudTextField ReadOnly="IsView"
|
||||
T="string?"
|
||||
Variant="Variant.Text"
|
||||
FullWidth="true"
|
||||
Class="customIcon-select"
|
||||
Lines="1"
|
||||
@bind-Value="ContactModel.Nazione"
|
||||
@bind-Value:after="OnAfterChangeValue"
|
||||
DebounceInterval="500"
|
||||
OnDebounceIntervalElapsed="OnAfterChangeValue"/>
|
||||
@if (Nazioni.IsNullOrEmpty())
|
||||
{
|
||||
<span class="warning-text">Nessuna nazione trovata</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSelectExtended FullWidth="true" ReadOnly="@(IsView || Nazioni.IsNullOrEmpty())" T="string?"
|
||||
Variant="Variant.Text" @bind-Value="ContactModel.Nazione" @bind-Value:after="OnAfterChangeValue"
|
||||
Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code">
|
||||
@foreach (var nazione in Nazioni)
|
||||
{
|
||||
<MudSelectItemExtended Class="custom-item-select" Value="@nazione.CodNazioneAlpha2">@($"{nazione.Descrizione}")</MudSelectItemExtended>
|
||||
}
|
||||
</MudSelectExtended>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -241,6 +244,25 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudMessageBox MarkupMessage="new MarkupString(VatMessage)" @ref="CheckVat" Class="c-messageBox" Title="Verifica partita iva" CancelText="@(VatAlreadyRegistered ? "" : "Annulla")">
|
||||
<YesButton>
|
||||
@if (VatAlreadyRegistered)
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error"
|
||||
StartIcon="@Icons.Material.Rounded.Close">
|
||||
Chiudi
|
||||
</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.Check">
|
||||
Aggiungi
|
||||
</MudButton>
|
||||
}
|
||||
</YesButton>
|
||||
</MudMessageBox>
|
||||
</DialogContent>
|
||||
</MudDialog>
|
||||
|
||||
@@ -254,6 +276,7 @@
|
||||
|
||||
private List<VtbTipi>? VtbTipi { get; set; }
|
||||
private List<PersRifDTO>? PersRifList { get; set; }
|
||||
private List<Nazioni>? Nazioni { get; set; }
|
||||
|
||||
private bool IsNew => OriginalModel is null;
|
||||
private bool IsView => !NetworkService.IsNetworkAvailable();
|
||||
@@ -264,6 +287,11 @@
|
||||
private bool VisibleOverlay { get; set; }
|
||||
private bool SuccessAnimation { get; set; }
|
||||
|
||||
//MessageBox
|
||||
private MudMessageBox CheckVat { get; set; }
|
||||
private string VatMessage { get; set; } = "";
|
||||
private bool VatAlreadyRegistered { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
|
||||
@@ -300,12 +328,14 @@
|
||||
if (IsNew)
|
||||
{
|
||||
ContactModel.IsContact = false;
|
||||
ContactModel.Nazione = "IT";
|
||||
}
|
||||
else
|
||||
{
|
||||
ContactModel = OriginalModel!.Clone();
|
||||
}
|
||||
|
||||
Nazioni = await ManageData.GetTable<Nazioni>();
|
||||
VtbTipi = await ManageData.GetTable<VtbTipi>();
|
||||
}
|
||||
|
||||
@@ -343,4 +373,98 @@
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnAfterChangePIva()
|
||||
{
|
||||
CheckVatResponseDTO? response = null;
|
||||
var error = false;
|
||||
|
||||
VisibleOverlay = true;
|
||||
StateHasChanged();
|
||||
|
||||
var nazione = Nazioni?.Find(x =>
|
||||
x.CodNazioneAlpha2.Equals(ContactModel.Nazione) ||
|
||||
x.CodNazioneIso.Equals(ContactModel.Nazione) ||
|
||||
x.Nazione.Equals(ContactModel.Nazione)
|
||||
);
|
||||
|
||||
if (nazione == null)
|
||||
return;
|
||||
|
||||
var pIva = ContactModel.PartIva.Trim();
|
||||
|
||||
var clie = (await ManageData.GetTable<AnagClie>(x => x.PartIva.Equals(pIva))).LastOrDefault();
|
||||
|
||||
if (clie == null)
|
||||
{
|
||||
var pros = (await ManageData.GetTable<PtbPros>(x => x.PartIva.Equals(pIva))).LastOrDefault();
|
||||
|
||||
if (pros == null)
|
||||
{
|
||||
if (nazione.ChkPartIva)
|
||||
{
|
||||
if (!IsView)
|
||||
{
|
||||
try
|
||||
{
|
||||
response = await IntegryApiService.CheckVat(new CheckVatRequestDTO
|
||||
{
|
||||
CountryCode = nazione.CodNazioneAlpha2,
|
||||
VatNumber = pIva
|
||||
});
|
||||
|
||||
VatMessage = $"La p.Iva (<b>{pIva}</b>) corrisponde a:<br><br><b>{response.RagSoc}</b><br><b>{response.CompleteAddress}</b><br><br>Si desidera aggiungere questi dati nel form?";
|
||||
VatAlreadyRegistered = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Snackbar.Clear();
|
||||
Snackbar.Add(e.Message, Severity.Error);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Clear();
|
||||
Snackbar.Add("La ricerca della partita iva non è al momento disponibile", Severity.Warning);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Clear();
|
||||
Snackbar.Add("La ricerca della partita iva non è abilitata per questa nazione", Severity.Warning);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VatMessage = $"Prospect (<b>{pros.CodPpro}</b>) già censito con la p.iva: <b>{pIva} - {pros.RagSoc}</b>";
|
||||
VatAlreadyRegistered = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VatMessage = $"Cliente (<b>{clie.CodAnag}</b>) già censito con la p.iva: <b>{pIva} - {clie.RagSoc}</b>";
|
||||
VatAlreadyRegistered = true;
|
||||
}
|
||||
|
||||
VisibleOverlay = false;
|
||||
StateHasChanged();
|
||||
|
||||
if (!error)
|
||||
{
|
||||
var result = await CheckVat.ShowAsync();
|
||||
|
||||
if (result is true && response != null)
|
||||
{
|
||||
ContactModel.RagSoc = response.RagSoc;
|
||||
ContactModel.Indirizzo = response.Indirizzo;
|
||||
ContactModel.Cap = response.Cap;
|
||||
ContactModel.Citta = response.Citta;
|
||||
ContactModel.Prov = response.Prov;
|
||||
}
|
||||
}
|
||||
|
||||
OnAfterChangeValue();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<MudDialog Class="customDialog-form">
|
||||
<DialogContent>
|
||||
<HeaderLayout ShowProfile="false" Cancel="true" OnCancel="() => MudDialog.Cancel()" LabelSave="@LabelSave" OnSave="Save" Title="@(IsNew ? "Nuovo" : "Persona di riferimento")" />
|
||||
<HeaderLayout ShowProfile="false" Cancel="true" OnCancel="() => MudDialog.Cancel()" LabelSave="@LabelSave" OnSave="Save" Title="@(IsNew ? "Nuovo" : "")" />
|
||||
|
||||
<div class="content">
|
||||
<div class="input-card">
|
||||
|
||||
12
salesbook.Shared/Core/Dto/CheckVatRequestDTO.cs
Normal file
12
salesbook.Shared/Core/Dto/CheckVatRequestDTO.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace salesbook.Shared.Core.Dto;
|
||||
|
||||
public class CheckVatRequestDTO
|
||||
{
|
||||
[JsonPropertyName("countryCode")]
|
||||
public string CountryCode { get; set; }
|
||||
|
||||
[JsonPropertyName("vatNumber")]
|
||||
public string VatNumber { get; set; }
|
||||
}
|
||||
39
salesbook.Shared/Core/Dto/CheckVatResponseDTO.cs
Normal file
39
salesbook.Shared/Core/Dto/CheckVatResponseDTO.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace salesbook.Shared.Core.Dto;
|
||||
|
||||
public class CheckVatResponseDTO
|
||||
{
|
||||
[JsonPropertyName("countryCode")]
|
||||
public string? CountryCode { get; set; }
|
||||
|
||||
[JsonPropertyName("vatNumber ")]
|
||||
public string? VatNumber { get; set; }
|
||||
|
||||
[JsonPropertyName("requestDate")]
|
||||
public string? RequestDate { get; set; }
|
||||
|
||||
[JsonPropertyName("valid")]
|
||||
public bool Valid { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("address")]
|
||||
public string? CompleteAddress { get; set; }
|
||||
|
||||
[JsonPropertyName("ragSoc")]
|
||||
public string? RagSoc { get; set; }
|
||||
|
||||
[JsonPropertyName("indirizzo")]
|
||||
public string? Indirizzo { get; set; }
|
||||
|
||||
[JsonPropertyName("cap")]
|
||||
public string? Cap { get; set; }
|
||||
|
||||
[JsonPropertyName("citta")]
|
||||
public string? Citta { get; set; }
|
||||
|
||||
[JsonPropertyName("prov")]
|
||||
public string? Prov { get; set; }
|
||||
}
|
||||
@@ -17,22 +17,22 @@ public class ContactDTO
|
||||
public string? CodVage { get; set; }
|
||||
|
||||
[JsonPropertyName("ragSoc")]
|
||||
public string RagSoc { get; set; }
|
||||
public string? RagSoc { get; set; }
|
||||
|
||||
[JsonPropertyName("indirizzo")]
|
||||
public string Indirizzo { get; set; }
|
||||
public string? Indirizzo { get; set; }
|
||||
|
||||
[JsonPropertyName("cap")]
|
||||
public string Cap { get; set; }
|
||||
public string? Cap { get; set; }
|
||||
|
||||
[JsonPropertyName("citta")]
|
||||
public string Citta { get; set; }
|
||||
public string? Citta { get; set; }
|
||||
|
||||
[JsonPropertyName("prov")]
|
||||
public string Prov { get; set; }
|
||||
public string? Prov { get; set; }
|
||||
|
||||
[JsonPropertyName("nazione")]
|
||||
public string Nazione { get; set; }
|
||||
public string? Nazione { get; set; }
|
||||
|
||||
[JsonPropertyName("telefono")]
|
||||
public string? Telefono { get; set; }
|
||||
|
||||
@@ -16,4 +16,7 @@ public class SettingsResponseDTO
|
||||
|
||||
[JsonPropertyName("vtbTipi")]
|
||||
public List<VtbTipi>? VtbTipi { get; set; }
|
||||
|
||||
[JsonPropertyName("nazioni")]
|
||||
public List<Nazioni>? Nazioni { get; set; }
|
||||
}
|
||||
23
salesbook.Shared/Core/Entity/Nazioni.cs
Normal file
23
salesbook.Shared/Core/Entity/Nazioni.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using SQLite;
|
||||
|
||||
namespace salesbook.Shared.Core.Entity;
|
||||
|
||||
[Table("nazioni")]
|
||||
public class Nazioni
|
||||
{
|
||||
[PrimaryKey, Column("nazione"), JsonPropertyName("nazione")]
|
||||
public string Nazione { get; set; }
|
||||
|
||||
[Column("cod_nazione_iso"), JsonPropertyName("codNazioneIso")]
|
||||
public string CodNazioneIso { get; set; }
|
||||
|
||||
[Column("cod_nazi_alpha_2"), JsonPropertyName("codNazioneAlpha2")]
|
||||
public string CodNazioneAlpha2 { get; set; }
|
||||
|
||||
[Column("descrizione"), JsonPropertyName("descrizione")]
|
||||
public string Descrizione { get; set; }
|
||||
|
||||
[Column("chk_part_iva"), JsonPropertyName("chkPartIva")]
|
||||
public bool ChkPartIva { get; set; }
|
||||
}
|
||||
@@ -15,4 +15,5 @@ public interface IIntegryApiService
|
||||
|
||||
Task<List<StbActivity>?> SaveActivity(ActivityDTO activity);
|
||||
Task SaveContact(CRMCreateContactRequestDTO request);
|
||||
Task<CheckVatResponseDTO> CheckVat(CheckVatRequestDTO request);
|
||||
}
|
||||
@@ -71,4 +71,7 @@ public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUser
|
||||
|
||||
public Task SaveContact(CRMCreateContactRequestDTO request) =>
|
||||
integryApiRestClient.AuthorizedPost<object>("crm/createContact", request);
|
||||
|
||||
public Task<CheckVatResponseDTO> CheckVat(CheckVatRequestDTO request) =>
|
||||
integryApiRestClient.Post<CheckVatResponseDTO>("checkPartitaIva", request)!;
|
||||
}
|
||||
Reference in New Issue
Block a user