Files
lux/Lux.UI/Components/Pages/Items.razor.cs
T
2026-03-09 18:39:12 +01:00

149 lines
4.0 KiB
C#

using EgwCoreLib.Lux.Core;
using EgwCoreLib.Lux.Data.DbModel.Items;
using EgwCoreLib.Lux.Data.DbModel.Task;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
namespace Lux.UI.Components.Pages
{
public partial class Items
{
#region Protected Methods
protected override async Task OnInitializedAsync()
{
isLoading = true;
await ReloadBaseData();
isLoading = false;
}
#endregion Protected Methods
#region Private Fields
private ItemModel? editRecItem = null;
private SellingItemModel? editRecSellItem = null;
private bool isLoading = false;
private List<ItemGroupModel> ListItemGroup = new List<ItemGroupModel>();
private List<JobTaskModel> ListJobTask = new List<JobTaskModel>();
/// <summary>
/// Modalità articoli vendita vs articoli acquisto
/// </summary>
private bool showItemsBuy = true;
#endregion Private Fields
#region Private Properties
private FiltSelect CurrFilt { get; set; } = new FiltSelect();
[Inject]
private DataLayerServices DLService { get; set; } = null!;
/// <summary>
/// Etichetta tipo items gestiti/mostrati
/// </summary>
private string txtCurrType
{
get => showItemsBuy ? "Acquisto" : "Vendita";
}
#endregion Private Properties
#region Private Methods
private void DoAdd()
{
if (showItemsBuy)
{
editRecItem = new ItemModel()
{
CodGroup = ListItemGroup.FirstOrDefault()?.CodGroup ?? "",
ItemType = EgwCoreLib.Lux.Core.Enums.ItemClassType.ND,
IsService = false,
ItemCode = 0,
ExtItemCode = "NEW-ITEM",
SupplCode = "",
Description = $"Nuovo ITEM {DateTime.Today:ddd yyyy.MM.dd}",
Cost = 0,
Margin = 0,
QtyMin = 0,
QtyMax = 0,
UM = "#"
};
}
else
{
editRecSellItem = new SellingItemModel()
{
Cost = 0,
Description = $"Nuovo PRODOTTO {DateTime.Today:ddd yyyy.MM.dd}",
ExtItemCode = "NEW-PROD",
Envir = CurrFilt.Envir,
IsService = false,
ItemCode = 0,
Margin = 0,
SupplCode = "",
UM = "#"
};
}
}
private void DoCancel()
{
editRecItem = null;
editRecSellItem = null;
}
private async Task DoSaveItem(ItemModel currRec)
{
isLoading = true;
// salvo
await DLService.ItemUpsertAsync(currRec);
editRecItem = null;
await Task.Delay(100);
isLoading = false;
}
private async Task DoSaveSelItem(SellingItemModel currRec)
{
isLoading = true;
// salvo
await DLService.SellingItemUpsertAsync(currRec);
editRecSellItem = null;
await Task.Delay(100);
isLoading = false;
}
private void EditItem(ItemModel editRec)
{
editRecItem = editRec;
}
private void EditSellItem(SellingItemModel editRec)
{
editRecSellItem = editRec;
}
private async Task ReloadBaseData()
{
ListItemGroup = await DLService.ItemGroupGetAllAsync();
ListJobTask = await DLService.JobTaskGetAllAsync();
isLoading = false;
}
private void UpdateFilt(FiltSelect newFilt)
{
isLoading = true;
CurrFilt = newFilt;
isLoading = false;
}
#endregion Private Methods
}
}