Search in sources :

Example 21 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.

the class AccountingSituationServiceImpl method getSupplierAccount.

@Override
public Account getSupplierAccount(Partner partner, Company company) throws AxelorException {
    Account account = null;
    AccountingSituation accountingSituation = getAccountingSituation(partner, company);
    if (accountingSituation != null) {
        account = accountingSituation.getSupplierAccount();
    }
    if (account == null) {
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        account = accountConfigService.getSupplierAccount(accountConfig);
    }
    return account;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 22 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.

the class AccountingSituationServiceImpl method getEmployeeAccount.

@Override
public Account getEmployeeAccount(Partner partner, Company company) throws AxelorException {
    Account account = null;
    AccountingSituation accountingSituation = getAccountingSituation(partner, company);
    if (accountingSituation != null) {
        account = accountingSituation.getEmployeeAccount();
    }
    if (account == null) {
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        account = accountConfigService.getEmployeeAccount(accountConfig);
    }
    return account;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 23 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.

the class DebtRecoveryService method getReferenceDate.

/**
 * Fonction qui détermine la date de référence
 *
 * @param debtRecovery Une relance
 * @return La date de référence
 */
public LocalDate getReferenceDate(DebtRecovery debtRecovery) {
    AccountingSituation accountingSituation = this.getAccountingSituation(debtRecovery);
    List<MoveLine> moveLineList = this.getMoveLineDebtRecovery(accountingSituation.getPartner(), accountingSituation.getCompany(), debtRecovery.getTradingName());
    // Date la plus ancienne des lignes d'écriture
    LocalDate minMoveLineDate = getOldDateMoveLine(moveLineList);
    log.debug("minMoveLineDate : {}", minMoveLineDate);
    // 2: Date la plus récente des relances
    LocalDate debtRecoveryLastDate = getLastDateDebtRecovery(debtRecovery);
    log.debug("debtRecoveryLastDate : {}", debtRecoveryLastDate);
    // Date de référence : Date la plus récente des deux ensembles (1 et 2)
    LocalDate debtRecoveryRefDate = getLastDate(minMoveLineDate, debtRecoveryLastDate);
    log.debug("debtRecoveryRefDate : {}", debtRecoveryRefDate);
    return debtRecoveryRefDate;
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation) MoveLine(com.axelor.apps.account.db.MoveLine) LocalDate(java.time.LocalDate)

Example 24 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.

the class DebtRecoveryService method debtRecoveryGenerate.

/**
 * Handle the debt recovery process for a partner and company. Can optionally specify a trading
 * name.
 *
 * @param partner The partner that has debts to be recovered
 * @param company The company for which to recover the debts
 * @param tradingName (optional) A trading name of the company for which to recover the debts
 * @throws AxelorException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 * @throws IOException
 */
@Transactional(rollbackOn = { Exception.class })
public boolean debtRecoveryGenerate(Partner partner, Company company, TradingName tradingName) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, JSONException {
    boolean remindedOk = false;
    DebtRecovery debtRecovery = this.getDebtRecovery(partner, company, // getDebtRecovery if one already exists
    tradingName);
    BigDecimal balanceDue = accountCustomerService.getBalanceDue(partner, company, tradingName);
    if (balanceDue.compareTo(BigDecimal.ZERO) > 0) {
        log.debug("balanceDue : {} ", balanceDue);
        BigDecimal balanceDueDebtRecovery = accountCustomerService.getBalanceDueDebtRecovery(partner, company, tradingName);
        if (balanceDueDebtRecovery.compareTo(BigDecimal.ZERO) > 0) {
            log.debug("balanceDueDebtRecovery : {} ", balanceDueDebtRecovery);
            remindedOk = true;
            if (debtRecovery == null) {
                AccountingSituationRepository accSituationRepo = Beans.get(AccountingSituationRepository.class);
                AccountingSituation accountingSituation = accSituationRepo.all().filter("self.partner = ?1 and self.company = ?2", partner, company).fetchOne();
                debtRecovery = this.createDebtRecovery(accountingSituation, tradingName);
            }
            debtRecovery.setCompany(companyRepo.find(company.getId()));
            if (tradingName != null)
                debtRecovery.setTradingName(tradingNameRepo.find(tradingName.getId()));
            debtRecovery.setCurrency(partner.getCurrency());
            debtRecovery.setBalanceDue(balanceDue);
            List<MoveLine> moveLineList = this.getMoveLineDebtRecovery(partner, company, tradingName);
            this.updateInvoiceDebtRecovery(debtRecovery, this.getInvoiceList(moveLineList));
            this.updatePaymentScheduleLineDebtRecovery(debtRecovery, this.getPaymentScheduleList(moveLineList, partner));
            debtRecovery.setBalanceDueDebtRecovery(balanceDueDebtRecovery);
            Integer levelDebtRecovery = -1;
            if (debtRecovery.getDebtRecoveryMethodLine() != null) {
                levelDebtRecovery = debtRecovery.getDebtRecoveryMethodLine().getSequence();
            }
            LocalDate referenceDate = this.getReferenceDate(debtRecovery);
            if (referenceDate != null) {
                log.debug("date de référence : {} ", referenceDate);
                debtRecovery.setReferenceDate(referenceDate);
            } else {
                throw new AxelorException(debtRecovery, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "%s :\n" + I18n.get("Partner") + " %s, " + I18n.get("Company") + " %s : " + tradingName != null ? I18n.get("Trading name") + " %s : " : "" + I18n.get(IExceptionMessage.DEBT_RECOVERY_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), company.getName());
            }
            if (debtRecovery.getDebtRecoveryMethod() == null) {
                DebtRecoveryMethod debtRecoveryMethod = debtRecoverySessionService.getDebtRecoveryMethod(debtRecovery);
                if (debtRecoveryMethod != null) {
                    debtRecovery.setDebtRecoveryMethod(debtRecoveryMethod);
                    debtRecoverySessionService.debtRecoverySession(debtRecovery);
                } else {
                    throw new AxelorException(debtRecovery, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "%s :\n" + I18n.get("Partner") + " %s, " + I18n.get("Company") + " %s : " + tradingName != null ? I18n.get("Trading name") + " %s : " : "" + I18n.get(IExceptionMessage.DEBT_RECOVERY_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), company.getName());
                }
            } else {
                debtRecoverySessionService.debtRecoverySession(debtRecovery);
            }
            if (debtRecovery.getWaitDebtRecoveryMethodLine() == null) {
                // Si le niveau de relance a évolué
                if (debtRecovery.getDebtRecoveryMethodLine() != null && debtRecovery.getDebtRecoveryMethodLine().getSequence() > levelDebtRecovery) {
                    debtRecoveryActionService.runAction(debtRecovery);
                    DebtRecoveryHistory debtRecoveryHistory = debtRecoveryActionService.getDebtRecoveryHistory(debtRecovery);
                    if (CollectionUtils.isEmpty(messageRepo.findByRelatedTo(Math.toIntExact(debtRecoveryHistory.getId()), DebtRecoveryHistory.class.getCanonicalName()).fetch())) {
                        debtRecoveryActionService.runMessage(debtRecovery);
                    }
                }
            } else {
                log.debug("Tiers {}, Société {} - Niveau de relance en attente ", partner.getName(), company.getName());
                // TODO Alarm ?
                TraceBackService.trace(new AxelorException(debtRecovery, TraceBackRepository.CATEGORY_INCONSISTENCY, "%s :\n" + I18n.get("Partner") + " %s, " + I18n.get("Company") + " %s : " + I18n.get(IExceptionMessage.DEBT_RECOVERY_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), company.getName()));
            }
        } else {
            debtRecoverySessionService.debtRecoveryInitialization(debtRecovery);
        }
    } else {
        debtRecoverySessionService.debtRecoveryInitialization(debtRecovery);
    }
    return remindedOk;
}
Also used : AxelorException(com.axelor.exception.AxelorException) DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory) DebtRecoveryMethod(com.axelor.apps.account.db.DebtRecoveryMethod) AccountingSituationRepository(com.axelor.apps.account.db.repo.AccountingSituationRepository) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) MoveLine(com.axelor.apps.account.db.MoveLine) DebtRecovery(com.axelor.apps.account.db.DebtRecovery) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 25 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.

the class DebtRecoveryService method getDebtRecovery.

/**
 * Find an existing debtRecovery object for a corresponding partner, company and optionally,
 * trading name.
 *
 * @param partner A partner
 * @param company A company
 * @param tradingName (Optional) A trading name
 * @return The corresponding DebtRecovery object, storing information regarding the current debt
 *     recovery situation of the partner for this company & trading name
 * @throws AxelorException
 */
public DebtRecovery getDebtRecovery(Partner partner, Company company, TradingName tradingName) throws AxelorException {
    AccountingSituationRepository accSituationRepo = Beans.get(AccountingSituationRepository.class);
    AccountingSituation accountingSituation = accSituationRepo.all().filter("self.partner = ?1 and self.company = ?2", partner, company).fetchOne();
    if (accountingSituation == null) {
        throw new AxelorException(accountingSituation, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "%s :\n" + I18n.get("Partner") + " %s, " + I18n.get("Company") + " %s : " + I18n.get(IExceptionMessage.DEBT_RECOVERY_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), company.getName());
    }
    if (tradingName == null) {
        return accountingSituation.getDebtRecovery();
    } else {
        if (accountingSituation.getTradingNameDebtRecoveryList() != null && !accountingSituation.getTradingNameDebtRecoveryList().isEmpty()) {
            for (DebtRecovery debtRecovery : accountingSituation.getTradingNameDebtRecoveryList()) {
                if (tradingName.equals(debtRecovery.getTradingName())) {
                    return debtRecovery;
                }
            }
        }
    }
    // if no debtRecovery has been found for the specified tradingName
    return null;
}
Also used : AxelorException(com.axelor.exception.AxelorException) AccountingSituationRepository(com.axelor.apps.account.db.repo.AccountingSituationRepository) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) DebtRecovery(com.axelor.apps.account.db.DebtRecovery)

Aggregations

AccountingSituation (com.axelor.apps.account.db.AccountingSituation)26 Partner (com.axelor.apps.base.db.Partner)9 Company (com.axelor.apps.base.db.Company)8 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 AxelorException (com.axelor.exception.AxelorException)6 AccountingSituationService (com.axelor.apps.account.service.AccountingSituationService)5 Transactional (com.google.inject.persist.Transactional)5 BankDetails (com.axelor.apps.base.db.BankDetails)4 BigDecimal (java.math.BigDecimal)4 Account (com.axelor.apps.account.db.Account)3 DebtRecovery (com.axelor.apps.account.db.DebtRecovery)3 Invoice (com.axelor.apps.account.db.Invoice)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingSituationRepository (com.axelor.apps.account.db.repo.AccountingSituationRepository)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 MoveLine (com.axelor.apps.account.db.MoveLine)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 Address (com.axelor.apps.base.db.Address)2