Files
2023-07-12 17:25:01 +02:00

227 lines
6.4 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using SHERPA.BBM.CORE.DbModels;
using SHERPA.BBM.UI.Data;
namespace SHERPA.BBM.UI.Components
{
public partial class BillExt
{
#region Public Properties
[Parameter]
public SelData CurrFilter { get; set; } = null!;
[Parameter]
public OrderModel? CurrOrd { get; set; } = null;
#endregion Public Properties
#region Protected Properties
private bool IsLoading { get; set; } = false;
private List<BillingExtModel>? ListRecords { get; set; } = null;
private List<BillingExtModel>? SearchRecords { get; set; } = null;
#endregion Protected Properties
#region Protected Methods
protected async Task Delete(BillingExtModel currRecord)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record {currRecord.IdxBillExt}?"))
return;
#if false
BBMService.ResourceDelete(currRecord);
await UpdateData();
#endif
}
protected async Task DoImport(BillingExtModel currRecord)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler importare la fattura ed associarla all ordine {CurrOrd?.Num}/{CurrOrd?.YearRef} del {CurrOrd?.DateIns:yyyy-MM-dd}?"))
return;
currItem = currRecord;
}
protected override async Task OnParametersSetAsync()
{
IsLoading = true;
//YearSel = CurrOrd == null ? 0 : CurrOrd.YearRef;
//CodCli = CurrOrd == null ? "" : CurrOrd.CustomerNav.RagSoc;
valMin = CurrOrd == null ? 0 : CurrOrd.AmountTot * 95 / 100;
valMax = CurrOrd == null ? 999999 : CurrOrd.AmountTot * 122 / 100;
dtMin = CurrOrd == null ? new DateTime(2000, 1, 1) : CurrOrd.DateIns.AddDays(-7);
dtMax = CurrOrd == null ? new DateTime(DateTime.Today.Year + 1, 1, 1) : CurrOrd.DateIns.AddMonths(2);
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private BillingExtModel? currItem = null;
private List<CustomersModel>? CustomersList;
private List<int> yearsList = new List<int>();
#endregion Private Fields
#region Private Properties
[Inject]
private BBM_EFService BBMService { get; set; } = null!;
private string CodCli
{
get => CurrFilter.Customer;
}
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
private int YearSel
{
get => CurrFilter.YearSel;
}
protected decimal ValoreMin
{
get => valMin;
set
{
if (valMin != value)
{
IsLoading = true;
valMin = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
protected decimal ValoreMax
{
get => valMax;
set
{
if (valMax != value)
{
IsLoading = true;
valMax = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
protected DateTime DateMin
{
get => dtMin;
set
{
if (dtMin != value)
{
IsLoading = true;
dtMin = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
protected DateTime DateMax
{
get => dtMax;
set
{
if (dtMax != value)
{
IsLoading = true;
dtMax = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
protected bool DoFiltDate
{
get => filtDate;
set
{
if (filtDate != value)
{
IsLoading = true;
filtDate = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
protected bool DoFiltValue
{
get => filtValue;
set
{
if (filtValue != value)
{
IsLoading = true;
filtValue = value;
ReloadData().ConfigureAwait(false);
IsLoading = false;
}
}
}
private bool filtDate { get; set; } = false;
private bool filtValue { get; set; } = false;
private decimal valMin { get; set; } = 1;
private decimal valMax { get; set; } = 1000;
private DateTime dtMin { get; set; } = new DateTime(2000, 1, 1);
private DateTime dtMax { get; set; } = new DateTime(DateTime.Today.Year + 1, 1, 1);
#endregion Private Properties
#region Private Methods
private async Task ReloadData()
{
IsLoading = true;
await Task.Delay(1);
if (CurrOrd != null)
{
SearchRecords = await BBMService.BillingExtGetFilt(YearSel, 0, CodCli, -1);
}
else
{
SearchRecords = new List<BillingExtModel>();
}
// filtro per i valori ammessi...
ListRecords = SearchRecords;
if (DoFiltValue)
{
ListRecords = ListRecords
.Where(x => (x.Amount >= ValoreMin && x.Amount <= ValoreMax))
.ToList();
}
if (DoFiltDate)
{
ListRecords = ListRecords
.Where(x => (x.DateIns >= DateMin && x.DateIns <= DateMax))
.ToList();
}
yearsList = await BBMService.DocsYears();
CustomersList = await BBMService.CustomersGetAll("");
IsLoading = false;
await Task.Delay(1);
}
#endregion Private Methods
}
}