Post Wed Apr 10, 2013 6:19 pm

Adding number of customer for a receipt

First modify the database with this sql command :
  Code:
ALTER TABLE payments ADD COLUMN NBCUSTOMERS SMALLINT;


Go to : PaymentInfo.java
and add
line 32 :
  Code:
    private int m_dNbCustomers;

line 39 :
  Code:
    public Integer getNbCustomers() {
        return m_dNbCustomers;
    }

    public void setNbCustomers(Integer dNbCustomers) {
        this.m_dNbCustomers = dNbCustomers;
    }


Add in DataLogicSales.java
line 410:
  Code:
paymentinsert.exec(new DataParams() { public void writeValues() throws BasicException {
   setString(1, UUID.randomUUID().toString());
   setString(2, ticket.getId());
   setString(3, p.getName());
   setDouble(4, p.getTotal());
   setString(5, ticket.getTransactionID());
   setBytes(6, (byte[]) Formats.BYTEA.parseValue(ticket.getReturnMessage()));
   setInt(7,p.getNbCustomers()); // <-- THIS ****
}});


Create a ressource named for example "addNumberCustomers" and affect it to the "ticket.save" event in "Ticket.Buttons" ressource

  Code:
<event key="ticket.save" code="addNumberCustomers"/>

And paste this code :
  Code:
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import com.openbravo.pos.payment.PaymentInfo;

JFrame frame = new JFrame("Customers");
// 30 customer, you can change it
String[] TotalCustomers = new String[30];

for (int i = 0; i < TotalCustomers.length; i++) {
   TotalCustomers[i] = Integer.toString(i+1);
}

String v = JOptionPane.showInputDialog(frame, "Choisissez", "Combien de clients ?", JOptionPane.QUESTION_MESSAGE, null, TotalCustomers, "1");
try {
    int n = Integer.parseInt( v );
    PaymentInfo p = ticket.payments.getFirst();
    p.setNbCustomers(n);
}

catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Veuillez saisir le nombre de clients", "ATTENTION", JOptionPane.ERROR_MESSAGE);
    return "Cancel";
}