FruitBankHybridApp/FruitBank.Common/Entities/StockTakingItem.cs

55 lines
2.3 KiB
C#

using FruitBank.Common.Dtos;
using LinqToDB;
using LinqToDB.Mapping;
using Mango.Nop.Core.Entities;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Column = LinqToDB.Mapping.ColumnAttribute;
using Table = LinqToDB.Mapping.TableAttribute;
namespace FruitBank.Common.Entities;
[Table(Name = FruitBankConstClient.StockTakingItemDbTableName)]
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingItemDbTableName)]
public class StockTakingItem : MgStockTakingItem<StockTaking, ProductDto>
{
public bool IsMeasurable { get; set; }
[Column(DataType = DataType.DecFloat, CanBeNull = false)]
public double OriginalNetWeight { get; set; }
[Column(DataType = DataType.DecFloat, CanBeNull = false)]
public double MeasuredNetWeight { get; set; }
public int InProcessOrdersQuantity { get; set; }
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public int TotalOriginalQuantity => OriginalStockQuantity + InProcessOrdersQuantity;
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public int QuantityDiff => IsMeasured ? MeasuredStockQuantity - TotalOriginalQuantity : 0;
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public double NetWeightDiff => IsMeasurable && IsMeasured ? double.Round(MeasuredNetWeight - OriginalNetWeight, 1) : 0d;
[Association(ThisKey = nameof(Id), OtherKey = nameof(StockTakingItemPallet.StockTakingItemId), CanBeNull = true)]
public List<StockTakingItemPallet>? StockTakingItemPallets { get; set; }
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsRequiredForMeasuring => !IsInvalid && (TotalOriginalQuantity != 0 || OriginalNetWeight != 0);
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsInvalid => TotalOriginalQuantity < 0;
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public string DisplayText
{
get
{
if (IsInvalid) return $"[HIBA] {Product!.Name}";
if (IsMeasured) return $"[KÉSZ] {Product!.Name}";
return IsRequiredForMeasuring ? $"[KÖT] {Product!.Name}" : $"{Product!.Name}";
}
}
}