FruitBankHybridApp/FruitBankHybrid.Shared/Components/StockTakings/StockTakingTemplate.razor

111 lines
3.8 KiB
Plaintext

@using AyCode.Utils.Extensions
@using FruitBank.Common.Dtos
@using FruitBank.Common.Entities
@using FruitBank.Common.Models
@using FruitBankHybrid.Shared.Databases
@using FruitBankHybrid.Shared.Services.SignalRs
@using Mango.Nop.Core.Entities
<DxFormLayout CaptionPosition="CaptionPosition.Vertical" CssClass="w-100">
<DxFormLayoutItem Caption="Termék:" ColSpanMd="2">
@* CaptionCssClass="@(SelectedProductDto?.IsMeasured == true ? "text-success" : "")"> *@
<DxComboBox Data="@_stockTakings"
TextFieldName="@nameof(StockTaking.StartDateTime)"
CssClass="cw-480"
DropDownBodyCssClass="dd-body-class"
Context="ctxProduct"
InputId="cbProduct"
Value="@SelectedStockTaking"
ValueChanged="@((StockTaking stockTaking) => ValueChanged(stockTaking))">
</DxComboBox>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="4">
<DxComboBox Data="@_stockTakingItems"
@bind-Value="@SelectedStockTakingItem"
TextFieldName="@nameof(StockTakingItem.DisplayText)"
CssClass="cw-480"
DropDownBodyCssClass="dd-body-class"
Context="ctxProduct2"
InputId="cbProduct2">
</DxComboBox>
</DxFormLayoutItem>
@* TextFieldName="StockTakingItem.Product.Name" *@
<DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Új" Enabled="@(_stockTakings.All(x => x.IsClosed))" Click="() => Callback()"></DxButton>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Módosít" Enabled="@(SelectedStockTaking?.IsClosed ?? false)" Click="() => Callback2()"></DxButton>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Lezárás" Enabled="@(SelectedStockTaking?.StockTakingItems?.Where(x=>x.IsRequiredForMeasuring).All(x=>x.IsMeasured) ?? false)" Click="() => Callback3()"></DxButton>
</DxFormLayoutItem>
</DxFormLayout>
@code
{
[Inject] public required DatabaseClient Database { get; set; }
[Inject] public required LoggedInModel LoggedInModel { get; set; }
[Inject] public required FruitBankSignalRClient FruitBankSignalRClient { get; set; }
List<StockTaking> _stockTakings { get; set; } = [];
List<StockTakingItem> _stockTakingItems { get; set; } = [];
List<StockTakingItemPallet> _stockTakingItemPallets { get; set; } = [];
StockTaking? SelectedStockTaking { get; set; }
StockTakingItem? SelectedStockTakingItem { get; set; }
protected override async Task OnInitializedAsync()
{
await ReloadDataFromDb(false);
}
public async Task ReloadDataFromDb(bool forceReload)
{
LoadingPanelVisibility.Visible = true;
_stockTakings = await FruitBankSignalRClient.GetStockTakings() ?? [];
ValueChanged(_stockTakings.FirstOrDefault());
LoadingPanelVisibility.Visible = false;
}
private async Task Callback()
{
var stockTaking = new StockTaking();
stockTaking.StartDateTime = DateTime.Now;
stockTaking.Creator = LoggedInModel.CustomerDto!.Id;
var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking);
if (resultStockTaking == null) return;
_stockTakings.Add(resultStockTaking);
StateHasChanged();
}
private async Task Callback2()
{
// var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking);
// if (resultStockTaking == null) return;
// _stockTakings.Add(resultStockTaking);
StateHasChanged();
}
private async Task Callback3()
{
// var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking);
// if (resultStockTaking == null) return;
// _stockTakings.Add(resultStockTaking);
StateHasChanged();
}
private void ValueChanged(StockTaking? newValue)
{
SelectedStockTaking = newValue;
_stockTakingItems = SelectedStockTaking?.StockTakingItems?.OrderByDescending(x => x.IsMeasured).ThenByDescending(x => x.OriginalStockQuantity != 0 || x.OriginalNetWeight != 0).ThenBy(x => x.Product?.Name).ToList() ?? [];
SelectedStockTakingItem = _stockTakingItems.FirstOrDefault();
}
}