protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); // Get shopping cart status - Ordered var statusOrdered = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query.Search(Connection, Transaction, new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query() { GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(DLCore_DBCommons.APODemand.EShoppingCartStatus.Ordered), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var tenant = securityTicket.TenantID; #region Find All Shopping Carts in Approved state for TenantID var statusApproved = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query.Search(Connection, Transaction, new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Status.Query { Tenant_RefID = securityTicket.TenantID, GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(DLCore_DBCommons.APODemand.EShoppingCartStatus.Approved), IsDeleted = false }).Single(); var approvedShoppingCarts = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart.Query.Search(Connection, Transaction, new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart.Query { ShoppingCart_CurrentStatus_RefID = statusApproved.ORD_PRC_ShoppingCart_StatusID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }); if (approvedShoppingCarts == null || approvedShoppingCarts.Count() == 0) { returnValue.Result = Guid.Empty; return(returnValue); } #endregion #region Procurement Order // Get procurement order status var procurementOrderStatus = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query.Search(Connection, Transaction, new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query() { GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(DLCore_DBCommons.APODemand.EProcurementStatus.Active), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var account = new CL1_USR.ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); #region var incrNumberParam = new P_L2NR_GaIINfUA_1454() { GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.ProcurementOrderNumber) }; var procurementNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber; #endregion // Create procurement order header var procurementOrderHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header(); procurementOrderHeader.Tenant_RefID = securityTicket.TenantID; procurementOrderHeader.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID; procurementOrderHeader.Current_ProcurementOrderStatus_RefID = procurementOrderStatus.ORD_PRC_ProcurementOrder_StatusID; procurementOrderHeader.ProcurementOrder_Supplier_RefID = Guid.Empty; procurementOrderHeader.ProcurementOrder_Date = DateTime.Now; procurementOrderHeader.TotalValue_BeforeTax = 0; procurementOrderHeader.ProcurementOrder_Number = procurementNumber; procurementOrderHeader.Save(Connection, Transaction); // Create procurement order status history var procurementOrderStatusHistory = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_StatusHistory(); procurementOrderStatusHistory.Tenant_RefID = securityTicket.TenantID; procurementOrderStatusHistory.ProcurementOrder_Header_RefID = procurementOrderHeader.ORD_PRC_ProcurementOrder_HeaderID; procurementOrderStatusHistory.ProcurementOrder_Status_RefID = procurementOrderStatus.ORD_PRC_ProcurementOrder_StatusID; procurementOrderStatusHistory.Save(Connection, Transaction); // Set return value returnValue.Result = procurementOrderHeader.ORD_PRC_ProcurementOrder_HeaderID; #endregion foreach (var item in approvedShoppingCarts) { #region Procurement Order Shopping Products var param = new P_L5AWSSC_GSPfSC_1650(); param.ShoppingCartID = item.ORD_PRC_ShoppingCartID; var shoppingProducts = cls_Get_ShoppingProducts_for_ShoppingCartID.Invoke(Connection, Transaction, param, securityTicket).Result; //when office is deleted but there is ordered items for it if (shoppingProducts == null) { continue; } // Create and save procurement order for shopping products foreach (var shoppingProduct in shoppingProducts.Products) { #region Skip if Product is not good if (shoppingProduct.IsProductCanceled || shoppingProduct.IsProductDeleted) { continue; } #endregion var procurementOrderPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position(); procurementOrderPosition.ORD_PRC_ProcurementOrder_PositionID = Guid.NewGuid(); procurementOrderPosition.ProcurementOrder_Header_RefID = procurementOrderHeader.ORD_PRC_ProcurementOrder_HeaderID; procurementOrderPosition.Position_Quantity = shoppingProduct.Quantity; procurementOrderPosition.Position_ValuePerUnit = shoppingProduct.Price; procurementOrderPosition.Position_ValueTotal = shoppingProduct.Price * (Decimal)shoppingProduct.Quantity; procurementOrderPosition.Position_Unit_RefID = Guid.Empty; procurementOrderPosition.Position_RequestedDateOfDelivery = new DateTime(); procurementOrderPosition.CMN_PRO_Product_RefID = shoppingProduct.CMN_PRO_Product_RefID; procurementOrderPosition.CMN_PRO_Product_Release_RefID = shoppingProduct.CMN_PRO_Product_Release_RefID; procurementOrderPosition.CMN_PRO_Product_Variant_RefID = shoppingProduct.CMN_PRO_Product_Variant_RefID; procurementOrderPosition.Creation_Timestamp = DateTime.Now; procurementOrderPosition.Tenant_RefID = securityTicket.TenantID; procurementOrderPosition.IsProductReplacementAllowed = shoppingProduct.IsProductReplacementAllowed; procurementOrderPosition.Save(Connection, Transaction); var shoppingCart2ProcurementOrder = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition(); shoppingCart2ProcurementOrder.AssignmentID = Guid.NewGuid(); shoppingCart2ProcurementOrder.ORD_PRC_ShoppingCart_Product_RefID = shoppingProduct.ORD_PRC_ShoppingCart_ProductID; shoppingCart2ProcurementOrder.ORD_PRC_ProcurementOrder_Position_RefID = procurementOrderPosition.ORD_PRC_ProcurementOrder_PositionID; shoppingCart2ProcurementOrder.Tenant_RefID = securityTicket.TenantID; shoppingCart2ProcurementOrder.Save(Connection, Transaction); procurementOrderHeader.TotalValue_BeforeTax += procurementOrderPosition.Position_ValueTotal; } #endregion #region ShoppingCartNotes var notesParam = new P_L5AWSAR_GSCNfSC_1454() { ShoppingCartID = item.ORD_PRC_ShoppingCartID }; var scNotes = cls_Get_ShoppingCart_Notes_for_ShoppingCartID.Invoke(Connection, Transaction, notesParam, securityTicket).Result; var count = 1; foreach (var scNote in scNotes) { if (!scNote.IsNoteForProcurementOrder) { continue; } var officeInfo = ORM_ORD_PRC_Office_ShoppingCart.Query.Search(Connection, Transaction, new ORM_ORD_PRC_Office_ShoppingCart.Query() { ORD_PRC_ShoppingCart_RefID = item.ORD_PRC_ShoppingCartID, IsDeleted = false }).Single(); var note = new ORM_ORD_PRC_ProcurementOrder_Note(); note.ORD_PRC_ProcurementOrder_NoteID = Guid.NewGuid(); note.ORD_PRC_ProcurementOrder_Header_RefID = procurementOrderHeader.ORD_PRC_ProcurementOrder_HeaderID; note.ORD_PRC_ProcurementOrder_Position_RefID = Guid.Empty; note.CMN_STR_Office_RefID = officeInfo.CMN_STR_Office_RefID; note.Comment = scNote.Memo_Text; note.Title = ""; note.NotePublishDate = scNote.UpdatedOn; note.SequenceOrderNumber = count; note.Tenant_RefID = securityTicket.TenantID; note.Save(Connection, Transaction); count++; } #endregion #region Shopping Cart // Change shopping cart status item.ShoppingCart_CurrentStatus_RefID = statusOrdered.ORD_PRC_ShoppingCart_StatusID; item.IsProcurementOrderCreated = true; item.Save(Connection, Transaction); // Create and save new shopping cart history var shoppingHistory = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCartStatus_History(); shoppingHistory.ORD_PRC_ShoppingCart_RefID = item.ORD_PRC_ShoppingCartID; shoppingHistory.ORD_PRC_ShoppingCart_Status_RefID = statusOrdered.ORD_PRC_ShoppingCart_StatusID; shoppingHistory.PerformedBy_Account_RefID = securityTicket.AccountID; shoppingHistory.Tenant_RefID = securityTicket.TenantID; shoppingHistory.Save(Connection, Transaction); #endregion } //Save TotalValue_BeforeTax after updates procurementOrderHeader.Save(Connection, Transaction); return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PO_CED_1410 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); //Put your code here List <Guid> positionsForCreating = new List <Guid>(); Guid headerID = new Guid(); var procurementHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header(); procurementHeader.Load(Connection, Transaction, Parameter.ProcurementHeaderID); if (procurementHeader == null) { throw new Exception("wrong procurment header!"); } #region Update Procurement Order var newProcurementOrderStatusID = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query.Search(Connection, Transaction, new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query() { GlobalPropertyMatchingID = DLCore_DBCommons.Utils.EnumUtils.GetEnumDescription(EProcurementStatus.Ordered), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single().ORD_PRC_ProcurementOrder_StatusID; procurementHeader.Current_ProcurementOrderStatus_RefID = newProcurementOrderStatusID; procurementHeader.Save(Connection, Transaction); // Create procurement order status history var procurementOrderStatusHistory = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_StatusHistory(); procurementOrderStatusHistory.Tenant_RefID = securityTicket.TenantID; procurementOrderStatusHistory.ProcurementOrder_Header_RefID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID; procurementOrderStatusHistory.ProcurementOrder_Status_RefID = newProcurementOrderStatusID; procurementOrderStatusHistory.StatusHistoryComment = ""; procurementOrderStatusHistory.Save(Connection, Transaction); #endregion var procurementPositionsQuery = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position.Query(); procurementPositionsQuery.ProcurementOrder_Header_RefID = Parameter.ProcurementHeaderID; procurementPositionsQuery.Tenant_RefID = securityTicket.TenantID; procurementPositionsQuery.IsDeleted = false; var foundProcurementPositions = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position.Query.Search(Connection, Transaction, procurementPositionsQuery).ToList(); //positionIDs var positionIDs = foundProcurementPositions.Select(x => x.ORD_PRC_ProcurementOrder_PositionID); //find expected delivery data if exist P_L5PO_GEDfPOP_1132 expDeliveryParam = new P_L5PO_GEDfPOP_1132(); expDeliveryParam.ProcurementOrderPositions = positionIDs.ToArray(); var expectedDeliveries = cls_Get_ExpectedDeliveries_for_ProcurementOrderPositions.Invoke(Connection, Transaction, expDeliveryParam, securityTicket).Result; CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header expectedDeliveryHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header(); if (expectedDeliveries != null && expectedDeliveries.Length > 0) { expectedDeliveryHeader = new ORM_ORD_PRC_ExpectedDelivery_Header(); expectedDeliveryHeader.Load(Connection, Transaction, expectedDeliveries.First().ORD_PRC_ExpectedDelivery_HeaderID); expectedDeliveryHeader.ExpectedDeliveryDate = Parameter.ExpectedDeliveryDate; expectedDeliveryHeader.Save(Connection, Transaction); headerID = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID; foreach (var item in expectedDeliveries) { if (!positionIDs.Contains(item.ORD_PRC_ProcurementOrder_Position_RefID)) { positionsForCreating.Add(item.ORD_PRC_ProcurementOrder_Position_RefID); } } } else { positionsForCreating.AddRange(positionIDs); //napraviti header expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID = Guid.NewGuid(); expectedDeliveryHeader.ExpectedDeliveryHeaderITL = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID.ToString(); //finding global property matchin id from number ranges for expected delivery var expectedDeliveryNumberParam = new CL2_NumberRange.Complex.Retrieval.P_L2NR_GaIINfUA_1454(); expectedDeliveryNumberParam.GlobalStaticMatchingID = DLCore_DBCommons.Utils.EnumUtils. GetEnumDescription(DLCore_DBCommons.APODemand.ENumberRangeUsageAreaType.ExpectedDeliveryNumber); expectedDeliveryHeader.ExpectedDeliveryNumber = CL2_NumberRange.Complex.Retrieval.cls_Get_and_Increase_IncreasingNumber_for_UsageArea. Invoke(Connection, Transaction, expectedDeliveryNumberParam, securityTicket).Result.Current_IncreasingNumber; expectedDeliveryHeader.ExpectedDeliveryDate = Parameter.ExpectedDeliveryDate; expectedDeliveryHeader.LOG_WRH_Warehouse_RefID = Guid.Empty; expectedDeliveryHeader.IsDeleted = false; expectedDeliveryHeader.Tenant_RefID = securityTicket.TenantID; expectedDeliveryHeader.IsDeliveryOpen = true; expectedDeliveryHeader.IsDeliveryManuallyCreated = true; expectedDeliveryHeader.Save(Connection, Transaction); headerID = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID; } #region Get receiptHeader or create it if don't exist var queryProcurement = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query() { ORD_PRO_ProcurementOrder_Header_RefID = Parameter.ProcurementHeaderID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }; var receiptToProcurementHeader = CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query.Search(Connection, Transaction, queryProcurement).SingleOrDefault(); var receiptHeader = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header(); Guid receiptHeaderID = Guid.Empty; if (receiptToProcurementHeader == null) { var incrNumberParam = new P_L2NR_GaIINfUA_1454() { GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.StockReceiptNumber) }; var receiptNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber; receiptHeader = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header(); receiptHeader.ReceiptNumber = receiptNumber; receiptHeader.ExpectedDeliveryHeader_RefID = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID; receiptHeader.ProvidingSupplier_RefID = procurementHeader.ProcurementOrder_Supplier_RefID; receiptHeader.LOG_RCP_Receipt_HeaderID = Guid.NewGuid(); receiptHeader.Creation_Timestamp = DateTime.Now; receiptHeader.ReceiptHeaderITL = receiptHeader.LOG_RCP_Receipt_HeaderID.ToString(); receiptHeader.IsTakenIntoStock = false; receiptHeader.Tenant_RefID = securityTicket.TenantID; receiptHeader.Save(Connection, Transaction); receiptHeaderID = receiptHeader.LOG_RCP_Receipt_HeaderID; var receipt2sProcurementHeader = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader(); receipt2sProcurementHeader.LOG_RCP_Receipt_Header_RefID = receiptHeaderID; receipt2sProcurementHeader.ORD_PRO_ProcurementOrder_Header_RefID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID; receipt2sProcurementHeader.Tenant_RefID = securityTicket.TenantID; receipt2sProcurementHeader.IsDeleted = false; receipt2sProcurementHeader.Creation_Timestamp = DateTime.Now; receipt2sProcurementHeader.Save(Connection, Transaction); } else { receiptHeaderID = receiptToProcurementHeader.LOG_RCP_Receipt_Header_RefID; } var receiptPositions = CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position.Query.Search(Connection, Transaction, new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Receipt_Header_RefID = receiptHeaderID }); #endregion foreach (var position in foundProcurementPositions) { #region Expected Delivery CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Position deliveryPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Position(); deliveryPosition.ORD_PRC_ExpectedDelivery_PositionID = Guid.NewGuid(); deliveryPosition.AlreadyReceivedQuantityOfDelivery = 0; deliveryPosition.ExpectedDeliveryPositionITL = deliveryPosition.ORD_PRC_ExpectedDelivery_PositionID.ToString(); deliveryPosition.TotalExpectedQuantity = position.Position_Quantity; deliveryPosition.ORD_PRC_ExpectedDelivery_RefID = headerID; deliveryPosition.Tenant_RefID = securityTicket.TenantID; deliveryPosition.IsDeleted = false; deliveryPosition.Creation_Timestamp = DateTime.Now; deliveryPosition.Save(Connection, Transaction); CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_2_ProcurementOrderPosition assignment = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_2_ProcurementOrderPosition(); assignment.AssignmentID = Guid.NewGuid(); assignment.ORD_PRC_ProcurementOrder_Position_RefID = position.ORD_PRC_ProcurementOrder_PositionID; assignment.ORD_PRC_ExpectedDelivery_Position_RefID = deliveryPosition.ORD_PRC_ExpectedDelivery_PositionID; assignment.AssignedQuantityFromProcurementOrderPosition = position.Position_Quantity; assignment.Tenant_RefID = securityTicket.TenantID; assignment.IsDeleted = false; assignment.Creation_Timestamp = DateTime.Now; assignment.Save(Connection, Transaction); #endregion #region Receipt Positions var receiptPosition = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position(); if (receiptPositions.Count == 0) { // create new position receiptPosition.LOG_RCP_Receipt_PositionID = Guid.NewGuid(); receiptPosition.Creation_Timestamp = DateTime.Now; receiptPosition.Tenant_RefID = securityTicket.TenantID; receiptPosition.ReceiptPositionITL = receiptPosition.LOG_RCP_Receipt_PositionID.ToString(); receiptPosition.Receipt_Header_RefID = receiptHeaderID; receiptPosition.ReceiptPosition_Product_RefID = position.CMN_PRO_Product_RefID; receiptPosition.TotalQuantityFreeOfCharge = 0.0; receiptPosition.TotalQuantityTakenIntoStock = 0.0; receiptPosition.ExpectedPositionPrice = position.Position_ValuePerUnit; receiptPosition.Save(Connection, Transaction); var receiptPosition2procurementorderposition = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition(); receiptPosition2procurementorderposition.AssignmentID = Guid.NewGuid(); receiptPosition2procurementorderposition.LOG_RCP_Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID; receiptPosition2procurementorderposition.ORD_PRO_ProcurementOrder_Position_RefID = position.ORD_PRC_ProcurementOrder_PositionID; receiptPosition2procurementorderposition.Tenant_RefID = securityTicket.TenantID; receiptPosition2procurementorderposition.Creation_Timestamp = DateTime.Now; receiptPosition2procurementorderposition.IsDeleted = false; receiptPosition2procurementorderposition.Save(Connection, Transaction); } #endregion #region Quality Control Items var qualityControlItem = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position_QualityControlItem(); if (receiptPositions.Count == 0) { qualityControlItem.LOG_RCP_Receipt_Position_QualityControlItem = Guid.NewGuid(); qualityControlItem.ReceiptPositionCountedItemITL = qualityControlItem.LOG_RCP_Receipt_Position_QualityControlItem.ToString(); qualityControlItem.Creation_Timestamp = DateTime.Now; qualityControlItem.Tenant_RefID = securityTicket.TenantID; qualityControlItem.Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID; } else { var query = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position_QualityControlItem.Query() { Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }; qualityControlItem = CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position_QualityControlItem.Query.Search(Connection, Transaction, query).Single(); } //qualityControlItem.BatchNumber = position.Position_OrdinalNumber; //qualityControlItem.ExpiryDate = position.date qualityControlItem.Quantity = position.Position_Quantity; qualityControlItem.Save(Connection, Transaction); #endregion #region Forwarding Instruction var forwardingInstruction = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction(); if (receiptPositions.Count == 0) { #region Create new var businessParticipant = CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant.Query() { IfTenant_Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); forwardingInstruction.ORD_PRC_ProcurementOrder_Position_ForwardingInstructionID = Guid.NewGuid(); forwardingInstruction.Creation_Timestamp = DateTime.Now; forwardingInstruction.Tenant_RefID = securityTicket.TenantID; forwardingInstruction.ProcurementOrder_Position_RefID = position.ORD_PRC_ProcurementOrder_PositionID; forwardingInstruction.ForwardTo_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; #endregion } else { #region Load Existing var query = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction.Query() { ProcurementOrder_Position_RefID = position.ORD_PRC_ProcurementOrder_PositionID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; forwardingInstruction = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction.Query.Search(Connection, Transaction, query).Single(); #endregion } forwardingInstruction.QuantityToForward = position.Position_Quantity; forwardingInstruction.Save(Connection, Transaction); #endregion } //returning created expected delivery header id returnValue.Result = headerID; return(returnValue); #endregion UserCode }