Search in sources :

Example 6 with Year

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;
}
Also used : Year(com.axelor.apps.base.db.Year)

Example 7 with 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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) YearServiceImpl(com.axelor.apps.base.service.YearServiceImpl) KilometricLog(com.axelor.apps.hr.db.KilometricLog) BigDecimal(java.math.BigDecimal)

Example 8 with 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);
}
Also used : Year(com.axelor.apps.base.db.Year) Currency(com.axelor.apps.base.db.Currency) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

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