Finish v2.2.0(24)

This commit is contained in:
2025-11-17 11:14:43 +01:00
13 changed files with 149 additions and 54 deletions

View File

@@ -90,14 +90,22 @@ public class ManageDataService(
public async Task<List<ContactDTO>> GetContact(WhereCondContact? whereCond, DateTime? lastSync) public async Task<List<ContactDTO>> GetContact(WhereCondContact? whereCond, DateTime? lastSync)
{ {
List<AnagClie>? contactList;
List<PtbPros>? prospectList;
whereCond ??= new WhereCondContact(); whereCond ??= new WhereCondContact();
// Ottengo liste locali
var contactList = await localDb.Get<AnagClie>(x =>
(whereCond.FlagStato != null && x.FlagStato == whereCond.FlagStato) ||
(whereCond.PartIva != null && x.PartIva == whereCond.PartIva) ||
(whereCond.PartIva == null && whereCond.FlagStato == null)
);
var prospectList = await localDb.Get<PtbPros>(x =>
(whereCond.PartIva != null && x.PartIva == whereCond.PartIva) ||
(whereCond.PartIva == null)
);
if (networkService.ConnectionAvailable) if (networkService.ConnectionAvailable)
{ {
var response = new UsersSyncResponseDTO();
var clienti = await integryApiService.RetrieveAnagClie( var clienti = await integryApiService.RetrieveAnagClie(
new CRMAnagRequestDTO new CRMAnagRequestDTO
{ {
@@ -109,10 +117,6 @@ public class ManageDataService(
} }
); );
response.AnagClie = clienti.AnagClie;
response.VtbDest = clienti.VtbDest;
response.VtbCliePersRif = clienti.VtbCliePersRif;
var prospect = await integryApiService.RetrieveProspect( var prospect = await integryApiService.RetrieveProspect(
new CRMProspectRequestDTO new CRMProspectRequestDTO
{ {
@@ -122,38 +126,62 @@ public class ManageDataService(
FilterDate = lastSync FilterDate = lastSync
} }
); );
_ = UpdateDbUsers(new UsersSyncResponseDTO
{
AnagClie = clienti.AnagClie,
VtbDest = clienti.VtbDest,
VtbCliePersRif = clienti.VtbCliePersRif,
PtbPros = prospect.PtbPros,
PtbProsRif = prospect.PtbProsRif
});
response.PtbPros = prospect.PtbPros; if (lastSync != null)
response.PtbProsRif = prospect.PtbProsRif; {
contactList = MergeLists(
contactList,
clienti.AnagClie,
x => x.CodAnag
);
_ = UpdateDbUsers(response); prospectList = MergeLists(
prospectList,
contactList = clienti.AnagClie; prospect.PtbPros,
prospectList = prospect.PtbPros; x => x.CodPpro
} );
else }
{ else
contactList = await localDb.Get<AnagClie>(x => {
(whereCond.FlagStato != null && x.FlagStato.Equals(whereCond.FlagStato)) || contactList = clienti.AnagClie;
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) || prospectList = prospect.PtbPros;
(whereCond.PartIva == null && whereCond.FlagStato == null) }
);
prospectList = await localDb.Get<PtbPros>(x =>
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null)
);
} }
// Mappa i contatti // Mappa i contatti
var contactMapper = mapper.Map<List<ContactDTO>>(contactList); var contactMapper = mapper.Map<List<ContactDTO>>(contactList);
// Mappa i prospects // Mappa i prospect
var prospectMapper = mapper.Map<List<ContactDTO>>(prospectList); var prospectMapper = mapper.Map<List<ContactDTO>>(prospectList);
contactMapper.AddRange(prospectMapper); contactMapper.AddRange(prospectMapper);
return contactMapper; return contactMapper;
} }
private static List<T>? MergeLists<T, TKey>(List<T>? localList, List<T>? apiList, Func<T, TKey> keySelector)
{
if (localList == null || apiList == null) return null;
var dictionary = localList.ToDictionary(keySelector);
foreach (var apiItem in apiList)
{
var key = keySelector(apiItem);
dictionary[key] = apiItem;
}
return dictionary.Values.ToList();
}
public async Task<ContactDTO?> GetSpecificContact(string codAnag, bool isContact) public async Task<ContactDTO?> GetSpecificContact(string codAnag, bool isContact)
{ {
@@ -240,7 +268,7 @@ public class ManageDataService(
.Distinct().ToList(); .Distinct().ToList();
IDictionary<string, string?>? distinctUser = null; IDictionary<string, string?>? distinctUser = null;
if (userListState.AllUsers != null) if (userListState.AllUsers != null)
{ {
distinctUser = userListState.AllUsers distinctUser = userListState.AllUsers
@@ -251,7 +279,8 @@ public class ManageDataService(
var returnDto = activities var returnDto = activities
.Select(activity => .Select(activity =>
{ {
if (activity.CodJcom is "0000" && userSession.ProfileDb != null && userSession.ProfileDb.Equals("smetar", StringComparison.OrdinalIgnoreCase)) if (activity.CodJcom is "0000" && userSession.ProfileDb != null &&
userSession.ProfileDb.Equals("smetar", StringComparison.OrdinalIgnoreCase))
{ {
activity.CodJcom = null; activity.CodJcom = null;
} }
@@ -263,8 +292,7 @@ public class ManageDataService(
var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value; var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value;
dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes); dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes);
dto.NotificationDate = dto.MinuteBefore == 0 ? dto.NotificationDate = dto.MinuteBefore == 0 ? activity.EstimatedTime : activity.AlarmTime;
activity.EstimatedTime : activity.AlarmTime;
} }
if (activity.CodJcom != null) if (activity.CodJcom != null)
@@ -281,7 +309,7 @@ public class ManageDataService(
string? ragSoc; string? ragSoc;
if (distinctUser != null && (distinctUser.TryGetValue(activity.CodAnag, out ragSoc) || if (distinctUser != null && (distinctUser.TryGetValue(activity.CodAnag, out ragSoc) ||
distinctUser.TryGetValue(activity.CodAnag, out ragSoc))) distinctUser.TryGetValue(activity.CodAnag, out ragSoc)))
{ {
dto.Cliente = ragSoc; dto.Cliente = ragSoc;
} }
@@ -343,7 +371,7 @@ public class ManageDataService(
public async Task DeleteProspect(string codPpro) public async Task DeleteProspect(string codPpro)
{ {
var persRifList = await GetTable<PtbProsRif>(x => x.CodPpro!.Equals(codPpro)); var persRifList = await GetTable<PtbProsRif>(x => x.CodPpro!.Equals(codPpro));
if (!persRifList.IsNullOrEmpty()) if (!persRifList.IsNullOrEmpty())
{ {
foreach (var persRif in persRifList) foreach (var persRif in persRifList)

View File

@@ -0,0 +1,8 @@
using salesbook.Shared.Core.Interface.System;
namespace salesbook.Maui.Core.System;
public class GenericSystemService : IGenericSystemService
{
public string GetCurrentAppVersion() => AppInfo.VersionString;
}

View File

@@ -7,6 +7,7 @@ using MudBlazor.Services;
using MudExtensions.Services; using MudExtensions.Services;
using salesbook.Maui.Core.RestClient.IntegryApi; using salesbook.Maui.Core.RestClient.IntegryApi;
using salesbook.Maui.Core.Services; using salesbook.Maui.Core.Services;
using salesbook.Maui.Core.System;
using salesbook.Maui.Core.System.Network; using salesbook.Maui.Core.System.Network;
using salesbook.Maui.Core.System.Notification; using salesbook.Maui.Core.System.Notification;
using salesbook.Maui.Core.System.Notification.Push; using salesbook.Maui.Core.System.Notification.Push;
@@ -16,6 +17,7 @@ using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Helpers;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Interface.System;
using salesbook.Shared.Core.Interface.System.Network; using salesbook.Shared.Core.Interface.System.Network;
using salesbook.Shared.Core.Interface.System.Notification; using salesbook.Shared.Core.Interface.System.Notification;
using salesbook.Shared.Core.Messages.Activity.Copy; using salesbook.Shared.Core.Messages.Activity.Copy;
@@ -102,6 +104,7 @@ namespace salesbook.Maui
builder.Services.AddSingleton<IFormFactor, FormFactor>(); builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IAttachedService, AttachedService>(); builder.Services.AddSingleton<IAttachedService, AttachedService>();
builder.Services.AddSingleton<INetworkService, NetworkService>(); builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddSingleton<LocalDbService>(); builder.Services.AddSingleton<LocalDbService>();
_ = typeof(System.Runtime.InteropServices.SafeHandle); _ = typeof(System.Runtime.InteropServices.SafeHandle);

View File

@@ -29,8 +29,8 @@
<ApplicationId>it.integry.salesbook</ApplicationId> <ApplicationId>it.integry.salesbook</ApplicationId>
<!-- Versions --> <!-- Versions -->
<ApplicationDisplayVersion>2.1.5</ApplicationDisplayVersion> <ApplicationDisplayVersion>2.2.0</ApplicationDisplayVersion>
<ApplicationVersion>23</ApplicationVersion> <ApplicationVersion>24</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'"> <!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">

View File

@@ -23,6 +23,7 @@
{ {
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync"); var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
var syncAllData = lastSyncDate.Equals(DateTime.MinValue) || (DateTime.Now - lastSyncDate).TotalDays >= 7; var syncAllData = lastSyncDate.Equals(DateTime.MinValue) || (DateTime.Now - lastSyncDate).TotalDays >= 7;
var syncCodJcom = lastSyncDate.Day != DateTime.Now.Day;
if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && syncAllData) if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && syncAllData)
{ {
@@ -31,6 +32,13 @@
return; return;
} }
if (syncCodJcom && !syncAllData)
{
var returnPath = System.Web.HttpUtility.UrlEncode("/");
NavigationManager.NavigateTo($"/sync/{DateTime.Today:yyyy-MM-dd}?path={returnPath}");
return;
}
NetworkService.ConnectionAvailable = NetworkService.IsNetworkAvailable(); NetworkService.ConnectionAvailable = NetworkService.IsNetworkAvailable();
await LoadNotification(); await LoadNotification();

View File

@@ -1,8 +1,10 @@
@page "/login" @page "/login"
@using salesbook.Shared.Components.Layout.Spinner @using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Core.Interface.System
@using salesbook.Shared.Core.Services @using salesbook.Shared.Core.Services
@inject IUserAccountService UserAccountService @inject IUserAccountService UserAccountService
@inject AppAuthenticationStateProvider AuthenticationStateProvider @inject AppAuthenticationStateProvider AuthenticationStateProvider
@inject IGenericSystemService GenericSystemService
@if (Spinner) @if (Spinner)
{ {
@@ -34,7 +36,7 @@ else
</div> </div>
<div class="my-4 login-footer"> <div class="my-4 login-footer">
<span>Powered by</span> <span>@($"v{GenericSystemService.GetCurrentAppVersion()} | Powered by")</span>
<img src="_content/salesbook.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry"> <img src="_content/salesbook.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry">
</div> </div>
</div> </div>

View File

@@ -1,6 +1,7 @@
@page "/PersonalInfo" @page "/PersonalInfo"
@attribute [Authorize] @attribute [Authorize]
@using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.Layout
@using salesbook.Shared.Components.SingleElements
@using salesbook.Shared.Core.Authorization.Enum @using salesbook.Shared.Core.Authorization.Enum
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Interface.System.Network
@@ -16,7 +17,8 @@
<div class="container content pb-safe-area"> <div class="container content pb-safe-area">
<div class="container-primary-info"> <div class="container-primary-info">
<div class="section-primary-info"> <div class="section-primary-info">
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary"> <MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold"
Color="Color.Secondary">
@UtilityString.ExtractInitials(UserSession.User.Fullname) @UtilityString.ExtractInitials(UserSession.User.Fullname)
</MudAvatar> </MudAvatar>
@@ -24,7 +26,8 @@
<span class="info-nome">@UserSession.User.Fullname</span> <span class="info-nome">@UserSession.User.Fullname</span>
@if (UserSession.User.KeyGroup is not null) @if (UserSession.User.KeyGroup is not null)
{ {
<span class="info-section">@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())</span> <span
class="info-section">@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())</span>
} }
</div> </div>
</div> </div>
@@ -85,7 +88,7 @@
FullWidth="true" FullWidth="true"
StartIcon="@Icons.Material.Outlined.Sync" StartIcon="@Icons.Material.Outlined.Sync"
Size="Size.Medium" Size="Size.Medium"
OnClick="() => UpdateDb()" OnClick="@(() => UpdateDb())"
Variant="Variant.Outlined"> Variant="Variant.Outlined">
Sincronizza Sincronizza
</MudButton> </MudButton>
@@ -113,6 +116,8 @@
</MudButton> </MudButton>
</div> </div>
</div> </div>
<AppVersion/>
} }
@code { @code {
@@ -149,6 +154,8 @@
private void UpdateDb(bool withData = false) private void UpdateDb(bool withData = false)
{ {
LocalStorage.Remove("last-user-sync");
var absoluteUri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri); var absoluteUri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
var pathAndQuery = absoluteUri.Segments.Length > 1 ? absoluteUri.PathAndQuery : null; var pathAndQuery = absoluteUri.Segments.Length > 1 ? absoluteUri.PathAndQuery : null;

View File

@@ -1,24 +1,29 @@
@page "/sync" @page "/sync"
@page "/sync/{DateFilter}" @page "/sync/{DateFilter}"
@using salesbook.Shared.Components.Layout.Spinner @using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Components.SingleElements
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@inject ISyncDbService syncDb @inject ISyncDbService SyncDb
@inject IManageDataService manageData @inject IManageDataService ManageData
<SyncSpinner Elements="@Elements"/> <SyncSpinner Elements="@Elements"/>
<AppVersion/>
@code { @code {
[Parameter] public string? DateFilter { get; set; } [Parameter] public string? DateFilter { get; set; }
private Dictionary<string, bool> Elements { get; set; } = new(); private Dictionary<string, bool> Elements { get; set; } = new();
private bool _hasStarted = false; private bool _hasStarted;
private int _completedCount = 0; private int _completedCount;
protected override void OnInitialized() protected override void OnInitialized()
{ {
Elements["Commesse"] = false; Elements["Commesse"] = false;
Elements["Impostazioni"] = false;
if (DateFilter is null)
Elements["Impostazioni"] = false;
} }
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -28,9 +33,7 @@
_hasStarted = true; _hasStarted = true;
if (DateFilter is null) if (DateFilter is null)
{ await ManageData.ClearDb();
await manageData.ClearDb();
}
await Task.WhenAll( await Task.WhenAll(
RunAndTrack(SetCommesse), RunAndTrack(SetCommesse),
@@ -58,7 +61,7 @@
private async Task SetCommesse() private async Task SetCommesse()
{ {
await Task.Run(async () => { await syncDb.GetAndSaveCommesse(DateFilter); }); await Task.Run(async () => { await SyncDb.GetAndSaveCommesse(DateFilter); });
Elements["Commesse"] = true; Elements["Commesse"] = true;
StateHasChanged(); StateHasChanged();
@@ -66,10 +69,13 @@
private async Task SetSettings() private async Task SetSettings()
{ {
await Task.Run(async () => { await syncDb.GetAndSaveSettings(DateFilter); }); if (DateFilter is null)
{
await Task.Run(async () => { await SyncDb.GetAndSaveSettings(DateFilter); });
Elements["Impostazioni"] = true; Elements["Impostazioni"] = true;
StateHasChanged(); StateHasChanged();
}
} }
} }

View File

@@ -0,0 +1,6 @@
@using salesbook.Shared.Core.Interface.System
@inject IGenericSystemService GenericSystemService
<div class="app-version">
<span>@($"v{GenericSystemService.GetCurrentAppVersion()}")</span>
</div>

View File

@@ -0,0 +1,11 @@
.app-version{
width: 100%;
display: flex;
justify-content: center;
margin: 8px 0;
}
.app-version span{
font-size: smaller;
color: var(--mud-palette-gray-darker);
}

View File

@@ -460,7 +460,10 @@
Users = await ManageData.GetTable<StbUser>(); Users = await ManageData.GetTable<StbUser>();
if (!ActivityModel.UserName.IsNullOrEmpty()) if (!ActivityModel.UserName.IsNullOrEmpty())
{
SelectedUser = Users.FindLast(x => x.UserName.Equals(ActivityModel.UserName)); SelectedUser = Users.FindLast(x => x.UserName.Equals(ActivityModel.UserName));
await InvokeAsync(StateHasChanged);
}
if (!IsNew && Id != null) if (!IsNew && Id != null)
ActivityFileList = await IntegryApiService.GetActivityFile(Id); ActivityFileList = await IntegryApiService.GetActivityFile(Id);

View File

@@ -0,0 +1,6 @@
namespace salesbook.Shared.Core.Interface.System;
public interface IGenericSystemService
{
string GetCurrentAppVersion();
}

View File

@@ -1,4 +1,6 @@
using salesbook.Shared.Core.Dto; using IntegryApiClient.Core.Domain.Abstraction.Contracts.Storage;
using Java.Sql;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Dto.PageState; using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Dto.Users; using salesbook.Shared.Core.Dto.Users;
@@ -6,7 +8,7 @@ using salesbook.Shared.Core.Interface;
namespace salesbook.Shared.Core.Services; namespace salesbook.Shared.Core.Services;
public class PreloadService(IManageDataService manageData, UserListState userState) public class PreloadService(IManageDataService manageData, ILocalStorage localStorage, UserListState userState)
{ {
public async Task PreloadUsersAsync() public async Task PreloadUsersAsync()
{ {
@@ -14,8 +16,11 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
return; return;
userState.IsLoading = true; userState.IsLoading = true;
DateTime? lastSync = localStorage.Get<DateTime>("last-user-sync");
lastSync = lastSync.Equals(DateTime.MinValue) ? null : lastSync;
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" }); var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" }, lastSync);
var sorted = users var sorted = users
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc)) .Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
@@ -27,6 +32,8 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
userState.FilteredGroupedUserList = userState.GroupedUserList; userState.FilteredGroupedUserList = userState.GroupedUserList;
userState.AllUsers = users; userState.AllUsers = users;
localStorage.Set("last-user-sync", DateTime.Now);
userState.NotifyUsersLoaded(); userState.NotifyUsersLoaded();
} }