Search in sources :

Example 11 with Period

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

the class PeriodServiceImpl method getActivePeriod.

/**
 * Fetches the active period with the date, company and type in parameter
 *
 * @param date
 * @param company
 * @param typeSelect
 * @return
 * @throws AxelorException
 */
public Period getActivePeriod(LocalDate date, Company company, int typeSelect) throws AxelorException {
    Period period = this.getPeriod(date, company, typeSelect);
    if (period == null || (period.getStatusSelect() == PeriodRepository.STATUS_CLOSED)) {
        String dateStr = date != null ? date.toString() : "";
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), dateStr);
    }
    LOG.debug("Period : {}", period);
    return period;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Period(com.axelor.apps.base.db.Period)

Example 12 with Period

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

the class PeriodServiceImpl method getNextPeriod.

public Period getNextPeriod(Period period) throws AxelorException {
    Period nextPeriod = periodRepo.all().filter("self.fromDate > ?1 AND self.year.company = ?2 AND self.statusSelect = ?3", period.getToDate(), period.getYear().getCompany(), PeriodRepository.STATUS_OPENED).fetchOne();
    if (nextPeriod == null || nextPeriod.getStatusSelect() == PeriodRepository.STATUS_CLOSED) {
        throw new AxelorException(period, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), period.getYear().getCompany().getName());
    }
    LOG.debug("Next Period : {}", nextPeriod);
    return nextPeriod;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Period(com.axelor.apps.base.db.Period)

Example 13 with Period

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

the class DeclarationOfExchangesExporterServices method exportToCSV.

// TODO: factorize code to parent.
@Override
protected 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 = new String[columnHeadersList.size()];
        StockMove stockMove = stockMoveLine.getStockMove();
        BigDecimal fiscalValue = stockMoveLine.getUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
        String taxNbr;
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
            if (stockMove.getPartner() == null) {
                taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
            }
            if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
                taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
            }
            taxNbr = stockMove.getPartner().getTaxNbr();
        } else {
            taxNbr = "";
        }
        data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum++);
        data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
        data[columnHeadersList.indexOf(TAKER)] = taxNbr;
        dataList.add(data);
    }
    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) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 14 with Period

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

the class MoveManagementRepository method copy.

@Override
public Move copy(Move entity, boolean deep) {
    Move copy = super.copy(entity, deep);
    copy.setDate(Beans.get(AppBaseService.class).getTodayDate(copy.getCompany()));
    Period period = null;
    try {
        period = Beans.get(PeriodService.class).getActivePeriod(copy.getDate(), entity.getCompany(), YearRepository.TYPE_FISCAL);
    } catch (AxelorException e) {
        throw new PersistenceException(e.getMessage(), e);
    }
    copy.setStatusSelect(STATUS_NEW);
    copy.setTechnicalOriginSelect(MoveRepository.TECHNICAL_ORIGIN_ENTRY);
    copy.setReference(null);
    copy.setExportNumber(null);
    copy.setExportDate(null);
    copy.setAccountingReport(null);
    copy.setValidationDate(null);
    copy.setPeriod(period);
    copy.setAccountingOk(false);
    copy.setIgnoreInDebtRecoveryOk(false);
    copy.setPaymentVoucher(null);
    copy.setRejectOk(false);
    copy.setInvoice(null);
    List<MoveLine> moveLineList = copy.getMoveLineList();
    if (moveLineList != null) {
        moveLineList.forEach(moveLine -> resetMoveLine(moveLine, copy.getDate()));
    }
    return copy;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) PersistenceException(javax.persistence.PersistenceException) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Period(com.axelor.apps.base.db.Period)

Example 15 with Period

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

the class MrpForecastController method generateMrpForecast.

@SuppressWarnings("unchecked")
public void generateMrpForecast(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
    LinkedHashMap<String, Object> periodMap = (LinkedHashMap<String, Object>) sopLineMap.get("period");
    Period period = Beans.get(PeriodRepository.class).find(Long.parseLong(periodMap.get("id").toString()));
    ArrayList<LinkedHashMap<String, Object>> mrpForecastList = (ArrayList<LinkedHashMap<String, Object>>) context.get("mrpForecasts");
    LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) context.get("stockLocation");
    StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(Long.parseLong(stockLocationMap.get("id").toString()));
    if (mrpForecastList != null && !mrpForecastList.isEmpty()) {
        mrpForecastProductionService.generateMrpForecast(period, mrpForecastList, stockLocation, MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP);
    }
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) PeriodRepository(com.axelor.apps.base.db.repo.PeriodRepository) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) LinkedHashMap(java.util.LinkedHashMap)

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