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