using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Common.StockEnum; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_IRecordRepository; using WIDESEAWCS_IRecordService; using WIDESEAWCS_Model.Models; namespace WIDESEAWCS_RecordService { public partial class StockQuantityChangeRecordService : ServiceBase, IStockQuantityChangeRecordService { public void AddStockChangeRecord(Dt_StockInfo stockInfo, List stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, 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); } } }