use of com.axelor.apps.account.db.DebtRecoveryMethod 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;
}
use of com.axelor.apps.account.db.DebtRecoveryMethod 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;
}
Aggregations