📄 dealadd.jsp
字号:
<%@ page import="org.ofbiz.entity.*" %>
<%@ page import="org.ofbiz.entity.model.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page import="org.ofbiz.entity.util.SequenceUtil" %>
<%@ page import="com.sourcetap.sfa.role.RoleHelper" %>
<%@ page import="com.sourcetap.sfa.replication.*" %>
<%@ include file="/includes/header.jsp" %>
<%!
/*
This method needs to validate that the opportunity is correct before it updates the database
needs to validate the following:
The opportunity is in the first stage. i.e. cant create an opportunity in the sold stage.
*/
boolean validateOpportunity(HttpServletRequest request){
return true;
}
%>
<%
Enumeration enum = request.getParameterNames();
while(enum.hasMoreElements()){
String na = (String)enum.nextElement();
}
String ENTITY = "Deal";
String action = "";
ModelEntity entity = delegator.getModelEntity(ENTITY);
if(request.getParameter("action") != null){
//actions=search, update, create
action = request.getParameter("action");
}
//handle creating a deal action
if(action.equals("create")){
try {
GenericValue genericValue = new GenericValue(entity);
genericValue.setDelegator(delegator);
Vector dealFields = entity.getFieldsCopy();
genericValue.set("dealId", GenericReplicator.getNextSeqId(ENTITY, delegator));
Enumeration params = request.getParameterNames();
String pName = "";
ModelField modelField = null;
while(params.hasMoreElements()){
pName = (String)params.nextElement();
if((modelField = contains(dealFields, pName)) != null){
genericValue = setCorrectDataType( genericValue, modelField, request.getParameter(pName));
}
}
//set the owner to the person adding the deal.
genericValue = setCorrectDataType( genericValue, entity.getField("ownerId"), (String)session.getAttribute("partyId"));
genericValue.set("createdBy", session.getAttribute("userName"));
genericValue.set("createdDate", new Timestamp(new java.util.Date().getTime()));
genericValue.set("modifiedBy", session.getAttribute("userName"));
genericValue.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
//Create a new Team, with the current logged-in user as primary.
GenericValue team = new GenericValue(delegator.getModelEntity("Team"));
team.setDelegator(delegator);
GenericValue party = new GenericValue(delegator.getModelEntity("Party"));
party.setDelegator(delegator);
GenericValue teamMember = new GenericValue(delegator.getModelEntity("TeamMember"));
teamMember.setDelegator(delegator);
GenericValue entityAccess = new GenericValue(delegator.getModelEntity("EntityAccess"));
entityAccess.setDelegator(delegator);
GenericValue entityRoleAccess = new GenericValue(delegator.getModelEntity("EntityAccess"));
entityRoleAccess.setDelegator(delegator);
party.set("partyId", GenericReplicator.getNextSeqId("Party", delegator));
team.set("teamId", party.getString("partyId"));
team.set("createdBy", session.getAttribute("userName"));
team.set("createdDate", new Timestamp(new java.util.Date().getTime()));
team.set("modifiedBy", session.getAttribute("userName"));
team.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
//Add team owner to team_member
teamMember.set("teamMemberId", GenericReplicator.getNextSeqId("TeamMember", delegator));
teamMember.set("teamId", team.getString("teamId"));
teamMember.set("partyId", (String)session.getAttribute("partyId"));
teamMember.set("teamOwner", "Y");
teamMember.set("createdBy", session.getAttribute("userName"));
teamMember.set("createdDate", new Timestamp(new java.util.Date().getTime()));
teamMember.set("modifiedBy", session.getAttribute("userName"));
teamMember.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
//add Team to Entity Access.
entityAccess.set("entityAccessId", GenericReplicator.getNextSeqId("EntityAccess", delegator));
entityAccess.set("entity", "Deal");
entityAccess.set("entityId", genericValue.getString("dealId"));
entityAccess.set("partyId", team.getString("teamId"));
entityAccess.set("partyEntityType", "Team");
entityAccess.set("createdBy", session.getAttribute("userName"));
entityAccess.set("createdDate", new Timestamp(new java.util.Date().getTime()));
entityAccess.set("modifiedBy", session.getAttribute("userName"));
entityAccess.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
//Add a Role entity to Entity_Access with Role_Path as the party_id
entityRoleAccess.set("entityAccessId", GenericReplicator.getNextSeqId("EntityAccess", delegator));
entityRoleAccess.set("entity", "Deal");
entityRoleAccess.set("entityId", genericValue.getString("dealId"));
entityRoleAccess.set("partyId", RoleHelper.getRolePath((String)session.getAttribute("partyId"), (String)session.getAttribute("roleId"),delegator));
entityRoleAccess.set("partyEntityType", "Role");
entityRoleAccess.set("createdBy", session.getAttribute("userName"));
entityRoleAccess.set("createdDate", new Timestamp(new java.util.Date().getTime()));
entityRoleAccess.set("modifiedBy", session.getAttribute("userName"));
entityRoleAccess.set("modifiedDate", new Timestamp(new java.util.Date().getTime()));
List storeGVL = new LinkedList();
storeGVL.add(genericValue);
storeGVL.add(party);
storeGVL.add(team);
storeGVL.add(teamMember);
storeGVL.add(entityAccess);
storeGVL.add(entityRoleAccess);
delegator.storeAll(storeGVL);
} catch (Exception e) { e.printStackTrace(); }
}
//build Deal status drop-down
HashMap statusProps = new HashMap();
statusProps.put("NAME", "dealStatusId");
statusProps.put("VALUE_FIELD", "dealStatusId" );
statusProps.put("DISPLAY_FIELD", "dealStatusName" );
statusProps.put("SELECTED", getFieldValue(request, "dealStatusId"));
ArrayList order = new ArrayList();
order.add("dealStatusId");
String dealStatusDropDown = buildDropDown(delegator.findAll("DealStatus", order), statusProps );
//build deal stage drop-down
HashMap stageProps = new HashMap();
stageProps.put("NAME", "stageId");
stageProps.put("VALUE_FIELD", "stageOrder" );
stageProps.put("DISPLAY_FIELD", "stageName" );
stageProps.put("SELECTED", getFieldValue(request, "stageId"));
order.remove(0);
order.add("stageOrder");
String dealStageDropDown = buildDropDown(delegator.findAll("DealStage", order), stageProps );
//build rep's account drop-down
HashMap accountProps = new HashMap();
accountProps.put("NAME", "accountId");
accountProps.put("VALUE_FIELD", "accountId" );
accountProps.put("DISPLAY_FIELD", "accountName");
accountProps.put("EMPTY_FIRST", "0,-- none --" );
accountProps.put("SELECTED", getFieldValue(request, "accountId"));
HashMap accountFields = new HashMap();
accountFields.put("accountOwnerId", session.getAttribute("partyId"));
String accountDropDown = buildDropDown(delegator.findByAnd("Account", accountFields, null), accountProps );
//build rep's contact drop-down
HashMap contactProps = new HashMap();
contactProps.put("NAME", "contactId");
contactProps.put("VALUE_FIELD", "contactId" );
contactProps.put("DISPLAY_FIELD", "firstName,lastName");
contactProps.put("EMPTY_FIRST", "0,-- none --" );
contactProps.put("SELECTED", getFieldValue(request, "contactId"));
HashMap contactFields = new HashMap();
contactFields.put("contactOwnerId", session.getAttribute("partyId"));
String contactDropDown = buildDropDown(delegator.findByAnd("Contact", contactFields, null), contactProps );
//build deal stage type drop-down
HashMap dealStageTypeProps = new HashMap();
dealStageTypeProps.put("NAME", "dealStageTypeId");
dealStageTypeProps.put("VALUE_FIELD", "dealStageTypeId" );
dealStageTypeProps.put("DISPLAY_FIELD", "dealStageTypeName");
dealStageTypeProps.put("EMPTY_FIRST", "0,-- none --" );
String dealStageTypeDropDown = buildDropDown(delegator.findAll("DealStageType", null), dealStageTypeProps);
%>
<!-- title table -->
<table width="100%" height="30" class="head1" ><tr><td>Opportunity</td></tr></table>
<!-- Outer table : begin -->
<table class="viewOneHeader" cellpadding='1' cellspacing='1' border="0" width='100%' >
<tr>
<td>Add a new Opportunity</td>
</tr>
<tr class="viewOneHeader" ><td>
<form method="post" action="<ofbiz:url>/dealAdd</ofbiz:url>">
<input type="hidden" value="create" name="action" >
<input type="hidden" value="<%=getFieldValue(request, "partyId")%>" name="ownerId" value="<%=getFieldValue(request, "ownerId")%>" >
<table cellpadding='1' cellspacing='1' border='0' width='100%' >
<tr>
<td class="viewOneLabel">Status</td>
<td class="viewOneField"><%=dealStatusDropDown%></td><!-- status -->
</tr>
<tr>
<td class="viewOneLabel">Region</td>
<td class="viewOneField"></td><!-- region -->
</tr>
<tr>
<td class="viewOneLabel">Stage</td>
<td class="viewOneField"><%=dealStageDropDown%></td><!-- stage -->
</tr>
<tr>
<td class="viewOneLabel">Opportunity Name</td>
<td class="viewOneField"><input type="text" name="dealName" size="40" value="<%=getFieldValue(request, "dealName")%>"></td><!-- deal name -->
</tr>
<tr>
<td class="viewOneLabel">Opportunity Amount</td>
<td class="viewOneField"><input type="text" name="amount" size="40" value="<%=getFieldValue(request, "amount")%>"></td><!-- amount -->
</tr>
<tr>
<td class="viewOneLabel">Projected Close Date</td>
<td class="viewOneField"><input type="text" name="projectedCloseDate" size="40" value="<%=getFieldValue(request, "projectedCloseDate")%>"></td><!-- projected close date -->
</tr>
<tr>
<td class="viewOneLabel">Actual Close</td>
<td class="viewOneField"><%=getFieldValue(request, "actualCloseDate")%></td><!-- actual close date -->
</tr>
<tr>
<td class="viewOneLabel">Description</td>
<td class="viewOneField"><input type="text" name="description" size="40" value="<%=getFieldValue(request, "description")%>"></td><!-- description -->
</tr>
<tr>
<td class="viewOneLabel">Lead Source</td>
<td class="viewOneField"><input type="text" name="leadSource" size="40" value="<%=getFieldValue(request, "leadSource")%>"></td><!-- Lead Source -->
</tr>
<tr>
<td class="viewOneLabel">Should this opportunity be included in your forecast?</td>
<td class="viewOneField"><input type="checkbox" name="isInForecast" <%=(getFieldValue(request, "isInForecast") != null && getFieldValue(request, "isInForecast").equals("1") ? "CHECKED" : "") %> ></td>
</tr>
<tr>
<td class="viewOneLabel">What is the proposed solution?</td>
<td class="viewOneField"><textarea name="proposedSolution" rows="10" cols="40" ><%=getFieldValue(request, "proposedSolution")%></textarea></td>
</tr>
<tr>
<td class="viewOneLabel">What sales process should be used?</td>
<td class="viewOneField"><%=dealStageTypeDropDown%></td>
</tr>
<tr>
<td class="viewOneLabel">What account is the opportunity with?</td>
<td class="viewOneField"><%=accountDropDown%></td>
</tr>
<tr>
<td class="viewOneLabel">Is there corporate approval for the opportunity?</td>
<td class="viewOneField">Yes<input type="radio" name="isCorporateApproved" value="1" checked> No<input type="radio" name="isCorporateApproved" value="0"></td>
</tr>
<tr>
<td class="viewOneLabel">Whose budget will the opportunity come from?</td>
<td class="viewOneField"><%=contactDropDown%></td>
</tr>
<tr>
<td class="viewOneLabel">Prospect Qualification</td>
<td class="viewOneField">
<%String fieldValue = getFieldValue(request, "prospectQualification");%>
Qualified<input type="radio" name="prospectQualification" value="qualified" <%=(fieldValue.equals("qualified") ? "checked" : " " )%> ><br>
Need information<input type="radio" name="prospectQualification" value="needInfo" <%=(fieldValue.equals("needInfo") ? "checked" : " " )%> ><br>
Invest in Next Step<input type="radio" name="prospectQualification" value="invest" <%=(fieldValue.equals("invest") ? "checked" : " " )%> ><br>
Disqualified<input type="radio" name="prospectQualification" value="disQualified" <%=(fieldValue.equals("disQualified") ? "checked" : " " )%> >
</tr>
<tr>
<td class="viewOneLabel">Preference Momentum</td>
<td class="viewOneField">
Selected<input type="radio" name="preferenceMomentum" value="selected" ><br>
Leaning Our Way<input type="radio" name="preferenceMomentum" value="leaning" ><br>
Going Away<input type="radio" name="preferenceMomentum" value="going" ><br>
Unknown<input type="radio" name="preferenceMomentum" value="unknown" ><br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -