Author: sichen
Date: Thu Jul 27 12:24:35 2006 New Revision: 426204 URL: http://svn.apache.org/viewvc?rev=426204&view=rev Log: Reorganized method for getting balance of billing account and imposed a limit of BillingAccount.accountLimit on the balance. See comments in code. Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java?rev=426204&r1=426203&r2=426204&view=diff ============================================================================== --- incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java (original) +++ incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/BillingAccountWorker.java Thu Jul 27 12:24:35 2006 @@ -116,20 +116,19 @@ return billingAccountList; } - public static BigDecimal getBillingAccountBalance(GenericValue billingAccount) throws GenericEntityException { - return getBillingAccountBalance(billingAccount.getDelegator(), billingAccount.getString("billingAccountId")); - } - /** - * Calculates the "available" balance of a billing account, which is net balance minus amount of pending (not canceled, rejected, or completed) orders. When looking at - * using a billing account for a new order, you should use this method + * Calculates the "available" balance of a billing account, which is net balance minus amount of pending (not canceled, rejected, or completed) orders. + * Available balance will not exceed billing account's accountLimit. + * When looking at using a billing account for a new order, you should use this method. * @param delegator * @param billingAccountId * @return * @throws GenericEntityException */ - - public static BigDecimal getBillingAccountBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException { + public static BigDecimal getBillingAccountBalance(GenericValue billingAccount) throws GenericEntityException { + GenericDelegator delegator = billingAccount.getDelegator(); + String billingAccountId = billingAccount.getString("billingAccountId"); + // first get the net balance of invoices - payments BigDecimal balance = getBillingAccountNetBalance(delegator, billingAccountId); @@ -151,9 +150,22 @@ balance = balance.add(orh.getOrderGrandTotalBd()); } } - - balance = balance.setScale(decimals, rounding); + + // set the balance to BillingAccount.accountLimit if it is greater. This is necessary because nowhere do we track the amount of BillingAccount + // to be charged to an order, such as FinAccountAuth entity does for FinAccount. As a result, we must assume that the system is doing things correctly + // and use the accountLimit + BigDecimal accountLimit = new BigDecimal(billingAccount.getDouble("accountLimit").doubleValue()); + if (balance.compareTo(accountLimit) == 1) { + balance = accountLimit; + } else { + balance = balance.setScale(decimals, rounding); + } return balance; + } + + public static BigDecimal getBillingAccountBalance(GenericDelegator delegator, String billingAccountId) throws GenericEntityException { + GenericValue billingAccount = delegator.findByPrimaryKey("BillingAccount", UtilMisc.toMap("billingAccountId", billingAccountId)); + return getBillingAccountBalance(billingAccount); } /** Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=426204&r1=426203&r2=426204&view=diff ============================================================================== --- incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original) +++ incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Thu Jul 27 12:24:35 2006 @@ -844,7 +844,7 @@ } if (billingAccountInfo != null) { billingAccount = (GenericValue) billingAccountInfo.get("billingAccount"); - // use net account balance because we want to know how much we can charge to a billing account + // use available to capture because we want to know how much we can charge to a billing account Double availableToCapture = (Double) billingAccountInfo.get("availableToCapture"); billingAccountAvail = new BigDecimal(availableToCapture.doubleValue()); } |
Free forum by Nabble | Edit this page |