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/2.30/HowTos/How To Create New Sequence

Contents

How To Create New Sequence

Objective

Create a new sequence for tickets.

Description

This guide is to add a new sequence to tickets. I've managed to add a new sequence to match my country's requirements (Dominican Republic), it is called NCF (Número de Consumidor Final). The structure of this sequences is composed by a prefix of 11 digits (A0100100102) which is fixed (doesn't change) followed by 8 incremental digits. So at the end we end up with this A01001001020000001 (A0100100102 + 0000001)

Note: You can use this guide to make any type of sequence with appropriate tweaks.

First of all

Before we dive into the code editing, we need to do some changes in our database (MySQL in this case, but you can edit according to your DB).

First we create a new table called "TICKETSNUM_NCF" in there will be stored the sequence's next number. If you would like to start the sequence at a particular digit just edit the "ID" column to match your value.

CREATE TABLE  `openbravopos`.`TICKETSNUM_NCF` (
  `ID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
INSERT INTO TICKETSNUM_NCF VALUES(1);

Then we edit the "TICKET" table to add a "NCF" column with integer type to it.

ALTER TABLE `openbravopos`.`TICKETS` ADD `NCF` int(8)

Steps

How this is going to work

I'm going to paste the necessary edits with the approximate line number. I will not paste the whole involving that method/declaration, I will put three dots where there is code between the new line.

Step 1

Make changes to the TicketInfo.java file (com/openbravo/pos/ticket/TicketInfo.java)

Initialize the m_iTicketNCF variable. [Line 52]

public class TicketInfo implements SerializableRead, Externalizable {
    ...
    private int m_iTicketNCF; // NCF
    ...
}

Add initial value to the variable. [Line 68]

public TicketInfo() {
        ...
        m_iTicketNCF = 0; // NCF
        ...
    }
// Line 86
 
    public void writeExternal(ObjectOutput out) throws IOException {
        ...
        out.writeInt(m_iTicketNCF); // NCF
        ...
    }
  // Line 98

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        ...
        m_iTicketNCF = in.readInt(); // NCF
        ...
    }

We get the value from the DB. Column 10 of the table.

// Line 125
 
    public void readValues(DataRead dr) throws BasicException {
        ...
        m_iTicketNCF = dr.getInt(10).intValue(); // NCF
        ...
    }


// Line 137
 
public TicketInfo copyTicket() {
        ...
        t.m_iTicketNCF = m_iTicketNCF; // NCF
        ...
}

Get the ticket NCF method.

// Line 177
 
    public int getTicketNCF() {
        return m_iTicketNCF; // NCF
    }

Used to set the ticket NCF.

// Line 185
 
    public void setTicketNCF(int iTicketNCF) {
        m_iTicketNCF = iTicketNCF; // NCF
    // refreshLines();
    }

In this line it is kind of important to make the output of the integer not-formatted (without commas) as it will match the sequence better.

// Líne 447
 
    public String printNCF() {
        if (m_iTicketNCF > 0) {
            // valid ticket NCF
            // Instead of formatting send a real plain integer
            return Integer.toString(m_iTicketNCF);
        } else {
            return "";
        }
    }

Step 2

Editing DataLogicSales.java file (com/openbravo/pos/forms/DataLogicSales.java). This file contains all the logic needed to interact with the database. It is kind of tricky to see the changes on this ones, but I suggest looking at the SQL queries.

// Line 189

public SentenceList getTicketsList() {
          return new StaticSentence(s
             , new QBFBuilder(
             "SELECT T.TICKETID, T.TICKETTYPE, R.DATENEW, P.NAME, C.NAME, SUM(PM.TOTAL), T.NCF "+
             "FROM RECEIPTS R JOIN TICKETS T ON R.ID = T.ID LEFT OUTER JOIN PAYMENTS PM ON R.ID = PM.RECEIPT LEFT OUTER JOIN CUSTOMERS C ON C.ID = T.CUSTOMER LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID " +
             "WHERE ?(QBF_FILTER) GROUP BY T.ID, T.TICKETID, T.TICKETTYPE, R.DATENEW, P.NAME, C.NAME ORDER BY R.DATENEW DESC, T.TICKETID", new String[] {"T.TICKETID", "T.TICKETTYPE", "PM.TOTAL", "R.DATENEW", "R.DATENEW", "P.NAME", "C.NAME"})
             , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.INT, Datas.OBJECT, Datas.INT, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING})
             , new SerializerReadClass(FindTicketsInfo.class));
     }
// Líne 296
 
    public final TicketInfo loadTicket(final int tickettype, final int ticketid, final int ticketncf) throws BasicException {
        TicketInfo ticket = (TicketInfo) new PreparedSentence(s
                , "SELECT T.ID, T.TICKETTYPE, T.TICKETID, R.DATENEW, R.MONEY, R.ATTRIBUTES, P.ID, P.NAME, T.CUSTOMER, T.NCF FROM RECEIPTS R JOIN TICKETS T ON R.ID = T.ID LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID WHERE T.TICKETTYPE = ? AND T.TICKETID = ?" //NCF
        ...
    }
// Líne 326
  public final void saveTicket(final TicketInfo ticket, final String location) throws BasicException {
 
        Transaction t = new Transaction(s) {
            public Object transact() throws BasicException {
		...
		// Set Receipt NCF
                ticket.setTicketNCF(getNextTicketNCF().intValue());
		...
	}});
 
   new PreparedSentence(s
    , "INSERT INTO TICKETS (ID, TICKETTYPE, TICKETID, PERSON, CUSTOMER, NCF) VALUES (?, ?, ?, ?, ?, ?)" // NCF
    , SerializerWriteParams.INSTANCE
    ).exec(new DataParams() { public void writeValues() throws BasicException {
        ...
        setInt(6, ticket.getTicketNCF()); // NCF
    }});


// Líne 528
 
    //Get NCF Sequence's next value
    public final Integer getNextTicketNCF() throws BasicException {
        return (Integer) s.DB.getSequenceSentence(s, "TICKETSNUM_NCF").find();
    }

Step 3

Lastly we need to make changes to the Ticket templates. This could be done on the templates located within the source or at the "Resources" (OpenBravo -> Mantenimiento -> Recursos -> Printer.Ticket). In this code what we do is get the NCF value and then format it to satisfy our sequence requirements, adding zeros to the beginning of it until it has an 8 character string.

<line>
            <text align="center" length="42">RNC: 0-00-00000-0</text>
        </line>
        <line>
            <text align="center" length="42">VALIDA PARA CONSUMIDOR FINAL:</text>
        </line>
        <line>
            #set( $tmp = "${ticket.printNCF()}" )
            #set( $str = $tmp )
            #set( $tmp = $tmp.length() + 1 )
            #foreach( $char in [$tmp..8] )
              #set( $str = "0" + $str )
            #end
          <!-- This will print the NCF in appropiate format: A010010010200000000 -->
          <text align="center" length="42">NCF: A0100100102${str}</text>
        </line>
        <line></line>

That is it. If you want to comment on this, recommendations are welcomed here: [1]

Retrieved from "http://wiki.openbravo.com/wiki/POS/2.30/HowTos/How_To_Create_New_Sequence"

This page has been accessed 8,700 times. This page was last modified on 30 March 2010, at 18:38. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.