From 1b6aae83f168452bd98a0510840cad8853152811 Mon Sep 17 00:00:00 2001 From: Loretta Date: Thu, 4 Dec 2025 13:52:51 +0100 Subject: [PATCH] StockTaking in progress... --- FruitBank.Common/Dtos/OrderDto.cs | 25 ++-- FruitBank.Common/Dtos/OrderItemDto.cs | 23 +-- FruitBank.Common/Dtos/ProductDto.cs | 19 +-- .../Dtos/StockQuantityHistoryDto.cs | 9 +- .../Entities/MeasuringItemPalletBase.cs | 3 +- FruitBank.Common/Entities/OrderItemPallet.cs | 6 +- .../Entities/ShippingDocumentToFiles.cs | 3 +- FruitBank.Common/Entities/ShippingItem.cs | 12 +- FruitBank.Common/Entities/StockTakingItem.cs | 25 +++- .../Entities/StockTakingItemPallet.cs | 10 +- .../Interfaces/IStockSignalREndpointCommon.cs | 2 +- FruitBank.Common/SignalRs/SignalRTags.cs | 7 +- .../GridStockTakingItem.razor | 48 +++++-- .../Components/PalletItemComponent.razor | 1 + .../StockTakings/StockTakingTemplate.razor | 133 +++++++++++++++--- .../Services/MeasurementService.cs | 17 ++- .../SignalRs/FruitBankSignalRClient.cs | 19 +-- 17 files changed, 268 insertions(+), 94 deletions(-) diff --git a/FruitBank.Common/Dtos/OrderDto.cs b/FruitBank.Common/Dtos/OrderDto.cs index 8993f86..c19a2b7 100644 --- a/FruitBank.Common/Dtos/OrderDto.cs +++ b/FruitBank.Common/Dtos/OrderDto.cs @@ -13,6 +13,7 @@ using Nop.Core; //using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Common; using Nop.Core.Domain.Orders; +using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq.Expressions; @@ -21,7 +22,7 @@ namespace FruitBank.Common.Dtos; public class OrderDto : MgOrderDto, IOrderDto { - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] private static Expression> RelationWithGenericAttribute => (orderDto, genericAttributeDto) => orderDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(Order); @@ -29,21 +30,21 @@ public class OrderDto : MgOrderDto, IOrderDto [Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = true)] public List GenericAttributes { get; set; } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsMeasured { get => IsMeasuredAndValid(); set => throw new Exception($"OrderDto.IsMeasured not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsMeasurable { get => OrderItemDtos.Any(oi => oi.IsMeasurable); set => throw new Exception($"OrderDto.IsMeasurable not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public string TimeOfReceiptText { get @@ -60,25 +61,25 @@ public class OrderDto : MgOrderDto, IOrderDto } } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public DateTime DateOfReceiptOrCreated => DateOfReceipt ?? CreatedOnUtc; - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public DateTime? DateOfReceipt => GenericAttributes.GetValueOrNull(nameof(IOrderDto.DateOfReceipt)); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int RevisorId => GenericAttributes.GetValueOrDefault(nameof(IOrderDto.RevisorId), 0); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int MeasurementOwnerId => GenericAttributes.GetValueOrDefault(nameof(IOrderDto.MeasurementOwnerId), 0); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsAllOrderItemAudited => OrderItemDtos.Count > 0 && OrderItemDtos.All(oi => oi.IsAudited); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsAllOrderItemAvgWeightValid => OrderItemDtos.All(oi => oi.AverageWeightIsValid); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public MeasuringStatus MeasuringStatus { get @@ -99,7 +100,7 @@ public class OrderDto : MgOrderDto, IOrderDto public OrderDto(Order order) : base(order) { } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsComplete => OrderStatus == OrderStatus.Complete; public bool HasMeasuringAccess(int? customerId, bool isRevisorUser = false) diff --git a/FruitBank.Common/Dtos/OrderItemDto.cs b/FruitBank.Common/Dtos/OrderItemDto.cs index db09af7..59fb1d5 100644 --- a/FruitBank.Common/Dtos/OrderItemDto.cs +++ b/FruitBank.Common/Dtos/OrderItemDto.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using Nop.Core; using Nop.Core.Domain.Common; using Nop.Core.Domain.Orders; +using System.ComponentModel.DataAnnotations.Schema; using System.Globalization; using System.Linq; using System.Linq.Expressions; @@ -15,7 +16,7 @@ namespace FruitBank.Common.Dtos; public class OrderItemDto : MgOrderItemDto, IOrderItemDto { - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] private static Expression> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) => orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(OrderItem); @@ -29,28 +30,28 @@ public class OrderItemDto : MgOrderItemDto, IOrderItemDto [Association(ThisKey = nameof(OrderId), OtherKey = nameof(OrderDto.Id), CanBeNull = false)] public OrderDto OrderDto { get; set; } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsMeasured { get => IsMeasuredAndValid(); set => throw new Exception($"OrderItemDto.IsMeasured not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsMeasurable { get => ProductDto!.IsMeasurable; set => throw new Exception($"OrderItemDto.IsMeasurable not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int TrayQuantity { get => OrderItemPallets.Sum(x => x.TrayQuantity); set => throw new Exception($"OrderItemDto.TrayQuantity not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double NetWeight { get @@ -67,7 +68,7 @@ public class OrderItemDto : MgOrderItemDto, IOrderItemDto } } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double GrossWeight { get @@ -84,20 +85,20 @@ public class OrderItemDto : MgOrderItemDto, IOrderItemDto } } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double AverageWeight => IsMeasurable && OrderItemPallets.Count > 0 ? double.Round(OrderItemPallets.Sum(oip => oip.AverageWeight) / OrderItemPallets.Count, 1) : 0d; - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double AverageWeightDifference => IsMeasurable ? double.Round(ProductDto!.AverageWeight - AverageWeight, 1) : 0; - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool AverageWeightIsValid => !IsMeasurable || (ProductDto!.AverageWeight > 0 && ((AverageWeightDifference / ProductDto!.AverageWeight) * 100) < ProductDto!.AverageWeightTreshold); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsAudited => OrderItemPallets.Count > 0 && OrderItemPallets.All(oip => oip.IsAudited); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public MeasuringStatus MeasuringStatus { get diff --git a/FruitBank.Common/Dtos/ProductDto.cs b/FruitBank.Common/Dtos/ProductDto.cs index c9d26dd..fe1eda6 100644 --- a/FruitBank.Common/Dtos/ProductDto.cs +++ b/FruitBank.Common/Dtos/ProductDto.cs @@ -2,17 +2,18 @@ using LinqToDB.Mapping; using Mango.Nop.Core.Dtos; using Mango.Nop.Core.Extensions; +using Mango.Nop.Core.Interfaces.ForeignKeys; using Newtonsoft.Json; //using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Common; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq.Expressions; -using Mango.Nop.Core.Interfaces.ForeignKeys; namespace FruitBank.Common.Dtos; public class ProductDto : MgProductDto, IProductDto { - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] private static Expression> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) => orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == "Product";// nameof(Product); @@ -27,7 +28,7 @@ public class ProductDto : MgProductDto, IProductDto //public ProductDto(Product product) : base(product) //{ } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsMeasurable { get => GenericAttributes.GetValueOrDefault(nameof(IMeasurable.IsMeasurable)); @@ -41,7 +42,7 @@ public class ProductDto : MgProductDto, IProductDto } } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double Tare { get => GenericAttributes.GetValueOrDefault(nameof(ITare.Tare)); @@ -49,14 +50,14 @@ public class ProductDto : MgProductDto, IProductDto set => throw new Exception($"ProductDto.Tare not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double NetWeight { get => GenericAttributes.GetValueOrDefault(nameof(IMeasuringNetWeight.NetWeight)); set => throw new Exception($"ProductDto.NetWeight not set"); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int IncomingQuantity { get => GenericAttributes.GetValueOrDefault(nameof(IIncomingQuantity.IncomingQuantity)); @@ -70,13 +71,13 @@ public class ProductDto : MgProductDto, IProductDto //} } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int AvailableQuantity => StockQuantity + IncomingQuantity; - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double AverageWeight => GenericAttributes.GetValueOrDefault(nameof(IProductDto.AverageWeight)); - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double AverageWeightTreshold => GenericAttributes.GetValueOrDefault(nameof(IProductDto.AverageWeightTreshold)); public bool HasMeasuringValues() => Id > 0 && NetWeight != 0 && IsMeasurable; diff --git a/FruitBank.Common/Dtos/StockQuantityHistoryDto.cs b/FruitBank.Common/Dtos/StockQuantityHistoryDto.cs index 751d6df..fbfb79a 100644 --- a/FruitBank.Common/Dtos/StockQuantityHistoryDto.cs +++ b/FruitBank.Common/Dtos/StockQuantityHistoryDto.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using Nop.Core.Domain.Catalog; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,28 +16,28 @@ namespace FruitBank.Common.Dtos { public class StockQuantityHistoryDto : MgStockQuantityHistoryDto, IStockQuantityHistoryDto { - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public int? StockQuantityHistoryId { get => StockQuantityHistoryExt?.StockQuantityHistoryId; set => StockQuantityHistoryExt!.StockQuantityHistoryId = value!.Value; } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double? NetWeightAdjustment { get => StockQuantityHistoryExt?.NetWeightAdjustment; set => StockQuantityHistoryExt!.NetWeightAdjustment = value; } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double? NetWeight { get => StockQuantityHistoryExt?.NetWeight; set => StockQuantityHistoryExt!.NetWeight = value; } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public bool IsInconsistent { get => StockQuantityHistoryExt?.IsInconsistent ?? false; diff --git a/FruitBank.Common/Entities/MeasuringItemPalletBase.cs b/FruitBank.Common/Entities/MeasuringItemPalletBase.cs index 6aa5416..1ef861a 100644 --- a/FruitBank.Common/Entities/MeasuringItemPalletBase.cs +++ b/FruitBank.Common/Entities/MeasuringItemPalletBase.cs @@ -35,7 +35,7 @@ public abstract class MeasuringItemPalletBase : MgEntityBase, IMeasuringItemPall set => _palletWeight = double.Round(value, 0); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, System.ComponentModel.DataAnnotations.Schema.NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double NetWeight { get => CalculateNetWeight(); @@ -59,6 +59,7 @@ public abstract class MeasuringItemPalletBase : MgEntityBase, IMeasuringItemPall public DateTime Created { get; set; } public DateTime Modified { get; set; } + [NotColumn, System.ComponentModel.DataAnnotations.Schema.NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public virtual MeasuringStatus MeasuringStatus => IsMeasured ? MeasuringStatus.Finnished : Id > 0 ? MeasuringStatus.Started : MeasuringStatus.NotStarted; public void SetForeignKey(int foreignKey) => ForeignItemId = foreignKey; diff --git a/FruitBank.Common/Entities/OrderItemPallet.cs b/FruitBank.Common/Entities/OrderItemPallet.cs index 7561870..1125549 100644 --- a/FruitBank.Common/Entities/OrderItemPallet.cs +++ b/FruitBank.Common/Entities/OrderItemPallet.cs @@ -4,10 +4,11 @@ using FruitBank.Common.Interfaces; using LinqToDB.Mapping; using Newtonsoft.Json; using Nop.Core.Domain.Orders; +using System.ComponentModel.DataAnnotations.Schema; namespace FruitBank.Common.Entities; -[Table(Name = FruitBankConstClient.OrderItemPalletDbTableName)] +[LinqToDB.Mapping.Table(Name = FruitBankConstClient.OrderItemPalletDbTableName)] [System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.OrderItemPalletDbTableName)] public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet { @@ -23,6 +24,7 @@ public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet [Association(ThisKey = nameof(OrderItemId), OtherKey = nameof(OrderItemDto.Id), CanBeNull = true)] public OrderItemDto? OrderItemDto { get; set; } + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public override MeasuringStatus MeasuringStatus => IsAudited ? MeasuringStatus.Audited : base.MeasuringStatus; public override double CalculateNetWeight() => base.CalculateNetWeight(); @@ -31,7 +33,7 @@ public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet return OrderItemId > 0 && base.IsValidSafeMeasuringValues(); } - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public double AverageWeight => double.Round(NetWeight / TrayQuantity, 1); /// /// "Szigorúbb" mint az IsValidSafeMeasuringValues() diff --git a/FruitBank.Common/Entities/ShippingDocumentToFiles.cs b/FruitBank.Common/Entities/ShippingDocumentToFiles.cs index a85c245..1e5f2f9 100644 --- a/FruitBank.Common/Entities/ShippingDocumentToFiles.cs +++ b/FruitBank.Common/Entities/ShippingDocumentToFiles.cs @@ -2,6 +2,7 @@ using FruitBank.Common.Interfaces; using LinqToDB.Mapping; using Mango.Nop.Core.Entities; +using Newtonsoft.Json; namespace FruitBank.Common.Entities; @@ -14,7 +15,7 @@ public class ShippingDocumentToFiles : MgEntityBase, IShippingDocumentToFiles public int DocumentTypeId { get; set; } - [NotColumn, NotMapped] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public DocumentType DocumentType { get => (DocumentType)DocumentTypeId; diff --git a/FruitBank.Common/Entities/ShippingItem.cs b/FruitBank.Common/Entities/ShippingItem.cs index eba39c8..31492ca 100644 --- a/FruitBank.Common/Entities/ShippingItem.cs +++ b/FruitBank.Common/Entities/ShippingItem.cs @@ -1,16 +1,19 @@ using AyCode.Core.Interfaces; +using FruitBank.Common.Dtos; +using FruitBank.Common.Enums; using FruitBank.Common.Interfaces; using LinqToDB; using LinqToDB.Mapping; using Mango.Nop.Core.Entities; +using Newtonsoft.Json; using Nop.Core.Domain.Customers; using Nop.Core.Domain.Orders; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; //using Nop.Core.Domain.Catalog; using DataType = LinqToDB.DataType; -using FruitBank.Common.Dtos; -using FruitBank.Common.Enums; -using Newtonsoft.Json; +using Column = LinqToDB.Mapping.ColumnAttribute; +using Table = LinqToDB.Mapping.TableAttribute; namespace FruitBank.Common.Entities; @@ -29,7 +32,7 @@ public class ShippingItem : MgEntityBase, IShippingItem /// /// get => ProductDto?.Name ?? Name /// - [NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public string ProductName => ProductDto?.Name ?? Name; public int PalletsOnDocument { get; set; } @@ -79,6 +82,7 @@ public class ShippingItem : MgEntityBase, IShippingItem [SkipValuesOnUpdate] public DateTime Created { get; set; } public DateTime Modified { get; set; } + [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] public MeasuringStatus MeasuringStatus { get diff --git a/FruitBank.Common/Entities/StockTakingItem.cs b/FruitBank.Common/Entities/StockTakingItem.cs index 9c002a2..a51fb5e 100644 --- a/FruitBank.Common/Entities/StockTakingItem.cs +++ b/FruitBank.Common/Entities/StockTakingItem.cs @@ -2,6 +2,10 @@ 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; @@ -9,21 +13,40 @@ namespace FruitBank.Common.Entities; [System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingItemDbTableName)] public class StockTakingItem : MgStockTakingItem { + 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? StockTakingItemPallets { get; set; } - public bool IsRequiredForMeasuring => OriginalStockQuantity != 0 || OriginalNetWeight != 0; + [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}"; diff --git a/FruitBank.Common/Entities/StockTakingItemPallet.cs b/FruitBank.Common/Entities/StockTakingItemPallet.cs index 9fbc832..4f11b68 100644 --- a/FruitBank.Common/Entities/StockTakingItemPallet.cs +++ b/FruitBank.Common/Entities/StockTakingItemPallet.cs @@ -28,16 +28,12 @@ public class StockTakingItemPallet : MeasuringItemPalletBase, IStockTakingItemPa public override bool IsValidSafeMeasuringValues() { - return StockTakingItemId > 0 && base.IsValidSafeMeasuringValues(); + return StockTakingItemId > 0 && TrayQuantity >= 0 && TareWeight >= 0 && PalletWeight >= 0 && NetWeight >= 0 && GrossWeight >= 0; } - /// - /// "Szigorúbb" mint az IsValidSafeMeasuringValues() - /// - /// - /// public override bool IsValidMeasuringValues(bool isMeasurable) { - return StockTakingItemId > 0 && base.IsValidMeasuringValues(isMeasurable); + return StockTakingItemId > 0 && TrayQuantity >= 0 && ((!isMeasurable && NetWeight == 0 && GrossWeight == 0 && PalletWeight == 0 && TareWeight == 0) + || (isMeasurable && NetWeight >= 0 && GrossWeight >= 0 && PalletWeight >= 0 && TareWeight >= 0)); } } \ No newline at end of file diff --git a/FruitBank.Common/Interfaces/IStockSignalREndpointCommon.cs b/FruitBank.Common/Interfaces/IStockSignalREndpointCommon.cs index 345a264..bdddc3c 100644 --- a/FruitBank.Common/Interfaces/IStockSignalREndpointCommon.cs +++ b/FruitBank.Common/Interfaces/IStockSignalREndpointCommon.cs @@ -5,7 +5,7 @@ namespace FruitBank.Common.Interfaces; public interface IStockSignalREndpointCommon { - public Task?> GetStockTakings(); + public Task?> GetStockTakings(bool loadRelations); public Task?> GetStockTakingsByProductId(int productId); public Task AddStockTaking(StockTaking stockTaking); public Task UpdateStockTaking(StockTaking stockTaking); diff --git a/FruitBank.Common/SignalRs/SignalRTags.cs b/FruitBank.Common/SignalRs/SignalRTags.cs index 8a80f2f..7ce695c 100644 --- a/FruitBank.Common/SignalRs/SignalRTags.cs +++ b/FruitBank.Common/SignalRs/SignalRTags.cs @@ -91,9 +91,14 @@ public class SignalRTags : AcSignalRTags public const int UpdateGenericAttributeDto = 169; public const int GetStockTakings = 170; + public const int AddStockTaking = 171; + public const int UpdateStockTaking = 172; public const int GetStockTakingItems = 173; public const int GetStockTakingItemsById = 174; - public const int AddStockTaking = 175; + public const int GetStockTakingItemsByProductId = 175; + public const int GetStockTakingItemsByStockTakingId = 176; + public const int AddOrUpdateMeasuredStockTakingItemPallet = 177; + public const int AuthenticateUser = 195; public const int RefreshToken = 200; diff --git a/FruitBankHybrid.Shared/Components/Grids/StockTakingItems/GridStockTakingItem.razor b/FruitBankHybrid.Shared/Components/Grids/StockTakingItems/GridStockTakingItem.razor index 502b85a..dbb9c28 100644 --- a/FruitBankHybrid.Shared/Components/Grids/StockTakingItems/GridStockTakingItem.razor +++ b/FruitBankHybrid.Shared/Components/Grids/StockTakingItems/GridStockTakingItem.razor @@ -14,21 +14,33 @@ @inject FruitBankSignalRClient FruitBankSignalRClient + CssClass="@GridCss" ValidationEnabled="false" FocusedRowChanged="Grid_FocusedRowChanged"> - - + + + + @(((StockTakingItem)context.DataItem)?.StockTaking?.StartDateTime.ToString("g") ?? "") + + - + + + - - + + + + + + + + + @@ -40,6 +52,7 @@ @code { + //[Inject] public required ObjectLock ObjectLock { get; set; } [Inject] public required DatabaseClient Database { get; set; } @@ -70,7 +83,7 @@ if (Grid == null) return; //using (await ObjectLock.GetSemaphore().UseWaitAsync()) - //if (forceReload) await Grid.ReloadDataSourceAsync(); + //if (forceReload) await Grid.ReloadDataSourceAsync(); if (forceReload) Grid.Reload(); } @@ -85,5 +98,24 @@ FocusedRowVisibleIndex = args.VisibleIndex; EditItemsEnabled = true; } + + // void Grid_CustomGroup(GridCustomGroupEventArgs e) + // { + // if (e.FieldName != "StockTaking.StartDateTime") return; + + // e.SameGroup = ((StockTakingItem)e.DataItem1).StockTakingId == ((StockTakingItem)e.DataItem2).StockTakingId; + // e.Handled = true; + // } + + // void Grid_CustomizeGroupValueDisplayText(GridCustomizeGroupValueDisplayTextEventArgs e) + // { + // return; + + // if (e.FieldName != "StockTaking.StartDateTime") return; + + // var startDate = (DateTime)e.Value; + // e.DisplayText = startDate.ToString("g"); + // } + } diff --git a/FruitBankHybrid.Shared/Components/PalletItemComponent.razor b/FruitBankHybrid.Shared/Components/PalletItemComponent.razor index 85bac89..ffa19fc 100644 --- a/FruitBankHybrid.Shared/Components/PalletItemComponent.razor +++ b/FruitBankHybrid.Shared/Components/PalletItemComponent.razor @@ -8,6 +8,7 @@ @using FruitBankHybrid.Shared.Extensions @using FruitBankHybrid.Shared.Services @using FruitBankHybrid.Shared.Services.SignalRs + @typeparam TPalletItem where TPalletItem : class, IMeasuringItemPalletBase + ValueChanged="@(async (StockTaking stockTaking) => await StockTakingComboValueChanged(stockTaking))"> @@ -31,21 +36,70 @@ @* TextFieldName="StockTakingItem.Product.Name" *@ - + - + - + +
+ @if (SelectedStockTakingItem is { ProductId: > 0 }) + { +

+ #@(SelectedStockTakingItem.ProductId). @(SelectedStockTakingItem.Product!.Name) +

+ +
+ @{ + var a = $"Várható rekesz: {SelectedStockTakingItem.TotalOriginalQuantity} ({SelectedStockTakingItem.OriginalStockQuantity} + {SelectedStockTakingItem.InProcessOrdersQuantity}), Várható net.súly: {SelectedStockTakingItem.OriginalNetWeight} kg."; + @a + } +
+ + + @for (var index = 0; index < (SelectedStockTakingItem?.StockTakingItemPallets?.Count ?? 0); index++) + { + var localI = index + 1; + var currentShippingItemPallet = SelectedStockTakingItem!.StockTakingItemPallets![index]; + + + + } + + + @* + + TOTAL: + + + Rekesz: @(SelectedStockTakingItem.MeasuredStockQuantity) db + Br: @(SelectedStockTakingItem.MeasuredGrossWeight) kg + Net: @(SelectedStockTakingItem.MeasuredNetWeight) kg + + + + *@ + + } +
+ @code { [Inject] public required DatabaseClient Database { get; set; } [Inject] public required LoggedInModel LoggedInModel { get; set; } + [Inject] public required IDialogService DialogService { get; set; } = null!; [Inject] public required FruitBankSignalRClient FruitBankSignalRClient { get; set; } List _stockTakings { get; set; } = []; @@ -63,26 +117,26 @@ { LoadingPanelVisibility.Visible = true; - _stockTakings = await FruitBankSignalRClient.GetStockTakings() ?? []; - ValueChanged(_stockTakings.FirstOrDefault()); + _stockTakings = await FruitBankSignalRClient.GetStockTakings(false) ?? []; + await StockTakingComboValueChanged(_stockTakings.FirstOrDefault()); LoadingPanelVisibility.Visible = false; } - private async Task Callback() + private async Task NewStockTakingClick() { var stockTaking = new StockTaking(); stockTaking.StartDateTime = DateTime.Now; stockTaking.Creator = LoggedInModel.CustomerDto!.Id; - var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); - if (resultStockTaking == null) return; + var resultStockTakings = await FruitBankSignalRClient.AddStockTaking(stockTaking); + if (resultStockTakings == null) return; - _stockTakings.Add(resultStockTaking); - StateHasChanged(); + _stockTakings.UpdateCollection(resultStockTakings, false); + await StockTakingComboValueChanged(_stockTakings.FirstOrDefault(x => x.Id == stockTaking.Id)); } - private async Task Callback2() + private async Task UpdateStockTakingClick() { // var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); // if (resultStockTaking == null) return; @@ -91,7 +145,7 @@ StateHasChanged(); } - private async Task Callback3() + private async Task StockTakingCloseClick() { // var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); // if (resultStockTaking == null) return; @@ -100,11 +154,58 @@ StateHasChanged(); } - private void ValueChanged(StockTaking? newValue) + private async Task StockTakingComboValueChanged(StockTaking? newValue) { SelectedStockTaking = newValue; - _stockTakingItems = SelectedStockTaking?.StockTakingItems?.OrderByDescending(x => x.IsMeasured).ThenByDescending(x => x.OriginalStockQuantity != 0 || x.OriginalNetWeight != 0).ThenBy(x => x.Product?.Name).ToList() ?? []; + + SelectedStockTaking?.StockTakingItems = await FruitBankSignalRClient.GetStockTakingItemsByStockTakingId(SelectedStockTaking.Id); + _stockTakingItems = SelectedStockTaking?.StockTakingItems? + .OrderByDescending(x => x.IsInvalid) + .ThenByDescending(x => x.IsRequiredForMeasuring) + .ThenBy(x => x.Product?.Name) + .ToList() ?? []; + + foreach (var stockTakingItem in _stockTakingItems) + { + stockTakingItem.StockTakingItemPallets ??= []; + stockTakingItem.StockTaking = SelectedStockTaking; + + if (!stockTakingItem.IsInvalid && stockTakingItem.StockTakingItemPallets.Count == 0) + { + stockTakingItem.StockTakingItemPallets.Add(MeasurementService.CreateNewStockTakingItemPallet(stockTakingItem, LoggedInModel.CustomerDto)); + } + } SelectedStockTakingItem = _stockTakingItems.FirstOrDefault(); + + StateHasChanged(); } + + private Task OnStockTakingItemPalletValueChanged(StockTakingItemPallet stockTakingItemPallet, StockTakingItem stockTakingItem) + { + // MeasuringValuesHelper.SetShippingItemTotalMeasuringValues(stockTakingItem); + // BtnSaveEnabled = stockTakingItem.IsValidMeasuringValues() && stockTakingItemPallet.IsValidMeasuringValues(stockTakingItem.IsMeasurable); + + StateHasChanged(); + return Task.CompletedTask; + } + + private async Task OnStockTakingItemPalletSaved(StockTakingItemPallet? responseStockTakingItemPallet) + { + if (responseStockTakingItemPallet != null) + { + SelectedStockTakingItem!.MeasuredStockQuantity = responseStockTakingItemPallet.TrayQuantity; + + if (SelectedStockTakingItem.IsMeasurable) SelectedStockTakingItem.MeasuredNetWeight = responseStockTakingItemPallet.NetWeight; + + SelectedStockTakingItem.StockTakingItemPallets!.UpdateCollection(responseStockTakingItemPallet, false); + SelectedStockTakingItem.IsMeasured = SelectedStockTakingItem.StockTakingItemPallets!.All(sip => sip.IsMeasuredAndValid(SelectedStockTakingItem.IsMeasurable)); + + // MeasuringValuesHelper.SetShippingItemTotalMeasuringValues(SelectedShippingItem); + } + else await DialogService.ShowMessageBoxAsync("Hiba", "Adatok mentése sikertelen volt, ellenőrizze a mérés adatait!", MessageBoxRenderStyle.Danger); + + await InvokeAsync(StateHasChanged); + } + } diff --git a/FruitBankHybrid.Shared/Services/MeasurementService.cs b/FruitBankHybrid.Shared/Services/MeasurementService.cs index fb619cf..6db0a97 100644 --- a/FruitBankHybrid.Shared/Services/MeasurementService.cs +++ b/FruitBankHybrid.Shared/Services/MeasurementService.cs @@ -65,7 +65,7 @@ public class MeasurementService(IEnumerable logWriters) public static ShippingItemPallet CreateNewShippingItemPallet(ShippingItem shippingItem, CustomerDto? customerDto) { - var shippingItemPallet = CreatePalletItem(shippingItem.Id, shippingItem.ProductDto?.Tare, shippingItem.IsMeasurable, customerDto); + var shippingItemPallet = CreatePalletItemBase(shippingItem.Id, shippingItem.ProductDto?.Tare, shippingItem.IsMeasurable, customerDto); shippingItemPallet.ShippingItem = shippingItem; shippingItemPallet.PalletWeight = shippingItem.IsMeasurable ? shippingItem.Pallet?.Weight ?? 0 : 0; @@ -75,13 +75,24 @@ public class MeasurementService(IEnumerable logWriters) public static OrderItemPallet CreateNewOrderItemPallet(OrderItemDto orderItemDto, CustomerDto? customerDto) { - var orderItemPallet = CreatePalletItem(orderItemDto.Id, orderItemDto.ProductDto?.Tare, orderItemDto.IsMeasurable, customerDto); + var orderItemPallet = CreatePalletItemBase(orderItemDto.Id, orderItemDto.ProductDto?.Tare, orderItemDto.IsMeasurable, customerDto); orderItemPallet.OrderItemDto = orderItemDto; return orderItemPallet; } - private static TPalletItem CreatePalletItem(int foreignKey, double? tare, bool isMeasurable, CustomerDto? customerDto) where TPalletItem : MeasuringItemPalletBase + public static StockTakingItemPallet CreateNewStockTakingItemPallet(StockTakingItem stockTakingItem, CustomerDto? customerDto) + { + var stockTakingItemPallet = CreatePalletItemBase(stockTakingItem.Id, stockTakingItem.Product?.Tare, stockTakingItem.IsMeasurable, customerDto); + + stockTakingItemPallet.GrossWeight = stockTakingItem.IsMeasurable ? -1 : 0; + stockTakingItemPallet.TrayQuantity = -1; + + stockTakingItemPallet.StockTakingItem = stockTakingItem; + return stockTakingItemPallet; + } + + private static TPalletItem CreatePalletItemBase(int foreignKey, double? tare, bool isMeasurable, CustomerDto? customerDto) where TPalletItem : MeasuringItemPalletBase { var palletItem = Activator.CreateInstance(); diff --git a/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs b/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs index 73fc176..11711f6 100644 --- a/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs +++ b/FruitBankHybrid.Shared/Services/SignalRs/FruitBankSignalRClient.cs @@ -281,7 +281,7 @@ namespace FruitBankHybrid.Shared.Services.SignalRs } - public Task?> GetStockTakings() => GetAllAsync>(SignalRTags.GetStockTakings); + public Task?> GetStockTakings(bool loadRelations) => GetAllAsync>(SignalRTags.GetStockTakings, [loadRelations]); public async Task?> GetStockTakingsByProductId(int productId) { @@ -290,25 +290,18 @@ namespace FruitBankHybrid.Shared.Services.SignalRs public Task AddStockTaking(StockTaking stockTaking) => PostDataAsync(SignalRTags.AddStockTaking, stockTaking); - public async Task UpdateStockTaking(StockTaking stockTaking) - { - throw new NotImplementedException(); - } + public Task UpdateStockTaking(StockTaking stockTaking) => PostDataAsync(SignalRTags.UpdateStockTaking, stockTaking); public Task?> GetStockTakingItems() => GetAllAsync>(SignalRTags.GetStockTakingItems); public Task GetStockTakingItemsById(int stockTakingItemId) => GetByIdAsync(SignalRTags.GetStockTakingItemsById, [stockTakingItemId]); - public async Task?> GetStockTakingItemsByProductId(int productId) - { - throw new NotImplementedException(); - } + public Task?> GetStockTakingItemsByProductId(int productId) + => GetAllAsync>(SignalRTags.GetStockTakingItemsByProductId, [productId]); - public async Task?> GetStockTakingItemsByStockTakingId(int stockTakingId) - { - throw new NotImplementedException(); - } + public Task?> GetStockTakingItemsByStockTakingId(int stockTakingId) + => GetAllAsync>(SignalRTags.GetStockTakingItemsByStockTakingId, [stockTakingId]); public async Task AddStockTakingItem(StockTakingItem stockTakingItem) {