}
public void syncCustomer(final CustomerSync customer) throws BasicException {
Transaction t = new Transaction(s) {
public Object transact() throws BasicException {
// Sync the Customer in a transaction
// Try to update
if (new PreparedSentence(s,
"UPDATE CUSTOMERS SET ADDRESS = ?, ADDRESS2 = ?, POSTAL = ?, CITY = ?, REGION = ?, COUNTRY = ?, FIRSTNAME = ?, LASTNAME = ?, EMAIL = ?, PHONE = ?, PHONE2 = ?, NOTES = ?, MAXDEBT = ?, NAME = ? WHERE TAXID = ?",
SerializerWriteParams.INSTANCE
).exec(new DataParams() { public void writeValues() throws BasicException {
setString(1, customer.getAddress());
setString(2, customer.getAddress2());
setString(3, customer.getPostal());
setString(4, customer.getCity());
setString(5, customer.getRegion());
setString(6, customer.getCountry());
setString(7, customer.getFirstname());
setString(8, customer.getLastname());
setString(9, customer.getEmail());
setString(10, customer.getPhone());
setString(11, customer.getPhone2());
setString(12, customer.getNotes());
setDouble(13, customer.getMaxdebt());
setString(14, customer.getName());
setString(15, customer.getTaxid());
}}) == 0) {
if (TicketInfo.getPayID()==2) {
//ZAV CURDEBT 0,0001
new PreparedSentence(s,
"INSERT INTO CUSTOMERS(ID, SEARCHKEY, NAME, ADDRESS, ADDRESS2, POSTAL, CITY, REGION, COUNTRY, FIRSTNAME, LASTNAME, EMAIL, PHONE, PHONE2, NOTES, TAXID, MAXDEBT, VISIBLE, CURDEBT) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " + s.DB.TRUE() + ",-0.0001)",
SerializerWriteParams.INSTANCE
).exec(new DataParams() { public void writeValues() throws BasicException {
setString(1, customer.getId());
setString(2, customer.getSearchkey());
setString(3, customer.getName());
setString(4, customer.getAddress());
setString(5, customer.getAddress2());
setString(6, customer.getPostal());
setString(7, customer.getCity());
setString(8, customer.getRegion());
setString(9, customer.getCountry());
setString(10, customer.getFirstname());
setString(11, customer.getLastname());
setString(12, customer.getEmail());
setString(13, customer.getPhone());
setString(14, customer.getPhone2());
setString(15, customer.getNotes());
setString(16, customer.getTaxid());
setDouble(17, customer.getMaxdebt());
}});
} else {
// If not updated, try to insert
new PreparedSentence(s,
"INSERT INTO CUSTOMERS(ID, SEARCHKEY, NAME, ADDRESS, ADDRESS2, POSTAL, CITY, REGION, COUNTRY, FIRSTNAME, LASTNAME, EMAIL, PHONE, PHONE2, NOTES, TAXID, MAXDEBT, VISIBLE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " + s.DB.TRUE() + ")",
SerializerWriteParams.INSTANCE
).exec(new DataParams() { public void writeValues() throws BasicException {
setString(1, customer.getId());
setString(2, customer.getSearchkey());
setString(3, customer.getName());
setString(4, customer.getAddress());
setString(5, customer.getAddress2());
setString(6, customer.getPostal());
setString(7, customer.getCity());
setString(8, customer.getRegion());
setString(9, customer.getCountry());
setString(10, customer.getFirstname());
setString(11, customer.getLastname());
setString(12, customer.getEmail());
setString(13, customer.getPhone());
setString(14, customer.getPhone2());
setString(15, customer.getNotes());
setString(16, customer.getTaxid());
setDouble(17, customer.getMaxdebt());
}});
}
}
return null;
}
};
t.execute();
}