use of com.axelor.apps.account.db.MoveTemplateLine in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
BigDecimal hundred = new BigDecimal(100);
for (HashMap<String, Object> data : dataList) {
LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
boolean isDebit = false;
Partner debitPartner = null;
Partner creditPartner = null;
BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
Partner partner = null;
if (data.get("debitPartner") != null) {
debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
partner = debitPartner;
}
if (data.get("creditPartner") != null) {
creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
partner = creditPartner;
}
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
partner = null;
if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
isDebit = true;
if (moveTemplateLine.getHasPartnerToDebit()) {
partner = debitPartner;
}
} else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
isDebit = false;
if (moveTemplateLine.getHasPartnerToCredit()) {
partner = creditPartner;
}
}
BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.MoveTemplateLine in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.MoveTemplateLine in project axelor-open-suite by axelor.
the class MoveTemplateService method checkValidityInAmount.
protected boolean checkValidityInAmount(MoveTemplate moveTemplate) {
BigDecimal debit = BigDecimal.ZERO;
BigDecimal credit = BigDecimal.ZERO;
for (MoveTemplateLine line : moveTemplate.getMoveTemplateLineList()) {
debit = debit.add(line.getDebit());
credit = credit.add(line.getCredit());
}
LOG.debug("Debit : {}, Credit : {}", debit, credit);
if (debit.compareTo(BigDecimal.ZERO) != 0 && credit.compareTo(BigDecimal.ZERO) != 0 && debit.compareTo(credit) == 0) {
this.validateMoveTemplateLine(moveTemplate);
return true;
} else {
return false;
}
}
use of com.axelor.apps.account.db.MoveTemplateLine in project axelor-open-suite by axelor.
the class MoveTemplateService method validateMoveTemplateLine.
@Transactional
public void validateMoveTemplateLine(MoveTemplate moveTemplate) {
moveTemplate.setIsValid(true);
for (MoveTemplateLine line : moveTemplate.getMoveTemplateLineList()) {
line.setIsValid(true);
}
moveTemplateRepo.save(moveTemplate);
}
use of com.axelor.apps.account.db.MoveTemplateLine in project axelor-open-suite by axelor.
the class MoveTemplateService method checkValidityInPercentage.
protected boolean checkValidityInPercentage(MoveTemplate moveTemplate) {
BigDecimal debitPercent = BigDecimal.ZERO;
BigDecimal creditPercent = BigDecimal.ZERO;
for (MoveTemplateLine line : moveTemplate.getMoveTemplateLineList()) {
LOG.debug("Adding percent: {}", line.getPercentage());
if (MoveTemplateLineRepository.DEBIT.equals(line.getDebitCreditSelect())) {
debitPercent = debitPercent.add(line.getPercentage());
} else {
creditPercent = creditPercent.add(line.getPercentage());
}
}
LOG.debug("Debit percent: {}, Credit percent: {}", debitPercent, creditPercent);
if (debitPercent.compareTo(BigDecimal.ZERO) != 0 && creditPercent.compareTo(BigDecimal.ZERO) != 0 && debitPercent.compareTo(creditPercent) == 0) {
this.validateMoveTemplateLine(moveTemplate);
return true;
} else {
return false;
}
}
Aggregations