You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/04/26 01:58:09 UTC
svn commit: r532542 - in /ofbiz/trunk/applications/accounting:
script/org/ofbiz/accounting/finaccount/FinAccountServices.xml
servicedef/services_finaccount.xml
src/org/ofbiz/accounting/finaccount/FinAccountServices.java
Author: jaz
Date: Wed Apr 25 16:58:09 2007
New Revision: 532542
URL: http://svn.apache.org/viewvc?view=rev&rev=532542
Log:
applied patch from Joe Eckard for JIRA Issue OFBIZ-928 (service credit implementation)
Modified:
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/finaccount/FinAccountServices.xml
ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/finaccount/FinAccountServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/finaccount/FinAccountServices.xml?view=diff&rev=532542&r1=532541&r2=532542
==============================================================================
--- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/finaccount/FinAccountServices.xml (original)
+++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/finaccount/FinAccountServices.xml Wed Apr 25 16:58:09 2007
@@ -32,6 +32,13 @@
<set from-field="finAccountId" field="newEntity.finAccountId"/>
</if-empty>
+ <!-- set the currency if none is already set -->
+ <if-empty field-name="newEntity.currencyUomId">
+
+ <property-to-field resource="general" property="currency.uom.id.default" field-name="defaultCurrency"/>
+ <set field="newEntity.currencyUomId" from-field="defaultCurrency"/>
+ </if-empty>
+
<!-- set the refundable flag from the type; if not set -->
<if-empty field-name="newEntity.isRefundable">
<entity-one entity-name="FinAccountType" value-name="finAccountType">
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=532542&r1=532541&r2=532542
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_finaccount.xml Wed Apr 25 16:58:09 2007
@@ -176,7 +176,17 @@
<attribute name="finAccountAuthId" type="String" mode="IN" optional="true"/>
<attribute name="finAccountId" type="String" mode="IN" optional="true"/>
</service>
-
+
+ <!-- service credit account w/ transaction -->
+ <service name="createServiceCredit" engine="java"
+ location="org.ofbiz.accounting.finaccount.FinAccountServices" invoke="createServiceCredit" auth="true">
+ <attribute name="finAccountId" type="String" mode="INOUT" optional="true"/>
+ <attribute name="partyId" type="String" mode="IN" optional="false"/>
+ <attribute name="amount" type="Double" mode="IN" optional="false"/>
+ <attribute name="currencyUomId" type="String" mode="IN" optional="true"/>
+ <attribute name="productStoreId" type="String" mode="IN" optional="true"/>
+ </service>
+
<!-- balance account created from product purchase -->
<service name="createPartyFinAccountFromPurchase" engine="java"
location="org.ofbiz.accounting.finaccount.FinAccountProductServices" invoke="createPartyFinAccountFromPurchase" auth="true">
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=532542&r1=532541&r2=532542
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java Wed Apr 25 16:58:09 2007
@@ -32,6 +32,7 @@
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
@@ -45,7 +46,89 @@
public class FinAccountServices {
public static final String module = FinAccountServices.class.getName();
-
+
+ public static Map createServiceCredit(DispatchContext dctx, Map context) {
+ GenericDelegator delegator = dctx.getDelegator();
+ LocalDispatcher dispatcher = dctx.getDispatcher();
+ String finAccountId = (String) context.get("finAccountId");
+
+ GenericValue userLogin = (GenericValue) context.get("userLogin");
+ try {
+ // find the most recent (active) service credit account for the specified party
+ String partyId = (String) context.get("partyId");
+ Map lookupMap = UtilMisc.toMap("finAccountTypeId", "SVCCRED_ACCOUNT", "ownerPartyId", partyId);
+
+ // if a productStoreId is present, restrict the accounts returned using the store's payToPartyId
+ String productStoreId = (String) context.get("productStoreId");
+ if (UtilValidate.isNotEmpty(productStoreId)) {
+ String payToPartyId = ProductStoreWorker.getProductStorePayToPartyId(productStoreId, delegator);
+ if (UtilValidate.isNotEmpty(payToPartyId)) {
+ lookupMap.put("organizationPartyId", payToPartyId);
+ }
+ }
+
+ // if a currencyUomId is present, use it to restrict the accounts returned
+ String currencyUomId = (String) context.get("currencyUomId");
+ if (UtilValidate.isNotEmpty(currencyUomId)) {
+ lookupMap.put("currencyUomId", currencyUomId);
+ }
+
+ // check for an existing account
+ GenericValue creditAccount;
+ if (finAccountId != null) {
+ creditAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccoutId", finAccountId));
+ } else {
+ List creditAccounts = delegator.findByAnd("FinAccount", lookupMap, UtilMisc.toList("-fromDate"));
+ creditAccount = EntityUtil.getFirst(EntityUtil.filterByDate(creditAccounts));
+ }
+
+ if (creditAccount == null) {
+ // create a new service credit account
+ String createAccountServiceName = "createFinAccount";
+ if (UtilValidate.isNotEmpty(productStoreId)) {
+ createAccountServiceName = "createFinAccountForStore";
+ }
+ // automatically set the parameters
+ ModelService createAccountService = dctx.getModelService(createAccountServiceName);
+ Map createAccountContext = createAccountService.makeValid(context, ModelService.IN_PARAM);
+ createAccountContext.put("finAccountTypeId", "SVCCRED_ACCOUNT");
+ createAccountContext.put("finAccountName", "Customer Service Credit Account");
+ createAccountContext.put("ownerPartyId", partyId);
+ createAccountContext.put("userLogin", userLogin);
+
+ Map createAccountResult = dispatcher.runSync(createAccountServiceName, createAccountContext);
+ if (ServiceUtil.isError(createAccountResult) || ServiceUtil.isFailure(createAccountResult)) {
+ return createAccountResult;
+ }
+
+ if (createAccountResult != null) {
+ String creditAccountId = (String) createAccountResult.get("finAccountId");
+ if (UtilValidate.isNotEmpty(creditAccountId)) {
+ creditAccount = delegator.findByPrimaryKey("FinAccount", UtilMisc.toMap("finAccountId", creditAccountId));
+
+ }
+ }
+ if (creditAccount == null) {
+ return ServiceUtil.returnError("Could not find or create a service credit account");
+ }
+ }
+
+ // create the credit transaction
+ Map creditTransResult = dispatcher.runSync("createFinAccountTrans",
+ UtilMisc.toMap("finAccountTransTypeId", "ADJUSTMENT", "finAccountId", creditAccount.getString("finAccountId"),
+ "partyId", partyId, "amount", context.get("amount"), "userLogin", userLogin));
+ if (ServiceUtil.isError(creditTransResult) || ServiceUtil.isFailure(creditTransResult)) {
+ return creditTransResult;
+ }
+ } catch (GenericEntityException gee) {
+ return ServiceUtil.returnError(gee.getMessage());
+ } catch (GenericServiceException gse) {
+ return ServiceUtil.returnError(gse.getMessage());
+ }
+
+ return ServiceUtil.returnSuccess();
+ }
+
public static Map createFinAccountForStore(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();