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 }
protected static FR_L5SO_SSHwP_1030 Execute(DbConnection Connection, DbTransaction Transaction, P_L5SO_SSHwP_1030 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5SO_SSHwP_1030(); returnValue.Result = new L5SO_SSHwP_1030(); var oldShipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); oldShipmentHeader.Load(Connection, Transaction, Parameter.HeaderID); var oldPositions = CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Position.Query.Search(Connection, Transaction, new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Position.Query { LOG_SHP_Shipment_Header_RefID = Parameter.HeaderID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); bool isThereAnyDifference = false; foreach (var item in Parameter.Positions) { var oldPosition = oldPositions.Single(x => x.LOG_SHP_Shipment_PositionID == item.PositionID); if (oldPosition.QuantityToShip > item.PickingQuantity) { isThereAnyDifference = true; break; } } if (!isThereAnyDifference) { throw new ShipmentHeaderException(ResultMessage.SplitShipment_ThereIsNoDifferenceBetweenNewAndOldOne); } #region Create New ShippmentHeader var incrNumberParam = new P_L2NR_GaIINfUA_1454() { GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.ShipmentNumber) }; var shipmentOrderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber; var newShipmentHeader = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Header(); newShipmentHeader.LOG_SHP_Shipment_HeaderID = Guid.NewGuid(); newShipmentHeader.ShipmentHeader_Number = shipmentOrderNumber; newShipmentHeader.Tenant_RefID = securityTicket.TenantID; newShipmentHeader.Creation_Timestamp = DateTime.Now; newShipmentHeader.IsPartialShippingAllowed = oldShipmentHeader.IsPartialShippingAllowed; newShipmentHeader.Shippipng_AddressUCD_RefID = oldShipmentHeader.Shippipng_AddressUCD_RefID; newShipmentHeader.Source_Warehouse_RefID = oldShipmentHeader.Source_Warehouse_RefID; newShipmentHeader.ShipmentPriority = oldShipmentHeader.ShipmentPriority; newShipmentHeader.ShipmentType_RefID = oldShipmentHeader.ShipmentType_RefID; newShipmentHeader.RecipientBusinessParticipant_RefID = oldShipmentHeader.RecipientBusinessParticipant_RefID; newShipmentHeader.Save(Connection, Transaction); var assignmentQuery = new CL1_LOG_SHP.ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader.Query(); assignmentQuery.LOG_SHP_Shipment_Header_RefID = oldShipmentHeader.LOG_SHP_Shipment_HeaderID; assignmentQuery.IsDeleted = false; assignmentQuery.Tenant_RefID = securityTicket.TenantID; var oldAssignment = CL1_LOG_SHP.ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader.Query.Search(Connection, Transaction, assignmentQuery).Single(); var shipmentToCustomerOrderHeader = new CL1_LOG_SHP.ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader(); shipmentToCustomerOrderHeader.ORD_CUO_CustomerOrder_Header_RefID = oldAssignment.ORD_CUO_CustomerOrder_Header_RefID; shipmentToCustomerOrderHeader.LOG_SHP_Shipment_Header_RefID = newShipmentHeader.LOG_SHP_Shipment_HeaderID; shipmentToCustomerOrderHeader.Tenant_RefID = securityTicket.TenantID; shipmentToCustomerOrderHeader.Creation_Timestamp = DateTime.Now; shipmentToCustomerOrderHeader.Save(Connection, Transaction); #region Status 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 account = new CL1_USR.ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); var shipmentStatusHistory = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_StatusHistory(); shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID = newShipmentHeader.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.Tenant_RefID; shipmentStatusHistory.Save(Connection, Transaction); #endregion #endregion var param = new P_L5SO_GSPwPaSfSH_1141() { ShippmentHeaderID = Parameter.HeaderID, LanguageID = Parameter.LanguageID }; var splittingPositions = cls_Get_ShipmentPositions_with_Prices_and_Stock_for_ShipmentHeaderID.Invoke(Connection, Transaction, param, securityTicket).Result; decimal totalAmountForOldHeader = 0; decimal totalAmountForNewHeader = 0; foreach (var item in Parameter.Positions) { var oldPosition = oldPositions.Single(x => x.LOG_SHP_Shipment_PositionID == item.PositionID); var newQuantity = oldPosition.QuantityToShip - item.PickingQuantity; var positionToSplit = splittingPositions.Single(x => x.ShipmentPositionID == item.PositionID); var availableQuantity = positionToSplit.QuantityAvailable; decimal unitPrice = oldPosition.ShipmentPosition_PricePerUnitValueWithoutTax; if (item.PickingQuantity > availableQuantity + positionToSplit.ReservedQuantity) { throw new ShipmentHeaderException(ResultMessage.SplitShipment_FreeQuantityNotAvailable); } if (newQuantity > 0) { var newPosition = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Position { LOG_SHP_Shipment_PositionID = Guid.NewGuid(), LOG_SHP_Shipment_Header_RefID = newShipmentHeader.LOG_SHP_Shipment_HeaderID, Tenant_RefID = securityTicket.TenantID, CMN_PRO_Product_RefID = oldPosition.CMN_PRO_Product_RefID, QuantityToShip = newQuantity, ShipmentPosition_PricePerUnitValueWithoutTax = unitPrice, ShipmentPosition_ValueWithoutTax = unitPrice * (decimal)newQuantity }; newPosition.Save(Connection, Transaction); totalAmountForNewHeader += newPosition.ShipmentPosition_ValueWithoutTax; var oldAssignmentCustomerOrderToShipmentPosition = CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query.Search(Connection, Transaction, new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition.Query { LOG_SHP_Shipment_Position_RefID = oldPosition.LOG_SHP_Shipment_PositionID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).Single(); var customerOrder2ShipmentPosition = new CL1_ORD_CUO.ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition { AssignmentID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, IsDeleted = false, LOG_SHP_Shipment_Position_RefID = newPosition.LOG_SHP_Shipment_PositionID, ORD_CUO_CustomerOrder_Position_RefID = oldAssignmentCustomerOrderToShipmentPosition.ORD_CUO_CustomerOrder_Position_RefID, CMN_BPT_CTM_OrganizationalUnit_RefID = oldAssignmentCustomerOrderToShipmentPosition.CMN_BPT_CTM_OrganizationalUnit_RefID }; customerOrder2ShipmentPosition.Save(Connection, Transaction); } oldPosition.QuantityToShip = item.PickingQuantity; oldPosition.ShipmentPosition_ValueWithoutTax = unitPrice * (decimal)item.PickingQuantity; oldPosition.IsDeleted = (oldPosition.QuantityToShip == 0); oldPosition.Save(Connection, Transaction); totalAmountForOldHeader += oldPosition.ShipmentPosition_ValueWithoutTax; } oldShipmentHeader.ShipmentHeader_ValueWithoutTax = totalAmountForOldHeader; oldShipmentHeader.Save(Connection, Transaction); newShipmentHeader.ShipmentHeader_ValueWithoutTax = totalAmountForNewHeader; newShipmentHeader.Save(Connection, Transaction); // set return value to ok and new header's id returnValue.Result.NewHeaderID = newShipmentHeader.LOG_SHP_Shipment_HeaderID; returnValue.Result.Message = CL5_APOLogistic_ShippingOrder.Utils.ResultMessage.SplitShipment_OK; return(returnValue); #endregion UserCode }