DROP VIEW WPOSS_ArticulosPrecios
GO

CREATE VIEW WPOSS_ArticulosPrecios
AS

SELECT prba.id_mone, 
	   prba.id_arti, 
	   precio_base = prba.precio_base, 
	   mone.cod_mone, 
	   ratio = CAST(CASE WHEN arti.precio_costo = 0
						 OR arti.factor_div = 0 THEN 0
						 ELSE ROUND(prba.precio_base / mone.tasa * sicla.tasa, 2) / arti.precio_costo / arti.factor_div
						 END AS NUMERIC(18, 2)), 
	   ganancia = CAST(CASE WHEN arti.precio_costo = 0
							OR arti.factor_div = 0 THEN 0
							ELSE ROUND(prba.precio_base / mone.tasa * sicla.tasa, 2) / arti.precio_costo / arti.factor_div * 100 - 100
							END AS NUMERIC(18, 2)),  
	   tasa_venta = mone.tasa, 
	   mone_costo = sicla.cod_mone, 
	   tasa_costo = sicla.tasa
FROM       RESTPRBA prba
INNER JOIN RESTARTI arti  ON prba.id_arti = arti.id_Arti
INNER JOIN SICLAMON mone  ON prba.id_mone = mone.id_mone
INNER JOIN SICLAMON sicla ON dbo.lnk_Get_Id_Mone_Inv() = sicla.id_mone