ShippingItemPallets improvements

This commit is contained in:
Loretta 2025-10-05 14:56:00 +02:00
parent 3ce49ab578
commit 460e29529f
7 changed files with 203 additions and 49 deletions

View File

@ -12,6 +12,9 @@ public class ShippingItemPallet : MgEntityBase, IShippingItemPallet
{
public int ShippingItemId { get; set; }
[NotColumn]
public string PalletSize { get; set; }
//[Nullable]
//[Column(CanBeNull = true)]
[Range(1, 100000, ErrorMessage = "The Quantity value should be a number between 1 and 100,000.")]
@ -27,6 +30,8 @@ public class ShippingItemPallet : MgEntityBase, IShippingItemPallet
[Range(1, 100000, ErrorMessage = "The GrossWeight value should be a number between 1 and 100,000.")]
public double GrossWeight { get; set; }
public bool IsMeasured { get; set; }
[LinqToDB.Mapping.Association(ThisKey = nameof(ShippingItemId), OtherKey = nameof(ShippingItem.Id), CanBeNull = true)]
public ShippingItem? ShippingItem { get; set; }
@ -38,8 +43,8 @@ public class ShippingItemPallet : MgEntityBase, IShippingItemPallet
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
public bool IsValidMeasuringValues()
public bool IsValidMeasuringValues(bool isMeasurable)
{
return ShippingItemId > 0 && Quantity > 0 && NetWeight > 0 && GrossWeight > 0;
return ShippingItemId > 0 && Quantity > 0 && (!isMeasurable || (NetWeight > 0 && GrossWeight > 0));
}
}

View File

@ -31,6 +31,11 @@ public interface IFruitBankDataControllerCommon
public Task<ShippingItem?> UpdateMeasuredShippingItem(ShippingItem shippingItem);
#endregion ShippingItem
#region ShippingItemPallet
public Task<ShippingItemPallet?> AddShippingItemPallet(ShippingItemPallet shippingItemPallet);
public Task<ShippingItemPallet?> UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet);
#endregion ShippingItemPallet
#region ShippingDocument
public Task<List<ShippingDocument>?> GetShippingDocuments();
public Task<ShippingDocument?> GetShippingDocumentById(int id);

View File

@ -7,10 +7,13 @@ namespace FruitBank.Common.Interfaces;
public interface IShippingItemPallet : IEntityInt, IMeasuringValues, ITimeStampInfo
{
int ShippingItemId { get; set; }
public string PalletSize { get; set; }
public bool IsMeasured { get; set; }
public ShippingItem? ShippingItem { get; set; }
public int? CreatorId { get; set; }
public int? ModifierId { get; set; }
public bool IsValidMeasuringValues();
public bool IsValidMeasuringValues(bool isMeasurable);
}

View File

@ -40,6 +40,9 @@ public class SignalRTags : AcSignalRTags
public const int GetMeasuringProductDtoById = 83;
public const int AddShippingItemPallet = 95;
public const int UpdateShippingItemPallet = 96;
public const int AuthenticateUser = 160;
public const int RefreshToken = 200;

View File

@ -10,7 +10,7 @@
<div style="margin-top: 50px;">
<DxFormLayout CaptionPosition="CaptionPosition.Vertical" CssClass="w-100">
<DxFormLayoutItem Caption="Érkezés dátuma" ColSpanMd="2" CaptionCssClass="@(SelectedShipping != null && _shippingDates.Where(x=>DaysEqual(x.DateTime, SelectedShipping.ShippingDate)).All(x => x.IsMeasured) ? "text-success" : "")">
<DxFormLayoutItem Caption="Érkezés dátuma" ColSpanMd="2" CaptionCssClass="@(SelectedShipping != null && _shippingDates.Where(x => DaysEqual(x.DateTime, SelectedShipping.ShippingDate)).All(x => x.IsMeasured) ? "text-success" : "")">
<DxDateEdit CssClass="cw-320"
DisplayFormat="m"
Format="m"
@ -102,32 +102,75 @@
OnInvalidSubmit="@HandleInvalidSubmit">
@* <DataAnnotationsValidator /> *@
<DxFormLayout Data="@SelectedShippingItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100" ItemUpdating="@((pair) => OnItemUpdating(pair.Key, pair.Value))">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.Name)" Caption="Item Name:" Enabled="false" ColSpanMd="6" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.Name)" Caption="Item Name:" Enabled="false" ColSpanMd="8" />
<DxFormLayoutItem Visible="false" CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.GrossWeightOnDocument)" Caption="GrossWeightOnDocument:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem Visible="false" CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")" Field="@nameof(ShippingItem.NetWeightOnDocument)" Caption="NetWeightOnDocument:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredQuantity)"
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredQuantity:" ColSpanMd="2" BeginRow="false">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.PalletsOnDocument)"
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="Pallets:" ColSpanMd="2" BeginRow="false">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredGrossWeight)"
<DxFormLayoutItem Visible="true" CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.IsMeasured)"
Enabled="false" Caption="Sikeres mérés:" ColSpanMd="2">
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="3" BeginRow="true" />
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredQuantity)"
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredQuantity:" ColSpanMd="3" BeginRow="false">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredNetWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredGrossWeight:" ColSpanMd="2">
Caption="MeasuredNetWeight:" ColSpanMd="3">
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredNetWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredNetWeight:" ColSpanMd="2">
<DxFormLayoutItem CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.MeasuredGrossWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredGrossWeight:" ColSpanMd="3">
</DxFormLayoutItem>
<DxFormLayoutItem Visible="false" CaptionCssClass="@(SelectedShippingItem.IsMeasured ? "text-success" : "")"
Field="@nameof(ShippingItem.IsMeasured)"
Enabled="false" Caption="Sikeres mérés:" ColSpanMd="6">
</DxFormLayoutItem>
<br /><br />
@for (var index = 0; index < SelectedShippingItem!.ShippingItemPallets!.Count; index++)
{
var localI = index + 1;
var currentShippingItemPallet = SelectedShippingItem!.ShippingItemPallets![index];
<DxFormLayout Data="@currentShippingItemPallet" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100" ItemUpdating="@((pair) => OnItemUpdating2(pair.Key, pair.Value, currentShippingItemPallet))">
<DxFormLayoutItem ColSpanMd="4" BeginRow="true">
<text>@(localI). Raklap</text>
</DxFormLayoutItem>
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : "")"
Field="@nameof(ShippingItemPallet.Quantity)"
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredQuantity:" ColSpanMd="2" />
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : "")"
Field="@nameof(ShippingItemPallet.NetWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredNetWeight:" ColSpanMd="2" />
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : "")"
Field="@nameof(ShippingItemPallet.GrossWeight)"
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
Caption="MeasuredGrossWeight:" ColSpanMd="2">
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="2">
<DxButton Text="@(currentShippingItemPallet.Id == 0 ? "Mentés" : "Módosítás")" Click="() => OnShippingItemPalletSaveClick(currentShippingItemPallet)" CssClass="w-100" />
</DxFormLayoutItem>
</DxFormLayout>
}
<DxFormLayoutItem ColSpanMd="12" BeginRow="true">
<ValidationSummary />
@ -136,14 +179,16 @@
@if (SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)
{
<DxFormLayoutItem ColSpanMd="12" BeginRow="true">
<DxButton Text="@(SelectedShippingItem.IsMeasured ? "Módosít" : "Mentés")" Enabled="BtnSaveEnabled" SubmitFormOnClick="true" CssClass="w-100"/>
<DxButton Text="@(SelectedShippingItem.IsMeasured ? "Befejezett mérés módosítása" : "Mérés befejezése")"
Enabled="BtnSaveEnabled && (SelectedShippingItem.ShippingItemPallets.All(x => ShippingitemPalletMeasuredAndValid(x, SelectedShippingItem.IsMeasurable)))"
SubmitFormOnClick="true" CssClass="w-100" />
</DxFormLayoutItem>
}
else
{
_errorText = "Nem végezhető el a mérés, nincs megadva a ProductId! Jelezze a vezetőségnek...";
}
@if (!_errorText.IsNullOrWhiteSpace())
{
<DxFormLayoutItem ColSpanMd="12" BeginRow="true">

View File

@ -1,4 +1,5 @@
using AyCode.Core.Loggers;
using AyCode.Core.Extensions;
using AyCode.Core.Loggers;
using DevExpress.Blazor;
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
@ -96,17 +97,66 @@ namespace FruitBankHybrid.Shared.Pages
SelectedShippingItem = eventArgs.DataItem?.ShippingItems?.FirstOrDefault();
}
private async Task OnSelectedShippingItemChanged(SelectedDataItemChangedEventArgs<ShippingItem> eventArgs)
private void UpdateShippingItemTotalMeasuringValues(ShippingItem? shippingItem)
{
if (shippingItem == null) return;
var totalMeasuringValues = GetTotalNetAndGrossWeightFromPallets(shippingItem);
shippingItem.MeasuredQuantity = totalMeasuringValues.TotalQuantity;
shippingItem.MeasuredNetWeight = totalMeasuringValues.TotalNetWeight;
shippingItem.MeasuredGrossWeight = totalMeasuringValues.TotalGrossWeight;
}
private (int TotalQuantity, double TotalNetWeight, double TotalGrossWeight) GetTotalNetAndGrossWeightFromPallets(ShippingItem? shippingItem)
{
if (shippingItem?.ShippingItemPallets == null) return (0, 0d, 0d);
var totalQuantity = 0;
var totalNetWeight = 0d;
var totalGrossWeight = 0d;
foreach (var shippingItemPallet in shippingItem.ShippingItemPallets)
{
totalQuantity += shippingItemPallet.Quantity;
totalNetWeight += shippingItemPallet.NetWeight;
totalGrossWeight += shippingItemPallet.GrossWeight;
}
return (totalQuantity, double.Round(totalNetWeight, 1), Math.Round(totalGrossWeight, 1));
}
private void OnSelectedShippingItemChanged(SelectedDataItemChangedEventArgs<ShippingItem> eventArgs)
{
BtnSaveEnabled = false;
var shippingItem = eventArgs.DataItem;
if (eventArgs.DataItem == null)
if (shippingItem == null)
{
SelectedShippingItem = null;
return;
}
await RefreshSelectedShippingItemMeasuredValuesFromDb(eventArgs.DataItem.Id);
SelectedShippingDocument!.IsAllMeasured = SelectedShippingDocument.ShippingItems?.All(si => si.IsMeasured) ?? false;
SelectedShipping!.IsAllMeasured = SelectedShipping.ShippingDocuments?.All(sd => sd.IsAllMeasured) ?? false;
var shippingDate = _shippingDates.FirstOrDefault(shipping => shipping.ShippingId == SelectedShipping.Id);
if (shippingDate != null) shippingDate.IsMeasured = SelectedShipping.IsAllMeasured;
UpdateShippingItemTotalMeasuringValues(shippingItem);
shippingItem.ShippingItemPallets ??= new List<ShippingItemPallet>(shippingItem.PalletsOnDocument);
if (shippingItem.ShippingItemPallets.Count >= shippingItem.PalletsOnDocument) return;
for (var i = shippingItem.ShippingItemPallets.Count; i < shippingItem.PalletsOnDocument; i++)
shippingItem.ShippingItemPallets.Add(new ShippingItemPallet
{
ShippingItemId = shippingItem.Id,
PalletSize = shippingItem.PalletSize
});
//if (shippingItem.Id == SelectedShippingItem?.Id) return;
//await RefreshSelectedShippingItemMeasuredValuesFromDb(shippingItem.Id);
}
private async Task RefreshSelectedShippingItemMeasuredValuesFromDb(int shippingItemId)
@ -116,31 +166,16 @@ namespace FruitBankHybrid.Shared.Pages
private void RefreshSelectedShippingItemMeasuredValuesFromDb(ShippingItem? shippingItemFromDb)
{
if (SelectedShippingItem == null || shippingItemFromDb == null) return;
if (SelectedShipping == null || SelectedShippingDocument == null || shippingItemFromDb == null) return;
SelectedShippingItem.MeasuredQuantity = shippingItemFromDb.MeasuredQuantity;
SelectedShippingItem.MeasuredNetWeight = shippingItemFromDb.MeasuredNetWeight;
SelectedShippingItem.MeasuredGrossWeight = shippingItemFromDb.MeasuredGrossWeight;
//SelectedShippingItem.MeasuredQuantity = shippingItemFromDb.MeasuredQuantity;
//SelectedShippingItem.MeasuredNetWeight = shippingItemFromDb.MeasuredNetWeight;
//SelectedShippingItem.MeasuredGrossWeight = shippingItemFromDb.MeasuredGrossWeight;
//SelectedShippingItem.IsMeasurable = shippingItemFromDb.IsMeasurable;
SelectedShippingItem.IsMeasured = shippingItemFromDb.IsMeasured;
//SelectedShippingItem.IsMeasured = shippingItemFromDb.IsMeasured;
if (SelectedShippingDocument != null)
SelectedShippingDocument.IsAllMeasured = SelectedShippingDocument.ShippingItems?.All(si => si.IsMeasured) ?? false;
if (SelectedShipping != null)
{
SelectedShipping.IsAllMeasured = SelectedShipping.ShippingDocuments?.All(sd => sd.IsAllMeasured) ?? false;
var shippingDate = _shippingDates.FirstOrDefault(shipping => shipping.ShippingId == SelectedShipping.Id);
if (shippingDate != null) shippingDate.IsMeasured = SelectedShipping.IsAllMeasured;
}
//if (SelectedShippingItem is { IsMeasured: true })
//{
// SelectedShippingDocument?.ShippingItems?.Remove(SelectedShippingItem);
// SelectedShippingItem = SelectedShippingDocument?.ShippingItems?.FirstOrDefault();
//}
SelectedShippingDocument.ShippingItems!.UpdateCollection(shippingItemFromDb, false);
SelectedShippingItem = shippingItemFromDb;
StateHasChanged();
}
@ -154,7 +189,7 @@ namespace FruitBankHybrid.Shared.Pages
var updatedShippingItem = await FruitBankSignalRClient.UpdateMeasuredShippingItem(shippingItem);
if (updatedShippingItem == null)
{
LogErrorAndDisplayText($"Sikertelen volt a shippingItem mentése! Id: {shippingItem.Id}");
LogErrorAndDisplayText($"Sikertelen volt a shippingItem mentése! {shippingItem}");
return;
}
@ -162,6 +197,33 @@ namespace FruitBankHybrid.Shared.Pages
}
}
private async Task OnShippingItemPalletSaveClick(ShippingItemPallet shippingItemPallet)
{
ShippingItemPallet? responseShippingItemPallet;
if (shippingItemPallet.Id == 0) responseShippingItemPallet = await FruitBankSignalRClient.AddShippingItemPallet(shippingItemPallet);
else responseShippingItemPallet = await FruitBankSignalRClient.UpdateShippingItemPallet(shippingItemPallet);
if (responseShippingItemPallet != null)
{
shippingItemPallet.Id = responseShippingItemPallet.Id; //Az UpdateCollection miatt kell, hogy megtalálja mit kell kicserélni! - J.
SelectedShippingItem!.ShippingItemPallets!.UpdateCollection(responseShippingItemPallet, false);
UpdateShippingItemTotalMeasuringValues(SelectedShippingItem);
}
else LogErrorAndDisplayText($"Sikertelen volt a raklap adatainak mentése! {shippingItemPallet}");
StateHasChanged();
}
private bool ShippingitemPalletMeasuredAndValid(ShippingItemPallet shippingItemPallet)
=> ShippingitemPalletMeasuredAndValid(shippingItemPallet, SelectedShippingItem!.IsMeasurable);
private static bool ShippingitemPalletMeasuredAndValid(ShippingItemPallet shippingItemPallet, bool isMeasurable)
{
return shippingItemPallet.Id != 0 && shippingItemPallet.IsMeasured && shippingItemPallet.IsValidMeasuringValues(isMeasurable);
}
private async Task HandleValidSubmit()
{
await UpdateShippingItem(SelectedShippingItem);
@ -202,6 +264,29 @@ namespace FruitBankHybrid.Shared.Pages
BtnSaveEnabled = SelectedShippingItem.IsValidMeasuringValues();
}
protected void OnItemUpdating2(string fieldName, object newValue, ShippingItemPallet shippingItemPallet)
{
BtnSaveEnabled = false;
if (SelectedShippingItem == null) return;
switch (fieldName)
{
case nameof(ShippingItemPallet.Quantity):
shippingItemPallet.Quantity = (int)newValue;
SelectedShippingItem.MeasuredQuantity = GetTotalNetAndGrossWeightFromPallets(SelectedShippingItem).TotalQuantity;
break;
case nameof(ShippingItemPallet.NetWeight):
shippingItemPallet.NetWeight = (double)newValue;
SelectedShippingItem.MeasuredNetWeight = GetTotalNetAndGrossWeightFromPallets(SelectedShippingItem).TotalNetWeight;
break;
case nameof(ShippingItemPallet.GrossWeight):
shippingItemPallet.GrossWeight = (double)newValue;
SelectedShippingItem.MeasuredGrossWeight = GetTotalNetAndGrossWeightFromPallets(SelectedShippingItem).TotalGrossWeight;
break;
}
BtnSaveEnabled = SelectedShippingItem.IsValidMeasuringValues();
}
private void LogErrorAndDisplayText(string errorText, Exception? ex = null)
{
_errorText = errorText;

View File

@ -70,6 +70,14 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
#endregion ShippingItem
#region ShippingItemPallet
public Task<ShippingItemPallet?> AddShippingItemPallet(ShippingItemPallet shippingItemPallet)
=> PostDataAsync(SignalRTags.AddShippingItemPallet, shippingItemPallet);
public Task<ShippingItemPallet?> UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet)
=> PostDataAsync(SignalRTags.UpdateShippingItemPallet, shippingItemPallet);
#endregion ShippingItemPallet
#region ShippingDocument
public Task<List<ShippingDocument>?> GetShippingDocuments()