Search in sources :

Example 61 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetManagementRepository method copy.

@Override
public FixedAsset copy(FixedAsset entity, boolean deep) {
    FixedAsset copy = super.copy(entity, deep);
    copy.setStatusSelect(STATUS_DRAFT);
    copy.setReference(null);
    copy.setResidualValue(entity.getGrossValue());
    copy.setFixedAssetLineList(null);
    return copy;
}
Also used : FixedAsset(com.axelor.apps.account.db.FixedAsset)

Example 62 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetLineMoveServiceImpl method realize.

@Override
@Transactional(rollbackOn = { Exception.class })
public void realize(FixedAssetLine fixedAssetLine) throws AxelorException {
    generateMove(fixedAssetLine);
    fixedAssetLine.setStatusSelect(FixedAssetLineRepository.STATUS_REALIZED);
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    BigDecimal residualValue = fixedAsset.getResidualValue();
    fixedAsset.setResidualValue(residualValue.subtract(fixedAssetLine.getDepreciation()));
    FixedAssetLine plannedFixedAssetLine = fixedAsset.getFixedAssetLineList().stream().filter(line -> line.getStatusSelect() == FixedAssetLineRepository.STATUS_PLANNED).findAny().orElse(null);
    if (plannedFixedAssetLine == null && fixedAsset.getDisposalValue().compareTo(BigDecimal.ZERO) == 0) {
        fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DEPRECIATED);
    }
    fixedAssetLineRepo.save(fixedAssetLine);
}
Also used : FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) FixedAsset(com.axelor.apps.account.db.FixedAsset) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 63 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetLineMoveServiceImpl method generateMove.

@Transactional(rollbackOn = { Exception.class })
private void generateMove(FixedAssetLine fixedAssetLine) throws AxelorException {
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    Journal journal = fixedAsset.getJournal();
    Company company = fixedAsset.getCompany();
    Partner partner = fixedAsset.getPartner();
    LocalDate date = fixedAssetLine.getDepreciationDate();
    log.debug("Creating an fixed asset line specific accounting entry {} (Company : {}, Journal : {})", fixedAsset.getReference(), company.getName(), journal.getCode());
    // Creating move
    Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
    if (move != null) {
        List<MoveLine> moveLines = new ArrayList<>();
        String origin = fixedAsset.getReference();
        Account debitLineAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
        Account creditLineAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
        BigDecimal amount = fixedAssetLine.getDepreciation();
        // Creating accounting debit move line
        MoveLine debitMoveLine = new MoveLine(move, partner, debitLineAccount, date, null, 1, amount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(debitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), debitMoveLine);
        // Creating accounting debit move line
        MoveLine creditMoveLine = new MoveLine(move, partner, creditLineAccount, date, null, 2, BigDecimal.ZERO, amount, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(creditMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
        move.getMoveLineList().addAll(moveLines);
    }
    moveRepo.save(move);
    fixedAssetLine.setDepreciationAccountMove(move);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) FixedAsset(com.axelor.apps.account.db.FixedAsset) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 64 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetServiceImpl method massValidation.

@Override
public int massValidation(List<Long> fixedAssetIds) {
    int count = 0;
    for (Long id : fixedAssetIds) {
        FixedAsset fixedAsset = fixedAssetRepo.find(id);
        if (fixedAsset.getStatusSelect() == FixedAssetRepository.STATUS_DRAFT) {
            validate(fixedAsset);
            JPA.clear();
            count++;
        }
    }
    return count;
}
Also used : FixedAsset(com.axelor.apps.account.db.FixedAsset)

Example 65 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetServiceImpl method disposal.

@Override
@Transactional(rollbackOn = { Exception.class })
public void disposal(LocalDate disposalDate, BigDecimal disposalAmount, FixedAsset fixedAsset) throws AxelorException {
    Map<Integer, List<FixedAssetLine>> fixedAssetLineMap = fixedAsset.getFixedAssetLineList().stream().collect(Collectors.groupingBy(FixedAssetLine::getStatusSelect));
    List<FixedAssetLine> previousPlannedLineList = fixedAssetLineMap.get(FixedAssetLineRepository.STATUS_PLANNED);
    List<FixedAssetLine> previousRealizedLineList = fixedAssetLineMap.get(FixedAssetLineRepository.STATUS_REALIZED);
    FixedAssetLine previousPlannedLine = previousPlannedLineList != null && !previousPlannedLineList.isEmpty() ? previousPlannedLineList.get(0) : null;
    FixedAssetLine previousRealizedLine = previousRealizedLineList != null && !previousRealizedLineList.isEmpty() ? previousRealizedLineList.get(previousRealizedLineList.size() - 1) : null;
    if (previousPlannedLine != null && disposalDate.isAfter(previousPlannedLine.getDepreciationDate())) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.FIXED_ASSET_DISPOSAL_DATE_ERROR_2));
    }
    if (previousRealizedLine != null && disposalDate.isBefore(previousRealizedLine.getDepreciationDate())) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.FIXED_ASSET_DISPOSAL_DATE_ERROR_1));
    }
    if (disposalAmount.compareTo(BigDecimal.ZERO) != 0) {
        FixedAssetLine depreciationFixedAssetLine = generateProrataDepreciationLine(fixedAsset, disposalDate, previousRealizedLine);
        fixedAssetLineMoveService.realize(depreciationFixedAssetLine);
        fixedAssetLineMoveService.generateDisposalMove(depreciationFixedAssetLine);
    } else {
        if (disposalAmount.compareTo(fixedAsset.getResidualValue()) != 0) {
            return;
        }
    }
    List<FixedAssetLine> fixedAssetLineList = fixedAsset.getFixedAssetLineList().stream().filter(fixedAssetLine -> fixedAssetLine.getStatusSelect() == FixedAssetLineRepository.STATUS_PLANNED).collect(Collectors.toList());
    for (FixedAssetLine fixedAssetLine : fixedAssetLineList) {
        fixedAsset.removeFixedAssetLineListItem(fixedAssetLine);
    }
    fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_TRANSFERRED);
    fixedAsset.setDisposalDate(disposalDate);
    fixedAsset.setDisposalValue(disposalAmount);
    fixedAssetRepo.save(fixedAsset);
}
Also used : AccountConfig(com.axelor.apps.account.db.AccountConfig) Inject(com.google.inject.Inject) FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) MoveLine(com.axelor.apps.account.db.MoveLine) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) I18n(com.axelor.i18n.I18n) FixedAssetRepository(com.axelor.apps.account.db.repo.FixedAssetRepository) RoundingMode(java.math.RoundingMode) MoveLineService(com.axelor.apps.account.service.move.MoveLineService) JPA(com.axelor.db.JPA) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) AnalyticDistributionTemplate(com.axelor.apps.account.db.AnalyticDistributionTemplate) FixedAssetLineRepository(com.axelor.apps.account.db.repo.FixedAssetLineRepository) FixedAsset(com.axelor.apps.account.db.FixedAsset) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(com.google.inject.persist.Transactional)

Aggregations

FixedAsset (com.axelor.apps.account.db.FixedAsset)65 FixedAssetTestTool.createFixedAsset (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAsset)52 BigDecimal (java.math.BigDecimal)52 Test (org.junit.Test)47 FixedAssetLine (com.axelor.apps.account.db.FixedAssetLine)12 FixedAssetTestTool.createFixedAssetLine (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAssetLine)10 Transactional (com.google.inject.persist.Transactional)6 AxelorException (com.axelor.exception.AxelorException)5 ArrayList (java.util.ArrayList)5 LocalDate (java.time.LocalDate)4 MoveLine (com.axelor.apps.account.db.MoveLine)3 FixedAssetRepository (com.axelor.apps.account.db.repo.FixedAssetRepository)3 FixedAssetService (com.axelor.apps.account.service.fixedasset.FixedAssetService)3 Account (com.axelor.apps.account.db.Account)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 Journal (com.axelor.apps.account.db.Journal)2 Move (com.axelor.apps.account.db.Move)2 Company (com.axelor.apps.base.db.Company)2 Partner (com.axelor.apps.base.db.Partner)2