Verifies issue 37596 : Added automated test 'I37343_VerifyPymtScheDetailWithCredit' 3.0RR17Q3
authorRanjith S R <ranjith@qualiantech.com>
Tue, 23 Jan 2018 16:49:27 +0530
changeset 7012 10a3d846d5da
parent 6937 b6267de0b585
child 7013 807a61410114
Verifies issue 37596 : Added automated test 'I37343_VerifyPymtScheDetailWithCredit'
src-test/org/openbravo/test/mobile/retail/pack/database/WebPOSDatabaseConstants.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/layaway/I31471_PayLayawayAlreadyInvoiced.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I31600_VerfiyPaidOnCredit.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I35571_VerifyReceiptWithMutiPaymentTerm.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36841_VerifyInvoiceDueDateByNewTerms.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36907_VerifyReceiptWithPaymentTermLine.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36907_VerifyReceiptWithPaymentTermLineII.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I37343_VerifyPymtScheDetailWithCredit.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/database/WebPOSDatabaseConstants.java	Mon Dec 11 17:20:42 2017 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/pack/database/WebPOSDatabaseConstants.java	Tue Jan 23 16:49:27 2018 +0530
@@ -58,6 +58,10 @@
   public static final String VBS_OBPOS_APP_PAYMENT_TYPE_CARD = "4785B70E9C1048AB9E9E7B26CFEF6E31";
   public static final String VBS_OBPOS_APP_PAYMENT_TYPE_VOUCHER = "5A2A5B8DABCF49759C1D0EE674B2CD04";
 
+  public static final String PAYMENT_METHOD_CASH = "45A202BF44884F05B8A1BF741E2063B6";
+  public static final String PAYMENT_METHOD_CHEQUE = "CAE4A5CFD6EA485AAA5D7D5859341DB0";
+  public static final String PAYMENT_METHOD_WIRETRANSFER = "5A741F883A31408CA3AC097D76AA6D32";
+
   public static final String VBS1001_CASHBOOK_STORE = "Cashbook - Vall Blanca Store-VBS1001";
   public static final String VBS1001_CASHBOOK_STORE_CASH_FIN_ACCOUNT_ID = "320FA6FCAF794AE69631216F9B1D666F";
   public static final String VBS1001_CASHBOOK2_STORE_USACASH_FIN_ACCOUNT_ID = "327E875C44DB48E1AC6DA7FD3C9F3522";
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/layaway/I31471_PayLayawayAlreadyInvoiced.java	Mon Dec 11 17:20:42 2017 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/layaway/I31471_PayLayawayAlreadyInvoiced.java	Tue Jan 23 16:49:27 2018 +0530
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo S.L.U.
- * All portions are Copyright (C) 2008-2015 Openbravo S.L.U.
+ * All portions are Copyright (C) 2008-2017 Openbravo S.L.U.
  * All Rights Reserved.
  * Contributor(s):
  ************************************************************************
@@ -28,6 +28,11 @@
 import java.math.BigDecimal;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
 
 import org.junit.Test;
 import org.openbravo.test.mobile.core.utils.OBNumber;
@@ -57,6 +62,14 @@
     final String receiptNo = BackboneHelper.getDocumentNo();
     final String cashupId = BackboneHelper.getTerminalValue("cashUpId");
 
+    final DateFormat dateFormatUTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+    final DateFormat parseDateFormat = (DateFormat) dateFormatUTC.clone();
+    parseDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+    final DateFormat paymentDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+    paymentDateFormat.setTimeZone(TimeZone
+        .getTimeZone(Calendar.getInstance().getTimeZone().getID()));
+
     // Create the layaway
     tap(TestIdPack.BUTTON_MENU);
     tap(TestIdPack.BUTTON_MENU_LAYAWAYTHISRECEIPT);
@@ -94,8 +107,14 @@
         organizationId);
     // processInvoice(cInvoiceId);
     // Load the layaway and pay it.
-    final String reloadedOrderDate = retrieveLayawayAndPay(receiptNo, customer);
-    assertThat(originalOrderDate.substring(0, 10), equalTo(reloadedOrderDate.substring(0, 10)));
+    try {
+      final String reloadedOrderDate = paymentDateFormat.format(parseDateFormat
+          .parse(retrieveLayawayAndPay(receiptNo, customer)));
+
+      assertThat(originalOrderDate.substring(0, 10), equalTo(reloadedOrderDate.substring(0, 10)));
+    } catch (final ParseException e) {
+
+    }
     // Check that order and invoice are paid
     WebPOSDatabaseHelper.verifyPaymentScheduleAndPaymentScheduleDetail(cOrderId, cInvoiceId,
         new OBNumber(new BigDecimal("20.00")), bpartnerId);
@@ -122,7 +141,7 @@
 
   /**
    * This method will create a non completed invoice for a certain NOT paid layaway
-   * 
+   *
    * @param cOrderId
    * @param Client
    * @param Organization
@@ -468,7 +487,7 @@
   }
 
   private String getNextInvoiceDocumentNo() {
-    final String nextDocNoQueryPostgresql = "select 'VBS'||(to_number(substring(documentno,4))+1) as nextDocNo from c_invoice where documentno ilike 'VBS%' order by created desc limit 1;";
+    final String nextDocNoQueryPostgresql = "select 'VBS'||(to_number(substring(documentno,4))+1) as nextDocNo from c_invoice where documentno ilike 'VBS%' order by created desc limit 1";
     final String nextDocNoQueryOracle = "select CONCAT('VBS',MAX(to_number(substr(documentno,4))+1)) as nextDocNo from c_invoice where documentno like 'VBS%' order by created desc";
     String query = "";
     if (ConnectionHelper.isOracle()) {
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I31600_VerfiyPaidOnCredit.java	Mon Dec 11 17:20:42 2017 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I31600_VerfiyPaidOnCredit.java	Tue Jan 23 16:49:27 2018 +0530
@@ -25,34 +25,30 @@
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-import java.math.BigDecimal;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
 import org.junit.Test;
 import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
-import org.openbravo.test.mobile.core.utils.OBNumber;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
-import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
 import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
 import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
 import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
 
 /**
- * 
+ *
  * Verifying that the existing receipt is paid by credit or not
- * 
+ *
  */
 public class I31600_VerfiyPaidOnCredit extends WebPOSTerminalHelper {
 
-  final OBNumber newCustomerCreditLimit = new OBNumber(2000);
-  OBNumber lastCustomerCreditLimit = OBNumber.ZERO;
+  final String strCarlStudson = "Carl Studson";
 
   final String vbsPOSTerminalType = "BD39916225594B32A88983899CF05F72";
 
   @Test
   public void test() {
     // Check PAID (On Credit) with Receipt
+    // Change Customer
+    changeCustomer();
+
     // Add Product
     tap(TestIdPack.BUTTON_BROWSE);
     tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
@@ -94,6 +90,9 @@
     tap(TestIdPack.BUTTON_DELETERECEIPT);
 
     // Check PAID (On Credit) with Return Receipt
+    // Change Customer
+    changeCustomer();
+
     tap(TestIdPack.BUTTON_MENU);
     tap(TestIdPack.BUTTON_MENU_RETURNTHISRECEIPT);
     // Add Product
@@ -137,51 +136,22 @@
     verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
   }
 
+  private void changeCustomer() {
+    // Change Customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_MODAL, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_MODAL_SEARCH);
+    verify(TestIdPack.LABEL_CUSTOMER_SEARCH_IDENTIFIER, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_SEARCH_ROW1);
+  }
+
   @Override
   public void beforeWithReload() {
-    createDatabaseChanges();
+    allowCredit(true);
   }
 
   @Override
   public void afterWithReload() {
-    restoreDatabaseChanges();
-  }
-
-  private void createDatabaseChanges() {
-    final String customerId = (String) SeleniumHelper
-        .executeScriptWithReturn("OB.POS.modelterminal.get('terminal').businessPartner");
-
-    // Check the Customer has Credit Line Limit
-    final String getCustomerSQL = String.format(
-        "select so_creditlimit from c_bpartner where c_bpartner_id = '%s'", customerId);
-    new DatabaseHelperSelect() {
-      @Override
-      protected void yieldResultSet(final ResultSet rs) throws SQLException {
-        lastCustomerCreditLimit = new OBNumber(rs.getString("so_creditlimit"));
-
-        if (rs.getBigDecimal("so_creditlimit").compareTo(new BigDecimal(0)) == 0) {
-          // Update Customer Credit Limit
-          final String updateSQL = String.format(
-              "update c_bpartner set so_creditlimit = %s where c_bpartner_id = '%s'",
-              newCustomerCreditLimit.toBigDecimal(), customerId);
-          new DatabaseHelperInsertUpdateOrDelete().execute(updateSQL, 1);
-        }
-      }
-    }.execute(getCustomerSQL, 1);
-
-    allowCredit(true);
-  }
-
-  private void restoreDatabaseChanges() {
-    final String customerId = (String) SeleniumHelper
-        .executeScriptWithReturn("OB.POS.modelterminal.get('terminal').businessPartner");
-
-    // Update Customer Credit Limit
-    final String updateCreditSQL = String.format(
-        "update c_bpartner set so_creditlimit = %s where c_bpartner_id = '%s'",
-        lastCustomerCreditLimit.toBigDecimal(), customerId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(updateCreditSQL, 1);
-
     allowCredit(false);
   }
 
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I35571_VerifyReceiptWithMutiPaymentTerm.java	Mon Dec 11 17:20:42 2017 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I35571_VerifyReceiptWithMutiPaymentTerm.java	Tue Jan 23 16:49:27 2018 +0530
@@ -48,58 +48,29 @@
   private final String strCarlStudsonID = "D5BF95FA079B4248B2CA2E2DA477D1B8";
   private final String strCarlStudson = "Carl Studson";
   final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+  String currentDate, currentDatePlus60;
 
   @Test
-  public void testWithDefaultPaymentTerm() {
-    updatePaymentTerm(false);
-    reload();
-    addProduct();
-
-    final String receiptNo = BackboneHelper.getDocumentNo();
-    isVisible(TestIdPack.BUTTON_PAY_USECREDIT, true);
-    tap(TestIdPack.BUTTON_PAY_USECREDIT);
-    isVisible(TestIdPack.LABEL_PAY_USECREDIT_POPUP, true);
-    verify(TestIdPack.LABEL_PAY_USECREDIT_POPUP,
-        (String) SeleniumHelper
-            .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_enoughCreditHeader')"));
-    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
-
-    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
-
+  public void test() {
     final Calendar calendar = Calendar.getInstance();
     calendar.setTime(new Date());
-    // Add 30days to date
-    calendar.add(Calendar.DATE, 30);
-    final String currentDatePlus30 = dateFormat.format(calendar.getTime());
+    currentDate = dateFormat.format(calendar.getTime());
+    // Add 60days to date
+    calendar.add(Calendar.DATE, 60);
+    currentDatePlus60 = dateFormat.format(calendar.getTime());
 
-    final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt, p.duedate "
-        + "from fin_payment_schedule p join c_invoice i on i.c_invoice_id = p.c_invoice_id "
-        + "join c_order o on o.c_order_id = i.c_order_id "
-        + "where o.documentno = '%s' order by p.amount, p.duedate", receiptNo);
-    new DatabaseHelperSelect() {
-      int count = 0;
+    testWithoutPayment(false);
+    testWithoutPayment(true);
 
-      @Override
-      protected void yieldResultSet(final ResultSet rs) throws SQLException {
-        count++;
-        final float amount = rs.getFloat("amount"), paidamt = rs.getFloat("paidamt"), outstandingamt = rs
-            .getFloat("outstandingamt");
-        final String dueDate = dateFormat.format(rs.getDate("duedate"));
-        switch (count) {
-        case 1:
-          assertThat(amount, equalTo((float) 40.00));
-          assertThat(paidamt, equalTo((float) 0.00));
-          assertThat(outstandingamt, equalTo((float) 40.00));
-          assertThat(dueDate, equalTo(currentDatePlus30));
-          break;
-        }
-      }
-    }.execute(sql, 1);
+    testWithPaymentBelowHalfTotal(false);
+    testWithPaymentBelowHalfTotal(true);
+
+    testWithPaymentAboveHalfTotal(false);
+    testWithPaymentAboveHalfTotal(true);
   }
 
-  @Test
-  public void testWithoutPayment() {
-    addProduct();
+  public void testWithoutPayment(final boolean isReturn) {
+    addProduct(isReturn);
     isVisible(TestIdPack.BUTTON_PAY_EXACT, true);
 
     final String receiptNo = BackboneHelper.getDocumentNo();
@@ -113,13 +84,6 @@
 
     verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
 
-    final Calendar calendar = Calendar.getInstance();
-    calendar.setTime(new Date());
-    final String currentDate = dateFormat.format(calendar.getTime());
-    // Add 60days to date
-    calendar.add(Calendar.DATE, 60);
-    final String currentDatePlus60 = dateFormat.format(calendar.getTime());
-
     // Verify Payment Schedule
     final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt, p.duedate "
         + "from fin_payment_schedule p join c_invoice i on i.c_invoice_id = p.c_invoice_id "
@@ -136,31 +100,24 @@
         final String dueDate = dateFormat.format(rs.getDate("duedate"));
         switch (count) {
         case 1:
-          assertThat(amount, equalTo((float) 0.00));
-          assertThat(paidamt, equalTo((float) 0.00));
-          assertThat(outstandingamt, equalTo((float) 0.00));
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(dueDate, equalTo(currentDate));
           break;
         case 2:
-          assertThat(amount, equalTo((float) 20.00));
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(paidamt, equalTo((float) 0));
-          assertThat(outstandingamt, equalTo((float) 20.00));
-          assertThat(dueDate, equalTo(currentDate));
-          break;
-        case 3:
-          assertThat(amount, equalTo((float) 20.00));
-          assertThat(paidamt, equalTo((float) 0));
-          assertThat(outstandingamt, equalTo((float) 20.00));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(dueDate, equalTo(currentDatePlus60));
           break;
         }
       }
-    }.execute(sql, 3);
+    }.execute(sql, 2);
   }
 
-  @Test
-  public void testWithPaymentBelowHalfTotal() {
-    addProduct();
+  public void testWithPaymentBelowHalfTotal(final boolean isReturn) {
+    addProduct(isReturn);
 
     tap(TestIdPack.BUTTON_CARD);
     tap(TestIdPack.BUTTON_KEYPAD_1);
@@ -177,16 +134,8 @@
         (String) SeleniumHelper
             .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_enoughCreditHeader')"));
     tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
-
     verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
 
-    final Calendar calendar = Calendar.getInstance();
-    calendar.setTime(new Date());
-    final String currentDate = dateFormat.format(calendar.getTime());
-    // Add 60days to date
-    calendar.add(Calendar.DATE, 60);
-    final String currentDatePlus60 = dateFormat.format(calendar.getTime());
-
     // Verify Payment Schedule
     final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt, p.duedate, "
         + "(SELECT count(distinct pd.fin_payment_id) FROM fin_payment_detail pd, "
@@ -209,31 +158,24 @@
         final String dueDate = dateFormat.format(rs.getDate("duedate"));
         switch (count) {
         case 1:
-          assertThat(amount, equalTo((float) 12.00));
-          assertThat(paidamt, equalTo((float) 12.00));
-          assertThat(outstandingamt, equalTo((float) 0.00));
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
+          assertThat(paidamt, equalTo(isReturn ? (float) -12.00 : (float) 12.00));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -8.00 : (float) 8.00));
           assertThat(dueDate, equalTo(currentDate));
           break;
         case 2:
-          assertThat(amount, equalTo((float) 8.00));
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(paidamt, equalTo((float) 0));
-          assertThat(outstandingamt, equalTo((float) 8.00));
-          assertThat(dueDate, equalTo(currentDate));
-          break;
-        case 3:
-          assertThat(amount, equalTo((float) 20.00));
-          assertThat(paidamt, equalTo((float) 0));
-          assertThat(outstandingamt, equalTo((float) 20.00));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(dueDate, equalTo(currentDatePlus60));
           break;
         }
       }
-    }.execute(sql, 3);
+    }.execute(sql, 2);
   }
 
-  @Test
-  public void testWithPaymentAboveHalfTotal() {
-    addProduct();
+  public void testWithPaymentAboveHalfTotal(final boolean isReturn) {
+    addProduct(isReturn);
 
     tap(TestIdPack.BUTTON_CARD);
     tap(TestIdPack.BUTTON_KEYPAD_2);
@@ -250,16 +192,8 @@
         (String) SeleniumHelper
             .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_enoughCreditHeader')"));
     tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
-
     verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
 
-    final Calendar calendar = Calendar.getInstance();
-    calendar.setTime(new Date());
-    final String currentDate = dateFormat.format(calendar.getTime());
-    // Add 60days to date
-    calendar.add(Calendar.DATE, 60);
-    final String currentDatePlus60 = dateFormat.format(calendar.getTime());
-
     // Verify Payment Schedule
     final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt, p.duedate, "
         + "(SELECT count(distinct pd.fin_payment_id) FROM fin_payment_detail pd, "
@@ -282,15 +216,15 @@
         final String dueDate = dateFormat.format(rs.getDate("duedate"));
         switch (count) {
         case 1:
-          assertThat(amount, equalTo((float) 24.00));
-          assertThat(paidamt, equalTo((float) 24.00));
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
+          assertThat(paidamt, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
           assertThat(outstandingamt, equalTo((float) 0.00));
           assertThat(dueDate, equalTo(currentDate));
           break;
-        case 3:
-          assertThat(amount, equalTo((float) 16.00));
-          assertThat(paidamt, equalTo((float) 0));
-          assertThat(outstandingamt, equalTo((float) 16.00));
+        case 2:
+          assertThat(amount, equalTo(isReturn ? (float) -20.00 : (float) 20.00));
+          assertThat(paidamt, equalTo(isReturn ? (float) -4.00 : (float) 4.00));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -16.00 : (float) 16.00));
           assertThat(dueDate, equalTo(currentDatePlus60));
           break;
         }
@@ -298,7 +232,7 @@
     }.execute(sql, 2);
   }
 
-  private void addProduct() {
+  private void addProduct(final boolean isReturn) {
     // Change Customer
     tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
     write(TestIdPack.FIELD_CUSTOMER_MODAL, strCarlStudson);
@@ -316,6 +250,12 @@
     tap(TestIdPack.BUTTON_KEYPAD_0);
     tap(TestIdPack.BUTTON_KEYPAD_PRICE);
     verify(TestIdPack.LABEL_TOTALTOPAY, "40.00");
+
+    if (isReturn) {
+      tap(TestIdPack.BUTTON_MENU);
+      tap(TestIdPack.BUTTON_MENU_RETURNTHISRECEIPT);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-40.00");
+    }
     tap(TestIdPack.BUTTON_PAY);
   }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36841_VerifyInvoiceDueDateByNewTerms.java	Tue Jan 23 16:49:27 2018 +0530
@@ -0,0 +1,111 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.system;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Calendar;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+public class I36841_VerifyInvoiceDueDateByNewTerms extends WebPOSTerminalHelper {
+
+  private final String paymentTermTreintaDias = "D8955F8808A54C63BBF478A6843D834D";
+  private final String customer = "Carl Studson";
+
+  @Test
+  public void test() {
+    // Create Receipt
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_MODAL, customer);
+    tap(TestIdPack.BUTTON_CUSTOMER_MODAL_SEARCH);
+    verify(TestIdPack.LABEL_CUSTOMER_SEARCH_IDENTIFIER, customer);
+    tap(TestIdPack.BUTTON_CUSTOMER_SEARCH_ROW1);
+
+    tap(TestIdPack.BUTTON_MENU);
+    tap(TestIdPack.BUTTON_MENU_INVOICETHISRECEIPT);
+    tap(TestIdPack.BUTTON_BROWSE);
+    tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestIdPack.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "150.50");
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    // Verify Invoice Payment plan Due date
+    final String sql = String.format("select ci.dateinvoiced, fps.duedate from c_invoice ci "
+        + "join c_order co on co.c_order_id = ci.c_order_id "
+        + "join fin_payment_schedule fps on fps.c_invoice_id = ci.c_invoice_id "
+        + "where co.documentno = '%s'", receiptNo);
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        final Calendar dateInvoice = Calendar.getInstance();
+        dateInvoice.setTime(rs.getDate("dateinvoiced"));
+        final Calendar dueDate = Calendar.getInstance();
+        dueDate.setTime(rs.getDate("duedate"));
+        final int maturityDate = 15;
+
+        final boolean result = dateInvoice.get(Calendar.DAY_OF_MONTH) <= 15 ? maturityDate == dueDate
+            .get(Calendar.DAY_OF_MONTH) : true;
+
+        assertThat("Due date is not set based on payment terms", result);
+      }
+    }.execute(sql, 1);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    updateUseCredit(true);
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_paymentterm set netdays = 0, isduefixed = 'Y', "
+            + "fixmonthday = 15, fixmonthday2 = null, fixmonthday3 = null "
+            + " where c_paymentterm_id = '%s'", paymentTermTreintaDias), 1);
+  }
+
+  @Override
+  public void afterWithReload() {
+    updateUseCredit(false);
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_paymentterm set netdays = 30, isduefixed = 'N', "
+            + "fixmonthday = null, fixmonthday2 = null, fixmonthday3 = null "
+            + "where c_paymentterm_id = '%s'", paymentTermTreintaDias), 1);
+  }
+
+  private void updateUseCredit(final boolean isForTest) {
+    final String terminalTypeId = BackboneHelper.getTerminalValue("terminalType.id");
+    final String sql = String.format(
+        "update obpos_terminaltype Set allowpayoncredit = '%s' where obpos_terminaltype_id = '%s'",
+        isForTest ? "Y" : "N", terminalTypeId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36907_VerifyReceiptWithPaymentTermLine.java	Tue Jan 23 16:49:27 2018 +0530
@@ -0,0 +1,146 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2017 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+package org.openbravo.test.mobile.retail.pack.selenium.tests.system;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+/**
+ *
+ * Verify Invoice Payment schedule based on Payment Term lines
+ *
+ */
+public class I36907_VerifyReceiptWithPaymentTermLine extends WebPOSTerminalHelper {
+
+  private final String strCarlStudson = "Carl Studson";
+  final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+  String currentDatePlus30;
+
+  @Test
+  public void test() {
+    final Calendar calendar = Calendar.getInstance();
+    calendar.setTime(new Date());
+    // Add 30days to date
+    calendar.add(Calendar.DATE, 30);
+    currentDatePlus30 = dateFormat.format(calendar.getTime());
+
+    testWithDefaultPaymentTerm(false);
+    testWithDefaultPaymentTerm(true);
+  }
+
+  public void testWithDefaultPaymentTerm(final boolean isReturn) {
+    addProduct(isReturn);
+
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    isVisible(TestIdPack.BUTTON_PAY_USECREDIT, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT);
+    isVisible(TestIdPack.LABEL_PAY_USECREDIT_POPUP, true);
+    verify(TestIdPack.LABEL_PAY_USECREDIT_POPUP,
+        (String) SeleniumHelper
+            .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_enoughCreditHeader')"));
+    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt, p.duedate "
+        + "from fin_payment_schedule p join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+        + "join c_order o on o.c_order_id = i.c_order_id "
+        + "where o.documentno = '%s' order by p.amount, p.duedate", receiptNo);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount"), paidamt = rs.getFloat("paidamt"), outstandingamt = rs
+            .getFloat("outstandingamt");
+        final String dueDate = dateFormat.format(rs.getDate("duedate"));
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo(isReturn ? (float) -40.00 : (float) 40.00));
+          assertThat(paidamt, equalTo((float) 0.00));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -40.00 : (float) 40.00));
+          assertThat(dueDate, equalTo(currentDatePlus30));
+          break;
+        }
+      }
+    }.execute(sql, 1);
+  }
+
+  private void addProduct(final boolean isReturn) {
+    // Change Customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_MODAL, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_MODAL_SEARCH);
+    verify(TestIdPack.LABEL_CUSTOMER_SEARCH_IDENTIFIER, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_SEARCH_ROW1);
+
+    // Add Product
+    tap(TestIdPack.BUTTON_BROWSE);
+    tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestIdPack.BUTTON_PRODUCT_MOUNTAINEERING_DESCENDERCLASSIC);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "7.80");
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_KEYPAD_4);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "40.00");
+    if (isReturn) {
+      tap(TestIdPack.BUTTON_MENU);
+      tap(TestIdPack.BUTTON_MENU_RETURNTHISRECEIPT);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-40.00");
+    }
+    tap(TestIdPack.BUTTON_PAY);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    updateUseCredit(true);
+  }
+
+  @Override
+  public void afterWithReload() {
+    updateUseCredit(false);
+  }
+
+  private void updateUseCredit(final boolean isForTest) {
+    // Enable "Use Credit" for terminal type
+    final String terminalTypeId = BackboneHelper.getTerminalValue("terminalType.id");
+    final String sql = String.format(
+        "update obpos_terminaltype Set allowpayoncredit = '%s' where obpos_terminaltype_id = '%s'",
+        isForTest ? "Y" : "N", terminalTypeId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I36907_VerifyReceiptWithPaymentTermLineII.java	Tue Jan 23 16:49:27 2018 +0530
@@ -0,0 +1,245 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2017 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+package org.openbravo.test.mobile.retail.pack.selenium.tests.system;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.database.WebPOSDatabaseConstants;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+/**
+ *
+ * Verify Invoice Payment schedule based on Payment Term lines
+ *
+ */
+public class I36907_VerifyReceiptWithPaymentTermLineII extends WebPOSTerminalHelper {
+
+  final String strCarlStudson = "Carl Studson";
+  final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+  final String paymentTermTreintaDias = "D8955F8808A54C63BBF478A6843D834D";
+  String currentDatePlus30, currentDatePlus60, currentDatePlus90;
+
+  @Test
+  public void test() {
+
+    final Calendar calendar = Calendar.getInstance();
+    calendar.setTime(new Date());
+    // Add 30days to date
+    calendar.add(Calendar.DATE, 30);
+    currentDatePlus30 = dateFormat.format(calendar.getTime());
+    // Add 60days to date
+    calendar.add(Calendar.DATE, 30);
+    currentDatePlus60 = dateFormat.format(calendar.getTime());
+    // Add 90days to date
+    calendar.add(Calendar.DATE, 30);
+    currentDatePlus90 = dateFormat.format(calendar.getTime());
+
+    testWithCustomPaymentTerm(false);
+    testWithCustomPaymentTerm(true);
+  }
+
+  public void testWithCustomPaymentTerm(final boolean isReturn) {
+    // Change Customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_MODAL, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_MODAL_SEARCH);
+    verify(TestIdPack.LABEL_CUSTOMER_SEARCH_IDENTIFIER, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_SEARCH_ROW1);
+
+    // Add Product
+    tap(TestIdPack.BUTTON_BROWSE);
+    tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestIdPack.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "150.50");
+    if (isReturn) {
+      tap(TestIdPack.BUTTON_MENU);
+      tap(TestIdPack.BUTTON_MENU_RETURNTHISRECEIPT);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-150.50");
+    }
+    tap(TestIdPack.BUTTON_PAY);
+    final String receiptNo = BackboneHelper.getDocumentNo();
+
+    tap(TestIdPack.BUTTON_CARD);
+    tap(TestIdPack.BUTTON_KEYPAD_3);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_ENTER);
+
+    tap(TestIdPack.BUTTON_CASH);
+    tap(TestIdPack.BUTTON_PAYMENTSWITCH);
+    tap(TestIdPack.BUTTON_KEYPAD_3);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_ENTER);
+
+    tap(TestIdPack.BUTTON_VOUCHER);
+    tap(TestIdPack.BUTTON_KEYPAD_3);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_ENTER);
+
+    verify(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, "60.50€");
+
+    isVisible(TestIdPack.BUTTON_PAY_USECREDIT, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT);
+    isVisible(TestIdPack.LABEL_PAY_USECREDIT_POPUP, true);
+    verify(TestIdPack.LABEL_PAY_USECREDIT_POPUP,
+        (String) SeleniumHelper
+            .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_enoughCreditHeader')"));
+    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    final String sqlPaymentSchedule = String.format(
+        "select p.fin_payment_schedule_id, p.amount, p.paidamt, "
+            + "p.outstandingamt, p.duedate from fin_payment_schedule p "
+            + "join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+            + "join c_order o on o.c_order_id = i.c_order_id "
+            + "where o.documentno = '%s' order by p.duedate", receiptNo);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount"), paidamt = rs.getFloat("paidamt"), outstandingamt = rs
+            .getFloat("outstandingamt");
+        final String dueDate = dateFormat.format(rs.getDate("duedate"));
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo(isReturn ? (float) -50.16 : (float) 50.16));
+          assertThat(paidamt, equalTo(isReturn ? (float) -50.16 : (float) 50.16));
+          assertThat(outstandingamt, equalTo((float) 0.00));
+          assertThat(dueDate, equalTo(currentDatePlus30));
+          break;
+        case 2:
+          assertThat(amount, equalTo(isReturn ? (float) -50.16 : (float) 50.16));
+          assertThat(paidamt, equalTo(isReturn ? (float) -39.84 : (float) 39.84));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -10.32 : (float) 10.32));
+          assertThat(dueDate, equalTo(currentDatePlus60));
+          break;
+        case 3:
+          assertThat(amount, equalTo(isReturn ? (float) -50.18 : (float) 50.18));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo(isReturn ? (float) -50.18 : (float) 50.18));
+          assertThat(dueDate, equalTo(currentDatePlus90));
+          break;
+        }
+      }
+    }.execute(sqlPaymentSchedule, 3);
+
+    final String sqlPaymentScheduleDetail = String.format(
+        "select psd.amount, p.fin_paymentmethod_id from fin_payment_scheduledetail psd "
+            + "join fin_payment_detail pd on pd.fin_payment_detail_id = psd.fin_payment_detail_id "
+            + "join fin_payment p on p.fin_payment_id = pd.fin_payment_id "
+            + "join fin_payment_schedule ps "
+            + "on psd.fin_payment_schedule_invoice = ps.fin_payment_schedule_id "
+            + "join c_invoice i on i.c_invoice_id = ps.c_invoice_id "
+            + "join c_order o on o.c_order_id = i.c_order_id "
+            + "where o.documentno = '%s' order by p.documentno, abs(psd.amount) desc", receiptNo);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount");
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo(isReturn ? (float) -30.00 : (float) 30.00));
+          assertThat(WebPOSDatabaseConstants.PAYMENT_METHOD_WIRETRANSFER,
+              equalTo(rs.getString("fin_paymentmethod_id")));
+          break;
+        case 2:
+          assertThat(amount, equalTo(isReturn ? (float) -20.16 : (float) 20.16));
+          assertThat(WebPOSDatabaseConstants.PAYMENT_METHOD_CASH,
+              equalTo(rs.getString("fin_paymentmethod_id")));
+          break;
+        case 3:
+          assertThat(amount, equalTo(isReturn ? (float) -9.84 : (float) 9.84));
+          assertThat(WebPOSDatabaseConstants.PAYMENT_METHOD_CASH,
+              equalTo(rs.getString("fin_paymentmethod_id")));
+          break;
+        case 4:
+          assertThat(amount, equalTo(isReturn ? (float) -30.00 : (float) 30.00));
+          assertThat(WebPOSDatabaseConstants.PAYMENT_METHOD_CHEQUE,
+              equalTo(rs.getString("fin_paymentmethod_id")));
+          break;
+        }
+      }
+    }.execute(sqlPaymentScheduleDetail, 4);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    updateUseCredit(true);
+    createPaymentTermLine(true);
+  }
+
+  @Override
+  public void afterWithReload() {
+    updateUseCredit(false);
+    createPaymentTermLine(false);
+  }
+
+  private void updateUseCredit(final boolean isForTest) {
+    // Enable "Use Credit" for terminal type
+    final String terminalTypeId = BackboneHelper.getTerminalValue("terminalType.id");
+    final String sql = String.format(
+        "update obpos_terminaltype set allowpayoncredit = '%s' where obpos_terminaltype_id = '%s'",
+        isForTest ? "Y" : "N", terminalTypeId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+
+  private void createPaymentTermLine(final boolean isForTest) {
+    // Update Overdue payment days
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_paymentterm set netdays = '%s' where c_paymentterm_id = '%s'", (isForTest ? "90"
+            : "30"), paymentTermTreintaDias), 1);
+
+    // Update Lines
+    if (isForTest) {
+      final String clientId = BackboneHelper.getTerminalValue("client");
+      final String sqlInsertPaymentTermLine = "INSERT INTO c_paymenttermline(c_paymenttermline_id, ad_client_id, ad_org_id, createdby, updatedby, c_paymentterm_id, line, percentage, "
+          + "onremainder, excludetax, isduefixed, netdays, isnextbusinessday) "
+          + "VALUES (get_uuid(), '%s', '0', '100', '100', '%s', '%s', '%s', 'N', 'N', 'N', '%s', 'N')";
+      new DatabaseHelperInsertUpdateOrDelete().execute(String.format(sqlInsertPaymentTermLine,
+          clientId, paymentTermTreintaDias, "10", "33.33", "30"), 1);
+      new DatabaseHelperInsertUpdateOrDelete().execute(String.format(sqlInsertPaymentTermLine,
+          clientId, paymentTermTreintaDias, "20", "33.33", "60"), 1);
+    } else {
+      // Delete New Payment term lines
+      new DatabaseHelperInsertUpdateOrDelete()
+          .execute(String.format("delete from c_paymenttermline where c_paymentterm_id = '%s'",
+              paymentTermTreintaDias), 2);
+    }
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I37343_VerifyPymtScheDetailWithCredit.java	Tue Jan 23 16:49:27 2018 +0530
@@ -0,0 +1,258 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2017 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+package org.openbravo.test.mobile.retail.pack.selenium.tests.system;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+public class I37343_VerifyPymtScheDetailWithCredit extends WebPOSTerminalHelper {
+
+  private final String strCarlStudsonID = "D5BF95FA079B4248B2CA2E2DA477D1B8";
+  private final String strCarlStudson = "Carl Studson";
+  private final String strPayMethod30 = "D8955F8808A54C63BBF478A6843D834D";
+  private final String strPayMethod204040 = "6D3B4000BE1E4E7EACFA36D97F6E35D5";
+
+  @Test
+  public void testWithoutPayment() {
+
+    // Verify without payment
+    addProduct();
+
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    isVisible(TestIdPack.BUTTON_PAY_USECREDIT, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT);
+    isVisible(TestIdPack.LABEL_PAY_USECREDIT_POPUP, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    // Verify Payment Schedule
+    final String sql = String.format("select p.amount, p.paidamt, p.outstandingamt "
+        + "from fin_payment_schedule p join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+        + "join c_order o on o.c_order_id = i.c_order_id "
+        + "where o.documentno = '%s' order by p.amount, p.duedate", receiptNo);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount"), paidamt = rs.getFloat("paidamt"), outstandingamt = rs
+            .getFloat("outstandingamt");
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo((float) 30.00));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo((float) 30.00));
+          break;
+        case 2:
+          assertThat(amount, equalTo((float) 60.00));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo((float) 60.00));
+          break;
+        case 3:
+          assertThat(amount, equalTo((float) 60.00));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo((float) 60.00));
+          break;
+        }
+      }
+    }.execute(sql, 3);
+
+    // Verify Payment Schedule Detail
+    final String sql2 = String.format("select pd.fin_payment_detail_id, pd.amount "
+        + "from fin_payment_scheduledetail pd join fin_payment_schedule p "
+        + "on p.fin_payment_schedule_id = pd.fin_payment_schedule_invoice "
+        + "join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+        + "join c_order o on o.c_order_id = i.c_order_id "
+        + "where o.documentno = '%s' order by p.amount, p.duedate", receiptNo);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount");
+        assertThat(rs.getString("fin_payment_detail_id"), equalTo(null));
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo((float) 30.00));
+          break;
+        case 2:
+          assertThat(amount, equalTo((float) 60.00));
+          break;
+        case 3:
+          assertThat(amount, equalTo((float) 60.00));
+          break;
+        }
+      }
+    }.execute(sql2, 3);
+  }
+
+  @Test
+  public void testWithPayment() {
+    addProduct();
+
+    // add payment
+    tap(TestIdPack.BUTTON_PAYMENTSWITCH);
+    tap(TestIdExtModules.BUTTON_KEYPAD_5);
+    tap(TestIdExtModules.BUTTON_KEYPAD_0);
+    tap(TestIdExtModules.BUTTON_KEYPAD_ENTER);
+
+    final String receiptNo2 = BackboneHelper.getDocumentNo();
+    isVisible(TestIdPack.BUTTON_PAY_USECREDIT, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT);
+    isVisible(TestIdPack.LABEL_PAY_USECREDIT_POPUP, true);
+    tap(TestIdPack.BUTTON_PAY_USECREDIT_OK);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    // Verify Payment Schedule
+    final String sql3 = String.format("select p.amount, p.paidamt, p.outstandingamt "
+        + "from fin_payment_schedule p join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+        + "join c_order o on o.c_order_id = i.c_order_id "
+        + "where o.documentno = '%s' order by p.amount, p.duedate", receiptNo2);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount"), paidamt = rs.getFloat("paidamt"), outstandingamt = rs
+            .getFloat("outstandingamt");
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo((float) 30.00));
+          assertThat(paidamt, equalTo((float) 30.00));
+          assertThat(outstandingamt, equalTo((float) 0.00));
+          break;
+        case 2:
+          assertThat(amount, equalTo((float) 60.00));
+          assertThat(paidamt, equalTo((float) 20.00));
+          assertThat(outstandingamt, equalTo((float) 40.00));
+          break;
+        case 3:
+          assertThat(amount, equalTo((float) 60.00));
+          assertThat(paidamt, equalTo((float) 0));
+          assertThat(outstandingamt, equalTo((float) 60.00));
+          break;
+        }
+      }
+    }.execute(sql3, 3);
+
+    // Verify Payment Schedule Detail
+    final String sql4 = String.format("select pd.fin_payment_detail_id, pd.amount "
+        + "from fin_payment_scheduledetail pd join fin_payment_schedule p "
+        + "on p.fin_payment_schedule_id = pd.fin_payment_schedule_invoice "
+        + "join c_invoice i on i.c_invoice_id = p.c_invoice_id "
+        + "join c_order o on o.c_order_id = i.c_order_id "
+        + "where o.documentno = '%s' order by p.amount, p.duedate, pd.fin_payment_detail_id",
+        receiptNo2);
+    new DatabaseHelperSelect() {
+      int count = 0;
+
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        count++;
+        final float amount = rs.getFloat("amount");
+        switch (count) {
+        case 1:
+          assertThat(amount, equalTo((float) 30.00));
+          assertThat(rs.getString("fin_payment_detail_id").length(), equalTo(32));
+          break;
+        case 2:
+          assertThat(amount, equalTo((float) 20.00));
+          assertThat(rs.getString("fin_payment_detail_id").length(), equalTo(32));
+          break;
+        case 3:
+          assertThat(amount, equalTo((float) 40.00));
+          assertThat(rs.getString("fin_payment_detail_id"), equalTo(null));
+          break;
+        case 4:
+          assertThat(amount, equalTo((float) 60.00));
+          assertThat(rs.getString("fin_payment_detail_id"), equalTo(null));
+          break;
+        }
+      }
+    }.execute(sql4, 4);
+  }
+
+  private void addProduct() {
+    // Change Customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_MODAL, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_MODAL_SEARCH);
+    verify(TestIdPack.LABEL_CUSTOMER_SEARCH_IDENTIFIER, strCarlStudson);
+    tap(TestIdPack.BUTTON_CUSTOMER_SEARCH_ROW1);
+
+    // Add Product
+    tap(TestIdPack.BUTTON_BROWSE);
+    tap(TestIdPack.BUTTON_CATEGORY_MOUNTAINEERING);
+    tap(TestIdPack.BUTTON_PRODUCT_MOUNTAINEERING_AVALANCHETRANSCEIVER);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "150.50");
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_KEYPAD_1);
+    tap(TestIdPack.BUTTON_KEYPAD_5);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "150.00");
+    tap(TestIdPack.BUTTON_PAY);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    updatePaymentTerm(true);
+    updateUseCredit(true);
+  }
+
+  @Override
+  public void afterWithReload() {
+    updatePaymentTerm(false);
+    updateUseCredit(false);
+  }
+
+  private void updatePaymentTerm(final boolean isForTest) {
+    // Update Customer("Carl Studson") payment term from "" to ""
+    final String updateCreditAllowSQL = String.format(
+        "update c_bpartner set c_paymentterm_id = '%s' where c_bpartner_id = '%s'",
+        isForTest ? strPayMethod204040 : strPayMethod30, strCarlStudsonID);
+    new DatabaseHelperInsertUpdateOrDelete().execute(updateCreditAllowSQL, 1);
+  }
+
+  private void updateUseCredit(final boolean isForTest) {
+    // Enable "Use Credit" for terminal type
+    final String terminalTypeId = BackboneHelper.getTerminalValue("terminalType.id");
+    final String sql = String.format(
+        "update obpos_terminaltype Set allowpayoncredit = '%s' where obpos_terminaltype_id = '%s'",
+        isForTest ? "Y" : "N", terminalTypeId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+}
\ No newline at end of file