Skip to content

Massimo Orisio #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions TestDB/Stored Procedures/usp_movecase.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
CREATE PROCEDURE [dbo].[usp_movecase]
@casetomove UNIQUEIDENTIFIER
CREATE PROCEDURE [dbo].[usp_movecase]
@casetomove UNIQUEIDENTIFIER,
@NewPallet UNIQUEIDENTIFIER,
@ExitCode INT OUTPUT -- 0 case moved, 99 case product different, 98 case already on pallet

WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON;

DECLARE @Result AS INT = 0
DECLARE @_errormessage NVARCHAR(MAX)
DECLARE @Rowcount as int = 0
DECLARE @PalletID uniqueidentifier
DECLARE @addcase as int = 0

BEGIN TRANSACTION
BEGIN TRY

PRINT 'your code goes here'

SET @ExitCode = 0

SELECT @PalletID = palletguid FROM [case] WHERE guid = @casetomove

-- test if case is on the same pallet
if @PalletID <> @NewPallet
BEGIN
-- test if pallet is empty and productID are identical
SELECT @Rowcount = COUNT(DISTINCT productguid) FROM [case] WHERE palletguid = @NewPallet

-- if pallet empty
IF @Rowcount = 0
SET @addcase = 1
ELSE
IF @Rowcount = 1 -- if only product ID
SET @addcase = 1

IF @addcase = 1
-- move case into new pallet
UPDATE [case] SET palletguid = @NewPallet WHERE guid = @casetomove
ELSE
SET @ExitCode = 99 -- Case product id not compatible with other cases on pallet

END
ELSE
SET @ExitCode = 98 -- Case is already on pallet

END TRY
BEGIN CATCH
Expand All @@ -36,4 +67,4 @@ BEGIN
END

RETURN @Result
END
END