/**
   * Procédure permettant de créer une écriture de paiement d'une facture
   *
   * @param company Une société
   * @param moveLine Une ligne d'écriture
   * @param pm Un mode de paiement
   * @param pse Un Export des prélèvement
   * @throws AxelorException
   */
  public Move createPaymentMove(Company company, MoveLine moveLine, PaymentMode paymentMode)
      throws AxelorException {

    log.debug("Create payment move");

    Move paymentMove =
        moveService
            .getMoveCreateService()
            .createMove(
                paymentModeService.getPaymentModeJournal(paymentMode, company),
                company,
                null,
                null,
                paymentMode);

    BigDecimal amountExported = moveLine.getAmountRemaining();

    this.createPaymentMoveLine(paymentMove, moveLine, 1);

    log.debug("Create payment move line");

    Account paymentModeAccount = paymentModeService.getCompanyAccount(paymentMode, company);

    String invoiceName = "";
    if (moveLine.getMove().getInvoice() != null) {
      invoiceName = moveLine.getMove().getInvoice().getInvoiceId();
    }
    MoveLine moveLineGenerated2 =
        moveLineServices.createMoveLine(
            paymentMove, null, paymentModeAccount, amountExported, true, today, 2, invoiceName);

    paymentMove.getMoveLineList().add(moveLineGenerated2);
    moveLineRepo.save(moveLineGenerated2);

    moveService.getMoveValidateService().validateMove(paymentMove);
    moveRepo.save(paymentMove);

    return paymentMove;
  }
 @Transactional(rollbackOn = {AxelorException.class, Exception.class})
 public Move validateMove(Move move) throws AxelorException {
   moveService.getMoveValidateService().validateMove(move);
   moveRepo.save(move);
   return move;
 }
  @Transactional(rollbackOn = {AxelorException.class, Exception.class})
  public PaymentScheduleLine generateExportMensu(
      PaymentScheduleLine paymentScheduleLine,
      List<PaymentScheduleLine> paymentScheduleLineList,
      Company company)
      throws AxelorException {

    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();

    this.testBankDetails(paymentSchedule);

    AccountConfig accountConfig = company.getAccountConfig();

    Account account = accountConfig.getCustomerAccount();
    PaymentMode paymentMode = accountConfig.getDirectDebitPaymentMode();

    BigDecimal amount = paymentScheduleLine.getInTaxAmount();
    Partner partner = paymentSchedule.getPartner();

    Move move =
        moveService
            .getMoveCreateService()
            .createMove(
                paymentModeService.getPaymentModeJournal(paymentMode, company),
                company,
                null,
                partner,
                paymentMode);

    this.setDebitNumber(paymentScheduleLineList, paymentScheduleLine, company);

    MoveLine moveLine =
        moveLineRepo.save(
            moveLineServices.createMoveLine(
                move, partner, account, amount, false, today, 1, paymentScheduleLine.getName()));

    move.addMoveLineListItem(moveLine);

    if (paymentScheduleLine.getFromReject()) {
      // lettrage avec le rejet
      PaymentScheduleLine rejectedPaymentScheduleLine =
          this.getPaymentScheduleLineRejectOrigin(paymentScheduleLine);
      if (rejectedPaymentScheduleLine.getRejectMoveLine() != null
          && rejectedPaymentScheduleLine
                  .getRejectMoveLine()
                  .getAmountRemaining()
                  .compareTo(BigDecimal.ZERO)
              == 1) {
        reconcileService.reconcile(rejectedPaymentScheduleLine.getRejectMoveLine(), moveLine);
      }
    } else {
      // Lettrage du paiement avec les factures d'échéances
      this.reconcileDirectDebit(moveLine, paymentSchedule);
    }

    move.addMoveLineListItem(
        moveLineServices.createMoveLine(
            move,
            partner,
            paymentModeService.getCompanyAccount(paymentMode, company),
            amount,
            true,
            today,
            2,
            null));

    this.validateMove(move);

    paymentScheduleLine.setDirectDebitAmount(amount);
    paymentScheduleLine.setInTaxAmountPaid(amount);
    paymentScheduleLine.setAdvanceOrPaymentMove(moveRepo.find(move.getId()));
    paymentScheduleLine.setAdvanceMoveLine(moveLine);
    paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
    return paymentScheduleLineRepo.save(paymentScheduleLine);
  }