492 lines
15 KiB
C#
492 lines
15 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
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 OrderList : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool AccMovEditEnabled { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool AccMovSelEnabled { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public SelData CurrFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public PagInfo CurrPagInfo { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<AccMovModel> E_AccMovSelected { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<Dictionary<int, OrderDTO>> E_DictSel { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_OrdId { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_SelBasketId { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_SelCustomerId { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_UpdateCount { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ShowAll { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Filtro stato registrazione:
|
|
/// 0: tutti
|
|
/// 1: registrati ORD-FATT
|
|
/// 2: PARZIALMENTE registrati ORD-FATT
|
|
/// -1: manca (almeno una) fattura
|
|
/// </summary>
|
|
[Parameter]
|
|
public int ShowDetails { get; set; } = 0;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(int OrdId)
|
|
{
|
|
string answ = "";
|
|
if (currItem != null)
|
|
{
|
|
answ = (currItem.OrdId == OrdId) ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
MServ.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected int TotalCount = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected BBM_EFService BBMService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected List<vOrderDataModel> ListRecords { get; set; } = new List<vOrderDataModel>();
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
protected List<vOrderDataModel> SearchRecords { get; set; } = new List<vOrderDataModel>();
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task closeModal()
|
|
{
|
|
await Task.Delay(1);
|
|
showModalCreate = false;
|
|
}
|
|
|
|
protected async Task Delete(vOrderDataModel currRecord)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record '{currRecord.Num}/{currRecord.YearRef}'?"))
|
|
return;
|
|
// elimino ordine + risorse + movimenti
|
|
await BBMService.OrderDelete(currRecord.OrdId);
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
MServ.EA_SearchUpdated += OnSeachUpdated;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
protected async Task ReloadOrdMov(bool doRefresh)
|
|
{
|
|
showModalCreate = false;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ReportAccMov(AccMovModel AccMovSel)
|
|
{
|
|
await E_AccMovSelected.InvokeAsync(AccMovSel);
|
|
}
|
|
|
|
protected async Task ResetSel()
|
|
{
|
|
currItem = null;
|
|
DictSel = new Dictionary<int, OrderDTO>();
|
|
await E_OrdId.InvokeAsync(0);
|
|
await E_DictSel.InvokeAsync(DictSel);
|
|
await E_AccMovSelected.InvokeAsync(new AccMovModel());
|
|
}
|
|
|
|
protected async Task SelBasket(int SelBaskId)
|
|
{
|
|
await E_SelBasketId.InvokeAsync(SelBaskId);
|
|
}
|
|
|
|
protected async Task SelCustomer(int SelCustId)
|
|
{
|
|
await E_SelCustomerId.InvokeAsync(SelCustId);
|
|
}
|
|
|
|
protected async Task Select(vOrderDataModel selRecord)
|
|
{
|
|
OrderModel currRecord = await BBMService.OrderGetByKey(selRecord.OrdId);
|
|
if (currRecord != null)
|
|
{
|
|
// verifico se serva creare movimenti...
|
|
await checkCreateMov(currRecord);
|
|
// preparo record
|
|
OrderDTO newRec = new OrderDTO()
|
|
{
|
|
OrdId = currRecord.OrdId,
|
|
Num = currRecord.Num,
|
|
Year = currRecord.YearRef,
|
|
AmountOrig = currRecord.AmountTot - currRecord.BillTot,
|
|
Amount = currRecord.AmountTot - currRecord.BillTot,
|
|
CodDoc = currRecord.CodDoc,
|
|
Descript = currRecord.Descript,
|
|
Note = currRecord.Note
|
|
};
|
|
DictSel = new Dictionary<int, OrderDTO>();
|
|
currItem = currRecord;
|
|
DictSel.Add(currRecord.OrdId, newRec);
|
|
await E_OrdId.InvokeAsync(currRecord.OrdId);
|
|
await E_DictSel.InvokeAsync(DictSel);
|
|
await E_AccMovSelected.InvokeAsync(new AccMovModel());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creazione movimenti richiesti
|
|
/// </summary>
|
|
/// <param name="createReq"></param>
|
|
/// <returns></returns>
|
|
protected async Task showCreateMov(bool createReq)
|
|
{
|
|
// mostro la modale x creare tipo di movimento...
|
|
showModalCreate = true;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
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 "CodDoc":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.CodDoc).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.CodDoc).ToList();
|
|
}
|
|
break;
|
|
|
|
case "DateIns":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.DateIns).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.DateIns).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Num":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Num).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Num).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Customer":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.RagSoc).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.RagSoc).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Basket":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.BaskDescript).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.BaskDescript).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Descript":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Descript).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Descript).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Amount":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.AmountTot).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.AmountTot).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Bill":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.BillTot).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.BillTot).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Paid":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.PaidTot).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.PaidTot).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
// filtro record x display
|
|
ListRecords = SearchRecords.Skip(NumRecord * (CurrPage - 1)).Take(NumRecord).ToList();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private OrderModel? currItem = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int CurrPage
|
|
{
|
|
get => CurrPagInfo.CurrPage;
|
|
set => CurrPagInfo.CurrPage = value;
|
|
}
|
|
|
|
private Dictionary<int, OrderDTO> DictSel { get; set; } = new Dictionary<int, OrderDTO>();
|
|
|
|
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 int NumRecord
|
|
{
|
|
get => CurrPagInfo.NumRec;
|
|
set => CurrPagInfo.NumRec = value;
|
|
}
|
|
|
|
private bool showModalCreate { get; set; } = false;
|
|
|
|
private bool sortAsc
|
|
{
|
|
get
|
|
{
|
|
bool answ = true;
|
|
var sVal = MServ.UsrParamGet("OrdListSortAsc");
|
|
if (!string.IsNullOrEmpty(sVal))
|
|
{
|
|
bool.TryParse(sVal, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
MServ.UsrParamSet("OrdListSortAsc", $"{value}");
|
|
}
|
|
}
|
|
|
|
private string sortField
|
|
{
|
|
get
|
|
{
|
|
string answ = MServ.UsrParamGet("BillListSortField");
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
MServ.UsrParamSet("BillListSortField", $"{value}");
|
|
}
|
|
}
|
|
|
|
#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.ToUpper().Equals(lastSearch))
|
|
{
|
|
lastSearch = MServ.SearchVal.ToUpper();
|
|
needReload = true;
|
|
}
|
|
// controllo se serve rilettura dati
|
|
if (needReload)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se l'ordine abbia movimenti associati, sennò li genera...
|
|
/// </summary>
|
|
private async Task checkCreateMov(OrderModel currOrd)
|
|
{
|
|
// se mancano movimenti
|
|
if (currOrd.AmountReq != currOrd.BillTot)
|
|
{
|
|
// creo 1 movimento...
|
|
List<AccMovModel> mov2create = new List<AccMovModel>();
|
|
mov2create.Add(new AccMovModel() { OrdId = currOrd.OrdId, IdxBillExt = null, Amount = currOrd.AmountOpen });
|
|
await BBMService.AccMovUpsert(mov2create);
|
|
await ReloadData();
|
|
}
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
SearchRecords = await BBMService.OrderGetFilt(CurrFilter);
|
|
// verifico se deve filtrare...
|
|
if (ShowDetails != 0)
|
|
{
|
|
if (ShowDetails == 1)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => !x.MovOpen).ToList();
|
|
}
|
|
else if (ShowDetails == -1)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.MovOpen).ToList();
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(lastSearch))
|
|
{
|
|
string SVAL = lastSearch.ToUpper();
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.CodDoc.ToUpper().Contains(SVAL) || x.Descript.ToUpper().Contains(SVAL) || x.Note.ToUpper().Contains(SVAL))
|
|
.ToList();
|
|
}
|
|
TotalCount = SearchRecords.Count;
|
|
// fix ordinamento e selezione record...
|
|
sortTable();
|
|
// paginazione
|
|
isLoading = false;
|
|
await InvokeAsync(() => E_UpdateCount.InvokeAsync(TotalCount));
|
|
}
|
|
|
|
private string trimTxt(string txtOrig, int maxChar)
|
|
{
|
|
string answ = txtOrig;
|
|
if (txtOrig.Length > maxChar)
|
|
{
|
|
answ = $"{txtOrig.Substring(0, maxChar - 3)}...";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |