9 Commits

Author SHA1 Message Date
5c1d74e04d Finish v2.2.1(25) 2025-12-18 11:55:00 +01:00
394d0ace47 Finish v2.2.1(25) 2025-12-18 11:54:58 +01:00
99cd67fd5e -> v2.2.1 (25) 2025-12-18 11:54:49 +01:00
c336084152 Fix sync 2025-12-18 11:53:51 +01:00
74ac06b4c1 Finish v2.2.0(24) 2025-11-17 11:14:44 +01:00
70e68e59fb Finish v2.2.0(24) 2025-11-17 11:14:43 +01:00
032dd78c8c -> v2.2.0 (24) 2025-11-17 11:14:37 +01:00
e4b252f301 Migliorato caricamento clienti 2025-11-17 11:11:05 +01:00
a91e08f162 Aggiunta sync giornaliera delle commesse 2025-11-14 15:59:09 +01:00
8 changed files with 112 additions and 52 deletions

View File

@@ -90,14 +90,22 @@ public class ManageDataService(
public async Task<List<ContactDTO>> GetContact(WhereCondContact? whereCond, DateTime? lastSync)
{
List<AnagClie>? contactList;
List<PtbPros>? prospectList;
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)
{
var response = new UsersSyncResponseDTO();
var clienti = await integryApiService.RetrieveAnagClie(
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(
new CRMProspectRequestDTO
{
@@ -123,31 +127,40 @@ public class ManageDataService(
}
);
response.PtbPros = prospect.PtbPros;
response.PtbProsRif = prospect.PtbProsRif;
_ = UpdateDbUsers(new UsersSyncResponseDTO
{
AnagClie = clienti.AnagClie,
VtbDest = clienti.VtbDest,
VtbCliePersRif = clienti.VtbCliePersRif,
PtbPros = prospect.PtbPros,
PtbProsRif = prospect.PtbProsRif
});
_ = UpdateDbUsers(response);
if (lastSync != null)
{
contactList = MergeLists(
contactList,
clienti.AnagClie,
x => x.CodAnag
);
contactList = clienti.AnagClie;
prospectList = prospect.PtbPros;
prospectList = MergeLists(
prospectList,
prospect.PtbPros,
x => x.CodPpro
);
}
else
{
contactList = await localDb.Get<AnagClie>(x =>
(whereCond.FlagStato != null && x.FlagStato.Equals(whereCond.FlagStato)) ||
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null && whereCond.FlagStato == null)
);
prospectList = await localDb.Get<PtbPros>(x =>
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null)
);
contactList = clienti.AnagClie;
prospectList = prospect.PtbPros;
}
}
// Mappa i contatti
var contactMapper = mapper.Map<List<ContactDTO>>(contactList);
// Mappa i prospects
// Mappa i prospect
var prospectMapper = mapper.Map<List<ContactDTO>>(prospectList);
contactMapper.AddRange(prospectMapper);
@@ -155,6 +168,23 @@ public class ManageDataService(
return contactMapper;
}
private static List<T>? MergeLists<T, TKey>(List<T>? localList, List<T>? apiList, Func<T, TKey> keySelector)
{
if (apiList == null && localList != null) return localList;
if (apiList != null && localList == null) return apiList;
if (apiList == null && localList == 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)
{
if (isContact)
@@ -251,7 +281,8 @@ public class ManageDataService(
var returnDto = activities
.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;
}
@@ -263,8 +294,7 @@ public class ManageDataService(
var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value;
dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes);
dto.NotificationDate = dto.MinuteBefore == 0 ?
activity.EstimatedTime : activity.AlarmTime;
dto.NotificationDate = dto.MinuteBefore == 0 ? activity.EstimatedTime : activity.AlarmTime;
}
if (activity.CodJcom != null)

View File

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

View File

@@ -23,6 +23,7 @@
{
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
var syncAllData = lastSyncDate.Equals(DateTime.MinValue) || (DateTime.Now - lastSyncDate).TotalDays >= 7;
var syncCodJcom = lastSyncDate.Day != DateTime.Now.Day;
if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && syncAllData)
{
@@ -31,6 +32,13 @@
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();
await LoadNotification();

View File

@@ -88,7 +88,7 @@
FullWidth="true"
StartIcon="@Icons.Material.Outlined.Sync"
Size="Size.Medium"
OnClick="() => UpdateDb()"
OnClick="@(() => UpdateDb())"
Variant="Variant.Outlined">
Sincronizza
</MudButton>
@@ -154,6 +154,8 @@
private void UpdateDb(bool withData = false)
{
LocalStorage.Remove("last-user-sync");
var absoluteUri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
var pathAndQuery = absoluteUri.Segments.Length > 1 ? absoluteUri.PathAndQuery : null;

View File

@@ -3,8 +3,8 @@
@using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Components.SingleElements
@using salesbook.Shared.Core.Interface
@inject ISyncDbService syncDb
@inject IManageDataService manageData
@inject ISyncDbService SyncDb
@inject IManageDataService ManageData
<SyncSpinner Elements="@Elements"/>
@@ -15,12 +15,14 @@
private Dictionary<string, bool> Elements { get; set; } = new();
private bool _hasStarted = false;
private int _completedCount = 0;
private bool _hasStarted;
private int _completedCount;
protected override void OnInitialized()
{
Elements["Commesse"] = false;
if (DateFilter is null)
Elements["Impostazioni"] = false;
}
@@ -31,9 +33,7 @@
_hasStarted = true;
if (DateFilter is null)
{
await manageData.ClearDb();
}
await ManageData.ClearDb();
await Task.WhenAll(
RunAndTrack(SetCommesse),
@@ -61,7 +61,7 @@
private async Task SetCommesse()
{
await Task.Run(async () => { await syncDb.GetAndSaveCommesse(DateFilter); });
await Task.Run(async () => { await SyncDb.GetAndSaveCommesse(DateFilter); });
Elements["Commesse"] = true;
StateHasChanged();
@@ -69,10 +69,13 @@
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;
StateHasChanged();
}
}
}

View File

@@ -3,6 +3,11 @@
public enum KeyGroupEnum
{
UtenteAziendale = 2,
Cliente = 3,
Agenti = 5,
Tecnico = 22
AmministratoreAziendale = 9,
Tecnico = 22,
ResponsabileDiReparto = 23,
ResponsabileAmministrativo = 29,
Programmatore = 30
}

View File

@@ -11,6 +11,11 @@ public static class KeyGroupHelper
KeyGroupEnum.Agenti => "Agenti",
KeyGroupEnum.Tecnico => "Tecnico",
KeyGroupEnum.UtenteAziendale => "Utente Aziendale",
KeyGroupEnum.AmministratoreAziendale => "Amministratore Aziendale",
KeyGroupEnum.ResponsabileDiReparto => "Responsabile Di Reparto",
KeyGroupEnum.Programmatore => "Programmatore",
KeyGroupEnum.Cliente => "Cliente",
KeyGroupEnum.ResponsabileAmministrativo => "Responsabile Amministrativo",
_ => throw new ArgumentOutOfRangeException(nameof(keyGroup), keyGroup, null)
};
}

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.PageState;
using salesbook.Shared.Core.Dto.Users;
@@ -6,7 +8,7 @@ using salesbook.Shared.Core.Interface;
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()
{
@@ -15,7 +17,10 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
userState.IsLoading = true;
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" });
DateTime? lastSync = localStorage.Get<DateTime>("last-user-sync");
lastSync = lastSync.Equals(DateTime.MinValue) ? null : lastSync;
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" }, lastSync);
var sorted = users
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
@@ -27,6 +32,8 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
userState.FilteredGroupedUserList = userState.GroupedUserList;
userState.AllUsers = users;
localStorage.Set("last-user-sync", DateTime.Now);
userState.NotifyUsersLoaded();
}