Search in sources :

Example 6 with Lead

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));
}
Also used : LeadService(com.axelor.apps.crm.service.LeadService) Lead(com.axelor.apps.crm.db.Lead)

Example 7 with 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"));
}
Also used : LeadService(com.axelor.apps.crm.service.LeadService) Lead(com.axelor.apps.crm.db.Lead)

Example 8 with Lead

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));
    }
}
Also used : Lead(com.axelor.apps.crm.db.Lead) List(java.util.List)

Example 9 with Lead

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;
}
Also used : LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress) Address(com.axelor.apps.base.db.Address) Lead(com.axelor.apps.crm.db.Lead) Country(com.axelor.apps.base.db.Country) Map(java.util.Map)

Example 10 with Lead

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;
    }
}
Also used : Lead(com.axelor.apps.crm.db.Lead)

Aggregations

Lead (com.axelor.apps.crm.db.Lead)24 Partner (com.axelor.apps.base.db.Partner)7 Transactional (com.google.inject.persist.Transactional)6 LeadService (com.axelor.apps.crm.service.LeadService)4 CampaignRepository (com.axelor.apps.marketing.db.repo.CampaignRepository)4 AxelorException (com.axelor.exception.AxelorException)4 LeadRepository (com.axelor.apps.crm.db.repo.LeadRepository)3 Map (java.util.Map)3 Address (com.axelor.apps.base.db.Address)2 AppBase (com.axelor.apps.base.db.AppBase)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 Context (com.axelor.rpc.Context)2 Company (com.axelor.apps.base.db.Company)1 Country (com.axelor.apps.base.db.Country)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 MapService (com.axelor.apps.base.service.MapService)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 Event (com.axelor.apps.crm.db.Event)1 Campaign (com.axelor.apps.marketing.db.Campaign)1