KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensourcestrategies > crmsfa > opportunities > OpportunitiesServices


1 /*
2  * Copyright (c) 2006 - 2007 Open Source Strategies, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the Honest Public License.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * Honest Public License for more details.
11  *
12  * You should have received a copy of the Honest Public License
13  * along with this program; if not, write to Funambol,
14  * 643 Bair Island Road, Suite 305 - Redwood City, CA 94063, USA
15  */

16
17 package com.opensourcestrategies.crmsfa.opportunities;
18
19 import java.util.Map JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.sql.Timestamp JavaDoc;
23
24 import javolution.util.FastMap;
25
26 import org.ofbiz.base.util.Debug;
27 import org.ofbiz.base.util.UtilMisc;
28 import org.ofbiz.base.util.UtilProperties;
29 import org.ofbiz.base.util.UtilDateTime;
30 import org.ofbiz.entity.GenericDelegator;
31 import org.ofbiz.entity.GenericEntityException;
32 import org.ofbiz.entity.GenericValue;
33 import org.ofbiz.entity.util.EntityUtil;
34 import org.ofbiz.service.DispatchContext;
35 import org.ofbiz.service.GenericServiceException;
36 import org.ofbiz.service.LocalDispatcher;
37 import org.ofbiz.service.ServiceUtil;
38 import org.ofbiz.security.Security;
39
40 import com.opensourcestrategies.crmsfa.party.PartyHelper;
41 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;
42 import com.opensourcestrategies.crmsfa.util.UtilCommon;
43 import com.opensourcestrategies.crmsfa.opportunities.UtilOpportunity;
44
45 /**
46  * Opportunities services. The service documentation is in services_opportunities.xml.
47  *
48  * @author <a HREF="mailto:leon@opensourcestrategies.com">Leon Torres</a>
49  */

50
51 public class OpportunitiesServices {
52
53     public static final String JavaDoc module = OpportunitiesServices.class.getName();
54
55     // TODO: the input for this service should be vastly simplified when AJAX autocomplete is finished: only input should be internalPartyId
56
public static Map JavaDoc createOpportunity(DispatchContext dctx, Map JavaDoc context) {
57         GenericDelegator delegator = dctx.getDelegator();
58         LocalDispatcher dispatcher = dctx.getDispatcher();
59         Security security = dctx.getSecurity();
60         GenericValue userLogin = (GenericValue) context.get("userLogin");
61         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
62
63         String JavaDoc internalPartyId = (String JavaDoc) context.get("internalPartyId");
64         String JavaDoc accountPartyId = (String JavaDoc) context.get("accountPartyId");
65         String JavaDoc contactPartyId = (String JavaDoc) context.get("contactPartyId");
66         String JavaDoc leadPartyId = (String JavaDoc) context.get("leadPartyId");
67
68         // if internal not supplied, then make sure either an account or lead is supplied, but not both
69
if (internalPartyId == null && ((accountPartyId == null && leadPartyId == null) || (accountPartyId != null && leadPartyId != null))) {
70             return UtilCommon.createAndLogServiceError("Please specify an account or a lead (not both).", "CrmErrorCreateOpportunityFail", locale, module);
71         }
72
73         // track which partyId we're using, the account or the lead
74
String JavaDoc partyId = null;
75         if (accountPartyId != null) partyId = accountPartyId;
76         if (leadPartyId != null) partyId = leadPartyId;
77         if (internalPartyId != null) partyId = internalPartyId;
78
79         // make sure userLogin has CRMSFA_OPP_CREATE permission for the account or lead
80
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_CREATE", userLogin, partyId)) {
81             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
82         }
83
84         try {
85             // set the accountPartyId or leadPartyId according to the role of internalPartyId
86
if (internalPartyId != null) {
87                 String JavaDoc roleTypeId = PartyHelper.getFirstValidInternalPartyRoleTypeId(internalPartyId, delegator);
88                 if ("ACCOUNT".equals(roleTypeId)) accountPartyId = internalPartyId;
89                 if ("PROSPECT".equals(roleTypeId)) leadPartyId = internalPartyId;
90             }
91
92             // make sure the lead is qualified if we're doing initial lead
93
if (leadPartyId != null) {
94                 GenericValue party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", leadPartyId));
95                 if (party == null) {
96                     return UtilCommon.createAndLogServiceError("Unknown lead ["+leadPartyId+"].", "CrmErrorPermissionDenied", locale, module);
97                 }
98                 if (!"PTYLEAD_QUALIFIED".equals(party.get("statusId"))) {
99                     return UtilCommon.createAndLogServiceError("Cannot create opportunities for unqualified lead ["
100                             +leadPartyId+"].", "CrmErrorPermissionDenied", locale, module);
101                 }
102             }
103
104             // set estimatedCloseDate to 23:59:59.999 so that it's at the end of the day
105
String JavaDoc estimatedCloseDateString = (String JavaDoc) context.get("estimatedCloseDate");
106             Timestamp JavaDoc estimatedCloseDate = Timestamp.valueOf(estimatedCloseDateString + " 23:59:59.999");
107
108             // create the opportunity
109
String JavaDoc salesOpportunityId = delegator.getNextSeqId("SalesOpportunity");
110             GenericValue opportunity = delegator.makeValue("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId));
111             opportunity.setNonPKFields(context);
112             opportunity.set("estimatedCloseDate", estimatedCloseDate);
113             opportunity.set("createdByUserLogin", userLogin.getString("userLoginId"));
114
115             // if an opportunityStageId is present, set the estimated probability to that of the related stage
116
String JavaDoc opportunityStageId = (String JavaDoc) context.get("opportunityStageId");
117             if (opportunityStageId != null) {
118                 GenericValue stage = opportunity.getRelatedOne("SalesOpportunityStage");
119                 opportunity.set("estimatedProbability", stage.getDouble("defaultProbability"));
120             }
121
122             // store it
123
opportunity.create();
124
125             // copy to history
126
UtilOpportunity.createSalesOpportunityHistory(opportunity, delegator, context);
127
128             // assign the initial account
129
if (accountPartyId != null) {
130                 Map JavaDoc serviceResults = dispatcher.runSync("crmsfa.assignOpportunityToAccount",
131                         UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "accountPartyId", accountPartyId, "userLogin", userLogin));
132                 if (ServiceUtil.isError(serviceResults)) {
133                     return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateOpportunityFail", locale, module);
134                 }
135             }
136
137             // assign the initial lead
138
if (leadPartyId != null) {
139                 Map JavaDoc serviceResults = dispatcher.runSync("crmsfa.assignOpportunityToLead",
140                         UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "leadPartyId", leadPartyId, "userLogin", userLogin));
141                 if (ServiceUtil.isError(serviceResults)) {
142                     return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateOpportunityFail", locale, module);
143                 }
144             }
145
146             // assign the initial contact, but only if account was specified
147
if (contactPartyId != null && accountPartyId != null) {
148                 Map JavaDoc serviceResults = dispatcher.runSync("crmsfa.addContactToOpportunity",
149                         UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "contactPartyId", contactPartyId, "userLogin", userLogin));
150                 if (ServiceUtil.isError(serviceResults)) {
151                     return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateOpportunityFail", locale, module);
152                 }
153             }
154
155             // update forecasts as the system user, so we can update all forecasts for all team members that need updating
156
GenericValue system = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
157             Map JavaDoc serviceResults = dispatcher.runSync("crmsfa.updateForecastsRelatedToOpportunity",
158                     UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "userLogin", system));
159             if (ServiceUtil.isError(serviceResults)) {
160                 return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateOpportunityFail", locale, module);
161             }
162
163             // return the resulting opportunity ID
164
Map JavaDoc results = ServiceUtil.returnSuccess();
165             results.put("salesOpportunityId", salesOpportunityId);
166             return results;
167         } catch (GenericServiceException e) {
168             return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateOpportunityFail", locale, module);
169         } catch (GenericEntityException e) {
170             return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateOpportunityFail", locale, module);
171         }
172     }
173
174     public static Map JavaDoc updateOpportunity(DispatchContext dctx, Map JavaDoc context) {
175         GenericDelegator delegator = dctx.getDelegator();
176         LocalDispatcher dispatcher = dctx.getDispatcher();
177         Security security = dctx.getSecurity();
178         GenericValue userLogin = (GenericValue) context.get("userLogin");
179         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
180
181         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
182
183         try {
184             GenericValue opportunity = delegator.findByPrimaryKey("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId));
185             if (opportunity == null) {
186                 return UtilCommon.createAndLogServiceError("CrmErrorUpdateOpportunityFail", locale, module);
187             }
188
189             // for security, we need to get the accountPartyId or leadPartyId for this opportunity
190
String JavaDoc partyId = UtilOpportunity.getOpportunityAccountOrLeadPartyId(opportunity);
191             
192             // make sure userLogin has CRMSFA_OPP_UPDATE permission for this account or lead
193
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_UPDATE", userLogin, partyId)) {
194                 return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
195             }
196
197             // get the new and old stages
198
String JavaDoc stageId = opportunity.getString("opportunityStageId");
199             String JavaDoc newStageId = (String JavaDoc) context.get("opportunityStageId");
200             if (stageId == null) stageId = "";
201             if (newStageId == null) newStageId = "";
202
203             // this is needed for updating forecasts
204
Timestamp JavaDoc previousEstimatedCloseDate = opportunity.getTimestamp("estimatedCloseDate");
205             
206             // update the fields
207
opportunity.setNonPKFields(context);
208
209             // set estimatedCloseDate to 23:59:59.999 so that it's at the end of the day
210
String JavaDoc estimatedCloseDateString = (String JavaDoc) context.get("estimatedCloseDate");
211             Timestamp JavaDoc estimatedCloseDate = Timestamp.valueOf(estimatedCloseDateString + " 23:59:59.999");
212             opportunity.set("estimatedCloseDate", estimatedCloseDate);
213
214             // if the stage changed, set the probability to the one of the stage
215
if (!stageId.equals(newStageId)) {
216                 opportunity.set("estimatedProbability", opportunity.getRelatedOne("SalesOpportunityStage").getDouble("defaultProbability"));
217             }
218
219             // store
220
opportunity.store();
221
222             // copy the _new_ opportunity into history
223
UtilOpportunity.createSalesOpportunityHistory(opportunity, delegator, context);
224
225             // update forecasts as the system user, so we can update all forecasts for all team members that need updating
226
GenericValue system = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
227             Map JavaDoc serviceResults = dispatcher.runSync("crmsfa.updateForecastsRelatedToOpportunity",
228                     UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "previousEstimatedCloseDate", previousEstimatedCloseDate,
229                             "changeNote", context.get("changeNote"), "userLogin", system));
230             if (ServiceUtil.isError(serviceResults)) {
231                 return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateOpportunityFail", locale, module);
232             }
233         } catch (GenericServiceException e) {
234             return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateOpportunityFail", locale, module);
235         } catch (GenericEntityException e) {
236             return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateOpportunityFail", locale, module);
237         }
238         return ServiceUtil.returnSuccess();
239     }
240
241     public static Map JavaDoc assignOpportunityToAccount(DispatchContext dctx, Map JavaDoc context) {
242         return assignOpportunityToPartyHelper(dctx, context, (String JavaDoc) context.get("accountPartyId"), "ACCOUNT", "CRMSFA_ACCOUNT");
243     }
244
245     public static Map JavaDoc assignOpportunityToLead(DispatchContext dctx, Map JavaDoc context) {
246         return assignOpportunityToPartyHelper(dctx, context, (String JavaDoc) context.get("leadPartyId"), "PROSPECT", "CRMSFA_LEAD");
247     }
248     
249     /** Helper method to assign an opportunity to an account/lead party */
250     private static Map JavaDoc assignOpportunityToPartyHelper(DispatchContext dctx, Map JavaDoc context, String JavaDoc partyId, String JavaDoc roleTypeId, String JavaDoc permissionId) {
251         GenericDelegator delegator = dctx.getDelegator();
252         LocalDispatcher dispatcher = dctx.getDispatcher();
253         Security security = dctx.getSecurity();
254         GenericValue userLogin = (GenericValue) context.get("userLogin");
255         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
256
257         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
258
259         // check if userLogin has update permission for this party
260
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, permissionId, "_UPDATE", userLogin, partyId)) {
261             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
262         }
263         try {
264             // create a SalesOpportunityRole with salesOpportunityId, partyId and roleTypeId
265
GenericValue role = delegator.makeValue("SalesOpportunityRole", UtilMisc.toMap("salesOpportunityId", salesOpportunityId,
266                         "partyId", partyId, "roleTypeId", roleTypeId));
267             role.create();
268         } catch (GenericEntityException e) {
269             return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);
270         }
271         return ServiceUtil.returnSuccess();
272     }
273
274     public static Map JavaDoc addContactToOpportunity(DispatchContext dctx, Map JavaDoc context) {
275         GenericDelegator delegator = dctx.getDelegator();
276         LocalDispatcher dispatcher = dctx.getDispatcher();
277         Security security = dctx.getSecurity();
278         GenericValue userLogin = (GenericValue) context.get("userLogin");
279         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
280
281         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
282         String JavaDoc contactPartyId = (String JavaDoc) context.get("contactPartyId");
283
284         try {
285             GenericValue opportunity = delegator.findByPrimaryKey("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId));
286             if (opportunity == null) {
287                 return UtilCommon.createAndLogServiceError("CrmErrorAddContactToOpportunity", locale, module);
288             }
289
290             // for security, we need to get the accountPartyId for this opportunity
291
String JavaDoc accountPartyId = UtilOpportunity.getOpportunityAccountPartyId(opportunity);
292
293             // if no account exists, don't add contact to opportunity (rationale: this is a weird case and we don't know if convert lead will copy these)
294
if (accountPartyId == null) {
295                 String JavaDoc leadPartyId = UtilOpportunity.getOpportunityLeadPartyId(opportunity);
296                 if (leadPartyId != null) {
297                     return UtilCommon.createAndLogServiceError("Cannot add contact to a lead opportunity.", "CrmErrorAddContactToOpportunity", locale, module);
298                 } else {
299                     return UtilCommon.createAndLogServiceError("Cound not find account for opportunity ["+salesOpportunityId+"].", "CrmErrorAddContactToOpportunity", locale, module);
300                 }
301             }
302
303             // check if userLogin has CRMSFA_OPP_UPDATE permission for this contact
304
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_UPDATE", userLogin, accountPartyId)) {
305                 return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
306             }
307
308             // check first that this contact is associated with the account
309
List JavaDoc candidates = EntityUtil.filterByDate(delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", contactPartyId,
310                             "partyIdTo", accountPartyId, "partyRelationshipTypeId", "CONTACT_REL_INV"), UtilMisc.toList("fromDate DESC")));
311             if (candidates.size() == 0) {
312                 return UtilCommon.createAndLogServiceError("Contact with ID [" + contactPartyId + "] is not associated with Account with ID [" +
313                         accountPartyId + "]", "CrmErrorAddContactToOpportunity", locale, module);
314             }
315
316             // avoid duplicates
317
Map JavaDoc keys = UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "partyId", contactPartyId, "roleTypeId", "CONTACT");
318             GenericValue role = delegator.findByPrimaryKey("SalesOpportunityRole", keys);
319             if (role != null) {
320                 return UtilCommon.createAndLogServiceError("Contact is already associated with this Opportunity.", "CrmErrorAddContactToOpportunity", locale, module);
321             }
322
323             // create a SalesOpportunityRole with salesOpportunityId and partyId=contactPartyId and roleTypeId=CONTACT
324
role = delegator.makeValue("SalesOpportunityRole", keys);
325             role.create();
326         } catch (GenericEntityException e) {
327             return UtilCommon.createAndLogServiceError(e, "CrmErrorAddContactToOpportunity", locale, module);
328         }
329         return ServiceUtil.returnSuccess();
330     }
331  
332     public static Map JavaDoc removeContactFromOpportunity(DispatchContext dctx, Map JavaDoc context) {
333         GenericDelegator delegator = dctx.getDelegator();
334         LocalDispatcher dispatcher = dctx.getDispatcher();
335         Security security = dctx.getSecurity();
336         GenericValue userLogin = (GenericValue) context.get("userLogin");
337         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
338
339         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
340         String JavaDoc contactPartyId = (String JavaDoc) context.get("contactPartyId");
341
342         try {
343             GenericValue opportunity = delegator.findByPrimaryKey("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId));
344             if (opportunity == null) {
345                 return UtilCommon.createAndLogServiceError("No opportunity with ID [" + salesOpportunityId + "] found.",
346                         "CrmErrorRemoveContactFromOpportunity", locale, module);
347             }
348
349             // for security, we need to get the accountPartyId for this opportunity
350
String JavaDoc accountPartyId = UtilOpportunity.getOpportunityAccountPartyId(opportunity);
351
352             // check if userLogin has CRMSFA_OPP_UPDATE permission for this contact
353
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_UPDATE", userLogin, accountPartyId)) {
354                 return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
355             }
356
357             // delete the SalesOpportunityRole with salesOpportunityId and partyId=contactPartyId and roleTypeId=CONTACT
358
GenericValue role = delegator.findByPrimaryKey("SalesOpportunityRole", UtilMisc.toMap("salesOpportunityId", salesOpportunityId,
359                         "partyId", contactPartyId, "roleTypeId", "CONTACT"));
360             if (role == null) {
361                 return UtilCommon.createAndLogServiceError("Could not find contact with ID [" +
362                         contactPartyId + "] for the opportunity with ID [" + salesOpportunityId + "].", "CrmErrorRemoveContactFromOpportunity", locale, module);
363             }
364             role.remove();
365         } catch (GenericEntityException e) {
366             return UtilCommon.createAndLogServiceError(e, "CrmErrorRemoveContactFromOpportunity", locale, module);
367         }
368         return ServiceUtil.returnSuccess();
369     }
370
371     public static Map JavaDoc addQuoteToOpportunity(DispatchContext dctx, Map JavaDoc context) {
372         GenericDelegator delegator = dctx.getDelegator();
373         LocalDispatcher dispatcher = dctx.getDispatcher();
374         Security security = dctx.getSecurity();
375         GenericValue userLogin = (GenericValue) context.get("userLogin");
376         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
377
378         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
379         String JavaDoc quoteId = (String JavaDoc) context.get("quoteId");
380
381         try {
382             // for security, we need to get the account or lead partyId for this opportunity
383
String JavaDoc partyId = UtilOpportunity.getOpportunityAccountOrLeadPartyId(delegator.findByPrimaryKey("SalesOpportunity",
384                         UtilMisc.toMap("salesOpportunityId", salesOpportunityId)));
385
386             // make sure userLogin has CRMSFA_OPP_UPDATE permission for this account
387
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_UPDATE", userLogin, partyId)) {
388                 return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
389             }
390
391             // There's no service in ofbiz to create SalesOpportunityQuote entries, so we do it by hand
392

393             // see if the relation already exists and if not, create it
394
Map JavaDoc input = UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "quoteId", quoteId);
395             GenericValue relation = delegator.findByPrimaryKey("SalesOpportunityQuote", input);
396             if (relation == null) {
397                 relation = delegator.makeValue("SalesOpportunityQuote", input);
398                 relation.create();
399             }
400         } catch (GenericEntityException e) {
401             return UtilCommon.createAndLogServiceError(e, "CrmErrorAddQuoteFail", locale, module);
402         }
403         return ServiceUtil.returnSuccess();
404     }
405
406     public static Map JavaDoc removeQuoteFromOpportunity(DispatchContext dctx, Map JavaDoc context) {
407         GenericDelegator delegator = dctx.getDelegator();
408         LocalDispatcher dispatcher = dctx.getDispatcher();
409         Security security = dctx.getSecurity();
410         GenericValue userLogin = (GenericValue) context.get("userLogin");
411         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
412
413         String JavaDoc salesOpportunityId = (String JavaDoc) context.get("salesOpportunityId");
414         String JavaDoc quoteId = (String JavaDoc) context.get("quoteId");
415
416         try {
417             // for security, we need to get the account or lead partyId for this opportunity
418
String JavaDoc partyId = UtilOpportunity.getOpportunityAccountOrLeadPartyId(delegator.findByPrimaryKey("SalesOpportunity",
419                         UtilMisc.toMap("salesOpportunityId", salesOpportunityId)));
420
421             // make sure userLogin has CRMSFA_OPP_UPDATE permission for this account
422
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_UPDATE", userLogin, partyId)) {
423                 return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
424             }
425
426             // There's no service in ofbiz to remove SalesOpportunityQuote entries, so we do it by hand
427

428             // see if the relation already exists and if so, remove it
429
Map JavaDoc input = UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "quoteId", quoteId);
430             GenericValue relation = delegator.findByPrimaryKey("SalesOpportunityQuote", input);
431             if (relation != null) {
432                 relation.remove();
433             }
434         } catch (GenericEntityException e) {
435             return UtilCommon.createAndLogServiceError(e, "CrmErrorRemoveQuoteFail", locale, module);
436         }
437         return ServiceUtil.returnSuccess();
438     }
439
440 }
441
Popular Tags