# HG changeset patch
# User Jorge Garcia <jorge.garcia@openbravo.com>
# Date 1474990746 -7200
#      Tue Sep 27 17:39:06 2016 +0200
# Node ID c2654d2919e8817ac23034708f4715014222e3d4
# Parent  030b6351be9367d361105ef83d823ad764f36f7c
Fixed issue 33939: SER QA 1790 Wrong remaining to pay amount when paying
with multicurrency

The solution is to not recalculate the value paid in other currency. For that,
it’s necessary to use the data stored in the transaction amount from the
payment.

diff --git a/src/org/openbravo/retail/posterminal/PaidReceipts.java b/src/org/openbravo/retail/posterminal/PaidReceipts.java
--- a/src/org/openbravo/retail/posterminal/PaidReceipts.java
+++ b/src/org/openbravo/retail/posterminal/PaidReceipts.java
@@ -246,15 +246,23 @@
         }
         for (int i = 0; i < listPaymentsIn.length(); i++) {
           JSONObject objectIn = (JSONObject) listPaymentsIn.get(i);
+
+          String hqlPaymentTrxAmount = "select p.financialTransactionAmount as amount "
+              + " from FIN_Payment as p where p.id=?)";
+          Query paymentTrxQuery = OBDal.getInstance().getSession().createQuery(hqlPaymentTrxAmount);
+          paymentTrxQuery.setString(0, objectIn.getString("paymentId"));
+          BigDecimal objPaymentTrx = BigDecimal.ZERO;
+          if (paymentTrxQuery.list().size() > 0) {
+            objPaymentTrx = (BigDecimal) paymentTrxQuery.list().get(0);
+          }
+
           boolean added = false;
           for (int j = 0; j < listPaymentsType.length(); j++) {
             JSONObject objectType = (JSONObject) listPaymentsType.get(j);
             if (objectIn.get("account").equals(objectType.get("account"))) {
               JSONObject paidReceiptPayment = new JSONObject();
               // FIXME: Multicurrency problem, amount always in terminal currency
-              paidReceiptPayment.put("amount", new BigDecimal((String) objectIn.get("amount")
-                  .toString()).multiply(new BigDecimal((String) objectType.get("mulrate")
-                  .toString())));
+              paidReceiptPayment.put("amount", objPaymentTrx);
               paidReceiptPayment.put("paymentDate", objectIn.get("paymentDate"));
               if (objectIn.has("paymentData")) {
                 paidReceiptPayment.put("paymentData",
@@ -267,8 +275,7 @@
               paidReceiptPayment.put("isocode", objectType.get("isocode"));
               paidReceiptPayment.put("openDrawer", objectType.get("openDrawer"));
               paidReceiptPayment.put("isPrePayment", true);
-              paidReceiptPayment.put("paymentAmount", new BigDecimal(objectIn.get("paymentAmount")
-                  .toString()).multiply(new BigDecimal(objectType.get("mulrate").toString())));
+              paidReceiptPayment.put("paymentAmount", objPaymentTrx);
               added = true;
               listpaidReceiptsPayments.put(paidReceiptPayment);
             }
