SELECT dv.id_sucursal AS suc, dvi.id_item AS item, 
    SUM(dvi.cantidad * (IF(dvi.valor>0,1,-1))) AS cantidad,
    SUM(dvi.cantidad * i.peso * (IF(dvi.valor>0,1,-1))) AS peso,
    SUM(dvi.valor) AS valor, SUM(dvi.costo) AS costo
FROM `documento_ventas_has_item` dvi 
JOIN documento_ventas dv USING ( id_documento, id_sucursal )
JOIN item i USING ( id_item, id_sucursal ) 
where fecha like "2010-0%" 
group by dvi.id_sucursal, dvi.id_item ;
