| | |
| | | { |
| | | public partial class StockQuantityChangeRecordService : ServiceBase<Dt_StockQuantityChangeRecord, IStockQuantityChangeRecordRepository>, IStockQuantityChangeRecordService |
| | | { |
| | | public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType) |
| | | public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType, int? taskNum = null) |
| | | { |
| | | List<Dt_StockQuantityChangeRecord> stockQuantityChangeRecords = new List<Dt_StockQuantityChangeRecord>(); |
| | | stockQuantityChangeRecords = _mapper.Map<List<Dt_StockQuantityChangeRecord>>(stockInfoDetails); |
| | | int index = 0; |
| | | decimal currentQuantity = 0; |
| | | stockQuantityChangeRecords.ForEach(x => |
| | | try |
| | | { |
| | | x.PalleCode = stockInfo.PalletCode; |
| | | x.BeforeQuantity = beforeQuantity; |
| | | if (totalQuantity > beforeQuantity) |
| | | List<Dt_StockQuantityChangeRecord> stockQuantityChangeRecords = new List<Dt_StockQuantityChangeRecord>(); |
| | | stockQuantityChangeRecords = _mapper.Map<List<Dt_StockQuantityChangeRecord>>(stockInfoDetails); |
| | | int index = 0; |
| | | decimal currentQuantity = 0; |
| | | stockQuantityChangeRecords.ForEach(x => |
| | | { |
| | | 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.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); |
| | | |
| | | x.ChangeType = changeType.ObjToInt(); |
| | | beforeQuantity += x.ChangeQuantity; |
| | | x.TaskNum = taskNum; |
| | | index++; |
| | | }); |
| | | BaseDal.AddData(stockQuantityChangeRecords); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |