Merge branch '4.80' of https://git.aycode.com/Adam/Mango.Nop.Plugins into 4.80
This commit is contained in:
commit
b5ef6caa39
|
|
@ -0,0 +1,157 @@
|
||||||
|
using AyCode.Core.Loggers;
|
||||||
|
using AyCode.Services.SignalRs;
|
||||||
|
using DevExpress.Data.Helpers;
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using FruitBank.Common.Enums;
|
||||||
|
using FruitBank.Common.Server.Interfaces;
|
||||||
|
using FruitBank.Common.Server.Services.SignalRs;
|
||||||
|
using FruitBank.Common.SignalRs;
|
||||||
|
using Mango.Nop.Core.Loggers;
|
||||||
|
using Nop.Core;
|
||||||
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
|
||||||
|
|
||||||
|
public class StockSignalREndpointServer(StockTakingDbContext ctx, SignalRSendToClientService sendToClient, IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable<IAcLogWriterBase> logWriters)
|
||||||
|
: IStockSignalREndpointServer
|
||||||
|
{
|
||||||
|
private const int LastStockTakingDays = 15;
|
||||||
|
private readonly ILogger _logger = new Logger<StockSignalREndpointServer>(logWriters.ToArray());
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockTakings)]
|
||||||
|
public async Task<List<StockTaking>> GetStockTakings(bool loadRelations)
|
||||||
|
{
|
||||||
|
_logger.Debug($"GetStockTakings invoke. loadRelations: {loadRelations}");
|
||||||
|
return await ctx.StockTakings.GetAll(loadRelations).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<StockTaking>> GetStockTakingsByProductId(int productId)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.CloseStockTaking)]
|
||||||
|
public async Task<StockTaking> CloseStockTaking(int stockTakingId)
|
||||||
|
{
|
||||||
|
var result = await ctx.TransactionSafeAsync(async _ =>
|
||||||
|
{
|
||||||
|
await ctx.CloseStockTaking(stockTakingId);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result) return await ctx.StockTakings.GetByIdAsync(stockTakingId, false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.AddStockTaking)]
|
||||||
|
public async Task<StockTaking> AddStockTaking(StockTaking stockTaking)
|
||||||
|
{
|
||||||
|
var result = await ctx.TransactionSafeAsync(async _ =>
|
||||||
|
{
|
||||||
|
stockTaking.IsClosed = false;
|
||||||
|
stockTaking.StartDateTime = DateTime.Now;
|
||||||
|
|
||||||
|
await ctx.StockTakings.InsertAsync(stockTaking);
|
||||||
|
|
||||||
|
var productDtos = await ctx.ProductDtos.GetAll(true).ToListAsync();
|
||||||
|
|
||||||
|
var orderItemDtos = (await ctx.OrderItemDtos.GetAllByProductIds(productDtos.Select(p => p.Id))
|
||||||
|
.Where(oi => oi.OrderDto.OrderStatusId != (int)OrderStatus.Complete).ToArrayAsync())
|
||||||
|
.Where(x => x.MeasuringStatus == MeasuringStatus.NotStarted).ToLookup(k => k.ProductId, v => v);
|
||||||
|
|
||||||
|
foreach (var productDto in productDtos)
|
||||||
|
{
|
||||||
|
var stockTakingItem = new StockTakingItem
|
||||||
|
{
|
||||||
|
StockTakingId = stockTaking.Id,
|
||||||
|
ProductId = productDto.Id,
|
||||||
|
IsMeasurable = productDto.IsMeasurable,
|
||||||
|
OriginalStockQuantity = productDto.StockQuantity,
|
||||||
|
InProcessOrdersQuantity = orderItemDtos[productDto.Id].Sum(x => x.Quantity),
|
||||||
|
//A NetWeight-et nem növeljük meg, mert az nem vonódik le automatikusan a rendelés létrehozásakor! - J.
|
||||||
|
OriginalNetWeight = productDto.NetWeight //double.Round(productDto.NetWeight + orderItemDtos[productDto.Id].Sum(x => x.NetWeight), 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
await ctx.StockTakingItems.InsertAsync(stockTakingItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result) return await ctx.StockTakings.GetByIdAsync(stockTaking.Id, false);
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.UpdateStockTaking)]
|
||||||
|
public async Task<StockTaking> UpdateStockTaking(StockTaking stockTaking)
|
||||||
|
{
|
||||||
|
if(stockTaking == null) return null;
|
||||||
|
|
||||||
|
await ctx.StockTakings.UpdateAsync(stockTaking);
|
||||||
|
return await ctx.StockTakings.GetByIdAsync(stockTaking.Id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockTakingItems)]
|
||||||
|
public async Task<List<StockTakingItem>> GetStockTakingItems()
|
||||||
|
{
|
||||||
|
return await ctx.StockTakingItems.GetAll(true).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockTakingItemsById)]
|
||||||
|
public async Task<StockTakingItem> GetStockTakingItemsById(int stockTakingItemId)
|
||||||
|
{
|
||||||
|
var result = await ctx.StockTakingItems.GetByIdAsync(stockTakingItemId, true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockTakingItemsByProductId)]
|
||||||
|
public async Task<List<StockTakingItem>> GetStockTakingItemsByProductId(int productId)
|
||||||
|
{
|
||||||
|
return await ctx.StockTakingItems.GetAllByProductId(productId, true).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockTakingItemsByStockTakingId)]
|
||||||
|
public async Task<List<StockTakingItem>> GetStockTakingItemsByStockTakingId(int stockTakingId)
|
||||||
|
{
|
||||||
|
return await ctx.StockTakingItems.GetAllByStockTakingId(stockTakingId, true).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItem> AddStockTakingItem(StockTakingItem stockTakingItem)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItem> UpdateStockTakingItem(StockTakingItem stockTakingItem)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<StockTakingItemPallet>> GetStockTakingItemPallets()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<StockTakingItemPallet>> GetStockTakingItemPalletsByProductId(int productId)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItemPallet> AddStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
return await ctx.AddStockTakingItemPallet(stockTakingItemPallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItemPallet> UpdateStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
return await ctx.UpdateStockTakingItemPallet(stockTakingItemPallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.AddOrUpdateMeasuredStockTakingItemPallet)]
|
||||||
|
public async Task<StockTakingItemPallet> AddOrUpdateMeasuredStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
return await ctx.AddOrUpdateMeasuredStockTakingItemPallet(stockTakingItemPallet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -70,20 +70,30 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id);
|
return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
|
||||||
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
|
||||||
|
{
|
||||||
|
_logger.Detail($"GetStockQuantityHistoryDtos invoked; lastDaysCount: {LastShippingDays}");
|
||||||
|
|
||||||
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
||||||
|
return await ctx.StockQuantityHistoryDtos.GetAll(true).Where(sqh => sqh.CreatedOnUtc >= fromDateUtc).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
|
||||||
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
|
||||||
|
{
|
||||||
|
_logger.Detail($"GetStockQuantityHistoryDtosByProductId invoked; productId: {productId}; lastDaysCount: {LastShippingDays}");
|
||||||
|
|
||||||
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
||||||
|
return await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).Where(sqh => sqh.CreatedOnUtc >= fromDateUtc).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetMeasuringModels)]
|
[SignalR(SignalRTags.GetMeasuringModels)]
|
||||||
public Task<List<MeasuringModel>> GetMeasuringModels()
|
public Task<List<MeasuringModel>> GetMeasuringModels()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("GetMeasuringModels");
|
throw new NotImplementedException("GetMeasuringModels");
|
||||||
}
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
|
|
||||||
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
|
|
||||||
=> await ctx.StockQuantityHistoryDtos.GetAll(true).ToListAsync();
|
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
|
|
||||||
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
|
|
||||||
=> await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).ToListAsync();
|
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetPartners)]
|
[SignalR(SignalRTags.GetPartners)]
|
||||||
public async Task<List<Partner>> GetPartners()
|
public async Task<List<Partner>> GetPartners()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using FruitBank.Common.Dtos;
|
||||||
using FruitBank.Common.Entities;
|
using FruitBank.Common.Entities;
|
||||||
using FruitBank.Common.Interfaces;
|
using FruitBank.Common.Interfaces;
|
||||||
using FruitBank.Common.Models;
|
using FruitBank.Common.Models;
|
||||||
|
using Mango.Nop.Core.Dtos;
|
||||||
using Mango.Nop.Core.Entities;
|
using Mango.Nop.Core.Entities;
|
||||||
using Mango.Nop.Core.Extensions;
|
using Mango.Nop.Core.Extensions;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
|
|
@ -25,6 +26,7 @@ using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
using Nop.Services.Catalog;
|
using Nop.Services.Catalog;
|
||||||
using Nop.Services.Security;
|
using Nop.Services.Security;
|
||||||
using WebMarkupMin.Core.Loggers;
|
using WebMarkupMin.Core.Loggers;
|
||||||
|
using static Nop.Services.Security.StandardPermission;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
|
@ -101,7 +103,6 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
|
|
||||||
Files = filesDbTable;
|
Files = filesDbTable;
|
||||||
Partners = partnerDbTable;
|
Partners = partnerDbTable;
|
||||||
Products = productRepository;
|
|
||||||
|
|
||||||
ProductDtos = productDtoDbTable;
|
ProductDtos = productDtoDbTable;
|
||||||
|
|
||||||
|
|
@ -766,4 +767,5 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
await CustomerAddressMappings.InsertAsync(customerAddressMapping);
|
await CustomerAddressMappings.InsertAsync(customerAddressMapping);
|
||||||
return customerAddressMapping;
|
return customerAddressMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Data.Interfaces;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
|
||||||
|
public interface IStockTakingDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<StockTaking>
|
||||||
|
{
|
||||||
|
public TDbTable StockTakings { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Data.Interfaces;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
|
||||||
|
public interface IStockTakingItemDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<StockTakingItem>
|
||||||
|
{
|
||||||
|
public TDbTable StockTakingItems { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Data.Interfaces;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
|
||||||
|
public interface IStockTakingItemPalletDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<StockTakingItemPallet>
|
||||||
|
{
|
||||||
|
public TDbTable StockTakingItemPallets { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
using FruitBank.Common.Dtos;
|
using FruitBank.Common.Dtos;
|
||||||
using FruitBank.Common.Entities;
|
using FruitBank.Common.Entities;
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
|
using Mango.Nop.Core.Loggers;
|
||||||
using Mango.Nop.Data.Repositories;
|
using Mango.Nop.Data.Repositories;
|
||||||
using Nop.Core.Caching;
|
using Nop.Core.Caching;
|
||||||
using Nop.Core.Configuration;
|
using Nop.Core.Configuration;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Domain.Payments;
|
||||||
using Nop.Core.Events;
|
using Nop.Core.Events;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Mango.Nop.Core.Loggers;
|
using System.Linq;
|
||||||
using Nop.Core.Domain.Payments;
|
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
|
@ -47,5 +48,8 @@ public class OrderDtoDbTable : MgDtoDbTableBase<OrderDto, Order>
|
||||||
|
|
||||||
public IQueryable<OrderDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId));
|
public IQueryable<OrderDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId));
|
||||||
|
|
||||||
|
public IQueryable<OrderDto> GetAllByProductIds(IEnumerable<int> productIds, bool loadRelations = true)
|
||||||
|
=> GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => productIds.Contains(oi.ProductId)));
|
||||||
|
|
||||||
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id));
|
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,15 +24,19 @@ public class OrderItemDtoDbTable : MgDtoDbTableBase<OrderItemDto, OrderItem>
|
||||||
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.Customer)
|
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.Customer)
|
||||||
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.OrderNotes)
|
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.OrderNotes)
|
||||||
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.GenericAttributes)
|
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.GenericAttributes)
|
||||||
.LoadWith(oi => oi.OrderItemPallets).ThenLoad(oip => oip.OrderItemDto).ThenLoad(oi => oi.GenericAttributes)
|
.LoadWith(oi => oi.OrderItemPallets)//.ThenLoad(oip => oip.OrderItemDto).ThenLoad(oi => oi.GenericAttributes)
|
||||||
.LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes);
|
.LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<OrderItemDto> GetByIdAsync(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(oi => oi.Id == orderItemId).FirstOrDefaultAsync(null);
|
public Task<OrderItemDto> GetByIdAsync(int orderItemId, bool loadRelations) => GetAll(loadRelations).Where(oi => oi.Id == orderItemId).FirstOrDefaultAsync(null);
|
||||||
|
|
||||||
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId, bool loadRelations = true) => GetAll(loadRelations).Where(oi => oi.OrderId == orderId);
|
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId, bool loadRelations = true) => GetAll(loadRelations).Where(oi => oi.OrderId == orderId);
|
||||||
|
|
||||||
public IQueryable<OrderItemDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(oi => oi.ProductId == productId);
|
public IQueryable<OrderItemDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(oi => oi.ProductId == productId);
|
||||||
|
|
||||||
|
public IQueryable<OrderItemDto> GetAllByProductIds(IEnumerable<int> productIds, bool loadRelations = true)
|
||||||
|
=> GetAll(loadRelations).Where(oi => productIds.Contains(oi.ProductId));
|
||||||
|
|
||||||
public IQueryable<OrderItemDto> GetAllByIds(IEnumerable<int> orderItemIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderItemIds.Contains(oi.Id));
|
public IQueryable<OrderItemDto> GetAllByIds(IEnumerable<int> orderItemIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderItemIds.Contains(oi.Id));
|
||||||
public IQueryable<OrderItemDto> GetAllByOrderIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderIds.Contains(oi.OrderId));
|
public IQueryable<OrderItemDto> GetAllByOrderIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(oi => orderIds.Contains(oi.OrderId));
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
#nullable enable
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AyCode.Core.Loggers;
|
||||||
|
using FruitBank.Common.Dtos;
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Core.Entities;
|
||||||
|
using Mango.Nop.Core.Loggers;
|
||||||
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Nop.Core;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Domain.Catalog;
|
||||||
|
using Nop.Core.Domain.Common;
|
||||||
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
|
using Nop.Services.Catalog;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class StockTakingDbContext : MgDbContextBase,
|
||||||
|
IStockTakingDbSet<StockTakingDbTable>,
|
||||||
|
IOrderItemDtoDbSet<OrderItemDtoDbTable>,
|
||||||
|
IStockTakingItemDbSet<StockTakingItemDbTable>,
|
||||||
|
IStockTakingItemPalletDbSet<StockTakingItemPalletDbTable>
|
||||||
|
{
|
||||||
|
private FruitBankDbContext _fruitBankDbContext;
|
||||||
|
public ProductDtoDbTable ProductDtos { get; set; }
|
||||||
|
public OrderItemDtoDbTable OrderItemDtos { get; set; }
|
||||||
|
|
||||||
|
public StockTakingDbTable StockTakings { get; set; }
|
||||||
|
public StockTakingItemDbTable StockTakingItems { get; set; }
|
||||||
|
public StockTakingItemPalletDbTable StockTakingItemPallets { get; set; }
|
||||||
|
public StockQuantityHistoryDtoDbTable StockQuantityHistoryDtos { get; set; }
|
||||||
|
|
||||||
|
public IRepository<GenericAttribute> GenericAttributes { get; set; }
|
||||||
|
public IRepository<StockQuantityHistory> StockQuantityHistories { get; set; }
|
||||||
|
public IRepository<StockQuantityHistoryExt> StockQuantityHistoriesExt { get; set; }
|
||||||
|
|
||||||
|
private readonly IStoreContext _storeContext;
|
||||||
|
private readonly IProductService _productService;
|
||||||
|
private readonly IStaticCacheManager _staticCacheManager;
|
||||||
|
protected readonly IEventPublisher _eventPublisher;
|
||||||
|
|
||||||
|
public StockTakingDbContext(INopDataProvider dataProvider, ILockService lockService, IStoreContext storeContext, FruitBankDbContext fruitBankDbContext,
|
||||||
|
ProductDtoDbTable productDtoDbTable,
|
||||||
|
OrderItemDtoDbTable orderItemDtoDbTable,
|
||||||
|
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtos,
|
||||||
|
StockTakingDbTable stockTakingDbTable,
|
||||||
|
StockTakingItemDbTable stockTakingItemDbTable,
|
||||||
|
StockTakingItemPalletDbTable stockTakingItemPalletDbTable,
|
||||||
|
IProductService productService, IStaticCacheManager staticCacheManager,
|
||||||
|
IRepository<Order> orderRepository,
|
||||||
|
IRepository<OrderItem> orderItemRepository,
|
||||||
|
IRepository<Product> productRepository,
|
||||||
|
IRepository<GenericAttribute> genericAttributes,
|
||||||
|
IRepository<StockQuantityHistory> stockQuantityHistories,
|
||||||
|
IRepository<StockQuantityHistoryExt> stockQuantityHistoriesExt,
|
||||||
|
IEventPublisher eventPublisher,
|
||||||
|
IEnumerable<IAcLogWriterBase> logWriters) : base(productRepository, orderRepository, orderItemRepository, dataProvider, lockService, new Logger<StockTakingDbContext>(logWriters.ToArray()))
|
||||||
|
{
|
||||||
|
_eventPublisher = eventPublisher;
|
||||||
|
_storeContext = storeContext;
|
||||||
|
_productService = productService;
|
||||||
|
_staticCacheManager = staticCacheManager;
|
||||||
|
|
||||||
|
_fruitBankDbContext = fruitBankDbContext;
|
||||||
|
|
||||||
|
ProductDtos = productDtoDbTable;
|
||||||
|
OrderItemDtos = orderItemDtoDbTable;
|
||||||
|
|
||||||
|
GenericAttributes = genericAttributes;
|
||||||
|
|
||||||
|
StockQuantityHistories = stockQuantityHistories;
|
||||||
|
StockQuantityHistoriesExt = stockQuantityHistoriesExt;
|
||||||
|
StockQuantityHistoryDtos = stockQuantityHistoryDtos;
|
||||||
|
|
||||||
|
StockTakings = stockTakingDbTable;
|
||||||
|
StockTakingItems = stockTakingItemDbTable;
|
||||||
|
StockTakingItemPallets = stockTakingItemPalletDbTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CloseStockTaking(int stockTakingId)
|
||||||
|
{
|
||||||
|
var stockTaking = await StockTakings.GetByIdAsync(stockTakingId, true);
|
||||||
|
|
||||||
|
if (!stockTaking.IsReadyForClose()) throw new Exception($"Not all IsRequiredForMeasuring items are IsMeasured! IsReadyForClose: false;");
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
foreach (var stockTakingItem in stockTaking.StockTakingItems!.Where(stockTakingItem => stockTakingItem is { IsMeasured: true, IsInvalid: false }))
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
|
||||||
|
//await _fruitBankDbContext.UpdateStockQuantityAndWeightAsync(stockTakingItem.Product!, stockTakingItem.QuantityDiff,
|
||||||
|
// $"Leltár által módosítva! stockTakingId: #{stockTaking.Id}, stockTakingItemId: #{stockTakingItem.Id}",
|
||||||
|
// stockTakingItem.NetWeightDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
stockTaking.IsClosed = true;
|
||||||
|
await StockTakings.UpdateAsync(stockTaking);
|
||||||
|
|
||||||
|
Logger.Info($"StockTaking closed! stockTakingId: {stockTaking.Id}; stockTakingItems count: {count}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItemPallet> AddOrUpdateMeasuredStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
if (stockTakingItemPallet.Id == 0) return await AddStockTakingItemPallet(stockTakingItemPallet);
|
||||||
|
return await UpdateStockTakingItemPallet(stockTakingItemPallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItemPallet> AddStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
await TransactionSafeAsync(async _ =>
|
||||||
|
{
|
||||||
|
await StockTakingItemPallets.InsertAsync(stockTakingItemPallet);
|
||||||
|
await RefreshStockTakingItemMeasuredValuesFromPallets(stockTakingItemPallet.StockTakingItemId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return await StockTakingItemPallets.GetByIdAsync(stockTakingItemPallet.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<StockTakingItemPallet> UpdateStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
||||||
|
{
|
||||||
|
await TransactionSafeAsync(async _ =>
|
||||||
|
{
|
||||||
|
await StockTakingItemPallets.UpdateAsync(stockTakingItemPallet);
|
||||||
|
await RefreshStockTakingItemMeasuredValuesFromPallets(stockTakingItemPallet.StockTakingItemId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return await StockTakingItemPallets.GetByIdAsync(stockTakingItemPallet.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshStockTakingItemMeasuredValuesFromPallets(int stockTakingItemId)
|
||||||
|
{
|
||||||
|
var stockTakingItem = await StockTakingItems.GetByIdAsync(stockTakingItemId, true)!;
|
||||||
|
|
||||||
|
if (stockTakingItem.IsInvalid) throw new Exception($"stockTakingItem.IsInvalid");
|
||||||
|
if (stockTakingItem.StockTaking!.IsClosed) throw new Exception($"stockTakingItem.StockTaking.IsClosed");
|
||||||
|
if (stockTakingItem.StockTakingItemPallets!.Count == 0) throw new Exception($"stockTakingItem.StockTakingItemPallets.Count == 0");
|
||||||
|
if (stockTakingItem.StockTakingItemPallets!.Any(x => !x.IsValidMeasuringValues(stockTakingItem.IsMeasurable))) throw new Exception($"IsValidMeasuringValues == false");
|
||||||
|
|
||||||
|
|
||||||
|
stockTakingItem.IsMeasured = true;
|
||||||
|
stockTakingItem.MeasuredStockQuantity = stockTakingItem.StockTakingItemPallets.Sum(x => x.TrayQuantity);
|
||||||
|
|
||||||
|
if (stockTakingItem.IsMeasurable) stockTakingItem.MeasuredNetWeight = double.Round(stockTakingItem.StockTakingItemPallets.Sum(x => x.NetWeight), 1);
|
||||||
|
|
||||||
|
await StockTakingItems.UpdateAsync(stockTakingItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using LinqToDB;
|
||||||
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Configuration;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
using static LinqToDB.Reflection.Methods.LinqToDB.Insert;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class StockTakingDbTable : MgDbTableBase<StockTaking>
|
||||||
|
{
|
||||||
|
public StockTakingDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
||||||
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IQueryable<StockTaking> GetAll() => base.GetAll();
|
||||||
|
|
||||||
|
public IQueryable<StockTaking> GetAll(bool loadRelations)
|
||||||
|
{
|
||||||
|
return loadRelations
|
||||||
|
? GetAll()
|
||||||
|
.LoadWith(st => st.StockTakingItems).ThenLoad(sti => sti.Product).ThenLoad(prod => prod.GenericAttributes)
|
||||||
|
//.LoadWith(st => st.StockTakingItems).ThenLoad(sti => sti.StockTakingItemPallets)
|
||||||
|
: GetAll();//.LoadWith(st => st.StockTakingItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<StockTaking> GetByIdAsync(int id, bool loadRelations)
|
||||||
|
=> GetAll(loadRelations).FirstOrDefaultAsync(st => st.Id == id);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using LinqToDB;
|
||||||
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Configuration;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class StockTakingItemDbTable : MgDbTableBase<StockTakingItem>
|
||||||
|
{
|
||||||
|
public StockTakingItemDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
||||||
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IQueryable<StockTakingItem> GetAll() => base.GetAll();
|
||||||
|
|
||||||
|
public IQueryable<StockTakingItem> GetAll(bool loadRelations)
|
||||||
|
{
|
||||||
|
return loadRelations
|
||||||
|
? GetAll()
|
||||||
|
.LoadWith(sti => sti.StockTaking)
|
||||||
|
.LoadWith(sti => sti.StockTakingItemPallets)
|
||||||
|
.LoadWith(sti => sti.Product).ThenLoad(prod => prod.GenericAttributes)
|
||||||
|
: GetAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<StockTakingItem> GetByIdAsync(int stockTakingItemId, bool loadRelations) => GetAll(loadRelations).FirstOrDefaultAsync(sti => sti.Id == stockTakingItemId);
|
||||||
|
|
||||||
|
public IQueryable<StockTakingItem> GetAllByProductId(int productId, bool loadRelations)
|
||||||
|
=> GetAll(loadRelations).Where(x => x.ProductId == productId);
|
||||||
|
|
||||||
|
public IQueryable<StockTakingItem> GetAllByStockTakingId(int stockTakingId, bool loadRelations)
|
||||||
|
=> GetAll(loadRelations).Where(x => x.StockTakingId == stockTakingId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using LinqToDB;
|
||||||
|
using Mango.Nop.Data.Repositories;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Configuration;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class StockTakingItemPalletDbTable : MgDbTableBase<StockTakingItemPallet>
|
||||||
|
{
|
||||||
|
public StockTakingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
||||||
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IQueryable<StockTakingItemPallet> GetAll() => base.GetAll();
|
||||||
|
|
||||||
|
public IQueryable<StockTakingItemPallet> GetAll(bool loadRelations)
|
||||||
|
{
|
||||||
|
return loadRelations
|
||||||
|
? GetAll()
|
||||||
|
.LoadWith(stip => stip.StockTakingItem).ThenLoad(sti => sti.StockTaking)
|
||||||
|
.LoadWith(stip => stip.StockTakingItem).ThenLoad(sti => sti.Product).ThenLoad(prod => prod.GenericAttributes)
|
||||||
|
: GetAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -75,11 +75,17 @@ public class PluginNopStartup : INopStartup
|
||||||
|
|
||||||
services.AddScoped<StockQuantityHistoryDtoDbTable>();
|
services.AddScoped<StockQuantityHistoryDtoDbTable>();
|
||||||
|
|
||||||
|
services.AddScoped<StockTakingDbTable>();
|
||||||
|
services.AddScoped<StockTakingItemDbTable>();
|
||||||
|
services.AddScoped<StockTakingItemPalletDbTable>();
|
||||||
|
|
||||||
|
services.AddScoped<StockTakingDbContext>();
|
||||||
services.AddScoped<FruitBankDbContext>();
|
services.AddScoped<FruitBankDbContext>();
|
||||||
|
|
||||||
services.AddScoped<SignalRSendToClientService>();
|
services.AddScoped<SignalRSendToClientService>();
|
||||||
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
|
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
|
||||||
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();
|
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();
|
||||||
|
services.AddScoped<IStockSignalREndpointServer, StockSignalREndpointServer>();
|
||||||
|
|
||||||
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
|
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
|
||||||
services.AddScoped<IPriceCalculationService, CustomPriceCalculationService>();
|
services.AddScoped<IPriceCalculationService, CustomPriceCalculationService>();
|
||||||
|
|
@ -163,6 +169,7 @@ public class PluginNopStartup : INopStartup
|
||||||
{
|
{
|
||||||
endpoints.MapHub<LoggerSignalRHub>(loggrHubEndPoint, options =>
|
endpoints.MapHub<LoggerSignalRHub>(loggrHubEndPoint, options =>
|
||||||
{
|
{
|
||||||
|
options.Transports = HttpTransportType.WebSockets;
|
||||||
options.AllowStatefulReconnects = false;
|
options.AllowStatefulReconnects = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ 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 Nop.Data.Mapping;
|
using Nop.Data.Mapping;
|
||||||
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Mapping;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Mapping;
|
||||||
|
|
||||||
|
|
@ -38,6 +39,9 @@ public partial class NameCompatibility : INameCompatibility
|
||||||
{ typeof(StockQuantityHistoryDto), nameof(StockQuantityHistory)},
|
{ typeof(StockQuantityHistoryDto), nameof(StockQuantityHistory)},
|
||||||
{ typeof(StockQuantityHistoryExt), FruitBankConstClient.StockQuantityHistoryExtDbTableName},
|
{ typeof(StockQuantityHistoryExt), FruitBankConstClient.StockQuantityHistoryExtDbTableName},
|
||||||
|
|
||||||
|
{ typeof(StockTaking), FruitBankConstClient.StockTakingDbTableName},
|
||||||
|
{ typeof(StockTakingItem), FruitBankConstClient.StockTakingItemDbTableName},
|
||||||
|
{ typeof(StockTakingItemPallet), FruitBankConstClient.StockTakingItemPalletDbTableName},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@
|
||||||
<PackageReference Include="DevExtreme.AspNet.Data" Version="5.1.0" />
|
<PackageReference Include="DevExtreme.AspNet.Data" Version="5.1.0" />
|
||||||
|
|
||||||
<!-- Your existing packages -->
|
<!-- Your existing packages -->
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
|
||||||
|
|
||||||
<!--<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />-->
|
<!--<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.10" />-->
|
||||||
<PackageReference Include="PdfPig" Version="0.1.11" />
|
<PackageReference Include="PdfPig" Version="0.1.11" />
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class PluginNopStartup : INopStartup
|
||||||
feature.AddPolicy(
|
feature.AddPolicy(
|
||||||
"AllowBlazorClient",
|
"AllowBlazorClient",
|
||||||
apiPolicy => apiPolicy
|
apiPolicy => apiPolicy
|
||||||
.WithOrigins(["https://localhost:7144", "https://measurementtest.fruitbank.hu", "https://localhost:60589", "http://localhost:5000"])
|
.WithOrigins("https://localhost:7144", "https://measurementtest.fruitbank.hu", "https://localhost:60589", "http://localhost:5000", "https://localhost:59579")
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowCredentials()
|
.AllowCredentials()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue