Search in sources :

Example 11 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class ConvertLeadWizardController method convertLead.

@SuppressWarnings("unchecked")
public void convertLead(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Map<String, Object> leadContext = (Map<String, Object>) context.get("_lead");
        Lead lead = Beans.get(LeadRepository.class).find(((Integer) leadContext.get("id")).longValue());
        Partner partner = createPartnerData(context);
        Partner contactPartner = null;
        if (partner != null) {
            contactPartner = createContactData(context, partner);
        }
        try {
            lead = Beans.get(LeadService.class).convertLead(lead, partner, contactPartner);
        } catch (Exception e) {
            TraceBackService.trace(e);
        }
        if (lead.getPartner() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONVERT_LEAD_ERROR));
        }
        openPartner(response, lead);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) AxelorException(com.axelor.exception.AxelorException) Lead(com.axelor.apps.crm.db.Lead) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException)

Example 12 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class ConvertLeadWizardController method createPartnerData.

@SuppressWarnings("unchecked")
private Partner createPartnerData(Context context) throws AxelorException {
    Integer leadToPartnerSelect = (Integer) context.get("leadToPartnerSelect");
    ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
    Partner partner = null;
    if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_CREATE_PARTNER) {
        Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
        if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_PARTNER_MISSING_ADDRESS));
        }
        partner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("partner"), primaryAddress);
    // TODO check all required fields...
    } else if (leadToPartnerSelect == LeadRepository.CONVERT_LEAD_SELECT_PARTNER) {
        Map<String, Object> selectPartnerContext = (Map<String, Object>) context.get("selectPartner");
        partner = Beans.get(PartnerRepository.class).find(((Integer) selectPartnerContext.get("id")).longValue());
        if (!partner.getIsCustomer()) {
            partner.setIsProspect(true);
        }
    }
    return partner;
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AxelorException(com.axelor.exception.AxelorException) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) ConvertLeadWizardService(com.axelor.apps.crm.service.ConvertLeadWizardService)

Example 13 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class MapRestCrm method getOpportunities.

@Path("/opportunity")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getOpportunities() {
    ObjectNode mainNode = factory.objectNode();
    try {
        List<? extends Opportunity> opportunities = opportunityRepo.all().fetch();
        ArrayNode arrayNode = factory.arrayNode();
        for (Opportunity opportunity : opportunities) {
            Partner partner = opportunity.getPartner();
            if (partner == null) {
                continue;
            }
            ObjectNode objectNode = factory.objectNode();
            String currencyCode = "";
            if (opportunity.getCurrency() != null) {
                currencyCode = opportunity.getCurrency().getCode();
            }
            String amtLabel = "Amount";
            if (!Strings.isNullOrEmpty(I18n.get("amount"))) {
                amtLabel = I18n.get("amount");
            }
            String amount = amtLabel + " : " + opportunity.getAmount() + " " + currencyCode;
            objectNode.put("fullName", opportunity.getName() + "<br/>" + amount);
            objectNode.put("fixedPhone", partner.getFixedPhone() != null ? partner.getFixedPhone() : " ");
            if (partner.getEmailAddress() != null) {
                objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
            }
            Address address = Beans.get(PartnerService.class).getInvoicingAddress(partner);
            if (address != null) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                objectNode.put("address", addressString);
            }
            objectNode.put("pinColor", "pink");
            objectNode.put("pinChar", I18n.get(ITranslation.PIN_CHAR_OPPORTUNITY));
            arrayNode.add(objectNode);
        }
        mapRestService.setData(mainNode, arrayNode);
    } catch (Exception e) {
        mapRestService.setError(mainNode, e);
    }
    return mainNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(com.axelor.apps.base.db.Address) Opportunity(com.axelor.apps.crm.db.Opportunity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerProductQualityRatingServiceImpl method undoCalculation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void undoCalculation(StockMove stockMove) throws AxelorException {
    Partner partner = stockMove.getPartner();
    if (partner == null || !partner.getIsSupplier()) {
        return;
    }
    List<StockMoveLine> stockMoveLines = stockMove.getStockMoveLineList();
    if (stockMoveLines != null) {
        for (StockMoveLine stockMoveLine : stockMoveLines) {
            Product product = stockMoveLine.getProduct();
            Optional<PartnerProductQualityRating> optional = searchPartnerProductQualityRating(partner, product);
            if (optional.isPresent()) {
                PartnerProductQualityRating partnerProductQualityRating = optional.get();
                updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine, true);
            }
        }
    }
    updateSupplier(partner);
}
Also used : PartnerProductQualityRating(com.axelor.apps.stock.db.PartnerProductQualityRating) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 15 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerSaleController method displayValues.

public void displayValues(ActionRequest request, ActionResponse response) {
    Partner customer = request.getContext().asType(Partner.class);
    try {
        customer = Beans.get(PartnerRepository.class).find(customer.getId());
        SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
        PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
        List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
        if (productList.isEmpty()) {
            response.setAttr("$saleDetailsByProduct", "hidden", true);
            return;
        }
        response.setAttr("$saleDetailsByProduct", "hidden", false);
        HashMap<String, BigDecimal> qtyAndPrice;
        for (Product product : productList) {
            qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", product.getName());
            map.put("$quantitySold", qtyAndPrice.get("qty"));
            map.put("$totalPrice", qtyAndPrice.get("price"));
            map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
            saleDetailsByProduct.add(map);
        }
        response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SortedSet(java.util.SortedSet) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) HashMap(java.util.HashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Partner(com.axelor.apps.base.db.Partner) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) RoundingMode(java.math.RoundingMode) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Partner (com.axelor.apps.base.db.Partner)199 AxelorException (com.axelor.exception.AxelorException)68 Company (com.axelor.apps.base.db.Company)67 Transactional (com.google.inject.persist.Transactional)54 BigDecimal (java.math.BigDecimal)43 ArrayList (java.util.ArrayList)34 MoveLine (com.axelor.apps.account.db.MoveLine)32 Move (com.axelor.apps.account.db.Move)30 PaymentMode (com.axelor.apps.account.db.PaymentMode)26 LocalDate (java.time.LocalDate)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)24 BankDetails (com.axelor.apps.base.db.BankDetails)24 List (java.util.List)22 PartnerService (com.axelor.apps.base.service.PartnerService)18 Map (java.util.Map)18 Journal (com.axelor.apps.account.db.Journal)17 Address (com.axelor.apps.base.db.Address)14 Currency (com.axelor.apps.base.db.Currency)14 AccountConfig (com.axelor.apps.account.db.AccountConfig)13