use of com.axelor.apps.base.db.Year in project axelor-open-suite by axelor.
the class ImportYear method importYear.
public Object importYear(Object bean, Map<String, Object> values) throws AxelorException {
Year year = (Year) bean;
year.getPeriodList().addAll(yearService.generatePeriods(year));
return year;
}
use of com.axelor.apps.base.db.Year in project axelor-open-suite by axelor.
the class KilometricService method getOrCreateKilometricLog.
public KilometricLog getOrCreateKilometricLog(Employee employee, LocalDate date) throws AxelorException {
KilometricLog log = getKilometricLog(employee, date);
if (log != null) {
return log;
}
if (employee.getMainEmploymentContract() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), employee.getName());
}
Year year = Beans.get(YearServiceImpl.class).getYear(date, employee.getMainEmploymentContract().getPayCompany(), YearRepository.TYPE_CIVIL);
if (year == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.KILOMETRIC_LOG_NO_CIVIL_YEAR), employee.getMainEmploymentContract().getPayCompany(), date);
}
return createKilometricLog(employee, new BigDecimal("0.00"), year);
}
use of com.axelor.apps.base.db.Year in project axelor-open-suite by axelor.
the class SopServiceImpl method setSalesForecast.
@Transactional
protected void setSalesForecast(SopLine sopLine, ProductCategory category, Company company) throws AxelorException {
sopLine = sopLineRepo.find(sopLine.getId());
LocalDate fromDate = sopLine.getPeriod().getFromDate();
LocalDate toDate = sopLine.getPeriod().getToDate();
Year year = sopLine.getSop().getYearbasedHistoric();
if (year != null) {
fromDate = fromDate.withYear(year.getFromDate().getYear());
toDate = toDate.withYear(year.getToDate().getYear());
}
Currency actualCurrency = company.getCurrency();
ArrayList<Integer> statusList = new ArrayList<Integer>();
statusList.add(SaleOrderRepository.STATUS_ORDER_COMPLETED);
statusList.add(SaleOrderRepository.STATUS_ORDER_CONFIRMED);
BigDecimal exTaxSum = BigDecimal.ZERO;
Query<SaleOrderLine> query = saleOrderLineRepo.all().filter("self.saleOrder.company = ?1 AND self.saleOrder.statusSelect in (?2) AND self.product.productCategory = ?3", company, statusList, category).order("id");
int offset = 0;
List<SaleOrderLine> saleOrderLineList;
while (!(saleOrderLineList = query.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += FETCH_LIMIT;
actualCurrency = currencyRepo.find(actualCurrency.getId());
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
LocalDate usedDate = saleOrderLine.getDesiredDelivDate() != null ? saleOrderLine.getDesiredDelivDate() : saleOrderLine.getEstimatedDelivDate() != null ? saleOrderLine.getEstimatedDelivDate() : saleOrderLine.getSaleOrder().getDeliveryDate() != null ? saleOrderLine.getSaleOrder().getDeliveryDate() : saleOrderLine.getSaleOrder().getConfirmationDateTime().toLocalDate();
if (usedDate.isAfter(fromDate) && usedDate.isBefore(toDate)) {
if (saleOrderLine.getSaleOrder().getCurrency().equals(actualCurrency)) {
exTaxSum = exTaxSum.add(saleOrderLine.getExTaxTotal().multiply(sopLine.getSop().getGrowthCoef())).setScale(2, RoundingMode.HALF_UP);
} else {
exTaxSum = exTaxSum.add(currencyService.getAmountCurrencyConvertedAtDate(saleOrderLine.getSaleOrder().getCurrency(), actualCurrency, saleOrderLine.getExTaxTotal(), today).multiply(sopLine.getSop().getGrowthCoef()).setScale(2, RoundingMode.HALF_UP));
}
}
}
JPA.clear();
}
sopLine = sopLineRepo.find(sopLine.getId());
sopLine.setSopSalesForecast(exTaxSum);
sopLineRepo.save(sopLine);
}
Aggregations