From 460e29529f37bc1fa00eb0d14e7e1e6469acfa47 Mon Sep 17 00:00:00 2001 From: Loretta Date: Sun, 5 Oct 2025 14:56:00 +0200 Subject: [PATCH] ShippingItemPallets improvements --- .../Entities/ShippingItemPallet.cs | 9 +- .../IFruitBankDataControllerCommon.cs | 5 + .../Interfaces/IShippingItemPallet.cs | 5 +- FruitBank.Common/SignalRs/SignalRTags.cs | 3 + .../Pages/MeasuringIn.razor | 83 ++++++++--- .../Pages/MeasuringIn.razor.cs | 139 ++++++++++++++---- .../SignalRs/FruitBankSignalRClient.cs | 8 + 7 files changed, 203 insertions(+), 49 deletions(-) diff --git a/FruitBank.Common/Entities/ShippingItemPallet.cs b/FruitBank.Common/Entities/ShippingItemPallet.cs index 21dae0f..f198cc4 100644 --- a/FruitBank.Common/Entities/ShippingItemPallet.cs +++ b/FruitBank.Common/Entities/ShippingItemPallet.cs @@ -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)); } } \ No newline at end of file diff --git a/FruitBank.Common/Interfaces/IFruitBankDataControllerCommon.cs b/FruitBank.Common/Interfaces/IFruitBankDataControllerCommon.cs index 1792cda..163ea3a 100644 --- a/FruitBank.Common/Interfaces/IFruitBankDataControllerCommon.cs +++ b/FruitBank.Common/Interfaces/IFruitBankDataControllerCommon.cs @@ -31,6 +31,11 @@ public interface IFruitBankDataControllerCommon public Task UpdateMeasuredShippingItem(ShippingItem shippingItem); #endregion ShippingItem + #region ShippingItemPallet + public Task AddShippingItemPallet(ShippingItemPallet shippingItemPallet); + public Task UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet); + #endregion ShippingItemPallet + #region ShippingDocument public Task?> GetShippingDocuments(); public Task GetShippingDocumentById(int id); diff --git a/FruitBank.Common/Interfaces/IShippingItemPallet.cs b/FruitBank.Common/Interfaces/IShippingItemPallet.cs index 796d8d1..a2d0cdd 100644 --- a/FruitBank.Common/Interfaces/IShippingItemPallet.cs +++ b/FruitBank.Common/Interfaces/IShippingItemPallet.cs @@ -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); } \ No newline at end of file diff --git a/FruitBank.Common/SignalRs/SignalRTags.cs b/FruitBank.Common/SignalRs/SignalRTags.cs index 8d9bc69..dcd2a39 100644 --- a/FruitBank.Common/SignalRs/SignalRTags.cs +++ b/FruitBank.Common/SignalRs/SignalRTags.cs @@ -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; diff --git a/FruitBankHybrid.Shared/Pages/MeasuringIn.razor b/FruitBankHybrid.Shared/Pages/MeasuringIn.razor index 83db8db..c6918fe 100644 --- a/FruitBankHybrid.Shared/Pages/MeasuringIn.razor +++ b/FruitBankHybrid.Shared/Pages/MeasuringIn.razor @@ -10,7 +10,7 @@
- + @* *@ - + - + - + + + + + + + + Caption="MeasuredNetWeight:" ColSpanMd="3"> - + - - +

+ @for (var index = 0; index < SelectedShippingItem!.ShippingItemPallets!.Count; index++) + { + var localI = index + 1; + var currentShippingItemPallet = SelectedShippingItem!.ShippingItemPallets![index]; + + + + @(localI). Raklap + + + + + + + + + + + + + + + + + } @@ -136,14 +179,16 @@ @if (SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0) { - + } else { _errorText = "Nem végezhető el a mérés, nincs megadva a ProductId! Jelezze a vezetőségnek..."; } - + @if (!_errorText.IsNullOrWhiteSpace()) { diff --git a/FruitBankHybrid.Shared/Pages/MeasuringIn.razor.cs b/FruitBankHybrid.Shared/Pages/MeasuringIn.razor.cs index aad2c2b..ad51f03 100644 --- a/FruitBankHybrid.Shared/Pages/MeasuringIn.razor.cs +++ b/FruitBankHybrid.Shared/Pages/MeasuringIn.razor.cs @@ -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 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 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(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; diff --git a/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs b/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs index ac86254..bac5d41 100644 --- a/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs +++ b/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs @@ -70,6 +70,14 @@ namespace FruitBankHybrid.Shared.Services.SignalRs #endregion ShippingItem + #region ShippingItemPallet + public Task AddShippingItemPallet(ShippingItemPallet shippingItemPallet) + => PostDataAsync(SignalRTags.AddShippingItemPallet, shippingItemPallet); + + public Task UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet) + => PostDataAsync(SignalRTags.UpdateShippingItemPallet, shippingItemPallet); + #endregion ShippingItemPallet + #region ShippingDocument public Task?> GetShippingDocuments()