View source | Discuss this page | Page history | Printable version   

POS - Category sales subreport into partial cash report

Code snippet

Name: POS - Category sales subreport into partial cash report
Version: POS 2.30
Author: Algaja



This subreport is based on Andrej Svininykh Sales subreport!

Add new method into PaymentsModel

Open PaymentsModel in com.openbravo.pos.panels package. Add variables:

...
public class PaymentsModel {
...
    private java.util.List<PaymentsLine> m_lpayments;

    private Integer m_iCategorySalesRows;
    private Double m_dCategorySalesTotalUnits;
    private Double m_dCategorySalesTotal;
    private java.util.List<CategorySalesLine> m_lcategorysales;
    
    private final static String[] PAYMENTHEADERS = {"Label.Payment", "label.totalcash"};
...

    public static PaymentsModel emptyInstance() {
...
        p.m_lpayments = new ArrayList<PaymentsLine>();

        p.m_iCategorySalesRows = new Integer(0);
        p.m_dCategorySalesTotalUnits = new Double(0.0);
        p.m_dCategorySalesTotal = new Double(0.0);
        p.m_lcategorysales = new ArrayList<CategorySalesLine>();
        
        p.m_iSales = null;
...
    public static PaymentsModel loadInstance(AppView app) throws BasicException {
...
        // Product category Sales
        Object[] valcategorysales = (Object []) new StaticSentence(app.getSession()
            , "SELECT COUNT(*), SUM(TICKETLINES.UNITS), SUM((TICKETLINES.PRICE + TICKETLINES.PRICE * TAXES.RATE ) * TICKETLINES.UNITS) " +
              "FROM TICKETLINES, TICKETS, RECEIPTS, TAXES " +
              "WHERE TICKETLINES.TICKET = TICKETS.ID AND TICKETS.ID = RECEIPTS.ID AND TICKETLINES.TAXID = TAXES.ID AND TICKETLINES.PRODUCT IS NOT NULL AND RECEIPTS.MONEY = ? " +
              "GROUP BY RECEIPTS.MONEY"
            , SerializerWriteString.INSTANCE
            , new SerializerReadBasic(new Datas[] {Datas.INT, Datas.DOUBLE, Datas.DOUBLE}))
            .find(app.getActiveCashIndex());

        if (valcategorysales == null) {
            p.m_iCategorySalesRows = new Integer(0);
            p.m_dCategorySalesTotalUnits = new Double(0.0);
            p.m_dCategorySalesTotal = new Double(0.0);
        } else {
            p.m_iCategorySalesRows = (Integer) valcategorysales[0];
            p.m_dCategorySalesTotalUnits = (Double) valcategorysales[1];
            p.m_dCategorySalesTotal= (Double) valcategorysales[2];
        }

        List categorys = new StaticSentence(app.getSession()
            , "SELECT a.NAME, sum(c.UNITS), sum(c.UNITS * (c.PRICE + (c.PRICE * d.RATE))) " +
              "FROM CATEGORIES as a " +
              "LEFT JOIN PRODUCTS as b on a.id = b.CATEGORY " +
              "LEFT JOIN TICKETLINES as c on b.id = c.PRODUCT " +
              "LEFT JOIN TAXES as d on c.TAXID = d.ID " +
              "LEFT JOIN RECEIPTS as e on c.TICKET = e.ID " +
              "WHERE e.MONEY = ? " +
              "GROUP BY a.NAME"
            , SerializerWriteString.INSTANCE
            , new SerializerReadClass(PaymentsModel.CategorySalesLine.class)) //new SerializerReadBasic(new Datas[] {Datas.STRING, Datas.DOUBLE}))
            .list(app.getActiveCashIndex());

        if (categorys == null) {
            p.m_lcategorysales = new ArrayList();
        } else {
            p.m_lcategorysales = categorys;
        }
...

Add new methods into PaymentsModel class:

...
    public double getCategorySalesRows() {
        return m_iCategorySalesRows.intValue();
    }

    public String printCategorySalesRows() {
        return Formats.INT.formatValue(m_iCategorySalesRows);
    }

    public double getCategorySalesTotalUnits() {
        return m_dCategorySalesTotalUnits.doubleValue();
    }

    public String printCategorySalesTotalUnits() {
        return Formats.DOUBLE.formatValue(m_dCategorySalesTotalUnits);
    }

    public double getCategorySalesTotal() {
        return m_dCategorySalesTotal.doubleValue();
    }

    public String printCategorySalesTotal() {
        return Formats.CURRENCY.formatValue(m_dCategorySalesTotal);
    }

    public List<CategorySalesLine> getCategorySalesLines() {
        return m_lcategorysales;
    }
...

And add new public class CategorySalesLine:

...
    // Products category sales class
    public static class CategorySalesLine implements SerializableRead {

        private String m_CategoryName;
        private Double m_CategoryUnits;
        private Double m_CategorySum;

        public void readValues(DataRead dr) throws BasicException {
            m_CategoryName = dr.getString(1);
            m_CategoryUnits = dr.getDouble(2);
            m_CategorySum = dr.getDouble(3);
        }

        public String printCategoryName() {
            return m_CategoryName;
        }

        public String printCategoryUnits() {
            return Formats.DOUBLE.formatValue(m_CategoryUnits);
        }

        public Double getCategoryUnits() {
            return m_CategoryUnits;
        }

        public String printCategorySum() {
            return Formats.CURRENCY.formatValue(m_CategorySum);
        }

        public Double getCategorySum() {
            return m_CategorySum;
        }
    }
...

Edit source code and compilation project. Edit Print.PartialCash resource:

        <line>
            <text bold="true">Product category sales</text>
        </line>
        <line>
            <text align ="left" length="25">Name</text>
            <text align ="right" length="5">Qty</text>
            <text align ="right" length="10">Total</text>
        </line>
        <line>
            <text>------------------------------------------</text>
        </line>
        #foreach ($line in $payments.getCategorySalesLines())
        <line>
            <text align ="left" length="25">${line.printCategoryName()}</text>
            <text align ="right" length="5">${line.printCategoryUnits()}</text>
            <text align ="right" length="10">${line.printCategorySum()}</text>
        </line>
        #end
        <line>
            <text>------------------------------------------</text>
        </line>
        <line>
            <text align ="left" length="32">Ticket rows:</text>
            <text align ="right" length="10">${payments.printCategorySalesRows()}</text>
        </line>
        <line></line>
        <line size="1">
            <text align ="left" length="22" bold="true">Total</text>
            <text align ="right" length="10" bold="true">${payments.printCategorySalesTotalUnits()}</text>
            <text align ="right" length="10" bold="true">${payments.printCategorySalesTotal()}</text>
        </line>
        <line></line>

Save resource and print partial cash report.

Retrieved from "http://wiki.openbravo.com/wiki/POS_-_Category_sales_subreport_into_partial_cash_report"

This page has been accessed 8,500 times. This page was last modified on 5 January 2010, at 03:49. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.