use of com.axelor.apps.crm.db.Lead in project axelor-open-suite by axelor.
the class LeadController method checkLeadName.
/**
* Called from lead view on name change and onLoad. Call {@link
* LeadService#isThereDuplicateLead(Lead)}
*
* @param request
* @param response
*/
public void checkLeadName(ActionRequest request, ActionResponse response) {
Lead lead = request.getContext().asType(Lead.class);
response.setAttr("duplicateLeadText", "hidden", !Beans.get(LeadService.class).isThereDuplicateLead(lead));
}
use of com.axelor.apps.crm.db.Lead in project axelor-open-suite by axelor.
the class LeadController method setSocialNetworkUrl.
public void setSocialNetworkUrl(ActionRequest request, ActionResponse response) throws IOException {
Lead lead = request.getContext().asType(Lead.class);
Map<String, String> urlMap = Beans.get(LeadService.class).getSocialNetworkUrl(lead.getName(), lead.getFirstName(), lead.getEnterpriseName());
response.setAttr("googleLabel", "title", urlMap.get("google"));
response.setAttr("facebookLabel", "title", urlMap.get("facebook"));
response.setAttr("twitterLabel", "title", urlMap.get("twitter"));
response.setAttr("linkedinLabel", "title", urlMap.get("linkedin"));
response.setAttr("youtubeLabel", "title", urlMap.get("youtube"));
}
use of com.axelor.apps.crm.db.Lead in project axelor-open-suite by axelor.
the class LeadController method print.
/**
* Method to generate Lead as a Pdf
*
* @param request
* @param response
* @return
* @throws BirtException
* @throws IOException
*/
public void print(ActionRequest request, ActionResponse response) throws AxelorException {
Lead lead = request.getContext().asType(Lead.class);
String leadIds = "";
@SuppressWarnings("unchecked") List<Integer> lstSelectedleads = (List<Integer>) request.getContext().get("_ids");
if (lstSelectedleads != null) {
for (Integer it : lstSelectedleads) {
leadIds += it.toString() + ",";
}
}
if (!leadIds.equals("")) {
leadIds = leadIds.substring(0, leadIds.length() - 1);
lead = Beans.get(LeadRepository.class).find(new Long(lstSelectedleads.get(0)));
} else if (lead.getId() != null) {
leadIds = lead.getId().toString();
}
if (!leadIds.equals("")) {
String title = " ";
if (lead.getFirstName() != null) {
title += lstSelectedleads == null ? "Lead " + lead.getName() + " " + lead.getFirstName() + " - " + lead.getEnterpriseName() : "Leads";
}
String fileLink = ReportFactory.createReport(IReport.LEAD, title + "-${date}").addParam("LeadId", leadIds).addParam("Timezone", getTimezone(lead)).addParam("Locale", ReportSettings.getPrintingLocale(lead.getPartner())).generate().getFileLink();
logger.debug("Printing " + title);
response.setView(ActionView.define(title).add("html", fileLink).map());
} else {
response.setFlash(I18n.get(IExceptionMessage.LEAD_1));
}
}
use of com.axelor.apps.crm.db.Lead in project axelor-open-suite by axelor.
the class ConvertLeadWizardService method createPrimaryAddress.
@SuppressWarnings("unchecked")
public Address createPrimaryAddress(Map<String, Object> context) {
Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
String addressL4 = lead.getPrimaryAddress();
if (addressL4 == null) {
return null;
}
String addressL5 = lead.getPrimaryState() != null ? lead.getPrimaryState().getName() : null;
String addressL6 = lead.getPrimaryPostalCode() + " " + (lead.getPrimaryCity() != null ? lead.getPrimaryCity().getName() : "");
Country addressL7Country = lead.getPrimaryCountry();
Address address = addressService.getAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
if (address == null) {
address = addressService.createAddress(null, null, addressL4, addressL5, addressL6, addressL7Country);
}
return address;
}
use of com.axelor.apps.crm.db.Lead in project axelor-open-suite by axelor.
the class LeadServiceImpl method isThereDuplicateLead.
/**
* Check if the lead in view has a duplicate.
*
* @param lead a context lead object
* @return if there is a duplicate lead
*/
public boolean isThereDuplicateLead(Lead lead) {
String newName = lead.getFullName();
if (Strings.isNullOrEmpty(newName)) {
return false;
}
Long leadId = lead.getId();
if (leadId == null) {
Lead existingLead = leadRepo.all().filter("lower(self.fullName) = lower(:newName) ").bind("newName", newName).fetchOne();
return existingLead != null;
} else {
Lead existingLead = leadRepo.all().filter("lower(self.fullName) = lower(:newName) " + "and self.id != :leadId ").bind("newName", newName).bind("leadId", leadId).fetchOne();
return existingLead != null;
}
}
Aggregations