Search in sources :

Example 21 with MoveLine

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

the class ChequeRejectionService method createChequeRejectionMove.

/**
 * Méthode permettant de créer une écriture de rejet de chèque (L'extourne de l'écriture de
 * paiement)
 *
 * @param chequeRejection Un rejet de cheque brouillon
 * @param company Une société
 * @return L'écriture de rejet de chèque
 * @throws AxelorException
 */
public Move createChequeRejectionMove(ChequeRejection chequeRejection, Company company) throws AxelorException {
    this.testCompanyField(company);
    Journal journal = company.getAccountConfig().getRejectJournal();
    PaymentVoucher paymentVoucher = chequeRejection.getPaymentVoucher();
    Move paymentMove = paymentVoucher.getGeneratedMove();
    Partner partner = paymentVoucher.getPartner();
    InterbankCodeLine interbankCodeLine = chequeRejection.getInterbankCodeLine();
    String description = chequeRejection.getDescription();
    LocalDate rejectionDate = chequeRejection.getRejectionDate();
    // Move
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, rejectionDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    int ref = 1;
    for (MoveLine moveLine : paymentMove.getMoveLineList()) {
        if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
            // Debit MoveLine
            MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getCredit(), true, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(debitMoveLine);
            debitMoveLine.setInterbankCodeLine(interbankCodeLine);
            debitMoveLine.setDescription(description);
        } else {
            // Credit MoveLine
            MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getDebit(), false, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(creditMoveLine);
            creditMoveLine.setInterbankCodeLine(interbankCodeLine);
            creditMoveLine.setDescription(description);
        }
        ref++;
    }
    move.setRejectOk(true);
    moveService.getMoveValidateService().validate(move);
    return move;
}
Also used : Move(com.axelor.apps.account.db.Move) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher)

Example 22 with MoveLine

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

the class DoubtfulCustomerService method createDoubtFulCustomerMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
 * de facture
 *
 * @param move Une écritures de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createDoubtFulCustomerMove(Move move, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
    log.debug("Concerned account move : {} ", move.getReference());
    Company company = move.getCompany();
    Partner partner = move.getPartner();
    Invoice invoice = move.getInvoice();
    Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, invoice.getCurrency(), partner, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, move.getFunctionalOriginSelect());
    newMove.setInvoice(invoice);
    LocalDate todayDate = appBaseService.getTodayDate(company);
    MoveLine invoicePartnerMoveLine = null;
    for (MoveLine moveLine : move.getMoveLineList()) {
        if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getAccount() != doubtfulCustomerAccount && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            invoicePartnerMoveLine = moveLine;
        }
    }
    String origin = "";
    BigDecimal amountRemaining = BigDecimal.ZERO;
    MoveLine creditMoveLine = null;
    if (invoicePartnerMoveLine != null) {
        amountRemaining = invoicePartnerMoveLine.getAmountRemaining();
        // Debit move line on partner account
        creditMoveLine = moveLineService.createMoveLine(newMove, partner, invoicePartnerMoveLine.getAccount(), amountRemaining, false, todayDate, 1, move.getInvoice().getInvoiceId(), debtPassReason);
        newMove.getMoveLineList().add(creditMoveLine);
        origin = creditMoveLine.getOrigin();
    }
    // Credit move line on partner account
    MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, partner, doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, origin, debtPassReason);
    newMove.getMoveLineList().add(debitMoveLine);
    debitMoveLine.setPassageReason(debtPassReason);
    moveService.getMoveValidateService().validate(newMove);
    moveRepo.save(newMove);
    if (creditMoveLine != null) {
        Reconcile reconcile = reconcileService.createReconcile(invoicePartnerMoveLine, creditMoveLine, amountRemaining, false);
        if (reconcile != null) {
            reconcileService.confirmReconcile(reconcile, true);
        }
    }
    this.invoiceProcess(newMove, doubtfulCustomerAccount, debtPassReason);
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 23 with MoveLine

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

the class DoubtfulCustomerService method updateDoubtfulCustomerMove.

/**
 * Procédure permettant de mettre à jour le motif de passage en client douteux, et créer
 * l'évènement lié.
 *
 * @param moveList Une liste d'éciture de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 */
public void updateDoubtfulCustomerMove(List<Move> moveList, Account doubtfulCustomerAccount, String debtPassReason) {
    for (Move move : moveList) {
        for (MoveLine moveLine : move.getMoveLineList()) {
            if (moveLine.getAccount().equals(doubtfulCustomerAccount) && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
                moveLine.setPassageReason(debtPassReason);
                moveLineRepo.save(moveLine);
                break;
            }
        }
    }
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 24 with MoveLine

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

the class BatchDoubtfulCustomer method createDoubtFulCustomerRejectMove.

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

Example 25 with MoveLine

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

the class BatchDoubtfulCustomer method process.

@SuppressWarnings("unchecked")
@Override
protected void process() {
    if (!end) {
        Company company = batch.getAccountingBatch().getCompany();
        AccountConfig accountConfig = company.getAccountConfig();
        Account doubtfulCustomerAccount = accountConfig.getDoubtfulCustomerAccount();
        String sixMonthDebtPassReason = accountConfig.getSixMonthDebtPassReason();
        String threeMonthDebtPassReason = accountConfig.getThreeMonthDebtPassReason();
        // FACTURES
        List<Move> moveList = doubtfulCustomerService.getMove(0, doubtfulCustomerAccount, company);
        log.debug("Nombre d'écritures de facture concernées (Créance de + 6 mois) au 411 : {} ", moveList.size());
        this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, sixMonthDebtPassReason);
        moveList = doubtfulCustomerService.getMove(1, doubtfulCustomerAccount, company);
        log.debug("Nombre d'écritures de facture concernées (Créance de + 3 mois) au 411 : {} ", moveList.size());
        this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, threeMonthDebtPassReason);
        // FACTURES REJETES
        List<MoveLine> moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(0, doubtfulCustomerAccount, company);
        log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 6 mois) au 411 : {} ", moveLineList.size());
        this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, sixMonthDebtPassReason);
        moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(1, doubtfulCustomerAccount, company);
        log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 3 mois) au 411 : {} ", moveLineList.size());
        this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, threeMonthDebtPassReason);
        updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(companyRepo.find(company.getId()));
    }
}
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) List(java.util.List) AccountConfig(com.axelor.apps.account.db.AccountConfig)

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