# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1548861487 -19800
#      Wed Jan 30 20:48:07 2019 +0530
# Node ID 22b071f5c3ce0a7f3ea684bee0d72d4c13429bd9
# Parent  64c74df0d918194d0a8d0a3c4d56bbe9aef7f51e
Related to issue 40061 : Applied New Java Formatting

diff -r 64c74df0d918 -r 22b071f5c3ce src/org/openbravo/retail/posterminal/UpdateCashup.java
--- a/src/org/openbravo/retail/posterminal/UpdateCashup.java	Fri Dec 14 15:28:47 2018 +0530
+++ b/src/org/openbravo/retail/posterminal/UpdateCashup.java	Wed Jan 30 20:48:07 2019 +0530
@@ -52,12 +52,13 @@
     // to get the lock on the record. The reason for this is to prevent the same cash up from being
     // processed twice in case of very quick duplicated requests.
     // These shouldn't happen in general but may happen specifically in case of unreliable networks
-    OBPOSApplications posTerminal = OBDal.getInstance().get(OBPOSApplications.class,
-        jsonCashup.getString("posterminal"));
+    OBPOSApplications posTerminal = OBDal.getInstance()
+        .get(OBPOSApplications.class, jsonCashup.getString("posterminal"));
     Date cashUpReportDate = null;
     Date lastCashUpReportDate = null;
     OBPOSAppCashup cashUp = null;
-    Query cashUpQuery = OBDal.getInstance().getSession()
+    Query cashUpQuery = OBDal.getInstance()
+        .getSession()
         .createQuery("from OBPOS_App_Cashup where id=:cashUpId");
     cashUpQuery.setParameter("cashUpId", cashUpId);
     // The record will be locked to this process until it ends. Other requests to process this cash
@@ -76,8 +77,8 @@
             PropertyByType.DATETIME,
             (cashUpReportString).subSequence(0, (cashUpReportString).lastIndexOf("Z")) + ":00");
       } else {
-        cashUpReportDate = (Date) JsonToDataConverter.convertJsonToPropertyValue(
-            PropertyByType.DATETIME, cashUpReportString);
+        cashUpReportDate = (Date) JsonToDataConverter
+            .convertJsonToPropertyValue(PropertyByType.DATETIME, cashUpReportString);
       }
     }
 
@@ -108,7 +109,8 @@
       } catch (JSONException e) {
         throw new OBException("Cashup JSON seems to be corrupted: ", e);
       } catch (Exception e) {
-        Query maybeCashupWasCreatedInParallel = OBDal.getInstance().getSession()
+        Query maybeCashupWasCreatedInParallel = OBDal.getInstance()
+            .getSession()
             .createQuery("from OBPOS_App_Cashup where id=:cashUpId");
         maybeCashupWasCreatedInParallel.setParameter("cashUpId", cashUpId);
         cashUp = (OBPOSAppCashup) maybeCashupWasCreatedInParallel.uniqueResult();
@@ -128,9 +130,8 @@
     }
 
     // If the cashup is new or the incoming cashup report is newer, update the cashUp info
-    if (cashUp.getLastcashupreportdate() == null
-        || (lastCashUpReportDate != null && lastCashUpReportDate.getTime() >= cashUp
-            .getLastcashupreportdate().getTime())) {
+    if (cashUp.getLastcashupreportdate() == null || (lastCashUpReportDate != null
+        && lastCashUpReportDate.getTime() >= cashUp.getLastcashupreportdate().getTime())) {
       if (jsonCashup.has("objToSend")) {
         JSONObject jsonInfoCashUp = new JSONObject(jsonCashup.getString("objToSend"));
         // JSONObject jsonInfoCashUp = (JSONObject) jsonCashup.get("objToSend");
@@ -145,8 +146,8 @@
     }
 
     // Associate master/slave cashup
-    if ((posTerminal.isMaster() && posTerminal.getOBPOSApplicationsMasterterminalIDList().size() != cashUp
-        .getOBPOSAppCashupObposParentCashupIDList().size())
+    if ((posTerminal.isMaster() && posTerminal.getOBPOSApplicationsMasterterminalIDList()
+        .size() != cashUp.getOBPOSAppCashupObposParentCashupIDList().size())
         || (posTerminal.getMasterterminal() != null && cashUp.getObposParentCashup() == null)) {
       associateMasterSlave(cashUp, posTerminal);
     }
@@ -163,8 +164,8 @@
    * @throws JSONException
    */
   private static void updateCashUpInfo(OBPOSAppCashup cashup, JSONObject jsonCashup,
-      Date cashUpDate, Date cashUpReportDate, Date lastCashUpReportDate) throws JSONException,
-      OBException {
+      Date cashUpDate, Date cashUpReportDate, Date lastCashUpReportDate)
+      throws JSONException, OBException {
 
     if (cashup.isProcessed() && jsonCashup.getString("isprocessed").equalsIgnoreCase("N")) {
       throw new OBException("The cashup is processed, and it can not be set as unprocessed");
@@ -173,8 +174,8 @@
     cashup.setGrosssales(new BigDecimal(jsonCashup.getString("grossSales")));
     cashup.setNetreturns(new BigDecimal(jsonCashup.getString("netReturns")));
     cashup.setGrossreturns(new BigDecimal(jsonCashup.getString("grossReturns")));
-    cashup.setTotalretailtransactions(new BigDecimal(jsonCashup
-        .getString("totalRetailTransactions")));
+    cashup.setTotalretailtransactions(
+        new BigDecimal(jsonCashup.getString("totalRetailTransactions")));
     cashup.setProcessed(jsonCashup.getString("isprocessed").equalsIgnoreCase("Y"));
     cashup.setCashUpDate(cashUpDate);
     cashup.setLastcashupreportdate(lastCashUpReportDate);
@@ -183,16 +184,10 @@
       // In case of Slave/Master Check if slave is processed or not
       for (OBPOSAppCashup slaveCashup : cashup.getOBPOSAppCashupObposParentCashupIDList()) {
         if (!slaveCashup.isProcessed()) {
-          log.debug("Master/Slave association ("
-              + new Date()
-              + "): Unlink slave terminal: "
-              + slaveCashup.getPOSTerminal().getName()
-              + " and Cashup id: "
-              + slaveCashup.getId()
-              + " linked with master terminal: "
-              + cashup.getPOSTerminal().getName()
-              + " and Cashup id: "
-              + cashup.getId()
+          log.debug("Master/Slave association (" + new Date() + "): Unlink slave terminal: "
+              + slaveCashup.getPOSTerminal().getName() + " and Cashup id: " + slaveCashup.getId()
+              + " linked with master terminal: " + cashup.getPOSTerminal().getName()
+              + " and Cashup id: " + cashup.getId()
               + " because slave terminal has no transactions and it will be associated with the next master terminal cashup");
           slaveCashup.setObposParentCashup(null);
           OBDal.getInstance().save(slaveCashup);
@@ -203,8 +198,8 @@
   }
 
   private static void updateOrCreateCashupInfo(String cashUpId, JSONObject jsonCashup,
-      Date cashUpDate, Date cashUpReportDate, Date lastCashUpReportDate) throws JSONException,
-      OBException {
+      Date cashUpDate, Date cashUpReportDate, Date lastCashUpReportDate)
+      throws JSONException, OBException {
     OBPOSAppCashup cashup = OBDal.getInstance().get(OBPOSAppCashup.class, cashUpId);
     // Update cashup info
     updateCashUpInfo(cashup, jsonCashup, cashUpDate, cashUpReportDate, lastCashUpReportDate);
@@ -223,18 +218,19 @@
       JSONArray paymentCashupInfo = jsonCashup.getJSONArray("cashPaymentMethodInfo");
       for (int i = 0; i < paymentCashupInfo.length(); ++i) {
         JSONObject payment = paymentCashupInfo.getJSONObject(i);
-        if ((payment.has("newPaymentMethod") && payment.getString("newPaymentMethod")
-            .equals("true"))
-            || (payment.has("usedInCurrentTrx") && payment.getString("usedInCurrentTrx").equals(
-                "true"))) {
+        if ((payment.has("newPaymentMethod")
+            && payment.getString("newPaymentMethod").equals("true"))
+            || (payment.has("usedInCurrentTrx")
+                && payment.getString("usedInCurrentTrx").equals("true"))) {
+
           // Set Amount To Keep
           if (jsonCashup.has("cashCloseInfo")) {
             // Get the paymentMethod id
             JSONArray cashCloseInfo = jsonCashup.getJSONArray("cashCloseInfo");
             for (int j = 0; j < cashCloseInfo.length(); ++j) {
               JSONObject paymentMethod = cashCloseInfo.getJSONObject(j);
-              if (paymentMethod.getString("paymentTypeId").equals(
-                  payment.getString("paymentMethodId"))) {
+              if (paymentMethod.getString("paymentTypeId")
+                  .equals(payment.getString("paymentMethodId"))) {
                 payment.put("amountToKeep",
                     paymentMethod.getJSONObject("paymentMethod").getString("amountToKeep"));
                 BigDecimal expected = BigDecimal.ZERO;
@@ -245,9 +241,9 @@
                   difference = new BigDecimal(paymentMethod.getString("difference"));
                 } else if (paymentMethod.has("foreignExpected")) {
                   expected = new BigDecimal(paymentMethod.getString("foreignExpected"));
-                  difference = new BigDecimal(
-                      paymentMethod.has("foreignDifference") ? paymentMethod
-                          .getString("foreignDifference") : paymentMethod.getString("difference"));
+                  difference = new BigDecimal(paymentMethod.has("foreignDifference")
+                      ? paymentMethod.getString("foreignDifference")
+                      : paymentMethod.getString("difference"));
                 }
                 payment.put("totalCounted",
                     expected.add(difference).setScale(2, RoundingMode.HALF_UP).toString());
@@ -268,8 +264,8 @@
    */
   private static void createPaymentMethodCashUp(OBPOSAppCashup cashup, JSONObject jsonCashup)
       throws JSONException {
-    OBPOSPaymentMethodCashup newPaymentMethodCashUp = OBDal.getInstance().get(
-        OBPOSPaymentMethodCashup.class, jsonCashup.get("id"));
+    OBPOSPaymentMethodCashup newPaymentMethodCashUp = OBDal.getInstance()
+        .get(OBPOSPaymentMethodCashup.class, jsonCashup.get("id"));
 
     if (newPaymentMethodCashUp == null) {
       newPaymentMethodCashUp = OBProvider.getInstance().get(OBPOSPaymentMethodCashup.class);
@@ -277,8 +273,8 @@
       newPaymentMethodCashUp.setId(jsonCashup.get("id"));
       cashup.getOBPOSPaymentmethodcashupList().add(newPaymentMethodCashUp);
     }
-    JSONPropertyToEntity.fillBobFromJSON(newPaymentMethodCashUp.getEntity(),
-        newPaymentMethodCashUp, jsonCashup);
+    JSONPropertyToEntity.fillBobFromJSON(newPaymentMethodCashUp.getEntity(), newPaymentMethodCashUp,
+        jsonCashup);
     newPaymentMethodCashUp.setCashUp(cashup);
 
     newPaymentMethodCashUp.setOrganization(cashup.getOrganization());
@@ -292,15 +288,17 @@
     newPaymentMethodCashUp.setTotalreturns(new BigDecimal(jsonCashup.getString("totalReturns")));
     newPaymentMethodCashUp.setTotalDeposits(new BigDecimal(jsonCashup.getString("totalDeposits")));
     newPaymentMethodCashUp.setTotalDrops(new BigDecimal(jsonCashup.getString("totalDrops")));
-    newPaymentMethodCashUp.setTotalCounted(jsonCashup.has("totalCounted") ? new BigDecimal(
-        jsonCashup.getString("totalCounted")) : BigDecimal.ZERO);
-    newPaymentMethodCashUp.setAmountToKeep(jsonCashup.has("amountToKeep") ? new BigDecimal(
-        jsonCashup.getString("amountToKeep")) : BigDecimal.ZERO);
+    newPaymentMethodCashUp.setTotalCounted(
+        jsonCashup.has("totalCounted") ? new BigDecimal(jsonCashup.getString("totalCounted"))
+            : BigDecimal.ZERO);
+    newPaymentMethodCashUp.setAmountToKeep(
+        jsonCashup.has("amountToKeep") ? new BigDecimal(jsonCashup.getString("amountToKeep"))
+            : BigDecimal.ZERO);
     newPaymentMethodCashUp.setRate(new BigDecimal(jsonCashup.getString("rate")));
     newPaymentMethodCashUp.setIsocode((String) jsonCashup.get("isocode"));
 
-    OBPOSAppPayment appPayment = OBDal.getInstance().get(OBPOSAppPayment.class,
-        jsonCashup.getString("paymentMethodId"));
+    OBPOSAppPayment appPayment = OBDal.getInstance()
+        .get(OBPOSAppPayment.class, jsonCashup.getString("paymentMethodId"));
     newPaymentMethodCashUp.setPaymentType(appPayment);
 
     String name = appPayment.getCommercialName();
@@ -316,8 +314,8 @@
    */
   private static void createTaxCashUp(OBPOSAppCashup cashup, JSONObject jsonCashup)
       throws JSONException {
-    OBPOSTaxCashup newTax = OBDal.getInstance().get(OBPOSTaxCashup.class,
-        jsonCashup.getString("id"));
+    OBPOSTaxCashup newTax = OBDal.getInstance()
+        .get(OBPOSTaxCashup.class, jsonCashup.getString("id"));
     if (newTax == null) {
       newTax = OBProvider.getInstance().get(OBPOSTaxCashup.class);
       newTax.setNewOBObject(true);
@@ -342,8 +340,8 @@
           + OBPOSAppCashup.PROPERTY_ISPROCESSEDBO + " = 'N' and "
           + OBPOSAppCashup.PROPERTY_ISPROCESSED + " = 'N' and "
           + OBPOSAppCashup.PROPERTY_OBPOSPARENTCASHUP + " is null";
-      OBQuery<OBPOSAppCashup> appCashupQuery = OBDal.getInstance().createQuery(
-          OBPOSAppCashup.class, query);
+      OBQuery<OBPOSAppCashup> appCashupQuery = OBDal.getInstance()
+          .createQuery(OBPOSAppCashup.class, query);
       appCashupQuery.setNamedParameter("terminalId", posTerminal.getId());
       List<OBPOSAppCashup> appCashupList = appCashupQuery.list();
       for (OBPOSAppCashup appCashup : appCashupList) {
@@ -377,8 +375,8 @@
         query = OBPOSAppCashup.PROPERTY_POSTERMINAL + ".id = :terminalId and "
             + OBPOSAppCashup.PROPERTY_ISPROCESSEDBO + " = 'N' and "
             + OBPOSAppCashup.PROPERTY_ISPROCESSED + " = 'N' ";
-        OBQuery<OBPOSAppCashup> appCashupQuery = OBDal.getInstance().createQuery(
-            OBPOSAppCashup.class, query);
+        OBQuery<OBPOSAppCashup> appCashupQuery = OBDal.getInstance()
+            .createQuery(OBPOSAppCashup.class, query);
         appCashupQuery.setNamedParameter("terminalId", posTerminal.getMasterterminal().getId());
         List<OBPOSAppCashup> appCashupList = appCashupQuery.list();
         if (appCashupList.size() > 0 && cashUp.getObposParentCashup() == null) {
