//    uniCenta oPOS - Touch Friendly Point Of Sale
//    Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
//    https://unicenta.com
//
//    This file is part of uniCenta oPOS
//
//    uniCenta oPOS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    uniCenta oPOS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with uniCenta oPOS.  If not, see <http://www.gnu.org/licenses/>.

// *** NOT SUITABLE FOR DERBY DB'S***

report = new com.unicenta.pos.reports.PanelReportBean();

report.setTitleKey("Menu.ExtendedByProducts");
report.setReport("/com/unicenta/reports/sales_extproducts");
report.setResourceBundle("com/unicenta/reports/sales_messages");

report.setSentence("SELECT " +
        "customers.TAXID,  " +
        "customers.NAME AS CUSTOMER, " +
        "categories.NAME AS CATEGORY, " +
        "products.REFERENCE AS REFERENCE,  " +
        "products.NAME AS PRODUCT, " +
        "SUM(ticketlines.UNITS) AS UNIT,  " +
        "SUM(ticketlines.UNITS * ticketlines.PRICE) AS TOTAL, " +
        "SUM(ticketlines.UNITS * ticketlines.PRICE) / SUM(ticketlines.UNITS) AS MEANPRICE " +
        "FROM tickets  " +
            "LEFT OUTER JOIN customers ON tickets.CUSTOMER = customers.ID, ticketlines " +
            "LEFT OUTER JOIN products ON ticketlines.PRODUCT = products.ID " +
            "LEFT OUTER JOIN categories ON products.CATEGORY = categories.ID, receipts " +
        "WHERE receipts.ID = tickets.ID AND tickets.ID = ticketlines.TICKET AND ?(QBF_FILTER) " +
        "GROUP BY customers.ID, categories.ID, products.ID " +
        "ORDER BY customers.NAME, categories.NAME, products.NAME");

report.addParameter("receipts.DATENEW");
report.addParameter("receipts.DATENEW");
report.addQBFFilter(new com.unicenta.pos.reports.JParamsDatesInterval());

report.addParameter("products.NAME");
report.addParameter("products.PRICEBUY");
report.addParameter("products.PRICESELL");
report.addParameter("products.CATEGORY");
report.addParameter("products.CODE");
report.addQBFFilter(new com.unicenta.pos.ticket.ProductFilter());

report.addParameter("customers.ID");
report.addParameter("customers.NAME");
report.addQBFFilter(new com.unicenta.pos.reports.JParamsCustomer());

report.addField("TAXID", com.unicenta.data.loader.Datas.STRING);
report.addField("CUSTOMER", com.unicenta.data.loader.Datas.STRING);
report.addField("CATEGORY", com.unicenta.data.loader.Datas.STRING);
report.addField("REFERENCE", com.unicenta.data.loader.Datas.STRING);
report.addField("PRODUCT", com.unicenta.data.loader.Datas.STRING);
report.addField("UNIT", com.unicenta.data.loader.Datas.DOUBLE);
report.addField("TOTAL", com.unicenta.data.loader.Datas.DOUBLE);
report.addField("MEANPRICE", com.unicenta.data.loader.Datas.DOUBLE);

report;

