imrpovements, fixes, etc...
This commit is contained in:
parent
8845385477
commit
dc249b8ef4
|
|
@ -0,0 +1,21 @@
|
|||
using FruitBank.Common.Interfaces;
|
||||
using LinqToDB;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
|
||||
namespace FruitBank.Common.Entities;
|
||||
|
||||
[Table(Name = FruitBankConstClient.PalletDbTableName)]
|
||||
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.PalletDbTableName)]
|
||||
public class Pallet : MgEntityBase, IPallet
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Size { get; set; }
|
||||
|
||||
[Column(DataType = DataType.DecFloat, CanBeNull = true)]
|
||||
public double? Weight { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -53,6 +53,9 @@ public class ShippingItem : MgEntityBase, IShippingItem
|
|||
public bool IsMeasurable { get; set; }
|
||||
public bool IsMeasured { get; set; }
|
||||
|
||||
[LinqToDB.Mapping.Association(ThisKey = nameof(PalletId), OtherKey = nameof(Pallet.Id), CanBeNull = true)]
|
||||
public Pallet? Pallet { get; set; }
|
||||
|
||||
[LinqToDB.Mapping.Association(ThisKey = nameof(ProductId), OtherKey = nameof(Product.Id), CanBeNull = true)]
|
||||
public Product? Product { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class ShippingItemPallet : MgEntityBase, IShippingItemPallet
|
|||
{
|
||||
public int ShippingItemId { get; set; }
|
||||
|
||||
[Column(DataType = DataType.DecFloat)]
|
||||
public double PalletWeight { get; set; }
|
||||
|
||||
//[Nullable]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public static class FruitBankConstClient
|
|||
public static string DefaultHubName = "fbHub";
|
||||
public static string LoggerHubName = "loggerHub";
|
||||
|
||||
public const string PalletDbTableName = "fbPallet";
|
||||
public const string FilesDbTableName = "fbFiles";
|
||||
public const string PartnerDbTableName = "fbPartner";
|
||||
public const string ShippingDbTableName = "fbShipping";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
using FruitBank.Common.Entities;
|
||||
|
||||
namespace FruitBank.Common.Helpers;
|
||||
|
||||
public static class MeasuringValuesHelper
|
||||
{
|
||||
public static void SetShippingItemTotalMeasuringValues(ShippingItem? shippingItem)
|
||||
{
|
||||
if (shippingItem == null) return;
|
||||
|
||||
var totalMeasuringValues = GetTotalNetAndGrossWeightFromPallets(shippingItem);
|
||||
|
||||
shippingItem.MeasuredQuantity = totalMeasuringValues.TotalQuantity;
|
||||
shippingItem.MeasuredNetWeight = totalMeasuringValues.TotalNetWeight;
|
||||
shippingItem.MeasuredGrossWeight = totalMeasuringValues.TotalGrossWeight;
|
||||
}
|
||||
|
||||
public static (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));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
|
||||
namespace FruitBank.Common.Interfaces;
|
||||
|
||||
public interface IPallet : IEntityInt, ITimeStampInfo
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Size { get; set; }
|
||||
double? Weight { get; set; }
|
||||
}
|
||||
|
|
@ -173,8 +173,9 @@ namespace FruitBankHybrid.Shared.Tests
|
|||
{
|
||||
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemId);
|
||||
|
||||
Assert.IsNotNull(shippingItem);
|
||||
Assert.IsNotNull(shippingItem.Product, $"shippingItem.Product == null; shippingItem.Id: {shippingItem.ProductId}");
|
||||
Assert.IsNotNull(shippingItem, $"shippingItemId: {shippingItemId}");
|
||||
Assert.IsNotNull(shippingItem.Pallet, $"shippingItem.Pallet == null; shippingItem.PalletId: {shippingItem.PalletId}");
|
||||
Assert.IsNotNull(shippingItem.Product, $"shippingItem.Product == null; shippingItem.ProductId: {shippingItem.ProductId}");
|
||||
Assert.IsTrue(shippingItem.Id == shippingItemId);
|
||||
|
||||
Assert.IsTrue(shippingItem.QuantityOnDocument > 0, "QuantityOnDocument == 0");
|
||||
|
|
@ -205,7 +206,7 @@ namespace FruitBankHybrid.Shared.Tests
|
|||
|
||||
if (shippingItemPallet == null)
|
||||
{
|
||||
shippingItemPallet = new ShippingItemPallet { ShippingItemId = shippingItem.Id/*, PalletSize = shippingItem.PalletSize*/ };
|
||||
shippingItemPallet = new ShippingItemPallet { ShippingItemId = shippingItem.Id, PalletWeight = shippingItem.Pallet?.Weight ?? 0 };
|
||||
shippingItem.ShippingItemPallets!.Add(shippingItemPallet);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,12 @@
|
|||
</DxFormLayoutItem>
|
||||
|
||||
<br /><br />
|
||||
@* <DxFormLayout CssClass="w-100">
|
||||
<DxFormLayoutItem ColSpanMd="4" BeginRow="true">
|
||||
<text>Raklap</text>
|
||||
</DxFormLayoutItem>
|
||||
</DxFormLayout
|
||||
*@
|
||||
@for (var index = 0; index < SelectedShippingItem!.ShippingItemPallets!.Count; index++)
|
||||
{
|
||||
var localI = index + 1;
|
||||
|
|
@ -147,26 +153,26 @@
|
|||
<text>@(localI). Raklap</text>
|
||||
</DxFormLayoutItem>
|
||||
|
||||
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : "")"
|
||||
|
||||
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : (currentShippingItemPallet.NetWeight < 0 ? "text-danger" : ""))"
|
||||
Field="@nameof(ShippingItemPallet.PalletWeight)"
|
||||
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
|
||||
Caption="Rakl.súly(kg):" ColSpanMd="1" />
|
||||
|
||||
<DxFormLayoutItem ColSpanMd="1"/>
|
||||
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : (currentShippingItemPallet.Quantity < 0 ? "text-danger" : ""))"
|
||||
Field="@nameof(ShippingItemPallet.Quantity)"
|
||||
Enabled="@(SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
|
||||
Caption="MeasuredQuantity:" ColSpanMd="2" />
|
||||
Caption="Rekesz/csomag:" ColSpanMd="1" />
|
||||
|
||||
|
||||
<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" : "")"
|
||||
<DxFormLayoutItem CaptionCssClass="@(ShippingitemPalletMeasuredAndValid(currentShippingItemPallet) ? "text-success" : (currentShippingItemPallet.NetWeight < 0 ? "text-danger" : ""))"
|
||||
Field="@nameof(ShippingItemPallet.GrossWeight)"
|
||||
Enabled="@(SelectedShippingItem.IsMeasurable && SelectedShippingItem.ProductId.GetValueOrDefault(0) > 0)"
|
||||
Caption="MeasuredGrossWeight:" ColSpanMd="2">
|
||||
Caption="Br.súly(kg):" ColSpanMd="1">
|
||||
</DxFormLayoutItem>
|
||||
|
||||
<DxFormLayoutItem ColSpanMd="2">
|
||||
<DxButton Text="@(currentShippingItemPallet.Id == 0 ? "Mentés" : "Módosítás")" Click="() => OnShippingItemPalletSaveClick(currentShippingItemPallet)" CssClass="w-100" />
|
||||
<DxFormLayoutItem ColSpanMd="4">
|
||||
@* <DxButton Text="@(currentShippingItemPallet.Id == 0 ? "Mentés" : "Módosítás")" Click="() => OnShippingItemPalletSaveClick(currentShippingItemPallet)" CssClass="w-100" /> *@
|
||||
</DxFormLayoutItem>
|
||||
|
||||
</DxFormLayout>
|
||||
|
|
@ -180,7 +186,7 @@
|
|||
{
|
||||
<DxFormLayoutItem ColSpanMd="12" BeginRow="true">
|
||||
<DxButton Text="@(SelectedShippingItem.IsMeasured ? "Befejezett mérés módosítása" : "Mérés befejezése")"
|
||||
Enabled="true || (BtnSaveEnabled && (SelectedShippingItem.ShippingItemPallets.All(x => ShippingitemPalletMeasuredAndValid(x, SelectedShippingItem.IsMeasurable))))"
|
||||
Enabled="BtnSaveEnabled || (BtnSaveEnabled && (SelectedShippingItem.ShippingItemPallets.All(x => ShippingitemPalletMeasuredAndValid(x, SelectedShippingItem.IsMeasurable))))"
|
||||
SubmitFormOnClick="true" CssClass="w-100" />
|
||||
</DxFormLayoutItem>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using DevExpress.Blazor;
|
||||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Helpers;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Models;
|
||||
using FruitBankHybrid.Shared.Services.Loggers;
|
||||
|
|
@ -97,35 +98,6 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
SelectedShippingItem = eventArgs.DataItem?.ShippingItems?.FirstOrDefault();
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -143,7 +115,7 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
var shippingDate = _shippingDates.FirstOrDefault(shipping => shipping.ShippingId == SelectedShipping.Id);
|
||||
if (shippingDate != null) shippingDate.IsMeasured = SelectedShipping.IsAllMeasured;
|
||||
|
||||
UpdateShippingItemTotalMeasuringValues(shippingItem);
|
||||
MeasuringValuesHelper.SetShippingItemTotalMeasuringValues(shippingItem);
|
||||
|
||||
shippingItem.ShippingItemPallets ??= new List<ShippingItemPallet>(shippingItem.PalletsOnDocument);
|
||||
if (shippingItem.ShippingItemPallets.Count >= shippingItem.PalletsOnDocument) return;
|
||||
|
|
@ -152,7 +124,7 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
shippingItem.ShippingItemPallets.Add(new ShippingItemPallet
|
||||
{
|
||||
ShippingItemId = shippingItem.Id,
|
||||
//PalletSize = shippingItem.PalletSize,
|
||||
PalletWeight = shippingItem.Pallet?.Weight ?? 0,
|
||||
});
|
||||
|
||||
//if (shippingItem.Id == SelectedShippingItem?.Id) return;
|
||||
|
|
@ -209,7 +181,7 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
shippingItemPallet.Id = responseShippingItemPallet.Id; //Az UpdateCollection miatt kell, hogy megtalálja mit kell kicserélni! - J.
|
||||
|
||||
SelectedShippingItem!.ShippingItemPallets!.UpdateCollection(responseShippingItemPallet, false);
|
||||
UpdateShippingItemTotalMeasuringValues(SelectedShippingItem);
|
||||
MeasuringValuesHelper.SetShippingItemTotalMeasuringValues(SelectedShippingItem);
|
||||
}
|
||||
else LogErrorAndDisplayText($"Sikertelen volt a raklap adatainak mentése! {shippingItemPallet}");
|
||||
|
||||
|
|
@ -236,20 +208,13 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
|
||||
protected void OnItemUpdating(string fieldName, object newValue)
|
||||
{
|
||||
return;
|
||||
|
||||
BtnSaveEnabled = false;
|
||||
if (SelectedShippingItem == null) return;
|
||||
|
||||
switch (fieldName)
|
||||
{
|
||||
//case nameof(ShippingItem.Name):
|
||||
// SelectedShippingItem.Name = newValue.ToString() ?? string.Empty;
|
||||
// break;
|
||||
//case nameof(ShippingItem.GrossWeight):
|
||||
// SelectedShippingItem.GrossWeight = (double)newValue;
|
||||
// break;
|
||||
//case nameof(ShippingItem.NetWeight):
|
||||
// SelectedShippingItem.NetWeight = (double)newValue;
|
||||
// break;
|
||||
case nameof(ShippingItem.MeasuredQuantity):
|
||||
SelectedShippingItem.MeasuredQuantity = (int)newValue <= 0 ? 0 : (int)newValue;
|
||||
break;
|
||||
|
|
@ -271,21 +236,24 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
|
||||
switch (fieldName)
|
||||
{
|
||||
case nameof(ShippingItemPallet.PalletWeight):
|
||||
shippingItemPallet.PalletWeight = (double)newValue;
|
||||
break;
|
||||
|
||||
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();
|
||||
shippingItemPallet.NetWeight = shippingItemPallet.GrossWeight - shippingItemPallet.PalletWeight;
|
||||
|
||||
MeasuringValuesHelper.SetShippingItemTotalMeasuringValues(SelectedShippingItem);
|
||||
|
||||
BtnSaveEnabled = SelectedShippingItem.IsValidMeasuringValues() && shippingItemPallet.IsValidMeasuringValues(SelectedShippingItem.IsMeasurable);
|
||||
}
|
||||
private void LogErrorAndDisplayText(string errorText, Exception? ex = null)
|
||||
{
|
||||
|
|
@ -293,10 +261,5 @@ namespace FruitBankHybrid.Shared.Pages
|
|||
_logger.Error($"{errorText}", ex);
|
||||
//Nem végezhető el a mérés, nincs megadva a ProductId! Jelezze a vezetőségnek...
|
||||
}
|
||||
|
||||
protected void OnAnyMeasuringValueKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
BtnSaveEnabled = SelectedShippingItem?.IsValidMeasuringValues() ?? false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue