Search in sources :

Example 91 with Move

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

the class BatchDoubtfulCustomer method createDoubtFulCustomerMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
 * de facture
 *
 * @param moveLineList Une liste d'écritures de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 * @throws AxelorException
 */
public void createDoubtFulCustomerMove(List<Move> moveList, Account doubtfulCustomerAccount, String debtPassReason) {
    int i = 0;
    for (Move move : moveList) {
        try {
            doubtfulCustomerService.createDoubtFulCustomerMove(moveRepo.find(move.getId()), accountRepo.find(doubtfulCustomerAccount.getId()), debtPassReason);
            updateInvoice(moveRepo.find(move.getId()).getInvoice());
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Invoice") + " %s", move.getInvoice().getInvoiceId()), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
            incrementAnomaly();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get("Invoice") + " %s", move.getInvoice().getInvoiceId()), e), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour la facture {}", moveRepo.find(move.getId()).getInvoice().getInvoiceId());
        } finally {
            if (i % 10 == 0) {
                JPA.clear();
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException)

Example 92 with Move

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

the class BatchReimbursementImport method process.

@Override
protected void process() {
    if (!end) {
        Company company = batch.getAccountingBatch().getCompany();
        company = companyRepo.find(company.getId());
        AccountConfig accountConfig = company.getAccountConfig();
        Map<List<String[]>, String> data = null;
        try {
            String dataImportDir = AppService.getFileUploadDir();
            String reimbursementImportFolderPathCFONB = accountConfig.getReimbursementImportFolderPathCFONB() == null ? null : dataImportDir + accountConfig.getReimbursementImportFolderPathCFONB();
            rejectImportService.createFilePath(reimbursementImportFolderPathCFONB);
            data = rejectImportService.getCFONBFileByLot(reimbursementImportFolderPathCFONB, accountConfig.getTempReimbImportFolderPathCFONB() == null ? null : dataImportDir + accountConfig.getTempReimbImportFolderPathCFONB(), company, 0);
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            stop();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour le batch d'import des remboursements {}", batch.getId());
            stop();
        }
        int seq = 1;
        int i = 0;
        for (Entry<List<String[]>, String> entry : data.entrySet()) {
            LocalDate rejectDate = rejectImportService.createRejectDate(entry.getValue());
            Move move = this.createMove(company, rejectDate);
            for (String[] reject : entry.getKey()) {
                try {
                    Reimbursement reimbursement = reimbursementImportService.createReimbursementRejectMoveLine(reject, companyRepo.find(company.getId()), seq, moveRepo.find(move.getId()), rejectDate);
                    if (reimbursement != null) {
                        log.debug("Remboursement n° {} traité", reimbursement.getRef());
                        seq++;
                        i++;
                        updateReimbursement(reimbursement);
                    }
                } catch (AxelorException e) {
                    TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_7), reject[1]), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
                    incrementAnomaly();
                } catch (Exception e) {
                    TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_7), reject[1]), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
                    incrementAnomaly();
                    log.error("Bug(Anomalie) généré(e) pour le rejet de remboursement {}", reject[1]);
                } finally {
                    if (i % 10 == 0) {
                        JPA.clear();
                    }
                }
            }
            this.validateMove(move, rejectDate, seq);
        }
        updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(company);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) List(java.util.List) Reimbursement(com.axelor.apps.account.db.Reimbursement)

Example 93 with Move

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

the class InvoiceServiceImpl method removeBecauseOfAmountRemaining.

protected boolean removeBecauseOfAmountRemaining(Invoice invoice, Invoice candidateAdvancePayment) throws AxelorException {
    List<InvoicePayment> invoicePayments = candidateAdvancePayment.getInvoicePaymentList();
    // no payment : remove the candidate invoice
    if (invoicePayments == null || invoicePayments.isEmpty()) {
        return true;
    }
    // imputed
    if (!accountConfigService.getAccountConfig(invoice.getCompany()).getGenerateMoveForInvoicePayment()) {
        for (InvoicePayment invoicePayment : invoicePayments) {
            if (invoicePayment.getImputedBy() == null) {
                return false;
            }
        }
        return true;
    }
    // else we check the remaining amount
    for (InvoicePayment invoicePayment : invoicePayments) {
        Move move = invoicePayment.getMove();
        if (move == null) {
            continue;
        }
        List<MoveLine> moveLineList = move.getMoveLineList();
        if (moveLineList == null || moveLineList.isEmpty()) {
            continue;
        }
        for (MoveLine moveLine : moveLineList) {
            BigDecimal amountRemaining = moveLine.getAmountRemaining();
            if (amountRemaining != null && amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal)

Example 94 with Move

use of com.axelor.apps.account.db.Move 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 95 with Move

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

the class DebtRecoveryService method getMoveLineDebtRecovery.

/**
 * Returns a list of recoverable move lines of a partner in the scope of the activity of a company
 *
 * @param partner The partner to be concerned by the move lines
 * @param company The company to be concerned by the move lines
 * @param tradingName (Optional) The trading name to be concerned by the move lines
 * @return A list of recoverable move lines
 */
@SuppressWarnings("unchecked")
public List<MoveLine> getMoveLineDebtRecovery(Partner partner, Company company, TradingName tradingName) {
    List<MoveLine> moveLineList = new ArrayList<MoveLine>();
    List<MoveLine> moveLineQuery = (List<MoveLine>) this.getMoveLine(partner, company, tradingName);
    int mailTransitTime = company.getAccountConfig().getMailTransitTime();
    for (MoveLine moveLine : moveLineQuery) {
        if (moveLine.getMove() != null && !moveLine.getMove().getIgnoreInDebtRecoveryOk()) {
            Move move = moveLine.getMove();
            // d'acheminement < date du jour
            if (move.getStatusSelect() != MoveRepository.STATUS_CANCELED && move.getInvoice() != null && !move.getInvoice().getDebtRecoveryBlockingOk() && !move.getInvoice().getSchedulePaymentOk() && ((move.getInvoice().getInvoiceDate()).plusDays(mailTransitTime)).isBefore(appAccountService.getTodayDate(company))) {
                if ((moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) && moveLine.getDueDate() != null && (appAccountService.getTodayDate(company).isAfter(moveLine.getDueDate()) || appAccountService.getTodayDate(company).isEqual(moveLine.getDueDate()))) {
                    if (moveLine.getAccount() != null && moveLine.getAccount().getUseForPartnerBalance()) {
                        if (moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0) {
                            moveLineList.add(moveLine);
                        }
                    }
                }
            } else // échéances rejetées qui ne sont pas bloqués
            if (move.getInvoice() == null) {
                if (moveLine.getPaymentScheduleLine() != null && (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) && moveLine.getDueDate() != null && (appAccountService.getTodayDate(company).isAfter(moveLine.getDueDate()) || appAccountService.getTodayDate(company).isEqual(moveLine.getDueDate()))) {
                    if (moveLine.getAccount() != null && moveLine.getAccount().getUseForPartnerBalance()) {
                        if (moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0) {
                            moveLineList.add(moveLine);
                        }
                    }
                }
            }
        }
    }
    return moveLineList;
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Move (com.axelor.apps.account.db.Move)101 MoveLine (com.axelor.apps.account.db.MoveLine)51 Transactional (com.google.inject.persist.Transactional)37 Company (com.axelor.apps.base.db.Company)36 AxelorException (com.axelor.exception.AxelorException)34 BigDecimal (java.math.BigDecimal)33 Partner (com.axelor.apps.base.db.Partner)31 LocalDate (java.time.LocalDate)28 Journal (com.axelor.apps.account.db.Journal)25 Account (com.axelor.apps.account.db.Account)22 ArrayList (java.util.ArrayList)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)18 Reconcile (com.axelor.apps.account.db.Reconcile)14 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)11 Invoice (com.axelor.apps.account.db.Invoice)11 List (java.util.List)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)5 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)5 MoveService (com.axelor.apps.account.service.move.MoveService)5