Attached Files | issue 41464 source giftcards.patch [^] (6,914 bytes) 2019-07-29 15:17 [Show Content] [Hide Content]# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1564399354 -19800
# Mon Jul 29 16:52:34 2019 +0530
# Node ID b0179943718188af84d233514ef937cea8a3a270
# Parent 99c1b8b2fc672300106d2dfc0560c811b7df8303
Related to issue 41464 : Credit Note and Customer Payment should be created when reimbursing credit note
diff -r 99c1b8b2fc67 -r b01799437181 src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java
--- a/src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java Mon Jul 29 15:37:07 2019 +0530
+++ b/src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java Mon Jul 29 16:52:34 2019 +0530
@@ -29,6 +29,7 @@
import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
import org.openbravo.model.financialmgmt.payment.FIN_Payment;
import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.retail.giftcards.GiftCardModel;
import org.openbravo.retail.giftcards.org.openbravo.retail.giftcards.GiftCardInst;
import org.openbravo.retail.giftcards.org.openbravo.retail.giftcards.GiftCardTrans;
import org.openbravo.retail.giftcards.process.GiftCardGLItemUtils;
@@ -118,11 +119,7 @@
OBPOSAppPayment obposAppPayment = OBDal.getInstance()
.get(OBPOSAppPayment.class, jsonsent.optString("paymentMethodId"));
- if (posterminal != null && obposAppPayment != null) {
- organization = posterminal.getOrganization();
- account = obposAppPayment.getFinancialAccount();
- finPaymentMethod = obposAppPayment.getPaymentMethod().getPaymentMethod();
- } else if (giftCardInst.getPayment() != null) {
+ if (giftCardInst.getPayment() != null) {
organization = giftCardInst.getPayment().getOrganization();
account = giftCardInst.getPayment().getAccount();
finPaymentMethod = giftCardInst.getPayment().getPaymentMethod();
@@ -130,7 +127,8 @@
// Make a payment
payment = GiftCardGLItemUtils.makePayment(giftCardInst, posterminal, cashup,
- organization, account, finPaymentMethod, amount, paymentcashupEvent);
+ organization, account, finPaymentMethod, obposAppPayment, amount,
+ paymentcashupEvent, GiftCardModel.GIFTCARD_REIMBURSED);
trans.setPayment(payment);
OBDal.getInstance().save(trans);
} else {
diff -r 99c1b8b2fc67 -r b01799437181 src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java
--- a/src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java Mon Jul 29 15:37:07 2019 +0530
+++ b/src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java Mon Jul 29 16:52:34 2019 +0530
@@ -34,6 +34,7 @@
import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
import org.openbravo.model.financialmgmt.payment.FIN_Payment;
import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
+import org.openbravo.retail.giftcards.GiftCardModel;
import org.openbravo.retail.giftcards.org.openbravo.retail.giftcards.GiftCardInst;
import org.openbravo.retail.giftcards.org.openbravo.retail.giftcards.GiftCardTrans;
import org.openbravo.retail.posterminal.OBPOSAppCashup;
@@ -122,11 +123,7 @@
FIN_FinancialAccount account = null;
FIN_PaymentMethod finPaymentMethod = null;
Organization organization = null;
- if (posterminal != null && obposAppPayment != null) {
- organization = posterminal.getOrganization();
- account = obposAppPayment.getFinancialAccount();
- finPaymentMethod = obposAppPayment.getPaymentMethod().getPaymentMethod();
- } else if (giftCardInst.getPayment() != null) {
+ if (giftCardInst.getPayment() != null) {
if (cashup != null && posterminal != null) {
organization = cashup.getOrganization();
account = getTerminalPaymentMethodForCN(posterminal).getFinancialAccount();
@@ -148,7 +145,7 @@
// Make a payment
FIN_Payment payment = makePayment(giftCardInst, posterminal, cashup, organization, account,
- finPaymentMethod, amount, paymentcashupEvent);
+ finPaymentMethod, obposAppPayment, amount, paymentcashupEvent, certificateStatus);
long init4 = System.currentTimeMillis();
boolean transCancelled = cancelled;
@@ -218,6 +215,15 @@
OBPOSApplications obposApplications, OBPOSAppCashup cashup, Organization organization,
FIN_FinancialAccount account, FIN_PaymentMethod paymentMethod, BigDecimal amount,
OBPOSPaymentcashupEvents paymentcashupEvent) throws Exception {
+ return makePayment(giftCardInst, obposApplications, cashup, organization, account,
+ paymentMethod, null, amount, paymentcashupEvent, null);
+ }
+
+ public static FIN_Payment makePayment(GiftCardInst giftCardInst,
+ OBPOSApplications obposApplications, OBPOSAppCashup cashup, Organization organization,
+ FIN_FinancialAccount account, FIN_PaymentMethod paymentMethod,
+ OBPOSAppPayment obposAppPayment, BigDecimal amount,
+ OBPOSPaymentcashupEvents paymentcashupEvent, String certificateStatus) throws Exception {
long init = System.currentTimeMillis();
FIN_Payment payment = null;
if (account != null && paymentMethod != null) {
@@ -287,6 +293,34 @@
updatePayment(payment, giftCardInst, cashup, paymentcashupEvent);
+ if (GiftCardModel.GIFTCARD_REIMBURSED.equals(certificateStatus) && obposApplications != null
+ && obposAppPayment != null) {
+ BigDecimal refundAmount = amount.negate();
+ FIN_Payment refundPayment = new AdvPaymentMngtDao().getNewPayment(true,
+ obposApplications.getOrganization(),
+ FIN_Utility.getDocumentType(organization, AcctServer.DOCTYPE_ARReceipt), null,
+ giftCardInst.getPayment().getBusinessPartner(),
+ obposAppPayment.getPaymentMethod().getPaymentMethod(),
+ obposAppPayment.getFinancialAccount(), refundAmount.toString(), new Date(), null,
+ account.getCurrency(), null, null);
+
+ FIN_AddPayment.saveGLItem(refundPayment, refundAmount, glitem,
+ giftCardInst.getPayment().getBusinessPartner(), null, null, null, null, null, null,
+ null, null);
+
+ if (cashup != null && refundPayment != null) {
+ refundPayment.setObposAppCashup(cashup);
+ refundPayment.setOBPOSPOSTerminal(cashup.getPOSTerminal());
+ OBDal.getInstance().save(refundPayment);
+ }
+
+ error = FIN_AddPayment.processPayment(RequestContext.get().getVariablesSecureApp(),
+ new DalConnectionProvider(true), "D", refundPayment);
+ if (!"Success".equals(error.getType())) {
+ throw new OBException(error.getMessage());
+ }
+ }
+
log4j.info("Time to process payment: " + (System.currentTimeMillis() - init3));
}
issue 41464 source giftcards 2.patch [^] (14,863 bytes) 2019-07-30 13:06 [Show Content] [Hide Content]# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1564484772 -19800
# Tue Jul 30 16:36:12 2019 +0530
# Node ID 474f954b1409697cb23e029c41f5cfa694bfca55
# Parent 753336ec49d91d3008d2ce82adcf20efc1583326
Related to issue 41464 : Reibursement Payment transaction should be linked with Cashup Events
diff -r 753336ec49d9 -r 474f954b1409 src/org/openbravo/retail/giftcards/GiftCardModel.java
--- a/src/org/openbravo/retail/giftcards/GiftCardModel.java Tue Jul 30 12:11:39 2019 +0530
+++ b/src/org/openbravo/retail/giftcards/GiftCardModel.java Tue Jul 30 16:36:12 2019 +0530
@@ -50,6 +50,7 @@
public final static String GIFTCARD_CANCELLED = "CA";
public final static String GIFTCARD_REIMBURSED = "R";
+ public final static String GIFTCARD_PARTIALLY_USED = "PU";
public GiftCardTrans cancelGiftCardTransaction(String transid) throws Exception {
@@ -152,7 +153,8 @@
giftcard.setGiftCardCertificateStatus(
giftcard.getCurrentamount().compareTo(BigDecimal.ZERO) == 0 ? "U"
- : giftcard.getCurrentamount().compareTo(giftcard.getAmount()) == 0 ? "C" : "PU");
+ : giftcard.getCurrentamount().compareTo(giftcard.getAmount()) == 0 ? "C"
+ : GIFTCARD_PARTIALLY_USED);
OBDal.getInstance().remove(trans);
OBDal.getInstance().save(giftcard);
@@ -322,11 +324,11 @@
giftcard.setCurrentamount(currentAmount);
giftcard.setAlertStatus(currentAmount.compareTo(BigDecimal.ZERO) == 0 ? "C" : "P");
if ("BasedOnGLItem".equals(giftcard.getType())) {
- giftcard
- .setGiftCardCertificateStatus(currentAmount.compareTo(BigDecimal.ZERO) == 0 ? "U" : "PU");
+ giftcard.setGiftCardCertificateStatus(
+ currentAmount.compareTo(BigDecimal.ZERO) == 0 ? "U" : GIFTCARD_PARTIALLY_USED);
} else if (giftcard.getType().equals("BasedOnCreditNote")) {
- giftcard
- .setGiftCardCertificateStatus(currentAmount.compareTo(BigDecimal.ZERO) == 0 ? "U" : "PU");
+ giftcard.setGiftCardCertificateStatus(
+ currentAmount.compareTo(BigDecimal.ZERO) == 0 ? "U" : GIFTCARD_PARTIALLY_USED);
}
// Make amount as negative if the receipt type is return
diff -r 753336ec49d9 -r 474f954b1409 src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java
--- a/src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java Tue Jul 30 12:11:39 2019 +0530
+++ b/src/org/openbravo/retail/giftcards/hooks/ProcessCashMgmtHookGiftCard.java Tue Jul 30 16:36:12 2019 +0530
@@ -1,6 +1,6 @@
/*
************************************************************************************
- * Copyright (C) 2015-2018 Openbravo S.L.U.
+ * Copyright (C) 2015-2019 Openbravo S.L.U.
* Licensed under the Openbravo Commercial License version 1.0
* You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
* or in the legal folder of this module distribution.
@@ -10,22 +10,12 @@
package org.openbravo.retail.giftcards.hooks;
import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import org.codehaus.jettison.json.JSONObject;
-import org.hibernate.criterion.Restrictions;
-import org.openbravo.advpaymentmngt.dao.TransactionsDao;
-import org.openbravo.base.exception.OBException;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.OBMessageUtils;
import org.openbravo.model.common.enterprise.Organization;
-import org.openbravo.model.financialmgmt.gl.GLItem;
-import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
import org.openbravo.model.financialmgmt.payment.FIN_Payment;
import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
@@ -51,98 +41,47 @@
GiftCardInst giftCardInst = OBDal.getInstance()
.get(GiftCardInst.class, jsonsent.getString("gcnvGiftCardId"));
if (giftCardInst != null) {
- // - Register cash out transaction (reimburse)
- // - Clears Gift Card remaining amount in financial account and closes gift card
- String description = jsonsent.getString("description");
- GLItem glitem = null;
- if ("BasedOnCreditNote".equals(giftCardInst.getType())) {
- OBCriteria<OBPOSAppPayment> appPaymentCri = OBDal.getInstance()
- .createCriteria(OBPOSAppPayment.class);
- appPaymentCri.add(Restrictions.eq(OBPOSAppPayment.PROPERTY_OBPOSAPPLICATIONS + ".id",
- jsonsent.getString("posTerminal")));
- appPaymentCri
- .add(Restrictions.eq(OBPOSAppPayment.PROPERTY_SEARCHKEY, "GCNV_payment.creditnote"));
- appPaymentCri.setMaxResults(1);
- List<OBPOSAppPayment> appPaymentList = appPaymentCri.list();
- if (appPaymentList.size() > 0) {
- OBPOSAppPayment appPayObj = appPaymentList.get(0);
- if (appPayObj.getPaymentMethod().getGcnvReimburseGlitem() == null) {
- OBPOSApplications terminal = OBDal.getInstance()
- .get(OBPOSApplications.class, jsonsent.getString("posTerminal"));
- throw new OBException(OBMessageUtils.getI18NMessage("GCNV_NoGLItemForReimburse",
- new String[] { OBMessageUtils.messageBD("GCNV_LblCreditNote"),
- terminal.getObposTerminaltype().getName() }));
- } else {
- glitem = appPayObj.getPaymentMethod().getGcnvReimburseGlitem();
- }
- }
- } else {
- glitem = giftCardInst.getCategory().getGLItem();
- }
-
- FIN_FinancialAccount cashFinancialAccount = paymentMethod.getFinancialAccount();
-
- FIN_FinaccTransaction cashOutTransaction = OBProvider.getInstance()
- .get(FIN_FinaccTransaction.class);
- cashOutTransaction.setCurrency(cashFinancialAccount.getCurrency());
- cashOutTransaction.setObposAppCashup(cashup);
- cashOutTransaction.setAccount(cashFinancialAccount);
- cashOutTransaction
- .setLineNo(TransactionsDao.getTransactionMaxLineNo(cashFinancialAccount) + 10);
- cashOutTransaction.setGLItem(glitem);
- cashOutTransaction.setPaymentAmount(amount);
- cashOutTransaction.setDepositAmount(BigDecimal.ZERO);
- cashFinancialAccount
- .setCurrentBalance(cashFinancialAccount.getCurrentBalance().subtract(amount));
- cashOutTransaction.setProcessed(true);
- cashOutTransaction.setTransactionType("BPW");
- cashOutTransaction.setDescription(description);
- cashOutTransaction.setDateAcct(new Date());
- cashOutTransaction.setTransactionDate(new Date());
- cashOutTransaction.setStatus("RDNC");
- OBDal.getInstance().save(cashOutTransaction);
-
- paymentcashupEvent.setFINFinaccTransaction(cashOutTransaction);
- OBDal.getInstance().save(paymentcashupEvent);
+ FIN_FinancialAccount account = null;
+ FIN_PaymentMethod finPaymentMethod = null;
+ Organization organization = null;
+ OBPOSApplications posterminal = OBDal.getInstance()
+ .get(OBPOSApplications.class, jsonsent.optString("posTerminal"));
+ OBPOSAppPayment obposAppPayment = OBDal.getInstance()
+ .get(OBPOSAppPayment.class, jsonsent.optString("paymentMethodId"));
// Consume Gift Card
if (jsonsent.has("transactionId")) {
GiftCardTrans trans = OBDal.getInstance()
.get(GiftCardTrans.class, jsonsent.getString("transactionId"));
- if (trans.getPayment() == null) {
- FIN_Payment payment = null;
- FIN_FinancialAccount account = null;
- FIN_PaymentMethod finPaymentMethod = null;
- Organization organization = null;
- OBPOSApplications posterminal = OBDal.getInstance()
- .get(OBPOSApplications.class, jsonsent.optString("posTerminal"));
- OBPOSAppPayment obposAppPayment = OBDal.getInstance()
- .get(OBPOSAppPayment.class, jsonsent.optString("paymentMethodId"));
+ if (trans != null) {
+ if (trans.getPayment() == null) {
+ FIN_Payment payment = null;
+ if (giftCardInst.getPayment() != null) {
+ organization = giftCardInst.getPayment().getOrganization();
+ account = giftCardInst.getPayment().getAccount();
+ finPaymentMethod = giftCardInst.getPayment().getPaymentMethod();
+ }
- if (giftCardInst.getPayment() != null) {
- organization = giftCardInst.getPayment().getOrganization();
- account = giftCardInst.getPayment().getAccount();
- finPaymentMethod = giftCardInst.getPayment().getPaymentMethod();
+ // Make a payment
+ payment = GiftCardGLItemUtils.makePayment(giftCardInst, posterminal, cashup,
+ organization, account, finPaymentMethod, obposAppPayment, amount,
+ paymentcashupEvent, GiftCardModel.GIFTCARD_REIMBURSED);
+ trans.setPayment(payment);
+ OBDal.getInstance().save(trans);
+ } else {
+ GiftCardGLItemUtils.updatePayment(trans.getPayment(), null, giftCardInst, posterminal,
+ cashup, paymentcashupEvent);
}
-
- // Make a payment
- payment = GiftCardGLItemUtils.makePayment(giftCardInst, posterminal, cashup,
- organization, account, finPaymentMethod, obposAppPayment, amount,
- paymentcashupEvent, GiftCardModel.GIFTCARD_REIMBURSED);
- trans.setPayment(payment);
- OBDal.getInstance().save(trans);
- } else {
- GiftCardGLItemUtils.updatePayment(trans.getPayment(), giftCardInst, cashup,
- paymentcashupEvent);
}
} else {
if (giftCardInst.getCurrentamount().compareTo(amount) > 0) {
- OBPOSApplications posterminal = cashup == null ? null : cashup.getPOSTerminal();
GiftCardGLItemUtils.makeGiftCardTrans(giftCardInst, cashup, posterminal,
- paymentcashupEvent, "PU", amount, false);
+ paymentcashupEvent, obposAppPayment, GiftCardModel.GIFTCARD_PARTIALLY_USED, amount,
+ false);
} else {
// Close GiftCard
- GiftCardGLItemUtils.close(giftCardInst, cashup, paymentcashupEvent, "R");
+ GiftCardGLItemUtils.close(giftCardInst, cashup, posterminal, paymentcashupEvent,
+ obposAppPayment, GiftCardModel.GIFTCARD_REIMBURSED);
}
}
}
diff -r 753336ec49d9 -r 474f954b1409 src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java
--- a/src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java Tue Jul 30 12:11:39 2019 +0530
+++ b/src/org/openbravo/retail/giftcards/process/GiftCardGLItemUtils.java Tue Jul 30 16:36:12 2019 +0530
@@ -174,18 +174,46 @@
return trans;
}
- public static void updatePayment(FIN_Payment payment, GiftCardInst giftCardInst,
- OBPOSAppCashup cashup, OBPOSPaymentcashupEvents paymentcashupEvent) throws Exception {
+ public static void updatePayment(FIN_Payment payment, FIN_Payment refundPayment,
+ GiftCardInst giftCardInst, OBPOSApplications obposApplications, OBPOSAppCashup cashup,
+ OBPOSPaymentcashupEvents paymentcashupEvent) throws Exception {
+ FIN_FinaccTransaction transaction = payment.getFINFinaccTransactionList().get(0);
+ FIN_FinaccTransaction refundTransaction = null;
+ if (refundPayment == null) {
+ OBCriteria<FIN_Payment> paymentCriteria = OBDal.getInstance()
+ .createCriteria(FIN_Payment.class);
+ paymentCriteria
+ .add(Restrictions.eq(FIN_Payment.PROPERTY_OBPOSPOSTERMINAL, obposApplications));
+ paymentCriteria.add(Restrictions.eq(FIN_Payment.PROPERTY_OBPOSAPPCASHUP, cashup));
+ paymentCriteria
+ .add(Restrictions.eq(FIN_Payment.PROPERTY_AMOUNT, payment.getAmount().negate()));
+ paymentCriteria
+ .add(Restrictions.gt(FIN_Payment.PROPERTY_CREATIONDATE, payment.getCreationDate()));
+ paymentCriteria.setMaxResults(1);
+ List<FIN_Payment> paymentList = paymentCriteria.list();
+ if (paymentList.size() > 0) {
+ refundTransaction = paymentList.get(0).getFINFinaccTransactionList().get(0);
+ }
+ } else {
+ refundTransaction = refundPayment.getFINFinaccTransactionList().get(0);
+ }
if (cashup != null) {
- FIN_FinaccTransaction transaction = payment.getFINFinaccTransactionList().get(0);
transaction.setObposAppCashup(cashup);
OBDal.getInstance().save(transaction);
- if (paymentcashupEvent != null) {
- paymentcashupEvent.setRelatedTransaction(transaction);
- OBDal.getInstance().save(paymentcashupEvent);
+ if (refundTransaction != null) {
+ refundTransaction.setObposAppCashup(cashup);
+ OBDal.getInstance().save(refundTransaction);
}
}
+ if (paymentcashupEvent != null) {
+ paymentcashupEvent.setFINFinaccTransaction(transaction);
+ if (refundTransaction != null) {
+ paymentcashupEvent.setRelatedTransaction(refundTransaction);
+ }
+ OBDal.getInstance().save(paymentcashupEvent);
+ }
+
if (((giftCardInst.getCategory() != null && giftCardInst.getCategory().isReimbursed())
|| "BasedOnCreditNote".equals(giftCardInst.getType())) && paymentcashupEvent != null) {
String paymentMethodName = "";
@@ -291,12 +319,11 @@
throw new OBException(error.getMessage());
}
- updatePayment(payment, giftCardInst, cashup, paymentcashupEvent);
-
+ FIN_Payment refundPayment = null;
if (GiftCardModel.GIFTCARD_REIMBURSED.equals(certificateStatus) && obposApplications != null
&& obposAppPayment != null) {
BigDecimal refundAmount = amount.negate();
- FIN_Payment refundPayment = new AdvPaymentMngtDao().getNewPayment(true,
+ refundPayment = new AdvPaymentMngtDao().getNewPayment(true,
obposApplications.getOrganization(),
FIN_Utility.getDocumentType(organization, AcctServer.DOCTYPE_ARReceipt), null,
giftCardInst.getPayment().getBusinessPartner(),
@@ -321,10 +348,14 @@
}
}
+ updatePayment(payment, refundPayment, giftCardInst, obposApplications, cashup,
+ paymentcashupEvent);
+
log4j.info("Time to process payment: " + (System.currentTimeMillis() - init3));
}
return payment;
+
}
public static FIN_Payment makePayment(GiftCardInst giftCardInst, OBPOSAppCashup cashup,
issue 41464 source test.patch [^] (16,986 bytes) 2019-07-30 14:05 [Show Content] [Hide Content]# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1564488179 -19800
# Tue Jul 30 17:32:59 2019 +0530
# Node ID 2980accc908d0ddf071e54dfbff6bc521f33e046
# Parent ecbf4a2804bb3b7649db3090d13c3f75ac97df21
Verifies issue 41464 : Modified automated test 'CreditNoteReimburse'
diff -r ecbf4a2804bb -r 2980accc908d src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/CreditNoteReimburse.java
--- a/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/CreditNoteReimburse.java Tue Jul 30 14:35:53 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/CreditNoteReimburse.java Tue Jul 30 17:32:59 2019 +0530
@@ -27,6 +27,7 @@
import java.sql.SQLException;
import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
import org.openbravo.test.mobile.retail.mobilecore.annotations.TestClassAnnotations;
@@ -38,9 +39,10 @@
@TestClassAnnotations(isHighVolumeCompatible = true)
public class CreditNoteReimburse extends WebPOSExtModulesTerminalHelper {
- static String creditNoteValue = "";
- static String giftCardInstId = "";
- static String query;
+ String creditNoteValue, giftCardInstId, cashUpId;
+ String query;
+ final String finAccountYS11Cash = "4EF5B639012847E2998D20B5DF1A5A7E";
+ final String finAccountYS11CreditNote = "80863656DCCD4AF7BD09E92D9C1CA12D";
private final String giftCardInstanceQuery = "select gci.gcnv_giftcard_inst_id as gcId, gci.value, gci.amount as initBal, gci.currentamount as currBal, gci.status, "
+ " gci.fin_payment_id paymentId, gci.type, bp.name as bPartner "
@@ -52,8 +54,6 @@
+ " left join c_order ord on ord.c_order_id=tr.c_order_id "
+ " where gcnv_giftcard_inst_id = '%s' order by tr.created";
- static String giftInstpaymentId = "";
- static String giftTranspaymentId = "";
private final String giftCardPaymentQuery = "select pay.amount as payAmt, paymthd.name as payMethod, pay.fin_financial_account_id as finAcctId, acc.name as finAcct, cur.iso_code as currency from fin_payment pay "
+ " join fin_paymentmethod paymthd on paymthd.fin_paymentmethod_id=pay.fin_paymentmethod_id "
+ " join fin_financial_account acc on acc.fin_financial_account_id=pay.fin_financial_account_id "
@@ -66,15 +66,13 @@
+ " left join c_glitem gl on gl.c_glitem_id=det.c_glitem_id "
+ " where det.fin_payment_id='%s' order by ord.documentno";
- static String payFinAcctId = "";
- private final String paymentFinAcctQuery = "select depositamt, paymentamt from fin_finacc_transaction where fin_financial_account_id ='%s' order by created desc";
+ private final String paymentFinAcctQuery = "select depositamt, paymentamt from fin_finacc_transaction where fin_financial_account_id ='%s' order by created desc, depositamt, paymentamt";
- static String cashUpId = "";
private final String paymentMethodCashupQuery = "select obpos_paymentmethodcashup_id as cashupId, name, totaldeposits, totaldrops, totalcounted, totalsales, totalreturns "
+ " from obpos_paymentmethodcashup where obpos_app_cashup_id = '%s' and (lower(name) like 'cash' or lower(name) like 'credit note') order by name desc";
- static String payMethdCashUpId = "";
- private final String paymentMethodCashupEventQuery = "select amount, type from obpos_paymentcashup_events where obpos_paymentmethodcashup_id ='%s' order by type ";
+ private final String paymentMethodCashupEventQuery = "select amount, type from obpos_paymentcashup_events where obpos_paymentmethodcashup_id ='%s' "
+ + " and fin_finacc_transaction_id is not null and related_transaction_id is not null order by type, amount";
@Test
public void test() {
@@ -145,7 +143,7 @@
}
}.execute(query, 1);
- // Reimburse GiftCard
+ // Reimburse GiftCard with Amount 100
tap(TestIdPack.BUTTON_MENU);
tap(TestIdPack.BUTTON_MENU_CASHMANAGEMENT);
tap(TestIdPack.BUTTON_KEYPAD_2);
@@ -160,9 +158,29 @@
verify(TestIdExtModules.LABEL_CURRENT_BALANCEE, "136.00");
tap(TestIdExtModules.BUTTON_CREDITNOTE_MODAL_APPLY);
verify(TestIdExtModules.FIELD_CASHMGMT_REIMBURSE_AMOUNT, "136.00");
+ write(TestIdExtModules.FIELD_CASHMGMT_REIMBURSE_AMOUNT, "100.00");
tap(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSE_APPLY);
tap(TestIdExtModules.BUTTON_CASHMGMT_PAYMENT_CASH);
- verify(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSED_BODY, "Reimbursed: 136.00€");
+ verify(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSED_BODY, "Reimbursed: 100.00€");
+ tap(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSED_OKBUTTON);
+ tap(TestIdExtModules.BUTTON_CASHMANAGEMENT_DONE);
+ verify(TestIdExtModules.BUTTON_CASHMGMT_PROCESSSUCCESS_BODY,
+ "The Cash Management process was completed successfully.");
+ tap(TestIdExtModules.BUTTON_POPUP_OK);
+
+ // Reimburse GiftCard with Amount 36
+ tap(TestIdPack.BUTTON_MENU);
+ tap(TestIdPack.BUTTON_MENU_CASHMANAGEMENT);
+ tap(TestIdExtModules.BUTTON_CARDORCREDIT_REIMBURSE);
+ write(TestIdExtModules.FIELD_CREDITNOTE_MODAL, creditNoteValue);
+ tap(TestIdExtModules.BUTTON_CREDITNOTE_MODAL_SEARCH);
+ verify(TestIdExtModules.LABEL_INITIAL_BALANCE, "150.50");
+ verify(TestIdExtModules.LABEL_CURRENT_BALANCEE, "36.00");
+ tap(TestIdExtModules.BUTTON_CREDITNOTE_MODAL_APPLY);
+ verify(TestIdExtModules.FIELD_CASHMGMT_REIMBURSE_AMOUNT, "36.00");
+ tap(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSE_APPLY);
+ tap(TestIdExtModules.BUTTON_CASHMGMT_PAYMENT_CASH);
+ verify(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSED_BODY, "Reimbursed: 36.00€");
tap(TestIdExtModules.BUTTON_CASHMGMT_REIMBURSED_OKBUTTON);
tap(TestIdExtModules.BUTTON_CASHMANAGEMENT_DONE);
verify(TestIdExtModules.BUTTON_CASHMGMT_PROCESSSUCCESS_BODY,
@@ -196,8 +214,6 @@
count++;
final BigDecimal transAmt = rs.getBigDecimal("transAmt").setScale(2);
final BigDecimal paymentAmt = rs.getBigDecimal("paymentAmt").setScale(2);
- giftTranspaymentId = rs.getString("paymentId");
-
switch (count) {
case 1:
assertThat("The Transaction Amount is not one of the expected", transAmt,
@@ -207,49 +223,54 @@
break;
case 2:
assertThat("The Transaction Amount is not one of the expected", transAmt,
- equalTo(new BigDecimal("136.00")));
+ equalTo(new BigDecimal("100.00")));
assertThat("The Payment Amount is not one of the expected", paymentAmt,
- equalTo(new BigDecimal("136.00")));
+ equalTo(new BigDecimal("100.00")));
+ verifyGiftCardPayment(rs.getString("paymentId"), "100.00");
+ break;
+ case 3:
+ assertThat("The Transaction Amount is not one of the expected", transAmt,
+ equalTo(new BigDecimal("36.00")));
+ assertThat("The Payment Amount is not one of the expected", paymentAmt,
+ equalTo(new BigDecimal("36.00")));
+ verifyGiftCardPayment(rs.getString("paymentId"), "36.00");
break;
default:
throw new IllegalArgumentException("The returned resulset is missing the assertions");
}
}
- }.execute(query, 2);
+ }.execute(query, 3, false);
- // Verify closed credit note gift transaction payment
- query = String.format(giftCardPaymentQuery, giftTranspaymentId);
+ // Verify Payment Financial Account Transaction after closed
+ query = String.format(paymentFinAcctQuery, finAccountYS11CreditNote);
new DatabaseHelperSelect() {
+ int count = 0;
+
@Override
protected void yieldResultSet(final ResultSet rs) throws SQLException {
- final BigDecimal payment = rs.getBigDecimal("payAmt").setScale(2);
- final String paymentMethod = rs.getString("payMethod");
- payFinAcctId = rs.getString("finAcctId");
-
- assertThat("The Payment is not one of the expected", payment,
- equalTo(new BigDecimal("136.00")));
- assertThat("The Payment Method is not one of the expected", paymentMethod, equalTo("Cash"));
+ count++;
+ final BigDecimal depositAmt = rs.getBigDecimal("depositamt").setScale(2);
+ switch (count) {
+ case 1:
+ assertThat("The Deposit Amount is not one of the expected", depositAmt,
+ equalTo(new BigDecimal("36.00")));
+ break;
+ case 2:
+ assertThat("The Withdraw Amount is not one of the expected", depositAmt,
+ equalTo(new BigDecimal("100.00")));
+ break;
+ case 3:
+ assertThat("The Withdraw Amount is not one of the expected", depositAmt,
+ equalTo(new BigDecimal("14.50")));
+ break;
+ default:
+ throw new IllegalArgumentException("The returned resulset is missing the assertions");
+ }
}
- }.execute(query, 1);
-
- // Verify closed credit note gift transaction payment lines
- query = String.format(giftCardPaymentLneQuery, giftTranspaymentId);
- new DatabaseHelperSelect() {
- @Override
- protected void yieldResultSet(final ResultSet rs) throws SQLException {
- final BigDecimal amount = rs.getBigDecimal("amount").setScale(2);
- final String glitem = rs.getString("glitem");
-
- assertThat("The Received Amount is not one of the expected", amount,
- equalTo(new BigDecimal("136.00")));
- assertThat("The Payment Method is not one of the expected", glitem,
- equalTo("Gift Card Reimburse"));
- }
- }.execute(query, 1);
+ }.execute(MobileCoreDatabaseHelper.getTOP(query, 3), 3);
// Verify Payment Financial Account Transaction after closed
- query = String.format(paymentFinAcctQuery, payFinAcctId);
-
+ query = String.format(paymentFinAcctQuery, finAccountYS11Cash);
new DatabaseHelperSelect() {
int count = 0;
@@ -258,31 +279,27 @@
count++;
final BigDecimal depositAmt = rs.getBigDecimal("depositamt").setScale(2);
final BigDecimal withdrawAmt = rs.getBigDecimal("paymentamt").setScale(2);
-
switch (count) {
case 1:
- assertThat("The Withdraw Amount is not one of the expected", withdrawAmt,
- equalTo(new BigDecimal("136.00")));
+ assertThat("The Deposit Amount is not one of the expected", withdrawAmt,
+ equalTo(new BigDecimal("36.00")));
break;
case 2:
- assertThat("The Deposit Amount is not one of the expected", depositAmt,
+ assertThat("The Withdraw Amount is not one of the expected", withdrawAmt,
+ equalTo(new BigDecimal("100.00")));
+ break;
+ case 3:
+ assertThat("The Withdraw Amount is not one of the expected", depositAmt,
equalTo(new BigDecimal("200.00")));
break;
default:
throw new IllegalArgumentException("The returned resulset is missing the assertions");
}
}
- }.execute(MobileCoreDatabaseHelper.getTOP(query, 2), 2);
+ }.execute(MobileCoreDatabaseHelper.getTOP(query, 3), 3);
- // Get cashupId
- new DatabaseHelperSelect() {
- @Override
- protected void yieldResultSet(final ResultSet rs) throws SQLException {
- cashUpId = rs.getString("obpos_app_cashup_id");
- }
- }.execute(MobileCoreDatabaseHelper.getTOP(String.format(
- "select obpos_app_cashup_id from obpos_app_cashup where obpos_applications_id = '%s' order by created desc",
- WebPOSExtModulesTerminalHelper.DEFAULT_TERMINAL_ID), 1), 1);
+ cashUpId = (String) SeleniumHelper
+ .executeScriptWithReturn("OB.MobileApp.model.get('terminal').cashUpId");
// Verify POS Terminal Payment Method CashUp
query = String.format(paymentMethodCashupQuery, cashUpId);
@@ -292,7 +309,6 @@
@Override
protected void yieldResultSet(final ResultSet rs) throws SQLException {
count++;
- payMethdCashUpId = rs.getString("cashupId");
final BigDecimal deposit = rs.getBigDecimal("totaldeposits").setScale(2);
final BigDecimal drops = rs.getBigDecimal("totaldrops").setScale(2);
final BigDecimal counted = rs.getBigDecimal("totalcounted").setScale(2);
@@ -313,42 +329,80 @@
equalTo(new BigDecimal("136.00")));
assertThat("The Total Counted is not one of the expected", counted,
equalTo(new BigDecimal("0.00")));
+
+ // Verify POS Terminal Payment Method Events
+ query = String.format(paymentMethodCashupEventQuery, rs.getString("cashupId"));
+ new DatabaseHelperSelect() {
+ int cnt = 0;
+
+ @Override
+ protected void yieldResultSet(final ResultSet rs2) throws SQLException {
+ cnt++;
+ final BigDecimal amount = rs2.getBigDecimal("amount").setScale(2);
+
+ switch (cnt) {
+ case 1:
+ assertThat("The Deposite Amount is not one of the expected", amount,
+ equalTo(new BigDecimal("200.00")));
+ break;
+ case 2:
+ assertThat("The Drop Amount is not one of the expected", amount,
+ equalTo(new BigDecimal("36.00")));
+ break;
+ case 3:
+ assertThat("The Drop Amount is not one of the expected", amount,
+ equalTo(new BigDecimal("100.00")));
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "The returned resulset is missing the assertions");
+ }
+ }
+ }.execute(query, 3, false);
+
break;
default:
throw new IllegalArgumentException("The returned resulset is missing the assertions");
}
}
- }.execute(query, 2);
-
- // Verify POS Terminal Payment Method Events
- query = String.format(paymentMethodCashupEventQuery, payMethdCashUpId);
- new DatabaseHelperSelect() {
- int count = 0;
-
- @Override
- protected void yieldResultSet(final ResultSet rs) throws SQLException {
- count++;
- final BigDecimal amount = rs.getBigDecimal("amount").setScale(2);
-
- switch (count) {
- case 1:
- assertThat("The Deposite Amount is not one of the expected", amount,
- equalTo(new BigDecimal("200.00")));
- break;
- case 2:
- assertThat("The Drop Amount is not one of the expected", amount,
- equalTo(new BigDecimal("136.00")));
- break;
- default:
- throw new IllegalArgumentException("The returned resulset is missing the assertions");
- }
- }
- }.execute(query, 2);
+ }.execute(query, 2, false);
WebPOSAPI.cleanCashup(this);
logIn();
}
+ private void verifyGiftCardPayment(String giftTranspaymentId, String expectedAmount) {
+ // Verify closed credit note gift transaction payment
+ query = String.format(giftCardPaymentQuery, giftTranspaymentId);
+ new DatabaseHelperSelect() {
+ @Override
+ protected void yieldResultSet(final ResultSet rs) throws SQLException {
+ final BigDecimal payment = rs.getBigDecimal("payAmt").setScale(2);
+ final String paymentMethod = rs.getString("payMethod");
+
+ assertThat("The Payment is not one of the expected", payment,
+ equalTo(new BigDecimal(expectedAmount)));
+ assertThat("The Payment Method is not one of the expected", paymentMethod,
+ equalTo("Credit Note"));
+ }
+ }.execute(query, 1, false);
+
+ // Verify closed credit note gift transaction payment lines
+ query = String.format(giftCardPaymentLneQuery, giftTranspaymentId);
+ new DatabaseHelperSelect() {
+ @Override
+ protected void yieldResultSet(final ResultSet rs) throws SQLException {
+ final BigDecimal amount = rs.getBigDecimal("amount").setScale(2);
+ final String glitem = rs.getString("glitem");
+
+ assertThat("The Received Amount is not one of the expected", amount,
+ equalTo(new BigDecimal(expectedAmount)));
+ assertThat("The Payment Method is not one of the expected", glitem,
+ equalTo("Gift Card Reimburse"));
+ }
+ }.execute(query, 1, false);
+ }
+
private void addAvalancheTransceiver() {
tap(TestIdExtModules.BUTTON_SEARCH);
write(TestIdExtModules.FIELD_SEARCH_TEXT, "Avalanche transceiver");
|