using AutoMapper; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_IRecordService; using WIDESEA_Model.Models; namespace WIDESEA_RecordService { public partial class StockQuantityChangeRecordService : ServiceBase>, IStockQuantityChangeRecordService { private readonly IMapper _mapper; public StockQuantityChangeRecordService(IRepository BaseDal, IMapper mapper) : base(BaseDal) { _mapper = mapper; } public IRepository Repository => BaseDal; public void AddStockChangeRecord(Dt_StockInfo stockInfo, List stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, WIDESEA_Common.StockEnum.StockChangeType changeType) { List stockQuantityChangeRecords = new List(); stockQuantityChangeRecords = _mapper.Map>(stockInfoDetails); int index = 0; decimal currentQuantity = 0; stockQuantityChangeRecords.ForEach(x => { x.PalleCode = stockInfo.PalletCode; x.BeforeQuantity = beforeQuantity; if (totalQuantity > beforeQuantity) { x.ChangeQuantity = stockInfoDetails[index].StockQuantity; currentQuantity += stockInfoDetails[index].StockQuantity; x.AfterQuantity = stockInfoDetails[index].StockQuantity + beforeQuantity; } else { x.ChangeQuantity = -stockInfoDetails[index].StockQuantity; currentQuantity -= stockInfoDetails[index].StockQuantity; x.AfterQuantity = beforeQuantity - stockInfoDetails[index].StockQuantity; } x.ChangeType = changeType.ObjToInt(); beforeQuantity += x.ChangeQuantity; }); BaseDal.AddData(stockQuantityChangeRecords); } } }