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;
}
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);
}
}
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;
}
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);
}
}
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());
}
Aggregations