Attached Files | 18Q3.diff [^] (16,447 bytes) 2019-07-10 17:21 [Show Content] [Hide Content]diff --git a/src/org/openbravo/retail/giftcards/ConsumeGiftCardAmount.java b/src/org/openbravo/retail/giftcards/ConsumeGiftCardAmount.java
--- a/src/org/openbravo/retail/giftcards/ConsumeGiftCardAmount.java
+++ b/src/org/openbravo/retail/giftcards/ConsumeGiftCardAmount.java
@@ -82,8 +82,7 @@
String newTrxId;
try {
- newTrxId = jsonsent.getJSONObject("_result").getJSONObject("data")
- .getJSONObject("transaction").getString("id");
+ newTrxId = jsonsent.getString("newTransactionId");
} catch (Exception e) {
newTrxId = SequenceIdData.getUUID();
}
diff --git a/src/org/openbravo/retail/giftcards/GiftCardModel.java b/src/org/openbravo/retail/giftcards/GiftCardModel.java
--- a/src/org/openbravo/retail/giftcards/GiftCardModel.java
+++ b/src/org/openbravo/retail/giftcards/GiftCardModel.java
@@ -323,8 +323,11 @@
realamount = realamount.negate();
}
- GiftCardTrans trans;
- if (transactionId != null) {
+ GiftCardTrans trans = transactionId != null
+ ? OBDal.getInstance().get(GiftCardTrans.class, transactionId)
+ : null;
+
+ if (trans != null) {
trans = OBDal.getInstance().get(GiftCardTrans.class, transactionId);
trans.setAmount(realamount.add(trans.getAmount()));
} else {
@@ -489,18 +492,30 @@
}
public GiftCardTrans populateGiftCardTransaction(String transactionid, Order order,
- OrderLine orderLine) {
+ OrderLine orderLine) throws Exception {
return populateGiftCardTransaction(transactionid, order, orderLine, null);
}
public GiftCardTrans populateGiftCardTransaction(String transactionid, Order order,
- OrderLine orderLine, String paymentId) {
+ OrderLine orderLine, String paymentId) throws Exception {
+ GiftCardModel model = new GiftCardModel();
GiftCardTrans trans = OBDal.getInstance().get(GiftCardTrans.class, transactionid);
FIN_Payment payment = null;
+ GiftCardInst giftCard = null;
if (paymentId != null) {
payment = OBDal.getInstance().get(FIN_Payment.class, paymentId);
+ giftCard = OBDal.getInstance()
+ .get(GiftCardInst.class,
+ new JSONObject(payment.getObposPaymentdata()).getString("cardId"));
+ }
+ // check if the transaction is created or not (Simple Gift Certificate and Credit Note)
+ if (trans == null) {
+ trans = model.consumeAmountGiftCard(transactionid, giftCard, new Date(), order, orderLine,
+ payment.getAmount().abs(), payment.getAmount().compareTo(BigDecimal.ZERO) < 0,
+ transactionid == null || "null".equals(transactionid) ? null : transactionid,
+ payment.getPaymentMethod() != null ? true : false);
}
if (payment != null && trans.getAmount().compareTo(payment.getAmount()) != 0) {
diff --git a/src/org/openbravo/retail/giftcards/hooks/OrderLoaderHookGiftCard.java b/src/org/openbravo/retail/giftcards/hooks/OrderLoaderHookGiftCard.java
--- a/src/org/openbravo/retail/giftcards/hooks/OrderLoaderHookGiftCard.java
+++ b/src/org/openbravo/retail/giftcards/hooks/OrderLoaderHookGiftCard.java
@@ -9,6 +9,8 @@
package org.openbravo.retail.giftcards.hooks;
+import java.math.BigDecimal;
+import java.util.Date;
import java.util.Iterator;
import javax.enterprise.context.ApplicationScoped;
@@ -25,6 +27,7 @@
import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
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.OrderLoaderPaymentHook;
@ApplicationScoped
@@ -84,6 +87,20 @@
gc.createGiftCard(giftcardid, product, bp, order.getOrderDate(), order, orderline,
orderline.getLineNetAmount(), giftCardProperties);
} else {
+ // check if the transaction is created or not (Simple Gift Card)
+ GiftCardTrans trans = transaction != null
+ ? OBDal.getInstance().get(GiftCardTrans.class, transaction)
+ : null;
+ if (trans == null) {
+ BigDecimal currentamt = new BigDecimal(
+ line.getJSONObject("product").optString("currentamt", null));
+ trans = gc.consumeAmountGiftCard(transaction,
+ OBDal.getInstance()
+ .get(GiftCardInst.class, line.getJSONObject("product").optString("cardId", null)),
+ new Date(), order, orderline, currentamt.negate(),
+ line.getJSONObject("product").optBoolean("isReturn"),
+ transaction == null || "null".equals(transaction) ? null : transaction, true);
+ }
// is a gift card transaction so just fill in the order and order-line fields
gc.populateGiftCardTransaction(transaction, order, orderline);
}
diff --git a/web/org.openbravo.retail.giftcards/js/hooks/PreReversePaymentHook.js b/web/org.openbravo.retail.giftcards/js/hooks/PreReversePaymentHook.js
--- a/web/org.openbravo.retail.giftcards/js/hooks/PreReversePaymentHook.js
+++ b/web/org.openbravo.retail.giftcards/js/hooks/PreReversePaymentHook.js
@@ -18,7 +18,7 @@
payment = args.paymentToReverse,
reversalPayment = args.reversalPayment,
amount = payment.get('amount'),
- hasPaymentMethod;
+ hasPaymentMethod, newTransactionId = OB.UTIL.get_UUID();
hasPaymentMethod = _.find(OB.MobileApp.model.get('payments'), function (payment) {
return payment.payment.searchKey === args.paymentToReverse.get('kind');
@@ -30,19 +30,13 @@
paymentToReverse: payment.get("paymentId"),
amount: OB.DEC.sub(0, amount),
isReturn: isReturn,
- hasPaymentMethod: !OB.UTIL.isNullOrUndefined(hasPaymentMethod)
+ hasPaymentMethod: !OB.UTIL.isNullOrUndefined(hasPaymentMethod),
+ newTransactionId: newTransactionId
}, function (result) {
- reversalPayment.set('transaction', result.transaction.id);
+ reversalPayment.set('transaction', newTransactionId);
OB.UTIL.HookManager.callbackExecutor(args, callbacks);
}, function (error) {
- var msgsplit = (error.exception.message || 'GCNV_ErrorGenericMessage').split(':');
- OB.MobileApp.view.$.containerWindow.getRoot().doShowPopup({
- popup: 'GCNV_UI_Message',
- args: {
- message: OB.I18N.getLabel(msgsplit[0], msgsplit.slice(1))
- }
- });
- args.cancelOperation = true;
+ reversalPayment.set('transaction', newTransactionId);
OB.UTIL.HookManager.callbackExecutor(args, callbacks);
});
} else {
diff --git a/web/org.openbravo.retail.giftcards/js/hooks/preaddpaymenthook.js b/web/org.openbravo.retail.giftcards/js/hooks/preaddpaymenthook.js
--- a/web/org.openbravo.retail.giftcards/js/hooks/preaddpaymenthook.js
+++ b/web/org.openbravo.retail.giftcards/js/hooks/preaddpaymenthook.js
@@ -72,7 +72,7 @@
paymentData.groupingCriteria = dialog.args.giftcard.searchKey;
args.paymentToAdd.set('paymentData', paymentData);
// Pay with a credit note
- OB.UI.GiftCardUtils.consumeCreditNoteAmount(args.keyboard, args.receipt, dialog.args.giftcard.searchKey, amount, args.paymentToAdd, successCallback, errorCallback);
+ OB.UI.GiftCardUtils.consumeCreditNoteAmount(args.keyboard, args.receipt, dialog.args.giftcard.searchKey, amount, args.paymentToAdd, successCallback, errorCallback, dialog.args.giftcard.id);
}
}
});
diff --git a/web/org.openbravo.retail.giftcards/js/model/GiftCardUtils.js b/web/org.openbravo.retail.giftcards/js/model/GiftCardUtils.js
--- a/web/org.openbravo.retail.giftcards/js/model/GiftCardUtils.js
+++ b/web/org.openbravo.retail.giftcards/js/model/GiftCardUtils.js
@@ -172,41 +172,38 @@
var giftCardPaymentMethod = _.find(OB.MobileApp.model.get('payments'), function (payment) {
return payment.payment.searchKey === 'OBPOS_payment.giftcard';
});
+ var newTransactionId = OB.UTIL.get_UUID();
- OB.UI.GiftCardUtils.service('org.openbravo.retail.giftcards.ConsumeGiftCardAmount', {
- giftcard: card.searchKey,
- _executeInOneServer: true,
- _tryCentralFromStore: true,
- amount: amount,
- isReturn: isReturn,
- transaction: payment ? payment.get('transaction') : null,
- hasPaymentMethod: giftCardPaymentMethod !== undefined && giftCardPaymentMethod !== null
- }, function (result) {
-
- if (result.product) {
- OB.UI.GiftCardUtils.findProductModel(result.product.id, function (transactionproduct) {
-
+ function cbkConsumeGc() {
+ var realAmt = card.currentamount > amount ? OB.DEC.abs(amount) : OB.DEC.abs(card.currentamount);
+ if (card.product) {
+ OB.UI.GiftCardUtils.findProductModel(card.product, function (
+ transactionproduct) {
// Add properties to product.
- transactionproduct.set('giftCardTransaction', result.transaction.id);
+ transactionproduct.set('giftCardTransaction', newTransactionId);
+ transactionproduct.set('cardId', card.id);
transactionproduct.set('isEditablePrice', false);
transactionproduct.set('isEditableQty', false);
- transactionproduct.set('standardPrice', (result.transaction.amount * (isReturn ? 1 : -1)));
+ transactionproduct.set('standardPrice', -amount);
transactionproduct.set('ignorePromotions', true);
- transactionproduct.set('currentamt', result.currentamt);
+ transactionproduct.set('currentamt', -realAmt);
+ transactionproduct.set('isReturn', isReturn);
keyboard.doAddProduct({
product: transactionproduct,
ignoreStockTab: true,
callback: function (success) {
if (success === false) {
- OB.UI.GiftCardUtils.cancelGiftCardTransaction(keyboard, result.transaction.id);
+ OB.UI.GiftCardUtils.cancelGiftCardTransaction(
+ keyboard, newTransactionId);
}
}
});
});
} else {
var p = _.find(OB.MobileApp.model.get('payments'), function (payment) {
- return result.paymentMethod.id === payment.paymentMethod.paymentMethod;
+ return (
+ giftCardPaymentMethod.paymentMethod.paymentMethod === payment.paymentMethod.paymentMethod);
});
// Add Payment
@@ -216,17 +213,19 @@
} else {
modelToApply = keyboard.model.get('multiOrders');
}
- modelToApply.addPayment(new OB.Model.PaymentLine({
+ modelToApply.addPayment(
+ new OB.Model.PaymentLine({
kind: p.payment.searchKey,
paymentData: {
card: card.searchKey,
+ cardId: card.id,
voidTransaction: function (callback) {
callback(false, null);
},
voidConfirmation: false
},
name: OB.I18N.getLabel('GCNV_LblGiftCardsCertificate') + ' ' + card.searchKey,
- amount: OB.DEC.abs(result.realamnt),
+ amount: OB.DEC.abs(realAmt),
rate: p.rate,
mulrate: p.mulrate,
isocode: p.isocode,
@@ -234,21 +233,26 @@
allowOpenDrawer: p.paymentMethod.allowOpenDrawer,
openDrawer: p.paymentMethod.openDrawer,
printtwice: p.paymentMethod.printtwice,
- transaction: result.transaction.id
+ transaction: newTransactionId
}));
}
if (success) {
success();
}
+ }
+ OB.UI.GiftCardUtils.service('org.openbravo.retail.giftcards.ConsumeGiftCardAmount', {
+ giftcard: card.searchKey,
+ _executeInOneServer: true,
+ _tryCentralFromStore: true,
+ amount: amount,
+ isReturn: isReturn,
+ transaction: payment ? payment.get('transaction') : null,
+ hasPaymentMethod: giftCardPaymentMethod !== undefined && giftCardPaymentMethod !== null,
+ newTransactionId: newTransactionId
+ }, function (result) {
+ cbkConsumeGc();
}, function (error) {
- var msgsplit = (error.exception.message || 'GCNV_ErrorGenericMessage').split(':');
- if (fail) {
- var errorMessage = {
- message: OB.I18N.getLabel(msgsplit[0], msgsplit.slice(1)),
- keyboard: keyboard
- };
- fail(errorMessage);
- }
+ cbkConsumeGc();
});
};
@@ -295,7 +299,7 @@
});
};
- var consumeCreditNoteAmount = function (keyboard, receipt, card, amount, paymentToAdd, success, fail) {
+ var consumeCreditNoteAmount = function (keyboard, receipt, card, amount, paymentToAdd, success, fail, cardId) {
var isMultiOrder = false,
isReturn = false;
@@ -317,25 +321,11 @@
return payment.payment.searchKey === 'GCNV_payment.creditnote';
});
- OB.UI.GiftCardUtils.service('org.openbravo.retail.giftcards.ConsumeGiftCardAmount', {
- giftcard: card,
- _executeInOneServer: true,
- _tryCentralFromStore: true,
- amount: amount,
- isReturn: isReturn,
- transaction: payment ? payment.get('transaction') : null,
- hasPaymentMethod: giftCardPaymentMethod !== undefined && giftCardPaymentMethod !== null
- }, function (result) {
+ var newTransactionId = payment ? payment.get('transaction') : OB.UTIL.get_UUID(),
+ p = giftCardPaymentMethod;
- var p = null,
- newPayment = new Backbone.Model();
- if (giftCardPaymentMethod !== undefined && giftCardPaymentMethod !== null) {
- p = giftCardPaymentMethod;
- } else {
- p = _.find(OB.MobileApp.model.get('payments'), function (payment) {
- return result.paymentMethod.id === payment.paymentMethod.paymentMethod;
- });
- }
+ function resultConsumeCreditNoteAmount(trx, amt, gftSk, gftId) {
+ var newPayment = new Backbone.Model();
// Add Payment
var modelToApply, paymentData = paymentToAdd.get('paymentData') || {};
@@ -345,28 +335,35 @@
modelToApply = keyboard.model.get('multiOrders');
}
OB.UTIL.clone(paymentToAdd, newPayment);
- paymentData.card = card;
+ paymentData.card = gftSk;
+ paymentData.cardId = gftId;
paymentData.voidTransaction = function (callback) {
callback(false, null);
};
paymentData.voidConfirmation = false;
newPayment.set('name', OB.MobileApp.model.getPaymentName(p.payment.searchKey) + ' ' + card);
- newPayment.set('amount', OB.DEC.abs(result.realamnt));
+ newPayment.set('amount', paymentData.creditNote.currentamount > amt ? OB.DEC.abs(amt) : OB.DEC.abs(paymentData.creditNote.currentamount));
newPayment.set('paymentData', paymentData);
- newPayment.set('transaction', result.transaction.id);
+ newPayment.set('transaction', trx);
modelToApply.addPayment(new OB.Model.PaymentLine(newPayment.attributes));
if (success) {
success();
}
+ }
+
+ OB.UI.GiftCardUtils.service('org.openbravo.retail.giftcards.ConsumeGiftCardAmount', {
+ giftcard: card,
+ _executeInOneServer: true,
+ _tryCentralFromStore: true,
+ amount: amount,
+ isReturn: isReturn,
+ transaction: payment ? payment.get('transaction') : null,
+ newTransactionId: newTransactionId,
+ hasPaymentMethod: giftCardPaymentMethod !== undefined && giftCardPaymentMethod !== null
+ }, function (result) {
+ resultConsumeCreditNoteAmount(newTransactionId, amount, card, cardId);
}, function (error) {
- var msgsplit = (error.exception.message || 'GCNV_ErrorGenericMessage').split(':');
- var errorMessage = {
- message: OB.I18N.getLabel(msgsplit[0], msgsplit.slice(1)),
- keyboard: keyboard
- };
- if (fail) {
- fail(errorMessage);
- }
+ resultConsumeCreditNoteAmount(newTransactionId, amount, card, cardId);
});
};
|