svn commit: r614074 - /ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r614074 - /ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java

jleroux@apache.org
Author: jleroux
Date: Mon Jan 21 16:45:41 2008
New Revision: 614074

URL: http://svn.apache.org/viewvc?rev=614074&view=rev
Log:
Applied fix from trunk for revision: 614072

Modified:
    ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java

Modified: ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?rev=614074&r1=614073&r2=614074&view=diff
==============================================================================
--- ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Mon Jan 21 16:45:41 2008
@@ -444,18 +444,23 @@
             GenericValue giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
             GenericValue finAccount = null;
             String finAccountId = null;
-            if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
-                if (validatePin(delegator, giftCard.getString("cardNumber"), giftCard.getString("pinNumber"))) {
-                    finAccountId = giftCard.getString("cardNumber");
-                    finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
-                }
+            if (UtilValidate.isNotEmpty(giftCertSettings)) {
+                if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
+                    if (validatePin(delegator, giftCard.getString("cardNumber"), giftCard.getString("pinNumber"))) {
+                        finAccountId = giftCard.getString("cardNumber");
+                        finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
+                    }
+                } else {
+                        finAccount = FinAccountHelper.getFinAccountFromCode(giftCard.getString("cardNumber"), delegator);
+                        if (finAccount == null) {
+                            return ServiceUtil.returnError("Gift certificate not found");
+                        }
+                        finAccountId = finAccount.getString("finAccountId");
+                }
             } else {
-                    finAccount = FinAccountHelper.getFinAccountFromCode(giftCard.getString("cardNumber"), delegator);
-                    if (finAccount == null) {
-                        return ServiceUtil.returnError("Gift certificate not found");
-                    }
-                    finAccountId = finAccount.getString("finAccountId");
+                return ServiceUtil.returnError("No product store financial account settings available");
             }
+            
             if (finAccountId == null) {
                 return ServiceUtil.returnError("Gift certificate pin number is invalid");
             }
@@ -475,7 +480,7 @@
             BigDecimal amountBd = (new BigDecimal(amount.doubleValue())).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding);
 
             // if availableBalance equal to or greater than amount, then auth
-            if (availableBalance.compareTo(amountBd) > -1) {
+            if (UtilValidate.isNotEmpty(availableBalance) && availableBalance.compareTo(amountBd) > -1) {
                 Timestamp thruDate = null;
                 if (giftCertSettings.getLong("authValidDays") != null) {
                     thruDate = UtilDateTime.getDayEnd(UtilDateTime.nowTimestamp(), giftCertSettings.getLong("authValidDays").intValue());