protected static FR_L5RS_CSaRSPfH_0449 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSPfH_0449 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5RS_CSaRSPfH_0449(); returnValue.Result = new L5RS_CSaRSPfH_0449(); FR_Base resultHeader, resultPosition, resultReturnPosition; if (Parameter.Positions.Count() <= 0) { returnValue.Status = FR_Status.Success; returnValue.Result = null; return(returnValue); } #region Load Shipment Header and calculate Total Price decimal totalValueWithoutTax = 0; #region Load Shipment Header var shipmentHeader = new ORM_LOG_SHP_Shipment_Header(); var result = shipmentHeader.Load(Connection, Transaction, Parameter.Positions[0].ShipmentHeaderID); if (result.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion #region Load Shipment Header Positions And Calculate Total Value var shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search( Connection, Transaction, new ORM_LOG_SHP_Shipment_Position.Query() { LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID, Tenant_RefID = securityTicket.TenantID }).ToList(); foreach (var position in shipmentPositions) { totalValueWithoutTax += position.ShipmentPosition_ValueWithoutTax; } #endregion shipmentHeader.ShipmentHeader_ValueWithoutTax = totalValueWithoutTax; #endregion var resultShipmentPositionsIDs = new List <Guid>(); var resultReturnShipmentPositionIDs = new List <Guid>(); foreach (P_L5RS_CSaRSPfH_0449a position in Parameter.Positions) { #region Create Shipment Position Object var newShipmentPositionObject = new ORM_LOG_SHP_Shipment_Position(); newShipmentPositionObject.CMN_PRO_Product_RefID = position.ProductId; newShipmentPositionObject.Creation_Timestamp = DateTime.Now; newShipmentPositionObject.LOG_SHP_Shipment_Header_RefID = position.ShipmentHeaderID; newShipmentPositionObject.LOG_SHP_Shipment_PositionID = Guid.NewGuid(); newShipmentPositionObject.QuantityToShip = position.Quantity; newShipmentPositionObject.ShipmentPosition_ValueWithoutTax = position.PricePerUnit * position.Quantity; newShipmentPositionObject.ShipmentPosition_PricePerUnitValueWithoutTax = position.PricePerUnit; newShipmentPositionObject.Tenant_RefID = securityTicket.TenantID; shipmentHeader.ShipmentHeader_ValueWithoutTax += newShipmentPositionObject.ShipmentPosition_ValueWithoutTax; #endregion #region Create ReturnShipment Position Object var newReturnShipmentPositionObject = new ORM_LOG_SHP_ReturnShipment_Position(); newReturnShipmentPositionObject.Creation_Timestamp = DateTime.Now; newReturnShipmentPositionObject.Ext_Shipment_Position_RefID = newShipmentPositionObject.LOG_SHP_Shipment_PositionID; newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID = Guid.NewGuid(); newReturnShipmentPositionObject.ReturnPolicy_RefID = position.ReturnPolicyId; newReturnShipmentPositionObject.ReturnProductOriginatedFromReceiptPosition_RefID = position.ReceiptPositionId; newReturnShipmentPositionObject.ReturnShipment_Header_RefID = position.ReturnShipmentHeaderID; newReturnShipmentPositionObject.Tenant_RefID = securityTicket.TenantID; #endregion #region Save Position resultPosition = newShipmentPositionObject.Save(Connection, Transaction); resultReturnPosition = newReturnShipmentPositionObject.Save(Connection, Transaction); if (resultPosition.Status != FR_Status.Success || resultReturnPosition.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } resultShipmentPositionsIDs.Add(newShipmentPositionObject.LOG_SHP_Shipment_PositionID); resultReturnShipmentPositionIDs.Add(newReturnShipmentPositionObject.LOG_SHP_ReturnShipment_PositionID); #endregion } #region Update Shipment Header with Total Value resultHeader = shipmentHeader.Save(Connection, Transaction); if (resultHeader.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion #region Fetch ShipmentHeader SupplierName var supplierBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant(); supplierBusinessParticipant.Load(Connection, Transaction, shipmentHeader.RecipientBusinessParticipant_RefID); #endregion returnValue.Status = FR_Status.Success; returnValue.Result.ShipmentPositionIDs = resultShipmentPositionsIDs.ToArray(); returnValue.Result.ReturnShipmentPositionIDs = resultReturnShipmentPositionIDs.ToArray(); returnValue.Result.ShipmentHeaderSupplierName = supplierBusinessParticipant == null ? string.Empty : supplierBusinessParticipant.DisplayName; returnValue.Result.ShipmentHeaderNumber = shipmentHeader.ShipmentHeader_Number; returnValue.Result.ShipmentHeaderTotalValue = shipmentHeader.ShipmentHeader_ValueWithoutTax; return(returnValue); #endregion UserCode }
///<summary> /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured ///<summary> public static FR_L5RS_CSaRSPfH_0449 Invoke(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSPfH_0449 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(Connection, Transaction, null, Parameter, securityTicket)); }
///<summary> /// Method Invocation of wrapper classes ///<summary> protected static FR_L5RS_CSaRSPfH_0449 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5RS_CSaRSPfH_0449 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; FR_L5RS_CSaRSPfH_0449 functionReturn = new FR_L5RS_CSaRSPfH_0449(); try { if (cleanupConnection == true) { Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString); Connection.Open(); } if (cleanupTransaction == true) { Transaction = Connection.BeginTransaction(); } functionReturn = Execute(Connection, Transaction, Parameter, securityTicket); #region Cleanup Connection/Transaction //Commit the transaction if (cleanupTransaction == true) { Transaction.Commit(); } //Close the connection if (cleanupConnection == true) { Connection.Close(); } #endregion } catch (Exception ex) { try { if (cleanupTransaction == true && Transaction != null) { Transaction.Rollback(); } } catch { } try { if (cleanupConnection == true && Connection != null) { Connection.Close(); } } catch { } throw new Exception("Exception occured in method cls_Create_Shipment_and_ReturnShipment_Positions_for_HeaderID", ex); } return(functionReturn); }
///<summary> /// Opens the connection/transaction for the given connectionString, and closes them when complete ///<summary> public static FR_L5RS_CSaRSPfH_0449 Invoke(string ConnectionString, P_L5RS_CSaRSPfH_0449 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(null, null, ConnectionString, Parameter, securityTicket)); }