Search in sources :

Example 1 with DebtRecoveryHistory

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

the class DebtRecoveryHistoryController method printPaymentReminder.

public void printPaymentReminder(ActionRequest request, ActionResponse response) {
    try {
        DebtRecoveryHistory debtRecoveryHistory = request.getContext().asType(DebtRecoveryHistory.class);
        debtRecoveryHistory = Beans.get(DebtRecoveryHistoryRepository.class).find(debtRecoveryHistory.getId());
        String name = I18n.get("Payment reminder") + " " + debtRecoveryHistory.getName();
        String fileLink = ReportFactory.createReport(IReport.DEBT_RECOVERY, name + "-${date}").addParam("DebtRecoveryHistoryID", debtRecoveryHistory.getId()).addParam("Locale", ReportSettings.getPrintingLocale(null)).addFormat("pdf").addParam("Timezone", debtRecoveryHistory.getDebtRecovery().getCompany() != null ? debtRecoveryHistory.getDebtRecovery().getCompany().getTimezone() : null).toAttach(debtRecoveryHistory).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory)

Example 2 with DebtRecoveryHistory

use of com.axelor.apps.account.db.DebtRecoveryHistory 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 3 with DebtRecoveryHistory

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

the class DebtRecoveryActionService method saveDebtRecovery.

/**
 * Procédure permettant d'enregistrer les éléments de la relance dans l'historique des relances
 *
 * @param debtRecovery Une relance
 */
@Transactional
public void saveDebtRecovery(DebtRecovery debtRecovery) {
    DebtRecoveryHistory debtRecoveryHistory = new DebtRecoveryHistory();
    debtRecoveryHistory.setDebtRecovery(debtRecovery);
    debtRecoveryHistory.setBalanceDue(debtRecovery.getBalanceDue());
    debtRecoveryHistory.setBalanceDueDebtRecovery(debtRecovery.getBalanceDueDebtRecovery());
    debtRecoveryHistory.setDebtRecoveryDate(debtRecovery.getDebtRecoveryDate());
    debtRecoveryHistory.setDebtRecoveryMethodLine(debtRecovery.getDebtRecoveryMethodLine());
    debtRecoveryHistory.setSetToIrrecoverableOK(debtRecovery.getSetToIrrecoverableOk());
    debtRecoveryHistory.setUnknownAddressOK(debtRecovery.getUnknownAddressOk());
    debtRecoveryHistory.setReferenceDate(debtRecovery.getReferenceDate());
    debtRecoveryHistory.setDebtRecoveryMethod(debtRecovery.getDebtRecoveryMethod());
    debtRecoveryHistory.setUserDebtRecovery(userService.getUser());
    debtRecovery.addDebtRecoveryHistoryListItem(debtRecoveryHistory);
    debtRecoveryHistoryRepository.save(debtRecoveryHistory);
}
Also used : DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory) Transactional(com.google.inject.persist.Transactional)

Example 4 with DebtRecoveryHistory

use of com.axelor.apps.account.db.DebtRecoveryHistory 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 5 with DebtRecoveryHistory

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

the class PayerQualityService method getPayerQualityNote.

public BigDecimal getPayerQualityNote(Partner partner, List<PayerQualityConfigLine> payerQualityConfigLineList) {
    BigDecimal burden = BigDecimal.ZERO;
    List<DebtRecoveryHistory> debtRecoveryHistoryList = this.getDebtRecoveryHistoryList(partner);
    List<MoveLine> moveLineList = this.getMoveLineRejectList(partner);
    log.debug("Tiers {} : Nombre de relances concernées : {}", partner.getName(), debtRecoveryHistoryList.size());
    log.debug("Tiers {} : Nombre de rejets concernés : {}", partner.getName(), moveLineList.size());
    for (DebtRecoveryHistory debtRecoveryHistory : debtRecoveryHistoryList) {
        burden = burden.add(this.getPayerQualityNote(debtRecoveryHistory, payerQualityConfigLineList));
    }
    for (MoveLine moveLine : moveLineList) {
        burden = burden.add(this.getPayerQualityNote(moveLine, payerQualityConfigLineList));
    }
    log.debug("Tiers {} : Qualité payeur : {}", partner.getName(), burden);
    return burden;
}
Also used : DebtRecoveryHistory(com.axelor.apps.account.db.DebtRecoveryHistory) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal)

Aggregations

DebtRecoveryHistory (com.axelor.apps.account.db.DebtRecoveryHistory)5 MoveLine (com.axelor.apps.account.db.MoveLine)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1 DebtRecovery (com.axelor.apps.account.db.DebtRecovery)1 DebtRecoveryMethod (com.axelor.apps.account.db.DebtRecoveryMethod)1 DebtRecoveryMethodLine (com.axelor.apps.account.db.DebtRecoveryMethodLine)1 AccountingSituationRepository (com.axelor.apps.account.db.repo.AccountingSituationRepository)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 AxelorException (com.axelor.exception.AxelorException)1 LocalDate (java.time.LocalDate)1 HashSet (java.util.HashSet)1