View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

POS - Sales subreport into partial cash report

Code snippet

Name: POS - Sales subreport into partial cash report
Version: POS 2.30
Author: Andrej Svininykh



I create this subreport for resolve Issue 27 in my project.

Add new methods into PaymentsModel

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

Example english sales subreport
Example russian sales subreport
 
...
public class PaymentsModel {
...
    private java.util.List<PaymentsLine> m_lpayments;
 
    private Integer m_iProductSalesRows;
    private Double m_dProductSalesTotalUnits;
    private Double m_dProductSalesTotal;
    private java.util.List<ProductSalesLine> m_lproductsales;
    
    private final static String[] PAYMENTHEADERS = {"Label.Payment", "label.totalcash"};
...
 
    public static PaymentsModel emptyInstance() {
...     
        p.m_lpayments = new ArrayList<PaymentsLine>();
 
        p.m_iProductSalesRows = new Integer(0);
        p.m_dProductSalesTotalUnits = new Double(0.0);
        p.m_dProductSalesTotal = new Double(0.0);
        p.m_lproductsales = new ArrayList<ProductSalesLine>();
        
        p.m_iSales = null;
...
    public static PaymentsModel loadInstance(AppView app) throws BasicException {
...
        // Product Sales
        Object[] valproductsales = (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 (valproductsales == null) {
            p.m_iProductSalesRows = new Integer(0);
            p.m_dProductSalesTotalUnits = new Double(0.0);
            p.m_dProductSalesTotal = new Double(0.0);
        } else {
            p.m_iProductSalesRows = (Integer) valproductsales[0];
            p.m_dProductSalesTotalUnits = (Double) valproductsales[1];
            p.m_dProductSalesTotal= (Double) valproductsales[2];
        }
 
        List products = new StaticSentence(app.getSession()
            , "SELECT PRODUCTS.NAME, SUM(TICKETLINES.UNITS), TICKETLINES.PRICE, TAXES.RATE " +
              "FROM TICKETLINES, TICKETS, RECEIPTS, PRODUCTS, TAXES " +
              "WHERE TICKETLINES.PRODUCT = PRODUCTS.ID AND TICKETLINES.TICKET = TICKETS.ID AND TICKETS.ID = RECEIPTS.ID AND TICKETLINES.TAXID = TAXES.ID AND RECEIPTS.MONEY = ? " +
              "GROUP BY PRODUCTS.NAME, TICKETLINES.PRICE, TAXES.RATE"
            , SerializerWriteString.INSTANCE
            , new SerializerReadClass(PaymentsModel.ProductSalesLine.class)) //new SerializerReadBasic(new Datas[] {Datas.STRING, Datas.DOUBLE}))
            .list(app.getActiveCashIndex());
 
        if (products == null) {
            p.m_lproductsales = new ArrayList();
        } else {
            p.m_lproductsales = products;
        }
...

Add new methods into PaymentsModel class:

 
...
    public double getProductSalesRows() {
        return m_iProductSalesRows.intValue();
    }
 
    public String printProductSalesRows() {
        return Formats.INT.formatValue(m_iProductSalesRows);
    }
 
    public double getProductSalesTotalUnits() {
        return m_dProductSalesTotalUnits.doubleValue();
    }
 
    public String printProductSalesTotalUnits() {
        return Formats.DOUBLE.formatValue(m_dProductSalesTotalUnits);
    }
 
    public double getProductSalesTotal() {
        return m_dProductSalesTotal.doubleValue();
    }
 
    public String printProductSalesTotal() {
        return Formats.CURRENCY.formatValue(m_dProductSalesTotal);
    }
 
    public List<ProductSalesLine> getProductSalesLines() {
        return m_lproductsales;
    }
...

And add new public class ProductSalesLine:

 
...
    public static class ProductSalesLine implements SerializableRead {
 
        private String m_ProductName;
        private Double m_ProductUnits;
        private Double m_ProductPrice;
        private Double m_TaxRate;
        private Double m_ProductPriceTax;
 
        public void readValues(DataRead dr) throws BasicException {
            m_ProductName = dr.getString(1);
            m_ProductUnits = dr.getDouble(2);
            m_ProductPrice = dr.getDouble(3);
            m_TaxRate = dr.getDouble(4);
 
            m_ProductPriceTax = m_ProductPrice + m_ProductPrice*m_TaxRate;
        }
 
        public String printProductName() {
            return StringUtils.encodeXML(m_ProductName);
        }
 
        public String printProductUnits() {
            return Formats.DOUBLE.formatValue(m_ProductUnits);
        }
 
        public Double getProductUnits() {
            return m_ProductUnits;
        }
 
        public String printProductPrice() {
            return Formats.CURRENCY.formatValue(m_ProductPrice);
        }
 
        public Double getProductPrice() {
            return m_ProductPrice;
        }
 
        public String printTaxRate() {
            return Formats.PERCENT.formatValue(m_TaxRate);
        }
 
        public Double getTaxRate() {
            return m_TaxRate;
        }
 
        public String printProductPriceTax() {
            return Formats.CURRENCY.formatValue(m_ProductPriceTax);
        }
        
        public String printProductSubValue() {
            return Formats.CURRENCY.formatValue(m_ProductPriceTax*m_ProductUnits);
        }
    }
...

Edit source code and compilation project.

Edit Print.PartialCash.xml template

Add new lines into Print.PartialCash resource:

 
        <line>
            <text bold="true">Sales report</text>
        </line>
        <line>
            <text align ="left" length="12">Name</text>
            <text align ="right" length="14">Price+Tax</text>
            <text align ="right" length="1"></text>
            <text align ="right" length="5">Unit</text>
            <text align ="right" length="10">Total</text>
        </line>
        <line>
            <text>------------------------------------------</text>
        </line>
        #foreach ($line in $payments.getProductSalesLines())
        <line>
            <text align ="left" length="12">${line.printProductName()}</text>
            <text align ="right" length="10">${line.printProductPriceTax()}</text>
            <text align ="right" length="5">${line.printTaxRate()}</text>
            <text align ="right" length="5">${line.printProductUnits()}</text>
            <text align ="right" length="10">${line.printProductSubValue()}</text>
        </line>
        #end
        <line>
            <text>------------------------------------------</text>
        </line>
        <line>
            <text align ="left" length="32">Ticket rows:</text>
            <text align ="right" length="10">${payments.printProductSalesRows()}</text>
        </line>
        <line></line>
        <line size="1">
            <text align ="left" length="22" bold="true">Total</text>
            <text align ="right" length="10" bold="true">${payments.printProductSalesTotalUnits()}</text>
            <text align ="right" length="10" bold="true">${payments.printProductSalesTotal()}</text>
        </line>

Save resource and print partial cash report.

Please write you response into forum thread.

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

This page has been accessed 8,574 times. This page was last modified on 5 October 2010, at 10:39. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.