protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5SR_SRP_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); #region Get_StandardPrices_for_ProductIDList var priceParam = new P_L3PR_GSPfPIL_1645 { ProductIDList = Parameter.StockPositions.Select(x => x.ProductID).ToArray() }; var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result; #endregion #region ProcurementHeader var procurementHeader = ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query.Search(Connection, Transaction, new ORM_LOG_RCP_ReceiptHeader_2_ProcurementOrderHeader.Query() { LOG_RCP_Receipt_Header_RefID = Parameter.ReceiptHeaderID, IsDeleted = false }).Single(); #endregion foreach (var item in Parameter.StockPositions) { var pricePerUnit = prices.Where(i => i.ProductID == item.ProductID).Select(j => j.AbdaPrice).SingleOrDefault(); #region Receipt Header and Positions // create new position var receiptPosition = new ORM_LOG_RCP_Receipt_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; receiptPosition.TotalQuantityFreeOfCharge = 0.0; receiptPosition.TotalQuantityTakenIntoStock = 0.0; receiptPosition.ExpectedPositionPrice = pricePerUnit; receiptPosition.Save(Connection, Transaction); #endregion #region Procurement Order Positions var product = CL1_CMN_PRO.ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new CL1_CMN_PRO.ORM_CMN_PRO_Product.Query() { CMN_PRO_ProductID = item.ProductID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).Single(); var packageInfo = CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query.Search(Connection, Transaction, new CL1_CMN_PRO_PAC.ORM_CMN_PRO_PAC_PackageInfo.Query() { CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).Single(); var procurementPosition = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position() { ORD_PRC_ProcurementOrder_PositionID = Guid.NewGuid(), ProcurementOrder_Header_RefID = procurementHeader.ORD_PRO_ProcurementOrder_Header_RefID, CMN_PRO_Product_RefID = item.ProductID, Position_Unit_RefID = packageInfo.PackageContent_MeasuredInUnit_RefID, Position_Quantity = item.OrderQuantity, Position_ValuePerUnit = pricePerUnit, Position_ValueTotal = pricePerUnit * (decimal)item.OrderQuantity, IsBonusDelivery_WasNotOrdered = true, Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, }; procurementPosition.Save(Connection, Transaction); var 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, ReceivedQuantityFromProcurementOrderPosition = item.OrderQuantity }; receiptToProcurementPosition.Save(Connection, Transaction); #endregion #region Forwarding Instruction var forwardingInstruction = new CL1_ORD_PRC.ORM_ORD_PRC_ProcurementOrder_Position_ForwardingInstruction(); 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; forwardingInstruction.QuantityToForward = 0; forwardingInstruction.Save(Connection, Transaction); #endregion } return(returnValue); #endregion UserCode }
protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L6CN_SCNwSRaQCI_0739 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Bool(); #region Get Preloading Data #region Get StandardPrices for Products var priceParam = new P_L3PR_GSPfPIL_1645 { ProductIDList = Parameter.Positions.Select(p => p.ProductId).ToArray() }; var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result; #endregion #endregion #region Create Receipt Header var resultReceiptHeader = cls_Save_StockReceiptHeader.Invoke( Connection, Transaction, new P_L5SR_SRH_1545() { ReceiptHeaderID = Guid.Empty, SupplierID = Parameter.SupplierID }, securityTicket); if (resultReceiptHeader.Result == Guid.Empty) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = false; return(returnValue); } #endregion #region Create Receipt positions for Receipt header var receiptPositions = new List <P_L5RS_CNfRS_1119a>(); foreach (var position in Parameter.Positions) { #region Get Preloading Data #region Get Performed By Account var performedByBusinessParticipant = new ORM_USR_Account(); performedByBusinessParticipant.Load(Connection, Transaction, securityTicket.AccountID); if (performedByBusinessParticipant.BusinessParticipant_RefID == Guid.Empty) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = false; return(returnValue); } #endregion #endregion #region Create new Receipt Position object var receiptPosition = new ORM_LOG_RCP_Receipt_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 = resultReceiptHeader.Result; receiptPosition.ReceiptPosition_Product_RefID = position.ProductId; receiptPosition.TotalQuantityFreeOfCharge = 0.0; receiptPosition.TotalQuantityTakenIntoStock = position.Quantity; receiptPosition.ExpectedPositionPrice = Convert.ToDecimal(position.Quantity) * position.ValuePerUnit; receiptPosition.ExpectedPositionPrice = prices.Where(i => i.ProductID == position.ProductId).Select(j => j.AbdaPrice).SingleOrDefault(); #endregion #region Create new QualityControlItem object var qualityControlItem = new ORM_LOG_RCP_Receipt_Position_QualityControlItem(); qualityControlItem.LOG_RCP_Receipt_Position_QualityControlItem = Guid.NewGuid(); qualityControlItem.Tenant_RefID = securityTicket.TenantID; qualityControlItem.Creation_Timestamp = DateTime.Now; qualityControlItem.Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID; qualityControlItem.Quantity = position.Quantity; qualityControlItem.BatchNumber = position.BatchNumber; qualityControlItem.ExpiryDate = position.ExpiryDate; qualityControlItem.Target_WRH_Shelf_RefID = position.ShelfId; qualityControlItem.QualityControl_PerformedByBusinessParticipant_RefID = performedByBusinessParticipant.BusinessParticipant_RefID; qualityControlItem.ReceiptPositionCountedItemITL = string.Empty; qualityControlItem.QualityControl_PerformedAtDate = DateTime.Now; #endregion #region Save objects var resultReceiptPosition = receiptPosition.Save(Connection, Transaction); if (resultReceiptPosition.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = false; return(returnValue); } var resultQualityControlItem = qualityControlItem.Save(Connection, Transaction); if (resultQualityControlItem.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = false; return(returnValue); } #endregion receiptPositions.Add(new P_L5RS_CNfRS_1119a() { receiptPositionId = receiptPosition.LOG_RCP_Receipt_PositionID, compesationValue = qualityControlItem.Quantity * Convert.ToDouble(position.ValuePerUnit) }); } #endregion #region Place articles on stock CL3_Warehouse.Complex.Manipulation.cls_StockReceipt_IntakeConfirmation.Invoke( Connection, Transaction, new P_L3WH_SRIC_1421() { ReceiptHeaderID = resultReceiptHeader.Result, WithoutProcurement = true }, securityTicket); #endregion #region Create CreditNote var resultCreditNote = cls_Save_CreditNote_for_ReturnShipment.Invoke( Connection, Transaction, new P_L5RS_CNfRS_1119() { headerId = Parameter.CreditNoteHeaderID, headerValue = Convert.ToDecimal(receiptPositions.Sum(rp => rp.compesationValue)), receiptPositions = receiptPositions.ToArray(), returnShipmentPositions = null }, securityTicket); if (resultCreditNote.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = false; return(returnValue); } #endregion returnValue.Result = true; returnValue.Status = FR_Status.Success; return(returnValue); #endregion UserCode }