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