Author: jaz
Date: Tue Mar 27 10:04:07 2007 New Revision: 522998 URL: http://svn.apache.org/viewvc?view=rev&rev=522998 Log: auto-replenish now working, capture now allows going negative Modified: ofbiz/trunk/applications/accounting/servicedef/secas.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/FinAccountServices.java Modified: ofbiz/trunk/applications/accounting/servicedef/secas.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas.xml?view=diff&rev=522998&r1=522997&r2=522998 ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/secas.xml Tue Mar 27 10:04:07 2007 @@ -105,12 +105,10 @@ </eca> <!-- financial account transaction ecas --> - <!-- <eca service="finAccountWithdraw" event="return"> <condition field-name="productStoreId" operator="is-not-empty"/> <action service="finAccountReplenish" mode="async" run-as-user="system"/> - </eca> - --> + </eca> <eca service="finAccountWithdraw" event="commit"> <action service="checkFinAccountStatus" mode="sync" run-as-user="system"/> </eca> @@ -118,12 +116,15 @@ <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"/> + <action service="checkFinAccountStatus" mode="sync" run-as-user="system"/> </eca> <!-- sample ECA rules for the sampleInvoiceAffiliateCommission service triggering 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=522998&r1=522997&r2=522998 ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml Tue Mar 27 10:04:07 2007 @@ -136,6 +136,7 @@ <description>Deposit Funds into a Financial Account</description> <attribute name="finAccountId" type="String" mode="IN" optional="false"/> <attribute name="productStoreId" type="String" mode="IN" optional="true"/> + <attribute name="requireBalance" type="Boolean" mode="IN" optional="true"/> <attribute name="currency" type="String" mode="IN" optional="true"/> <attribute name="partyId" type="String" mode="IN" optional="true"/> <attribute name="amount" type="Double" mode="INOUT" optional="false"/> @@ -156,6 +157,7 @@ <attribute name="finAccountId" type="String" mode="IN" optional="false"/> <attribute name="availableBalance" type="Double" mode="OUT" optional="false"/> <attribute name="balance" type="Double" mode="OUT" optional="false"/> + <attribute name="isFrozen" type="Boolean" mode="OUT" optional="false"/> </service> <service name="checkFinAccountStatus" engine="java" location="org.ofbiz.accounting.finaccount.FinAccountServices" invoke="checkFinAccountStatus" auth="true"> 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=522998&r1=522997&r2=522998 ============================================================================== --- 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 10:04:07 2007 @@ -57,16 +57,9 @@ String finAccountCode = (String) context.get("finAccountCode"); String finAccountPin = (String) context.get("finAccountPin"); String finAccountId = (String) context.get("finAccountId"); - - String currency = (String) context.get("currency"); String orderId = (String) context.get("orderId"); Double amount = (Double) context.get("processAmount"); - // make sure we have a currency - if (currency == null) { - currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD"); - } - // check for an existing auth trans and cancel it GenericValue authTrans = PaymentGatewayServices.getAuthTransaction(paymentPref); if (authTrans != null) { @@ -173,6 +166,7 @@ // mark the account as frozen if we have gone negative BigDecimal newBalance = FinAccountHelper.getAvailableBalance(finAccountId, delegator); if (newBalance.compareTo(FinAccountHelper.ZERO) == -1) { + Debug.logInfo("Financal account [" + finAccountId + "] now frozen: " + newBalance, module); finAccount.set("isFrozen", "Y"); try { finAccount.store(); @@ -312,6 +306,7 @@ withdrawCtx.put("currency", currency); withdrawCtx.put("partyId", partyId); withdrawCtx.put("amount", amount); + withdrawCtx.put("requireBalance", Boolean.FALSE); // for captures; if auth passed, allow withdrawCtx.put("userLogin", userLogin); // call the withdraw service @@ -421,7 +416,9 @@ GenericValue userLogin = (GenericValue) context.get("userLogin"); String productStoreId = (String) context.get("productStoreId"); String finAccountId = (String) context.get("finAccountId"); + Boolean requireBalance = (Boolean) context.get("requireBalance"); Double amount = (Double) context.get("amount"); + if (requireBalance == null) requireBalance = Boolean.TRUE; final String WITHDRAWAL = "WITHDRAWAL"; @@ -469,7 +466,11 @@ BigDecimal balance; String refNum; Boolean procResult; - if (previousBalance.doubleValue() >= amount.doubleValue()) { + if (requireBalance.booleanValue() && previousBalance.doubleValue() < amount.doubleValue()) { + procResult = Boolean.FALSE; + balance = previousBalance; + refNum = "N/A"; + } else { try { refNum = FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator, dispatcher, userLogin, amount, productStoreId, partyId, currencyUom, WITHDRAWAL, finAccountId); @@ -479,10 +480,6 @@ Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } - } else { - procResult = Boolean.FALSE; - balance = previousBalance; - refNum = "N/A"; } Map result = ServiceUtil.returnSuccess(); @@ -601,6 +598,27 @@ return ServiceUtil.returnSuccess(); } + // get the product store settings + GenericValue finAccountSettings; + try { + finAccountSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", + UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", + finAccount.getString("finAccountTypeId"))); + } catch (GenericEntityException e) { + Debug.logError(e, module); + return ServiceUtil.returnError(e.getMessage()); + } + if (finAccountSettings == null) { + // no settings; don't replenish + return ServiceUtil.returnSuccess(); + } + + Double replThres = finAccountSettings.getDouble("replenishThreshold"); + if (replThres == null) { + return ServiceUtil.returnSuccess(); + } + BigDecimal replenishThreshold = new BigDecimal(replThres.doubleValue()); + BigDecimal replenishLevel = finAccount.getBigDecimal("replenishLevel"); if (replenishLevel == null || replenishLevel.compareTo(FinAccountHelper.ZERO) == 0) { // no replenish level set; this account goes not support auto-replenish @@ -616,30 +634,27 @@ return ServiceUtil.returnError(e.getMessage()); } + // see if we are within the threshold for replenishment + if (balance.compareTo(replenishThreshold) > -1) { + // not ready + return ServiceUtil.returnSuccess(); + } + // the deposit is level - balance (500 - (-10) = 510 || 500 - (10) = 490) BigDecimal depositAmount = replenishLevel.subtract(balance); - // find the owner party - List finAcctOwners; - try { - finAcctOwners = delegator.findByAnd("FinAccountRole", UtilMisc.toMap("finAccountId", finAccountId, "roleTypeId", "OWNER"), UtilMisc.toList("-fromDate")); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); - } - finAcctOwners = EntityUtil.filterByDate(finAcctOwners); - GenericValue finAccountOwner = EntityUtil.getFirst(finAcctOwners); - if (finAccountOwner == null) { + // get the owner party + String ownerPartyId = finAccount.getString("ownerPartyId"); + if (ownerPartyId == null) { // no owner cannot replenish; (not fatal, just not supported by this account) Debug.logWarning("No owner attached to financial account [" + finAccountId + "] cannot auto-replenish", module); return ServiceUtil.returnSuccess(); } - String partyId = finAccountOwner.getString("partyId"); // determine the payment method to use to replenish List paymentMethods; try { - paymentMethods = delegator.findByAnd("PaymentMethod", UtilMisc.toMap("partyId", partyId), UtilMisc.toList("-fromDate")); + paymentMethods = delegator.findByAnd("PaymentMethod", UtilMisc.toMap("partyId", ownerPartyId), UtilMisc.toList("-fromDate")); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -648,7 +663,7 @@ GenericValue paymentMethod = EntityUtil.getFirst(paymentMethods); if (paymentMethod == null) { // no payment methods on file; cannot replenish - Debug.logWarning("No payment methods attached to party [" + partyId + "] cannot auto-replenish", module); + Debug.logWarning("No payment methods attached to party [" + ownerPartyId + "] cannot auto-replenish", module); return ServiceUtil.returnSuccess(); } @@ -662,12 +677,12 @@ } // hit the payment method for the amount to replenish - Map orderItemMap = UtilMisc.toMap("Auto-Replenishment", new Double(depositAmount.doubleValue())); + Map orderItemMap = UtilMisc.toMap("Auto-Replenishment FA #" + finAccountId, new Double(depositAmount.doubleValue())); Map replOrderCtx = FastMap.newInstance(); replOrderCtx.put("productStoreId", productStoreId); replOrderCtx.put("paymentMethodId", paymentMethod.getString("paymentMethodId")); replOrderCtx.put("currency", currency); - replOrderCtx.put("partyId", partyId); + replOrderCtx.put("partyId", ownerPartyId); replOrderCtx.put("itemMap", orderItemMap); replOrderCtx.put("userLogin", userLogin); Map replResp; @@ -686,7 +701,7 @@ depositCtx.put("productStoreId", productStoreId); depositCtx.put("finAccountId", finAccountId); depositCtx.put("currency", currency); - depositCtx.put("partyId", partyId); + depositCtx.put("partyId", ownerPartyId); depositCtx.put("amount", new Double(depositAmount.doubleValue())); depositCtx.put("userLogin", userLogin); Map depositResp; 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=522998&r1=522997&r2=522998 ============================================================================== --- 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 10:04:07 2007 @@ -136,11 +136,13 @@ return ServiceUtil.returnError(e.getMessage()); } - Debug.log("FinAccount Balance [" + balance + "] Available [" + availableBalance + "]", module); - + Debug.log("FinAccount Balance [" + balance + "] Available [" + availableBalance + "]", module); + Boolean isFrozen = Boolean.valueOf("Y".equals(finAccount.getString("isFrozen"))); + Map result = ServiceUtil.returnSuccess(); result.put("availableBalance", new Double(availableBalance.doubleValue())); result.put("balance", new Double(balance.doubleValue())); + result.put("isFrozen", isFrozen); return result; } @@ -183,12 +185,12 @@ return ServiceUtil.returnError(e.getMessage()); } - if ("N".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) == -1) { + if ("N".equals(frozen) && balance.compareTo(FinAccountHelper.ZERO) < 1) { finAccount.set("isFrozen", "Y"); - Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [Frozen]", module); + 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 make current [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 |