use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method isBalanced.
@Override
public boolean isBalanced(List<Reconcile> reconcileList) {
List<MoveLine> debitMoveLineList = reconcileList.stream().map(Reconcile::getDebitMoveLine).distinct().collect(Collectors.toList());
List<MoveLine> creditMoveLineList = reconcileList.stream().map(Reconcile::getCreditMoveLine).distinct().collect(Collectors.toList());
List<Account> accountList = debitMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList());
accountList.addAll(creditMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList()));
for (Account account : accountList) {
BigDecimal totalDebit = debitMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getDebit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
BigDecimal totalCredit = creditMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getCredit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
if (totalDebit.compareTo(totalCredit) != 0) {
return false;
}
}
return true;
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ReconcileServiceImpl method unreconcile.
/**
* Permet de déréconcilier
*
* @param reconcile Une reconciliation
* @return L'etat de la réconciliation
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void unreconcile(Reconcile reconcile) throws AxelorException {
log.debug("unreconcile : reconcile : {}", reconcile);
MoveLine debitMoveLine = reconcile.getDebitMoveLine();
MoveLine creditMoveLine = reconcile.getCreditMoveLine();
// Change the state
reconcile.setStatusSelect(ReconcileRepository.STATUS_CANCELED);
// Add the reconciled amount to the reconciled amount in the move line
creditMoveLine.setAmountPaid(creditMoveLine.getAmountPaid().subtract(reconcile.getAmount()));
debitMoveLine.setAmountPaid(debitMoveLine.getAmountPaid().subtract(reconcile.getAmount()));
reconcileRepository.save(reconcile);
// Update amount remaining on invoice or refund
this.updatePartnerAccountingSituation(reconcile);
this.updateInvoiceCompanyInTaxTotalRemaining(reconcile);
this.updateInvoicePaymentsCanceled(reconcile);
this.reverseTaxPaymentMoveLines(reconcile);
// Update reconcile group
Beans.get(ReconcileGroupService.class).remove(reconcile);
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ReconcileServiceImpl method reconcilePreconditions.
public void reconcilePreconditions(Reconcile reconcile) throws AxelorException {
MoveLine debitMoveLine = reconcile.getDebitMoveLine();
MoveLine creditMoveLine = reconcile.getCreditMoveLine();
if (debitMoveLine == null || creditMoveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
// Check if move lines companies are the same as the reconcile company
Company reconcileCompany = reconcile.getCompany();
Company debitMoveLineCompany = debitMoveLine.getMove().getCompany();
Company creditMoveLineCompany = creditMoveLine.getMove().getCompany();
if (!debitMoveLineCompany.equals(reconcileCompany) && !creditMoveLineCompany.equals(reconcileCompany)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.RECONCILE_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), debitMoveLineCompany, creditMoveLineCompany, reconcileCompany));
}
// Check if move lines accounts are the same (debit and credit)
if (!creditMoveLine.getAccount().equals(debitMoveLine.getAccount())) {
log.debug("Compte ligne de credit : {} , Compte ligne de debit : {}", creditMoveLine.getAccount(), debitMoveLine.getAccount());
// Check if move lines accounts are compatible
if (!debitMoveLine.getAccount().getCompatibleAccountSet().contains(creditMoveLine.getAccount())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
}
// Check if the amount to reconcile is != zero
if (reconcile.getAmount() == null || reconcile.getAmount().compareTo(BigDecimal.ZERO) == 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel());
}
if ((reconcile.getAmount().compareTo(creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid())) > 0 || (reconcile.getAmount().compareTo(debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid())) > 0))) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_5) + " " + I18n.get(IExceptionMessage.RECONCILE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), reconcile.getAmount(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid()), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel(), creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid()));
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class ReconcileServiceImpl method updateInvoicePayments.
public void updateInvoicePayments(Reconcile reconcile) throws AxelorException {
MoveLine debitMoveLine = reconcile.getDebitMoveLine();
MoveLine creditMoveLine = reconcile.getCreditMoveLine();
Move debitMove = debitMoveLine.getMove();
Move creditMove = creditMoveLine.getMove();
Invoice debitInvoice = debitMove.getInvoice();
Invoice creditInvoice = creditMove.getInvoice();
BigDecimal amount = reconcile.getAmount();
if (debitInvoice != null && debitMoveLine.getAccount().getUseForPartnerBalance() && creditMoveLine.getAccount().getUseForPartnerBalance()) {
InvoicePayment debitInvoicePayment = invoicePaymentCreateService.createInvoicePayment(debitInvoice, amount, creditMove);
debitInvoicePayment.setReconcile(reconcile);
}
if (creditInvoice != null && debitMoveLine.getAccount().getUseForPartnerBalance() && creditMoveLine.getAccount().getUseForPartnerBalance()) {
InvoicePayment creditInvoicePayment = invoicePaymentCreateService.createInvoicePayment(creditInvoice, amount, debitMove);
creditInvoicePayment.setReconcile(reconcile);
}
}
use of com.axelor.apps.account.db.MoveLine in project axelor-open-suite by axelor.
the class AccountingCloseAnnualServiceImpl method reconcile.
protected void reconcile(Move move, Move reverseMove) throws AxelorException {
List<MoveLine> moveLineSortedList = move.getMoveLineList();
Collections.sort(moveLineSortedList, Comparator.comparing(MoveLine::getCounter));
List<MoveLine> reverseMoveLineSortedList = reverseMove.getMoveLineList();
Collections.sort(reverseMoveLineSortedList, Comparator.comparing(MoveLine::getCounter));
Iterator<MoveLine> reverseMoveLinesIt = reverseMoveLineSortedList.iterator();
for (MoveLine moveLine : moveLineSortedList) {
MoveLine reverseMoveLine = reverseMoveLinesIt.next();
reconcileService.reconcile(moveLine, reverseMoveLine, false, false);
}
}
Aggregations