Search in sources :

Example 1 with Period

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

the class YearServiceImpl method generatePeriods.

public List<Period> generatePeriods(Year year) throws AxelorException {
    List<Period> periods = new ArrayList<Period>();
    Integer duration = year.getPeriodDurationSelect();
    LocalDate fromDate = year.getFromDate();
    LocalDate toDate = year.getToDate();
    LocalDate periodToDate = fromDate;
    Integer periodNumber = 1;
    int c = 0;
    int loopLimit = 1000;
    while (periodToDate.isBefore(toDate)) {
        if (periodNumber != 1)
            fromDate = fromDate.plusMonths(duration);
        if (c >= loopLimit) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PERIOD_3));
        }
        c += 1;
        periodToDate = fromDate.plusMonths(duration).minusDays(1);
        if (periodToDate.isAfter(toDate))
            periodToDate = toDate;
        if (fromDate.isAfter(toDate))
            continue;
        Period period = new Period();
        period.setFromDate(fromDate);
        period.setToDate(periodToDate);
        period.setYear(year);
        period.setName(String.format("%02d", periodNumber) + "/" + year.getCode());
        period.setCode((String.format("%02d", periodNumber) + "/" + year.getCode() + "_" + year.getCompany().getCode()).toUpperCase());
        period.setStatusSelect(year.getStatusSelect());
        periods.add(period);
        periodNumber++;
    }
    return periods;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) LocalDate(java.time.LocalDate)

Example 2 with Period

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

the class PeriodController method continueClose.

public void continueClose(ActionRequest request, ActionResponse response) {
    try {
        Period period = request.getContext().asType(Period.class);
        period = Beans.get(PeriodRepository.class).find(period.getId());
        Beans.get(PeriodService.class).close(period);
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
        response.setReload(true);
    }
}
Also used : Period(com.axelor.apps.base.db.Period) PeriodService(com.axelor.apps.base.service.PeriodService)

Example 3 with Period

use of com.axelor.apps.base.db.Period 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 Period

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

the class PeriodController method close.

public void close(ActionRequest request, ActionResponse response) {
    Period period = request.getContext().asType(Period.class);
    period = Beans.get(PeriodRepository.class).find(period.getId());
    try {
        Beans.get(PeriodService.class).close(period);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Period(com.axelor.apps.base.db.Period) PeriodService(com.axelor.apps.base.service.PeriodService)

Example 5 with Period

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

the class DeclarationOfExchangesExporterGoods method exportToCSV.

@Override
public String exportToCSV() throws AxelorException {
    Path path = getFilePath();
    Period period = declarationOfExchanges.getPeriod();
    List<StockMoveLine> stockMoveLines = Beans.get(StockMoveLineRepository.class).findForDeclarationOfExchanges(period.getFromDate(), period.getToDate(), declarationOfExchanges.getProductTypeSelect(), declarationOfExchanges.getStockMoveTypeSelect(), declarationOfExchanges.getCountry(), declarationOfExchanges.getCompany()).fetch();
    List<String[]> dataList = new ArrayList<>(stockMoveLines.size());
    int lineNum = 1;
    for (StockMoveLine stockMoveLine : stockMoveLines) {
        String[] data = exportLineToCsv(stockMoveLine, lineNum);
        if (data != null && data.length != 0) {
            dataList.add(data);
            lineNum++;
        }
    }
    try {
        MoreFiles.createParentDirectories(path);
        CsvTool.csvWriter(path.getParent().toString(), path.getFileName().toString(), ';', getTranslatedHeaders(), dataList);
    } catch (IOException e) {
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getLocalizedMessage());
    }
    return attach(path.toString());
}
Also used : Path(java.nio.file.Path) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) IOException(java.io.IOException)

Aggregations

Period (com.axelor.apps.base.db.Period)17 AxelorException (com.axelor.exception.AxelorException)8 Company (com.axelor.apps.base.db.Company)5 ArrayList (java.util.ArrayList)5 PeriodService (com.axelor.apps.base.service.PeriodService)4 PeriodRepository (com.axelor.apps.base.db.repo.PeriodRepository)3 Transactional (com.google.inject.persist.Transactional)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 Path (java.nio.file.Path)2 LocalDate (java.time.LocalDate)2 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)1 Move (com.axelor.apps.account.db.Move)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 AdjustHistory (com.axelor.apps.base.db.AdjustHistory)1 Partner (com.axelor.apps.base.db.Partner)1 Year (com.axelor.apps.base.db.Year)1