//    uniCenta oPOS - Touch Friendly Point Of Sale
//    Copyright (c) 2018 uniCenta
//    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/>.

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

report.setTitleKey("Menu.Inventory.Reports.Diary");
report.setReport("/com/unicenta/reports/inventory_diary");
report.setResourceBundle("com/unicenta/reports/inventory_messages");

report.setSentence("SELECT "
            + "TIMESTAMP(stockdiary.datenew), stockdiary.reason, MIN(stockdiary.supplierdoc), "
            + "sum(stockdiary.units), MIN(stockdiary.price), "
            + "sum(stockdiary.UNITS * stockdiary.PRICE) AS TOTALP, "
            + "MIN(suppliers.name) AS SUPPLIERNAME, "
            + "products.name, MIN(products.reference), MIN(products.code), "
            + "locations.name "
        + "FROM ((stockdiary stockdiary "
            + "INNER JOIN locations locations "
                + "ON (stockdiary.location = locations.id)) "
            + "INNER JOIN products products "
                + "ON (stockdiary.product = products.id)) "
            + "LEFT OUTER JOIN suppliers suppliers "
                + "ON (products.supplier = suppliers.id) "
        + "WHERE VISIBLE = " + app.getSession().DB.TRUE() + " AND ?(QBF_FILTER) " 
        + "GROUP BY locations.name, stockdiary.reason, stockdiary.datenew, products.name");

report.addParameter("stockdiary.DATENEW");
report.addParameter("stockdiary.DATENEW");
paramdates = new com.unicenta.pos.reports.JParamsDatesInterval();
paramdates.setStartDate(com.unicenta.beans.DateUtils.getToday());
paramdates.setEndDate(com.unicenta.beans.DateUtils.getTodayMinutes());
report.addQBFFilter(paramdates);

report.addParameter("stockdiary.REASON");
report.addQBFFilter(new com.unicenta.pos.reports.JParamsReason());

report.addParameter("suppliers.ID");
report.addParameter("suppliers.NAME");
report.addQBFFilter(new com.unicenta.pos.reports.JParamsSuppliers());

report.addField("DATENEW", com.unicenta.data.loader.Datas.TIMESTAMP);
report.addField("REASON", com.unicenta.data.loader.Datas.INT);
report.addField("SUPPLIERDOC", com.unicenta.data.loader.Datas.STRING);
report.addField("UNITS", com.unicenta.data.loader.Datas.DOUBLE);
report.addField("PRICE", com.unicenta.data.loader.Datas.DOUBLE);
report.addField("TOTALP", com.unicenta.data.loader.Datas.DOUBLE);
report.addField("SUPPLIERNAME", com.unicenta.data.loader.Datas.STRING);
report.addField("PRODUCTNAME", com.unicenta.data.loader.Datas.STRING);
report.addField("REFERENCE", com.unicenta.data.loader.Datas.STRING);
report.addField("CODE", com.unicenta.data.loader.Datas.STRING);
report.addField("LOCATION", com.unicenta.data.loader.Datas.STRING);

report;