SELECT
dv.id_sucursal, i.id_item, i.descripcion, SUM( dvi.valor ) AS valor
FROM documento_ventas dv
JOIN documento_ventas_has_item dvi
ON ( dv.id_documento = dvi.id_documento AND dv.id_sucursal = dvi.id_sucursal )
JOIN item i
ON ( dvi.id_item = i.id_item AND dvi.id_sucursal = i.id_sucursal )
LEFT JOIN linea l
ON ( l.id_linea =  i.id_linea AND l.tipo = i.tipo )
WHERE 
NOT (
	dv.id_cliente LIKE "999"
)
AND YEAR( dv.fecha ) = 2013
AND (
	l.id_linea IS NULL
)
GROUP BY dv.id_sucursal,dvi.id_item
ORDER BY valor DESC
