using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.StockValuation; using MMDAL.Query.StockValuation; using System.Data.Common; namespace MMDAL.CustomCode.StockPosition; public class StockPositionDAL : IStockPositionDAL { private readonly IQueryExecutor _qe; public StockPositionDAL(IQueryExecutor qe) => _qe = qe; public async Task GetStockPositionAsync( int itemId, int skuId, int storeId, int ouid, LoginDTO login, CancellationToken ct) { return await _qe.QuerySingleAsync( login, StockPositionQB.GET_STOCK_POSITION, new { OUID = ouid, ItemId = itemId, SKUId = skuId, StoreId = storeId }, cancellationToken: ct).ConfigureAwait(false); } public async Task EnsurePositionExistsAsync( int itemId, int skuId, int storeId, int ouid, LoginDTO login, DbTransaction tx, CancellationToken ct) { await _qe.ExecuteAsync( login, StockPositionQB.INSERT_POSITION_IF_MISSING, new { OUID = ouid, ItemId = itemId, SKUId = skuId, StoreId = storeId }, transaction: tx, cancellationToken: ct).ConfigureAwait(false); } public async Task UpdatePositionQuantitiesAsync( int itemId, int skuId, int storeId, int ouid, decimal goodQuantity, decimal shadowGoodQuantity, decimal rejectedQuantity, decimal reworkQuantity, decimal otherQuantity, decimal wipQuantity, decimal unlinkedWipGoodQty, decimal unlinkedWipReworkQty, int postSign, LoginDTO login, DbTransaction tx, CancellationToken ct) { await _qe.ExecuteAsync( login, StockPositionQB.UPDATE_POSITION_QUANTITIES, new { OUID = ouid, ItemId = itemId, SKUId = skuId, StoreId = storeId, GoodQuantity = goodQuantity, ShadowGoodQuantity = shadowGoodQuantity, RejectedQuantity = rejectedQuantity, ReworkQuantity = reworkQuantity, OtherQuantity = otherQuantity, WipQuantity = wipQuantity, UnlinkedWipGoodQty = unlinkedWipGoodQty, UnlinkedWipReworkQty = unlinkedWipReworkQty, PostSign = postSign }, transaction: tx, cancellationToken: ct).ConfigureAwait(false); } public async Task UpdateDirectAverageCostAsync( int itemId, int skuId, int storeId, int ouid, decimal newAverageCost, decimal newAverageValue, LoginDTO login, DbTransaction tx, CancellationToken ct) { await _qe.ExecuteAsync( login, StockPositionQB.UPDATE_DIRECT_AVERAGE_COST, new { OUID = ouid, ItemId = itemId, SKUId = skuId, StoreId = storeId, NewAverageCost = newAverageCost, NewAverageValue = newAverageValue }, transaction: tx, cancellationToken: ct).ConfigureAwait(false); } }