Search in sources :

Example 1 with FixedAssetLine

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

Example 2 with 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();
    }
}
Also used : FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) LocalDate(java.time.LocalDate) FixedAssetLineRepository(com.axelor.apps.account.db.repo.FixedAssetLineRepository)

Example 3 with FixedAssetLine

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

Example 4 with FixedAssetLine

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;
}
Also used : FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 5 with 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;
}
Also used : FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine)

Aggregations

FixedAssetLine (com.axelor.apps.account.db.FixedAssetLine)18 BigDecimal (java.math.BigDecimal)13 FixedAsset (com.axelor.apps.account.db.FixedAsset)12 FixedAssetTestTool.createFixedAsset (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAsset)10 FixedAssetTestTool.createFixedAssetLine (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAssetLine)10 Test (org.junit.Test)10 LocalDate (java.time.LocalDate)3 FixedAssetLineRepository (com.axelor.apps.account.db.repo.FixedAssetLineRepository)2 Transactional (com.google.inject.persist.Transactional)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 AnalyticDistributionTemplate (com.axelor.apps.account.db.AnalyticDistributionTemplate)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 FixedAssetRepository (com.axelor.apps.account.db.repo.FixedAssetRepository)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 FixedAssetLineMoveService (com.axelor.apps.account.service.fixedasset.FixedAssetLineMoveService)1 MoveLineService (com.axelor.apps.account.service.move.MoveLineService)1 JPA (com.axelor.db.JPA)1