
ALTER PROCEDURE [dbo].[sp_invDetalle_Solicitud_Saldo]
(
@coddoc int,
@numinv int
)
AS
--DECLARE @salcan decimal(18,4) = (SELECT top(1) salcan 
--						FROM invDetalle 
--						WHERE     A.codbus = D.codbus
--						AND	  D.coddoc = @coddoc
--						AND   D.numinv = @numinv)

	SELECT    D.numlin, 
				D.codbus, 
				D.nomart, 
				U.abruni, 
				D.salcan as cantidad, 
				D.cantidad as cantidadReal,
				D.preuni, 
				D.preuniadi, 
				D.pretot, 
				D.pretotadi, 
				D.fecent, 
				D.glolin, 
				D.numlinorden,
				D.canalt,saldoGral,stockGral,D.costo,D.fechacosto ,costobodega,COALESCE(stockBodega,0) AS stockBodega,
				D.codbod
	FROM      invDetalle D, invArticulos A, invUnidadMedida U
	WHERE     A.codbus = D.codbus 
	AND	  A.coduni = U.coduni
	AND	  D.coddoc = @coddoc
	AND   D.numinv = @numinv
	--AND   D.salcan > 0
	ORDER BY 1