diff --git a/salesbook.Maui/Core/Services/LocalDbService.cs b/salesbook.Maui/Core/Services/LocalDbService.cs index df6d385..abcfe8f 100644 --- a/salesbook.Maui/Core/Services/LocalDbService.cs +++ b/salesbook.Maui/Core/Services/LocalDbService.cs @@ -24,6 +24,7 @@ public class LocalDbService _connection.CreateTableAsync(); _connection.CreateTableAsync(); _connection.CreateTableAsync(); + _connection.CreateTableAsync(); } 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(); await _connection.CreateTableAsync(); await _connection.CreateTableAsync(); await _connection.CreateTableAsync(); + await _connection.CreateTableAsync(); } catch (Exception ex) { diff --git a/salesbook.Maui/Core/Services/SyncDbService.cs b/salesbook.Maui/Core/Services/SyncDbService.cs index 2b1f1c4..8178aa6 100644 --- a/salesbook.Maui/Core/Services/SyncDbService.cs +++ b/salesbook.Maui/Core/Services/SyncDbService.cs @@ -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!); } } \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor index fde932d..574884a 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor @@ -149,7 +149,7 @@ + StartIcon="@Icons.Material.Rounded.Check"> Cancella @@ -161,7 +161,7 @@ + StartIcon="@Icons.Material.Rounded.DeleteForever"> Crea diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor index 6d4130b..be17acc 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor @@ -13,234 +13,256 @@
-
+
+ +
+ +
+
+ P. IVA + + +
+ +
+ +
+ Cod. Fiscale + + +
+
+ +
+
+ Tipo cliente + + @if (VtbTipi.IsNullOrEmpty()) + { + Nessun tipo cliente trovato + } + else + { + + @foreach (var tipo in VtbTipi) + { + @($"{tipo.CodVtip} - {tipo.Descrizione}") + } + + } +
+
+ +
+
+ Indirizzo +
-
-
- P. IVA +
- -
+
+ CAP -
- -
- Cod. Fiscale - - -
+
-
-
- Tipo cliente +
- @if (VtbTipi.IsNullOrEmpty()) +
+ Città + + +
+ +
+ +
+ Provincia + + +
+ +
+ +
+ Nazione + + @if (Nazioni.IsNullOrEmpty()) { - Nessun tipo cliente trovato + Nessuna nazione trovata } else { - - @foreach (var tipo in VtbTipi) + + @foreach (var nazione in Nazioni) { - @($"{tipo.CodVtip} - {tipo.Descrizione}") + @($"{nazione.Descrizione}") } } -
- -
-
- Indirizzo - - -
- -
- -
- CAP - - -
- -
- -
- Città - - -
- -
- -
- Provincia - - -
- -
- -
- Nazione - - -
-
- -
-
- PEC - - -
- -
- -
- E-Mail - - -
- -
- -
- Telefono - - -
-
- - @if (IsNew) - { -
- @if (!PersRifList.IsNullOrEmpty()) - { - foreach (var item in PersRifList!.Select((p, index) => new { p, index })) - { - - @item.p.PersonaRif - - } - } -
- -
- - Persona di riferimento - -
- }
+ +
+
+ PEC + + +
+ +
+ +
+ E-Mail + + +
+ +
+ +
+ Telefono + + +
+
+ + @if (IsNew) + { +
+ @if (!PersRifList.IsNullOrEmpty()) + { + foreach (var item in PersRifList!.Select((p, index) => new { p, index })) + { + + @item.p.PersonaRif + + } + } +
+ +
+ + Persona di riferimento + +
+ } +
+ + + + @if (VatAlreadyRegistered) + { + + Chiudi + + } + else + { + + Aggiungi + + } + + @@ -254,6 +276,7 @@ private List? VtbTipi { get; set; } private List? PersRifList { get; set; } + private List? 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(); VtbTipi = await ManageData.GetTable(); } @@ -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(x => x.PartIva.Equals(pIva))).LastOrDefault(); + + if (clie == null) + { + var pros = (await ManageData.GetTable(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 ({pIva}) corrisponde a:

{response.RagSoc}
{response.CompleteAddress}

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 ({pros.CodPpro}) già censito con la p.iva: {pIva} - {pros.RagSoc}"; + VatAlreadyRegistered = true; + } + } + else + { + VatMessage = $"Cliente ({clie.CodAnag}) già censito con la p.iva: {pIva} - {clie.RagSoc}"; + 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(); + } } \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor b/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor index fc2b31d..a9778ed 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor @@ -8,7 +8,7 @@ - +
diff --git a/salesbook.Shared/Core/Dto/CheckVatRequestDTO.cs b/salesbook.Shared/Core/Dto/CheckVatRequestDTO.cs new file mode 100644 index 0000000..dfa0dab --- /dev/null +++ b/salesbook.Shared/Core/Dto/CheckVatRequestDTO.cs @@ -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; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/CheckVatResponseDTO.cs b/salesbook.Shared/Core/Dto/CheckVatResponseDTO.cs new file mode 100644 index 0000000..9bc63a3 --- /dev/null +++ b/salesbook.Shared/Core/Dto/CheckVatResponseDTO.cs @@ -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; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/ContactDTO.cs b/salesbook.Shared/Core/Dto/ContactDTO.cs index 4d7d272..9d77864 100644 --- a/salesbook.Shared/Core/Dto/ContactDTO.cs +++ b/salesbook.Shared/Core/Dto/ContactDTO.cs @@ -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; } diff --git a/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs b/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs index 6af838a..0e8a49c 100644 --- a/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs +++ b/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs @@ -16,4 +16,7 @@ public class SettingsResponseDTO [JsonPropertyName("vtbTipi")] public List? VtbTipi { get; set; } + + [JsonPropertyName("nazioni")] + public List? Nazioni { get; set; } } \ No newline at end of file diff --git a/salesbook.Shared/Core/Entity/Nazioni.cs b/salesbook.Shared/Core/Entity/Nazioni.cs new file mode 100644 index 0000000..f072f9d --- /dev/null +++ b/salesbook.Shared/Core/Entity/Nazioni.cs @@ -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; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Interface/IIntegryApiService.cs b/salesbook.Shared/Core/Interface/IIntegryApiService.cs index dff527c..efcab36 100644 --- a/salesbook.Shared/Core/Interface/IIntegryApiService.cs +++ b/salesbook.Shared/Core/Interface/IIntegryApiService.cs @@ -15,4 +15,5 @@ public interface IIntegryApiService Task?> SaveActivity(ActivityDTO activity); Task SaveContact(CRMCreateContactRequestDTO request); + Task CheckVat(CheckVatRequestDTO request); } \ No newline at end of file diff --git a/salesbook.Shared/Core/Services/IntegryApiService.cs b/salesbook.Shared/Core/Services/IntegryApiService.cs index 67a9ced..379aee5 100644 --- a/salesbook.Shared/Core/Services/IntegryApiService.cs +++ b/salesbook.Shared/Core/Services/IntegryApiService.cs @@ -71,4 +71,7 @@ public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUser public Task SaveContact(CRMCreateContactRequestDTO request) => integryApiRestClient.AuthorizedPost("crm/createContact", request); + + public Task CheckVat(CheckVatRequestDTO request) => + integryApiRestClient.Post("checkPartitaIva", request)!; } \ No newline at end of file