Aggiunto blocco per ispezioni non completate più vecchie di 20 giorni

This commit is contained in:
2026-03-02 12:30:24 +01:00
parent ab9578a45f
commit 63368748ab
13 changed files with 232 additions and 142 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using SteUp.Shared.Core.Entities; using SteUp.Shared.Core.Entities;
using SteUp.Shared.Core.Enum; using SteUp.Shared.Core.Enum;
using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Helpers;
@@ -17,6 +18,11 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
x.Data == data && x.Data == data &&
x.Rilevatore == rilevatore); x.Rilevatore == rilevatore);
public Task<List<Ispezione>> GetAllIspezioni() =>
db.Ispezioni
.AsNoTracking()
.ToListAsync();
public Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync() => public Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync() =>
db.Ispezioni db.Ispezioni
.Include(x => x.Schede) .Include(x => x.Schede)
@@ -68,7 +74,8 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
return true; return true;
} }
public async Task<bool> UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato) public async Task<bool> UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore,
StatusEnum stato)
{ {
var ispezione = await db.Ispezioni var ispezione = await db.Ispezioni
.FirstOrDefaultAsync(x => .FirstOrDefaultAsync(x =>

View File

@@ -1,7 +1,4 @@
@using CommunityToolkit.Mvvm.Messaging @using CommunityToolkit.Mvvm.Messaging
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.System.Network
@using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Ispezione
@using SteUp.Shared.Core.Messages.Scheda @using SteUp.Shared.Core.Messages.Scheda
@inject INetworkService NetworkService @inject INetworkService NetworkService
@@ -40,18 +37,18 @@
Size="Size.Medium" IconSize="Size.Medium"> Size="Size.Medium" IconSize="Size.Medium">
@if (SchedaVisible) @if (SchedaVisible)
{ {
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda"
Label="Nuova scheda" Color="Color.Surface"/>
if (ShowCompleteInspection) if (ShowCompleteInspection)
{ {
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@CompleteInspection" <MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@CompleteInspection"
Label="Concludi ispezione" Color="Color.Surface"/> Label="Concludi ispezione" Color="Color.Surface"/>
} }
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda"
Label="Nuova scheda" Color="Color.Surface"/>
} }
else else
{ {
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewActivity" <MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewInspection"
Label="Nuova ispezione" Color="Color.Surface"/> Label="Nuova ispezione" Color="Color.Surface"/>
} }
</MudFabMenu> </MudFabMenu>
@@ -87,9 +84,16 @@
return Task.CompletedTask; return Task.CompletedTask;
} }
private void NewActivity() private async Task NewInspection()
{ {
_ = ModalHelper.OpenSelectShop(Dialog); if (await SteupDataService.CanOpenNewInspection())
{
_ = Dialog.OpenSelectShop();
}
else
{
await Dialog.ShowWarning("Per aprire una nuova ispezione è necessario concludere prima tutte le ispezioni aperte più vecchie di 20 giorni!");
}
} }
private void CompleteInspection() => private void CompleteInspection() =>
@@ -98,7 +102,7 @@
private async Task NewScheda() private async Task NewScheda()
{ {
var ispezione = SteupDataService.InspectionPageState.Ispezione; var ispezione = SteupDataService.InspectionPageState.Ispezione;
var modal = await ModalHelper.OpenFormScheda(Dialog, ispezione.CodMdep, ispezione.Data, true); var modal = await Dialog.OpenFormScheda(ispezione.CodMdep, ispezione.Data, true);
if (modal is { Canceled: false }) if (modal is { Canceled: false })
Messenger.Send(new NewSchedaMessage()); Messenger.Send(new NewSchedaMessage());

View File

@@ -173,8 +173,7 @@
private async Task CreateNewScheda(JtbFasiDto jtbFasi) private async Task CreateNewScheda(JtbFasiDto jtbFasi)
{ {
var modal = await ModalHelper.OpenFormScheda( var modal = await Dialog.OpenFormScheda(
Dialog,
SteupDataService.InspectionPageState.Ispezione.CodMdep, SteupDataService.InspectionPageState.Ispezione.CodMdep,
SteupDataService.InspectionPageState.Ispezione.Data, SteupDataService.InspectionPageState.Ispezione.Data,
true, true,
@@ -244,7 +243,7 @@
{ {
if (errorMessage == null) return; if (errorMessage == null) return;
_ = ModalHelper.ShowError(Dialog, errorMessage); _ = Dialog.ShowError(errorMessage);
} }
void IDisposable.Dispose() void IDisposable.Dispose()

View File

@@ -64,7 +64,7 @@
private async Task UpdateScheda() private async Task UpdateScheda()
{ {
var modal = await ModalHelper.OpenFormScheda(Dialog, CodMdep, Data, false, Scheda); var modal = await Dialog.OpenFormScheda(CodMdep, Data, false, Scheda);
if (modal is { Canceled: false, Data: Scheda scheda }) await OnSchedaModified.InvokeAsync(scheda); if (modal is { Canceled: false, Data: Scheda scheda }) await OnSchedaModified.InvokeAsync(scheda);
} }
@@ -74,8 +74,17 @@
if (result is true) if (result is true)
{ {
VisibleOverlay = true;
StateHasChanged();
if (Scheda.ActivityId != null)
await IntegrySteupService.DeleteScheda(Scheda.ActivityId);
var deleteScheda = await IspezioniService.DeleteSchedaAsync(Scheda.Id); var deleteScheda = await IspezioniService.DeleteSchedaAsync(Scheda.Id);
if (deleteScheda) await OnSchedaDeleted.InvokeAsync(Scheda); if (deleteScheda) await OnSchedaDeleted.InvokeAsync(Scheda);
VisibleOverlay = false;
StateHasChanged();
} }
} }

View File

@@ -1,9 +1,19 @@
<MudDialog OnBackdropClick="Cancel"> <MudDialog OnBackdropClick="Cancel">
<DialogContent> <DialogContent>
@if (IsWarning)
{
<div class="exception-header mb-2">
<i class="ri-error-warning-line"></i>
<span>Attenzione</span>
</div>
}
else
{
<div class="exception-header mb-2"> <div class="exception-header mb-2">
<i class="ri-emotion-unhappy-line"></i> <i class="ri-emotion-unhappy-line"></i>
<span>Ops</span> <span>Ops</span>
</div> </div>
}
<div class="text"> <div class="text">
<code>@ErrorMessage</code> <code>@ErrorMessage</code>
</div> </div>
@@ -18,6 +28,7 @@
@code { @code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter] public string ErrorMessage { get; set; } = string.Empty; [Parameter] public string ErrorMessage { get; set; } = string.Empty;
[Parameter] public bool IsWarning { get; set; }
private void Cancel() => MudDialog.Cancel(); private void Cancel() => MudDialog.Cancel();
} }

View File

@@ -8,9 +8,16 @@
.exception-header > i { .exception-header > i {
font-size: 3rem; font-size: 3rem;
line-height: normal; line-height: normal;
}
.error-icon {
color: var(--bs-danger); color: var(--bs-danger);
} }
.warning-icon {
color: var(--bs-warning);
}
.exception-header > span { .exception-header > span {
font-size: x-large; font-size: x-large;
font-weight: 700; font-weight: 700;

View File

@@ -285,7 +285,7 @@
{ {
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
await ModalHelper.ShowError(Dialog, e.Message); await Dialog.ShowError(e.Message);
} }
if (IsNew) await NewSave(apiResponse); if (IsNew) await NewSave(apiResponse);
@@ -474,7 +474,7 @@
private async Task OpenAddAttached() private async Task OpenAddAttached()
{ {
var result = await ModalHelper.OpenAddAttached(Dialog); var result = await Dialog.OpenAddAttached();
if (result is not { Canceled: false, Data: List<AttachedDto> attachedList }) return; if (result is not { Canceled: false, Data: List<AttachedDto> attachedList }) return;
OnLoading = true; OnLoading = true;
@@ -561,7 +561,7 @@
return; return;
} }
var modal = await ModalHelper.OpenSelectArt(Dialog, articoli); var modal = await Dialog.OpenSelectArt(articoli);
await InvokeAsync(() => await InvokeAsync(() =>
{ {
@@ -614,7 +614,7 @@
{ {
var activityDescriptions = await IntegryApiService.SuggestActivityDescription(Scheda.ActivityTypeId); var activityDescriptions = await IntegryApiService.SuggestActivityDescription(Scheda.ActivityTypeId);
var modal = await ModalHelper.OpenSuggestActivityDescription(Dialog, activityDescriptions); var modal = await Dialog.OpenSuggestActivityDescription(activityDescriptions);
if (modal is { Canceled: false, Data: not null }) if (modal is { Canceled: false, Data: not null })
Scheda.Note = modal.Data!.ToString(); Scheda.Note = modal.Data!.ToString();
@@ -694,7 +694,7 @@
{ {
if (errorMessage == null) return; if (errorMessage == null) return;
_ = ModalHelper.ShowError(Dialog, errorMessage); _ = Dialog.ShowError(errorMessage);
} }
private void RemoveArt(string barcode) private void RemoveArt(string barcode)

View File

@@ -6,6 +6,7 @@ namespace SteUp.Shared.Core.Data.Contracts;
public interface ISteupDataService public interface ISteupDataService
{ {
Task Init(); Task Init();
Task<bool> CanOpenNewInspection();
void RegisterAppVersion(); void RegisterAppVersion();
List<PuntoVenditaDto> PuntiVenditaList { get; } List<PuntoVenditaDto> PuntiVenditaList { get; }

View File

@@ -3,11 +3,11 @@ using IntegryApiClient.Core.Domain.Abstraction.Contracts.Device;
using SteUp.Shared.Core.Data.Contracts; using SteUp.Shared.Core.Data.Contracts;
using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Dto;
using SteUp.Shared.Core.Dto.PageState; using SteUp.Shared.Core.Dto.PageState;
using SteUp.Shared.Core.Enum;
using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Helpers;
using SteUp.Shared.Core.Interface.IntegryApi; using SteUp.Shared.Core.Interface.IntegryApi;
using SteUp.Shared.Core.Interface.LocalDb; using SteUp.Shared.Core.Interface.LocalDb;
using SteUp.Shared.Core.Interface.System; using SteUp.Shared.Core.Interface.System;
using SteUp.Shared.Core.Interface.System.Network;
namespace SteUp.Shared.Core.Data; namespace SteUp.Shared.Core.Data;
@@ -76,6 +76,20 @@ public class SteupDataService(
} }
} }
public async Task<bool> CanOpenNewInspection()
{
var completedInspection = await ispezioniService.GetAllIspezioni();
if (completedInspection.IsNullOrEmpty()) return true;
//Controllo se sono presenti attività più vecchie di 20 giorni non chiuse
//Se presenti non si possono aprire nuove ispezioni
return !completedInspection.Any(x =>
x.Stato != StatusEnum.Completata &&
x.Data < DateTime.Now.AddDays(-20)
);
}
private async Task LoadDataAsync() private async Task LoadDataAsync()
{ {
if (!await userSession.IsLoggedIn()) return; if (!await userSession.IsLoggedIn()) return;

View File

@@ -6,9 +6,11 @@ using SteUp.Shared.Core.Entities;
namespace SteUp.Shared.Core.Helpers; namespace SteUp.Shared.Core.Helpers;
public abstract class ModalHelper public static class ModalHelper
{ {
public static async Task<DialogResult?> OpenSelectShop(IDialogService dialog) extension(IDialogService dialog)
{
public async Task<DialogResult?> OpenSelectShop()
{ {
var modal = await dialog.ShowAsync<ModalSelectShop>( var modal = await dialog.ShowAsync<ModalSelectShop>(
"ModalSelectShop", "ModalSelectShop",
@@ -25,7 +27,7 @@ public abstract class ModalHelper
return await modal.Result; return await modal.Result;
} }
public static async Task<DialogResult?> OpenFormScheda(IDialogService dialog, string codMdep, DateTime data, public async Task<DialogResult?> OpenFormScheda(string codMdep, DateTime data,
bool isNew = false, Scheda? scheda = null) bool isNew = false, Scheda? scheda = null)
{ {
scheda = isNew && scheda == null ? new Scheda() : scheda; scheda = isNew && scheda == null ? new Scheda() : scheda;
@@ -50,7 +52,7 @@ public abstract class ModalHelper
return await modal.Result; return await modal.Result;
} }
public static async Task<DialogResult?> OpenAddAttached(IDialogService dialog) public async Task<DialogResult?> OpenAddAttached()
{ {
var modal = await dialog.ShowAsync<ModalAddAttached>( var modal = await dialog.ShowAsync<ModalAddAttached>(
"Add attached", "Add attached",
@@ -67,8 +69,7 @@ public abstract class ModalHelper
return await modal.Result; return await modal.Result;
} }
public static async Task<DialogResult?> OpenSuggestActivityDescription(IDialogService dialog, public async Task<DialogResult?> OpenSuggestActivityDescription(List<StbActivityTyperDto>? activityTypers)
List<StbActivityTyperDto>? activityTypers)
{ {
var modal = await dialog.ShowAsync<ModalSuggestDescription>( var modal = await dialog.ShowAsync<ModalSuggestDescription>(
"Suggest activity description", "Suggest activity description",
@@ -88,7 +89,7 @@ public abstract class ModalHelper
return await modal.Result; return await modal.Result;
} }
public static async Task<DialogResult?> OpenSelectArt(IDialogService dialog, List<ArticoliInGrigliaDto>? articoli) public async Task<DialogResult?> OpenSelectArt(List<ArticoliInGrigliaDto>? articoli)
{ {
var modal = await dialog.ShowAsync<ModalSelectArt>( var modal = await dialog.ShowAsync<ModalSelectArt>(
"ModalSelectArt", "ModalSelectArt",
@@ -110,7 +111,7 @@ public abstract class ModalHelper
return await modal.Result; return await modal.Result;
} }
public static async Task ShowError(IDialogService dialog, string message) public async Task ShowError(string message)
{ {
var modal = await dialog.ShowAsync<ModalError>( var modal = await dialog.ShowAsync<ModalError>(
"ModalError", "ModalError",
@@ -131,4 +132,28 @@ public abstract class ModalHelper
await modal.Result; await modal.Result;
} }
public async Task ShowWarning(string message)
{
var modal = await dialog.ShowAsync<ModalError>(
"ModalError",
new DialogParameters<ModalError>
{
{ x => x.ErrorMessage, message },
{ x => x.IsWarning, true }
},
new DialogOptions
{
FullScreen = false,
CloseButton = false,
NoHeader = true,
BackdropClick = true,
FullWidth = true,
MaxWidth = MaxWidth.ExtraLarge
}
);
await modal.Result;
}
}
} }

View File

@@ -17,4 +17,6 @@ public interface IIntegrySteupService
Task<SaveSchedaResponseDto?> SaveMultipleSchede(List<SaveRequestDto> request); Task<SaveSchedaResponseDto?> SaveMultipleSchede(List<SaveRequestDto> request);
Task CompleteInspection(string activityId); Task CompleteInspection(string activityId);
Task UploadFile(string activityId, byte[] file, string fileName); Task UploadFile(string activityId, byte[] file, string fileName);
Task DeleteScheda(string activityId);
} }

View File

@@ -1,4 +1,5 @@
using SteUp.Shared.Core.Entities; using System.Linq.Expressions;
using SteUp.Shared.Core.Entities;
using SteUp.Shared.Core.Enum; using SteUp.Shared.Core.Enum;
namespace SteUp.Shared.Core.Interface.LocalDb; namespace SteUp.Shared.Core.Interface.LocalDb;
@@ -7,6 +8,7 @@ public interface IIspezioniService
{ {
// ISPEZIONI // ISPEZIONI
Task<Ispezione?> GetIspezioneAsync(string codMdep, DateTime data, string rilevatore); Task<Ispezione?> GetIspezioneAsync(string codMdep, DateTime data, string rilevatore);
Task<List<Ispezione>> GetAllIspezioni();
Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync(); Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync();
Task AddIspezioneAsync(Ispezione ispezione); Task AddIspezioneAsync(Ispezione ispezione);
Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore); Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore);

View File

@@ -67,4 +67,13 @@ public class IntegrySteupService(IIntegryApiRestClient integryApiRestClient) : I
return integryApiRestClient.Post<object>($"{BaseRequest}/uploadAttachment", content, queryParams!); return integryApiRestClient.Post<object>($"{BaseRequest}/uploadAttachment", content, queryParams!);
} }
public Task DeleteScheda(string activityId) =>
integryApiRestClient.AuthorizedGet<object>(
$"{BaseRequest}/deleteScheda",
new Dictionary<string, object>
{
{ "activityId", activityId }
}
);
} }