Search in sources :

Example 16 with Address

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

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

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

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

Example 20 with Address

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

the class DeclarationOfExchangesExporterGoods method exportLineToCsv.

protected String[] exportLineToCsv(StockMoveLine stockMoveLine, int lineNum) throws AxelorException {
    String[] data = new String[columnHeadersList.size()];
    StockMove stockMove = stockMoveLine.getStockMove();
    String customsCode = stockMoveLine.getCustomsCode();
    Product product = stockMoveLine.getProduct();
    if (StringUtils.isBlank(customsCode)) {
        if (product == null) {
            customsCode = I18n.get("Product is missing.");
        }
        if (product != null && product.getCustomsCodeNomenclature() != null) {
            customsCode = product.getCustomsCodeNomenclature().getCode();
        }
        if (StringUtils.isBlank(customsCode)) {
            customsCode = String.format(I18n.get("Customs code nomenclature is missing on product %s."), product.getCode());
        }
    }
    BigDecimal fiscalValue = stockMoveLine.getCompanyUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
    // Only positive fiscal value should be take into account
    if (fiscalValue.compareTo(BigDecimal.ZERO) <= 0) {
        return new String[0];
    }
    Regime regime = stockMoveLine.getRegime();
    if (regime == null) {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
            regime = Regime.EXONERATED_SHIPMENT_AND_TRANSFER;
        } else if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            regime = Regime.INTRACOMMUNITY_ACQUISITION_TAXABLE_IN_FRANCE;
        }
    }
    BigDecimal totalNetMass = stockMoveLine.getTotalNetMass().setScale(0, RoundingMode.HALF_UP);
    BigInteger supplementaryUnit = stockMoveLine.getRealQty().setScale(0, RoundingMode.CEILING).toBigInteger();
    NatureOfTransaction natTrans = stockMoveLine.getNatureOfTransaction();
    if (natTrans == null) {
        natTrans = stockMove.getIsReversion() ? NatureOfTransaction.RETURN_OF_GOODS : NatureOfTransaction.FIRM_PURCHASE_OR_SALE;
    }
    ModeOfTransport modeOfTransport = stockMove.getModeOfTransport();
    if (modeOfTransport == null) {
        modeOfTransport = ModeOfTransport.CONSIGNMENTS_BY_POST;
    }
    String srcDstCountry;
    String dept;
    try {
        Address partnerAddress = stockMoveToolService.getPartnerAddress(stockMoveLine.getStockMove());
        srcDstCountry = partnerAddress.getAddressL7Country().getAlpha2Code();
    } catch (AxelorException e) {
        srcDstCountry = e.getMessage();
    }
    try {
        Address companyAddress = stockMoveToolService.getCompanyAddress(stockMoveLine.getStockMove());
        dept = companyAddress.getCity().getDepartment().getCode();
    } catch (AxelorException e) {
        dept = e.getMessage();
    }
    String countryOrigCode;
    if (stockMoveLine.getCountryOfOrigin() != null) {
        countryOrigCode = stockMoveLine.getCountryOfOrigin().getAlpha2Code();
    } else {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            countryOrigCode = srcDstCountry;
        } else {
            countryOrigCode = "";
        }
    }
    String taxNbr;
    if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
        if (stockMove.getPartner() == null) {
            taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
        } else if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
            taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
        } else {
            taxNbr = stockMove.getPartner().getTaxNbr();
        }
    } else {
        taxNbr = "";
    }
    String partnerSeq = "";
    if (stockMove.getPartner() != null) {
        partnerSeq = stockMove.getPartner().getPartnerSeq();
    }
    String productCode = "";
    String productName = "";
    if (product != null) {
        productCode = product.getCode();
        productName = product.getName();
    }
    String invoiceId = "";
    Set<Invoice> invoiceSet = stockMove.getInvoiceSet();
    if (invoiceSet != null) {
        for (Invoice invoice : invoiceSet) {
            if (invoice.getStatusSelect() == InvoiceRepository.STATUS_VENTILATED) {
                invoiceId += invoice.getInvoiceId() + "|";
            }
        }
        if (invoiceId != null && !invoiceId.isEmpty()) {
            invoiceId = invoiceId.substring(0, invoiceId.length() - 1);
        }
    }
    data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum);
    data[columnHeadersList.indexOf(NOMENCLATURE)] = customsCode;
    data[columnHeadersList.indexOf(SRC_DST_COUNTRY)] = srcDstCountry;
    data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
    data[columnHeadersList.indexOf(REGIME)] = String.valueOf(regime.getValue());
    data[columnHeadersList.indexOf(MASS)] = String.valueOf(totalNetMass);
    data[columnHeadersList.indexOf(UNITS)] = String.valueOf(supplementaryUnit);
    data[columnHeadersList.indexOf(NAT_TRANS)] = String.valueOf(natTrans.getValue());
    data[columnHeadersList.indexOf(TRANSP)] = String.valueOf(modeOfTransport.getValue());
    data[columnHeadersList.indexOf(DEPT)] = dept;
    data[columnHeadersList.indexOf(COUNTRY_ORIG)] = countryOrigCode;
    data[columnHeadersList.indexOf(ACQUIRER)] = taxNbr;
    data[columnHeadersList.indexOf(PRODUCT_CODE)] = productCode;
    data[columnHeadersList.indexOf(PRODUCT_NAME)] = productName;
    data[columnHeadersList.indexOf(PARTNER_SEQ)] = partnerSeq;
    data[columnHeadersList.indexOf(INVOICE)] = invoiceId;
    return data;
}
Also used : Regime(com.axelor.apps.stock.db.Regime) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) Product(com.axelor.apps.base.db.Product) NatureOfTransaction(com.axelor.apps.stock.db.NatureOfTransaction) BigDecimal(java.math.BigDecimal) ModeOfTransport(com.axelor.apps.stock.db.ModeOfTransport) BigInteger(java.math.BigInteger)

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