358 lines
10 KiB
C#
358 lines
10 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using SHERPA.BBM.CORE.DbModels;
|
|
using SHERPA.BBM.CORE.DTO;
|
|
using SHERPA.BBM.UI.Data;
|
|
using static EgwCoreLib.Razor.Sorter;
|
|
|
|
namespace SHERPA.BBM.UI.Components
|
|
{
|
|
public partial class BillExtList : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelData CurrFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public PagInfo CurrPagInfo { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<BillDTO> E_BillSel { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_IdxBillExt { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_UpdateCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Filtro stato registrazione:
|
|
/// 0: tutti
|
|
/// 1: registrati ORD-FATT
|
|
/// -1: manca (almeno una) fattura
|
|
/// </summary>
|
|
[Parameter]
|
|
public int ShowDetails { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Mostrare solo record che mancano di CustomerId validi
|
|
/// </summary>
|
|
[Parameter]
|
|
public bool ShowOnlyNoCustId { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool ShowOnlyNoOrd { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool ShowSelect { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
MServ.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected BBM_EFService BBMService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string cssSelect(int IdxBillExt)
|
|
{
|
|
string answ = "";
|
|
if (currItem != null)
|
|
{
|
|
answ = (currItem.IdxBillExt == IdxBillExt) ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected bool isSelect(int IdxBillExt)
|
|
{
|
|
return BillSel.IdxBillExt == IdxBillExt;
|
|
//return DictSel.ContainsKey(IdxBillExt);
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
MServ.EA_SearchUpdated += OnSeachUpdated;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
protected void ResetSel()
|
|
{
|
|
currItem = null;
|
|
BillSel = new BillDTO();
|
|
E_IdxBillExt.InvokeAsync(0);
|
|
E_BillSel.InvokeAsync(BillSel);
|
|
}
|
|
|
|
protected void Select(BillingExtModel currRecord)
|
|
{
|
|
// preparo record
|
|
BillDTO newRec = new BillDTO()
|
|
{
|
|
IdxBillExt = currRecord.IdxBillExt,
|
|
Num = currRecord.Num,
|
|
Year = currRecord.YearRef,
|
|
Net = currRecord.Net - currRecord.B2ONav.Sum(x => x.Amount),
|
|
Amount = currRecord.Amount,
|
|
Paid = currRecord.Paid
|
|
};
|
|
|
|
// cerco eventuali movimenti associati da sottrarre..
|
|
|
|
currItem = currRecord;
|
|
BillSel = newRec;
|
|
E_IdxBillExt.InvokeAsync(currRecord.IdxBillExt);
|
|
E_BillSel.InvokeAsync(newRec);
|
|
}
|
|
|
|
protected async Task SortRequested(SortCallBack e)
|
|
{
|
|
sortField = e.ParamName;
|
|
sortAsc = e.IsAscending;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void sortTable()
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "NumAnno":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.YearRef).ThenBy(x => x.Num).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.YearRef).ThenByDescending(x => x.Num).ToList();
|
|
//SearchRecords = SearchRecords.OrderByDescending(x => x.Num).ToList();
|
|
}
|
|
break;
|
|
|
|
//case "Customer":
|
|
// if (sortAsc)
|
|
// {
|
|
// SearchRecords = SearchRecords.OrderBy(x => x.CustomerNav.RagSoc).ToList();
|
|
// }
|
|
// else
|
|
// {
|
|
// SearchRecords = SearchRecords.OrderByDescending(x => x.CustomerNav.RagSoc).ToList();
|
|
// }
|
|
// break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
// filtro record x display
|
|
ListRecords = SearchRecords
|
|
.Skip(NumRecord * (CurrPage - 1))
|
|
.Take(NumRecord).ToList();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private BillingExtModel? currItem = null;
|
|
|
|
private int TotalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int CurrPage
|
|
{
|
|
get => CurrPagInfo.CurrPage;
|
|
set => CurrPagInfo.CurrPage = value;
|
|
}
|
|
|
|
private int CustomerIdSel
|
|
{
|
|
get => CurrFilter != null ? CurrFilter.CustomerId : -1;
|
|
}
|
|
|
|
private BillDTO BillSel { get; set; } = new BillDTO();
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private SelData LastFilter { get; set; } = new SelData() { YearSel = -1 };
|
|
|
|
private PagInfo lastPagInfo { get; set; } = new PagInfo();
|
|
|
|
private string lastSearch { get; set; } = "";
|
|
private int lastShowDetails { get; set; } = 0;
|
|
|
|
private List<BillingExtModel> ListRecords { get; set; } = null!;
|
|
|
|
private int NumRecord
|
|
{
|
|
get => CurrPagInfo.NumRec;
|
|
set => CurrPagInfo.NumRec = value;
|
|
}
|
|
|
|
private List<BillingExtModel> SearchRecords { get; set; } = null!;
|
|
|
|
private bool sortAsc
|
|
{
|
|
get
|
|
{
|
|
bool answ = true;
|
|
var sVal = MServ.UsrParamGet("BillListSortAsc");
|
|
if (!string.IsNullOrEmpty(sVal))
|
|
{
|
|
bool.TryParse(sVal, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
MServ.UsrParamSet("BillListSortAsc", $"{value}");
|
|
}
|
|
}
|
|
|
|
private string sortField
|
|
{
|
|
get
|
|
{
|
|
string answ = MServ.UsrParamGet("BillListSortField");
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
MServ.UsrParamSet("BillListSortField", $"{value}");
|
|
}
|
|
}
|
|
|
|
private int YearSel
|
|
{
|
|
get => CurrFilter != null ? CurrFilter.YearSel : 0;
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task checkAndReload()
|
|
{
|
|
isLoading = true;
|
|
bool needReload = false;
|
|
if (!CurrFilter.Equals(LastFilter))
|
|
{
|
|
CurrPage = 1;
|
|
LastFilter = CurrFilter.Clone();
|
|
currItem = null;
|
|
needReload = true;
|
|
}
|
|
if (!CurrPagInfo.Equals(lastPagInfo))
|
|
{
|
|
lastPagInfo = CurrPagInfo.Clone();
|
|
needReload = true;
|
|
}
|
|
if (ShowDetails != lastShowDetails)
|
|
{
|
|
lastShowDetails = ShowDetails;
|
|
needReload = true;
|
|
}
|
|
if (!MServ.SearchVal.Equals(lastSearch))
|
|
{
|
|
lastSearch = MServ.SearchVal;
|
|
needReload = true;
|
|
}
|
|
// controllo se serve rilettura dati
|
|
if (needReload)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
isLoading = false;
|
|
}
|
|
|
|
private string fixReturn(string origString)
|
|
{
|
|
// elimino doppioni...
|
|
string answ = origString.Replace("\n\n", "\n");
|
|
// ora converto
|
|
answ = answ.Replace("\n", "<br/>");
|
|
return answ;
|
|
}
|
|
|
|
private string limChar(string origStr, int maxChar)
|
|
{
|
|
string answ = origStr;
|
|
if (origStr.Length > maxChar)
|
|
{
|
|
answ = origStr.Substring(0, maxChar) + "...";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await BBMService.BillingExtGetFilt(YearSel, 0, "", CustomerIdSel);
|
|
if (ShowOnlyNoCustId)
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.CustomerId == 0)
|
|
.ToList();
|
|
}
|
|
if (ShowOnlyNoOrd)
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.B2ONav.Count == 0)
|
|
.ToList();
|
|
}
|
|
// verifico se deve filtrare...
|
|
if (ShowDetails != 0)
|
|
{
|
|
if (ShowDetails == 1)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.HasBill).ToList();
|
|
}
|
|
else if (ShowDetails == -1)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => !x.HasBill || x.AccMovAmount != x.Net).ToList();
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(lastSearch))
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.Descript.Contains(lastSearch, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
TotalCount = SearchRecords.Count;
|
|
sortTable();
|
|
isLoading = false;
|
|
await InvokeAsync(() => E_UpdateCount.InvokeAsync(TotalCount));
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |