1 18 19 package org.ofbiz.accounting.finaccount; 20 21 import java.sql.Timestamp ; 22 import java.util.Map ; 23 24 import org.ofbiz.base.util.Debug; 25 import org.ofbiz.base.util.UtilDateTime; 26 import org.ofbiz.base.util.UtilMisc; 27 import org.ofbiz.entity.GenericDelegator; 28 import org.ofbiz.entity.GenericEntityException; 29 import org.ofbiz.entity.GenericValue; 30 import org.ofbiz.service.DispatchContext; 31 import org.ofbiz.service.GenericServiceException; 32 import org.ofbiz.service.LocalDispatcher; 33 import org.ofbiz.service.ModelService; 34 import org.ofbiz.service.ServiceUtil; 35 36 import org.ofbiz.order.finaccount.FinAccountHelper; 37 38 public class FinAccountServices { 39 40 public static final String module = FinAccountServices.class.getName(); 41 42 public static Map createFinAccountForStore(DispatchContext dctx, Map context) { 43 GenericDelegator delegator = dctx.getDelegator(); 44 LocalDispatcher dispatcher = dctx.getDispatcher(); 45 GenericValue userLogin = (GenericValue) context.get("userLogin"); 46 String productStoreId = (String ) context.get("productStoreId"); 47 String finAccountTypeId = (String ) context.get("finAccountTypeId"); 48 49 try { 50 GenericValue productStoreFinAccountSetting = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId)); 52 if (productStoreFinAccountSetting == null) { 53 return ServiceUtil.returnError("No settings found for store [" + productStoreId + "] for fin account type [" + finAccountTypeId + "]"); 54 } 55 56 Long accountCodeLength = productStoreFinAccountSetting.getLong("accountCodeLength"); 57 Long accountValidDays = productStoreFinAccountSetting.getLong("accountValidDays"); 58 59 ModelService createService = dctx.getModelService("createFinAccount"); 61 Map inContext = createService.makeValid(context, "IN"); 62 Timestamp now = UtilDateTime.nowTimestamp(); 63 inContext.put("fromDate", now); 65 inContext.put("thruDate", UtilDateTime.getDayEnd(now, accountValidDays.intValue())); 66 String finAccountCode = FinAccountHelper.getNewFinAccountCode(accountCodeLength.intValue(), delegator); 67 inContext.put("finAccountCode", finAccountCode); 68 inContext.put("userLogin", userLogin); 69 Map createResult = dispatcher.runSync("createFinAccount", inContext); 70 71 if (ServiceUtil.isError(createResult)) { 72 return createResult; 73 } else { 74 Map result = ServiceUtil.returnSuccess(); 75 result.put("finAccountId", createResult.get("finAccountId")); 76 result.put("finAccountCode", finAccountCode); 77 return result; 78 } 79 } catch (GenericEntityException ex) { 80 return ServiceUtil.returnError(ex.getMessage()); 81 } catch (GenericServiceException ex) { 82 return ServiceUtil.returnError(ex.getMessage()); 83 } 84 85 } 86 } 87 | Popular Tags |