85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using FruitBank.Common.Interfaces;
|
|
using LinqToDB;
|
|
using LinqToDB.Mapping;
|
|
using Mango.Nop.Core.Entities;
|
|
|
|
namespace FruitBank.Common.Entities;
|
|
|
|
public abstract class MeasuringItemPalletBase : MgEntityBase, IMeasuringItemPalletBase
|
|
{
|
|
private double _palletWeight;
|
|
private double _grossWeight;
|
|
private double _tareWeight;
|
|
|
|
[NotColumn]
|
|
protected int ForeignItemId;
|
|
[NotColumn]
|
|
public int ForeignKey => ForeignItemId;
|
|
|
|
public int Quantity { get; set; }
|
|
|
|
[Column(DataType = DataType.DecFloat)]
|
|
public double TareWeight
|
|
{
|
|
get => _tareWeight;
|
|
set => _tareWeight = double.Round(value, 1);
|
|
}
|
|
|
|
[Column(DataType = DataType.DecFloat)]
|
|
public double PalletWeight
|
|
{
|
|
get => _palletWeight;
|
|
set => _palletWeight = double.Round(value, 1);
|
|
}
|
|
|
|
[NotColumn] public double NetWeight => CalculateNetWeight();
|
|
|
|
[Column(DataType = DataType.DecFloat, CanBeNull = false)]
|
|
public double GrossWeight
|
|
{
|
|
get => _grossWeight;
|
|
set => _grossWeight = double.Round(value, 1);
|
|
}
|
|
|
|
public bool IsMeasured { get; set; }
|
|
|
|
[SkipValuesOnUpdate]
|
|
public int? CreatorId { get; set; }
|
|
public int? ModifierId { get; set; }
|
|
|
|
[SkipValuesOnUpdate]
|
|
public DateTime Created { get; set; }
|
|
public DateTime Modified { get; set; }
|
|
|
|
public virtual double CalculateNetWeight() => double.Round(GrossWeight - PalletWeight - (TareWeight * Quantity), 1);
|
|
|
|
/// <summary>
|
|
/// Nem lehet nullánál kisebb "Weight" érték és a ShippingId, Quantity nagyobb mint nulla! Megengedőbb mint az IsValidMeasuringValues(bool isMeasurable)...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual bool IsValidSafeMeasuringValues()
|
|
{
|
|
return Quantity > 0 && TareWeight >= 0 && PalletWeight >= 0 && NetWeight >= 0 && GrossWeight >= 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// "Szigorúbb" mint az IsValidSafeMeasuringValues()
|
|
/// </summary>
|
|
/// <param name="isMeasurable"></param>
|
|
/// <returns></returns>
|
|
public virtual bool IsValidMeasuringValues(bool isMeasurable)
|
|
{
|
|
return Quantity > 0 && ((!isMeasurable && NetWeight == 0 && GrossWeight == 0 && PalletWeight == 0 && TareWeight == 0)
|
|
|| (isMeasurable && NetWeight > 0 && GrossWeight > 0 && PalletWeight >= 0 && TareWeight >= 0));
|
|
}
|
|
|
|
public bool IsMeasuredAndValid(bool isMeasurable)
|
|
{
|
|
return Id > 0 && IsMeasured && IsValidMeasuringValues(isMeasurable);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{base.ToString()} [ForeignItemId: {ForeignItemId}; IsMeasured: {IsMeasured}; PalletWeight: {PalletWeight}; TareWeight: {TareWeight}; Quantity: {Quantity}; NetWeight: {NetWeight}; GrossWeight: {GrossWeight}]";
|
|
}
|
|
} |