use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetLineComputationServiceImpl method createPlannedFixedAssetLine.
protected FixedAssetLine createPlannedFixedAssetLine(LocalDate depreciationDate, BigDecimal depreciation, BigDecimal cumulativeDepreciation, BigDecimal residualValue) {
FixedAssetLine fixedAssetLine = new FixedAssetLine();
fixedAssetLine.setStatusSelect(FixedAssetLineRepository.STATUS_PLANNED);
fixedAssetLine.setDepreciationDate(depreciationDate);
fixedAssetLine.setDepreciation(depreciation);
fixedAssetLine.setCumulativeDepreciation(cumulativeDepreciation);
fixedAssetLine.setResidualValue(residualValue);
return fixedAssetLine;
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class BatchRealizeFixedAssetLine method process.
@Override
protected void process() {
String query = "self.statusSelect = :statusSelect";
LocalDate startDate = batch.getAccountingBatch().getStartDate();
LocalDate endDate = batch.getAccountingBatch().getEndDate();
if (!batch.getAccountingBatch().getUpdateAllRealizedFixedAssetLines() && startDate != null && endDate != null && startDate.isBefore(endDate)) {
query += " AND self.depreciationDate < :endDate AND self.depreciationDate > :startDate";
} else {
query += " AND self.depreciationDate < :dateNow";
}
List<FixedAssetLine> fixedAssetLineList = Beans.get(FixedAssetLineRepository.class).all().filter(query).bind("statusSelect", FixedAssetLineRepository.STATUS_PLANNED).bind("startDate", startDate).bind("endDate", endDate).bind("dateNow", appBaseService.getTodayDate(batch.getAccountingBatch() != null ? batch.getAccountingBatch().getCompany() : Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))).fetch();
for (FixedAssetLine fixedAssetLine : fixedAssetLineList) {
try {
fixedAssetLine = fixedAssetLineRepo.find(fixedAssetLine.getId());
if (fixedAssetLine.getFixedAsset().getStatusSelect() > FixedAssetRepository.STATUS_DRAFT) {
fixedAssetLineMoveService.realize(fixedAssetLine);
incrementDone();
}
} catch (Exception e) {
incrementAnomaly();
TraceBackService.trace(e);
}
JPA.clear();
}
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetServiceImpl method generateAndComputeLines.
@Override
public FixedAsset generateAndComputeLines(FixedAsset fixedAsset) {
FixedAssetLine initialFixedAssetLine = fixedAssetLineComputationService.computeInitialPlannedFixedAssetLine(fixedAsset);
fixedAsset.addFixedAssetLineListItem(initialFixedAssetLine);
// counter to avoid too many iterations in case of a current or future mistake
int c = 0;
final int MAX_ITERATION = 1000;
FixedAssetLine fixedAssetLine = initialFixedAssetLine;
while (c < MAX_ITERATION && fixedAssetLine.getResidualValue().signum() != 0) {
fixedAssetLine = fixedAssetLineComputationService.computePlannedFixedAssetLine(fixedAsset, fixedAssetLine);
fixedAsset.addFixedAssetLineListItem(fixedAssetLine);
c++;
}
return fixedAsset;
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetServiceImpl method generateProrataDepreciationLine.
protected FixedAssetLine generateProrataDepreciationLine(FixedAsset fixedAsset, LocalDate disposalDate, FixedAssetLine previousRealizedLine) {
LocalDate previousRealizedDate = previousRealizedLine != null ? previousRealizedLine.getDepreciationDate() : fixedAsset.getFirstDepreciationDate();
long monthsBetweenDates = ChronoUnit.MONTHS.between(previousRealizedDate.withDayOfMonth(1), disposalDate.withDayOfMonth(1));
FixedAssetLine fixedAssetLine = new FixedAssetLine();
fixedAssetLine.setDepreciationDate(disposalDate);
BigDecimal prorataTemporis = BigDecimal.valueOf(monthsBetweenDates).divide(BigDecimal.valueOf(fixedAsset.getPeriodicityInMonth()), CALCULATION_SCALE, RoundingMode.HALF_UP);
int numberOfDepreciation = fixedAsset.getFixedAssetCategory().getIsProrataTemporis() ? fixedAsset.getNumberOfDepreciation() - 1 : fixedAsset.getNumberOfDepreciation();
BigDecimal depreciationRate = BigDecimal.valueOf(100).divide(BigDecimal.valueOf(numberOfDepreciation), CALCULATION_SCALE, RoundingMode.HALF_UP);
BigDecimal ddRate = BigDecimal.ONE;
if (fixedAsset.getComputationMethodSelect().equals(FixedAssetRepository.COMPUTATION_METHOD_DEGRESSIVE)) {
ddRate = fixedAsset.getDegressiveCoef();
}
BigDecimal deprecationValue = fixedAsset.getGrossValue().multiply(depreciationRate).multiply(ddRate).multiply(prorataTemporis).divide(new BigDecimal(100), RETURNED_SCALE, RoundingMode.HALF_UP);
fixedAssetLine.setDepreciation(deprecationValue);
BigDecimal cumulativeValue = previousRealizedLine != null ? previousRealizedLine.getCumulativeDepreciation().add(deprecationValue) : deprecationValue;
fixedAssetLine.setCumulativeDepreciation(cumulativeValue);
fixedAssetLine.setResidualValue(fixedAsset.getGrossValue().subtract(fixedAssetLine.getCumulativeDepreciation()));
fixedAsset.addFixedAssetLineListItem(fixedAssetLine);
return fixedAssetLine;
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetTestTool method createFixedAssetLine.
public static FixedAssetLine createFixedAssetLine(LocalDate depreciationDate, BigDecimal depreciation, BigDecimal cumulativeDepreciation, BigDecimal residualValue) {
FixedAssetLine fixedAssetLine = new FixedAssetLine();
fixedAssetLine.setDepreciationDate(depreciationDate);
fixedAssetLine.setDepreciation(depreciation);
fixedAssetLine.setCumulativeDepreciation(cumulativeDepreciation);
fixedAssetLine.setResidualValue(residualValue);
return fixedAssetLine;
}
Aggregations