From 7bcb0581ccec57c7d517768d9e301a69679f0a1b Mon Sep 17 00:00:00 2001 From: MarcoE Date: Mon, 21 Jul 2025 10:08:10 +0200 Subject: [PATCH] Form persone di riferimento e clienti --- .../Core/Services/LocalDbService.cs | 3 + salesbook.Maui/Core/Services/SyncDbService.cs | 3 + .../Components/Pages/User.razor.css | 5 + .../SingleElements/Card/CommessaCard.razor | 2 +- .../SingleElements/Modal/ContactForm.razor | 292 +++++++++++++----- .../Modal/ContactForm.razor.css | 5 + .../SingleElements/Modal/PersRifForm.razor | 22 +- .../Core/Dto/CRMCreateContactRequestDTO.cs | 18 ++ salesbook.Shared/Core/Dto/PersRifDTO.cs | 3 + .../Core/Dto/SettingsResponseDTO.cs | 3 + salesbook.Shared/Core/Entity/VtbTipi.cs | 14 + .../Core/Interface/IIntegryApiService.cs | 1 + .../Core/Services/IntegryApiService.cs | 6 +- salesbook.Shared/wwwroot/css/form.css | 9 +- 14 files changed, 298 insertions(+), 88 deletions(-) create mode 100644 salesbook.Shared/Core/Dto/CRMCreateContactRequestDTO.cs create mode 100644 salesbook.Shared/Core/Entity/VtbTipi.cs diff --git a/salesbook.Maui/Core/Services/LocalDbService.cs b/salesbook.Maui/Core/Services/LocalDbService.cs index 4697be2..df6d385 100644 --- a/salesbook.Maui/Core/Services/LocalDbService.cs +++ b/salesbook.Maui/Core/Services/LocalDbService.cs @@ -23,6 +23,7 @@ public class LocalDbService _connection.CreateTableAsync(); _connection.CreateTableAsync(); _connection.CreateTableAsync(); + _connection.CreateTableAsync(); } public async Task ResetSettingsDb() @@ -32,10 +33,12 @@ public class LocalDbService await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_activity_result;"); 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.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 c883d0f..2b1f1c4 100644 --- a/salesbook.Maui/Core/Services/SyncDbService.cs +++ b/salesbook.Maui/Core/Services/SyncDbService.cs @@ -82,5 +82,8 @@ public class SyncDbService(IIntegryApiService integryApiService, LocalDbService if (!settingsResponse.StbUsers.IsNullOrEmpty()) await localDb.InsertAll(settingsResponse.StbUsers!); + + if (!settingsResponse.VtbTipi.IsNullOrEmpty()) + await localDb.InsertAll(settingsResponse.VtbTipi!); } } \ No newline at end of file diff --git a/salesbook.Shared/Components/Pages/User.razor.css b/salesbook.Shared/Components/Pages/User.razor.css index fd088e5..45277bc 100644 --- a/salesbook.Shared/Components/Pages/User.razor.css +++ b/salesbook.Shared/Components/Pages/User.razor.css @@ -139,8 +139,13 @@ margin-bottom: 1rem; box-shadow: var(--custom-box-shadow); border-radius: 16px; + max-height: 32vh; + overflow: auto; + scrollbar-width: none; } +.container-pers-rif::-webkit-scrollbar { display: none; } + .container-pers-rif .divider { margin: 0 0 0 3.5rem; width: unset; diff --git a/salesbook.Shared/Components/SingleElements/Card/CommessaCard.razor b/salesbook.Shared/Components/SingleElements/Card/CommessaCard.razor index 5cb7e23..d8fb918 100644 --- a/salesbook.Shared/Components/SingleElements/Card/CommessaCard.razor +++ b/salesbook.Shared/Components/SingleElements/Card/CommessaCard.razor @@ -1,6 +1,6 @@ @using salesbook.Shared.Core.Entity -
+
diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor index e663947..6d4130b 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor @@ -2,9 +2,11 @@ @using salesbook.Shared.Components.Layout @using salesbook.Shared.Core.Interface @using salesbook.Shared.Components.Layout.Overlay +@using salesbook.Shared.Core.Entity @inject IManageDataService ManageData @inject INetworkService NetworkService @inject IIntegryApiService IntegryApiService +@inject IDialogService Dialog @@ -12,8 +14,8 @@
-
-
- -
-
- Indirizzo + P. IVA
- +
- CAP + Cod. Fiscale -
- -
- -
- Città - - -
- -
- -
- Provincia - - -
- -
- -
- Nazione - - @@ -114,24 +63,172 @@
Tipo cliente - @* @if (Commesse.IsNullOrEmpty()) + @if (VtbTipi.IsNullOrEmpty()) { - Nessuna commessa presente + Nessun tipo cliente trovato } else { - - @foreach (var com in Commesse) + + @foreach (var tipo in VtbTipi) { - @($"{com.CodJcom} - {com.Descrizione}") + @($"{tipo.CodVtip} - {tipo.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 + + } + } +
+
? VtbTipi { get; set; } + private List? PersRifList { get; set; } + private bool IsNew => OriginalModel is null; private bool IsView => !NetworkService.IsNetworkAvailable(); @@ -168,13 +268,25 @@ { Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter; - _ = LoadData(); + await LoadData(); LabelSave = IsNew ? "Aggiungi" : null; } private async Task Save() { + VisibleOverlay = true; + StateHasChanged(); + + var requestDto = new CRMCreateContactRequestDTO + { + TipoAnag = ContactModel.IsContact ? "C" : "P", + Cliente = ContactModel, + PersRif = PersRifList + }; + + await IntegryApiService.SaveContact(requestDto); + SuccessAnimation = true; StateHasChanged(); @@ -185,8 +297,16 @@ private async Task LoadData() { - if (!IsNew) + if (IsNew) + { + ContactModel.IsContact = false; + } + else + { ContactModel = OriginalModel!.Clone(); + } + + VtbTipi = await ManageData.GetTable(); } private void OnAfterChangeValue() @@ -197,8 +317,30 @@ } } - private void NewPersRif() - { + private Task NewPersRif() => OpenPersRifForm(null, null); + private async Task OpenPersRifForm(int? index, PersRifDTO? persRif) + { + var result = await ModalHelpers.OpenPersRifForm(Dialog, persRif); + + if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(PersRifDTO)) + { + if (index != null) + OnRemovePersRif(index.Value); + + PersRifList ??= []; + + PersRifList.Add((PersRifDTO)result.Data); + } } + + private void OnRemovePersRif(int index) + { + if (PersRifList is null || index < 0 || index >= PersRifList.Count) + return; + + PersRifList.RemoveAt(index); + StateHasChanged(); + } + } \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css index cb50e2e..17ef28b 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css @@ -2,3 +2,8 @@ background: var(--mud-palette-background-gray) !important; box-shadow: unset; } + +.container-chip-persrif { + width: 100%; + margin-bottom: 1rem; +} \ 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 0998dca..fc2b31d 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor @@ -8,13 +8,13 @@ - +
? PersRif { get; set; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/PersRifDTO.cs b/salesbook.Shared/Core/Dto/PersRifDTO.cs index 10ec7cc..fe2edd2 100644 --- a/salesbook.Shared/Core/Dto/PersRifDTO.cs +++ b/salesbook.Shared/Core/Dto/PersRifDTO.cs @@ -28,6 +28,9 @@ public class PersRifDTO [JsonPropertyName("telefono")] public string Telefono { get; set; } + [JsonIgnore] + public int TempId { get; set; } + public PersRifDTO Clone() { return (PersRifDTO)MemberwiseClone(); diff --git a/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs b/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs index 2059adb..6af838a 100644 --- a/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs +++ b/salesbook.Shared/Core/Dto/SettingsResponseDTO.cs @@ -13,4 +13,7 @@ public class SettingsResponseDTO [JsonPropertyName("stbUsers")] public List? StbUsers { get; set; } + + [JsonPropertyName("vtbTipi")] + public List? VtbTipi { get; set; } } \ No newline at end of file diff --git a/salesbook.Shared/Core/Entity/VtbTipi.cs b/salesbook.Shared/Core/Entity/VtbTipi.cs new file mode 100644 index 0000000..69e3c5a --- /dev/null +++ b/salesbook.Shared/Core/Entity/VtbTipi.cs @@ -0,0 +1,14 @@ +using SQLite; +using System.Text.Json.Serialization; + +namespace salesbook.Shared.Core.Entity; + +[Table("vtb_tipi")] +public class VtbTipi +{ + [PrimaryKey, Column("cod_vtip"), JsonPropertyName("codVtip")] + public string CodVtip { get; set; } + + [Column("descrizione"), JsonPropertyName("descrizione")] + public string Descrizione { 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 1d58af9..dff527c 100644 --- a/salesbook.Shared/Core/Interface/IIntegryApiService.cs +++ b/salesbook.Shared/Core/Interface/IIntegryApiService.cs @@ -14,4 +14,5 @@ public interface IIntegryApiService Task DeleteActivity(string activityId); Task?> SaveActivity(ActivityDTO activity); + Task SaveContact(CRMCreateContactRequestDTO request); } \ No newline at end of file diff --git a/salesbook.Shared/Core/Services/IntegryApiService.cs b/salesbook.Shared/Core/Services/IntegryApiService.cs index bbf259e..67a9ced 100644 --- a/salesbook.Shared/Core/Services/IntegryApiService.cs +++ b/salesbook.Shared/Core/Services/IntegryApiService.cs @@ -1,4 +1,5 @@ -using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account; +using System.Xml; +using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account; using IntegryApiClient.Core.Domain.RestClient.Contacts; using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Entity; @@ -67,4 +68,7 @@ public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUser public Task?> SaveActivity(ActivityDTO activity) => integryApiRestClient.AuthorizedPost?>("crm/saveActivity", activity); + + public Task SaveContact(CRMCreateContactRequestDTO request) => + integryApiRestClient.AuthorizedPost("crm/createContact", request); } \ No newline at end of file diff --git a/salesbook.Shared/wwwroot/css/form.css b/salesbook.Shared/wwwroot/css/form.css index 5a04a9c..c6d05a3 100644 --- a/salesbook.Shared/wwwroot/css/form.css +++ b/salesbook.Shared/wwwroot/css/form.css @@ -41,20 +41,23 @@ } .form-container > span { - font-weight: 600; + font-weight: 700; width: 50%; margin-right: .3rem; } .form-container > .warning-text { - font-weight: 500; + font-weight: 700; color: var(--mud-palette-gray-darker); width: unset; margin: 0; } -.form-container > .disable-full-width { width: unset !important; } +.form-container > .disable-full-width { + width: unset !important; + white-space: nowrap; +} .dateTime-picker { display: flex;