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