final String payment_total = request.getParameter("payment_total");
final String erp_org = request.getParameter("erp.org");
final Order iOrder = new Order();
final ExternalPOS extPos = (ExternalPOS) obq.list().get(0);
// Client
iOrder.setClient(extPos.getClient());
// Organization
final Organization syncOrgSel = (Organization) OBDal.getInstance().get(
"Organization", erp_org);
iOrder.setOrganization(syncOrgSel);
// Sales representative
iOrder.setSalesRepresentative(extPos.getSalesRepresentative());
// Warehouse
iOrder.setWarehouse(extPos.getWarehouse());
// Price list
iOrder.setPriceList(extPos.getPriceList());
// Currency
iOrder.setCurrency(extPos.getPriceList().getCurrency());
// Shipping company
iOrder.setShippingCompany(extPos.getShippingCompany());
// Business Partner
if (bp_id == null) {
final BusinessPartner syncBp = extPos.getBusinessPartner();
iOrder.setBusinessPartner(syncBp);
final Location syncBpLoc = (syncBp.getBusinessPartnerLocationList()
.isEmpty()) ? null : syncBp
.getBusinessPartnerLocationList().get(0);
iOrder.setPartnerAddress(syncBpLoc);
// Payment Term
iOrder.setPaymentTerms(syncBp.getPaymentTerms());
} else {
final BusinessPartner syncSelBp = (BusinessPartner) OBDal
.getInstance().get("BusinessPartner", bp_id);
iOrder.setBusinessPartner(syncSelBp);
final Location syncBpLoc = (syncSelBp
.getBusinessPartnerLocationList().isEmpty()) ? null
: syncSelBp.getBusinessPartnerLocationList().get(0);
iOrder.setPartnerAddress(syncBpLoc);
}
// Document type
iOrder.setDocumentType(extPos.getDocumentType());
// Document number
iOrder.setDocumentNo(ti_id + "." + ti_type);
// Document name
iOrder.setDocumentTypeName(extPos.getDocumentType().getName());
// Product
final Product pro = (Product) OBDal.getInstance().get("Product",
line_product);
iOrder.setProduct(pro);