using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Common.StockEnum; 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, float beforeQuantity, float totalQuantity, StockChangeTypeEnum changeType, int? taskNum = null) { try { List stockQuantityChangeRecords = new List(); stockQuantityChangeRecords = _mapper.Map>(stockInfoDetails); int index = 0; float 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); } } public void AddStockChangeRecord(Dt_StockInfo stockInfo, List updateDetails, List deleteDetails, StockChangeTypeEnum changeType, int? taskNum = null) { try { List stockQuantityChangeRecords = new List(); int index1 = 0; List records1 = _mapper.Map>(updateDetails); records1.ForEach(x => { x.PalleCode = stockInfo.PalletCode; x.BeforeQuantity = deleteDetails[index1].StockQuantity + deleteDetails[index1].OutboundQuantity; x.ChangeQuantity = -deleteDetails[index1].OutboundQuantity; x.AfterQuantity = deleteDetails[index1].StockQuantity; index1++; }); stockQuantityChangeRecords.AddRange(records1); int index2 = 0; List records2 = _mapper.Map>(deleteDetails); records2.ForEach(x => { x.PalleCode = stockInfo.PalletCode; x.BeforeQuantity = deleteDetails[index2].StockQuantity; x.ChangeQuantity = -deleteDetails[index2].StockQuantity; x.AfterQuantity = 0; index2++; }); stockQuantityChangeRecords.AddRange(records2); BaseDal.AddData(stockQuantityChangeRecords); } catch (Exception ex) { throw new Exception(ex.Message); } } } }