Search in sources :

Example 76 with MoveLine

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

the class MoveLineServiceImpl method findConsolidateMoveLine.

@Override
public MoveLine findConsolidateMoveLine(Map<List<Object>, MoveLine> map, MoveLine moveLine, List<Object> keys) {
    if (map != null && !map.isEmpty()) {
        Map<List<Object>, MoveLine> copyMap = new HashMap<List<Object>, MoveLine>(map);
        while (!copyMap.isEmpty()) {
            if (map.containsKey(keys)) {
                MoveLine moveLineIt = map.get(keys);
                int count = 0;
                if (moveLineIt.getAnalyticMoveLineList() == null && moveLine.getAnalyticMoveLineList() == null) {
                    return moveLineIt;
                } else if (moveLineIt.getAnalyticMoveLineList() == null || moveLine.getAnalyticMoveLineList() == null) {
                    break;
                }
                List<AnalyticMoveLine> list1 = moveLineIt.getAnalyticMoveLineList();
                List<AnalyticMoveLine> list2 = moveLine.getAnalyticMoveLineList();
                List<AnalyticMoveLine> copyList = new ArrayList<AnalyticMoveLine>(list1);
                if (list1.size() == list2.size()) {
                    for (AnalyticMoveLine analyticDistributionLine : list2) {
                        for (AnalyticMoveLine analyticDistributionLineIt : copyList) {
                            if (analyticDistributionLine.getAnalyticAxis().equals(analyticDistributionLineIt.getAnalyticAxis()) && analyticDistributionLine.getAnalyticAccount().equals(analyticDistributionLineIt.getAnalyticAccount()) && analyticDistributionLine.getAccount().equals(analyticDistributionLineIt.getAccount()) && analyticDistributionLine.getPercentage().equals(analyticDistributionLineIt.getPercentage()) && ((analyticDistributionLine.getAnalyticJournal() == null && analyticDistributionLineIt.getAnalyticJournal() == null) || analyticDistributionLine.getAnalyticJournal().equals(analyticDistributionLineIt.getAnalyticJournal()))) {
                                copyList.remove(analyticDistributionLineIt);
                                count++;
                                break;
                            }
                        }
                    }
                    if (count == list1.size()) {
                        return moveLineIt;
                    }
                }
            } else {
                return null;
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 77 with MoveLine

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

the class MoveRemoveService method checkDaybookMove.

protected void checkDaybookMove(Move move) throws Exception {
    String errorMessage = "";
    Map<String, String> objectsLinkToMoveMap = archivingToolService.getObjectLinkTo(move, move.getId());
    String moveModelError = null;
    for (Map.Entry<String, String> entry : objectsLinkToMoveMap.entrySet()) {
        String modelName = I18n.get(archivingToolService.getModelTitle(entry.getKey()));
        if (!entry.getKey().equals("MoveLine")) {
            if (moveModelError == null) {
                moveModelError = modelName;
            } else {
                moveModelError += ", " + modelName;
            }
        }
    }
    if (moveModelError != null) {
        errorMessage += String.format(I18n.get(IExceptionMessage.MOVE_ARCHIVE_NOT_OK_BECAUSE_OF_LINK_WITH), move.getReference(), moveModelError);
    }
    for (MoveLine moveLine : move.getMoveLineList()) {
        errorMessage += checkDaybookMoveLine(moveLine);
    }
    if (errorMessage != null && !errorMessage.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, errorMessage);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) Map(java.util.Map)

Example 78 with MoveLine

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

the class MoveServiceImpl method createMoveUseInvoiceDue.

/**
 * Méthode permettant d'employer les dûs sur l'avoir On récupère prioritairement les dûs
 * (factures) selectionné sur l'avoir, puis les autres dûs du tiers
 *
 * <p>2 cas : - le compte des dûs est le même que celui de l'avoir : alors on lettre directement -
 * le compte n'est pas le même : on créée une O.D. de passage sur le bon compte
 *
 * @param invoice
 * @return
 * @throws AxelorException
 */
@Override
public Move createMoveUseInvoiceDue(Invoice invoice) throws AxelorException {
    Company company = invoice.getCompany();
    Move move = null;
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    // Récupération des dûs
    List<MoveLine> debitMoveLines = moveDueService.getInvoiceDue(invoice, accountConfig.getAutoReconcileOnInvoice());
    if (!debitMoveLines.isEmpty()) {
        MoveLine invoiceCustomerMoveLine = moveToolService.getCustomerMoveLineByLoop(invoice);
        // Si c'est le même compte sur les trop-perçus et sur la facture, alors on lettre directement
        if (moveToolService.isSameAccount(debitMoveLines, invoiceCustomerMoveLine.getAccount())) {
            List<MoveLine> creditMoveLineList = new ArrayList<MoveLine>();
            creditMoveLineList.add(invoiceCustomerMoveLine);
            paymentService.useExcessPaymentOnMoveLines(debitMoveLines, creditMoveLineList);
        } else // Sinon on créée une O.D. pour passer du compte de la facture à un autre compte sur les
        // trop-perçus
        {
            this.createMoveUseDebit(invoice, debitMoveLines, invoiceCustomerMoveLine);
        }
        // Gestion du passage en 580
        reconcileService.balanceCredit(invoiceCustomerMoveLine);
        invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
    }
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ArrayList(java.util.ArrayList) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 79 with MoveLine

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

the class MoveToolService method getInTaxTotalRemaining.

@Transactional(rollbackOn = { Exception.class })
public BigDecimal getInTaxTotalRemaining(Invoice invoice) throws AxelorException {
    BigDecimal inTaxTotalRemaining = BigDecimal.ZERO;
    log.debug("Update Remaining amount of invoice : {}", invoice.getInvoiceId());
    if (invoice != null) {
        boolean isMinus = this.isMinus(invoice);
        Beans.get(InvoiceRepository.class).save(invoice);
        MoveLine moveLine = this.getCustomerMoveLineByLoop(invoice);
        if (moveLine != null) {
            inTaxTotalRemaining = inTaxTotalRemaining.add(moveLine.getAmountRemaining());
            if (isMinus) {
                inTaxTotalRemaining = inTaxTotalRemaining.negate();
            }
        }
    }
    return inTaxTotalRemaining;
}
Also used : MoveLine(com.axelor.apps.account.db.MoveLine) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 80 with MoveLine

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

the class MoveValidateService method validateWellBalancedMove.

/**
 * Procédure permettant de vérifier qu'une écriture est équilibré, et la validé si c'est le cas
 *
 * @param move Une écriture
 * @throws AxelorException
 */
public void validateWellBalancedMove(Move move) throws AxelorException {
    log.debug("Well-balanced validation on account move {}", move.getReference());
    if (move.getMoveLineList() != null) {
        BigDecimal totalDebit = BigDecimal.ZERO;
        BigDecimal totalCredit = BigDecimal.ZERO;
        for (MoveLine moveLine : move.getMoveLineList()) {
            if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0 && moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.MOVE_6), moveLine.getName());
            }
            totalDebit = totalDebit.add(moveLine.getDebit());
            totalCredit = totalCredit.add(moveLine.getCredit());
        }
        if (totalDebit.compareTo(totalCredit) != 0) {
            throw new AxelorException(move, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.MOVE_7), move.getReference(), totalDebit, totalCredit);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal)

Aggregations

MoveLine (com.axelor.apps.account.db.MoveLine)135 BigDecimal (java.math.BigDecimal)60 Move (com.axelor.apps.account.db.Move)51 Transactional (com.google.inject.persist.Transactional)42 AxelorException (com.axelor.exception.AxelorException)40 Company (com.axelor.apps.base.db.Company)38 ArrayList (java.util.ArrayList)38 Partner (com.axelor.apps.base.db.Partner)33 Account (com.axelor.apps.account.db.Account)28 LocalDate (java.time.LocalDate)27 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)25 Journal (com.axelor.apps.account.db.Journal)22 Reconcile (com.axelor.apps.account.db.Reconcile)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)17 Invoice (com.axelor.apps.account.db.Invoice)15 List (java.util.List)13 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)8 Tax (com.axelor.apps.account.db.Tax)7 TaxLine (com.axelor.apps.account.db.TaxLine)7 MoveLineRepository (com.axelor.apps.account.db.repo.MoveLineRepository)7