You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/03/28 03:17:00 UTC
svn commit: r523131 - in /ofbiz/trunk/applications:
accounting/src/org/ofbiz/accounting/finaccount/
accounting/src/org/ofbiz/accounting/payment/ accounting/widget/
order/src/org/ofbiz/order/finaccount/ order/src/org/ofbiz/order/shoppingcart/
Author: jonesde
Date: Tue Mar 27 18:17:00 2007
New Revision: 523131
URL: http://svn.apache.org/viewvc?view=rev&rev=523131
Log:
Changed code in a bunch of places to use the FinAccount.availableBalance and actualBalance fields; this involved removing the method in FinAccountHelper to get the available and actual balances without a date specified, ie the most current values
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.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/widget/FinAccountForms.xml
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/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=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java Tue Mar 27 18:17:00 2007
@@ -133,7 +133,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, delegator);
+ BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
Map result = ServiceUtil.returnSuccess();
Boolean processResult;
String refNum;
@@ -164,7 +164,8 @@
}
// mark the account as frozen if we have gone negative
- BigDecimal newBalance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
+ finAccount.refresh();
+ BigDecimal newBalance = finAccount.getBigDecimal("availableBalance");
if (newBalance.compareTo(FinAccountHelper.ZERO) == -1) {
Debug.logInfo("Financal account [" + finAccountId + "] now frozen: " + newBalance, module);
finAccount.set("isFrozen", "Y");
@@ -455,13 +456,7 @@
}
// check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
- BigDecimal previousBalance;
- try {
- previousBalance = FinAccountHelper.getBalance(finAccountId, delegator);
- } catch (GeneralException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- }
+ BigDecimal previousBalance = finAccount.getBigDecimal("actualBalance");
BigDecimal balance;
String refNum;
@@ -474,8 +469,9 @@
try {
refNum = FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator, dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, WITHDRAWAL, finAccountId);
- balance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
- procResult = Boolean.TRUE;
+ finAccount.refresh();
+ balance = finAccount.getBigDecimal("actualBalance");
+ procResult = Boolean.TRUE;
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -533,13 +529,7 @@
Debug.log("Deposit into financial account #" + finAccountId + " [" + amount + "]", module);
// get the previous balance
- BigDecimal previousBalance;
- try {
- previousBalance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
- } catch (GeneralException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- }
+ BigDecimal previousBalance = finAccount.getBigDecimal("actualBalance");
// create the transaction
BigDecimal balance;
@@ -547,7 +537,8 @@
try {
refNum = FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator, dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, DEPOSIT, finAccountId);
- balance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
+ finAccount.refresh();
+ balance = finAccount.getBigDecimal("actualBalance");
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -626,13 +617,7 @@
}
// get the current balance
- BigDecimal balance;
- try {
- balance = FinAccountHelper.getBalance(finAccountId, delegator);
- } catch (GenericEntityException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- }
+ BigDecimal balance = finAccount.getBigDecimal("actualBalance");
// see if we are within the threshold for replenishment
if (balance.compareTo(replenishThreshold) > -1) {
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=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java Tue Mar 27 18:17:00 2007
@@ -127,14 +127,8 @@
}
// get the balance
- BigDecimal availableBalance;
- BigDecimal balance;
- try {
- availableBalance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
- balance = FinAccountHelper.getBalance(finAccountId, delegator);
- } catch (GenericEntityException e) {
- return ServiceUtil.returnError(e.getMessage());
- }
+ BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
+ BigDecimal balance= finAccount.getBigDecimal("actualBalance");
Debug.log("FinAccount Balance [" + balance + "] Available [" + availableBalance + "]", module);
Boolean isFrozen = Boolean.valueOf("Y".equals(finAccount.getString("isFrozen")));
@@ -178,19 +172,14 @@
String frozen = finAccount.getString("isFrozen");
if (frozen == null) frozen = "N";
- BigDecimal balance;
- try {
- balance = FinAccountHelper.getAvailableBalance(finAccountId, delegator);
- } catch (GenericEntityException e) {
- return ServiceUtil.returnError(e.getMessage());
- }
+ BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
- if ("N".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) < 1) {
+ if ("N".equals(frozen) && FinAccountHelper.ZERO.compareTo(availableBalance) < 1) {
finAccount.set("isFrozen", "Y");
- Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + balance + "] (Frozen)", module);
- } else if ("Y".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) > 0) {
+ Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + availableBalance + "] (Frozen)", module);
+ } else if ("Y".equals(frozen) && FinAccountHelper.ZERO.compareTo(availableBalance) > 0) {
finAccount.set("isFrozen", "N");
- Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + balance + "] (Un-Frozen)", module);
+ Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + availableBalance + "] (Un-Frozen)", module);
}
try {
finAccount.store();
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=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Tue Mar 27 18:17:00 2007
@@ -170,35 +170,41 @@
}
String finAccountId = null;
+ GenericValue finAccount = null;
// validate the pin if the store requires it and figure out the finAccountId from card number
try {
GenericValue giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));
- if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
- if (!validatePin(delegator, cardNumber, pinNumber)) {
- return ServiceUtil.returnError("PIN number is not valid!");
- }
- finAccountId = cardNumber;
- } else {
- GenericValue finAccount = FinAccountHelper.getFinAccountFromCode(cardNumber, delegator);
- if (finAccount != null) {
- finAccountId = finAccount.getString("finAccountId");
- }
- }
- } catch (GenericEntityException ex) {
- return ServiceUtil.returnError("Cannot get store fin account settings " + ex.getMessage());
+ if ("Y".equals(giftCertSettings.getString("requirePinCode"))) {
+ if (!validatePin(delegator, cardNumber, pinNumber)) {
+ return ServiceUtil.returnError("PIN number is not valid!");
+ }
+ finAccountId = cardNumber;
+ } else {
+ finAccount = FinAccountHelper.getFinAccountFromCode(cardNumber, delegator);
+ if (finAccount != null) {
+ finAccountId = finAccount.getString("finAccountId");
+ }
+ }
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError("Cannot get store financial account settings " + e.getMessage());
}
if (finAccountId == null) {
return ServiceUtil.returnError("Cannot get fin account for adding to balance");
}
+
+ if (finAccount == null) {
+ try {
+ finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", finAccountId));
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
+ }
+ }
// get the previous balance
BigDecimal previousBalance = ZERO;
- try {
- previousBalance = FinAccountHelper.getAvailableBalance(cardNumber, delegator);
- } catch (GeneralException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
+ if (finAccount.get("availableBalance") != null) {
+ previousBalance = finAccount.getBigDecimal("availableBalance");
}
// create the transaction
@@ -207,7 +213,8 @@
try {
refNum = GiftCertificateServices.createTransaction(delegator, dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, deposit, finAccountId);
- balance = FinAccountHelper.getAvailableBalance(cardNumber, delegator);
+ finAccount.refresh();
+ balance = finAccount.getBigDecimal("availableBalance");
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -260,14 +267,15 @@
}
Debug.logInfo("Attempting to redeem GC for " + amount, module);
- // check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
- double previousBalance = 0.00;
+ GenericValue finAccount = null;
try {
- previousBalance = FinAccountHelper.getBalance(cardNumber, delegator).doubleValue();
- } catch (GeneralException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
+ finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", cardNumber));
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
}
+
+ // check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
+ double previousBalance = finAccount.get("actualBalance") == null ? 0.0 : finAccount.getDouble("actualBalance").doubleValue();
double balance = 0.00;
String refNum = null;
@@ -276,7 +284,8 @@
try {
refNum = GiftCertificateServices.createTransaction(delegator, dispatcher, userLogin, amount,
productStoreId, partyId, currencyUom, withdrawl, cardNumber);
- balance = FinAccountHelper.getAvailableBalance(cardNumber, delegator).doubleValue();
+ finAccount.refresh();
+ balance = finAccount.get("availableBalance") == null ? 0.0 : finAccount.getDouble("availableBalance").doubleValue();
procResult = Boolean.TRUE;
} catch (GeneralException e) {
Debug.logError(e, module);
@@ -309,15 +318,17 @@
return ServiceUtil.returnError("PIN number is not valid!");
}
- // TODO: get the real currency from context
- String currencyUom = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
- // get the balance
- double balance = 0.00;
+ GenericValue finAccount = null;
try {
- balance = FinAccountHelper.getAvailableBalance(cardNumber, delegator).doubleValue();
- } catch (GeneralException e) {
- return ServiceUtil.returnError(e.getMessage());
+ finAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", cardNumber));
+ } catch (GenericEntityException e) {
+ return ServiceUtil.returnError("Cannot get financial account settings " + e.getMessage());
}
+
+ // TODO: get the real currency from context
+ //String currencyUom = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
+ // get the balance
+ double balance = finAccount.get("availableBalance") == null ? 0.0 : finAccount.getDouble("availableBalance").doubleValue();
Map result = ServiceUtil.returnSuccess();
result.put("balance", new Double(balance));
@@ -455,7 +466,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, delegator);
+ BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
Boolean processResult = null;
String refNum = null;
Map result = ServiceUtil.returnSuccess();
Modified: ofbiz/trunk/applications/accounting/widget/FinAccountForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/FinAccountForms.xml?view=diff&rev=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/FinAccountForms.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/FinAccountForms.xml Tue Mar 27 18:17:00 2007
@@ -45,15 +45,11 @@
<field-map field-name="orderBy" value="fromDate"/>
</service>
</actions>
+ <auto-fields-entity entity-name="FinAccount" default-field-type="display"/>
<field name="finAccountId"> <hyperlink description="${finAccountId}" target="EditFinAccount?finAccountId=${finAccountId}"/> </field>
<field name="finAccountTypeId"><display-entity entity-name="FinAccountType" description="${description}"/></field>
- <field name="finAccountName"><display/></field>
- <field name="finAccountCode"><display/></field>
- <field name="fromdate"><display/></field>
- <field name="thrudate"><display/></field>
<field name="deleteLink" title="" widget-style="buttontext">
- <hyperlink target="deleteFinAccount?finAccountId=${finAccountId}"
- description="${uiLabelMap.CommonDelete}" also-hidden="false"/>
+ <hyperlink target="deleteFinAccount?finAccountId=${finAccountId}" description="${uiLabelMap.CommonDelete}" also-hidden="false"/>
</field>
</form>
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=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java Tue Mar 27 18:17:00 2007
@@ -175,6 +175,8 @@
* @throws GenericEntityException
*/
public static BigDecimal getBalance(String finAccountId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException {
+ if (asOfDateTime == null) asOfDateTime = UtilDateTime.nowTimestamp();
+
BigDecimal incrementTotal = ZERO; // total amount of transactions which increase balance
BigDecimal decrementTotal = ZERO; // decrease balance
@@ -209,17 +211,6 @@
}
/**
- * Same as above for the current instant
- * @param finAccountId
- * @param delegator
- * @return
- * @throws GenericEntityException
- */
- 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 asOfDateTime
@@ -228,6 +219,8 @@
* @throws GenericEntityException
*/
public static BigDecimal getAvailableBalance(String finAccountId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException {
+ if (asOfDateTime == null) asOfDateTime = UtilDateTime.nowTimestamp();
+
BigDecimal netBalance = getBalance(finAccountId, asOfDateTime, delegator);
// find sum of all authorizations which are not expired and which were authorized before as of time
@@ -244,17 +237,6 @@
// the total available balance is transactions total minus authorizations total
return netBalance.subtract(authorizationsTotal).setScale(decimals, rounding);
}
-
- /**
- * Same as above for the current instant
- * @param finAccountId
- * @param delegator
- * @return
- * @throws GenericEntityException
- */
- public static BigDecimal getAvailableBalance(String finAccountId, GenericDelegator delegator) throws GenericEntityException {
- return getAvailableBalance(finAccountId, UtilDateTime.nowTimestamp(), delegator);
- }
public static boolean validateFinAccount(GenericValue finAccount) {
return false;
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=523131&r1=523130&r2=523131
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Tue Mar 27 18:17:00 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"), delegator) == null) ||
- !(FinAccountHelper.getAvailableBalance(finAccount.getString("finAccountId"), delegator).compareTo(FinAccountHelper.ZERO) == 1)) {
+ } else if ((finAccount.getBigDecimal("availableBalance") == null) ||
+ !((finAccount.getBigDecimal("availableBalance")).compareTo(FinAccountHelper.ZERO) > 0)) {
// 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);