304 lines
8.2 KiB
C#
304 lines
8.2 KiB
C#
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.DbModel.Items;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services.General;
|
|
using EgwCoreLib.Lux.Data.Services.Items;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Lux.UI.Components.Compo.Common
|
|
{
|
|
public partial class EditBom
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<BomItemDTO> BomList { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public OfferRowModel CurrRowRec { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<List<BomItemDTO>> EC_Updated { get; set; }
|
|
|
|
[Parameter]
|
|
public bool MassEdit { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Conversione oggetti x editing
|
|
/// </summary>
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (BomList != null && BomList.Count > 0)
|
|
{
|
|
int idx = 1;
|
|
// Convert List to Dictionary with index as key
|
|
bomDict = BomList
|
|
.Select(x => new BomDtoSel()
|
|
{
|
|
isSelected = false,
|
|
numRow = idx++,
|
|
ClassCode = x.ClassCode,
|
|
DescriptionCode = x.DescriptionCode,
|
|
ItemCode = x.ItemCode,
|
|
ItemID = x.ItemID,
|
|
ItemQty = x.ItemQty,
|
|
Price = x.Price,
|
|
PriceEff = x.PriceEff,
|
|
Qty = x.Qty,
|
|
Volume = x.Volume
|
|
})
|
|
.ToList();
|
|
totalCount = BomList.Count();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
}
|
|
else
|
|
{
|
|
isLoading = true;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Protected Classes
|
|
|
|
protected class BomDtoSel : BomItemDTO
|
|
{
|
|
#region Public Properties
|
|
|
|
public bool isSelected { get; set; } = false;
|
|
public int numRow { get; set; } = 1;
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
#endregion Protected Classes
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Dizionario interno oggetti x editare con indice
|
|
/// </summary>
|
|
private List<BomDtoSel> bomDict = new List<BomDtoSel>();
|
|
|
|
private List<BomDtoSel> bomPaged = new List<BomDtoSel>();
|
|
|
|
private int currPage = 1;
|
|
|
|
private decimal defMargin = 0.2M;
|
|
|
|
private double defQtyMax = 999;
|
|
|
|
private int defRound = 5;
|
|
|
|
private string defUM = "m";
|
|
|
|
private BomDtoSel? EditRecord = null;
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<ItemModel> ListItemAlt = new List<ItemModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
private bool selAll = false;
|
|
|
|
private int totalCount = 0;
|
|
|
|
private double totCost = 100;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
private double ImportoTotale
|
|
{
|
|
get
|
|
{
|
|
double valTot = 0;
|
|
if (bomDict != null)
|
|
{
|
|
valTot = bomDict.Sum(x => x.TotalCost);
|
|
}
|
|
return valTot;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
private IItemService IService { get; set; } = null!;
|
|
|
|
private double QtyTotale
|
|
{
|
|
get
|
|
{
|
|
double valTot = 0;
|
|
if (bomDict != null)
|
|
{
|
|
valTot = bomDict.Sum(x => x.Qty);
|
|
}
|
|
return valTot;
|
|
}
|
|
}
|
|
|
|
private bool SelAll
|
|
{
|
|
get => selAll;
|
|
set
|
|
{
|
|
if (selAll != value)
|
|
{
|
|
selAll = value;
|
|
foreach (var item in bomDict)
|
|
{
|
|
item.isSelected = selAll;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool showMassEditSave
|
|
{
|
|
get => bomDict != null && bomDict.Any(x => x.isSelected);
|
|
}
|
|
|
|
private bool ShowVolume
|
|
{
|
|
get => CurrRowRec.Envir == Constants.EXECENVIRONMENTS.BEAM || CurrRowRec.Envir == Constants.EXECENVIRONMENTS.WALL;
|
|
}
|
|
|
|
private int TotItemQty
|
|
{
|
|
get
|
|
{
|
|
int numTot = 0;
|
|
if (bomDict != null)
|
|
{
|
|
numTot = bomDict.Sum(x => x.ItemQty);
|
|
}
|
|
return numTot;
|
|
}
|
|
}
|
|
|
|
private double VolTotale
|
|
{
|
|
get
|
|
{
|
|
double valTot = 0;
|
|
if (bomDict != null)
|
|
{
|
|
valTot = bomDict.Sum(x => x.Volume);
|
|
}
|
|
return valTot;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void DoCancel()
|
|
{
|
|
EditRecord = null;
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task DoEdit(BomDtoSel editRec)
|
|
{
|
|
if (editRec.ItemID > 0)
|
|
{
|
|
// carico elenco alternative...
|
|
ListItemAlt = await IService.GetAltAsync(editRec.ItemID);
|
|
// riordino...
|
|
ListItemAlt = ListItemAlt
|
|
.OrderBy(x => x.ItemIDParent)
|
|
.ThenBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListItemAlt = new List<ItemModel>();
|
|
}
|
|
EditRecord = editRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio con conversion a list + ritorno a parent
|
|
/// </summary>
|
|
private Task DoSave()
|
|
{
|
|
isLoading = true;
|
|
// aggiorno l'oggetto nel mio dizionario
|
|
if (EditRecord != null)
|
|
{
|
|
// modifico il valore ID con quello selezionato nel selettore x l'oggetto
|
|
UpdateItem(EditRecord);
|
|
}
|
|
// deseleziono...
|
|
DoCancel();
|
|
// ...e passo al controller parent LINQ projection to base type
|
|
List<BomItemDTO> baseList = bomDict.Cast<BomItemDTO>().ToList();
|
|
return EC_Updated.InvokeAsync(baseList);
|
|
}
|
|
|
|
private async Task ForceItemPrice()
|
|
{
|
|
isLoading = true;
|
|
// chiamo metodo update x i soli valori selezionati...
|
|
var list2upd = bomDict.Where(x => x.isSelected).Cast<BomItemDTO>().ToList();
|
|
await IService.MassUpdateAsync(list2upd, totCost, (double)defMargin, defQtyMax, defUM, defRound);
|
|
// ...e passo al controller parent LINQ projection to base type
|
|
List<BomItemDTO> baseList = bomDict.Cast<BomItemDTO>().ToList();
|
|
await EC_Updated.InvokeAsync(baseList);
|
|
SelAll = false;
|
|
}
|
|
|
|
private void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update item nel dictionary
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="updatedItem"></param>
|
|
private void UpdateItem(BomDtoSel updatedItem)
|
|
{
|
|
int index = bomDict.FindIndex(x => x.numRow == updatedItem.numRow);
|
|
if (index >= 0)
|
|
{
|
|
bomDict[index] = updatedItem;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
bomPaged = bomDict
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |