Search in sources :

Example 1 with DebtRecoveryMethodLine

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

the class DebtRecoverySessionService method debtRecoverySession.

/**
 * Session de relance
 *
 * @param debtRecovery Une relance
 * @throws AxelorException
 */
public DebtRecovery debtRecoverySession(DebtRecovery debtRecovery) throws AxelorException {
    log.debug("Begin debtRecoverySession service...");
    LocalDate referenceDate = debtRecovery.getReferenceDate();
    BigDecimal balanceDueDebtRecovery = debtRecovery.getBalanceDueDebtRecovery();
    int debtRecoveryLevel = -1;
    if (debtRecovery.getDebtRecoveryMethodLine() != null) {
        debtRecoveryLevel = debtRecovery.getDebtRecoveryMethodLine().getSequence();
    }
    int theoricalDebtRecoveryLevel;
    int levelMax = this.getMaxLevel(debtRecovery);
    // Test inutile... à verifier
    if ((appAccountService.getTodayDate(debtRecovery.getCompany()).isAfter(referenceDate) || appAccountService.getTodayDate(debtRecovery.getCompany()).isEqual(referenceDate)) && balanceDueDebtRecovery.compareTo(BigDecimal.ZERO) > 0) {
        log.debug("Si la date actuelle est égale ou ultérieur à la date de référence et le solde due relançable positif");
        // de relance 4
        if (debtRecoveryLevel < levelMax) {
            log.debug("Sinon ce n'est pas un client à haut risque vital");
            theoricalDebtRecoveryLevel = debtRecoveryLevel + 1;
        } else {
            log.debug("Sinon c'est un client à un haut risque vital");
            theoricalDebtRecoveryLevel = levelMax;
        }
        DebtRecoveryMethodLine debtRecoveryMethodLine = this.getDebtRecoveryMethodLine(debtRecovery, theoricalDebtRecoveryLevel);
        if ((!(referenceDate.plusDays(debtRecoveryMethodLine.getStandardDeadline())).isAfter(appAccountService.getTodayDate(debtRecovery.getCompany()))) && balanceDueDebtRecovery.compareTo(debtRecoveryMethodLine.getMinThreshold()) > 0) {
            log.debug("Si le seuil du solde exigible relançable est respecté et le délai est respecté");
            if (!debtRecoveryMethodLine.getManualValidationOk()) {
                log.debug("Si le niveau ne necessite pas de validation manuelle");
                debtRecovery.setDebtRecoveryMethodLine(// Afin d'afficher la ligne de niveau sur le tiers
                debtRecoveryMethodLine);
                debtRecovery.setWaitDebtRecoveryMethodLine(null);
            // et lancer les autres actions du niveau
            } else {
                log.debug("Si le niveau necessite une validation manuelle");
                debtRecovery.setWaitDebtRecoveryMethodLine(// Si le passage est manuel
                debtRecoveryMethodLine);
            }
        }
    } else {
        log.debug("Sinon on lance une réinitialisation");
        this.debtRecoveryInitialization(debtRecovery);
    }
    log.debug("End debtRecoverySession service");
    return debtRecovery;
}
Also used : DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 2 with DebtRecoveryMethodLine

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

the class DebtRecoverySessionService method getMaxLevel.

public int getMaxLevel(DebtRecovery debtRecovery) {
    DebtRecoveryMethod debtRecoveryMethod = debtRecovery.getDebtRecoveryMethod();
    int levelMax = -1;
    if (debtRecoveryMethod != null && debtRecoveryMethod.getDebtRecoveryMethodLineList() != null) {
        for (DebtRecoveryMethodLine debtRecoveryMethodLine : debtRecoveryMethod.getDebtRecoveryMethodLineList()) {
            int currentLevel = debtRecoveryMethodLine.getSequence();
            if (currentLevel > levelMax) {
                levelMax = currentLevel;
            }
        }
    }
    return levelMax;
}
Also used : DebtRecoveryMethod(com.axelor.apps.account.db.DebtRecoveryMethod) DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine)

Example 3 with DebtRecoveryMethodLine

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

the class DebtRecoveryActionService method runStandardMessage.

/**
 * Fonction permettant de créer un courrier à destination des tiers pour un contrat standard
 *
 * @param debtRecovery
 * @return
 * @throws AxelorException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws IOException
 */
public Set<Message> runStandardMessage(DebtRecovery debtRecovery) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    Set<Message> messages = new HashSet<>();
    DebtRecoveryMethodLine debtRecoveryMethodLine = debtRecovery.getDebtRecoveryMethodLine();
    Set<Template> templateSet = debtRecoveryMethodLine.getMessageTemplateSet();
    DebtRecoveryHistory debtRecoveryHistory = this.getDebtRecoveryHistory(debtRecovery);
    for (Template template : templateSet) {
        messages.add(templateMessageAccountService.generateMessage(debtRecoveryHistory, template));
    }
    return messages;
}
Also used : DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine) HashSet(java.util.HashSet) Template(com.axelor.apps.message.db.Template)

Example 4 with DebtRecoveryMethodLine

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

the class DebtRecoveryActionService method runManualAction.

/**
 * Procédure permettant de lancer manuellement l'ensemble des actions relative au niveau de
 * relance d'un tiers
 *
 * @param debtRecovery Une relance
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void runManualAction(DebtRecovery debtRecovery) throws AxelorException, ClassNotFoundException, IOException, InstantiationException, IllegalAccessException, JSONException {
    log.debug("Begin runManualAction service ...");
    DebtRecoveryMethodLine debtRecoveryMethodLine = debtRecovery.getWaitDebtRecoveryMethodLine();
    Partner partner = (debtRecovery.getTradingName() == null || debtRecovery.getTradingNameAccountingSituation() == null) ? debtRecovery.getAccountingSituation().getPartner() : debtRecovery.getTradingNameAccountingSituation().getPartner();
    if (debtRecovery.getDebtRecoveryMethod() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "%s :\n" + I18n.get("Partner") + " %s: " + I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName());
    }
    if (debtRecoveryMethodLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "%s :\n" + I18n.get("Partner") + " %s: " + I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName());
    } else if (CollectionUtils.isEmpty(debtRecoveryMethodLine.getMessageTemplateSet())) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), debtRecoveryMethodLine.getDebtRecoveryMethod().getName(), debtRecoveryMethodLine.getSequence());
    } else {
        // On enregistre la date de la relance
        debtRecovery.setDebtRecoveryDate(appAccountService.getTodayDate(debtRecovery.getCompany()));
        this.debtRecoveryLevelValidate(debtRecovery);
        this.saveDebtRecovery(debtRecovery);
        /* Messages are send from this transaction
      If an exception occurs while sending messages
      The debtRecovery process is rollbacked */
        this.runMessage(debtRecovery);
    }
    log.debug("End runManualAction service");
}
Also used : AxelorException(com.axelor.exception.AxelorException) DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 5 with DebtRecoveryMethodLine

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

the class DebtRecoveryActionService method runAction.

/**
 * Procédure permettant de lancer l'ensemble des actions relative au niveau de relance d'un tiers
 *
 * @param debtRecovery Une relance
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void runAction(DebtRecovery debtRecovery) throws AxelorException {
    DebtRecoveryMethodLine debtRecoveryMethodLine = debtRecovery.getDebtRecoveryMethodLine();
    Partner partner = (debtRecovery.getTradingName() == null || debtRecovery.getTradingNameAccountingSituation() == null) ? debtRecovery.getAccountingSituation().getPartner() : debtRecovery.getTradingNameAccountingSituation().getPartner();
    if (debtRecovery.getDebtRecoveryMethod() == null) {
        throw new AxelorException(debtRecovery, TraceBackRepository.CATEGORY_MISSING_FIELD, "%s :\n" + I18n.get("Partner") + " %s: " + I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName());
    }
    if (debtRecoveryMethodLine == null) {
        throw new AxelorException(debtRecovery, TraceBackRepository.CATEGORY_MISSING_FIELD, "%s :\n" + I18n.get("Partner") + " %s: " + I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName());
    } else if (CollectionUtils.isEmpty(debtRecoveryMethodLine.getMessageTemplateSet())) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), debtRecoveryMethodLine.getDebtRecoveryMethod().getName(), debtRecoveryMethodLine.getSequence());
    } else {
        // On enregistre la date de la relance
        debtRecovery.setDebtRecoveryDate(appAccountService.getTodayDate(debtRecovery.getCompany()));
        this.saveDebtRecovery(debtRecovery);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) DebtRecoveryMethodLine(com.axelor.apps.account.db.DebtRecoveryMethodLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

DebtRecoveryMethodLine (com.axelor.apps.account.db.DebtRecoveryMethodLine)5 Partner (com.axelor.apps.base.db.Partner)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 DebtRecoveryHistory (com.axelor.apps.account.db.DebtRecoveryHistory)1 DebtRecoveryMethod (com.axelor.apps.account.db.DebtRecoveryMethod)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 Message (com.axelor.apps.message.db.Message)1 Template (com.axelor.apps.message.db.Template)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 HashSet (java.util.HashSet)1