StockTaking in progress...

This commit is contained in:
Loretta 2025-12-04 13:52:51 +01:00
parent e13e32dc57
commit 1b6aae83f1
17 changed files with 268 additions and 94 deletions

View File

@ -13,6 +13,7 @@ using Nop.Core;
//using Nop.Core.Domain.Catalog; //using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common; using Nop.Core.Domain.Common;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -21,7 +22,7 @@ namespace FruitBank.Common.Dtos;
public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto
{ {
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
private static Expression<Func<OrderDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderDto, genericAttributeDto) => private static Expression<Func<OrderDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderDto, genericAttributeDto) =>
orderDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(Order); orderDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(Order);
@ -29,21 +30,21 @@ public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto
[Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = true)] [Association(ThisKey = nameof(Id), OtherKey = nameof(GenericAttribute.EntityId), ExpressionPredicate = nameof(RelationWithGenericAttribute), CanBeNull = true)]
public List<GenericAttributeDto> GenericAttributes { get; set; } public List<GenericAttributeDto> GenericAttributes { get; set; }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsMeasured public bool IsMeasured
{ {
get => IsMeasuredAndValid(); get => IsMeasuredAndValid();
set => throw new Exception($"OrderDto.IsMeasured not set"); 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 public bool IsMeasurable
{ {
get => OrderItemDtos.Any(oi => oi.IsMeasurable); get => OrderItemDtos.Any(oi => oi.IsMeasurable);
set => throw new Exception($"OrderDto.IsMeasurable not set"); 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 public string TimeOfReceiptText
{ {
get get
@ -60,25 +61,25 @@ public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto
} }
} }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public DateTime DateOfReceiptOrCreated => DateOfReceipt ?? CreatedOnUtc; 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<DateTime>(nameof(IOrderDto.DateOfReceipt)); public DateTime? DateOfReceipt => GenericAttributes.GetValueOrNull<DateTime>(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); 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); 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); 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); 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 public MeasuringStatus MeasuringStatus
{ {
get get
@ -99,7 +100,7 @@ public class OrderDto : MgOrderDto<OrderItemDto, ProductDto>, IOrderDto
public OrderDto(Order order) : base(order) 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 IsComplete => OrderStatus == OrderStatus.Complete;
public bool HasMeasuringAccess(int? customerId, bool isRevisorUser = false) public bool HasMeasuringAccess(int? customerId, bool isRevisorUser = false)

View File

@ -7,6 +7,7 @@ using Newtonsoft.Json;
using Nop.Core; using Nop.Core;
using Nop.Core.Domain.Common; using Nop.Core.Domain.Common;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -15,7 +16,7 @@ namespace FruitBank.Common.Dtos;
public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto
{ {
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
private static Expression<Func<OrderItemDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) => private static Expression<Func<OrderItemDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) =>
orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(OrderItem); orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == nameof(OrderItem);
@ -29,28 +30,28 @@ public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto
[Association(ThisKey = nameof(OrderId), OtherKey = nameof(OrderDto.Id), CanBeNull = false)] [Association(ThisKey = nameof(OrderId), OtherKey = nameof(OrderDto.Id), CanBeNull = false)]
public OrderDto OrderDto { get; set; } public OrderDto OrderDto { get; set; }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsMeasured public bool IsMeasured
{ {
get => IsMeasuredAndValid(); get => IsMeasuredAndValid();
set => throw new Exception($"OrderItemDto.IsMeasured not set"); 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 public bool IsMeasurable
{ {
get => ProductDto!.IsMeasurable; get => ProductDto!.IsMeasurable;
set => throw new Exception($"OrderItemDto.IsMeasurable not set"); 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 public int TrayQuantity
{ {
get => OrderItemPallets.Sum(x => x.TrayQuantity); get => OrderItemPallets.Sum(x => x.TrayQuantity);
set => throw new Exception($"OrderItemDto.TrayQuantity not set"); 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 public double NetWeight
{ {
get get
@ -67,7 +68,7 @@ public class OrderItemDto : MgOrderItemDto<ProductDto>, IOrderItemDto
} }
} }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public double GrossWeight public double GrossWeight
{ {
get get
@ -84,20 +85,20 @@ public class OrderItemDto : MgOrderItemDto<ProductDto>, 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; 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; 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 || public bool AverageWeightIsValid => !IsMeasurable ||
(ProductDto!.AverageWeight > 0 && ((AverageWeightDifference / ProductDto!.AverageWeight) * 100) < ProductDto!.AverageWeightTreshold); (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); 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 public MeasuringStatus MeasuringStatus
{ {
get get

View File

@ -2,17 +2,18 @@
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Mango.Nop.Core.Dtos; using Mango.Nop.Core.Dtos;
using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Extensions;
using Mango.Nop.Core.Interfaces.ForeignKeys;
using Newtonsoft.Json; using Newtonsoft.Json;
//using Nop.Core.Domain.Catalog; //using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common; using Nop.Core.Domain.Common;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq.Expressions; using System.Linq.Expressions;
using Mango.Nop.Core.Interfaces.ForeignKeys;
namespace FruitBank.Common.Dtos; namespace FruitBank.Common.Dtos;
public class ProductDto : MgProductDto, IProductDto public class ProductDto : MgProductDto, IProductDto
{ {
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
private static Expression<Func<ProductDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) => private static Expression<Func<ProductDto, GenericAttributeDto, bool>> RelationWithGenericAttribute => (orderItemDto, genericAttributeDto) =>
orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == "Product";// nameof(Product); orderItemDto.Id == genericAttributeDto.EntityId && genericAttributeDto.KeyGroup == "Product";// nameof(Product);
@ -27,7 +28,7 @@ public class ProductDto : MgProductDto, IProductDto
//public ProductDto(Product product) : base(product) //public ProductDto(Product product) : base(product)
//{ } //{ }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsMeasurable public bool IsMeasurable
{ {
get => GenericAttributes.GetValueOrDefault<bool>(nameof(IMeasurable.IsMeasurable)); get => GenericAttributes.GetValueOrDefault<bool>(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 public double Tare
{ {
get => GenericAttributes.GetValueOrDefault<double>(nameof(ITare.Tare)); get => GenericAttributes.GetValueOrDefault<double>(nameof(ITare.Tare));
@ -49,14 +50,14 @@ public class ProductDto : MgProductDto, IProductDto
set => throw new Exception($"ProductDto.Tare not set"); 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 public double NetWeight
{ {
get => GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight)); get => GenericAttributes.GetValueOrDefault<double>(nameof(IMeasuringNetWeight.NetWeight));
set => throw new Exception($"ProductDto.NetWeight not set"); 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 public int IncomingQuantity
{ {
get => GenericAttributes.GetValueOrDefault<int>(nameof(IIncomingQuantity.IncomingQuantity)); get => GenericAttributes.GetValueOrDefault<int>(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; 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<double>(nameof(IProductDto.AverageWeight)); public double AverageWeight => GenericAttributes.GetValueOrDefault<double>(nameof(IProductDto.AverageWeight));
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public double AverageWeightTreshold => GenericAttributes.GetValueOrDefault<double>(nameof(IProductDto.AverageWeightTreshold)); public double AverageWeightTreshold => GenericAttributes.GetValueOrDefault<double>(nameof(IProductDto.AverageWeightTreshold));
public bool HasMeasuringValues() => Id > 0 && NetWeight != 0 && IsMeasurable; public bool HasMeasuringValues() => Id > 0 && NetWeight != 0 && IsMeasurable;

View File

@ -7,6 +7,7 @@ using Newtonsoft.Json;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,28 +16,28 @@ namespace FruitBank.Common.Dtos
{ {
public class StockQuantityHistoryDto : MgStockQuantityHistoryDto<ProductDto>, IStockQuantityHistoryDto public class StockQuantityHistoryDto : MgStockQuantityHistoryDto<ProductDto>, IStockQuantityHistoryDto
{ {
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public int? StockQuantityHistoryId public int? StockQuantityHistoryId
{ {
get => StockQuantityHistoryExt?.StockQuantityHistoryId; get => StockQuantityHistoryExt?.StockQuantityHistoryId;
set => StockQuantityHistoryExt!.StockQuantityHistoryId = value!.Value; set => StockQuantityHistoryExt!.StockQuantityHistoryId = value!.Value;
} }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public double? NetWeightAdjustment public double? NetWeightAdjustment
{ {
get => StockQuantityHistoryExt?.NetWeightAdjustment; get => StockQuantityHistoryExt?.NetWeightAdjustment;
set => StockQuantityHistoryExt!.NetWeightAdjustment = value; set => StockQuantityHistoryExt!.NetWeightAdjustment = value;
} }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public double? NetWeight public double? NetWeight
{ {
get => StockQuantityHistoryExt?.NetWeight; get => StockQuantityHistoryExt?.NetWeight;
set => StockQuantityHistoryExt!.NetWeight = value; set => StockQuantityHistoryExt!.NetWeight = value;
} }
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public bool IsInconsistent public bool IsInconsistent
{ {
get => StockQuantityHistoryExt?.IsInconsistent ?? false; get => StockQuantityHistoryExt?.IsInconsistent ?? false;

View File

@ -35,7 +35,7 @@ public abstract class MeasuringItemPalletBase : MgEntityBase, IMeasuringItemPall
set => _palletWeight = double.Round(value, 0); 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 public double NetWeight
{ {
get => CalculateNetWeight(); get => CalculateNetWeight();
@ -59,6 +59,7 @@ public abstract class MeasuringItemPalletBase : MgEntityBase, IMeasuringItemPall
public DateTime Created { get; set; } public DateTime Created { get; set; }
public DateTime Modified { 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 virtual MeasuringStatus MeasuringStatus => IsMeasured ? MeasuringStatus.Finnished : Id > 0 ? MeasuringStatus.Started : MeasuringStatus.NotStarted;
public void SetForeignKey(int foreignKey) => ForeignItemId = foreignKey; public void SetForeignKey(int foreignKey) => ForeignItemId = foreignKey;

View File

@ -4,10 +4,11 @@ using FruitBank.Common.Interfaces;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Newtonsoft.Json; using Newtonsoft.Json;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using System.ComponentModel.DataAnnotations.Schema;
namespace FruitBank.Common.Entities; namespace FruitBank.Common.Entities;
[Table(Name = FruitBankConstClient.OrderItemPalletDbTableName)] [LinqToDB.Mapping.Table(Name = FruitBankConstClient.OrderItemPalletDbTableName)]
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.OrderItemPalletDbTableName)] [System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.OrderItemPalletDbTableName)]
public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet
{ {
@ -23,6 +24,7 @@ public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet
[Association(ThisKey = nameof(OrderItemId), OtherKey = nameof(OrderItemDto.Id), CanBeNull = true)] [Association(ThisKey = nameof(OrderItemId), OtherKey = nameof(OrderItemDto.Id), CanBeNull = true)]
public OrderItemDto? OrderItemDto { get; set; } public OrderItemDto? OrderItemDto { get; set; }
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public override MeasuringStatus MeasuringStatus => IsAudited ? MeasuringStatus.Audited : base.MeasuringStatus; public override MeasuringStatus MeasuringStatus => IsAudited ? MeasuringStatus.Audited : base.MeasuringStatus;
public override double CalculateNetWeight() => base.CalculateNetWeight(); public override double CalculateNetWeight() => base.CalculateNetWeight();
@ -31,7 +33,7 @@ public class OrderItemPallet : MeasuringItemPalletBase, IOrderItemPallet
return OrderItemId > 0 && base.IsValidSafeMeasuringValues(); 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); public double AverageWeight => double.Round(NetWeight / TrayQuantity, 1);
/// <summary> /// <summary>
/// "Szigorúbb" mint az IsValidSafeMeasuringValues() /// "Szigorúbb" mint az IsValidSafeMeasuringValues()

View File

@ -2,6 +2,7 @@
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Mango.Nop.Core.Entities; using Mango.Nop.Core.Entities;
using Newtonsoft.Json;
namespace FruitBank.Common.Entities; namespace FruitBank.Common.Entities;
@ -14,7 +15,7 @@ public class ShippingDocumentToFiles : MgEntityBase, IShippingDocumentToFiles
public int DocumentTypeId { get; set; } public int DocumentTypeId { get; set; }
[NotColumn, NotMapped] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public DocumentType DocumentType public DocumentType DocumentType
{ {
get => (DocumentType)DocumentTypeId; get => (DocumentType)DocumentTypeId;

View File

@ -1,16 +1,19 @@
using AyCode.Core.Interfaces; using AyCode.Core.Interfaces;
using FruitBank.Common.Dtos;
using FruitBank.Common.Enums;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using LinqToDB; using LinqToDB;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Mango.Nop.Core.Entities; using Mango.Nop.Core.Entities;
using Newtonsoft.Json;
using Nop.Core.Domain.Customers; using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
//using Nop.Core.Domain.Catalog; //using Nop.Core.Domain.Catalog;
using DataType = LinqToDB.DataType; using DataType = LinqToDB.DataType;
using FruitBank.Common.Dtos; using Column = LinqToDB.Mapping.ColumnAttribute;
using FruitBank.Common.Enums; using Table = LinqToDB.Mapping.TableAttribute;
using Newtonsoft.Json;
namespace FruitBank.Common.Entities; namespace FruitBank.Common.Entities;
@ -29,7 +32,7 @@ public class ShippingItem : MgEntityBase, IShippingItem
/// <summary> /// <summary>
/// get => ProductDto?.Name ?? Name /// get => ProductDto?.Name ?? Name
/// </summary> /// </summary>
[NotColumn, JsonIgnore, System.Text.Json.Serialization.JsonIgnore] [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public string ProductName => ProductDto?.Name ?? Name; public string ProductName => ProductDto?.Name ?? Name;
public int PalletsOnDocument { get; set; } public int PalletsOnDocument { get; set; }
@ -79,6 +82,7 @@ public class ShippingItem : MgEntityBase, IShippingItem
[SkipValuesOnUpdate] public DateTime Created { get; set; } [SkipValuesOnUpdate] public DateTime Created { get; set; }
public DateTime Modified { get; set; } public DateTime Modified { get; set; }
[NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
public MeasuringStatus MeasuringStatus public MeasuringStatus MeasuringStatus
{ {
get get

View File

@ -2,6 +2,10 @@
using LinqToDB; using LinqToDB;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Mango.Nop.Core.Entities; 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; namespace FruitBank.Common.Entities;
@ -9,21 +13,40 @@ namespace FruitBank.Common.Entities;
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingItemDbTableName)] [System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingItemDbTableName)]
public class StockTakingItem : MgStockTakingItem<StockTaking, ProductDto> public class StockTakingItem : MgStockTakingItem<StockTaking, ProductDto>
{ {
public bool IsMeasurable { get; set; }
[Column(DataType = DataType.DecFloat, CanBeNull = false)] [Column(DataType = DataType.DecFloat, CanBeNull = false)]
public double OriginalNetWeight { get; set; } public double OriginalNetWeight { get; set; }
[Column(DataType = DataType.DecFloat, CanBeNull = false)] [Column(DataType = DataType.DecFloat, CanBeNull = false)]
public double MeasuredNetWeight { get; set; } 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)] [Association(ThisKey = nameof(Id), OtherKey = nameof(StockTakingItemPallet.StockTakingItemId), CanBeNull = true)]
public List<StockTakingItemPallet>? StockTakingItemPallets { get; set; } public List<StockTakingItemPallet>? 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 public string DisplayText
{ {
get get
{ {
if (IsInvalid) return $"[HIBA] {Product!.Name}";
if (IsMeasured) return $"[KÉSZ] {Product!.Name}"; if (IsMeasured) return $"[KÉSZ] {Product!.Name}";
return IsRequiredForMeasuring ? $"[KÖT] {Product!.Name}" : $"{Product!.Name}"; return IsRequiredForMeasuring ? $"[KÖT] {Product!.Name}" : $"{Product!.Name}";

View File

@ -28,16 +28,12 @@ public class StockTakingItemPallet : MeasuringItemPalletBase, IStockTakingItemPa
public override bool IsValidSafeMeasuringValues() public override bool IsValidSafeMeasuringValues()
{ {
return StockTakingItemId > 0 && base.IsValidSafeMeasuringValues(); return StockTakingItemId > 0 && TrayQuantity >= 0 && TareWeight >= 0 && PalletWeight >= 0 && NetWeight >= 0 && GrossWeight >= 0;
} }
/// <summary>
/// "Szigorúbb" mint az IsValidSafeMeasuringValues()
/// </summary>
/// <param name="isMeasurable"></param>
/// <returns></returns>
public override bool IsValidMeasuringValues(bool isMeasurable) 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));
} }
} }

View File

@ -5,7 +5,7 @@ namespace FruitBank.Common.Interfaces;
public interface IStockSignalREndpointCommon public interface IStockSignalREndpointCommon
{ {
public Task<List<StockTaking>?> GetStockTakings(); public Task<List<StockTaking>?> GetStockTakings(bool loadRelations);
public Task<List<StockTaking>?> GetStockTakingsByProductId(int productId); public Task<List<StockTaking>?> GetStockTakingsByProductId(int productId);
public Task<StockTaking?> AddStockTaking(StockTaking stockTaking); public Task<StockTaking?> AddStockTaking(StockTaking stockTaking);
public Task<StockTaking?> UpdateStockTaking(StockTaking stockTaking); public Task<StockTaking?> UpdateStockTaking(StockTaking stockTaking);

View File

@ -91,9 +91,14 @@ public class SignalRTags : AcSignalRTags
public const int UpdateGenericAttributeDto = 169; public const int UpdateGenericAttributeDto = 169;
public const int GetStockTakings = 170; public const int GetStockTakings = 170;
public const int AddStockTaking = 171;
public const int UpdateStockTaking = 172;
public const int GetStockTakingItems = 173; public const int GetStockTakingItems = 173;
public const int GetStockTakingItemsById = 174; 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 AuthenticateUser = 195;
public const int RefreshToken = 200; public const int RefreshToken = 200;

View File

@ -14,21 +14,33 @@
@inject FruitBankSignalRClient FruitBankSignalRClient @inject FruitBankSignalRClient FruitBankSignalRClient
<GridStockTakingItemBase @ref="Grid" AutoSaveLayoutName="GridStockTakingItem" SignalRClient="FruitBankSignalRClient" Logger="_logger" <GridStockTakingItemBase @ref="Grid" AutoSaveLayoutName="GridStockTakingItem" SignalRClient="FruitBankSignalRClient" Logger="_logger"
CssClass="@GridCss" ValidationEnabled="false" CssClass="@GridCss" ValidationEnabled="false" FocusedRowChanged="Grid_FocusedRowChanged">
FocusedRowChanged="Grid_FocusedRowChanged">
<Columns> <Columns>
<DxGridDataColumn FieldName="Id" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" ReadOnly="true" /> <DxGridDataColumn FieldName="Id" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" ReadOnly="true" />
<DxGridDataColumn FieldName="StockTaking.StartDateTime" /> <DxGridDataColumn FieldName="@nameof(StockTakingItem.StockTakingId)" TextAlignment="GridTextAlignment.Left" Caption="Leltár időpontja">
<CellDisplayTemplate>
<span>@(((StockTakingItem)context.DataItem)?.StockTaking?.StartDateTime.ToString("g") ?? "")</span>
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="Product.Name" /> <DxGridDataColumn FieldName="Product.Name" />
<DxGridDataColumn FieldName="IsMeasured" />
<DxGridDataColumn FieldName="OriginalStockQuantity" /> <DxGridDataColumn FieldName="OriginalStockQuantity" />
<DxGridDataColumn FieldName="@nameof(StockTakingItem.InProcessOrdersQuantity)" />
<DxGridDataColumn FieldName="@nameof(StockTakingItem.TotalOriginalQuantity)" />
<DxGridDataColumn FieldName="MeasuredStockQuantity" /> <DxGridDataColumn FieldName="MeasuredStockQuantity" />
<DxGridDataColumn FieldName="OriginalNetWeight" /> <DxGridDataColumn FieldName="OriginalNetWeight" />
<DxGridDataColumn FieldName="MeasuredNetWeight" /> <DxGridDataColumn FieldName="MeasuredNetWeight" />
<DxGridDataColumn FieldName="Created" ReadOnly="true" /> <DxGridDataColumn FieldName="@nameof(StockTakingItem.QuantityDiff)" />
<DxGridDataColumn FieldName="Modified" ReadOnly="true" /> <DxGridDataColumn FieldName="@nameof(StockTakingItem.NetWeightDiff)" />
<DxGridDataColumn FieldName="@nameof(StockTakingItem.IsMeasurable)" />
<DxGridDataColumn FieldName="@nameof(StockTakingItem.IsMeasured)" />
<DxGridDataColumn FieldName="@nameof(StockTakingItem.IsInvalid)" />
<DxGridDataColumn FieldName="Created" ReadOnly="true" Visible="false" DisplayFormat="g" />
<DxGridDataColumn FieldName="Modified" ReadOnly="true" DisplayFormat="g" />
<DxGridCommandColumn Visible="!IsMasterGrid" Width="120"></DxGridCommandColumn> <DxGridCommandColumn Visible="!IsMasterGrid" Width="120"></DxGridCommandColumn>
</Columns> </Columns>
<ToolbarTemplate> <ToolbarTemplate>
@ -40,6 +52,7 @@
</GridStockTakingItemBase> </GridStockTakingItemBase>
@code { @code {
//[Inject] public required ObjectLock ObjectLock { get; set; } //[Inject] public required ObjectLock ObjectLock { get; set; }
[Inject] public required DatabaseClient Database { get; set; } [Inject] public required DatabaseClient Database { get; set; }
@ -70,7 +83,7 @@
if (Grid == null) return; if (Grid == null) return;
//using (await ObjectLock.GetSemaphore<StockTakingItem>().UseWaitAsync()) //using (await ObjectLock.GetSemaphore<StockTakingItem>().UseWaitAsync())
//if (forceReload) await Grid.ReloadDataSourceAsync(); //if (forceReload) await Grid.ReloadDataSourceAsync();
if (forceReload) Grid.Reload(); if (forceReload) Grid.Reload();
} }
@ -85,5 +98,24 @@
FocusedRowVisibleIndex = args.VisibleIndex; FocusedRowVisibleIndex = args.VisibleIndex;
EditItemsEnabled = true; 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");
// }
} }

View File

@ -8,6 +8,7 @@
@using FruitBankHybrid.Shared.Extensions @using FruitBankHybrid.Shared.Extensions
@using FruitBankHybrid.Shared.Services @using FruitBankHybrid.Shared.Services
@using FruitBankHybrid.Shared.Services.SignalRs @using FruitBankHybrid.Shared.Services.SignalRs
@typeparam TPalletItem where TPalletItem : class, IMeasuringItemPalletBase @typeparam TPalletItem where TPalletItem : class, IMeasuringItemPalletBase
<DxFormLayout Context="ctxFromLayoutPallet" Data="@PalletItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100 measuring-form-layout" <DxFormLayout Context="ctxFromLayoutPallet" Data="@PalletItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100 measuring-form-layout"

View File

@ -1,8 +1,13 @@
@using AyCode.Utils.Extensions @using AyCode.Core.Extensions
@using AyCode.Utils.Extensions
@using FruitBank.Common.Dtos @using FruitBank.Common.Dtos
@using FruitBank.Common.Entities @using FruitBank.Common.Entities
@using FruitBank.Common.Helpers
@using FruitBank.Common.Models @using FruitBank.Common.Models
@using FruitBank.Common.SignalRs
@using FruitBankHybrid.Shared.Databases @using FruitBankHybrid.Shared.Databases
@using FruitBankHybrid.Shared.Extensions
@using FruitBankHybrid.Shared.Services
@using FruitBankHybrid.Shared.Services.SignalRs @using FruitBankHybrid.Shared.Services.SignalRs
@using Mango.Nop.Core.Entities @using Mango.Nop.Core.Entities
@ -16,7 +21,7 @@
Context="ctxProduct" Context="ctxProduct"
InputId="cbProduct" InputId="cbProduct"
Value="@SelectedStockTaking" Value="@SelectedStockTaking"
ValueChanged="@((StockTaking stockTaking) => ValueChanged(stockTaking))"> ValueChanged="@(async (StockTaking stockTaking) => await StockTakingComboValueChanged(stockTaking))">
</DxComboBox> </DxComboBox>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="4"> <DxFormLayoutItem ColSpanMd="4">
@ -31,21 +36,70 @@
</DxFormLayoutItem> </DxFormLayoutItem>
@* TextFieldName="StockTakingItem.Product.Name" *@ @* TextFieldName="StockTakingItem.Product.Name" *@
<DxFormLayoutItem ColSpanMd="1"> <DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Új" Enabled="@(_stockTakings.All(x => x.IsClosed))" Click="() => Callback()"></DxButton> <DxButton Text="Új" Enabled="@(_stockTakings.All(x => x.IsClosed))" Click="() => NewStockTakingClick()"></DxButton>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1"> <DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Módosít" Enabled="@(SelectedStockTaking?.IsClosed ?? false)" Click="() => Callback2()"></DxButton> <DxButton Text="Módosít" Enabled="@(SelectedStockTaking?.IsClosed ?? false)" Click="() => UpdateStockTakingClick()"></DxButton>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1"> <DxFormLayoutItem ColSpanMd="1">
<DxButton Text="Lezárás" Enabled="@(SelectedStockTaking?.StockTakingItems?.Where(x=>x.IsRequiredForMeasuring).All(x=>x.IsMeasured) ?? false)" Click="() => Callback3()"></DxButton> <DxButton Text="Lezárás" Enabled="@(SelectedStockTaking?.StockTakingItems?.Where(x => x.IsRequiredForMeasuring).All(x => x.IsMeasured) ?? false)"
Click="() => StockTakingCloseClick()"></DxButton>
</DxFormLayoutItem> </DxFormLayoutItem>
</DxFormLayout> </DxFormLayout>
<div style="margin-top: 50px;">
@if (SelectedStockTakingItem is { ProductId: > 0 })
{
<h3 style="margin-bottom: 30px;" class="@(SelectedStockTakingItem.IsMeasured && SelectedStockTakingItem.StockTakingItemPallets!.All(x => x.IsMeasuredAndValid(SelectedStockTakingItem.IsMeasurable)) ? "text-success" : "")">
#@(SelectedStockTakingItem.ProductId). @(SelectedStockTakingItem.Product!.Name)
</h3>
<div>
@{
var a = $"Várható rekesz: {SelectedStockTakingItem.TotalOriginalQuantity} ({SelectedStockTakingItem.OriginalStockQuantity} + {SelectedStockTakingItem.InProcessOrdersQuantity}), Várható net.súly: {SelectedStockTakingItem.OriginalNetWeight} kg.";
<span>@a</span>
}
</div>
<DxFormLayout Data="@SelectedStockTakingItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100">
<DxFormLayoutItem Context="ctxShippingItemFromLayoutItem" ColSpanMd="12">
@for (var index = 0; index < (SelectedStockTakingItem?.StockTakingItemPallets?.Count ?? 0); index++)
{
var localI = index + 1;
var currentShippingItemPallet = SelectedStockTakingItem!.StockTakingItemPallets![index];
<PalletItemComponent IsMeasurable="@SelectedStockTakingItem!.IsMeasurable"
MeasuringIndex="@localI"
PalletItem="@currentShippingItemPallet"
ProductId="@SelectedStockTakingItem.Product!.Id"
AddOrUpdateSignalRTag="SignalRTags.AddOrUpdateMeasuredStockTakingItemPallet"
OnPalletItemSaved="pallet => OnStockTakingItemPalletSaved(pallet)"
OnPalletItemValueChanged="pallet => OnStockTakingItemPalletValueChanged(pallet, SelectedStockTakingItem)">
</PalletItemComponent>
}
</DxFormLayoutItem>
@* <DxFormLayoutItem Context="vfdfgfd" ColSpanMd="12" BeginRow="true">
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem ColSpanMd="1" BeginRow="false"><strong>TOTAL:</strong></DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="2" BeginRow="false" Visible="@(SelectedStockTakingItem.IsMeasurable)" />
<DxFormLayoutItem ColSpanMd="2" BeginRow="false" Visible="@(SelectedStockTakingItem.IsMeasurable)" />
<DxFormLayoutItem ColSpanMd="2" BeginRow="false"><strong>Rekesz: @(SelectedStockTakingItem.MeasuredStockQuantity) db</strong></DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="2" BeginRow="false" Visible="@(SelectedStockTakingItem.IsMeasurable)"><strong>Br: @(SelectedStockTakingItem.MeasuredGrossWeight) kg</strong></DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1" BeginRow="false" Visible="@(SelectedStockTakingItem.IsMeasurable)"><strong>Net: @(SelectedStockTakingItem.MeasuredNetWeight) kg</strong></DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="1" BeginRow="false" />
</DxFormLayout>
</DxFormLayoutItem>
*@
</DxFormLayout>
}
</div>
@code @code
{ {
[Inject] public required DatabaseClient Database { get; set; } [Inject] public required DatabaseClient Database { get; set; }
[Inject] public required LoggedInModel LoggedInModel { get; set; } [Inject] public required LoggedInModel LoggedInModel { get; set; }
[Inject] public required IDialogService DialogService { get; set; } = null!;
[Inject] public required FruitBankSignalRClient FruitBankSignalRClient { get; set; } [Inject] public required FruitBankSignalRClient FruitBankSignalRClient { get; set; }
List<StockTaking> _stockTakings { get; set; } = []; List<StockTaking> _stockTakings { get; set; } = [];
@ -63,26 +117,26 @@
{ {
LoadingPanelVisibility.Visible = true; LoadingPanelVisibility.Visible = true;
_stockTakings = await FruitBankSignalRClient.GetStockTakings() ?? []; _stockTakings = await FruitBankSignalRClient.GetStockTakings(false) ?? [];
ValueChanged(_stockTakings.FirstOrDefault()); await StockTakingComboValueChanged(_stockTakings.FirstOrDefault());
LoadingPanelVisibility.Visible = false; LoadingPanelVisibility.Visible = false;
} }
private async Task Callback() private async Task NewStockTakingClick()
{ {
var stockTaking = new StockTaking(); var stockTaking = new StockTaking();
stockTaking.StartDateTime = DateTime.Now; stockTaking.StartDateTime = DateTime.Now;
stockTaking.Creator = LoggedInModel.CustomerDto!.Id; stockTaking.Creator = LoggedInModel.CustomerDto!.Id;
var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); var resultStockTakings = await FruitBankSignalRClient.AddStockTaking(stockTaking);
if (resultStockTaking == null) return; if (resultStockTakings == null) return;
_stockTakings.Add(resultStockTaking); _stockTakings.UpdateCollection(resultStockTakings, false);
StateHasChanged(); await StockTakingComboValueChanged(_stockTakings.FirstOrDefault(x => x.Id == stockTaking.Id));
} }
private async Task Callback2() private async Task UpdateStockTakingClick()
{ {
// var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); // var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking);
// if (resultStockTaking == null) return; // if (resultStockTaking == null) return;
@ -91,7 +145,7 @@
StateHasChanged(); StateHasChanged();
} }
private async Task Callback3() private async Task StockTakingCloseClick()
{ {
// var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking); // var resultStockTaking = await FruitBankSignalRClient.AddStockTaking(stockTaking);
// if (resultStockTaking == null) return; // if (resultStockTaking == null) return;
@ -100,11 +154,58 @@
StateHasChanged(); StateHasChanged();
} }
private void ValueChanged(StockTaking? newValue) private async Task StockTakingComboValueChanged(StockTaking? newValue)
{ {
SelectedStockTaking = 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(); 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);
}
} }

View File

@ -65,7 +65,7 @@ public class MeasurementService(IEnumerable<IAcLogWriterClientBase> logWriters)
public static ShippingItemPallet CreateNewShippingItemPallet(ShippingItem shippingItem, CustomerDto? customerDto) public static ShippingItemPallet CreateNewShippingItemPallet(ShippingItem shippingItem, CustomerDto? customerDto)
{ {
var shippingItemPallet = CreatePalletItem<ShippingItemPallet>(shippingItem.Id, shippingItem.ProductDto?.Tare, shippingItem.IsMeasurable, customerDto); var shippingItemPallet = CreatePalletItemBase<ShippingItemPallet>(shippingItem.Id, shippingItem.ProductDto?.Tare, shippingItem.IsMeasurable, customerDto);
shippingItemPallet.ShippingItem = shippingItem; shippingItemPallet.ShippingItem = shippingItem;
shippingItemPallet.PalletWeight = shippingItem.IsMeasurable ? shippingItem.Pallet?.Weight ?? 0 : 0; shippingItemPallet.PalletWeight = shippingItem.IsMeasurable ? shippingItem.Pallet?.Weight ?? 0 : 0;
@ -75,13 +75,24 @@ public class MeasurementService(IEnumerable<IAcLogWriterClientBase> logWriters)
public static OrderItemPallet CreateNewOrderItemPallet(OrderItemDto orderItemDto, CustomerDto? customerDto) public static OrderItemPallet CreateNewOrderItemPallet(OrderItemDto orderItemDto, CustomerDto? customerDto)
{ {
var orderItemPallet = CreatePalletItem<OrderItemPallet>(orderItemDto.Id, orderItemDto.ProductDto?.Tare, orderItemDto.IsMeasurable, customerDto); var orderItemPallet = CreatePalletItemBase<OrderItemPallet>(orderItemDto.Id, orderItemDto.ProductDto?.Tare, orderItemDto.IsMeasurable, customerDto);
orderItemPallet.OrderItemDto = orderItemDto; orderItemPallet.OrderItemDto = orderItemDto;
return orderItemPallet; return orderItemPallet;
} }
private static TPalletItem CreatePalletItem<TPalletItem>(int foreignKey, double? tare, bool isMeasurable, CustomerDto? customerDto) where TPalletItem : MeasuringItemPalletBase public static StockTakingItemPallet CreateNewStockTakingItemPallet(StockTakingItem stockTakingItem, CustomerDto? customerDto)
{
var stockTakingItemPallet = CreatePalletItemBase<StockTakingItemPallet>(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<TPalletItem>(int foreignKey, double? tare, bool isMeasurable, CustomerDto? customerDto) where TPalletItem : MeasuringItemPalletBase
{ {
var palletItem = Activator.CreateInstance<TPalletItem>(); var palletItem = Activator.CreateInstance<TPalletItem>();

View File

@ -281,7 +281,7 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
} }
public Task<List<StockTaking>?> GetStockTakings() => GetAllAsync<List<StockTaking>>(SignalRTags.GetStockTakings); public Task<List<StockTaking>?> GetStockTakings(bool loadRelations) => GetAllAsync<List<StockTaking>>(SignalRTags.GetStockTakings, [loadRelations]);
public async Task<List<StockTaking>?> GetStockTakingsByProductId(int productId) public async Task<List<StockTaking>?> GetStockTakingsByProductId(int productId)
{ {
@ -290,25 +290,18 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
public Task<StockTaking?> AddStockTaking(StockTaking stockTaking) => PostDataAsync(SignalRTags.AddStockTaking, stockTaking); public Task<StockTaking?> AddStockTaking(StockTaking stockTaking) => PostDataAsync(SignalRTags.AddStockTaking, stockTaking);
public async Task<StockTaking?> UpdateStockTaking(StockTaking stockTaking) public Task<StockTaking?> UpdateStockTaking(StockTaking stockTaking) => PostDataAsync(SignalRTags.UpdateStockTaking, stockTaking);
{
throw new NotImplementedException();
}
public Task<List<StockTakingItem>?> GetStockTakingItems() => GetAllAsync<List<StockTakingItem>>(SignalRTags.GetStockTakingItems); public Task<List<StockTakingItem>?> GetStockTakingItems() => GetAllAsync<List<StockTakingItem>>(SignalRTags.GetStockTakingItems);
public Task<StockTakingItem?> GetStockTakingItemsById(int stockTakingItemId) public Task<StockTakingItem?> GetStockTakingItemsById(int stockTakingItemId)
=> GetByIdAsync<StockTakingItem>(SignalRTags.GetStockTakingItemsById, [stockTakingItemId]); => GetByIdAsync<StockTakingItem>(SignalRTags.GetStockTakingItemsById, [stockTakingItemId]);
public async Task<List<StockTakingItem>?> GetStockTakingItemsByProductId(int productId) public Task<List<StockTakingItem>?> GetStockTakingItemsByProductId(int productId)
{ => GetAllAsync<List<StockTakingItem>>(SignalRTags.GetStockTakingItemsByProductId, [productId]);
throw new NotImplementedException();
}
public async Task<List<StockTakingItem>?> GetStockTakingItemsByStockTakingId(int stockTakingId) public Task<List<StockTakingItem>?> GetStockTakingItemsByStockTakingId(int stockTakingId)
{ => GetAllAsync<List<StockTakingItem>>(SignalRTags.GetStockTakingItemsByStockTakingId, [stockTakingId]);
throw new NotImplementedException();
}
public async Task<StockTakingItem?> AddStockTakingItem(StockTakingItem stockTakingItem) public async Task<StockTakingItem?> AddStockTakingItem(StockTakingItem stockTakingItem)
{ {