349 lines
11 KiB
C#
349 lines
11 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using EgwCoreLib.Razor;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using NLog.LayoutRenderers;
|
|
using static EgwCoreLib.Lux.Core.Enums;
|
|
|
|
namespace Lux.UI.Components.Pages
|
|
{
|
|
public partial class Offers
|
|
{
|
|
#region Protected Enums
|
|
|
|
/// <summary>
|
|
/// Stato compilazione offerta
|
|
/// </summary>
|
|
protected enum CompileStep
|
|
{
|
|
Draft = 0,
|
|
Header = 1,
|
|
General,
|
|
Rows,
|
|
Delivery,
|
|
FinalCheck
|
|
}
|
|
|
|
#endregion Protected Enums
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Filtro offerte: ogni stato / sole aperte
|
|
/// </summary>
|
|
protected bool AllStates
|
|
{
|
|
get => allState;
|
|
set
|
|
{
|
|
if (allState != value)
|
|
{
|
|
allState = value;
|
|
DoFilter();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string DivMainCss
|
|
{
|
|
get => SelRecord != null ? "col-6" : "col-12";
|
|
}
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected string txtState
|
|
{
|
|
get => allState ? "Tutte" : "Aperte";
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSelect(OfferModel curRec)
|
|
{
|
|
string answ = "";
|
|
if (SelRecord != null)
|
|
{
|
|
answ = curRec.OfferID == SelRecord.OfferID ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected void DoAdd()
|
|
{
|
|
EditRecord = new OfferModel()
|
|
{
|
|
RefYear = DateTime.Today.Year,
|
|
Description = $"Nuova Offerta {DateTime.Today:ddd yyyy.MM.dd}",
|
|
ValidUntil = DateTime.Today.AddMonths(1)
|
|
};
|
|
}
|
|
|
|
protected async Task DoClone(OfferModel rec2clone)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler duplicare interamente l'offerta selezionata?{Environment.NewLine}---------------------------{Environment.NewLine}Env: {rec2clone.Envir} | {rec2clone.OfferCode}{Environment.NewLine}{rec2clone.Description}{Environment.NewLine}Articoli: {rec2clone.NumItems}{Environment.NewLine}---------------------------{Environment.NewLine}Importo: {rec2clone.TotalPrice:C2}"))
|
|
return;
|
|
// clona intera offerta + tutte le righe...
|
|
await DLService.OfferClone(rec2clone);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void DoEdit(OfferModel curRec)
|
|
{
|
|
currStep = CompileStep.Header;
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
protected void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
|
|
protected void DoSelect(OfferModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
PeriodoSel = new EgwCoreLib.Utils.DtUtils.Periodo(EgwCoreLib.Utils.DtUtils.PeriodSet.ThisTrim);
|
|
SetupArrows();
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta lo stato dell'offerta VERIFICANDO i vari casi di stato di artenza/arrivo...
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <param name="newStatus"></param>
|
|
/// <returns></returns>
|
|
protected async Task SetState(OfferModel currRec, OfferStates newStatus)
|
|
{
|
|
/* ---------------------------------
|
|
* se lo conferma: esegue step speciali come
|
|
* - generazione item prod con ID ed etichetta
|
|
* - generazione delle "buste di stima" x richiedere task stima preliminare
|
|
* - generazione della lista delle etichette + riga d'ordine da inviare
|
|
* - invio chiamata su channelRedis
|
|
*
|
|
* il puro invio dovrà poter essere fatto anche dalla tab ordini... e serve visualizzazione delle estim pending
|
|
* --------------------------------- */
|
|
|
|
// in primis: se è già confermata chiede una autorizzazione di conferma speciale
|
|
if (currRec.OffertState == OfferStates.Confirmed)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler modificare l'offerta già confermata?"))
|
|
return;
|
|
}
|
|
// se va verso conferma ricorda che ora l'ordine passa in pianificazione (carico macchine)
|
|
if (newStatus == OfferStates.Confirmed)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler confermare l'offerta e generare gli ordini? verranno generate anche le etichette per tutti i prodotti correlati ({currRec.NumProdItems})"))
|
|
return;
|
|
await DLService.OrderFromOffer(currRec);
|
|
}
|
|
|
|
|
|
currRec.OffertState = newStatus;
|
|
await DLService.OffertUpsert(currRec);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<OfferModel> AllRecords = new List<OfferModel>();
|
|
private bool allState = false;
|
|
private int currPage = 1;
|
|
private CompileStep currStep = CompileStep.Draft;
|
|
private OfferModel? EditRecord = null;
|
|
private OfferModel? EditStateRec = null;
|
|
private bool isLoading = false;
|
|
private List<OfferModel> ListFilt = new List<OfferModel>();
|
|
private List<OfferModel> ListRecords = new List<OfferModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
/// <summary>
|
|
/// Periodo selezionato attuale
|
|
/// </summary>
|
|
private EgwCoreLib.Utils.DtUtils.Periodo PeriodoSel = new EgwCoreLib.Utils.DtUtils.Periodo(EgwCoreLib.Utils.DtUtils.PeriodSet.ThisYear);
|
|
|
|
private string searchVal = "";
|
|
private OfferModel? SelRecord = null;
|
|
|
|
private int totalCount = 0;
|
|
|
|
private string txtStyle = "font-size: 1.2em; font-weight:bold; fill: white;";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private List<string> listBord01 { get; set; } = new();
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void AdvStep(CompileStep newStep)
|
|
{
|
|
currStep = newStep;
|
|
}
|
|
|
|
private string ArrowBackCol(CompileStep arrowStep)
|
|
{
|
|
string answ = $"fill: #000000;";
|
|
if (arrowStep == currStep)
|
|
{
|
|
answ = $"fill: #123456;";
|
|
}
|
|
else if (arrowStep < currStep)
|
|
{
|
|
answ = $"fill: #456789;";
|
|
}
|
|
else
|
|
{
|
|
answ = $"fill: #89ABCD;";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private void DoClose()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
private void DoFilter()
|
|
{
|
|
// verifico eventuali filtri
|
|
ListFilt = AllRecords
|
|
.Where(x => x.OffertState == OfferStates.Open || allState)
|
|
.ToList();
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
ListFilt = ListFilt
|
|
.Where(x => x.Description.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase) || x.OfferCode.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
totalCount = ListFilt.Count();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva record ed avanza compilazione
|
|
/// </summary>
|
|
/// <param name="updRec"></param>
|
|
/// <returns></returns>
|
|
private async Task DoSave(OfferModel updRec)
|
|
{
|
|
// salvo record
|
|
await DLService.OffertUpsert(updRec);
|
|
// cambio step
|
|
CompileStep nextStep = currStep < CompileStep.FinalCheck ? currStep + 1 : currStep;
|
|
AdvStep(nextStep);
|
|
}
|
|
|
|
private void EditState(OfferModel? curRec)
|
|
{
|
|
EditStateRec = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rilegge tabella
|
|
/// </summary>
|
|
private async Task ForceReload()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(50);
|
|
await ReloadData();
|
|
await Task.Delay(50);
|
|
UpdateTable();
|
|
await Task.Delay(50);
|
|
isLoading = false;
|
|
await Task.Delay(50);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Legge i dati dei record completi
|
|
/// </summary>
|
|
private async Task ReloadData()
|
|
{
|
|
await DLService.OffersCheckExpired();
|
|
//AllRecords = await DLService.OfferGetAll();
|
|
AllRecords = await DLService.OfferGetFilt(PeriodoSel.Inizio, PeriodoSel.Fine);
|
|
DoFilter();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta periodo da filtro
|
|
/// </summary>
|
|
/// <param name="newPeriod"></param>
|
|
/// <returns></returns>
|
|
private async Task SetPeriodo(EgwCoreLib.Utils.DtUtils.Periodo newPeriod)
|
|
{
|
|
PeriodoSel = newPeriod;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SetupArrows()
|
|
{
|
|
listBord01 = new();
|
|
listBord01.Add("");
|
|
listBord01.Add("White");
|
|
listBord01.Add("");
|
|
listBord01.Add("");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = ListFilt
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#if false
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
RefreshDisplay();
|
|
}
|
|
|
|
protected void SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
RefreshDisplay();
|
|
}
|
|
|
|
protected void SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
if (sortField == e.ParamName)
|
|
{
|
|
sortAsc = e.IsAscending;
|
|
}
|
|
sortField = e.ParamName;
|
|
RefreshDisplay();
|
|
}
|
|
#endif
|
|
}
|
|
} |