protected static FR_L5RS_CRSH_1332_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CRSH_1332 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5RS_CRSH_1332_Array(); var results = new List <L5RS_CRSH_1332>(); var contentAdjustments = new List <P_L3WH_SSCA_1732a>(); var deleteReservationsParam = new List <P_L3SO_DARaUSHfPTIL_1159a>(); foreach (var inputHeader in Parameter.ReturnShipmentHeaders) { #region Create New Shipment and ReturnShipment Headers var createShipmentandReturnShipmentHeaderParam = new P_L5RS_CSaRSH_0244() { SupplierID = inputHeader.SupplierID }; var resultHeadersCreation = cls_Create_Shipment_and_ReturnShipment_Header.Invoke(Connection, Transaction, createShipmentandReturnShipmentHeaderParam, securityTicket); if (resultHeadersCreation.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion #region Create New Shipment and ReturnShipment Positions var positionsParam = new List <P_L5RS_CRSP_1405a>(); foreach (var inputPosition in inputHeader.ReturnShipmentPositions) { var position = new P_L5RS_CRSP_1405a(); position.ShipmentHeaderID = resultHeadersCreation.Result.ShipmentHeaderID; position.ReturnShipmentHeaderID = resultHeadersCreation.Result.ReturnShipmentHeaderID; position.ProductID = inputPosition.ProductID; position.Quantity = inputPosition.Quantity;; position.PricePerUnit = inputPosition.PricePerUnit; position.ReturnPolicyID = inputPosition.ReturnPolicyID; position.ReceiptPositionID = inputPosition.ReceiptPositionID; positionsParam.Add(position); } var createPositionsParam = new P_L5RS_CRSP_1405() { Positions = positionsParam.ToArray() }; var resultPositionsCreation = cls_Create_ReturnShipment_Positions.Invoke(Connection, Transaction, createPositionsParam, securityTicket); if (resultPositionsCreation.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion #region Create New ContentAdjustments and DeleteReservatins parameters foreach (var inputPosition in inputHeader.ReturnShipmentPositions) { var productTrackingInstance = new ORM_LOG_ProductTrackingInstance(); productTrackingInstance.Load(Connection, Transaction, inputPosition.ProductTrackingInstanceID); var savedPosition = resultPositionsCreation.Result.Positions.Single(i => i.ProductID == inputPosition.ProductID && i.ReceiptPositionID == inputPosition.ReceiptPositionID); var paramContentAdjustment = new P_L3WH_SSCA_1732a(); paramContentAdjustment.AdjustedQuantity = productTrackingInstance.CurrentQuantityOnTrackingInstance - inputPosition.Quantity; paramContentAdjustment.IsManualCorrection = true; paramContentAdjustment.IfManualCorrection_InventoryChangeReason_RefID = inputPosition.ReturnPolicyID; paramContentAdjustment.IsShipmentWithdrawal = true; paramContentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID = savedPosition.ShipmentPositionID; paramContentAdjustment.ProductID = inputPosition.ProductID; paramContentAdjustment.ShelfContentID = inputPosition.ShelfContentID; paramContentAdjustment.TrackingInstanceID = inputPosition.ProductTrackingInstanceID; contentAdjustments.Add(paramContentAdjustment); deleteReservationsParam.Add(new P_L3SO_DARaUSHfPTIL_1159a() { ProductTrackingInstanceID = inputPosition.ProductTrackingInstanceID, RemovedQuantityFromTrackingInstance = inputPosition.Quantity, CurrentQuantityOnTrackingInstance = productTrackingInstance.CurrentQuantityOnTrackingInstance }); } #endregion var result = new L5RS_CRSH_1332() { ShipmentHeaderNumber = resultPositionsCreation.Result.ShipmentHeaderNumber, ShipmentHeaderTotalValue = resultPositionsCreation.Result.ShipmentHeaderTotalValue, ShipmentHeaderSupplierName = resultPositionsCreation.Result.ShipmentHeaderSupplierName }; results.Add(result); } #region ClearReservations var deleteResParam = new P_L3SO_DARaUSHfPTIL_1159() { TracknigInstances = deleteReservationsParam.ToArray() }; cls_Delete_ActiveReservations_and_UpdateShipmentHeaders_for_ProductTrackingInstanceIDList.Invoke(Connection, Transaction, deleteResParam, securityTicket); #endregion #region Save ShelfContentAdjustments P_L3WH_SSCA_1732 paramContent = new P_L3WH_SSCA_1732(); paramContent.Adjustments = contentAdjustments.ToArray(); var resultContentAdjustments = cls_Save_Shelf_ContentAdjustments.Invoke(Connection, Transaction, paramContent, securityTicket); if (resultContentAdjustments.Status != FR_Status.Success || resultContentAdjustments.Result == false) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion returnValue.Status = FR_Status.Success; returnValue.Result = results.ToArray(); return(returnValue); #endregion UserCode }
protected static FR_L6SO_FPC_1548 Execute(DbConnection Connection, DbTransaction Transaction, P_L6SO_FPC_1548 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6SO_FPC_1548(); returnValue.Result = new L6SO_FPC_1548(); #region Validation var isAllowedParam = new P_L6SO_IPCA_1039() { LOG_SHP_Shipment_HeaderID = Parameter.LOG_SHP_Shipment_HeaderID }; var validationResult = cls_Is_PickingControlAllowed.Invoke(Connection, Transaction, isAllowedParam, securityTicket).Result; if (!validationResult.IsPickingControlAllowed) { if (validationResult.IfPickingControlNotAllowed_ResetShipmentFlags) { var updateHeaderParam = new P_L3SO_USHSaDARfSH_1054() { ShipmentHeaderID = Parameter.LOG_SHP_Shipment_HeaderID }; var result = cls_Update_ShipmentHeaderStatus_and_DeleteActiveReservations_for_ShipmentHeaderID.Invoke(Connection, Transaction, updateHeaderParam, securityTicket).Result; if (result) { returnValue.Result.Status = EPickingControlStatus.Error_InconsistentData; } else { returnValue.Result.Status = EPickingControlStatus.Error_AlreadyFinished; } } else { returnValue.Result.Status = EPickingControlStatus.Error_AlreadyFinished; } return(returnValue); } #endregion #region GetAllShippingorderPositions var positions = 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 }); #endregion foreach (var position in positions) { var reservations = ORM_LOG_RSV_Reservation.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation.Query() { LOG_SHP_Shipment_Position_RefID = position.LOG_SHP_Shipment_PositionID, IsReservationExecuted = false, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); #region Update Contents and positions foreach (var reservation in reservations) { reservation.IsReservationExecuted = true; reservation.Save(Connection, Transaction); #region Shelf Conent var shelfContent = new ORM_LOG_WRH_Shelf_Content(); shelfContent.Load(Connection, Transaction, reservation.LOG_WRH_Shelf_Content_RefID); shelfContent.Quantity_Current -= reservation.ReservedQuantity; shelfContent.Save(Connection, Transaction); #endregion #region Shelf Content Adjustments var contentAdjustment = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment(); contentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID = Guid.NewGuid(); contentAdjustment.ShelfContent_RefID = shelfContent.LOG_WRH_Shelf_ContentID; contentAdjustment.QuantityChangedAmount = -reservation.ReservedQuantity;; contentAdjustment.QuantityChangedDate = DateTime.Now; contentAdjustment.IsInitialReceipt = false; contentAdjustment.IsInventoryJobCorrection = false; contentAdjustment.IsShipmentWithdrawal = false; contentAdjustment.IsManualCorrection = false; contentAdjustment.IsShipmentWithdrawal = true; contentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID = reservation.LOG_SHP_Shipment_Position_RefID; contentAdjustment.PerformedBy_Account_RefID = securityTicket.AccountID; contentAdjustment.PerformedAt_Date = DateTime.Now; contentAdjustment.ContentAdjustmentComment = "Product is being moved from the shelf after picking control"; contentAdjustment.Tenant_RefID = securityTicket.TenantID; contentAdjustment.Creation_Timestamp = DateTime.Now; contentAdjustment.Save(Connection, Transaction); #endregion #region Reservation TrackingInstance var reservationTrackingInstance = ORM_LOG_RSV_Reservation_TrackingInstance.Query.Search(Connection, Transaction, new ORM_LOG_RSV_Reservation_TrackingInstance.Query() { LOG_RSV_Reservation_RefID = reservation.LOG_RSV_ReservationID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).SingleOrDefault(); if (reservationTrackingInstance != default(ORM_LOG_RSV_Reservation_TrackingInstance)) { var trackingInstance = new ORM_LOG_ProductTrackingInstance(); trackingInstance.Load(Connection, Transaction, reservationTrackingInstance.LOG_ProductTrackingInstance_RefID); trackingInstance.CurrentQuantityOnTrackingInstance -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance; trackingInstance.R_FreeQuantity -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance; trackingInstance.R_ReservedQuantity -= reservationTrackingInstance.ReservedQuantityFromTrackingInstance; trackingInstance.Save(Connection, Transaction); #region ORM_LOG_ProductTrackingInstance_HistoryEntry var trackingInstanceHistory = new CL1_LOG.ORM_LOG_ProductTrackingInstance_HistoryEntry(); trackingInstanceHistory.LOG_ProductTrackingInstance_HistoryEntryID = Guid.NewGuid(); trackingInstanceHistory.ProductTrackingInstance_RefID = trackingInstance.LOG_ProductTrackingInstanceID; trackingInstanceHistory.HistoryEntry_Text = "Products are being removed from the shelf after picking control finish"; trackingInstanceHistory.Creation_Timestamp = DateTime.Now; trackingInstanceHistory.Tenant_RefID = securityTicket.TenantID; trackingInstanceHistory.Save(Connection, Transaction); #endregion #region ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance var adjustment2tracking = new CL1_LOG_WRH.ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance(); adjustment2tracking.LOG_WRH_Shelf_ContentAdjustment_TrackingInstanceID = Guid.NewGuid(); adjustment2tracking.LOG_ProductTrackingInstance_RefID = trackingInstance.LOG_ProductTrackingInstanceID; adjustment2tracking.LOG_WRH_Shelf_ContentAdjustment_RefID = contentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID; adjustment2tracking.QuantityChangedAmount = -reservation.ReservedQuantity; adjustment2tracking.Creation_Timestamp = DateTime.Now; adjustment2tracking.Tenant_RefID = securityTicket.TenantID; adjustment2tracking.Save(Connection, Transaction); #endregion } #endregion } #endregion } #region Change ShipmentOrderStatus Status var parameter = new P_L5SO_CSOS_1148(); parameter.LOG_SHP_Shipment_HeaderID = Parameter.LOG_SHP_Shipment_HeaderID; parameter.HasPickingFinished = true; parameter.IsShipped = true; cls_Change_ShippigOrderHeader_Status.Invoke(Connection, Transaction, parameter, securityTicket); #endregion returnValue.Result.Status = EPickingControlStatus.Finished; return(returnValue); #endregion UserCode }
protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5SG_SSCR_1048 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Bool(); //Put your code here foreach (var adjustment in Parameter.Adjustments) { var currentShelfContetnAdjustment = new ORM_LOG_WRH_Shelf_ContentAdjustment(); var currentshelfContent = new ORM_LOG_WRH_Shelf_Content(); var destinationShelfContent = new ORM_LOG_WRH_Shelf_Content(); var destinationShelf = new ORM_LOG_WRH_Shelf(); currentshelfContent.Load(Connection, Transaction, adjustment.ShelfContentID); currentShelfContetnAdjustment = ORM_LOG_WRH_Shelf_ContentAdjustment.Query.Search( Connection, Transaction, new ORM_LOG_WRH_Shelf_ContentAdjustment.Query() { ShelfContent_RefID = currentshelfContent.LOG_WRH_Shelf_ContentID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).FirstOrDefault(); destinationShelfContent.Tenant_RefID = securityTicket.TenantID; destinationShelfContent.Shelf_RefID = adjustment.DestinationShelf; destinationShelfContent.Product_RefID = adjustment.ProductID; destinationShelfContent.LOG_WRH_Shelf_ContentID = Guid.NewGuid(); var destinationShelfContentID = new FR_Guid(destinationShelfContent.Save(Connection, Transaction), destinationShelfContent.LOG_WRH_Shelf_ContentID).Result; var destinationShelfContentTrackingInstance = new ORM_LOG_ProductTrackingInstance(); var sourceShelfContentTrackingInstance = new ORM_LOG_ProductTrackingInstance(); if (adjustment.TrackingInstanceID != null && adjustment.TrackingInstanceID != Guid.Empty) { sourceShelfContentTrackingInstance.Load(Connection, Transaction, adjustment.TrackingInstanceID); destinationShelfContentTrackingInstance.ExpirationDate = sourceShelfContentTrackingInstance.ExpirationDate; destinationShelfContentTrackingInstance.BatchNumber = sourceShelfContentTrackingInstance.BatchNumber; destinationShelfContentTrackingInstance.Tenant_RefID = securityTicket.TenantID; destinationShelfContentTrackingInstance.TrackingCode = String.Empty; destinationShelfContentTrackingInstance.CMN_PRO_Product_RefID = adjustment.ProductID; destinationShelfContentTrackingInstance.LOG_ProductTrackingInstanceID = Guid.NewGuid(); var destinationShelfContentTrackingInstanceID = new FR_Guid(destinationShelfContentTrackingInstance.Save(Connection, Transaction), destinationShelfContentTrackingInstance.LOG_ProductTrackingInstanceID).Result; var historyEntry = new ORM_LOG_ProductTrackingInstance_HistoryEntry(); historyEntry.LOG_ProductTrackingInstance_HistoryEntryID = Guid.NewGuid(); historyEntry.ProductTrackingInstance_RefID = destinationShelfContentTrackingInstanceID; historyEntry.Tenant_RefID = securityTicket.TenantID; historyEntry.HistoryEntry_Text = "Transfered from other shelf content."; historyEntry.Save(Connection, Transaction); var assignment = new ORM_LOG_WRH_ShelfContent_2_TrackingInstance(); assignment.LOG_ProductTrackingInstance_RefID = destinationShelfContentTrackingInstanceID; assignment.LOG_WRH_Shelf_Content_RefID = destinationShelfContentID; assignment.Tenant_RefID = securityTicket.TenantID; assignment.AssignmentID = Guid.NewGuid(); var savedAssignment = new FR_Guid(assignment.Save(Connection, Transaction), assignment.AssignmentID); } else { destinationShelfContentTrackingInstance.Tenant_RefID = securityTicket.TenantID; destinationShelfContentTrackingInstance.CMN_PRO_Product_RefID = adjustment.ProductID; destinationShelfContentTrackingInstance.LOG_ProductTrackingInstanceID = Guid.NewGuid(); var destinationShelfContentTrackingInstanceID = new FR_Guid(destinationShelfContentTrackingInstance.Save(Connection, Transaction), destinationShelfContentTrackingInstance.LOG_ProductTrackingInstanceID).Result; var historyEntry = new ORM_LOG_ProductTrackingInstance_HistoryEntry(); historyEntry.LOG_ProductTrackingInstance_HistoryEntryID = Guid.NewGuid(); historyEntry.ProductTrackingInstance_RefID = destinationShelfContentTrackingInstanceID; historyEntry.Tenant_RefID = securityTicket.TenantID; historyEntry.HistoryEntry_Text = "Transfered from other shelf content."; historyEntry.Save(Connection, Transaction); } var sourceAdjustmentSaveParameter = new P_L3WH_SSCA_1732(); var adjustmentsList = new List <P_L3WH_SSCA_1732a>(); var sourceAdjustment = new P_L3WH_SSCA_1732a(); sourceAdjustment.AdjustedQuantity = currentshelfContent.Quantity_Current - adjustment.AdjustedQuantity; sourceAdjustment.ProductID = adjustment.ProductID; sourceAdjustment.ShelfContentID = adjustment.ShelfContentID; sourceAdjustment.TrackingInstanceID = sourceShelfContentTrackingInstance.LOG_ProductTrackingInstanceID; sourceAdjustment.IsManualCorrection = true; sourceAdjustment.IfManualCorrection_InventoryChangeReason_RefID = Guid.Empty; sourceAdjustment.IsRelocation = true; sourceAdjustment.RelocationAdjustmentID = Guid.NewGuid(); var destinationAdjustment = new P_L3WH_SSCA_1732a(); destinationAdjustment.AdjustedQuantity = destinationShelfContent.Quantity_Current + adjustment.AdjustedQuantity; destinationAdjustment.IsManualCorrection = true; destinationAdjustment.ProductID = adjustment.ProductID; destinationAdjustment.ShelfContentID = destinationShelfContent.LOG_WRH_Shelf_ContentID; destinationAdjustment.TrackingInstanceID = destinationShelfContentTrackingInstance.LOG_ProductTrackingInstanceID; destinationAdjustment.IfManualCorrection_InventoryChangeReason_RefID = Guid.Empty; destinationAdjustment.IsRelocation = true; destinationAdjustment.RelocationAdjustmentID = Guid.NewGuid(); sourceAdjustment.IfRelocation_CorrespondingAdjustment_RefID = destinationAdjustment.RelocationAdjustmentID; destinationAdjustment.IfRelocation_CorrespondingAdjustment_RefID = sourceAdjustment.RelocationAdjustmentID; adjustmentsList.Add(sourceAdjustment); adjustmentsList.Add(destinationAdjustment); sourceAdjustmentSaveParameter.Adjustments = adjustmentsList.ToArray(); var IsAdjustmentSaved = cls_Save_Shelf_ContentAdjustments.Invoke(Connection, Transaction, sourceAdjustmentSaveParameter, securityTicket).Result; } return(returnValue); #endregion UserCode }
protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5IN_SCRR_1056 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Bool(); #region save new items Boolean proceed = true; List <P_L5IN_SCR_1056a> newItemsList = new List <P_L5IN_SCR_1056a>(); foreach (var item in Parameter.NewItemsData) { Guid productTrackingInstanceID = Guid.Empty; Guid shelfContentID = new Guid(); P_L5SG_GPfSbP_1109 parameter = new P_L5SG_GPfSbP_1109(); parameter.BatchNumber = item.BatchNumber; parameter.ExparationDate = item.ExpirationDate; parameter.ProductID = item.Product_RefID; parameter.ShelfID = item.ShelfID; var articles = cls_Get_Product_from_Shelf_by_ProductID.Invoke(Connection, Transaction, parameter, securityTicket).Result.ToList(); if (articles.Count > 0) { P_L5IN_SIJPSCaTI_1418 paramSaveInvJob = new P_L5IN_SIJPSCaTI_1418(); paramSaveInvJob.InvJobProcessShelfID = item.InvJobProcessShelfID; paramSaveInvJob.ShelfContentID = articles.First().LOG_WRH_Shelf_ContentID; paramSaveInvJob.ProductTrackingInstanceID = articles.First().LOG_ProductTrackingInstanceID; paramSaveInvJob.ShelfExpectedQuantity = item.ExpectedQuantity; paramSaveInvJob.TrackingInstanceExpectedQuantity = item.ExpectedQuantity; shelfContentID = articles.First().LOG_WRH_Shelf_ContentID; var invJob = cls_Save_InventoryJob_Process_ShelfContent_and_TrackingInstance.Invoke(Connection, Transaction, paramSaveInvJob, securityTicket).Result; } else { List <Guid> articleIDs = new List <Guid>(); articleIDs.Add(item.Product_RefID); P_L3AR_GAfAL_0942 paramArticleData = new P_L3AR_GAfAL_0942(); paramArticleData.ProductID_List = articleIDs.ToArray(); var articleData = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, paramArticleData, securityTicket).Result.First(); if (articleData.IsStorage_BatchNumberMandatory && (item.BatchNumber == string.Empty || item.BatchNumber == null)) { proceed = false; } else if (articleData.IsStorage_ExpiryDateMandatory && (item.ExpirationDate == null || item.ExpirationDate == DateTime.MinValue)) { proceed = false; } else { P_L3WH_SSCfP_1635 paramShelfContent = new P_L3WH_SSCfP_1635(); paramShelfContent.BatchNumber = item.BatchNumber; paramShelfContent.ExpirationDate = item.ExpirationDate; paramShelfContent.ProductID = item.Product_RefID; paramShelfContent.Quantity = item.ExpectedQuantity; paramShelfContent.ShelfID = item.ShelfID; var shelfContent = cls_Save_Shelf_Content_for_ProductID.Invoke(Connection, Transaction, paramShelfContent, securityTicket).Result; P_L5IN_SIJPSCaTI_1418 paramSaveInvJob = new P_L5IN_SIJPSCaTI_1418(); paramSaveInvJob.InvJobProcessShelfID = item.InvJobProcessShelfID; paramSaveInvJob.ShelfContentID = shelfContent.ShelfContentID; paramSaveInvJob.ProductTrackingInstanceID = shelfContent.TrackingInstanceID; paramSaveInvJob.ShelfExpectedQuantity = item.ExpectedQuantity; paramSaveInvJob.TrackingInstanceExpectedQuantity = item.ExpectedQuantity; shelfContentID = shelfContent.ShelfContentID; productTrackingInstanceID = shelfContent.TrackingInstanceID; var invJob = cls_Save_InventoryJob_Process_ShelfContent_and_TrackingInstance.Invoke(Connection, Transaction, paramSaveInvJob, securityTicket).Result; } } if (!(item.CountedQuantity == 0 || item.CountedQuantity == null)) { P_L5IN_SCR_1056a result = new P_L5IN_SCR_1056a(); result.Quantity = item.CountedQuantity.Value; result.ShelfContentID = shelfContentID; result.ProductRefID = item.Product_RefID; result.ProcessShelfRefID = item.InvJobProcessShelfID; if (productTrackingInstanceID != Guid.Empty) { result.ProductTrackingInstanceID = productTrackingInstanceID; } newItemsList.Add(result); } } #endregion #region Edit items var editItems = Parameter.Results.Where(x => x.IsEdited == true).ToList(); List <P_L5IN_SCR_1056a> countingResults = new List <P_L5IN_SCR_1056a>(); if (editItems.Count > 0) { List <L3WH_UPTI_1439a> batchNrResultsList = new List <L3WH_UPTI_1439a>(); List <P_L3WH_UPTI_1439a> param = new List <P_L3WH_UPTI_1439a>(); foreach (var item in editItems) { if (item.ProductTrackingInstanceID == null) { continue; } //check if batch number has changed var existingTrackingInstance = new ORM_LOG_ProductTrackingInstance(); existingTrackingInstance.Load(Connection, Transaction, (Guid)item.ProductTrackingInstanceID); if (existingTrackingInstance.BatchNumber != item.BatchNumber) { //create new tracking instance var newTrackingInstance = new ORM_LOG_ProductTrackingInstance(); newTrackingInstance.LOG_ProductTrackingInstanceID = Guid.NewGuid(); newTrackingInstance.BatchNumber = item.BatchNumber; newTrackingInstance.ExpirationDate = item.ExpirationDate; newTrackingInstance.CurrentQuantityOnTrackingInstance = item.Quantity; newTrackingInstance.TrackingInstanceTakenFromSourceTrackingInstance_RefID = existingTrackingInstance.TrackingInstanceTakenFromSourceTrackingInstance_RefID; newTrackingInstance.TrackingCode = existingTrackingInstance.TrackingCode; newTrackingInstance.SerialNumber = existingTrackingInstance.SerialNumber; newTrackingInstance.OwnedBy_BusinessParticipant_RefID = existingTrackingInstance.OwnedBy_BusinessParticipant_RefID; newTrackingInstance.CMN_PRO_Product_RefID = existingTrackingInstance.CMN_PRO_Product_RefID; newTrackingInstance.CMN_PRO_Product_Variant_RefID = existingTrackingInstance.CMN_PRO_Product_Variant_RefID; newTrackingInstance.CMN_PRO_Product_Release_RefID = existingTrackingInstance.CMN_PRO_Product_Release_RefID; newTrackingInstance.IsDeleted = false; newTrackingInstance.Tenant_RefID = securityTicket.TenantID; newTrackingInstance.InitialQuantityOnTrackingInstance = existingTrackingInstance.InitialQuantityOnTrackingInstance; newTrackingInstance.R_FreeQuantity = existingTrackingInstance.R_FreeQuantity; newTrackingInstance.R_ReservedQuantity = existingTrackingInstance.R_ReservedQuantity; newTrackingInstance.Save(Connection, Transaction); //delete old and create new shelf content and tracking instance assotiation var existingSCtoTIQuery = new ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query(); existingSCtoTIQuery.LOG_ProductTrackingInstance_RefID = existingTrackingInstance.LOG_ProductTrackingInstanceID; existingSCtoTIQuery.Tenant_RefID = securityTicket.TenantID; existingSCtoTIQuery.IsDeleted = false; var existingSCtoTI = ORM_LOG_WRH_ShelfContent_2_TrackingInstance.Query.Search(Connection, Transaction, existingSCtoTIQuery).FirstOrDefault(); existingSCtoTI.IsDeleted = true; existingSCtoTI.Save(Connection, Transaction); var newSCtoTI = new ORM_LOG_WRH_ShelfContent_2_TrackingInstance(); newSCtoTI.AssignmentID = Guid.NewGuid(); newSCtoTI.LOG_ProductTrackingInstance_RefID = newTrackingInstance.LOG_ProductTrackingInstanceID; newSCtoTI.LOG_WRH_Shelf_Content_RefID = existingSCtoTI.LOG_WRH_Shelf_Content_RefID; newSCtoTI.Tenant_RefID = securityTicket.TenantID; newSCtoTI.Creation_Timestamp = DateTime.Now; newSCtoTI.Save(Connection, Transaction); //delete old and create new content adjustment and tracking instance assotiation and content adjustment var existingCAtoTIQuery = new ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance.Query(); existingCAtoTIQuery.LOG_ProductTrackingInstance_RefID = existingTrackingInstance.LOG_ProductTrackingInstanceID; existingCAtoTIQuery.IsDeleted = false; existingCAtoTIQuery.Tenant_RefID = securityTicket.TenantID; var existingCAtoTI = ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance.Query.Search(Connection, Transaction, existingCAtoTIQuery).FirstOrDefault(); existingCAtoTI.IsDeleted = true; existingCAtoTI.Save(Connection, Transaction); var existingContentAdjustment = new ORM_LOG_WRH_Shelf_ContentAdjustment(); existingContentAdjustment.Load(Connection, Transaction, existingCAtoTI.LOG_WRH_Shelf_ContentAdjustment_RefID); var newContentAdjustment = new ORM_LOG_WRH_Shelf_ContentAdjustment(); newContentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID = Guid.NewGuid(); newContentAdjustment.ShelfContent_RefID = existingContentAdjustment.ShelfContent_RefID; newContentAdjustment.QuantityChangedAmount = item.Quantity; newContentAdjustment.QuantityChangedDate = DateTime.Now; newContentAdjustment.IsInitialReceipt = false; newContentAdjustment.IsInventoryJobCorrection = existingContentAdjustment.IsInventoryJobCorrection; newContentAdjustment.IfInventoryJobCorrection_InvenoryJobProcess_RefID = existingContentAdjustment.IfInventoryJobCorrection_InvenoryJobProcess_RefID; newContentAdjustment.IsShipmentWithdrawal = existingContentAdjustment.IsShipmentWithdrawal; newContentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID = existingContentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID; newContentAdjustment.IsManualCorrection = existingContentAdjustment.IsManualCorrection; newContentAdjustment.IfManualCorrection_InventoryChangeReason_RefID = existingContentAdjustment.IfManualCorrection_InventoryChangeReason_RefID; newContentAdjustment.PerformedAt_Date = existingContentAdjustment.PerformedAt_Date; newContentAdjustment.PerformedBy_Account_RefID = existingContentAdjustment.PerformedBy_Account_RefID; newContentAdjustment.ContentAdjustmentComment = existingContentAdjustment.ContentAdjustmentComment; newContentAdjustment.IsBatchNumberOrSerialKeyUpdate = true; newContentAdjustment.IfBatchNumberOrSerialKeyUpdate_CorrespondingAdjustment_RefID = existingContentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID; newContentAdjustment.IsRelocation = false; newContentAdjustment.IfRelocation_CorrespondingAdjustment_RefID = Guid.Empty; newContentAdjustment.Creation_Timestamp = DateTime.Now; newContentAdjustment.Tenant_RefID = securityTicket.TenantID; newContentAdjustment.Save(Connection, Transaction); var newCAtoTI = new ORM_LOG_WRH_Shelf_ContentAdjustment_TrackingInstance(); newCAtoTI.LOG_WRH_Shelf_ContentAdjustment_TrackingInstanceID = Guid.NewGuid(); newCAtoTI.LOG_ProductTrackingInstance_RefID = newTrackingInstance.LOG_ProductTrackingInstanceID; newCAtoTI.LOG_WRH_Shelf_ContentAdjustment_RefID = newContentAdjustment.LOG_WRH_Shelf_ContentAdjustmentID; newCAtoTI.LOG_WRH_Shelf_ContentAdjustment_TrackingInstanceID = newTrackingInstance.LOG_ProductTrackingInstanceID; newCAtoTI.QuantityChangedAmount = item.Quantity - existingContentAdjustment.QuantityChangedAmount; newCAtoTI.IsDeleted = false; newCAtoTI.Tenant_RefID = securityTicket.TenantID; newCAtoTI.Creation_Timestamp = DateTime.Now; newCAtoTI.Save(Connection, Transaction); item.ProductTrackingInstanceID = newTrackingInstance.LOG_ProductTrackingInstanceID; L3WH_UPTI_1439a batchNrChangedResults = new L3WH_UPTI_1439a(); batchNrChangedResults.TrackingInstanceID = newTrackingInstance.LOG_ProductTrackingInstanceID; batchNrChangedResults.ProductID = newTrackingInstance.CMN_PRO_Product_RefID; batchNrChangedResults.LOG_WRH_Shelf_ContentID = newContentAdjustment.ShelfContent_RefID; existingTrackingInstance.IsDeleted = true; existingTrackingInstance.Save(Connection, Transaction); batchNrResultsList.Add(batchNrChangedResults); } else { P_L3WH_UPTI_1439a p = new P_L3WH_UPTI_1439a(); p.BatchNumber = item.BatchNumber; p.ExpirationDate = item.ExpirationDate; p.ProductTrackingInstanceID = (Guid)item.ProductTrackingInstanceID; p.ShelfContentID = item.ShelfContentID; p.Quantity = item.Quantity; p.ProductID = item.ProductRefID; param.Add(p); } } P_L3WH_UPTI_1439 paramUpdateTrackingInstance = new P_L3WH_UPTI_1439(); paramUpdateTrackingInstance.ProductTrackingInstance = param.ToArray(); var result = cls_Update_ProductTrackingInstance.Invoke(Connection, Transaction, paramUpdateTrackingInstance, securityTicket).Result; List <L3WH_UPTI_1439a> finalList = new List <L3WH_UPTI_1439a>(); finalList = result.newTrackingInstance.ToList(); finalList.AddRange(batchNrResultsList); result.newTrackingInstance = finalList.ToArray(); foreach (var item in editItems) { if (item.ProductTrackingInstanceID == null) { continue; } //var oldProcessShelf = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_Process_Shelf().Load(Connection, Transaction, item.ProcessShelfRefID); //var newProcessShelf = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_Process_Shelf(); var oldProcessShelfContent = CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_Process_ShelfContent.Query.Search(Connection, Transaction, new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_Process_ShelfContent.Query() { LOG_WRH_INJ_InventoryJob_Process_Shelf_RefID = item.ProcessShelfRefID, LOG_WRH_Shelf_Content_RefID = item.ShelfContentID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var newProcessShelfContent = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_Process_ShelfContent(); newProcessShelfContent.Creation_Timestamp = DateTime.Now; newProcessShelfContent.ExpectedQuantityOnShelfContent = oldProcessShelfContent.ExpectedQuantityOnShelfContent; newProcessShelfContent.IsDeleted = false; newProcessShelfContent.LOG_WRH_INJ_InventoryJob_Process_Shelf_RefID = oldProcessShelfContent.LOG_WRH_INJ_InventoryJob_Process_Shelf_RefID; newProcessShelfContent.LOG_WRH_INJ_InventoryJob_Process_ShelfContentID = Guid.NewGuid(); newProcessShelfContent.LOG_WRH_Shelf_Content_RefID = result.newTrackingInstance.Where(x => x.ProductID == item.ProductRefID).Single().LOG_WRH_Shelf_ContentID; newProcessShelfContent.Tenant_RefID = securityTicket.TenantID; newProcessShelfContent.Save(Connection, Transaction); oldProcessShelfContent.IsDeleted = true; oldProcessShelfContent.Save(Connection, Transaction); var oldProcessShelfContentTrackingInstance = CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_Process_ShelfContents_TrackingInstance.Query.Search(Connection, Transaction, new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_Process_ShelfContents_TrackingInstance.Query() { LOG_WRH_INJ_InventoryJob_Process_ShelfContent_RefID = oldProcessShelfContent.LOG_WRH_INJ_InventoryJob_Process_ShelfContentID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var newProcessShelfContentTrackingInstance = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_Process_ShelfContents_TrackingInstance(); newProcessShelfContentTrackingInstance.Creation_Timestamp = DateTime.Now; newProcessShelfContentTrackingInstance.ExpectedQuantityOnTrackingInstance = oldProcessShelfContentTrackingInstance.ExpectedQuantityOnTrackingInstance; newProcessShelfContentTrackingInstance.LOG_ProductTrackingInstance_RefID = result.newTrackingInstance.Where(x => x.ProductID == item.ProductRefID).Single().TrackingInstanceID; newProcessShelfContentTrackingInstance.LOG_WRH_INJ_InventoryJob_Process_ShelfContent_RefID = newProcessShelfContent.LOG_WRH_INJ_InventoryJob_Process_ShelfContentID; newProcessShelfContentTrackingInstance.LOG_WRH_INJ_Process_ShelfContents_TrackingInstanceID = Guid.NewGuid(); newProcessShelfContentTrackingInstance.Tenant_RefID = securityTicket.TenantID; newProcessShelfContentTrackingInstance.Save(Connection, Transaction); oldProcessShelfContentTrackingInstance.IsDeleted = true; oldProcessShelfContentTrackingInstance.Save(Connection, Transaction); } foreach (var item in Parameter.Results.ToList()) { if (result.newTrackingInstance.Any(x => x.ProductID == item.ProductRefID)) { var res = result.newTrackingInstance.Where(x => x.ProductID == item.ProductRefID).Single(); item.ProductTrackingInstanceID = res.TrackingInstanceID; item.ShelfContentID = res.LOG_WRH_Shelf_ContentID; } countingResults.Add(item); } } else { countingResults = Parameter.Results.ToList(); } #endregion List <P_L5IN_SCR_1056a> completeList = new List <P_L5IN_SCR_1056a>(); completeList.AddRange(newItemsList); completeList.AddRange(countingResults); if (proceed) { var countingRun = CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_CountingRun.Query.Search(Connection, Transaction, new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventoryJob_CountingRun.Query { LOG_WRH_INJ_InventoryJob_CountingRunID = Parameter.CountingRunID, IsCounting_Started = true, IsCounting_Completed = false, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).Single(); var countingResult = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventryJob_CountingResult(); var countingResultTrackingInstance = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_CountingResult_TrackingInstance(); foreach (var item in completeList) { bool isTrackingInstance = (item.ProductTrackingInstanceID != Guid.Empty); #region Load or create new Counting Result // try to find counting result for the same ShelfContentID countingResult = CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventryJob_CountingResult.Query.Search(Connection, Transaction, new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventryJob_CountingResult.Query { CountingRun_RefID = Parameter.CountingRunID, Product_RefID = item.ProductRefID, Process_Shelf_RefID = item.ProcessShelfRefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).SingleOrDefault(); #region Create new counting result if none is found by ShelfContent_RefID if (countingResult == null) { countingResult = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_InventryJob_CountingResult { LOG_WRH_INJ_InventoryJob_CountingResultID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, CountedAmount = 0.0, CountingRun_RefID = Parameter.CountingRunID, IsDifferenceToExpectedQuantityFound = false, Product_RefID = item.ProductRefID, Process_Shelf_RefID = item.ProcessShelfRefID, }; countingResult.Save(Connection, Transaction); } #endregion #endregion if (isTrackingInstance) { if (item.InventoryJob_CountingResultID == Guid.Empty || item.CountingResult_TrackingInstanceID == Guid.Empty) { countingResultTrackingInstance = new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_CountingResult_TrackingInstance { LOG_WRH_INJ_CountingResult_TrackingInstanceID = Guid.NewGuid(), Creation_Timestamp = DateTime.Now, Tenant_RefID = securityTicket.TenantID, LOG_WRH_INJ_InventoryJob_CountingResult_RefID = countingResult.LOG_WRH_INJ_InventoryJob_CountingResultID, LOG_ProductTrackingInstanceID = item.ProductTrackingInstanceID.Value }; } else { countingResultTrackingInstance.Load(Connection, Transaction, item.CountingResult_TrackingInstanceID); } countingResultTrackingInstance.CountedAmount = item.Quantity; countingResultTrackingInstance.Save(Connection, Transaction); var tiResults = CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_CountingResult_TrackingInstance.Query.Search(Connection, Transaction, new CL1_LOG_WRH_INJ.ORM_LOG_WRH_INJ_CountingResult_TrackingInstance.Query { LOG_WRH_INJ_InventoryJob_CountingResult_RefID = countingResult.LOG_WRH_INJ_InventoryJob_CountingResultID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); countingResult.CountedAmount = tiResults.Sum(x => x.CountedAmount); countingResult.Save(Connection, Transaction); } } } returnValue.Result = proceed; return(returnValue); #endregion UserCode }
protected static FR_L5RS_SRSHaP_0807_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_SRSHaP_0807 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5RS_SRSHaP_0807_Array(); var results = new List <L5RS_SRSHaP_0807>(); var contentAdjustments = new List <P_L3WH_SSCA_1732a>(); var deleteReservationsParam = new List <P_L3SO_DARaUSHfPTIL_1159a>(); foreach (var returnShipment in Parameter.ReturnShipments) { #region Create New Shipment and ReturnShipment Headers var resultHeadersCreation = new FR_L5RS_CSaRSH_0244(); if (returnShipment.CreateNewHeader) { resultHeadersCreation = cls_Create_Shipment_and_ReturnShipment_Header.Invoke( Connection, Transaction, returnShipment.ShipmentHeader, securityTicket); if (resultHeadersCreation.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } } #endregion #region Create New Shipment and ReturnShipment Positions var resultPositionsCreation = new FR_L5RS_CSaRSPfH_0449(); if (returnShipment.CreateNewHeader) { foreach (var position in returnShipment.ShipmentPositions.Positions) { position.ShipmentHeaderID = resultHeadersCreation.Result.ShipmentHeaderID; position.ReturnShipmentHeaderID = resultHeadersCreation.Result.ReturnShipmentHeaderID; #region Fetch ReturnPolicyID if needed if (position.ReturnPolicyId == Guid.Empty) { var returnPolicy = ORM_LOG_RET_ReturnPolicy.Query.Search(Connection, Transaction, new ORM_LOG_RET_ReturnPolicy.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, GlobalPropertyMatchingID = position.ReturnPolicyGlobalPropertyMatchingId }).FirstOrDefault(); if (returnPolicy != null) { position.ReturnPolicyId = returnPolicy.LOG_RET_ReturnPolicyID; } } #endregion } } resultPositionsCreation = cls_Create_Shipment_and_ReturnShipment_Positions_for_HeaderID.Invoke( Connection, Transaction, returnShipment.ShipmentPositions, securityTicket); if (resultPositionsCreation.Status != FR_Status.Success) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion #region Create New ContentAdjustments parameter foreach (var item in returnShipment.ShipmentPositions.Positions) { var productTrackingInstance = new ORM_LOG_ProductTrackingInstance(); productTrackingInstance.Load( Connection, Transaction, (Guid)item.ProductTrackingInstance); var paramContentAdjustment = new P_L3WH_SSCA_1732a(); paramContentAdjustment.AdjustedQuantity = productTrackingInstance.CurrentQuantityOnTrackingInstance - item.Quantity; paramContentAdjustment.IsManualCorrection = true; paramContentAdjustment.IfManualCorrection_InventoryChangeReason_RefID = item.ReturnPolicyId; paramContentAdjustment.IsShipmentWithdrawal = true; paramContentAdjustment.IfShipmentWithdrawal_ShipmentPosition_RefID = item.ShipmentPositionID; paramContentAdjustment.ProductID = item.ProductId; paramContentAdjustment.ShelfContentID = item.ShelfContentID; paramContentAdjustment.TrackingInstanceID = item.ProductTrackingInstance ?? Guid.Empty; contentAdjustments.Add(paramContentAdjustment); deleteReservationsParam.Add(new P_L3SO_DARaUSHfPTIL_1159a() { ProductTrackingInstanceID = (Guid)item.ProductTrackingInstance, RemovedQuantityFromTrackingInstance = item.Quantity, CurrentQuantityOnTrackingInstance = productTrackingInstance.CurrentQuantityOnTrackingInstance }); } #endregion var result = new L5RS_SRSHaP_0807() { ShipmentHeaderID = returnShipment.ShipmentPositions.Positions[0].ShipmentHeaderID, ShipmentHeaderNumber = resultPositionsCreation.Result.ShipmentHeaderNumber, ShipmentHeaderTotalValue = resultPositionsCreation.Result.ShipmentHeaderTotalValue, ReturnShipmentHeaderID = returnShipment.ShipmentPositions.Positions[0].ReturnShipmentHeaderID, ShipmentHeaderSupplierName = resultPositionsCreation.Result.ShipmentHeaderSupplierName, ShipmentPositionIDs = resultPositionsCreation.Result.ShipmentPositionIDs, ReturnShipmentPositionIDs = resultPositionsCreation.Result.ReturnShipmentPositionIDs }; results.Add(result); } #region ClearReservations var deleteResParam = new P_L3SO_DARaUSHfPTIL_1159() { TracknigInstances = deleteReservationsParam.ToArray() }; cls_Delete_ActiveReservations_and_UpdateShipmentHeaders_for_ProductTrackingInstanceIDList.Invoke(Connection, Transaction, deleteResParam, securityTicket); #endregion #region Save ShelfContentAdjustments P_L3WH_SSCA_1732 paramContent = new P_L3WH_SSCA_1732(); paramContent.Adjustments = contentAdjustments.ToArray(); var resultContentAdjustments = cls_Save_Shelf_ContentAdjustments.Invoke(Connection, Transaction, paramContent, securityTicket); if (resultContentAdjustments.Status != FR_Status.Success || resultContentAdjustments.Result == false) { returnValue.Status = FR_Status.Error_Internal; returnValue.Result = null; return(returnValue); } #endregion returnValue.Status = FR_Status.Success; returnValue.Result = results.ToArray(); return(returnValue); #endregion UserCode }