182 lines
5.3 KiB
C#
182 lines
5.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using SHERPA.Data;
|
|
using SHERPA.Data.DbModels;
|
|
using SHERPA.Data.Services;
|
|
|
|
namespace SHERPA.AD.Components
|
|
{
|
|
public partial class DocsStats
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelectDocExp CurrFilter { get; set; } = new SelectDocExp();
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> UpdateReq { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
protected bool IsLoading { get; set; }
|
|
|
|
protected SelectDocExp LastFilter { get; set; } = new SelectDocExp();
|
|
|
|
protected string percInc
|
|
{
|
|
get
|
|
{
|
|
string answ = "0%";
|
|
if (totImporto > 0)
|
|
{
|
|
answ = $"{totIncassato / totImporto:P0}";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected string percSca
|
|
{
|
|
get
|
|
{
|
|
string answ = "0%";
|
|
if (totImporto > 0)
|
|
{
|
|
answ = $"{totScadenze / totImporto:P0}";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected SADDataService SDService { get; set; } = null!;
|
|
|
|
protected List<vDocsExplModel>? SearchRecords { get; set; }
|
|
protected int totalCount { get; set; } = 0;
|
|
protected decimal totImporto { get; set; } = 1;
|
|
protected decimal totIncassato { get; set; } = 0;
|
|
protected decimal totScadenze { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task creaScadenze()
|
|
{
|
|
await SDService.CreaScadenze();
|
|
await Task.Delay(1);
|
|
await UpdateReq.InvokeAsync(true);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
LastFilter.Anno = -1;
|
|
ListSelCli = await SDService.VSelCliGetAll();
|
|
ListSelTipo = await SDService.TipoDocGetAll();
|
|
}
|
|
|
|
private bool reqAddNew { get; set; } = false;
|
|
|
|
private string addNewMessage
|
|
{
|
|
get => reqAddNew ? "Nascondi Nuova" : "Crea Nuova Fattura";
|
|
}
|
|
private string addNewCss
|
|
{
|
|
get => reqAddNew ? "btn-secondary" : "btn-primary";
|
|
}
|
|
|
|
private void toggleAddNew()
|
|
{
|
|
reqAddNew = !reqAddNew;
|
|
}
|
|
|
|
private async Task AggiungiDoc()
|
|
{
|
|
// aggiungo doc...
|
|
AccoDocModel newDoc = new AccoDocModel()
|
|
{
|
|
Anno = AnnoSel,
|
|
IdxTipo = IdxTipoSel,
|
|
IdxCli = IdxCliSel,
|
|
Num = NumSel,
|
|
Ritenuta = RitenutaSel,
|
|
Emesso = EmessoSel
|
|
};
|
|
await SDService.AccDocUpdate(newDoc);
|
|
// chiudo add
|
|
reqAddNew = false;
|
|
// riporto update
|
|
await Task.Delay(1);
|
|
await UpdateReq.InvokeAsync(true);
|
|
}
|
|
|
|
protected List<vSelCliModel> ListSelCli { get; set; } = new List<vSelCliModel>();
|
|
protected List<AnagTipoDocModel> ListSelTipo { get; set; } = new List<AnagTipoDocModel>();
|
|
private int _IdxTipo { get; set; } = 0;
|
|
protected int IdxTipoSel
|
|
{
|
|
get => _IdxTipo;
|
|
set
|
|
{
|
|
if (_IdxTipo != value)
|
|
{
|
|
_IdxTipo = value;
|
|
NumSel = SDService.DocsGetNextNum(AnnoSel, value);
|
|
}
|
|
}
|
|
}
|
|
protected int IdxCliSel { get; set; } = 0;
|
|
protected int AnnoSel { get; set; } = DateTime.Today.Year;
|
|
protected int NumSel { get; set; } = 0;
|
|
protected DateTime EmessoSel { get; set; } = DateTime.Today;
|
|
|
|
protected double RitenutaSel { get; set; } = 0;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
bool needReload = false;
|
|
// verifica filtro
|
|
if (!LastFilter.Equals(CurrFilter))
|
|
{
|
|
LastFilter = CurrFilter.clone();
|
|
needReload = true;
|
|
}
|
|
// deve ricaricare?
|
|
if (needReload)
|
|
{
|
|
await ReloadData(false);
|
|
}
|
|
}
|
|
|
|
protected async Task ReloadData(bool setChanged)
|
|
{
|
|
IsLoading = true;
|
|
SearchRecords = null;
|
|
await Task.Delay(1);
|
|
var allRec = await SDService.VDocExplGetFilt(CurrFilter);
|
|
if (CurrFilter.OnlySync)
|
|
{
|
|
SearchRecords = allRec.Where(x => string.IsNullOrEmpty(x.id_ext) || (x.Changed > 0)).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = allRec;
|
|
}
|
|
totalCount = SearchRecords.Where(x => x.ValMult != 0).ToList().Count;
|
|
totImporto = SearchRecords.Sum(x => x.netto * x.ValMult);
|
|
totIncassato = SearchRecords.Sum(x => x.totPagato * x.ValMult);
|
|
totScadenze = SearchRecords.Sum(x => x.totScadenze * x.ValMult);
|
|
await Task.Delay(1);
|
|
if (setChanged)
|
|
{
|
|
await InvokeAsync(() => StateHasChanged());
|
|
}
|
|
IsLoading = false;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |