Search in sources :

Example 6 with Country

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

the class AddressServiceImpl method autocompleteAddress.

@Override
public void autocompleteAddress(Address address) {
    String zip = address.getZip();
    if (zip == null) {
        return;
    }
    Country country = address.getAddressL7Country();
    List<City> cities = cityRepository.findByZipAndCountry(zip, country).fetch();
    City city = cities.size() == 1 ? cities.get(0) : null;
    address.setCity(city);
    address.setAddressL6(city != null ? zip + " " + city.getName() : null);
    if (appBaseService.getAppBase().getStoreStreets()) {
        List<Street> streets = streetRepository.all().filter("self.city = :city").bind("city", city).fetch();
        if (streets.size() == 1) {
            Street street = streets.get(0);
            address.setStreet(street);
            String name = street.getName();
            String num = address.getStreetNumber();
            address.setAddressL4(num != null ? num + " " + name : name);
        } else {
            address.setStreet(null);
            address.setAddressL4(null);
        }
    }
}
Also used : Country(com.axelor.apps.base.db.Country) Street(com.axelor.apps.base.db.Street) City(com.axelor.apps.base.db.City)

Example 7 with Country

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

the class BankServiceImpl method splitBic.

@Override
public void splitBic(Bank bank) {
    String bic = bank.getCode();
    // BNPA FR PP XXX
    // 0123 45 67 8910
    bank.setBusinessPartyPrefix(bic.substring(0, 4));
    String alpha2 = bic.substring(4, 6);
    Country country = Beans.get(CountryRepository.class).all().filter("alpha2code = ?", alpha2).fetchOne();
    bank.setCountry(country);
    bank.setBusinessPartySuffix(bic.substring(6, 8));
    String branchId;
    try {
        branchId = bic.substring(8, 11);
    } catch (IndexOutOfBoundsException e) {
        branchId = "XXX";
    } catch (Exception e) {
        throw e;
    }
    bank.setBranchIdentifier(branchId);
}
Also used : CountryRepository(com.axelor.apps.base.db.repo.CountryRepository) Country(com.axelor.apps.base.db.Country)

Example 8 with Country

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

the class BankOrderFileAFB320XCTService method createDetailRecord.

/**
 * Method to create a recipient record for international transfer AFB320
 *
 * @param bankOrderLine
 * @return
 * @throws AxelorException
 */
protected String createDetailRecord(BankOrderLine bankOrderLine) throws AxelorException {
    try {
        BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
        // Zone 1 : Code enregistrement
        String detailRecord = cfonbToolService.createZone("1", "04", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
        // Zone 2 : Code opération
        detailRecord += cfonbToolService.createZone("2", OPERATION_CODE_PI, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
        // Zone 3 : Numéro séquentiel
        detailRecord += cfonbToolService.createZone("3", sequence++, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 6);
        // national, "0" : Autre )
        if (receiverBankDetails.getBank() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_RECEIVER_BANK_DETAILS_MISSING_BANK));
        }
        detailRecord += cfonbToolService.createZone(I18n.get("4 - Bank details type"), receiverBankDetails.getBank().getBankDetailsTypeSelect(), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
        // Zone 5 : Identifiant du compte du bénéficiaire
        detailRecord += cfonbToolService.createZone(I18n.get("5 - Bank details IBAN"), getIban(receiverBankDetails), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, 34);
        // Zone 6 et 7 attribution des longueurs des zones en fonction de la longueur du nom:
        int ownerNameLength = receiverBankDetails.getOwnerName().length();
        int adressLength = 3 * 35;
        if (ownerNameLength <= 35) {
            ownerNameLength = 35;
        } else if (35 < ownerNameLength && ownerNameLength <= 70) {
            adressLength = 3 * 35 - (ownerNameLength - 35);
        } else if (ownerNameLength > 70) {
            ownerNameLength = 2 * 35;
            adressLength = 2 * 35;
        }
        // Zone 6 : Nom du bénéficiaire
        detailRecord += cfonbToolService.createZone(I18n.get("6 - Bank details owner name"), receiverBankDetails.getOwnerName(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, ownerNameLength);
        // Zone 7 : Adresse du bénéficiaire (Obligatoire si mode de règlement par chèque (zone 18 =
        // "1" ou "2")
        // Si le nom du bénéficiaire contient plus de 35 caractères, utiliser le début de la première
        // zone pour le compléter et le reste de cette zone pour indiquer le début de l'adresse)
        detailRecord += cfonbToolService.createZone("7", getReceiverAddress(bankOrderLine), cfonbToolService.STATUS_DEPENDENT, cfonbToolService.FORMAT_ALPHA_NUMERIC, adressLength);
        // Zone 8 : Identification nationale du bénéficiaire (Cette zone n'est pas utilisée)
        detailRecord += cfonbToolService.createZone("8", "", cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 17);
        // Zone 9 : Code pays du bénéficiaire (Norme ISO)
        Country receiverCountry = bankOrderLine.getReceiverCountry();
        String countryCode = "";
        if (receiverCountry != null) {
            countryCode = receiverCountry.getAlpha2Code();
        }
        detailRecord += cfonbToolService.createZone(I18n.get("9 - Country code"), countryCode, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
        // Zone 10 : Référence de l'opération
        detailRecord += cfonbToolService.createZone(I18n.get("10 - Sequence"), bankOrderLine.getSequence(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 16);
        // Zone 11 : Qualifiant du montant de l'ordre :
        // "T" : Montant exprimé dans la devise du transfert
        // "D" : Montant équivalent exprimé dans la devise du compte à débiter. Cette valeur ne doit
        // être utilisée que lorsque la devise du compte à débiter est différente de celle du
        // transfert.
        String qualifyngOfAmountStr;
        if (senderCurrency.equals(bankOrderCurrency)) {
            qualifyngOfAmountStr = BankOrderFileFormatRepository.QUALIFYING_AMOUNT_TRANSFER_CURRENCY;
        } else {
            qualifyngOfAmountStr = qualityOfAmount;
            if (Strings.isNullOrEmpty(qualifyngOfAmountStr)) {
                qualifyngOfAmountStr = BankOrderFileFormatRepository.QUALIFYING_AMOUNT_TRANSFER_CURRENCY;
            }
        }
        detailRecord += cfonbToolService.createZone("11", qualifyngOfAmountStr, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
        // Zone 12 : Zone réservée
        detailRecord += cfonbToolService.createZone("12", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 4);
        // Zone 13 : Montant de l'ordre (Le montant comporte le nombre de décimales indiqué dans la
        // zone "Nombre de décimales" du même enregistrement)
        BigDecimal orderAmount;
        if (qualifyngOfAmountStr.equals(BankOrderFileFormatRepository.QUALIFYING_AMOUNT_SENDER_BANK_DETAILS_CURRENCY)) {
            orderAmount = bankOrderLine.getCompanyCurrencyAmount();
        } else {
            orderAmount = bankOrderLine.getBankOrderAmount();
        }
        detailRecord += cfonbToolService.createZone("13", orderAmount, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 14);
        // Zone 14 : Nombre de décimales
        detailRecord += cfonbToolService.createZone("14", "2", cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, // TODO
        1);
        // Zone 15 : Zone réservée
        detailRecord += cfonbToolService.createZone("15", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
        // Zone 16 : Code motif économique (3 caract. numériques ou valeur "NNN" )
        BankOrderEconomicReason bankOrderEconomicReason = bankOrderLine.getBankOrderEconomicReason();
        String bankOrderEconomicReasonCode = "NNN";
        if (bankOrderEconomicReason != null) {
            bankOrderEconomicReasonCode = bankOrderEconomicReason.getCode();
        }
        detailRecord += cfonbToolService.createZone(I18n.get("16 - Economic reason code"), bankOrderEconomicReasonCode, cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
        // Zone 17 : Zone réservée
        detailRecord += cfonbToolService.createZone("17", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 2);
        // Zone 18 : Mode de règlement ("0" = Virement ou autre sauf chèque, "1" ou "2" = par chèque)
        detailRecord += cfonbToolService.createZone(I18n.get("18 - Payment mode select"), bankOrderLine.getPaymentModeSelect(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 1);
        // Zone 19 : Code imputation des frais ("13" = Bénéficiaire (BEN), "14" = Emetteur et
        // Bénéficiaire (SHA), "15" = Emetteur (OUR))
        detailRecord += cfonbToolService.createZone(I18n.get("19 - Fees imputation mode"), bankOrderLine.getFeesImputationModeSelect(), cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 2);
        // Zone 23 : Zone réservée
        detailRecord += cfonbToolService.createZone("23", "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 57);
        // Zone 24-1 : Qualifiant de la date ("203" (date d'exécution demandée))
        detailRecord += cfonbToolService.createZone(I18n.get("24-1 - Qualifying of date"), bankOrderFileFormat.getQualifyingOfDate(), cfonbToolService.STATUS_OPTIONAL, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
        // l'"Entête" = "3" ou "4"), pour les autres remises, elle ne doit pas être renseignée.)
        if (isMultiDates) {
            String bankOrderDate = "";
            if (bankOrderLine.getBankOrderDate() != null) {
                bankOrderDate = bankOrderLine.getBankOrderDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
            }
            detailRecord += cfonbToolService.createZone(I18n.get("24-2 - Date"), bankOrderDate, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_NUMERIC, 8);
        } else {
            detailRecord += cfonbToolService.createZone(I18n.get("24-2 - Date"), "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_NUMERIC, 8);
        }
        // renseignée.
        if (isMultiCurrencies) {
            String bankOrderCurrencyCode = "";
            if (bankOrderLine.getBankOrderCurrency() != null) {
                bankOrderCurrencyCode = bankOrderLine.getBankOrderCurrency().getCode();
            }
            detailRecord += cfonbToolService.createZone(I18n.get("25 - Currency"), bankOrderCurrencyCode, cfonbToolService.STATUS_MANDATORY, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
        } else {
            detailRecord += cfonbToolService.createZone(I18n.get("25 - Currency"), "", cfonbToolService.STATUS_NOT_USED, cfonbToolService.FORMAT_ALPHA_NUMERIC, 3);
        }
        cfonbToolService.toUpperCase(detailRecord);
        cfonbToolService.testLength(detailRecord, NB_CHAR_PER_LINE);
        return detailRecord;
    } catch (Exception e) {
        throw new AxelorException(e, bankOrderLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.BANK_ORDER_WRONG_MAIN_DETAIL_RECORD) + ": " + e.getMessage(), bankOrderLine.getSequence());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) BankOrderEconomicReason(com.axelor.apps.bankpayment.db.BankOrderEconomicReason) BankOrderFileFormatCountry(com.axelor.apps.bankpayment.db.BankOrderFileFormatCountry) Country(com.axelor.apps.base.db.Country) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 9 with Country

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

the class StockMoveLineServiceImpl method checkMassesRequired.

@Override
public boolean checkMassesRequired(StockMove stockMove, StockMoveLine stockMoveLine) {
    Address fromAddress = stockMoveToolService.getFromAddress(stockMove);
    Address toAddress = stockMoveToolService.getToAddress(stockMove);
    Country fromCountry = fromAddress != null ? fromAddress.getAddressL7Country() : null;
    Country toCountry = toAddress != null ? toAddress.getAddressL7Country() : null;
    return fromCountry != null && toCountry != null && !fromCountry.equals(toCountry) && stockMoveLine.getProduct() != null && fromCountry.getEconomicArea() != null && fromCountry.getEconomicArea().equals(toCountry.getEconomicArea()) && stockMoveLine.getProduct().getUsedInDEB();
}
Also used : Address(com.axelor.apps.base.db.Address) Country(com.axelor.apps.base.db.Country)

Aggregations

Country (com.axelor.apps.base.db.Country)9 Address (com.axelor.apps.base.db.Address)3 City (com.axelor.apps.base.db.City)2 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 BigDecimal (java.math.BigDecimal)2 BankOrderEconomicReason (com.axelor.apps.bankpayment.db.BankOrderEconomicReason)1 BankOrderFileFormatCountry (com.axelor.apps.bankpayment.db.BankOrderFileFormatCountry)1 Bank (com.axelor.apps.base.db.Bank)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 PartnerAddress (com.axelor.apps.base.db.PartnerAddress)1 Street (com.axelor.apps.base.db.Street)1 CountryRepository (com.axelor.apps.base.db.repo.CountryRepository)1 Lead (com.axelor.apps.crm.db.Lead)1 LeadRepository (com.axelor.apps.crm.db.repo.LeadRepository)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 AxelorException (com.axelor.exception.AxelorException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Transactional (com.google.inject.persist.Transactional)1