Calendar cal = new GregorianCalendar();
date = cal.get(Calendar.DATE) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.YEAR) ;
g.setFont(theFont);
g.drawString("Postila",80,10);
try{
DbBean db = new DbBean();
db.connect();
int id = 0;
String mySQL = "SELECT MAX(id) from pos";
ResultSet rs = db.execSQL(mySQL);
while (rs.next()) {
id = rs.getInt(1);
}
g.drawString("No.",10,20);
g.drawString(String.valueOf(id),25,20);
int x=5,y=35;
mySQL = "SELECT posId, name, quantity, price FROM product_pos a JOIN pos b on a.posId=b.id JOIN product c on c.code=a.productCode WHERE posId = '" + id + "'";
rs = db.execSQL(mySQL);
while (rs.next()) {
name = (rs.getString("name"));
qty = (rs.getInt("quantity"));
subtotal = qty * (rs.getDouble("price"));
total = total + subtotal;
len = String.valueOf(subtotal).length() * 6;
len1 = String.valueOf(qty).length() * 5;
g.drawString(name, x, y); x+=100;
g.drawString(String.valueOf(Check.viewMoney(new BigDecimal(qty))), x-len1, y); x+=80;
g.drawString(String.valueOf(Check.viewMoney(new BigDecimal(subtotal))), x-len, y);
x=5; y+=10;
}
g.drawString(date,130,20);
len = String.valueOf(total).length() * 6;
g.drawLine(180-len,y-7,180,y-7);
g.drawString(String.valueOf(Check.viewMoney(new BigDecimal(total))), 185-len, y+7);
db.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}