⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leadconvert.jsp

📁 国外的一套开源CRM
💻 JSP
字号:
<%@ include file="/includes/header.jsp" %>
<%@ page import="com.sourcetap.sfa.lead.*" %>
<%@ page import="com.sourcetap.sfa.ui.UIDealStageDropDown" %>
<jsp:useBean id="leadWebEventProcessor" class="com.sourcetap.sfa.lead.LeadWebEventProcessor" scope="application" />
<jsp:useBean id="leadEventProcessor" class="com.sourcetap.sfa.lead.LeadEventProcessor" scope="application" />

<%
try {
	String action = UtilFormatOut.checkNull(request.getParameter("action"));
	
	String leadId = UtilFormatOut.checkNull(request.getParameter("leadId"));
	
	String accountId = UtilFormatOut.checkNull(request.getParameter("accountId"));
	String contactId = UtilFormatOut.checkNull(request.getParameter("contactId"));
	String opportunityName = UtilFormatOut.checkNull(request.getParameter("opportunityName"));
	String opportunityStageId = UtilFormatOut.checkNull(request.getParameter("opportunityStageId"));
	boolean createContactFlag =true;
	boolean createOpportunityFlag = true;
	
	if ( !action.equals("start") && (request.getParameter("createContactFlag") == null ))
		createContactFlag = false;

	if ( !action.equals("start") && (request.getParameter("createOpportunityFlag") == null ))
		createOpportunityFlag = false;

	
	if ( ( accountId.length() < 1 ) && ( action.equals("checkContacts") ) )
		action = "convert";
	
	GenericValue leadGV = delegator.findByPrimaryKey("Lead", UtilMisc.toMap("leadId", leadId));
	if ( leadGV == null )
	{
%>
<TABLE>
<TR>
<TD>Unable to find lead!</TD>
</TR>
</TABLE>
<%
	}
	else if ( action.equals("start") || action.equals("checkContacts") )
	{
	    
		String nextStep = "convert";
		String leadCompanyName = leadGV.getString("companyName");
		
		List opportunityStages = UIDealStageDropDown.getDefaultSalesProcessStages(delegator, userInfo);
		LeadHelper leadHelper = LeadHelper.getInstance(delegator);
		
		List matchingAccounts = null;
		int numAccounts = 0;
		if ( action.equals("start") )
		{
			matchingAccounts = leadHelper.findMatchingAccounts( leadCompanyName, userInfo );
		
			if ( (matchingAccounts != null ) && ( matchingAccounts.size() > 0 ) )
			{
				nextStep = "checkContacts";
				numAccounts = matchingAccounts.size();
			}
		}
		
		List matchingContacts = null;
		int numContacts = 0;
		if ( action.equals("checkContacts") )
		{
			matchingContacts = leadHelper.findMatchingContacts( accountId, leadGV.getString("firstName"), leadGV.getString("lastName"), userInfo);
		
			if ( (matchingContacts != null ) && ( matchingContacts.size() > 0 ) )
			{
				numContacts = matchingContacts.size();
			}
		}
%>
		<BR>
		<TABLE CLASS="freeFormSectionTitleTable" width="100%">
		<TR><TD>Convert Lead to an Account, Contact, and Opportunity</TD></TR>
		</TABLE>
		<BR>
		<TABLE CLASS="freeFormSectionDisplayTable" width=500>
		<TR><TD colspan=2 class=freeFormSectionLabelOptional style="TEXT-ALIGN: left;">Lead Information</TD></TR>
		<TR><TD class=freeFormSectionLabelOptional>Lead Name:</TD><TD class=freeFormSectionField><%=leadGV.getString("firstName") + " " + leadGV.getString("lastName")%></TD></TR>
		<TR><TD class=freeFormSectionLabelOptional>Company Name:</TD><TD class=freeFormSectionField><%=leadCompanyName%></TD></TR>
		</TABLE>
		<BR>
		<BR>
		<FORM action=/sfa/control/leadConvert>
		<input type=hidden name=action value=<%=nextStep%>>
		<input type=hidden name=leadId value=<%=leadId%>>
<%
		if ( accountId.length() > 0 ) {
%>			<input type=hidden name=accountId value="<%=accountId%>">
<%
		}
		
		if ( opportunityName.length() > 0 ) {
%>			<input type=hidden name=opportunityName value="<%=opportunityName%>">
<%
		}
%>
		<TABLE class=freeFormSectionDisplayTable width=500>
<%
		if ( numAccounts > 0 ) {
%>			<TR><TD colspan=2><BR></TD></TR>
  			<TR><TD colspan=2 class=freeFormSectionLabelOptional style="TEXT-ALIGN: left;">Account creation option</TD></TR>
            <TR><TD colspan=2 class=freeFormSectionField><input type=radio name=accountId value="" checked align=left>Create a new Account for this Lead</TD></TR>
<%		
			for ( int i=0; i < numAccounts; i++ ) {
				GenericValue matchingAcctGV = (GenericValue) matchingAccounts.get(i);
%>				<TR><TD colspan=2 class=freeFormSectionField><input type=radio name=accountId value=<%=matchingAcctGV.getString("accountId")%> align=left>Update existing Account with name <%=matchingAcctGV.getString("accountName")%> and id <%=matchingAcctGV.getString("accountId")%></TD></TR>
<%			}
%>			<TR><TD colspan=2><BR></TD></TR>
			<TR><TD colspan=2><BR></TD></TR>  
<%
		}

		if ( numContacts > 0 ) {
%>			<TR><TD colspan=2><BR></TD></TR>
  			<TR><TD colspan=2 class=freeFormSectionLabelOptional style="TEXT-ALIGN: left;">Contact creation option</TD></TR>
            <TR><TD colspan=2 class=freeFormSectionField><input type=radio name=contactId value="" checked align=left>Create a new Contact for this Lead</TD></TR>
<%		
			for ( int i=0; i < numContacts; i++ ) {
				GenericValue matchingContactGV = (GenericValue) matchingContacts.get(i);
%>				<TR><TD colspan=2 class=freeFormSectionField><input type=radio name=contactId value=<%=matchingContactGV.getString("contactId")%> align=left>
					Update existing Contact with name <%=matchingContactGV.getString("firstName") + " " + matchingContactGV.getString("lastName")%> and id <%=matchingContactGV.getString("contactId")%></TD></TR>
<%			}
%>			<TR><TD colspan=2><BR></TD></TR>
			<TR><TD colspan=2><BR></TD></TR>  
<%
		}
%>
		<TR><TD class=freeFormSectionLabelOptional>Opportunity Name:</TD><TD class=freeFormSectionField><input type=text name=opportunityName value="<%=opportunityName%>"></TD></TR>
		<TR><TD class=freeFormSectionLabelOptional>Opportunity Stage:</TD><TD class=freeFormSectionField>
		    <SELECT NAME="opportunityStageId" CLASS="selectBox">
<%
		if ( opportunityStages != null )
		{
			for ( int i=0; i < opportunityStages.size(); i++ )
			{
				String checked = "";
				GenericValue stageGV = (GenericValue) opportunityStages.get(i);
				String stageId = stageGV.getString("stageId");
				String stageName = stageGV.getString("stageName");
				
				if ( opportunityStageId.length() < 1 )
					opportunityStageId = stageId;
					
				if ( stageId.equals(opportunityStageId) )
					checked = "SELECTED";
%>
				<OPTION VALUE="<%=stageId%>" <%=checked%>><%=stageName%></OPTION>
<%
			}
		}
%>
			</SELECT>
	        </TD></TR>
	        
		<TR><TD class=freeFormSectionLabelOptional>Create Contact:</TD><TD class=freeFormSectionField><input type=checkbox name=createContactFlag <%= createContactFlag ? "CHECKED" : ""%>></TD></TR>
		<TR><TD class=freeFormSectionLabelOptional>Create Opportunity:</TD><TD class=freeFormSectionField><input type=checkbox name=createOpportunityFlag <%= createOpportunityFlag ? "CHECKED" : ""%>></TD></TR>
		<TR><TD colspan=2 align=center><input type=submit value=convert></TD></TR>
		</TABLE>
		</FORM>
<%
	}
	else if ( action.equals("convert") )
	{
		LeadConverter leadConverter = new LeadConverter( delegator, uiCache, userInfo, leadEventProcessor );
		
		if ( accountId.length() > 0 )
			leadConverter.setAccountId(accountId);

		if ( contactId.length() > 0 )
			leadConverter.setContactId(contactId);

		if ( opportunityName.length() > 0 )
			leadConverter.setOpportunityName(opportunityName);
		
		if ( opportunityStageId.length() > 0 )
			leadConverter.setOpportunityStageId(opportunityStageId);
			
		leadConverter.setCreateContact( createContactFlag );
		leadConverter.setCreateOpportunity( createOpportunityFlag );

		leadConverter.convert( leadGV.getString("leadId") );
		
%>
		<BR><h3> Lead Converted</h3>
		<BR> Click <a href=/sfa/control/accounts?action=show&accountId=<%=leadConverter.getAccountId()%>>here</a> to view the converted Account
<%		
		if ( createContactFlag ) {
%>			<BR> Click <a href=/sfa/control/contacts?action=show&contactId=<%=leadConverter.getContactId()%>>here</a> to view the converted Contact
<%		}

		if ( createOpportunityFlag ) {		
%>			<BR> Click <a href=/sfa/control/deals?action=show&dealId=<%=leadConverter.getOpportunityId()%>>here</a> to view the converted Opportunity
<%		}
	}
}
catch (Exception e)
{
	Debug.logError("Error on leadConvert" + e.getMessage(), "leadConvert");
	e.printStackTrace();
	out.write("Error on leadConvert" + e.getMessage());
}
%>
<%@ include file="/includes/footer.jsp" %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -