| | |
| | | public readonly IOutboundService _outboundService; |
| | | public readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; |
| | | public readonly IRepository<Dt_AllocateOrderDetail> _allocateOrderDetailRepository; |
| | | public AllocateService(IRepository<Dt_AllocateOrder> BaseDal, |
| | | public AllocateService(IRepository<Dt_AllocateOrder> BaseDal, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | | IInboundService inboundService, |
| | | IOutboundService outboundService, |
| | |
| | | { |
| | | try |
| | | { |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟淇℃伅"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟鏄庣粏淇℃伅"); |
| | | } |
| | | List<Dt_AllocateOrderDetail> allocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<Dt_AllocateOrderDetail> updateAllocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | foreach (var item in model.Details) |
| | | { |
| | | if (string.IsNullOrEmpty(item.Barcode)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟淇℃伅"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟鏄庣粏淇℃伅"); |
| | | } |
| | | List<Dt_AllocateOrderDetail> allocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<Dt_AllocateOrderDetail> updateAllocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | foreach (var item in model.Details) |
| | | { |
| | | if (string.IsNullOrEmpty(item.Barcode)) |
| | | { |
| | | |
| | | } |
| | | else |
| | | { |
| | | Dt_AllocateOrderDetail? allocateOrderDetail = allocateOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode); |
| | | if (allocateOrderDetail == null) |
| | | { |
| | | allocateOrderDetail = new Dt_AllocateOrderDetail() |
| | | { |
| | | OrderId = allocateOrder.Id, |
| | | MaterielCode = item.MaterielCode, |
| | | LineNo = item.LineNo, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Barcode = item.Barcode, |
| | | BarcodeUnit = item.BarcodeUnit, |
| | | BarcodeQty = (decimal)item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | allocateOrderDetails.Add(allocateOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | Dt_AllocateOrderDetail? allocateOrderDetail = allocateOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode); |
| | | if (allocateOrderDetail == null) |
| | | { |
| | | allocateOrderDetail = new Dt_AllocateOrderDetail() |
| | | { |
| | | OrderId = allocateOrder.Id, |
| | | MaterielCode = item.MaterielCode, |
| | | LineNo= item.LineNo, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Barcode = item.Barcode, |
| | | BarcodeUnit = item.BarcodeUnit, |
| | | BarcodeQty = (decimal)item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | allocateOrderDetails.Add(allocateOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | allocateOrderDetail.LineNo = item.LineNo; |
| | | allocateOrderDetail.MaterielCode = item.MaterielCode; |
| | | allocateOrderDetail.BatchNo = item.BatchNo; |
| | | allocateOrderDetail.Unit = item.Unit; |
| | | allocateOrderDetail.WarehouseCode = item.WarehouseCode; |
| | | allocateOrderDetail.Barcode = item.Barcode; |
| | | allocateOrderDetail.BarcodeUnit = item.BarcodeUnit; |
| | | allocateOrderDetail.BarcodeQty = item.BarcodeQty; |
| | | allocateOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | allocateOrderDetail.LineNo = item.LineNo; |
| | | allocateOrderDetail.MaterielCode = item.MaterielCode; |
| | | allocateOrderDetail.BatchNo = item.BatchNo; |
| | | allocateOrderDetail.Unit = item.Unit; |
| | | allocateOrderDetail.WarehouseCode = item.WarehouseCode; |
| | | allocateOrderDetail.Barcode = item.Barcode; |
| | | allocateOrderDetail.BarcodeUnit = item.BarcodeUnit; |
| | | allocateOrderDetail.BarcodeQty = item.BarcodeQty; |
| | | allocateOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | |
| | | |
| | | updateAllocateOrderDetails.Add(allocateOrderDetail); |
| | | detailIds.Add(allocateOrderDetail.Id); |
| | | } |
| | | updateAllocateOrderDetails.Add(allocateOrderDetail); |
| | | detailIds.Add(allocateOrderDetail.Id); |
| | | } |
| | | } |
| | | } |
| | | |
| | | allocateOrder.UpperOrderNo = model.UpperOrderNo; |
| | | allocateOrder.BusinessType = model.BusinessType; |
| | | allocateOrder.IsBatch = model.IsBatch; |
| | | allocateOrder.FactoryArea = model.FactoryArea; |
| | | allocateOrder.UpperOrderNo = model.UpperOrderNo; |
| | | allocateOrder.BusinessType = model.BusinessType; |
| | | allocateOrder.IsBatch = model.IsBatch; |
| | | allocateOrder.FactoryArea = model.FactoryArea; |
| | | |
| | | List<Dt_AllocateOrderDetail> deletePurchaseOrderDetails = allocateOrder.Details.Where(x => !detailIds.Contains(x.Id)).ToList(); |
| | | List<Dt_AllocateOrderDetail> deletePurchaseOrderDetails = allocateOrder.Details.Where(x => !detailIds.Contains(x.Id)).ToList(); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | } |
| | | |
| | | _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails); |
| | | _allocateOrderDetailRepository.AddData(allocateOrderDetails); |
| | | _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails); |
| | | _allocateOrderDetailRepository.AddData(allocateOrderDetails); |
| | | |
| | | BaseDal.UpdateData(allocateOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | BaseDal.UpdateData(allocateOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | { |
| | | try |
| | | { |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟淇℃伅"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟鏄庣粏淇℃伅"); |
| | | } |
| | | //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.DeleteAndMoveIntoHty(allocateOrder, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | foreach (var item in allocateOrder.Details) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟淇℃伅"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"鏈壘鍒拌皟鎷ㄥ崟鏄庣粏淇℃伅"); |
| | | } |
| | | //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | // BaseDal.DeleteAndMoveIntoHty(allocateOrder, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | foreach (var item in allocateOrder.Details) |
| | | { |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎); |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | BaseDal.DeleteData(allocateOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | return new Dt_OutboundOrder() |
| | | { |
| | | WarehouseId= allocateOrder.WarehouseId, |
| | | OrderNo=allocateOrder.OrderNo, |
| | | UpperOrderNo=allocateOrder.UpperOrderNo, |
| | | OrderType=allocateOrder.OrderType, |
| | | OrderStatus=allocateOrder.OrderStatus, |
| | | CreateType=allocateOrder.CreateType, |
| | | BusinessType=allocateOrder.BusinessType, |
| | | IsBatch=allocateOrder.IsBatch, |
| | | FactoryArea=allocateOrder.FactoryArea, |
| | | Remark=allocateOrder.Remark, |
| | | DepartmentCode="", |
| | | DepartmentName="", |
| | | Details=allocateOrder.Details.Select(detail=>new Dt_OutboundOrderDetail |
| | | { |
| | | OrderId= detail.OrderId, |
| | | MaterielCode=detail.MaterielCode, |
| | | MaterielName="", |
| | | BatchNo=detail.BatchNo, |
| | | OrderQuantity=detail.OrderQuantity, |
| | | LockQuantity=0, |
| | | OverOutQuantity=0, |
| | | OrderDetailStatus=detail.OrderDetailStatus, |
| | | Unit=detail.Unit, |
| | | RowNo=0, |
| | | SupplyCode="", |
| | | WarehouseCode=detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | WarehouseId = allocateOrder.WarehouseId, |
| | | OrderNo = allocateOrder.OrderNo, |
| | | UpperOrderNo = allocateOrder.UpperOrderNo, |
| | | OrderType = allocateOrder.OrderType, |
| | | OrderStatus = allocateOrder.OrderStatus, |
| | | CreateType = allocateOrder.CreateType, |
| | | BusinessType = allocateOrder.BusinessType, |
| | | IsBatch = allocateOrder.IsBatch, |
| | | FactoryArea = allocateOrder.FactoryArea, |
| | | Remark = allocateOrder.Remark, |
| | | DepartmentCode = "", |
| | | DepartmentName = "", |
| | | Details = allocateOrder.Details.Select(detail => new Dt_OutboundOrderDetail |
| | | { |
| | | OrderId = detail.OrderId, |
| | | MaterielCode = detail.MaterielCode, |
| | | MaterielName = "", |
| | | BatchNo = detail.BatchNo, |
| | | OrderQuantity = detail.OrderQuantity, |
| | | LockQuantity = 0, |
| | | OverOutQuantity = 0, |
| | | OrderDetailStatus = detail.OrderDetailStatus, |
| | | Unit = detail.Unit, |
| | | RowNo = 0, |
| | | SupplyCode = "", |
| | | WarehouseCode = detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | }; |
| | | } |
| | | |