Search in sources :

Example 1 with AdjustHistory

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

the class AdjustHistoryService method setEndDate.

@Transactional
public void setEndDate(Period period) {
    AdjustHistory adjustHistory = adjustHistoryRepo.all().filter("self.period.id = ? AND self.endDate IS NULL", period.getId()).fetchOne();
    adjustHistory.setEndDate(LocalDateTime.now());
    adjustHistoryRepo.save(adjustHistory);
}
Also used : AdjustHistory(com.axelor.apps.base.db.AdjustHistory) Transactional(com.google.inject.persist.Transactional)

Example 2 with AdjustHistory

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

the class AdjustHistoryService method setEndDate.

@Transactional
public AdjustHistory setEndDate(Year year) {
    AdjustHistory adjustHistory = adjustHistoryRepo.all().filter("self.fiscalYear.id = ? AND self.endDate IS NULL", year.getId()).fetchOne();
    adjustHistory.setEndDate(LocalDateTime.now());
    adjustHistoryRepo.save(adjustHistory);
    return adjustHistory;
}
Also used : AdjustHistory(com.axelor.apps.base.db.AdjustHistory) Transactional(com.google.inject.persist.Transactional)

Example 3 with AdjustHistory

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

the class AdjustHistoryService method setStartDate.

@Transactional
public void setStartDate(Period period) {
    AdjustHistory adjustHistory = new AdjustHistory();
    adjustHistory.setPeriod(period);
    adjustHistory.setStartDate(LocalDateTime.now());
    adjustHistoryRepo.save(adjustHistory);
}
Also used : AdjustHistory(com.axelor.apps.base.db.AdjustHistory) Transactional(com.google.inject.persist.Transactional)

Example 4 with AdjustHistory

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

the class AdjustHistoryService method setStartDate.

@Transactional
public void setStartDate(Year year) {
    AdjustHistory adjustHistory = new AdjustHistory();
    adjustHistory.setFiscalYear(year);
    adjustHistory.setStartDate(LocalDateTime.now());
    adjustHistoryRepo.save(adjustHistory);
}
Also used : AdjustHistory(com.axelor.apps.base.db.AdjustHistory) Transactional(com.google.inject.persist.Transactional)

Example 5 with AdjustHistory

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

the class YearServiceAccountImpl method closeYearProcess.

/**
 * Procédure permettant de cloturer un exercice comptable
 *
 * @param year Un exercice comptable
 * @throws AxelorException
 */
public void closeYearProcess(Year year) throws AxelorException {
    year = yearRepository.find(year.getId());
    for (Period period : year.getPeriodList()) {
        if (period.getStatusSelect() == PeriodRepository.STATUS_ADJUSTING) {
            adjustHistoryService.setEndDate(period);
        }
        period.setStatusSelect(PeriodRepository.STATUS_CLOSED);
        period.setClosureDateTime(LocalDateTime.now());
    }
    Company company = year.getCompany();
    if (company == null) {
        throw new AxelorException(year, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.YEAR_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), year.getName());
    }
    Query q;
    if (year.getStatusSelect() == YearRepository.STATUS_ADJUSTING) {
        AdjustHistory adjustHistory = adjustHistoryService.setEndDate(year);
        q = JPA.em().createQuery("select DISTINCT(self.partner) FROM MoveLine as self WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year = ?1 " + "AND self.move.statusSelect = ?2 AND self.move.adjustingMove = true AND self.date >= ?3 AND self.date <= ?4 AND self.move.company = ?5");
        q.setParameter(1, year);
        q.setParameter(2, MoveRepository.STATUS_VALIDATED);
        q.setParameter(3, adjustHistory.getStartDate().toLocalDate());
        q.setParameter(4, adjustHistory.getEndDate().toLocalDate());
    } else {
        q = JPA.em().createQuery("select DISTINCT(self.partner) FROM MoveLine as self WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year = ?1 " + "AND self.move.statusSelect = ?2 AND self.date >= ?3 AND self.date <= ?4 AND self.move.company = ?5");
        q.setParameter(1, year);
        q.setParameter(2, MoveRepository.STATUS_VALIDATED);
        q.setParameter(3, year.getFromDate());
        q.setParameter(4, year.getToDate());
    }
    q.setParameter(5, year.getCompany());
    @SuppressWarnings("unchecked") List<Partner> partnerList = q.getResultList();
    List<? extends Partner> partnerListAll = partnerRepository.all().fetch();
    log.debug("Nombre total de tiers : {}", partnerListAll.size());
    log.debug("Nombre de tiers récupéré : {}", partnerList.size());
    for (Partner partner : partnerList) {
        partner = partnerRepository.find(partner.getId());
        year = yearRepository.find(year.getId());
        log.debug("Tiers en cours de traitement : {}", partner.getName());
        for (AccountingSituation accountingSituation : partner.getAccountingSituationList()) {
            if (accountingSituation.getCompany().equals(year.getCompany())) {
                log.debug("On ajoute une ligne à la Situation comptable trouvée");
                BigDecimal reportedBalanceAmount = this.computeReportedBalance(year.getFromDate(), year.getToDate(), partner, year);
                this.createReportedBalanceLine(accountingSituation, reportedBalanceAmount, year);
                break;
            }
        }
        JPA.clear();
    }
    year = yearRepository.find(year.getId());
    closeYear(year);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Query(javax.persistence.Query) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Period(com.axelor.apps.base.db.Period) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AdjustHistory(com.axelor.apps.base.db.AdjustHistory)

Aggregations

AdjustHistory (com.axelor.apps.base.db.AdjustHistory)5 Transactional (com.google.inject.persist.Transactional)4 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 Period (com.axelor.apps.base.db.Period)1 AxelorException (com.axelor.exception.AxelorException)1 BigDecimal (java.math.BigDecimal)1 Query (javax.persistence.Query)1