Search in sources :

Example 1 with Year

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

the class BatchCloseAnnualAccounts method process.

protected void process() {
    if (!end) {
        AccountingBatch accountingBatch = batch.getAccountingBatch();
        boolean allocatePerPartner = accountingBatch.getAllocatePerPartner();
        boolean closeYear = accountingBatch.getCloseYear();
        boolean openYear = accountingBatch.getOpenYear();
        Year year = accountingBatch.getYear();
        LocalDate endOfYearDate = year.getToDate();
        LocalDate reportedBalanceDate = year.getReportedBalanceDate();
        String origin = accountingBatch.getCode();
        String moveDescription = accountingBatch.getMoveDescription();
        List<Long> accountIdList = accountingCloseAnnualService.getAllAccountOfYear(accountingBatch.getAccountSet(), year);
        List<Pair<Long, Long>> accountAndPartnerPairList = accountingCloseAnnualService.assignPartner(accountIdList, year, allocatePerPartner);
        Account account = null;
        Partner partner = null;
        for (Pair<Long, Long> accountAndPartnerPair : accountAndPartnerPairList) {
            try {
                account = accountRepository.find(accountAndPartnerPair.getLeft());
                if (accountAndPartnerPair.getRight() != null) {
                    partner = partnerRepository.find(accountAndPartnerPair.getRight());
                } else {
                    partner = null;
                }
                List<Move> generateMoves = accountingCloseAnnualService.generateCloseAnnualAccount(yearRepository.find(year.getId()), account, partner, endOfYearDate, reportedBalanceDate, origin, moveDescription, closeYear, openYear, allocatePerPartner);
                if (generateMoves != null && !generateMoves.isEmpty()) {
                    updateAccount(account);
                    for (Move move : generateMoves) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Account") + " %s", account.getCode()), null, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Account") + " %s", account.getCode()), e), null, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the account {}", account.getCode());
                break;
            } finally {
                JPA.clear();
            }
        }
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) Move(com.axelor.apps.account.db.Move) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with Year

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

the class YearController method close.

public void close(ActionRequest request, ActionResponse response) {
    Year year = request.getContext().asType(Year.class);
    try {
        Beans.get(YearServiceAccountImpl.class).closeYearProcess(year);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Year(com.axelor.apps.base.db.Year) YearServiceAccountImpl(com.axelor.apps.account.service.YearServiceAccountImpl)

Example 3 with Year

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

the class UpdateAll method updatePeriod.

@Transactional
public Object updatePeriod(Object bean, Map<String, Object> values) {
    try {
        assert bean instanceof Company;
        Company company = (Company) bean;
        for (Year year : yearRepo.all().filter("self.company.id = ?1 AND self.typeSelect = 1", company.getId()).fetch()) {
            if (!year.getPeriodList().isEmpty()) {
                continue;
            }
            for (Integer month : Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 })) {
                Period period = new Period();
                LocalDate dt = LocalDate.of(year.getFromDate().getYear(), month, 1);
                period.setFromDate(dt.withDayOfMonth(1));
                period.setToDate(dt.withDayOfMonth(dt.lengthOfMonth()));
                period.setYear(year);
                period.setStatusSelect(PeriodRepository.STATUS_OPENED);
                period.setCode((dt.toString().split("-")[1] + "/" + year.getCode().split("_")[0] + "_" + company.getCode()).toUpperCase());
                period.setName(dt.toString().split("-")[1] + '/' + year.getName());
                periodRepo.save(period);
            }
        }
        return company;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bean;
}
Also used : Company(com.axelor.apps.base.db.Company) Year(com.axelor.apps.base.db.Year) Period(com.axelor.apps.base.db.Period) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 4 with Year

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

the class YearController method generatePeriods.

public void generatePeriods(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Year year = request.getContext().asType(Year.class);
        response.setValue("periodList", Beans.get(YearService.class).generatePeriods(year));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Year(com.axelor.apps.base.db.Year) AxelorException(com.axelor.exception.AxelorException)

Example 5 with Year

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

the class YearController method adjust.

public void adjust(ActionRequest request, ActionResponse response) {
    Year year = request.getContext().asType(Year.class);
    try {
        Beans.get(YearServiceAccountImpl.class).adjust(year);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Year(com.axelor.apps.base.db.Year) YearServiceAccountImpl(com.axelor.apps.account.service.YearServiceAccountImpl)

Aggregations

Year (com.axelor.apps.base.db.Year)8 AxelorException (com.axelor.exception.AxelorException)3 LocalDate (java.time.LocalDate)3 YearServiceAccountImpl (com.axelor.apps.account.service.YearServiceAccountImpl)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 Account (com.axelor.apps.account.db.Account)1 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 Move (com.axelor.apps.account.db.Move)1 Company (com.axelor.apps.base.db.Company)1 Currency (com.axelor.apps.base.db.Currency)1 Partner (com.axelor.apps.base.db.Partner)1 Period (com.axelor.apps.base.db.Period)1 YearServiceImpl (com.axelor.apps.base.service.YearServiceImpl)1 KilometricLog (com.axelor.apps.hr.db.KilometricLog)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 ArrayList (java.util.ArrayList)1 Pair (org.apache.commons.lang3.tuple.Pair)1