public void DeliverySubmitted(Guid pOrderGuid, Guid pDeliveryGuid) { using (BookStoreEntityModelContainer lContainer = new BookStoreEntityModelContainer()) { Console.WriteLine("Delivery for order: " + pOrderGuid + "has been submitted for delivery. Delivery id: " + pDeliveryGuid); var pOrder = lContainer.Orders.Include("Customer").First(x => x.OrderNumber == pOrderGuid); Delivery lDelivery = new Delivery() { DeliveryStatus = DeliveryStatus.Submitted, SourceAddress = "Book Store Address", DestinationAddress = pOrder.Customer.Address, Order = pOrder, ExternalDeliveryIdentifier = pDeliveryGuid }; pOrder.Delivery = lDelivery; lContainer.Deliveries.Add(lDelivery); //update stocks foreach (OrderItem lOrderItem in pOrder.OrderItems) { int book_id = lContainer.WBooks.Where(books => books.Title == lOrderItem.Book.Title).First().Id; WStock lWStock = lContainer.WStocks.Where(stock => stock.Warehouse_id == pOrder.Warehouse_Id).Where(Stock => Stock.WBook_id == book_id).First(); lWStock.quantity -= lOrderItem.Quantity; } lContainer.SaveChanges(); SendOrderPlacedConfirmation(pOrder); } }
/// <summary> /// 出库 /// </summary> /// <param name="stockOuts"></param> /// <returns></returns> public ResultData <string> DeleteStocks(List <WStockOut> stockOuts) { ResultData <string> rData = new ResultData <string>(); decimal rt = 0; foreach (WStockOut stockOut in stockOuts) { //如果库存ID为空,则根据物料+货位+所有者+批次进行查询 if (stockOut.StockID < 1) { WStock stock = sRepository.GetStocks(stockOut.MaterialID, stockOut.PositionID, stockOut.Batch); if (stock == null) { rData.status = -1; rData.message = BuilderStockLessMessage(stockOut); return(rData); } stockOut.StockID = stock.ID; } switch (stockOut.StockOutType) { case StockOutEnum.TransferOut: //调拨出库 rt = sRepository.AddTransitCount(stockOut.StockID, stockOut.OutCount); if (rt < 0) { rData.status = -1; rData.message = BuilderStockLessMessage(stockOut); return(rData); } break; default: rt = sRepository.DeleteStockCount(stockOut.StockID, stockOut.OutCount); if (rt < 0) { rData.status = -1; rData.message = BuilderStockLessMessage(stockOut); return(rData); } break; } soRepository.Insert(stockOut); } return(rData); }
/// <summary> /// 入库 /// </summary> /// <param name="stockIns"></param> /// <returns></returns> public ResultData <string> AddStocks(List <WStockIn> stockIns) { ResultData <string> rData = new ResultData <string>(); foreach (WStockIn stockIn in stockIns) { switch (stockIn.StockInType) { case StockInEnum.TransferIn: //调拨入库 decimal result = sRepository.DeleteTransitCount(stockIn.StockID, stockIn.InCount); if (result < 0) { StringBuilder sb = new StringBuilder("库存在途数量小于入库数量"); sb.AppendLine(",货位:" + stockIn.PositionCode); sb.AppendLine(",物料:" + stockIn.MaterialCode); if (!string.IsNullOrWhiteSpace(stockIn.Batch)) { sb.AppendLine(",批次:" + stockIn.Batch); } if (!string.IsNullOrWhiteSpace(stockIn.OwnerCode)) { sb.AppendLine(",货主:" + stockIn.OwnerCode); } rData.message = sb.ToString(); rData.status = -1; return(rData); } break; } //根据物料+货位+入库时间+所有人+批次查询是否存在 WStock stock = sRepository.GetStocks(stockIn.MaterialID, stockIn.PositionID, stockIn.StockInDate, stockIn.Batch); if (stock == null) { stock = CloneStockIn(stockIn); sRepository.Insert(stock); } else { sRepository.AddStockCount(stock.ID, stockIn.InCount); } siRepository.Insert(stockIn); } return(rData); }
/// <summary> /// 入库记录转库存表 /// </summary> /// <param name="stockIn"></param> /// <returns></returns> private WStock CloneStockIn(WStockIn stockIn) { WStock stock = new WStock(); stock.Batch = string.IsNullOrEmpty(stockIn.Batch) ? "" : stockIn.Batch; //批次 stock.StockInDate = stockIn.StockInDate; //入库时间 stock.DateBatch = stockIn.StockInDate.ToString("yyyyMMdd"); //时间批次 stock.Factory = string.IsNullOrEmpty(stockIn.Factory) ? "" : stockIn.Factory; //工厂 stock.MaterialCode = stockIn.MaterialCode; //物料编码 stock.MaterialID = stockIn.MaterialID; //物料ID stock.OwnerCode = string.IsNullOrEmpty(stockIn.OwnerCode) ? "" : stockIn.OwnerCode; //所有人 stock.PositionCode = stockIn.PositionCode; //货位编码 stock.PositionID = stockIn.PositionID; //货位ID stock.StockCount = stockIn.InCount; //入库数量 stock.UnLimitCount = stockIn.InCount; //可用数量 stock.UnitID = stockIn.UnitID; //单位 stock.WarehouseCode = stockIn.WarehouseCode; //仓库编码 stock.WarehouseID = stockIn.WarehouseID; //仓库ID return(stock); }