protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5SR_SRPaEDP_1406 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var queryProcurement = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query() { LOG_RCP_Receipt_Header_RefID = Parameter.ReceiptHeaderID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }; var receiptToProcurementHeader = CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query.Search(Connection, Transaction, queryProcurement).Single(); Guid procurementHeaderID = receiptToProcurementHeader.ORD_PRO_ProcurementOrder_Header_RefID; #region Positions if (Parameter.StockPositions != null) { foreach (var item in Parameter.StockPositions) { #region Receipt Positions var receiptPosition = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position(); if (item.ReceiptPositionID == Guid.Empty) { // 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 = Parameter.ReceiptHeaderID; receiptPosition.ReceiptPosition_Product_RefID = item.ProductID; } else { // load and edit existing position receiptPosition.Load(Connection, Transaction, item.ReceiptPositionID); } receiptPosition.TotalQuantityFreeOfCharge = 0.0; receiptPosition.TotalQuantityTakenIntoStock = 0.0; receiptPosition.ExpectedPositionPrice = item.UnitPrice; receiptPosition.Save(Connection, Transaction); #endregion #region Procurement Order Positions var procurementPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position(); var receiptToProcurementPosition = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition(); if (item.ReceiptPositionID == Guid.Empty) { #region Create new var query2 = new CL1_CMN_PRO.ORM_CMN_PRO_Product.Query() { CMN_PRO_ProductID = item.ProductID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; var product = CL1_CMN_PRO.ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, query2).Single(); var query3 = new CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query() { CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; var packageInfo = CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query.Search(Connection, Transaction, query3).Single(); var unitID = packageInfo.PackageContent_MeasuredInUnit_RefID; // Create procurement order position for this position procurementPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position() { ORD_PRC_ProcurementOrder_PositionID = Guid.NewGuid(), ProcurementOrder_Header_RefID = procurementHeaderID, Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, CMN_PRO_Product_RefID = item.ProductID, Position_Unit_RefID = unitID, }; receiptToProcurementPosition = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition() { AssignmentID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, ORD_PRO_ProcurementOrder_Position_RefID = procurementPosition.ORD_PRC_ProcurementOrder_PositionID, LOG_RCP_Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID, }; #endregion } else { #region Load existing procurement order position var query = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition.Query() { LOG_RCP_Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; receiptToProcurementPosition = CL1_LOG_RCP.ORM_LOG_RCP_ReceiptPosition_2_ProcurementOrderPosition.Query.Search(Connection, Transaction, query).Single(); var query2 = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position.Query() { ORD_PRC_ProcurementOrder_PositionID = receiptToProcurementPosition.ORD_PRO_ProcurementOrder_Position_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; procurementPosition = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position.Query.Search(Connection, Transaction, query2).Single(); #endregion } // save changed or newly created procurement position and assignment procurementPosition.Position_Quantity = item.OrderQuantity; procurementPosition.Position_ValuePerUnit = item.UnitPrice; procurementPosition.Position_ValueTotal = item.UnitPrice * (decimal)item.OrderQuantity; procurementPosition.Save(Connection, Transaction); receiptToProcurementPosition.ReceivedQuantityFromProcurementOrderPosition = item.OrderQuantity; receiptToProcurementPosition.Save(Connection, Transaction); #endregion #region Expected Delivery var expectedDeliveryPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Position(); var expectedDeliveryToProcurementOrderPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_2_ProcurementOrderPosition(); if (item.ReceiptPositionID == Guid.Empty) { #region Create new // get expected delivery header assigned to receipt header of this position var query2 = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header.Query { LOG_RCP_Receipt_HeaderID = receiptPosition.Receipt_Header_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; var receiptHeader = CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header.Query.Search(Connection, Transaction, query2).Single(); expectedDeliveryPosition.ORD_PRC_ExpectedDelivery_PositionID = Guid.NewGuid(); expectedDeliveryPosition.Creation_Timestamp = DateTime.Now; expectedDeliveryPosition.Tenant_RefID = securityTicket.TenantID; expectedDeliveryPosition.ORD_PRC_ExpectedDelivery_RefID = receiptHeader.ExpectedDeliveryHeader_RefID; expectedDeliveryPosition.ExpectedDeliveryPositionITL = expectedDeliveryPosition.ORD_PRC_ExpectedDelivery_PositionID.ToString(); //expectedDeliveryPosition.AlreadyReceivedQuantityOfDelivery = ? expectedDeliveryToProcurementOrderPosition.AssignmentID = Guid.NewGuid(); expectedDeliveryToProcurementOrderPosition.ORD_PRC_ExpectedDelivery_Position_RefID = expectedDeliveryPosition.ORD_PRC_ExpectedDelivery_PositionID; expectedDeliveryToProcurementOrderPosition.ORD_PRC_ProcurementOrder_Position_RefID = procurementPosition.ORD_PRC_ProcurementOrder_PositionID; expectedDeliveryToProcurementOrderPosition.Creation_Timestamp = DateTime.Now; expectedDeliveryToProcurementOrderPosition.Tenant_RefID = securityTicket.TenantID; #endregion } else { #region Load existing var query = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_2_ProcurementOrderPosition.Query() { ORD_PRC_ProcurementOrder_Position_RefID = procurementPosition.ORD_PRC_ProcurementOrder_PositionID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; expectedDeliveryToProcurementOrderPosition = CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_2_ProcurementOrderPosition.Query.Search(Connection, Transaction, query).Single(); var query2 = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Position.Query() { ORD_PRC_ExpectedDelivery_PositionID = expectedDeliveryToProcurementOrderPosition.ORD_PRC_ExpectedDelivery_Position_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; expectedDeliveryPosition = CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Position.Query.Search(Connection, Transaction, query2).Single(); #endregion } expectedDeliveryPosition.TotalExpectedQuantity = item.OrderQuantity; expectedDeliveryPosition.Save(Connection, Transaction); expectedDeliveryToProcurementOrderPosition.AssignedQuantityFromProcurementOrderPosition = procurementPosition.Position_Quantity; expectedDeliveryToProcurementOrderPosition.Save(Connection, Transaction); #endregion #region Quality Control Items var qualityControlItem = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Position_QualityControlItem(); if (item.ReceiptPositionID == Guid.Empty) { 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 = item.BatchNumber; qualityControlItem.ExpiryDate = item.ExpiryDate; qualityControlItem.Quantity = procurementPosition.Position_Quantity; qualityControlItem.Save(Connection, Transaction); #endregion #region Forwarding Instruction var forwardingInstruction = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction(); if (item.ReceiptPositionID == Guid.Empty) { #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 = procurementPosition.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 = procurementPosition.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 = procurementPosition.Position_Quantity; forwardingInstruction.Save(Connection, Transaction); #endregion } } #endregion returnValue.Result = Parameter.ReceiptHeaderID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5SR_SRH_1545 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); Guid HeaderID = Parameter.ReceiptHeaderID; 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(); bool isNew = HeaderID == Guid.Empty; var expectedDeliveryHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header(); var receiptHeader = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header(); var procurementHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header(); var receiptToProcurement = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader(); #region Receipt Header if (isNew) { 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.LOG_RCP_Receipt_HeaderID = Guid.NewGuid(); receiptHeader.Creation_Timestamp = DateTime.Now; receiptHeader.Tenant_RefID = securityTicket.TenantID; receiptHeader.ReceiptHeaderITL = receiptHeader.LOG_RCP_Receipt_HeaderID.ToString(); receiptHeader.IsTakenIntoStock = false; } else { var query = new CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header.Query { LOG_RCP_Receipt_HeaderID = Parameter.ReceiptHeaderID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; receiptHeader = CL1_LOG_RCP.ORM_LOG_RCP_Receipt_Header.Query.Search(Connection, Transaction, query).Single(); } HeaderID = receiptHeader.LOG_RCP_Receipt_HeaderID; receiptHeader.ProvidingSupplier_RefID = Parameter.SupplierID; receiptHeader.Save(Connection, Transaction); #endregion Receipt Header #region Expected Delivery Header if (isNew) { var incrNumberParam = new P_L2NR_GaIINfUA_1454() { GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.ExpectedDeliveryNumber) }; var expectedDeliveryNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber; expectedDeliveryHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header { ORD_PRC_ExpectedDelivery_HeaderID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, Creation_Timestamp = DateTime.Now, ExpectedDeliveryNumber = expectedDeliveryNumber, IsDeliveryOpen = true, IsDeliveryClosed = false, }; expectedDeliveryHeader.ExpectedDeliveryHeaderITL = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID.ToString(); // save receipt header with new expected delivery header receiptHeader.ExpectedDeliveryHeader_RefID = expectedDeliveryHeader.ORD_PRC_ExpectedDelivery_HeaderID; receiptHeader.Save(Connection, Transaction); } else { var query = new CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header.Query { ORD_PRC_ExpectedDelivery_HeaderID = receiptHeader.ExpectedDeliveryHeader_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; expectedDeliveryHeader = CL1_ORD_PRC.ORM_ORD_PRC_ExpectedDelivery_Header.Query.Search(Connection, Transaction, query).Single(); } if (Parameter.LatestDeliveryDate != null) { expectedDeliveryHeader.ExpectedDeliveryDate = Parameter.LatestDeliveryDate.Value; } expectedDeliveryHeader.Save(Connection, Transaction); #endregion Expected Delivery Header #region Procurement Order if (isNew) { procurementHeader = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header(); procurementHeader.ORD_PRC_ProcurementOrder_HeaderID = Guid.NewGuid(); procurementHeader.Creation_Timestamp = DateTime.Now; procurementHeader.Tenant_RefID = securityTicket.TenantID; procurementHeader.CreatedBy_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; procurementHeader.IsCreatedForExpectedDelivery = true; procurementHeader.ProcurementOrder_Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID; receiptToProcurement = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader(); receiptToProcurement.AssignmentID = Guid.NewGuid(); receiptToProcurement.Creation_Timestamp = DateTime.Now; receiptToProcurement.Tenant_RefID = securityTicket.TenantID; receiptToProcurement.LOG_RCP_Receipt_Header_RefID = receiptHeader.LOG_RCP_Receipt_HeaderID; receiptToProcurement.ORD_PRO_ProcurementOrder_Header_RefID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID; receiptToProcurement.Save(Connection, Transaction); } else { var query = new CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query { LOG_RCP_Receipt_Header_RefID = HeaderID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; receiptToProcurement = CL1_LOG_RCP.ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query.Search(Connection, Transaction, query).Single(); var query2 = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header.Query { ORD_PRC_ProcurementOrder_HeaderID = receiptToProcurement.ORD_PRO_ProcurementOrder_Header_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }; procurementHeader = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Header.Query.Search(Connection, Transaction, query2).Single(); } #region get status for 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; #endregion procurementHeader.Current_ProcurementOrderStatus_RefID = newProcurementOrderStatusID; procurementHeader.ProcurementOrder_Supplier_RefID = Parameter.SupplierID; procurementHeader.Save(Connection, Transaction); if (!string.IsNullOrEmpty(Parameter.ProcurementOrderStatus)) { var queryStatus = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query() { GlobalPropertyMatchingID = Parameter.ProcurementOrderStatus, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }; var status = CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Status.Query.Search(Connection, Transaction, queryStatus).Single(); var statusHistory = new ORM_ORD_PRC_ProcurementOrder_StatusHistory(); statusHistory.ORD_PRC_ProcurementOrder_StatusHistoryID = Guid.NewGuid(); statusHistory.ProcurementOrder_Header_RefID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID; statusHistory.ProcurementOrder_Status_RefID = status.ORD_PRC_ProcurementOrder_StatusID; statusHistory.IsDeleted = false; statusHistory.Tenant_RefID = securityTicket.TenantID; statusHistory.Creation_Timestamp = DateTime.Now; statusHistory.Save(Connection, Transaction); } #endregion Procurement Order returnValue.Result = HeaderID; return(returnValue); #endregion UserCode }