Search in sources :

Example 51 with BankDetails

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

the class ReimbursementExportService method updatePartnerCurrentRIB.

/**
 * Procédure permettant de mettre à jour la liste des RIBs du tiers
 *
 * @param reimbursement Un remboursement
 */
@Transactional
public void updatePartnerCurrentRIB(Reimbursement reimbursement) {
    BankDetails bankDetails = reimbursement.getBankDetails();
    Partner partner = reimbursement.getPartner();
    BankDetails defaultBankDetails = partnerService.getDefaultBankDetails(partner);
    if (partner != null && bankDetails != null && !bankDetails.equals(defaultBankDetails)) {
        bankDetails.setIsDefault(true);
        defaultBankDetails.setIsDefault(false);
        partner.addBankDetailsListItem(bankDetails);
        partnerRepository.save(partner);
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 52 with BankDetails

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

the class ReimbursementService method updatePartnerCurrentRIB.

/**
 * Procédure permettant de mettre à jour la liste des RIBs du tiers
 *
 * @param reimbursement Un remboursement
 */
@Transactional
public void updatePartnerCurrentRIB(Reimbursement reimbursement) {
    BankDetails bankDetails = reimbursement.getBankDetails();
    Partner partner = reimbursement.getPartner();
    BankDetails defaultBankDetails = partnerService.getDefaultBankDetails(partner);
    if (bankDetails != null && partner != null && !bankDetails.equals(defaultBankDetails)) {
        defaultBankDetails.setIsDefault(false);
        bankDetails.setIsDefault(true);
        partner.addBankDetailsListItem(bankDetails);
        partnerRepository.save(partner);
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 53 with BankDetails

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

the class BankDetailsServiceAccountImpl method createCompanyBankDetailsDomainFromFactorPartner.

private List<BankDetails> createCompanyBankDetailsDomainFromFactorPartner(Company company) throws AxelorException {
    AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
    List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
    return bankDetailsList.stream().filter(bankDetails -> bankDetails.getActive()).collect(Collectors.toList());
}
Also used : Company(com.axelor.apps.base.db.Company) StringTool(com.axelor.apps.tool.StringTool) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AccountConfig(com.axelor.apps.account.db.AccountConfig) AccountManagement(com.axelor.apps.account.db.AccountManagement) PaymentModeRepository(com.axelor.apps.account.db.repo.PaymentModeRepository) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) AxelorException(com.axelor.exception.AxelorException) Beans(com.axelor.inject.Beans) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) PaymentMode(com.axelor.apps.account.db.PaymentMode) BankDetailsServiceImpl(com.axelor.apps.base.service.BankDetailsServiceImpl) Partner(com.axelor.apps.base.db.Partner) BankDetails(com.axelor.apps.base.db.BankDetails) BankDetails(com.axelor.apps.base.db.BankDetails) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 54 with BankDetails

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

the class BankDetailsServiceAccountImpl method createCompanyBankDetailsDomain.

/**
 * In this implementation, we use the O2M in payment mode.
 *
 * @param company
 * @param paymentMode
 * @return
 * @throws AxelorException
 */
@Override
public String createCompanyBankDetailsDomain(Partner partner, Company company, PaymentMode paymentMode, Integer operationTypeSelect) throws AxelorException {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (!appAccountService.isApp("account") || !appAccountService.getAppBase().getManageMultiBanks()) {
        return super.createCompanyBankDetailsDomain(partner, company, paymentMode, operationTypeSelect);
    } else {
        if (partner != null) {
            partner = Beans.get(PartnerRepository.class).find(partner.getId());
        }
        List<BankDetails> authorizedBankDetails = new ArrayList<>();
        if (partner != null && partner.getFactorizedCustomer() && operationTypeSelect != null && (operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_SALE || operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND)) {
            authorizedBankDetails = createCompanyBankDetailsDomainFromFactorPartner(company);
        } else {
            if (paymentMode == null) {
                return "self.id IN (0)";
            }
            List<AccountManagement> accountManagementList = paymentMode.getAccountManagementList();
            authorizedBankDetails = new ArrayList<>();
            for (AccountManagement accountManagement : accountManagementList) {
                if (accountManagement.getCompany() != null && accountManagement.getCompany().equals(company)) {
                    authorizedBankDetails.add(accountManagement.getBankDetails());
                }
            }
        }
        if (authorizedBankDetails.isEmpty()) {
            return "self.id IN (0)";
        } else {
            return "self.id IN (" + StringTool.getIdListString(authorizedBankDetails) + ") AND self.active = true";
        }
    }
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 55 with BankDetails

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

the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetails.

/**
 * Find a default bank details.
 *
 * @param company
 * @param paymentMode
 * @param partner
 * @return the default bank details in accounting situation if it is active and allowed by the
 *     payment mode, or an authorized bank details if he is the only one authorized.
 * @throws AxelorException
 */
@Override
public BankDetails getDefaultCompanyBankDetails(Company company, PaymentMode paymentMode, Partner partner, Integer operationTypeSelect) throws AxelorException {
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (!appAccountService.isApp("account") || !appAccountService.getAppBase().getManageMultiBanks()) {
        return super.getDefaultCompanyBankDetails(company, paymentMode, partner, operationTypeSelect);
    } else {
        if (partner != null && partner.getFactorizedCustomer() && operationTypeSelect != null && (operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_SALE || operationTypeSelect.intValue() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND)) {
            return getDefaultCompanyBankDetailsFromFactorPartner(company);
        } else {
            if (paymentMode == null) {
                return null;
            }
            BankDetails candidateBankDetails = getDefaultCompanyBankDetailsFromPartner(company, paymentMode, partner);
            List<BankDetails> authorizedBankDetails = Beans.get(PaymentModeService.class).getCompatibleBankDetailsList(paymentMode, company);
            if (candidateBankDetails != null && authorizedBankDetails.contains(candidateBankDetails) && candidateBankDetails.getActive()) {
                return candidateBankDetails;
            } else // we did not find a bank details in accounting situation
            {
                if (authorizedBankDetails.size() == 1) {
                    return authorizedBankDetails.get(0);
                }
            }
        }
        return null;
    }
}
Also used : PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) BankDetails(com.axelor.apps.base.db.BankDetails) AppAccountService(com.axelor.apps.account.service.app.AppAccountService)

Aggregations

BankDetails (com.axelor.apps.base.db.BankDetails)63 Partner (com.axelor.apps.base.db.Partner)26 AxelorException (com.axelor.exception.AxelorException)26 PaymentMode (com.axelor.apps.account.db.PaymentMode)22 Company (com.axelor.apps.base.db.Company)22 BigDecimal (java.math.BigDecimal)14 LocalDate (java.time.LocalDate)13 Transactional (com.google.inject.persist.Transactional)12 ArrayList (java.util.ArrayList)11 Invoice (com.axelor.apps.account.db.Invoice)10 Journal (com.axelor.apps.account.db.Journal)9 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)8 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)7 Currency (com.axelor.apps.base.db.Currency)7 Account (com.axelor.apps.account.db.Account)6 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)6 Move (com.axelor.apps.account.db.Move)6 MoveLine (com.axelor.apps.account.db.MoveLine)6