using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_IRecordRepository; using WIDESEA_IRecordService; using WIDESEA_Model.Models; namespace WIDESEA_RecordService { public partial class StockQuantityChangeRecordService : ServiceBase, IStockQuantityChangeRecordService { public void AddStockChangeRecord(Dt_StockInfo stockInfo, List stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType, int? taskNum = null) { try { 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; x.TaskNum = taskNum; index++; }); BaseDal.AddData(stockQuantityChangeRecords); } catch (Exception ex) { throw new Exception(ex.Message); } } } }