Files

272 lines
6.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using SHERPA.BBM.CORE.DTO;
using SHERPA.BBM.UI.Data;
namespace SHERPA.BBM.UI.Components
{
public partial class BillCard : IDisposable
{
#region Public Properties
[Parameter]
public SelData CurrFilter { get; set; } = null!;
[Parameter]
public EventCallback<bool> E_DataUpdated { get; set; }
[Parameter]
public EventCallback<BillDTO> E_BillSel { get; set; }
[Parameter]
public EventCallback<int> E_IdxBillExt { 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;
[Parameter]
public bool ShowDropRec { get; set; } = false;
[Parameter]
public bool ShowImport { get; set; } = false;
/// <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;
[Parameter]
public bool ShowTryLink { get; set; } = false;
[Parameter]
public string Title { get; set; } = "Fatture";
#endregion Public Properties
#region Public Methods
public void Dispose()
{
MServ.EA_SearchUpdated -= OnSeachUpdated;
}
public async void OnSeachUpdated()
{
currPage = 1;
await Task.Delay(1);
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected BBM_EFService BBMService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MessageService MServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task<bool> HasBill(int IdxBillExt)
{
var result = await BBMService.Bill2OrdgetByBill(IdxBillExt);
return result.Count > 0;
}
protected async Task ImportExtBill()
{
isLoading = true;
await Task.Delay(50);
DateTime dtStart = new DateTime(YearFrom, 1, 1);
DateTime dtEnd = new DateTime(DateTime.Today.Year + 1, 1, 1);
await BBMService.BillExtImport(dtStart, dtEnd);
await ReportUpdated(true);
}
protected override void OnInitialized()
{
MServ.ShowSearch = true;
MServ.EA_SearchUpdated += OnSeachUpdated;
}
protected async Task RemoveB2O()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare le registrazioni per la fattura selezionata?"))
return;
await Task.Delay(1);
// eseguo rimozione record Bill2Ord
await BBMService.Bill2OrdRemLinkBill(selIdxBill);
SetBill(0);
SaveBillSel(new BillDTO());
await E_DataUpdated.InvokeAsync(true);
}
protected async Task ReportUpdated(bool forceReload)
{
await E_DataUpdated.InvokeAsync(forceReload);
}
protected void SaveBillSel(BillDTO newBill)
{
BillSel = newBill;
E_BillSel.InvokeAsync(newBill);
}
protected void SetBasket(int newBaskId)
{
currPage = 1;
selBaskId = newBaskId;
E_SelBasketId.InvokeAsync(newBaskId);
}
protected void SetBill(int newIdx)
{
selIdxBill = newIdx;
E_IdxBillExt.InvokeAsync(newIdx);
}
protected void SetCount(int newNum)
{
totalCount = newNum;
isLoading = false;
}
protected void SetCurrPage(int newNum)
{
currPage = newNum;
}
protected void SetCustomer(int newCustId)
{
currPage = 1;
selCustId = newCustId;
E_SelCustomerId.InvokeAsync(newCustId);
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
}
protected async Task TryLinkBill()
{
isLoading = true;
await Task.Delay(50);
await BBMService.BillExtTryLink();
await ReportUpdated(true);
}
#endregion Protected Methods
#region Private Fields
private bool isLoading = false;
private int totalCount = 0;
private int YearFrom = 2021;
#endregion Private Fields
#region Private Properties
private decimal AmountTot
{
get => BillSel != null ? BillSel.Net : 0;
}
private string cssBtnResDetail
{
get => ShowDet == 0 ? "btn btn-secondary" : "btn btn-primary";
}
private int currPage
{
get => CurrPagInfo.CurrPage;
set => CurrPagInfo.CurrPage = value;
}
private PagInfo CurrPagInfo { get; set; } = new PagInfo() { NumRec = 5 };
private BillDTO BillSel { get; set; } = new BillDTO();
private bool IsLoading { get; set; } = false;
private int numRecord
{
get => CurrPagInfo.NumRec;
set => CurrPagInfo.NumRec = value;
}
private decimal PaidTot
{
get => BillSel != null ? BillSel.Paid : 0;
}
private int selBaskId { get; set; } = 1;
private int selCustId { get; set; } = 1;
private int selIdxBill { get; set; } = 0;
/// <summary>
/// Modalità show ordini 0 = Tutti 1 = Registrati
/// -1 = NON Registrati
/// </summary>
private int ShowDet
{
get
{
int answ = 0;
var sVal = MServ.UsrParamGet("BillCardShowDet");
if (!string.IsNullOrEmpty(sVal))
{
int.TryParse(sVal, out answ);
}
return answ;
}
set
{
MServ.UsrParamSet("BillCardShowDet", $"{value}");
}
}
#endregion Private Properties
#region Private Methods
private async Task ResetDetail()
{
if (ShowDet != 0)
{
ShowDet = 0;
await Task.Delay(1);
}
}
#endregion Private Methods
}
}