CREATE function [dbo].[fn_crm_getCamposPresupuesto] (
@campos crm_camposType READONLY,
@controlOrigen varchar(200),
@id_vendedor int
) returns @camposNuevos table (
campo varchar(200) collate latin1_general_bin not null,
valorTexto varchar(8000) collate latin1_general_bin null,
valorNumerico decimal(18,2) null,
valorFecha datetime null,
valorBit bit null
)
AS
BEGIN
if upper(@controlOrigen) in (upper('GrPresupuestosRenglones.CA_ListaPrecios'))
begin
declare @listaRenglon int=0, @listaGeneral int=0, @lista int=null, @cod_articu varchar(15)='', @precio decimal(18,2)=null
select @listaRenglon=coalesce(valorNumerico,0) from @campos where upper(campo) =upper('GrPresupuestosRenglones.CA_ListaPrecios')
select @listaGeneral=coalesce(valortexto,0) from @campos where upper(campo) =upper('TxtNroLista')
select @cod_articu=coalesce(valortexto,'') from @campos where upper(campo) =upper('GrPresupuestosRenglones.Cod_articu')
insert into @camposNuevos(campo,valorNumerico) values('GrPresupuestosRenglones.Precio',coalesce(@precio,0))
if @listaRenglon>0
begin
set @lista=@listarenglon
end
else
begin
set @lista=@listaGeneral
end
if @lista>0 and exists(select * from gva10 where NRO_DE_LIS=@lista) and exists(select * from sta11 where cod_articu=@cod_articu)
begin
select @precio=coalesce(PRECIO,0) from gva17 where NRO_DE_LIS=@lista and COD_ARTICU=@cod_articu
insert into @camposNuevos(campo,valorNumerico) values('GrPresupuestosRenglones.Precio',coalesce(@precio,0))
end
end
return
END
GO