Author: jaz
Date: Wed Mar 28 15:34:35 2007 New Revision: 523483 URL: http://svn.apache.org/viewvc?view=rev&rev=523483 Log: fixed financount status service, now does the right compareTo; removed code to mark frozen accounts in auth, now accounts are only frozen during withdraws (not auths) and moved the trigger to the eeca Modified: ofbiz/trunk/applications/accounting/entitydef/eecas.xml ofbiz/trunk/applications/accounting/servicedef/secas.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 Modified: ofbiz/trunk/applications/accounting/entitydef/eecas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/eecas.xml?view=diff&rev=523483&r1=523482&r2=523483 ============================================================================== --- ofbiz/trunk/applications/accounting/entitydef/eecas.xml (original) +++ ofbiz/trunk/applications/accounting/entitydef/eecas.xml Wed Mar 28 15:34:35 2007 @@ -24,6 +24,7 @@ <!-- To maintain FinAccount.actualBalance and FinAccount.availableBalance --> <eca entity="FinAccountTrans" operation="create-store" event="return"> <action service="updateFinAccountBalancesFromTrans" mode="sync"/> + <action service="checkFinAccountStatus" mode="sync"/> </eca> <!-- To maintain FinAccount.availableBalance --> <eca entity="FinAccountAuth" operation="create-store" event="return"> Modified: ofbiz/trunk/applications/accounting/servicedef/secas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas.xml?view=diff&rev=523483&r1=523482&r2=523483 ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/secas.xml Wed Mar 28 15:34:35 2007 @@ -109,24 +109,13 @@ <condition field-name="productStoreId" operator="is-not-empty"/> <action service="finAccountReplenish" mode="async" run-as-user="system"/> </eca> - <eca service="finAccountWithdraw" event="commit"> - <action service="checkFinAccountStatus" mode="sync" run-as-user="system"/> - </eca> - <eca service="finAccountDeposit" event="commit"> - <action service="checkFinAccountStatus" mode="sync" run-as-user="system"/> - </eca> - + <!-- <eca service="createFinAccountTrans" event="commit"> <action service="postFinAccountTransToGl" mode="sync"/> </eca> --> - <!-- financial account AUTH ecas --> - <eca service="expireFinAccountAuth" event="commit"> - <action service="checkFinAccountStatus" mode="sync" run-as-user="system"/> - </eca> - <!-- sample ECA rules for the sampleInvoiceAffiliateCommission service triggering <eca service="createPayment" event="commit"> <condition field-name="statusId" operator="equals" value="PMNT_RECEIVED"/> 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=523483&r1=523482&r2=523483 ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountPaymentServices.java Wed Mar 28 15:34:35 2007 @@ -158,6 +158,10 @@ // check the amount to authorize against the available balance of fin account, which includes active authorizations as well as transactions BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance"); + if (availableBalance == null) { + availableBalance = FinAccountHelper.ZERO; + } + Map result = ServiceUtil.returnSuccess(); String authMessage = null; Boolean processResult; @@ -188,20 +192,8 @@ processResult = Boolean.TRUE; } - // mark the account as frozen if we have gone negative + // refresh the account 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"); - try { - finAccount.store(); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); - } - } - } else { Debug.logError("Attempted to authorize [" + amount + "] against a balance of only [" + availableBalance + "]", module); refNum = "0"; // a refNum is always required from authorization 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=523483&r1=523482&r2=523483 ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountProductServices.java Wed Mar 28 15:34:35 2007 @@ -138,6 +138,7 @@ createCtx.put("productStoreId", productStoreId); createCtx.put("ownerPartyId", partyId); createCtx.put("currencyUomId", currency); + createCtx.put("isFrozen", "N"); createCtx.put("userLogin", userLogin); // if we auto-replenish this type; set the level to the initial deposit 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=523483&r1=523482&r2=523483 ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java Wed Mar 28 15:34:35 2007 @@ -135,8 +135,8 @@ balance = FinAccountHelper.ZERO; } - Debug.log("FinAccount Balance [" + balance + "] Available [" + availableBalance + "]", module); Boolean isFrozen = Boolean.valueOf("Y".equals(finAccount.getString("isFrozen"))); + Debug.log("FinAccount Balance [" + balance + "] Available [" + availableBalance + "] - Frozen: " + isFrozen, module); Map result = ServiceUtil.returnSuccess(); result.put("availableBalance", new Double(availableBalance.doubleValue())); @@ -147,21 +147,8 @@ 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!"); } @@ -177,17 +164,19 @@ String frozen = finAccount.getString("isFrozen"); if (frozen == null) frozen = "N"; - BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance"); - if (availableBalance == null) { - availableBalance = FinAccountHelper.ZERO; + BigDecimal balance = finAccount.getBigDecimal("actualBalance"); + if (balance == null) { + balance = FinAccountHelper.ZERO; } - - if ("N".equals(frozen) && FinAccountHelper.ZERO.compareTo(availableBalance) < 1) { + + Debug.log("Account #" + finAccountId + " Balance: " + balance + " Frozen: " + frozen, module); + + if ("N".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) < 1) { finAccount.set("isFrozen", "Y"); - Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + availableBalance + "] (Frozen)", module); - } else if ("Y".equals(frozen) && FinAccountHelper.ZERO.compareTo(availableBalance) > 0) { + Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + balance + "] (Frozen)", module); + } else if ("Y".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) > 0) { finAccount.set("isFrozen", "N"); - Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + availableBalance + "] (Un-Frozen)", module); + Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + balance + "] (Un-Frozen)", module); } try { finAccount.store(); |
Free forum by Nabble | Edit this page |