📄 viewopportunity.bsh
字号:
/* * Copyright (C) 2006 Open Source Strategies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *//* Copyright (c) 2005-2006 Open Source Strategies, Inc. */import java.util.ArrayList;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.base.util.UtilDateTime;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;import com.opensourcestrategies.crmsfa.opportunities.UtilOpportunity;/* * Finds all information relevant to opportunities. Also checks that user has * permission to view opportunity based on lead or account */salesOpportunityId = parameters.get("salesOpportunityId");// opportunities may have a primary account or lead (this triggers the list of contacts and add contact, which we don't want if we're a lead opportunity)context.put("isAccountOpportunity", false);// get the opportunity and accountPartyId/leadPartyId all into one mapopportunity = delegator.findByPrimaryKey("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId));if (opportunity == null) return;opportunityAndParty = opportunity.getAllFields();accountPartyId = UtilOpportunity.getOpportunityAccountPartyId(opportunity);if (accountPartyId != null) { opportunityAndParty.put("accountPartyId", accountPartyId); context.put("isAccountOpportunity", true);}leadPartyId = UtilOpportunity.getOpportunityLeadPartyId(opportunity);if (leadPartyId != null) { opportunityAndParty.put("leadPartyId", leadPartyId);}// now check if user has view permissioncontext.put("allowed", true);security = request.getAttribute("security");if (accountParty != null && !CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_VIEW", userLogin, accountPartyId)) { context.put("allowed", false); return;} else if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_OPP", "_VIEW", userLogin, leadPartyId)) { context.put("allowed", false); return;}// add the opportunity to the contextcontext.put("opportunityAndParty", opportunityAndParty);// opportunity history, which is just the list of all opportunities with this ID. history = delegator.findByAnd("SalesOpportunityHistory", UtilMisc.toMap("salesOpportunityId", salesOpportunityId), UtilMisc.toList("modifiedTimestamp DESC"));context.put("opportunityHistory", history);// is the oportunity open (stage != CLOSED)?opportunityOpen = ("SOSTG_CLOSED".equals(opportunity.getString("opportunityStageId")) ? false : true);context.put("opportunityOpen", opportunityOpen);// now set data only available when we have an opportunityif (opportunityOpen) { // permission to update opportunity information (includes add/remove contact) if (CrmsfaSecurity.hasOpportunityPermission(security, "_UPDATE", request.getAttribute("userLogin"), salesOpportunityId)) { context.put("hasUpdatePermission", true); // this also means activiites may be created, but only if user has CRMSFA_ACT_CREATE if (security.hasEntityPermission("CRMSFA_ACT", "_CREATE", userLogin)) { context.put("hasNewActivityPermission", true); } } // opportunity contacts (a list of contact partyId's) but only if this is not a PROSPECT (lead) opportunity if (leadPartyId == null) { contacts = delegator.findByAnd("SalesOpportunityRole", UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "roleTypeId", "CONTACT")); context.put("contacts", contacts); } // opportunity quotes quotes = new ArrayList(); relations = opportunity.getRelated("SalesOpportunityQuote"); for (iter = relations.iterator(); iter.hasNext(); ) { quotes.addAll(iter.next().getRelated("Quote")); } context.put("quoteList", quotes);}//whether opportunity is closed or open, should still be able to view its activitiescontext.put("validView", true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -