}
}
CreateOrderInput orders;
for (int i = 0; i < ticketlist.size(); i++) {
TicketInfo ticket = ticketlist.get(i);
String userID = usersMap.get(ticket.getCustomerId());
orders = new CreateOrderInput();
orders.setPayment_method_id(externalsales.getWsPayID());
orders.setPrice_including_tax(String.valueOf(ticket.getTotal()));
orders.setProduct_currency("EUR");
orders.setShipping_carrier_name("0");
orders.setShipping_method("0");
orders.setShipping_price("0");
orders.setShipping_rate_id("0");
orders.setShipping_rate_name("0");
orders.setUser_id(userID);
orders.setVendor_id(externalsales.getWsPosid());
Product[] products = new Product[ticket.getLines().size()];
for (int j = 0; j < ticket.getLines().size(); j++) {
TicketLineInfo line = ticket.getLines().get(j);
// String pDesc = line.getProductName();
String pDesc = "";
products[j] = new Product();
System.out.println("> " + line.getProductName());
try {
if (line.getProductID().equals("0")) {
pDesc = line.getProductName();
products[j].setProduct_id(productsMap.get(line.getProductID()));
products[j].setQuantity(String.valueOf(line.getMultiply() * line.getPriceTax() * 100));
//pDesc += " " + String.valueOf(line.getMultiply()) + " > " + line.getPriceTax();
} else {
products[j].setProduct_id(productsMap.get(line.getProductID()));
products[j].setQuantity(String.valueOf(line.getMultiply()));
}
} catch (NullPointerException npe) {
pDesc = line.getProductName();
products[j].setProduct_id(productsMap.get("0"));
products[j].setQuantity(String.valueOf(line.getMultiply() * line.getPriceTax() * 100));
}
if (line.getProductAttSetInstDesc() != null && !line.getProductAttSetInstDesc().equals("")) {
if (pDesc.equalsIgnoreCase("")) {
pDesc += ", ";
}
pDesc += line.getProductAttSetInstDesc();
}
products[j].setDescription(pDesc);
//System.out.println(products[j].getProduct_id()+" "+products[j].getDescription());
}
orders.setCoupon_code("0");
orders.setProducts(products);
Double totalpaid = 0.0;
for (int j = 0; j < ticket.getPayments().size(); j++) {
PaymentInfo payment = ticket.getPayments().get(j);
if (("magcard".equals(payment.getName()))
|| ("cheque".equals(payment.getName()))
|| ("cash".equals(payment.getName()))) {
totalpaid += payment.getTotal();
}
}
totalpaid = (Math.round(totalpaid * 100.0)) / 1.0;
String note = ("TicketID=" + ticket.printId() + ",TotalPaid=" + (totalpaid / 100) + ",Vendeur=" + ticket.printUser());
// + ".Date." + ticket.printDate() + ".DateRetour." + ticket.printDateReturn() + ".DateRendu." + ticket.printDateRendu());
orders.setCustomer_note(note);
String orderID = externalsales.uploadOrders(orders);
if (!orderID.equals("")) {
cpt++;
// Set status as orderID from the website (correlation)
externalsales.updateStatus(orderID, ticket.getDate(), ticket.getDateReturn());
if (totalpaid >= Math.round((ticket.getTotal() * 100))) {
//Payment made set as paid on website
externalsales.setPaid(orderID, ticket.getDate());
}
if (ticket.getTicketType() == TicketInfo.RECEIPT_REFUND) {
//The ticket is a refund, Add return date locally and update website status
dlintegration.execUpdateTicketsRefundPayment(String.valueOf(ticket.getTicketType()), String.valueOf(ticket.getStatus()));
externalsales.setRendu(orderID);
} else if (ticket.getTicketType() == TicketInfo.RECEIPT_NORMAL) // Normal ticket > Update status to website orderId
{
dlintegration.execUpdateTicket(String.valueOf(ticket.getTicketId()), orderID);
}
}
}
}
//PAYMENTS
List<Integer> orderids = dlintegration.getTicketsPayments();
if (orderids.size() > 0) {
for (Integer oid : orderids) {
// List<Double> dd = dlintegration.getDebt(oid);
double dd = Math.round(dlintegration.getDebt(String.valueOf(oid)) * 100) / 100;
double dp = Math.round(dlintegration.getPaid(String.valueOf(oid)) * 100) / 100;
if ((dd + dp) <= 0.0) {
//for each ticket of paid type set paid on website
externalsales.setPaid(String.valueOf(oid), null);
// then update the date return to know it was updated on the website
dlintegration.execUpdateTicketsRefundPayment(String.valueOf(TicketInfo.RECEIPT_PAYMENT), String.valueOf(oid));
dlintegration.execUpdateTicketsRefundPayment(String.valueOf(TicketInfo.RECEIPT_REFUND), String.valueOf(oid));
}
}
}
//RETURNS
List<TicketInfo> ticketlistr = dlintegration.getTicketsReturned();
if (ticketlistr.size() > 0) {
for (TicketInfo ticket : ticketlistr) {
//each returned tickets are updated as returned on the website
if (ticket.getTicketType() == 0 && externalsales.setRendu(String.valueOf(ticket.getStatus()))) {
if (WSInfo.isWsdeletert()) {
dlsales.deleteTicket(ticket, "0");
}
} else {
if (WSInfo.isWsdeletert()) {