protected static FR_L6SO_IPCA_1039 Execute(DbConnection Connection, DbTransaction Transaction, P_L6SO_IPCA_1039 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6SO_IPCA_1039(); returnValue.Result = new L6SO_IPCA_1039(); #region Check Header var shipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); shipmentHeader.Load(Connection, Transaction, Parameter.LOG_SHP_Shipment_HeaderID); if (shipmentHeader.IsReadyForPicking == false) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = true; returnValue.Result.IfPickingControlNotAllowed_Reason = "IsReadyForPicking == false"; return(returnValue); } if (shipmentHeader.IsManuallyCleared_ForPicking == false) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = true; returnValue.Result.IfPickingControlNotAllowed_Reason = "IsManuallyCleared_ForPicking == false"; return(returnValue); } if (shipmentHeader.HasPickingStarted == false) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = true; returnValue.Result.IfPickingControlNotAllowed_Reason = "HasPickingStarted == false"; return(returnValue); } if (shipmentHeader.HasPickingFinished == true) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = false; returnValue.Result.IfPickingControlNotAllowed_Reason = "HasPickingFinished == true"; return(returnValue); } if (shipmentHeader.IsShipped == true) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = false; returnValue.Result.IfPickingControlNotAllowed_Reason = "IsShipped == true"; return(returnValue); } if (shipmentHeader.IsBilled == true) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = false; returnValue.Result.IfPickingControlNotAllowed_Reason = "IsBilled == true"; return(returnValue); } #endregion #region Check Positions var shipmentPositions = ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Position.Query() { LOG_SHP_Shipment_Header_RefID = Parameter.LOG_SHP_Shipment_HeaderID, IsDeleted = false }); if (shipmentPositions.Count() == 0) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = false; returnValue.Result.IfPickingControlNotAllowed_Reason = "shipmentPositions.Count() == 0"; return(returnValue); } foreach (var shipmentPosition in shipmentPositions) { var quantityToShip = shipmentPosition.QuantityToShip; var reservations = ORM_LOG_RSV_Reservation.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation.Query() { LOG_SHP_Shipment_Position_RefID = shipmentPosition.LOG_SHP_Shipment_PositionID, IsReservationExecuted = false, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); var reservedQuantity = reservations.Sum(i => i.ReservedQuantity); if (quantityToShip != reservedQuantity || reservedQuantity == 0) { returnValue.Result.IsPickingControlAllowed = false; returnValue.Result.IfPickingControlNotAllowed_ResetShipmentFlags = true; returnValue.Result.IfPickingControlNotAllowed_Reason = String.Format("Shipment position {0} with quantity {1}, has {2} reserved quantity", shipmentPosition.LOG_SHP_Shipment_PositionID.ToString(), shipmentPosition.QuantityToShip, reservedQuantity); return(returnValue); } } #endregion returnValue.Result.IsPickingControlAllowed = true; return(returnValue); #endregion UserCode }
private static List <ORM_LOG_SHP_Shipment_Header> Search(Query query, string connectionString, DbConnection connection, DbTransaction transaction) { CSV2Core.Core.Interfaces.IManagedConnection managedConnection = new CSV2Core_MySQL.MySQLManagedConnection(); List <ORM_LOG_SHP_Shipment_Header> items; try { managedConnection.set(connectionString, connection, transaction); var loader = new CSV2Core_MySQL.Dictionaries.MultiTable.Loader.DictionaryLoader(managedConnection.getConnection(), managedConnection.getTransaction()); DbCommand command = managedConnection.manage(query.CreateSelectQuery(TableName)); query.SetParameters(command); items = new List <ORM_LOG_SHP_Shipment_Header>(); var reader = new CSV2Core_MySQL.Support.DBSQLReader(command.ExecuteReader()); reader.SetOrdinals(new string[] { "LOG_SHP_Shipment_HeaderID", "RecipientBusinessParticipant_RefID", "Source_Warehouse_RefID", "ShipmentType_RefID", "ShipmentHeaderITL", "ShipmentHeader_Number", "Shippipng_AddressUCD_RefID", "IsPartiallyReadyForPicking", "IsReadyForPicking", "HasPickingStarted", "HasPickingFinished", "IsShipped", "IsBilled", "DemandDate", "ShipmentPriority", "IsPartialShippingAllowed", "IsManuallyCleared_ForPicking", "ShipmentHeader_ValueWithoutTax", "ShipmentHeader_Currency_RefID", "IsCustomerReturnShipment", "Creation_Timestamp", "Tenant_RefID", "IsDeleted" }); while (reader.Read()) { ORM_LOG_SHP_Shipment_Header item = new ORM_LOG_SHP_Shipment_Header(); //0:Parameter LOG_SHP_Shipment_HeaderID of type Guid item.LOG_SHP_Shipment_HeaderID = reader.GetGuid(0); //1:Parameter RecipientBusinessParticipant_RefID of type Guid item.RecipientBusinessParticipant_RefID = reader.GetGuid(1); //2:Parameter Source_Warehouse_RefID of type Guid item.Source_Warehouse_RefID = reader.GetGuid(2); //3:Parameter ShipmentType_RefID of type Guid item.ShipmentType_RefID = reader.GetGuid(3); //4:Parameter ShipmentHeaderITL of type String item.ShipmentHeaderITL = reader.GetString(4); //5:Parameter ShipmentHeader_Number of type String item.ShipmentHeader_Number = reader.GetString(5); //6:Parameter Shippipng_AddressUCD_RefID of type Guid item.Shippipng_AddressUCD_RefID = reader.GetGuid(6); //7:Parameter IsPartiallyReadyForPicking of type Boolean item.IsPartiallyReadyForPicking = reader.GetBoolean(7); //8:Parameter IsReadyForPicking of type Boolean item.IsReadyForPicking = reader.GetBoolean(8); //9:Parameter HasPickingStarted of type Boolean item.HasPickingStarted = reader.GetBoolean(9); //10:Parameter HasPickingFinished of type Boolean item.HasPickingFinished = reader.GetBoolean(10); //11:Parameter IsShipped of type Boolean item.IsShipped = reader.GetBoolean(11); //12:Parameter IsBilled of type Boolean item.IsBilled = reader.GetBoolean(12); //13:Parameter DemandDate of type DateTime item.DemandDate = reader.GetDate(13); //14:Parameter ShipmentPriority of type int item.ShipmentPriority = reader.GetInteger(14); //15:Parameter IsPartialShippingAllowed of type Boolean item.IsPartialShippingAllowed = reader.GetBoolean(15); //16:Parameter IsManuallyCleared_ForPicking of type Boolean item.IsManuallyCleared_ForPicking = reader.GetBoolean(16); //17:Parameter ShipmentHeader_ValueWithoutTax of type Decimal item.ShipmentHeader_ValueWithoutTax = reader.GetDecimal(17); //18:Parameter ShipmentHeader_Currency_RefID of type Guid item.ShipmentHeader_Currency_RefID = reader.GetGuid(18); //19:Parameter IsCustomerReturnShipment of type Boolean item.IsCustomerReturnShipment = reader.GetBoolean(19); //20:Parameter Creation_Timestamp of type DateTime item.Creation_Timestamp = reader.GetDate(20); //21:Parameter Tenant_RefID of type Guid item.Tenant_RefID = reader.GetGuid(21); //22:Parameter IsDeleted of type Boolean item.IsDeleted = reader.GetBoolean(22); item.Status_IsAlreadySaved = true; item.Status_IsDirty = false; items.Add(item); } reader.Close(); loader.Load(); managedConnection.commit(); } catch (Exception ex) { managedConnection.rollback(); throw; } return(items); }
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 }