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

📄 leadlistconverter.jsp

📁 国外的一套开源CRM
💻 JSP
📖 第 1 页 / 共 2 页
字号:
					opportunityStageId = stageId;
					
				if ( stageId.equals(opportunityStageId) )
					checked = "SELECTED";
%>
				<OPTION VALUE="<%=stageId%>" <%=checked%>><%=stageName%></OPTION>
<%
			}
		}
%>
			</SELECT>
	        </TD></TR>
	        
		<TR><TD colspan=2 align=center><CENTER><BR><input type=submit value=next></CENTER></TD></TR>
		</TABLE>
		</FORM>
	
<%	
	}
	else if ( action.equals("mapAccounts" ) )
	{		
        DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "Lead"); 
		dve.addMemberEntity("UiListItem", "UiListItem");
		dve.addMemberEntity("Address", "Address");
        dve.addViewLink("Lead", "UiListItem", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("leadId", "entityId")));
        dve.addViewLink("Lead", "Address", Boolean.TRUE, UtilMisc.toList(new ModelKeyMap("leadId", "addressOwnerId")));
        dve.addAlias("UiListItem", "listItemId", null, null, null, null, null);
        dve.addAlias("UiListItem", "entityName", null, null, null, null, null);
        dve.addAlias("UiListItem", "listId", null, null, null, null, null);
        dve.addAlias("UiListItem", "status", null, null, null, null, null);

        dve.addAlias("Address", "mailingAddress", null, null, null, null, null);
        dve.addAlias("Address", "city", null, null, null, null, null);
        dve.addAlias("Address", "state", null, null, null, null, null);
        dve.addAlias("Address", "zip", null, null, null, null, null);
        dve.addAlias("Address", "isPrimary", null, null, null, null, null);
 
        EntityCondition condition = new EntityConditionList(UtilMisc.toList(
			                 	new EntityExpr("listId", EntityOperator.EQUALS, listId),
			                 	new EntityExpr("entityName", EntityOperator.EQUALS, "Lead"),
			                 	new EntityExpr("status", EntityOperator.EQUALS, "new"),
			                 	new EntityExpr("isPrimary", EntityOperator.EQUALS, "Y")),
			                 EntityOperator.AND);
		
		EntityListIterator eli = EntityHelper.findIteratorByCondition( delegator, dve, condition, null, UtilMisc.toList("lastName", "firstName"));
		
		List leadList = eli.getPartialList( 1, 25);
		eli.close();

		if ( (leadList == null ) || (leadList.size() == 0 ))
		{
			action = "convertLeads";
		}
		else
		{
			LeadHelper leadHelper = LeadHelper.getInstance(delegator);
			
			Iterator iter = leadList.iterator();
%>
			<BR>Verify Mapping of the Leads to Existing Accounts or New Accounts<BR>
			<FORM>
			<INPUT TYPE=HIDDEN NAME=listId VALUE='<%=listId%>'>
			<INPUT TYPE=HIDDEN NAME=action VALUE=setAccountMapping>
<%			if ( createContactFlag ) {
%>				<INPUT TYPE=HIDDEN NAME=createContactFlag value=Y>
<%			}
			if ( createOpportunityFlag ) {
%>				<INPUT TYPE=HIDDEN NAME=createOpportunityFlag value=Y>
				<INPUT TYPE=HIDDEN NAME=opportunityStageId value='<%=opportunityStageId%>'>
				<INPUT TYPE=HIDDEN NAME=opportunityName value='<%=opportunityName%>'>
<%			}
%>
			<TABLE class=its>
			<THEAD><TR><TD>Lead Info</TD><TD>Map to Account</TD><TD>Map to Contact</TD></TR></THEAD><TBODY>
<%
			int i = 0;
	
			while ( iter.hasNext() )
			{
				i++;
				String rowClass = (( i % 2 ) == 0 ) ? "even" : "odd";
				String checked = ( i==1) ? " checked " : "";
				GenericValue listGV = (GenericValue) iter.next();
				String name = listGV.getString("firstName");
				if ( (name == null) || ( name.length() == 0 ) )
					name = listGV.getString("lastName");
				else
					name = name + " " + listGV.getString("lastName");
				
				if ( ( name == null ) || ( name.length() == 0 ) )
					name = listGV.getString("fullName");
					
				String accountName = UtilFormatOut.checkNull(listGV.getString("companyName"));
				out.write("<TR class=" + rowClass + "><TD>" + name + "&nbsp; Company: " + accountName + 
				                                           "<BR>" + UtilFormatOut.checkNull(listGV.getString("businessPhone")) + 
				                                           "<BR>" + UtilFormatOut.checkNull(listGV.getString("mailingAddress")) +
				                                           "<BR>" + UtilFormatOut.checkNull(listGV.getString("city")) + ", " + UtilFormatOut.checkNull(listGV.getString("state"))
				                                                  + " " + UtilFormatOut.checkNull(listGV.getString("zip")) + 
				                                           "</TD><TD>");
					
				int numAccounts = 0;
				String radioName = "lead2Account_" + listGV.getString("listItemId");
				String selected = "checked";
				String shortName = (accountName.length() > 10) ? accountName.substring(0,10) : accountName;

				if ( accountName.length() > 0 )	
				{
					List matchingAccounts = leadHelper.findMatchingAccounts(accountName, userInfo);
					if ( ( matchingAccounts != null )  && (matchingAccounts.size() > 0))
						numAccounts = matchingAccounts.size();
						
					for ( int ii=0; ii < numAccounts; ii++ ) {
						GenericValue matchingAcctGV = (GenericValue) matchingAccounts.get(ii);
%>						<input type=radio name='<%=radioName%>' id='<%=radioName + "_" + ii%>' value=<%=matchingAcctGV.getString("accountId")%> <%=selected%> align=left><%=matchingAcctGV.getString("accountName")%><BR>
<%
						selected = "";
					}
				}
%>				<input type=radio name=<%=radioName%> id=<%=radioName + "_" + numAccounts%> <%=selected%> value=''><%= selected.equals("checked") ? "<font color=red>" : "<font color=black>" %>Create A New Account for this Lead</font><br>
				<input type=radio name=<%=radioName%> id=<%=radioName + "_" + numAccounts+1%> value='' disabled><input id=<%=radioName%>_display name=<%=radioName%>_display disabled size=30 value=''>
					<a href="#" onClick="showAccountSearch('<%=radioName + "_" + numAccounts+1%>', '<%=radioName%>_display', '<%=URLEncoder.encode(shortName,"UTF-8")%>');return(false);">Find Account</a>
				</TD><TD>
					
<%				int numContacts = 0;
				radioName = "lead2Contact_" + listGV.getString("listItemId");
				selected = "checked";
				List matchingContacts = leadHelper.findMatchingContacts(listGV.getString("firstName"), listGV.getString("lastName"), userInfo);
				if ( ( matchingContacts != null )  && (matchingContacts.size() > 0))
					numContacts = matchingContacts.size();
				
				if ( numContacts > 5 )
					numContacts = 5;
				for ( int ii=0; ii < numContacts; ii++ ) {
					GenericValue matchingContactsGV = (GenericValue) matchingContacts.get(ii);
%>					<input type=radio name='<%=radioName%>' id='<%=radioName + "_" + ii%>' value=<%=matchingContactsGV.getString("contactId")%> <%=selected%> align=left><%=matchingContactsGV.getString("firstName") + " " + matchingContactsGV.getString("lastName")%><BR>
<%
					selected = "";
				}

%>				<input type=radio name=<%=radioName%> id=<%=radioName + "_" + numContacts%> <%=selected%> value=''><%= selected.equals("checked") ? "<font color=red>" : "<font color=black>" %>Create A New Contact for this Lead</font><br>
				<input type=radio name=<%=radioName%> id=<%=radioName + "_" + numContacts+1%> value='' disabled><input id=<%=radioName%>_display name=<%=radioName%>_display disabled size=30 value=''>
					<a href="#" onClick="showContactSearch('<%=radioName + "_" + numContacts+1%>', '<%=radioName%>_display', '<%=URLEncoder.encode(listGV.getString("lastName"),"UTF-8")%>');return(false);">Find Contact</a>
				</TD></TR>
<%
			}
%>      
			</TBODY>
			</TABLE>
			<input type=submit value=next>
			</FORM>
			<BR>
<%
		}		
	}
	if ( action.equals("mapContacts") )
	{
		out.write("mapContacts");
	}
	
	if ( action.equals("convertLeads") )
	{
		LeadConverter leadConverter = new LeadConverter( delegator, uiCache, userInfo, leadEventProcessor );
		
		DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "Lead"); 
		dve.addMemberEntity("UiListItem", "UiListItem");
        dve.addViewLink("Lead", "UiListItem", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("leadId", "entityId")));
        dve.addAlias("UiListItem", "listItemId", null, null, null, null, null);
        dve.addAlias("UiListItem", "entityName", null, null, null, null, null);
        dve.addAlias("UiListItem", "listId", null, null, null, null, null);
        dve.addAlias("UiListItem", "status", null, null, null, null, null);
 
        EntityCondition condition = new EntityConditionList(UtilMisc.toList(
			                 	new EntityExpr("status", EntityOperator.NOT_EQUAL, "converted"),
			                 	new EntityExpr("listId", EntityOperator.EQUALS, listId),
			                 	new EntityExpr("entityName", EntityOperator.EQUALS, "Lead")),
			                 EntityOperator.AND);
		
		EntityListIterator eli = EntityHelper.findIteratorByCondition( delegator, dve, condition, null, UtilMisc.toList("lastName", "firstName"));
		eli.setFetchSize(10);
		
		GenericValue leadGV = null;
		int numConverted = 0;
		int numErrors = 0;
		
		while ( (leadGV = (GenericValue) eli.next()) != null )
		{
			leadConverter.setAccountId(leadGV.getString("convertedAccountId"));
			leadConverter.setContactId(leadGV.getString("convertedContactId")); 
			leadConverter.setCreateContact( true );
			leadConverter.setCreateOpportunity( false );
	
			if ( !leadConverter.convert( leadGV.getString("leadId") ) )
			{
				numErrors++;
				out.write("<BR>error converting lead " + leadGV.getString("firstName") + " " + leadGV.getString("lastName"));
			}
			else
			{
				numConverted++;
				GenericValue liGV = delegator.findByPrimaryKey("UiListItem", UtilMisc.toMap("listItemId", leadGV.getString("listItemId")));
	    		liGV.set("status", "converted");
	    		liGV.store();
				
				out.write("<BR>Converted lead " + leadGV.getString("firstName") + " " + leadGV.getString("lastName") + " to Account " + leadConverter.getAccountId() + " and Contact " + leadConverter.getContactId());
			}
		}
		eli.close();
		
		if ( ( numConverted == 0 ) && ( numErrors == 0 ) )
			out.write("<BR><BR><BR>No Leads in this list needs to be converted.");
		else
			out.write("<BR><BR><BR>Number of Leads Converted: " + numConverted + "<BR>Number of Leads not converted due to errors: " + numErrors);
	}
} catch (Exception e) {
	Debug.logError("Error on leadListConvert" + e.getMessage(), "leadListConvert");
	e.printStackTrace();
	out.write("Error on leadListConvert" + e.getMessage());
}
%>

⌨️ 快捷键说明

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