protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CSHfCO_1528 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); #region Get CustomerOrderHeader var customerOrderHeader = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Header(); customerOrderHeader.Load(Connection, Transaction, Parameter.CustomerOrderHeaderID); #endregion var incrNumberParam = new P_L2NR_GaIINfUA_1454() { GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.ShipmentNumber) }; var shipmentHeaderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber; var shipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); shipmentHeader.LOG_SHP_Shipment_HeaderID = Guid.NewGuid(); shipmentHeader.ShipmentHeader_Number = shipmentHeaderNumber; shipmentHeader.Tenant_RefID = securityTicket.TenantID; shipmentHeader.IsPartiallyReadyForPicking = false; shipmentHeader.IsReadyForPicking = false; shipmentHeader.HasPickingFinished = false; shipmentHeader.HasPickingStarted = false; shipmentHeader.IsShipped = false; shipmentHeader.IsBilled = false; shipmentHeader.IsPartialShippingAllowed = true; shipmentHeader.ShipmentHeader_Currency_RefID = customerOrderHeader.CustomerOrder_Currency_RefID; shipmentHeader.RecipientBusinessParticipant_RefID = customerOrderHeader.OrderingCustomer_BusinessParticipant_RefID; shipmentHeader.Shippipng_AddressUCD_RefID = customerOrderHeader.ShippingAddressUCD_RefID; shipmentHeader.Save(Connection, Transaction); if (shipmentHeader.Shippipng_AddressUCD_RefID == Guid.Empty) { var AllAddressForShipmentHeader = cls_Get_AllAddresses_for_ShipmentHeaderID.Invoke(Connection, Transaction, new P_L3SO_GAAfSHI_1612 { ShipmentHeaderID = shipmentHeader.LOG_SHP_Shipment_HeaderID }, securityTicket).Result.ToList(); var defaultAddressForOU = AllAddressForShipmentHeader.Where(x => x.hasOrganizationUnit).SingleOrDefault(x => x.IsDefault); if (defaultAddressForOU != null) { shipmentHeader.Shippipng_AddressUCD_RefID = cls_Save_Address_for_ShipmentHeaderID.Invoke(Connection, Transaction, new P_L3SO_SA_f_SHI_1535 { LOG_SHP_Shipment_HeaderID = shipmentHeader.LOG_SHP_Shipment_HeaderID, StreetName = defaultAddressForOU.Street_Name, StreetNumber = defaultAddressForOU.Street_Number, Town = defaultAddressForOU.Town, ZIP = defaultAddressForOU.ZIP, IsCompany = defaultAddressForOU.IsCompany }, securityTicket).Result; } else { var defaultAddressForCustomer = AllAddressForShipmentHeader.Where(x => !x.hasOrganizationUnit && x.IsCompany && x.IsShipping).SingleOrDefault(x => x.IsDefault); if (defaultAddressForCustomer != null) { shipmentHeader.Shippipng_AddressUCD_RefID = cls_Save_Address_for_ShipmentHeaderID.Invoke(Connection, Transaction, new P_L3SO_SA_f_SHI_1535 { LOG_SHP_Shipment_HeaderID = shipmentHeader.LOG_SHP_Shipment_HeaderID, StreetName = defaultAddressForCustomer.Street_Name, StreetNumber = defaultAddressForCustomer.Street_Number, Town = defaultAddressForCustomer.Town, ZIP = defaultAddressForCustomer.ZIP, IsCompany = defaultAddressForCustomer.IsCompany }, securityTicket).Result; } else { var defaultPersonAddress = AllAddressForShipmentHeader.Where(x => !x.IsCompany).SingleOrDefault(x => x.IsDefault); if (defaultPersonAddress != null) { shipmentHeader.Shippipng_AddressUCD_RefID = cls_Save_Address_for_ShipmentHeaderID.Invoke(Connection, Transaction, new P_L3SO_SA_f_SHI_1535 { LOG_SHP_Shipment_HeaderID = shipmentHeader.LOG_SHP_Shipment_HeaderID, StreetName = defaultPersonAddress.Street_Name, StreetNumber = defaultPersonAddress.Street_Number, Town = defaultPersonAddress.Town, ZIP = defaultPersonAddress.ZIP, IsCompany = defaultPersonAddress.IsCompany }, securityTicket).Result; } } } } var shipmentToCustomerOrderHeader = new CL1_LOG_SHP.ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader(); shipmentToCustomerOrderHeader.ORD_CUO_CustomerOrder_Header_RefID = Parameter.CustomerOrderHeaderID; shipmentToCustomerOrderHeader.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID; shipmentToCustomerOrderHeader.Tenant_RefID = securityTicket.TenantID; shipmentToCustomerOrderHeader.Save(Connection, Transaction); #region Status #region Get Current Account var account = new CL1_USR.ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); #endregion var statusCreated = CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction, new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Status.Query() { GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Created), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var shipmentStatusHistory = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_StatusHistory(); shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID; shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID = statusCreated.LOG_SHP_Shipment_StatusID; shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID; shipmentStatusHistory.Tenant_RefID = (account == null) ? Guid.Empty : account.Tenant_RefID; shipmentStatusHistory.Save(Connection, Transaction); #endregion returnValue.Result = shipmentHeader.LOG_SHP_Shipment_HeaderID; return(returnValue); #endregion UserCode }
///<summary> /// Method Invocation of wrapper classes ///<summary> protected static FR_Guid Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5CO_CSHfCO_1528 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; FR_Guid functionReturn = new FR_Guid(); 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_ShipmentHeader_for_CustomerOrderID", ex); } return(functionReturn); }
///<summary> /// Opens the connection/transaction for the given connectionString, and closes them when complete ///<summary> public static FR_Guid Invoke(string ConnectionString, P_L5CO_CSHfCO_1528 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(null, null, ConnectionString, Parameter, securityTicket)); }
///<summary> /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured ///<summary> public static FR_Guid Invoke(DbConnection Connection, DbTransaction Transaction, P_L5CO_CSHfCO_1528 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { return(Invoke(Connection, Transaction, null, Parameter, securityTicket)); }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CSHwP_1519 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Base(); #region Get CustomerOrderPositions var param = new P_L5CO_GACOPaOUDfCH_1623() { CustomerOrderHeaderID = Parameter.CustomerOrderHeaderID }; var customerOrderPositions = cls_Get_AllCustomerOrderPositions_and_OrganizationalUnitDistributions_for_CustomerOrderHeaderID.Invoke(Connection, Transaction, param, securityTicket).Result; #endregion #region Create ShipmentHeaders var orgUnit2ShipmentHeader = new Dictionary <Guid, Guid>(); var allOrganizationalUnitsInOrder = customerOrderPositions.SelectMany(i => i.OrgUnitAssigments).Select(j => j.CMN_BPT_CTM_OrganizationalUnit_RefID).Distinct(); foreach (var organizationalUnits in allOrganizationalUnitsInOrder) { var shipmentHeaderParam = new P_L5CO_CSHfCO_1528() { CustomerOrderHeaderID = Parameter.CustomerOrderHeaderID }; var shipmentHeaderID = cls_Create_ShipmentHeader_for_CustomerOrderID.Invoke(Connection, Transaction, shipmentHeaderParam, securityTicket).Result; orgUnit2ShipmentHeader.Add(organizationalUnits, shipmentHeaderID); } #endregion #region Positions if (customerOrderPositions != null) { foreach (var position in customerOrderPositions) { #region Orders for office foreach (var item in position.OrgUnitAssigments) { var shippmentHeaderID = orgUnit2ShipmentHeader[item.CMN_BPT_CTM_OrganizationalUnit_RefID]; var shipmentPosition = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Position { LOG_SHP_Shipment_PositionID = Guid.NewGuid(), LOG_SHP_Shipment_Header_RefID = shippmentHeaderID, CMN_PRO_Product_RefID = position.CMN_PRO_Product_RefID, Tenant_RefID = securityTicket.TenantID, Creation_Timestamp = DateTime.Now, QuantityToShip = item.Quantity, ShipmentPosition_PricePerUnitValueWithoutTax = position.Position_ValuePerUnit, ShipmentPosition_ValueWithoutTax = (decimal)item.Quantity * position.Position_ValuePerUnit }; shipmentPosition.Save(Connection, Transaction); var customerOrderToShipmentPosition = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition { AssignmentID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID, ORD_CUO_CustomerOrder_Position_RefID = position.ORD_CUO_CustomerOrder_PositionID, CMN_BPT_CTM_OrganizationalUnit_RefID = item.CMN_BPT_CTM_OrganizationalUnit_RefID, IsDeleted = false }; customerOrderToShipmentPosition.Save(Connection, Transaction); #region Update ShipmentHeader var shipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); shipmentHeader.Load(Connection, Transaction, shippmentHeaderID); shipmentHeader.ShipmentHeader_ValueWithoutTax += shipmentPosition.ShipmentPosition_ValueWithoutTax; shipmentHeader.Save(Connection, Transaction); #endregion } #endregion #region Orders for company var quantitiesForOffices = position.OrgUnitAssigments.Sum(i => i.Quantity); var quantitiesForCompany = position.Position_Quantity - quantitiesForOffices; if (quantitiesForCompany > 0) { var shippmentHeaderID = Guid.Empty; var containsOrderCompany = orgUnit2ShipmentHeader.ContainsKey(Guid.Empty); if (!containsOrderCompany) { var shipmentHeaderParam = new P_L5CO_CSHfCO_1528() { CustomerOrderHeaderID = Parameter.CustomerOrderHeaderID }; shippmentHeaderID = cls_Create_ShipmentHeader_for_CustomerOrderID.Invoke(Connection, Transaction, shipmentHeaderParam, securityTicket).Result; orgUnit2ShipmentHeader.Add(Guid.Empty, shippmentHeaderID); } shippmentHeaderID = orgUnit2ShipmentHeader[Guid.Empty]; var shipmentPosition = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Position { LOG_SHP_Shipment_PositionID = Guid.NewGuid(), LOG_SHP_Shipment_Header_RefID = shippmentHeaderID, CMN_PRO_Product_RefID = position.CMN_PRO_Product_RefID, Tenant_RefID = securityTicket.TenantID, Creation_Timestamp = DateTime.Now, QuantityToShip = quantitiesForCompany, ShipmentPosition_PricePerUnitValueWithoutTax = position.Position_ValuePerUnit, ShipmentPosition_ValueWithoutTax = (decimal)quantitiesForCompany * position.Position_ValuePerUnit }; shipmentPosition.Save(Connection, Transaction); var customerOrderToShipmentPosition = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition { AssignmentID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID, ORD_CUO_CustomerOrder_Position_RefID = position.ORD_CUO_CustomerOrder_PositionID, CMN_BPT_CTM_OrganizationalUnit_RefID = Guid.Empty }; customerOrderToShipmentPosition.Save(Connection, Transaction); #region Update ShipmentHeader var shipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); shipmentHeader.Load(Connection, Transaction, shippmentHeaderID); shipmentHeader.ShipmentHeader_ValueWithoutTax += shipmentPosition.ShipmentPosition_ValueWithoutTax; shipmentHeader.Save(Connection, Transaction); #endregion } #endregion } } #endregion #region Comments var allOrgUnitIDs = orgUnit2ShipmentHeader.Select(x => x.Key); foreach (var orgUnitID in allOrgUnitIDs) { var currentShipmentID = orgUnit2ShipmentHeader[orgUnitID]; var custOrderNotes = ORM_ORD_CUO_CustomerOrder_Note.Query.Search(Connection, Transaction, new ORM_ORD_CUO_CustomerOrder_Note.Query() { CustomerOrder_Header_RefID = Parameter.CustomerOrderHeaderID, CMN_BPT_CTM_OrganizationalUnit_RefID = orgUnitID, IsDeleted = false } ); foreach (var custOrderNote in custOrderNotes) { var shipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); shipmentHeader.Load(Connection, Transaction, currentShipmentID); var shipmentNote = new ORM_LOG_SHP_Shipment_Note() { LOG_SHP_Shipment_NoteID = Guid.NewGuid(), Shipment_Header_RefID = currentShipmentID, Shipment_Position_RefID = Guid.Empty, IsNotePrintedOnDeliveryPaper = true, Title = custOrderNote.Title, Comment = custOrderNote.Comment, NotePublishDate = custOrderNote.NotePublishDate, SequenceOrderNumber = custOrderNote.SequenceOrderNumber, Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, CreatedBy_BusinessParticipant_RefID = shipmentHeader.RecipientBusinessParticipant_RefID }; shipmentNote.Save(Connection, Transaction); } } #endregion return(returnValue); #endregion UserCode }