Search in sources :

Example 66 with Partner

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

the class MapRest method getPartners.

@Path("/partner")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getPartners() {
    ObjectNode mainNode = nodeFactory.objectNode();
    try {
        List<? extends Partner> partners = partnerRepo.all().filter("self.isCustomer = true OR self.isSupplier = true AND self.isContact=?", false).fetch();
        ArrayNode arrayNode = nodeFactory.arrayNode();
        for (Partner partner : partners) {
            ObjectNode objectNode = nodeFactory.objectNode();
            Address address = partnerService.getInvoicingAddress(partner);
            if (address != null && StringUtils.notBlank(address.getFullName()) && address.getIsValidLatLong()) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                if (StringUtils.isBlank(addressString)) {
                    continue;
                }
                objectNode.put("address", addressString);
            } else {
                continue;
            }
            objectNode.put("fullName", partner.getFullName());
            if (partner.getFixedPhone() != null) {
                objectNode.put("fixedPhone", partner.getFixedPhone());
            }
            if (partner.getEmailAddress() != null) {
                objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
            }
            objectNode.put("pinColor", partner.getIsProspect() ? "red" : "orange");
            String pinChar = partner.getIsProspect() ? "P" : "C";
            if (partner.getIsSupplier()) {
                pinChar = pinChar + "/S";
            }
            objectNode.put("pinChar", pinChar);
            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) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with Partner

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

the class MapRest method getProspects.

@Path("/prospect")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getProspects() {
    ObjectNode mainNode = nodeFactory.objectNode();
    try {
        List<? extends Partner> customers = partnerRepo.all().filter("self.isProspect = true AND self.isContact=?", false).fetch();
        ArrayNode arrayNode = nodeFactory.arrayNode();
        for (Partner prospect : customers) {
            ObjectNode objectNode = nodeFactory.objectNode();
            Address address = partnerService.getInvoicingAddress(prospect);
            if (address != null && address.getIsValidLatLong()) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                if (StringUtils.isBlank(addressString)) {
                    continue;
                }
                objectNode.put("address", addressString);
            } else {
                continue;
            }
            objectNode.put("fullName", prospect.getFullName());
            objectNode.put("fixedPhone", prospect.getFixedPhone() != null ? prospect.getFixedPhone() : " ");
            if (prospect.getEmailAddress() != null) {
                objectNode.put("emailAddress", prospect.getEmailAddress().getAddress());
            }
            objectNode.put("pinColor", "red");
            objectNode.put("pinChar", "P");
            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) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 68 with Partner

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

the class MapRest method getCustomers.

@Path("/customer")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getCustomers() {
    ObjectNode mainNode = nodeFactory.objectNode();
    try {
        List<? extends Partner> customers = partnerRepo.all().filter("self.isCustomer = true AND self.isContact=?", false).fetch();
        ArrayNode arrayNode = nodeFactory.arrayNode();
        for (Partner customer : customers) {
            ObjectNode objectNode = nodeFactory.objectNode();
            Address address = partnerService.getInvoicingAddress(customer);
            if (address != null && address.getIsValidLatLong()) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                if (StringUtils.isBlank(addressString)) {
                    continue;
                }
                objectNode.put("address", addressString);
            } else {
                continue;
            }
            objectNode.put("fullName", customer.getFullName());
            objectNode.put("fixedPhone", customer.getFixedPhone() != null ? customer.getFixedPhone() : " ");
            if (customer.getEmailAddress() != null) {
                objectNode.put("emailAddress", customer.getEmailAddress().getAddress());
            }
            objectNode.put("pinColor", "orange");
            objectNode.put("pinChar", "C");
            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) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 69 with Partner

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

the class MapRest method getSuppliers.

@Path("/supplier")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getSuppliers() {
    ObjectNode mainNode = nodeFactory.objectNode();
    try {
        ArrayNode arrayNode = nodeFactory.arrayNode();
        List<? extends Partner> customers = partnerRepo.all().filter("self.isSupplier = true AND self.isContact=?", false).fetch();
        for (Partner supplier : customers) {
            ObjectNode objectNode = nodeFactory.objectNode();
            Address address = partnerService.getInvoicingAddress(supplier);
            if (address != null && address.getIsValidLatLong()) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                if (StringUtils.isBlank(addressString)) {
                    continue;
                }
                objectNode.put("address", addressString);
            } else {
                continue;
            }
            objectNode.put("fullName", supplier.getFullName());
            objectNode.put("fixedPhone", supplier.getFixedPhone() != null ? supplier.getFixedPhone() : " ");
            if (supplier.getEmailAddress() != null) {
                objectNode.put("emailAddress", supplier.getEmailAddress().getAddress());
            }
            objectNode.put("pinColor", "purple");
            objectNode.put("pinChar", "S");
            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) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 70 with Partner

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

the class MapRest method getPartner.

@Path("/partner/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getPartner(@PathParam("id") long id) {
    ObjectNode mainNode = nodeFactory.objectNode();
    try {
        Partner partner = partnerRepo.find(id);
        if (partner == null) {
            throw new AxelorException(Partner.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.PARTNER_NOT_FOUND));
        }
        ArrayNode arrayNode = nodeFactory.arrayNode();
        String pinColor = getPinColor(partner);
        List<PartnerAddress> partnerAddressList = partner.getPartnerAddressList() != null ? partner.getPartnerAddressList() : Collections.emptyList();
        for (PartnerAddress partnerAddress : partnerAddressList) {
            Address address = partnerAddress.getAddress();
            if (address == null || !address.getIsValidLatLong()) {
                continue;
            }
            ObjectNode objectNode = nodeFactory.objectNode();
            if (!StringUtils.isBlank(address.getFullName())) {
                String addressString = mapRestService.makeAddressString(address, objectNode);
                if (StringUtils.isBlank(addressString)) {
                    continue;
                }
                objectNode.put("address", addressString);
            } else {
                continue;
            }
            objectNode.put("fullName", getFullName(partnerAddress));
            if (partnerAddress.getIsDefaultAddr()) {
                if (!StringUtils.isBlank(partner.getFixedPhone())) {
                    objectNode.put("fixedPhone", partner.getFixedPhone());
                }
                if (partner.getEmailAddress() != null) {
                    objectNode.put("emailAddress", partner.getEmailAddress().getAddress());
                }
            }
            objectNode.put("pinColor", pinColor);
            objectNode.put("pinChar", getPinChar(partnerAddress));
            arrayNode.add(objectNode);
        }
        mapRestService.setData(mainNode, arrayNode);
    } catch (Exception e) {
        mapRestService.setError(mainNode, e);
    }
    return mainNode;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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