1030 lines
35 KiB
C#
1030 lines
35 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using EgwMultiEngineManager.Data;
|
|
using Lux.UI.Components.Compo.Config;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using Microsoft.EntityFrameworkCore.Storage.Json;
|
|
using Microsoft.JSInterop;
|
|
using NLog.LayoutRenderers;
|
|
using System.Text;
|
|
using WebWindowComplex;
|
|
using WebWindowComplex.DTO;
|
|
using static EgwCoreLib.Lux.Core.Enums;
|
|
|
|
namespace Lux.UI.Components.Compo
|
|
{
|
|
public partial class OfferRowMan : IDisposable
|
|
{
|
|
#region Public Enums
|
|
|
|
/// <summary>
|
|
/// modalità modifica riga offerta
|
|
/// </summary>
|
|
public enum EditMode
|
|
{
|
|
None = 0,
|
|
|
|
/// <summary>
|
|
/// Dati generici del record
|
|
/// </summary>
|
|
RecData,
|
|
|
|
/// <summary>
|
|
/// Struttura serializzata (es JWD)
|
|
/// </summary>
|
|
SerStruc,
|
|
|
|
/// <summary>
|
|
/// BOM editing
|
|
/// </summary>
|
|
BOM,
|
|
|
|
/// <summary>
|
|
/// File editing (es BTL)
|
|
/// </summary>
|
|
File
|
|
}
|
|
|
|
#endregion Public Enums
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public OfferModel CurrRecord { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public DisplayMode DisplayMode { get; set; } = DisplayMode.Standard;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_Updated { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Dispose sottoscrizione canale
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
DLService.UpdatePipe.EA_NewMessage -= UpdatePipe_EA_NewMessage;
|
|
DLService.CalcDonePipe.EA_NewMessage -= CalcDonePipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Predisposizione valori live SVG/JWD
|
|
/// </summary>
|
|
protected LivePayload CurrData = new LivePayload();
|
|
|
|
/// <summary>
|
|
/// Configurazione elenchi anagrafiche
|
|
/// </summary>
|
|
protected BaseListPayload SetupList = new BaseListPayload();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected ConfigDataService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IConfiguration Config { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected CalcRequestService CService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Costo totale calcolato x offerta
|
|
/// </summary>
|
|
protected double GrandTotCost
|
|
{
|
|
get => AllRecords != null && AllRecords.Count > 0 ? AllRecords.Sum(x => x.TotalCost) : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Margine medio calcolato x offerta
|
|
/// </summary>
|
|
protected double GrandTotMargin
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (AllRecords != null && AllRecords.Count > 0)
|
|
{
|
|
double totPrice = AllRecords.Sum(x => x.TotalPrice);
|
|
double totCost = AllRecords.Sum(x => x.TotalCost);
|
|
if (totPrice > 0)
|
|
{
|
|
answ = (totPrice - totCost) / totPrice;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Importo totale calcolato x offerta
|
|
/// </summary>
|
|
protected double GrandTotPrice
|
|
{
|
|
get => AllRecords != null && AllRecords.Count > 0 ? AllRecords.Sum(x => x.TotalPrice) : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Num totale obj calcolato x offerta
|
|
/// </summary>
|
|
protected double GrandTotQty
|
|
{
|
|
get => AllRecords != null && AllRecords.Count > 0 ? AllRecords.Sum(x => x.Qty) : 0;
|
|
}
|
|
|
|
[Inject]
|
|
protected IWebHostEnvironment HostEnv { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected ImageCacheService ICService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// ID Offerta corrente
|
|
/// </summary>
|
|
protected int OfferID
|
|
{
|
|
get => CurrRecord.OfferID;
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected void ClosePopup()
|
|
{
|
|
CurrEditMode = EditMode.None;
|
|
EditRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunge una nuova riga vuota come nota sotto il record selezionato oppure in coda...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task DoAddNote()
|
|
{
|
|
int numRow = AllRecords.Count + 1;
|
|
if (EditRecord != null)
|
|
{
|
|
numRow = EditRecord.RowNum + 1;
|
|
}
|
|
OfferRowModel newNote = new OfferRowModel()
|
|
{
|
|
OfferID = CurrRecord.OfferID,
|
|
Envir = CurrRecord.Envir,
|
|
RowNum = numRow,
|
|
OfferRowUID = "",
|
|
Qty = 0,
|
|
BomCost = 0,
|
|
BomPrice = 0,
|
|
StepCost = 0,
|
|
StepPrice = 0
|
|
};
|
|
await DLService.OffertRowUpsert(newNote);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annullamento modifica
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoCancel()
|
|
{
|
|
isLoading = true;
|
|
CurrEditMode = EditMode.None;
|
|
EditRecord = null;
|
|
await Task.Delay(20);
|
|
await DLService.FlushCacheOffersAsync();
|
|
await Task.Delay(20);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona riga richiesta
|
|
/// </summary>
|
|
/// <param name="rec2clone"></param>
|
|
protected async Task DoClone(OfferRowModel rec2clone)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler duplicare la riga corrente?"))
|
|
return;
|
|
|
|
// calcolo indice riga...
|
|
int numRow = totalCount + 1;
|
|
OfferRowModel newRec = new OfferRowModel()
|
|
{
|
|
AwaitBom = true,
|
|
AwaitPrice = true,
|
|
Envir = rec2clone.Envir,
|
|
FileName = rec2clone.FileName,
|
|
FileResource = rec2clone.FileResource,
|
|
FileSize = rec2clone.FileSize,
|
|
Inserted = DateTime.Now,
|
|
ItemBOM = rec2clone.ItemBOM,
|
|
ItemSteps = rec2clone.ItemSteps,
|
|
Modified = DateTime.Now,
|
|
Note = rec2clone.Note,
|
|
OfferID = OfferID,
|
|
OfferRowUID = "",
|
|
Qty = rec2clone.Qty,
|
|
RowNum = numRow,
|
|
SellingItemID = rec2clone.SellingItemID,
|
|
SerStruct = rec2clone.SerStruct,
|
|
StepCost = rec2clone.StepCost,
|
|
StepPrice = rec2clone.StepPrice,
|
|
};
|
|
// salvo sul DB
|
|
await DLService.OffertRowUpsert(newRec);
|
|
// chiamo update record che non hanno UID x questo ordine
|
|
var list2fix = await DLService.OffertRowFixUid(OfferID);
|
|
if (list2fix != null && list2fix.Count > 0)
|
|
{
|
|
// rileggo i miei record...
|
|
await ReloadData();
|
|
var listCalc = SorListCalc();
|
|
foreach (var item in listCalc)
|
|
{
|
|
// se UID è tra quelli da ricalcolare...
|
|
if (list2fix.Contains(item.OfferRowUID))
|
|
{
|
|
// chiedo BOM e immagine
|
|
await reqBomUpdate(item);
|
|
}
|
|
}
|
|
}
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione riga offerta
|
|
/// </summary>
|
|
/// <param name="rec2del"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoDelete(OfferRowModel rec2del)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler eliminare la riga corrente?<br/>Codice: {rec2del.OfferRowUID} | {rec2del.Note} | importo tot: {rec2del.TotalPrice}"))
|
|
return;
|
|
|
|
await DLService.OffertRowDelete(rec2del);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Va in edit della riga richiesta
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEdit(OfferRowModel curRec)
|
|
{
|
|
// imposto edit record
|
|
EditRecord = curRec;
|
|
/// modalitàedit: gestione valori campi record
|
|
CurrEditMode = EditMode.RecData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Apre editor finestre del record richiesto
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEditJwd(OfferRowModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
/// modalitàedit: gestione JWD
|
|
CurrEditMode = EditMode.SerStruc;
|
|
// preparazione dati da record corrente
|
|
PrepareWindowData(EditRecord.SerStruct);
|
|
// reset prev
|
|
prevJwd = "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio edit record + reload
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoSave(OfferRowModel curRec)
|
|
{
|
|
isLoading = true;
|
|
// salvo record modificato...
|
|
await DLService.OffertRowUpsert(curRec);
|
|
// reset
|
|
CurrEditMode = EditMode.None;
|
|
EditRecord = null;
|
|
await DLService.FlushCacheOffersAsync();
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Seleziono riga senza cambiare modalità editing
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoSelect(OfferRowModel curRec)
|
|
{
|
|
// imposto edit record
|
|
EditRecord = curRec;
|
|
/// modalitàedit: gestione valori campi record
|
|
CurrEditMode = EditMode.None;
|
|
}
|
|
|
|
protected void DoSwapMat(OfferRowModel currRow)
|
|
{
|
|
CurrEditMode = EditMode.BOM;
|
|
EditRecord = currRow;
|
|
CurrBomList = DLService.OffertGetBomList(EditRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Display fileSize scalato
|
|
/// </summary>
|
|
/// <param name="size"></param>
|
|
/// <returns></returns>
|
|
protected string fSize(long size)
|
|
{
|
|
return EgwCoreLib.Utils.FileHelpers.SizeSuffix(size, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcolo URL immagine
|
|
/// </summary>
|
|
/// <param name="imgUid"></param>
|
|
/// <param name="env"></param>
|
|
/// <returns></returns>
|
|
protected string imgUrl(string imgUid, string env)
|
|
{
|
|
// cast string su env..
|
|
EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
Enum.TryParse(env, out envir);
|
|
return ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Forza parametri general selezionati nell'offerta
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task OfferForceParameters()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler impostare i parametri selezionati per l'offerta?"))
|
|
return;
|
|
// recupero obj dizionario x i parametri compresi...
|
|
ParamDict CurrSel = new ParamDict(CurrRecord.DictPresel);
|
|
// metto a waiting tutte le righe con bom...
|
|
var listCalc = SorListCalc();
|
|
foreach (var item in listCalc)
|
|
{
|
|
await DLService.OffertUpdateAwaitState(item.OfferRowID, true, true);
|
|
// poiché non è gestito evento ritorno update window interno si "scassa" --> try catch/ if FALSE
|
|
try
|
|
{
|
|
string rColor = CurrSel.GetVal("Color");
|
|
string rGlass = CurrSel.GetVal("Glass");
|
|
string rProfile = CurrSel.GetVal("Profile");
|
|
string rWood = CurrSel.GetVal("Wood");
|
|
var newSerStruct = SerialMan.MassUpdate((string)item.SerStruct, null, null, rColor, rWood, rGlass, rProfile);
|
|
await DLService.OffertRowUpdateSerStruct(item.OfferRowID, newSerStruct);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// verifica preliminare UID
|
|
await DLService.OffertRowFixUid(OfferID);
|
|
|
|
// ricalcolo di tutte le BOM e relativi prezzi...
|
|
foreach (var item in listCalc)
|
|
{
|
|
// chiedo BOM e immagine
|
|
await reqBomUpdate(item);
|
|
}
|
|
|
|
//await DoRecalcOffer();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento costing completo:
|
|
/// - verifica UID
|
|
/// - ricalcolo BOM
|
|
/// - update prezzi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task OfferUpdateAllCosting()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler ricalcolare/validare in toto l'offerta?"))
|
|
return;
|
|
|
|
// metto a waiting tutte le righe con bom...
|
|
var listCalc = SorListCalc();
|
|
foreach (var item in listCalc)
|
|
{
|
|
await DLService.OffertUpdateAwaitState(item.OfferRowID, true, true);
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// verifica preliminare UID
|
|
await DLService.OffertRowFixUid(OfferID);
|
|
|
|
// fixme todo da riverificare con calcolo BOM funzionante
|
|
#if false
|
|
// rileggo i record...
|
|
await ReloadData();
|
|
#endif
|
|
// ricalcolo di tutte le BOM e relativi prezzi...
|
|
foreach (var item in listCalc)
|
|
{
|
|
// chiedo BOM e immagine
|
|
await reqBomUpdate(item);
|
|
}
|
|
#if false
|
|
await DoRecalcOffer();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica e ricalcolo dei prezzi degli items nell'offerta
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task OfferUpdatePrices()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler ricalcolare a costi correnti offerta?"))
|
|
return;
|
|
|
|
await DoRecalcOffer();
|
|
}
|
|
|
|
/// <summary>
|
|
/// init obj
|
|
/// </summary>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ConfInit();
|
|
prevJwd = "";
|
|
await ReloadBaseList();
|
|
DLService.UpdatePipe.EA_NewMessage += UpdatePipe_EA_NewMessage;
|
|
DLService.CalcDonePipe.EA_NewMessage += CalcDonePipe_EA_NewMessage;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lancia la richiesta di ricaolo della BOM dal JWD (o equivalente)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task RequestBom(OfferRowModel currRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler ricalcolare la BOM?"))
|
|
return;
|
|
|
|
await reqBomUpdate(currRec);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Css di verifica riga selezionata
|
|
/// </summary>
|
|
/// <param name="selRow"></param>
|
|
/// <returns></returns>
|
|
protected string RowClass(OfferRowModel selRow)
|
|
{
|
|
return EditRecord != null && EditRecord.OfferRowID == selRow.OfferRowID ? "table-info" : "";
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<GenValueModel> AllColors = new();
|
|
|
|
private List<EnvirParamModel> AllConfEnvir = new();
|
|
|
|
private List<GlassModel> AllConfGlass = new();
|
|
|
|
private List<HardwareModel> AllConfHardware = new();
|
|
|
|
private List<ProfileModel> AllConfProfile = new();
|
|
|
|
private List<WoodModel> AllConfWood = new();
|
|
|
|
private List<OfferRowModel> AllRecords = new List<OfferRowModel>();
|
|
|
|
private string apiUrl = "";
|
|
|
|
private List<string> AvailColorMaterialList = new List<string>();
|
|
|
|
private List<string> AvailFamilyHardwareList = new List<string>();
|
|
|
|
private List<string> AvailGlassList = new List<string>();
|
|
|
|
private List<Egw.Window.Data.Hardware> AvailHardwareList = new();
|
|
|
|
private List<string> AvailMaterialList = new List<string>();
|
|
|
|
private List<string> AvailProfileList = new List<string>();
|
|
|
|
private string calcTag = "calc";
|
|
|
|
private List<BomItemDTO>? CurrBomList = null;
|
|
|
|
/// <summary>
|
|
/// Modalità editint attiva
|
|
/// </summary>
|
|
private EditMode CurrEditMode = EditMode.None;
|
|
|
|
private int currPage = 1;
|
|
|
|
private string currSvg = "";
|
|
|
|
/// <summary>
|
|
/// Record in Edit corrente
|
|
/// </summary>
|
|
private OfferRowModel? EditRecord = null;
|
|
|
|
private string genBasePath = "generic";
|
|
|
|
private string GenericBasePath = "";
|
|
|
|
private string imgBasePath = "";
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<OfferRowModel> ListRecords = new List<OfferRowModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
/// <summary>
|
|
/// Versione originale (pre edit)
|
|
/// </summary>
|
|
private string origJwd = "";
|
|
|
|
/// <summary>
|
|
/// Versione precedente JWD x test e confronto
|
|
/// </summary>
|
|
private string prevJwd = "";
|
|
|
|
/// <summary>
|
|
/// Dizionario richieste
|
|
/// </summary>
|
|
private Dictionary<string, string> reqDict = new Dictionary<string, string>();
|
|
|
|
private string subChannel = "";
|
|
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Ricevuto SVG, se è il mio lo aggiorno...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async void CalcDonePipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
// vale SOLO SE sono in editing...
|
|
if (EditRecord != null)
|
|
{
|
|
// aggiorno visualizzazione
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly SVG da mostrare
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
if (currArgs.msgUid.Equals($"{subChannel}:{EditRecord.OfferRowUID}"))
|
|
{
|
|
currSvg = currArgs.newMessage;
|
|
// salvo in live data...
|
|
CurrData.SvgPreview = currSvg;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiude edit andando eventualmente a salvare
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
private async Task CloseEdit(bool doSave)
|
|
{
|
|
// ...se ho editing
|
|
if (EditRecord != null)
|
|
{
|
|
bool updateBom = false;
|
|
// SE richiesto salvataggio...
|
|
if (doSave)
|
|
{
|
|
// salvo su DB!
|
|
await DLService.OffertRowUpdateSerStruct(EditRecord.OfferRowID, prevJwd);
|
|
updateBom = true;
|
|
}
|
|
else
|
|
// altrimenti ricalcolo valore salvato
|
|
{
|
|
prevJwd = EditRecord.SerStruct;
|
|
CurrData.CurrJwd = EditRecord.SerStruct;
|
|
}
|
|
if (updateBom)
|
|
{
|
|
await reqBomUpdate(EditRecord);
|
|
}
|
|
// aggiorno nel dizionari
|
|
if (reqDict.ContainsKey("Jwd"))
|
|
{
|
|
reqDict["Jwd"] = prevJwd;
|
|
}
|
|
|
|
if (reqDict != null && reqDict.Count > 0)
|
|
{
|
|
// chiamo richiesta update
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
|
|
calcRequestDTO.EnvType = EditRecord.Envir;
|
|
calcRequestDTO.DictExec = reqDict;
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{EditRecord.OfferRowUID}", calcRequestDTO);
|
|
}
|
|
EditRecord = null;
|
|
CurrEditMode = EditMode.None;
|
|
}
|
|
}
|
|
|
|
private void ConfInit()
|
|
{
|
|
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
|
|
imgBasePath = Config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "";
|
|
GenericBasePath = Config.GetValue<string>("ServerConf:GenericBaseUrl") ?? "";
|
|
calcTag = Config.GetValue<string>("ServerConf:CalcTag") ?? "calc";
|
|
subChannel = Config.GetValue<string>("ServerConf:SvgChannel") ?? "";
|
|
}
|
|
|
|
private async Task DoRecalcOffer()
|
|
{
|
|
isLoading = true;
|
|
// ciclo sulle righe...
|
|
await setAwaitPrice(true, false);
|
|
await Task.Delay(50);
|
|
await DLService.OffertUpdateCost(OfferID);
|
|
await Task.Delay(50);
|
|
await setAwaitPrice(false, true);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
await EC_Updated.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Svuota cache corrente + rilegge dati
|
|
/// </summary>
|
|
private async Task ForceReloadData()
|
|
{
|
|
isLoading = true;
|
|
CurrEditMode = EditMode.None;
|
|
EditRecord = null;
|
|
await Task.Delay(20);
|
|
await DLService.FlushCacheOffersAsync();
|
|
await Task.Delay(20);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Preparazione dati x componente edit JWD
|
|
/// </summary>
|
|
/// <param name="currJwd"></param>
|
|
private void PrepareWindowData(string currJwd)
|
|
{
|
|
// preparo conf oggetti x controllo
|
|
SetupList = SetupList = new BaseListPayload()
|
|
{
|
|
ColorMaterial = AvailColorMaterialList,
|
|
FamilyHardware = AvailFamilyHardwareList,
|
|
Glass = AvailGlassList,
|
|
Hardware = AvailHardwareList,
|
|
Material = AvailMaterialList,
|
|
Profile = AvailProfileList,
|
|
TemplateDTO = null
|
|
};
|
|
CurrData = new LivePayload()
|
|
{
|
|
CurrJwd = currJwd,
|
|
SvgPreview = currSvg
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// init classi configurazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ReloadBaseList()
|
|
{
|
|
// lettura config setup varie da DB/Cache Redis
|
|
AllConfEnvir = await DLService.ConfEnvirParamGetAllAsync();
|
|
AllConfGlass = await DLService.ConfGlassGetAllAsync();
|
|
var rawHw = CDService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "HW.AGB");
|
|
// hw filtro solo validi...
|
|
AllConfHardware = rawHw
|
|
.Where(x => !x.FamilyName.Equals(x.Description, StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
AllConfProfile = await DLService.ConfProfileGetAllAsync();
|
|
AllConfWood = await DLService.ConfWoodGetAllAsync();
|
|
AllColors = await DLService.GenValGetFiltAsync("WoodCol");
|
|
// conversione tipi
|
|
AvailGlassList = AllConfGlass
|
|
.Select(x => x.Description)
|
|
.ToList();
|
|
AvailProfileList = AllConfProfile
|
|
.Select(x => x.Description)
|
|
.ToList();
|
|
AvailFamilyHardwareList = AllConfHardware
|
|
.DistinctBy(x => x.FamilyName)
|
|
.OrderBy(x => x.FamilyName)
|
|
.Select(x => x.FamilyName)
|
|
.ToList();
|
|
AvailHardwareList = AllConfHardware
|
|
.Select(x => new Egw.Window.Data.Hardware(x.Id, x.FamilyName, x.Description, x.OpeningType, x.Shape, x.SashQty, x.SashPosition))
|
|
.ToList();
|
|
AvailMaterialList = AllConfWood
|
|
.Select(x => x.Description)
|
|
.ToList();
|
|
// FixMe Todo: aggiunta profili (manca anche nel costruttore...)
|
|
AvailColorMaterialList = AllColors
|
|
.OrderBy(x => x.Ordinal)
|
|
.Select(x => x.ValString)
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Legge i dati dei record completi
|
|
/// </summary>
|
|
private async Task ReloadData()
|
|
{
|
|
if (OfferID > 0)
|
|
{
|
|
AllRecords = await DLService.OfferRowGetByOffer(OfferID);
|
|
totalCount = AllRecords.Count();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua vera richiesta della BOM
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
private async Task reqBomUpdate(OfferRowModel currRec)
|
|
{
|
|
// salvo richiesta BOM su record
|
|
currRec.AwaitBom = true;
|
|
currRec.AwaitPrice = true;
|
|
await DLService.OffertUpdateAwaitState(currRec.OfferRowID, true, true);
|
|
|
|
// preparo la domanda serializzata
|
|
Dictionary<string, string> DictExec = new Dictionary<string, string>();
|
|
// verifico parametri da conf envir...
|
|
var envRec = AllConfEnvir.FirstOrDefault(x => x.EnvirID == currRec.Envir);
|
|
string serKey = envRec != null ? envRec.SerStrucKey : "Jwd";
|
|
// cablata la BOM
|
|
DictExec.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.BOM}");
|
|
//DictExec.Add("Mode", "2");
|
|
// UID cablato x ora...
|
|
DictExec.Add("UID", currRec.OfferRowUID);
|
|
DictExec.Add(serKey, currRec.SerStruct);
|
|
|
|
CalcRequestDTO req = new CalcRequestDTO()
|
|
{
|
|
EnvType = currRec.Envir,
|
|
//EnvType = currEnv,
|
|
DictExec = DictExec
|
|
};
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await CService.CallRestPost($"{apiUrl}/{genBasePath}", $"{calcTag}/{currRec.OfferRowUID}", req);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue salvataggio del file ricevuto
|
|
/// </summary>
|
|
/// <param name="secureName">Nome secure da impiegare</param>
|
|
/// <param name="content">Contenuto file</param>
|
|
private bool saveFileContent(string folderPath, string secureName, string content)
|
|
{
|
|
bool answ = false;
|
|
if (!string.IsNullOrEmpty(folderPath))
|
|
{
|
|
// calcolo path file...
|
|
string filePath = Path.Combine("unsafe_uploads", folderPath, secureName);
|
|
File.WriteAllText(filePath, content);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio del JWD aggiornato nella mia riga di offerta
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
private async void SaveJWD(Dictionary<string, string> args)
|
|
{
|
|
// ...se ho editing
|
|
if (EditRecord != null)
|
|
{
|
|
// SE contiene il mio Jwd...
|
|
if (args.ContainsKey("Jwd"))
|
|
{
|
|
reqDict = args;
|
|
string serStruct = reqDict["Jwd"];
|
|
// controllo SE variato...
|
|
if (!prevJwd.Equals(serStruct))
|
|
{
|
|
// aggiorno val prev
|
|
prevJwd = serStruct;
|
|
// aggiorno live data
|
|
CurrData.CurrJwd = serStruct;
|
|
// chiamo richiesta update
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
|
|
calcRequestDTO.EnvType = EditRecord.Envir;
|
|
calcRequestDTO.DictExec = reqDict;
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{EditRecord.OfferRowUID}", calcRequestDTO);
|
|
#if false
|
|
// salvo su DB!
|
|
await DLService.OffertRowUpdateSerStruct(EditRecord.OfferRowID, serStruct);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task setAwaitPrice(bool awaitPrice, bool flushCache)
|
|
{
|
|
foreach (var item in AllRecords)
|
|
{
|
|
await DLService.OffertUpdateAwaitState(item.OfferRowID, false, awaitPrice, flushCache);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco SalesOfferRows calcolabili:
|
|
/// - contengono serializzazione come JWD
|
|
/// - contengono file come BTL
|
|
/// </summary>
|
|
private List<OfferRowModel> SorListCalc()
|
|
{
|
|
var rawList = AllRecords
|
|
.Where(x => (!string.IsNullOrEmpty(x.SerStruct) && x.SerStruct.Length > 2) || (!string.IsNullOrEmpty(x.FileName) && !string.IsNullOrEmpty(x.FileResource)))
|
|
.ToList();
|
|
return rawList ?? new List<OfferRowModel>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle visibilità modifica file indicando ID della OfferRow corrente (o zero se deselect)
|
|
/// </summary>
|
|
private void ToggleFileEdit(OfferRowModel? currRec)
|
|
{
|
|
CurrEditMode = currRec == null ? EditMode.None : EditMode.File;
|
|
EditRecord = currRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva nel record corrente la BOM aggiornata e poi ricalcola importo...
|
|
/// </summary>
|
|
/// <param name="newBomList"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private async void UpdateBom(List<BomItemDTO> newBomList)
|
|
{
|
|
if (EditRecord != null)
|
|
{
|
|
// salvo BOM nel record corrente...
|
|
bool fatto = await DLService.OffertRowUpdateBom(EditRecord.OfferRowID, newBomList);
|
|
// ricalcolo offerta completa
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Task verifica update ricevuti
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private async void UpdatePipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
// aggiorno visualizzazione
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly SVG da mostrare
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
// cerco se faccia aprte dei record correnti...
|
|
var recFound = AllRecords.Any(x => x.OfferRowUID == currArgs.newMessage);
|
|
if (recFound)
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(10);
|
|
#if false
|
|
if (currArgs.msgUid.Equals($"{subChannel}:{windowUid}"))
|
|
{
|
|
}
|
|
#endif
|
|
// se si tratta dell'UID corrente --> fa update
|
|
await DoRecalcOffer();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.OrderBy(x => x.RowNum)
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue lettura file + invio richiesta specifica
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <returns></returns>
|
|
|
|
private async Task UploadFile(InputFileChangeEventArgs e)
|
|
{
|
|
if (EditRecord != null)
|
|
{
|
|
// init dizionari arg richiesta update
|
|
Dictionary<string, string> fileArgs = new Dictionary<string, string>();
|
|
|
|
// leggo il contenuto del PRIMO (singolo) file
|
|
IBrowserFile file = e.File;
|
|
// limite file size (al momento 10 MB)
|
|
var maxAllowedSize = 10 * 1024 * 1024;
|
|
|
|
using var stream = file.OpenReadStream(maxAllowedSize);
|
|
using var reader = new StreamReader(stream);
|
|
string rawContent = await reader.ReadToEndAsync();
|
|
|
|
// calcolo il nome del file trusted...
|
|
string trustedFileName = Path.GetRandomFileName();
|
|
EditRecord.FileResource = trustedFileName;
|
|
EditRecord.FileName = file.Name;
|
|
EditRecord.FileSize = rawContent.LongCount();
|
|
// salvo sul DB i dati (nome, nome sicuro, size...)
|
|
await DLService.OffertRowUpdateFileData(EditRecord);
|
|
|
|
// parametri richiesta
|
|
fileArgs.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.PREVIEW}");
|
|
fileArgs.Add("Btl", rawContent);
|
|
// invio!
|
|
CalcRequestDTO calcRequestDTO = new CalcRequestDTO();
|
|
calcRequestDTO.EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.BEAM;
|
|
calcRequestDTO.DictExec = fileArgs;
|
|
await ICService.CallRestPost($"{apiUrl}/{GenericBasePath}", $"{calcTag}/{EditRecord.OfferRowUID}", calcRequestDTO);
|
|
|
|
#if false
|
|
// salvo in locale il file: SISTEMARE PERMESSI
|
|
saveFileContent(EditFileRecord.OfferRowUID, trustedFileName, rawContent);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |