72af60d96f
- Fix gestione storni su AccMov - paramewtro x fix all mov
280 lines
7.7 KiB
C#
280 lines
7.7 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using SHERPA.BBM.CORE.DbModels;
|
|
using SHERPA.BBM.CORE.DTO;
|
|
using SHERPA.BBM.UI.Data;
|
|
|
|
namespace SHERPA.BBM.UI.Components
|
|
{
|
|
public partial class OrdersCard : 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 EventCallback<AccMovModel> E_AccMovSel { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> E_DataUpdated { 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 ShowConvert { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public bool ShowFixAllMov { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public string Title { get; set; } = "Ordini";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
private bool EnableFixAllMov { get; set; } = false;
|
|
|
|
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 OrdId)
|
|
{
|
|
var result = await BBMService.Bill2OrdgetByOrd(OrdId);
|
|
return result.Count > 0;
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
EnableFixAllMov = Configuration.GetValue<bool>("RuntimeOpt:EnableFixAllMov");
|
|
MServ.ShowSearch = true;
|
|
MServ.EA_SearchUpdated += OnSeachUpdated;
|
|
}
|
|
[Inject]
|
|
private IConfiguration Configuration { get; set; } = null!;
|
|
|
|
private bool OrdersTrySetup = false;
|
|
|
|
protected async Task RemoveB2O()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare le registrazioni per l'ordine selezionato?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
// eseguo rimozione record Bill2Ord
|
|
await BBMService.Bill2OrdRemLinkOrd(selOrdId);
|
|
SetOrd(0);
|
|
SaveDictSel(new Dictionary<int, OrderDTO>());
|
|
await E_DataUpdated.InvokeAsync(true);
|
|
}
|
|
|
|
protected void SaveDictSel(Dictionary<int, OrderDTO> newDict)
|
|
{
|
|
DictOrdSel = newDict;
|
|
}
|
|
|
|
protected void SaveMovSel(AccMovModel recordSel)
|
|
{
|
|
AccMovSel = recordSel;
|
|
E_AccMovSel.InvokeAsync(recordSel);
|
|
}
|
|
|
|
protected void SetBasket(int newBaskId)
|
|
{
|
|
currPage = 1;
|
|
selBaskId = newBaskId;
|
|
E_SelBasketId.InvokeAsync(newBaskId);
|
|
}
|
|
|
|
protected void SetCount(int newNum)
|
|
{
|
|
totalCount = newNum;
|
|
}
|
|
|
|
protected void SetCurrPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected void SetCustomer(int newCustId)
|
|
{
|
|
currPage = 1;
|
|
E_SelCustomerId.InvokeAsync(newCustId);
|
|
}
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void SetOrd(int newIdx)
|
|
{
|
|
selOrdId = newIdx;
|
|
}
|
|
|
|
protected async Task TrySetupOrd()
|
|
{
|
|
OrdersTrySetup = Configuration.GetValue<bool>("RuntimeOpt:OrdersTrySetup");
|
|
if (OrdersTrySetup)
|
|
{
|
|
await BBMService.OrdersTrySetup();
|
|
await E_DataUpdated.InvokeAsync(true);
|
|
}
|
|
}
|
|
protected bool isProcessing { get; set; } = false;
|
|
protected async Task TrySetupMovOrd()
|
|
{
|
|
// recupero i record
|
|
var allRecords = await BBMService.OrderGetFilt(CurrFilter);
|
|
// confrerma poiché lenta...
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler procedere a generare i movimenti mancanti? saranno analizzati {allRecords.Count:N0} ordini..."))
|
|
return;
|
|
isProcessing = true;
|
|
// ciclo per TUTTI gli ordini mostrati e cerca di generare i movimenti mancanti
|
|
if (allRecords != null)
|
|
{
|
|
foreach (var record in allRecords)
|
|
{
|
|
await checkCreateMov(record);
|
|
}
|
|
}
|
|
isProcessing = false;
|
|
}
|
|
/// <summary>
|
|
/// Verifica se l'ordine abbia movimenti associati, sennò li genera...
|
|
/// </summary>
|
|
private async Task checkCreateMov(vOrderDataModel 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);
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool isLoading = false;
|
|
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private AccMovModel? AccMovSel { get; set; } = null;
|
|
|
|
private decimal AmountTot
|
|
{
|
|
get => DictOrdSel != null ? DictOrdSel.Sum(x => x.Value.Amount) : 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 Dictionary<int, OrderDTO> DictOrdSel { get; set; } = new Dictionary<int, OrderDTO>();
|
|
|
|
private int numRecord
|
|
{
|
|
get => CurrPagInfo.NumRec;
|
|
set => CurrPagInfo.NumRec = value;
|
|
}
|
|
|
|
private int selBaskId { get; set; } = 1;
|
|
|
|
private int selOrdId { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Modalita display ordini: 0 = Tutti 1 = Registrati
|
|
/// -1 = NON Registrati
|
|
/// </summary>
|
|
private int ShowDet
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
var sVal = MServ.UsrParamGet("OrdCardShowDet");
|
|
if (!string.IsNullOrEmpty(sVal))
|
|
{
|
|
int.TryParse(sVal, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
MServ.UsrParamSet("OrdCardShowDet", $"{value}");
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ResetDetail()
|
|
{
|
|
if (ShowDet != 0)
|
|
{
|
|
ShowDet = 0;
|
|
await Task.Delay(1);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |