Author: jaz
Date: Mon Mar 26 23:14:11 2007
New Revision: 522769
URL: http://svn.apache.org/viewvc?view=rev&rev=522769
Log:
fixed currency issues in balance code
Modified:
ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
--- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Mon Mar 26
23:14:11 2007
@@ -565,8 +565,7 @@
<alias entity-alias="FAA" name="authorizationDate" group-by="false"/>
<alias entity-alias="FAA" name="fromDate" group-by="false"/>
<alias entity-alias="FAA" name="thruDate" group-by="false"/>
- <alias entity-alias="FAA" name="amount" function="sum"/>
- <alias entity-alias="FAA" name="currencyUomId" group-by="true"/>
+ <alias entity-alias="FAA" name="amount" function="sum"/>
</view-entity>
<!-- ========================================================= -->
Modified: ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
(original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml Mon
Mar 26 23:14:11 2007
@@ -101,7 +101,7 @@
<description>Expires a fin account authorization. Will use current
time if no time is supplied in parameter</description>
<attribute name="finAccountAuthId" type="String" mode="IN"
optional="false"/>
<attribute name="expireDateTime" type="Timestamp" mode="IN"
optional="true"/>
- </service>
+ </service>
<!-- these services use the product store's fin account settings -->
<service name="createFinAccountForStore" engine="java"
default-entity-name="FinAccount"
@@ -160,7 +160,8 @@
<service name="checkFinAccountStatus" engine="java"
location="org.ofbiz.accounting.finaccount.FinAccountServices"
invoke="checkFinAccountStatus" auth="true">
<description>Checks the status of the financial account; changes the
isFrozen flag</description>
- <attribute name="finAccountId" type="String" mode="IN"
optional="false"/>
+ <attribute name="finAccountAuthId" type="String" mode="IN"
optional="true"/>
+ <attribute name="finAccountId" type="String" mode="IN"
optional="true"/>
</service>
<!-- balance account created from product purchase -->
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
Mon Mar 26 23:14:11 2007
@@ -140,7 +140,7 @@
}
// check the amount to authorize against the available balance of
fin account, which includes active authorizations as well as transactions
- BigDecimal availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, currency, delegator);
+ BigDecimal availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, delegator);
Map result = ServiceUtil.returnSuccess();
Boolean processResult;
String refNum;
@@ -161,7 +161,7 @@
}
Map tmpResult = dispatcher.runSync("createFinAccountAuth",
UtilMisc.toMap("finAccountId", finAccountId,
- "amount", amount, "currencyUomId", currency,
"thruDate", thruDate, "userLogin", userLogin));
+ "amount", amount, "thruDate", thruDate, "userLogin",
userLogin));
if (ServiceUtil.isError(tmpResult)) {
return tmpResult;
@@ -171,7 +171,7 @@
}
// mark the account as frozen if we have gone negative
- BigDecimal newBalance =
FinAccountHelper.getAvailableBalance(finAccountId, currency, delegator);
+ BigDecimal newBalance =
FinAccountHelper.getAvailableBalance(finAccountId, delegator);
if (newBalance.compareTo(FinAccountHelper.ZERO) == -1) {
finAccount.set("isFrozen", "Y");
try {
@@ -458,7 +458,7 @@
// check the actual balance (excluding authorized amounts) and create
the transaction if it is sufficient
BigDecimal previousBalance;
try {
- previousBalance = FinAccountHelper.getBalance(finAccountId,
currencyUom, delegator);
+ previousBalance = FinAccountHelper.getBalance(finAccountId,
delegator);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -471,7 +471,7 @@
try {
refNum =
FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator,
dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, WITHDRAWAL,
finAccountId);
- balance = FinAccountHelper.getAvailableBalance(finAccountId,
currencyUom, delegator);
+ balance = FinAccountHelper.getAvailableBalance(finAccountId,
delegator);
procResult = Boolean.TRUE;
} catch (GeneralException e) {
Debug.logError(e, module);
@@ -536,7 +536,7 @@
// get the previous balance
BigDecimal previousBalance;
try {
- previousBalance =
FinAccountHelper.getAvailableBalance(finAccountId, currencyUom, delegator);
+ previousBalance =
FinAccountHelper.getAvailableBalance(finAccountId, delegator);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -548,7 +548,7 @@
try {
refNum =
FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator,
dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, DEPOSIT,
finAccountId);
- balance = FinAccountHelper.getAvailableBalance(finAccountId,
currencyUom, delegator);
+ balance = FinAccountHelper.getAvailableBalance(finAccountId,
delegator);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -600,7 +600,7 @@
}
BigDecimal replenishLevel = finAccount.getBigDecimal("replenishLevel");
- if (replenishLevel == null) {
+ if (replenishLevel == null ||
replenishLevel.compareTo(FinAccountHelper.ZERO) == 0) {
// no replenish level set; this account goes not support
auto-replenish
return ServiceUtil.returnSuccess();
}
@@ -608,7 +608,7 @@
// get the current balance
BigDecimal balance;
try {
- balance = FinAccountHelper.getBalance(finAccountId, currency,
delegator);
+ balance = FinAccountHelper.getBalance(finAccountId, delegator);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java
Mon Mar 26 23:14:11 2007
@@ -142,7 +142,7 @@
// if we auto-replenish this type; set the level to the initial deposit
if (replenishEnumId != null &&
"FARP_AUTOMATIC".equals(replenishEnumId)) {
- createCtx.put("replenishLevel", deposit);
+ createCtx.put("replenishLevel", new Double(deposit.doubleValue()));
}
Map createResp;
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
Mon Mar 26 23:14:11 2007
@@ -34,6 +34,7 @@
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.order.finaccount.FinAccountHelper;
+import org.ofbiz.product.store.ProductStoreWorker;
public class FinAccountServices {
@@ -77,7 +78,11 @@
inContext.put("thruDate", UtilDateTime.getDayEnd(now,
accountValidDays.intValue()));
inContext.put("fromDate", now);
inContext.put("userLogin", userLogin);
-
+
+ // product store payToPartyId
+ String payToPartyId =
ProductStoreWorker.getProductStorePayToPartyId(productStoreId, delegator);
+ inContext.put("organizationPartyId", payToPartyId);
+
Map createResult = dispatcher.runSync("createFinAccount",
inContext);
if (ServiceUtil.isError(createResult)) {
@@ -130,8 +135,8 @@
BigDecimal availableBalance;
BigDecimal balance;
try {
- availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, currencyUom, delegator);
- balance = FinAccountHelper.getBalance(finAccountId, currencyUom,
delegator);
+ availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, delegator);
+ balance = FinAccountHelper.getBalance(finAccountId, delegator);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
@@ -146,8 +151,25 @@
public static Map checkFinAccountStatus(DispatchContext dctx, Map context)
{
GenericDelegator delegator = dctx.getDelegator();
+ String finAccountAuthId = (String) context.get("finAccountAuthId");
String finAccountId = (String) context.get("finAccountId");
+ if (finAccountId == null && finAccountAuthId != null) {
+ GenericValue auth;
+ try {
+ auth = delegator.findByPrimaryKey("FinAccountAuth",
UtilMisc.toMap("finAccountAuthId", finAccountAuthId));
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ if (auth != null) {
+ finAccountId = auth.getString("finAccountId");
+ }
+ }
+
+ if (finAccountId == null) {
+ return ServiceUtil.returnError("Financial account ID is required
for this service!");
+ }
+
GenericValue finAccount;
try {
finAccount = delegator.findByPrimaryKey("FinAccount",
UtilMisc.toMap("finAccountId", finAccountId));
@@ -162,7 +184,7 @@
BigDecimal balance;
try {
- balance = FinAccountHelper.getAvailableBalance(finAccountId,
currency, delegator);
+ balance = FinAccountHelper.getAvailableBalance(finAccountId,
delegator);
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
Mon Mar 26 23:14:11 2007
@@ -195,7 +195,7 @@
// get the previous balance
BigDecimal previousBalance = ZERO;
try {
- previousBalance = FinAccountHelper.getAvailableBalance(cardNumber,
currencyUom, delegator);
+ previousBalance = FinAccountHelper.getAvailableBalance(cardNumber,
delegator);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -207,7 +207,7 @@
try {
refNum = GiftCertificateServices.createTransaction(delegator,
dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, deposit,
finAccountId);
- balance = FinAccountHelper.getAvailableBalance(cardNumber,
currencyUom, delegator);
+ balance = FinAccountHelper.getAvailableBalance(cardNumber,
delegator);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -263,7 +263,7 @@
// check the actual balance (excluding authorized amounts) and create
the transaction if it is sufficient
double previousBalance = 0.00;
try {
- previousBalance = FinAccountHelper.getBalance(cardNumber,
currencyUom, delegator).doubleValue();
+ previousBalance = FinAccountHelper.getBalance(cardNumber,
delegator).doubleValue();
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -276,7 +276,7 @@
try {
refNum = GiftCertificateServices.createTransaction(delegator,
dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, withdrawl,
cardNumber);
- balance = FinAccountHelper.getAvailableBalance(cardNumber,
currencyUom, delegator).doubleValue();
+ balance = FinAccountHelper.getAvailableBalance(cardNumber,
delegator).doubleValue();
procResult = Boolean.TRUE;
} catch (GeneralException e) {
Debug.logError(e, module);
@@ -314,7 +314,7 @@
// get the balance
double balance = 0.00;
try {
- balance = FinAccountHelper.getAvailableBalance(cardNumber,
currencyUom, delegator).doubleValue();
+ balance = FinAccountHelper.getAvailableBalance(cardNumber,
delegator).doubleValue();
} catch (GeneralException e) {
return ServiceUtil.returnError(e.getMessage());
}
@@ -455,7 +455,7 @@
}
// check the amount to authorize against the available balance of
fin account, which includes active authorizations as well as transactions
- BigDecimal availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, currency, delegator);
+ BigDecimal availableBalance =
FinAccountHelper.getAvailableBalance(finAccountId, delegator);
Boolean processResult = null;
String refNum = null;
Map result = ServiceUtil.returnSuccess();
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
Mon Mar 26 23:14:11 2007
@@ -484,6 +484,7 @@
result.put("refundFlag", parameters.get("RESULT"));
result.put("refundMessage", parameters.get("RESPMSG"));
}
+
private static String parseContext(Map context) {
StringBuffer buf = new StringBuffer();
Set keySet = context.keySet();
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java
Mon Mar 26 23:14:11 2007
@@ -168,16 +168,18 @@
/**
* Sum of all DEPOSIT and ADJUSTMENT transactions minus all WITHDRAWAL
transactions whose transactionDate is before asOfDateTime
- * @param finAccountId
- * @param currencyUomId
+ * @param finAccountId
* @param asOfDateTime
* @param delegator
* @return
* @throws GenericEntityException
*/
- public static BigDecimal getBalance(String finAccountId, String
currencyUomId, Timestamp asOfDateTime, GenericDelegator delegator) throws
GenericEntityException {
+ public static BigDecimal getBalance(String finAccountId, Timestamp
asOfDateTime, GenericDelegator delegator) throws GenericEntityException {
BigDecimal incrementTotal = ZERO; // total amount of transactions
which increase balance
BigDecimal decrementTotal = ZERO; // decrease balance
+
+ GenericValue finAccount =
delegator.findByPrimaryKeyCache("FinAccount", UtilMisc.toMap("finAccountId",
finAccountId));
+ String currencyUomId = finAccount.getString("currencyUomId");
// find the sum of all transactions which increase the value
EntityConditionList incrementConditions = new
EntityConditionList(UtilMisc.toList(
@@ -209,32 +211,29 @@
/**
* Same as above for the current instant
* @param finAccountId
- * @param currencyUomId
* @param delegator
* @return
* @throws GenericEntityException
*/
- public static BigDecimal getBalance(String finAccountId, String
currencyUomId, GenericDelegator delegator) throws GenericEntityException {
- return getBalance(finAccountId, currencyUomId,
UtilDateTime.nowTimestamp(), delegator);
+ public static BigDecimal getBalance(String finAccountId, GenericDelegator
delegator) throws GenericEntityException {
+ return getBalance(finAccountId, UtilDateTime.nowTimestamp(),
delegator);
}
/**
* Returns the net balance (see above) minus the sum of all authorization
amounts which are not expired and were authorized by the as of date
* @param finAccountId
- * @param currencyUomId
* @param asOfDateTime
* @param delegator
* @return
* @throws GenericEntityException
*/
- public static BigDecimal getAvailableBalance(String finAccountId, String
currencyUomId, Timestamp asOfDateTime, GenericDelegator delegator) throws
GenericEntityException {
- BigDecimal netBalance = getBalance(finAccountId, currencyUomId,
asOfDateTime, delegator);
+ public static BigDecimal getAvailableBalance(String finAccountId,
Timestamp asOfDateTime, GenericDelegator delegator) throws
GenericEntityException {
+ BigDecimal netBalance = getBalance(finAccountId, asOfDateTime,
delegator);
// find sum of all authorizations which are not expired and which
were authorized before as of time
EntityConditionList authorizationConditions = new
EntityConditionList(UtilMisc.toList(
new EntityExpr("finAccountId", EntityOperator.EQUALS,
finAccountId),
new EntityExpr("authorizationDate",
EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime),
- new EntityExpr("currencyUomId", EntityOperator.EQUALS,
currencyUomId),
EntityUtil.getFilterByDateExpr(asOfDateTime)),
EntityOperator.AND);
@@ -249,13 +248,12 @@
/**
* Same as above for the current instant
* @param finAccountId
- * @param currencyUomId
* @param delegator
* @return
* @throws GenericEntityException
*/
- public static BigDecimal getAvailableBalance(String finAccountId, String
currencyUomId, GenericDelegator delegator) throws GenericEntityException {
- return getAvailableBalance(finAccountId, currencyUomId,
UtilDateTime.nowTimestamp(), delegator);
+ public static BigDecimal getAvailableBalance(String finAccountId,
GenericDelegator delegator) throws GenericEntityException {
+ return getAvailableBalance(finAccountId, UtilDateTime.nowTimestamp(),
delegator);
}
public static boolean validateFinAccount(GenericValue finAccount) {
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?view=diff&rev=522769&r1=522768&r2=522769
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
Mon Mar 26 23:14:11 2007
@@ -416,8 +416,8 @@
errMsg =
UtilProperties.getMessage(resource,"checkhelper.gift_card_does_not_exist",
(cart != null ? cart.getLocale() : Locale.getDefault()));
errorMessages.add(errMsg);
gcFieldsOkay = false;
- } else if
((FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"),
cart.getCurrency(), delegator) == null) ||
-
!(FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"),
cart.getCurrency(), delegator).compareTo(FinAccountHelper.ZERO) == 1)) {
+ } else if
((FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"),
delegator) == null) ||
+
!(FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"),
delegator).compareTo(FinAccountHelper.ZERO) == 1)) {
// if account's available balance (including
authorizations) is not greater than zero, then return an error
errMsg =
UtilProperties.getMessage(resource,"checkhelper.gift_card_has_no_value", (cart
!= null ? cart.getLocale() : Locale.getDefault()));
errorMessages.add(errMsg);