SET NAMES 'utf8';

SELECT
    YEAR(e.fecha) AS year,
    RIGHT(l.id_linea,2) AS cod_linea,
    l.descripcion AS linea,
    e.id_proveedor AS Nit_Proveedor,
    p.nombre_proveedor AS proveedor,
    SUM(ei.costo) AS costo, 
    ROUND(SUM(ei.cantidad * i.peso), 2) AS peso

FROM
    entrada e
    JOIN entrada_has_item ei
        ON ( e.id_entrada = ei.id_entrada
            AND e.id_sucursal = ei.id_sucursal )
    JOIN item i
        USING ( id_item )
    LEFT JOIN linea l
        ON ( l.id_linea = i.id_linea
            AND l.tipo = i.tipo )
    LEFT JOIN proveedor p
        ON ( p.id_proveedor = e.id_proveedor )
    LEFT JOIN proveedor_has_sucursal ps
        ON ( p.id_proveedor = ps.id_proveedor
            AND ps.id_sucursal = e.id_sucursal )

GROUP BY
    year, linea, proveedor

HAVING
    year > 2015
