-- =============================================
-- Author:		<YONATAN GAETE>
-- Edition date: <19-06-2024>
-- Description:	<Se agrega numlin para Lotes y Series>
-- =============================================
ALTER PROCEDURE [dbo].[sp_invPreToma_Ins]
(
 @codtoma		int,
 @fechatoma		date,
 @usuario		varchar(50),
 @codbod		int,
 @codsuc		int,
 @codbus		varchar(50),
 @stockfisico	decimal(18,4),
 @cierretoma	int,
 @nuevapretoma	int,
 @idlinea		int,
 @stockAlt		int = 0,
 @numlin		INT = 0
)

as

IF @nuevapretoma = 0
BEGIN
	UPDATE invPreToma
	SET codBod = @codbod,
		codSuc = @codsuc,
		codBus = @codbus,
		stockFisico = @stockfisico,
		stockAlt = @stockAlt,
		numlin = @numlin
	WHERE idlinea = @idlinea

END


IF @nuevapretoma = 1
BEGIN
	INSERT INTO invPreToma (
		idPreToma,
		fecha,
		usuario,
		codBod,
		codSuc,
		codBus,
		stockFisico,
		cierre,
		stockAlt,
		numlin
	)
	VALUES
	(
		@codtoma,
		@fechatoma,
		@usuario,
		@codbod,
		@codsuc,
		@codbus,
		@stockfisico,
		@cierretoma,
		@stockAlt,
		@numlin
	)

END