Search in sources :

Example 11 with Address

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

the class AddressController method viewDirection.

public void viewDirection(ActionRequest request, ActionResponse response) {
    AddressRepository addressRepository = Beans.get(AddressRepository.class);
    try {
        MapService mapService = Beans.get(MapService.class);
        String key = null;
        if (Beans.get(AppBaseService.class).getAppBase().getMapApiSelect() == AppBaseRepository.MAP_API_GOOGLE) {
            key = mapService.getGoogleMapsApiKey();
        }
        Company company = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
        if (company == null) {
            response.setFlash(I18n.get(IExceptionMessage.PRODUCT_NO_ACTIVE_COMPANY));
            return;
        }
        Address departureAddress = company.getAddress();
        if (departureAddress == null) {
            response.setFlash(I18n.get(IExceptionMessage.ADDRESS_7));
            return;
        }
        departureAddress = addressRepository.find(departureAddress.getId());
        Optional<Pair<BigDecimal, BigDecimal>> departureLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(departureAddress);
        if (!departureLatLong.isPresent()) {
            response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), departureAddress.getFullName()));
            return;
        }
        Address arrivalAddress = request.getContext().asType(Address.class);
        arrivalAddress = addressRepository.find(arrivalAddress.getId());
        Optional<Pair<BigDecimal, BigDecimal>> arrivalLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(arrivalAddress);
        if (!arrivalLatLong.isPresent()) {
            response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), arrivalAddress.getFullName()));
            return;
        }
        Map<String, Object> mapView = new HashMap<>();
        mapView.put("title", "Map");
        mapView.put("resource", mapService.getDirectionUrl(key, departureLatLong.get(), arrivalLatLong.get()));
        mapView.put("viewType", "html");
        response.setView(mapView);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) HashMap(java.util.HashMap) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) AddressService(com.axelor.apps.base.service.AddressService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AddressRepository(com.axelor.apps.base.db.repo.AddressRepository) PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) MapService(com.axelor.apps.base.service.MapService) Pair(org.apache.commons.lang3.tuple.Pair)

Example 12 with Address

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

the class AddressController method updateLatLong.

public void updateLatLong(ActionRequest request, ActionResponse response) {
    AddressService addressService = Beans.get(AddressService.class);
    try {
        Address address = request.getContext().asType(Address.class);
        address = Beans.get(AddressRepository.class).find(address.getId());
        addressService.resetLatLong(address);
        addressService.updateLatLong(address);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AddressService(com.axelor.apps.base.service.AddressService) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 13 with Address

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

the class AddressController method autocompleteAddress.

public void autocompleteAddress(ActionRequest request, ActionResponse response) {
    Address address = request.getContext().asType(Address.class);
    Beans.get(AddressService.class).autocompleteAddress(address);
    response.setValues(address);
}
Also used : PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) AddressService(com.axelor.apps.base.service.AddressService)

Example 14 with Address

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

the class SyncContactService method createAddress.

protected Address createAddress(com.google.api.services.people.v1.model.Address googleAddr) {
    Address partnerAddr = new Address();
    Country partnerCountry = countryRepo.findByName(googleAddr.getCountry());
    if (partnerCountry == null) {
        partnerCountry = createCountry(googleAddr.getCountry(), googleAddr.getCountryCode());
    }
    partnerAddr.setAddressL7Country(partnerCountry);
    if (!Strings.isNullOrEmpty(googleAddr.getCity())) {
        City partnerCity = cityRepo.findByName(googleAddr.getCity());
        if (partnerCity == null) {
            partnerCity = createCity(googleAddr.getCity(), partnerCountry);
        }
        partnerAddr.setCity(partnerCity);
    }
    StringBuilder addrL4 = new StringBuilder();
    if (!Strings.isNullOrEmpty(googleAddr.getPoBox())) {
        addrL4.append(googleAddr.getPoBox()).append(" - ");
    }
    partnerAddr.setZip(googleAddr.getPostalCode());
    addrL4.append(googleAddr.getStreetAddress());
    partnerAddr.setAddressL4(addrL4.toString());
    partnerAddr.setAddressL5(googleAddr.getCity());
    partnerAddr.setAddressL2(googleAddr.getExtendedAddress());
    partnerAddr.setAddressL6(googleAddr.getPostalCode() + " " + googleAddr.getCity());
    partnerAddr.setFullName(Beans.get(AddressService.class).computeFullName(partnerAddr));
    partnerAddr.setImportOrigin(importOrigin);
    return partnerAddr;
}
Also used : EmailAddress(com.axelor.apps.message.db.EmailAddress) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) Country(com.axelor.apps.base.db.Country) City(com.axelor.apps.base.db.City)

Example 15 with Address

use of com.axelor.apps.base.db.Address 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)

Aggregations

Address (com.axelor.apps.base.db.Address)32 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)18 AxelorException (com.axelor.exception.AxelorException)15 Partner (com.axelor.apps.base.db.Partner)13 AddressService (com.axelor.apps.base.service.AddressService)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 EmailAddress (com.axelor.apps.message.db.EmailAddress)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PartnerService (com.axelor.apps.base.service.PartnerService)5 Map (java.util.Map)4 Invoice (com.axelor.apps.account.db.Invoice)3 Company (com.axelor.apps.base.db.Company)3 Country (com.axelor.apps.base.db.Country)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 StockMove (com.axelor.apps.stock.db.StockMove)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3