Search in sources :

Example 1 with InterbankCodeLine

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

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

the class BankStatementFileAFB120Service method createBankStatementLine.

@Transactional
public BankStatementLineAFB120 createBankStatementLine(Map<String, Object> structuredContentLine, int sequence) {
    String description = (String) structuredContentLine.get("description");
    if (structuredContentLine.containsKey("additionalInformation") && structuredContentLine.get("additionalInformation") != null) {
        description += "\n" + (String) structuredContentLine.get("additionalInformation");
    }
    BankDetails bankDetails = null;
    if (structuredContentLine.containsKey("bankDetails") && structuredContentLine.get("bankDetails") != null) {
        bankDetails = bankDetailsRepository.find(((BankDetails) structuredContentLine.get("bankDetails")).getId());
    }
    Currency currency = null;
    if (structuredContentLine.containsKey("currency") && structuredContentLine.get("currency") != null) {
        currency = currencyRepository.find(((Currency) structuredContentLine.get("currency")).getId());
    }
    InterbankCodeLine operationInterbankCodeLine = null;
    if (structuredContentLine.containsKey("operationInterbankCodeLine") && structuredContentLine.get("operationInterbankCodeLine") != null) {
        operationInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("operationInterbankCodeLine")).getId());
    }
    InterbankCodeLine rejectInterbankCodeLine = null;
    if (structuredContentLine.containsKey("rejectInterbankCodeLine") && structuredContentLine.get("rejectInterbankCodeLine") != null) {
        rejectInterbankCodeLine = interbankCodeLineRepository.find(((InterbankCodeLine) structuredContentLine.get("rejectInterbankCodeLine")).getId());
    }
    BankStatementLineAFB120 bankStatementLineAFB120 = bankStatementLineAFB120Service.createBankStatementLine(findBankStatement(), sequence, bankDetails, (BigDecimal) structuredContentLine.get("debit"), (BigDecimal) structuredContentLine.get("credit"), currency, description, (LocalDate) structuredContentLine.get("operationDate"), (LocalDate) structuredContentLine.get("valueDate"), operationInterbankCodeLine, rejectInterbankCodeLine, (String) structuredContentLine.get("origin"), (String) structuredContentLine.get("reference"), (int) structuredContentLine.get("lineType"), (String) structuredContentLine.get("unavailabilityIndexSelect"), (String) structuredContentLine.get("commissionExemptionIndexSelect"));
    return bankStatementLineAFB120Repository.save(bankStatementLineAFB120);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) Currency(com.axelor.apps.base.db.Currency) BankStatementLineAFB120(com.axelor.apps.bankpayment.db.BankStatementLineAFB120) Transactional(com.google.inject.persist.Transactional)

Example 3 with InterbankCodeLine

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

the class PaymentScheduleLineController method reject.

public void reject(ActionRequest request, ActionResponse response) {
    try {
        @SuppressWarnings("unchecked") List<? extends Number> idList = MoreObjects.firstNonNull((List<? extends Number>) request.getContext().get("idList"), Collections.emptyList());
        boolean represent = (boolean) request.getContext().get("represent");
        // TODO: one rejection reason per payment schedule line
        InterbankCodeLine interbankCodeLine;
        @SuppressWarnings("unchecked") Map<String, Object> interbankCodeLineMap = (Map<String, Object>) request.getContext().get("interbankCodeLine");
        if (interbankCodeLineMap != null) {
            interbankCodeLine = Beans.get(InterbankCodeLineRepository.class).find(((Number) interbankCodeLineMap.get("id")).longValue());
        } else {
            interbankCodeLine = null;
        }
        Map<Long, InterbankCodeLine> idMap = new LinkedHashMap<>();
        idList.stream().map(Number::longValue).forEach(id -> idMap.put(id, interbankCodeLine));
        PaymentScheduleLineBankPaymentService paymentScheduleLineBankPaymentService = Beans.get(PaymentScheduleLineBankPaymentService.class);
        if (idMap.size() == 1) {
            Entry<Long, InterbankCodeLine> entry = idMap.entrySet().iterator().next();
            long id = entry.getKey();
            InterbankCodeLine rejectionReason = entry.getValue();
            paymentScheduleLineBankPaymentService.reject(id, rejectionReason, represent);
        } else {
            int errorCount = paymentScheduleLineBankPaymentService.rejectFromIdMap(idMap, represent);
            if (errorCount != 0) {
                response.setError(String.format(I18n.get("%d errors occurred. Please check tracebacks for details."), errorCount));
                return;
            }
        }
        response.setFlash(String.format(I18n.get("%d line successfully rejected", "%d lines successfully rejected", idMap.size()), idMap.size()));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PaymentScheduleLineBankPaymentService(com.axelor.apps.bankpayment.service.PaymentScheduleLineBankPaymentService) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with InterbankCodeLine

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

the class PaymentScheduleLineBankPaymentServiceImpl method rejectFromMap.

protected <T> int rejectFromMap(Map<T, InterbankCodeLine> map, boolean represent, Function<T, PaymentScheduleLine> findFunc) {
    int errorCount = 0;
    for (Entry<T, InterbankCodeLine> entry : map.entrySet()) {
        T key = entry.getKey();
        InterbankCodeLine rejectionReason = entry.getValue();
        PaymentScheduleLine paymentScheduleLine = findFunc.apply(key);
        try {
            reject(paymentScheduleLine, rejectionReason, represent);
        } catch (Exception e) {
            TraceBackService.trace(e);
            ++errorCount;
        }
    }
    return errorCount;
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) AxelorException(com.axelor.exception.AxelorException)

Example 5 with InterbankCodeLine

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

the class ReimbursementImportService method createReimbursementRejectMoveLine.

@Transactional(rollbackOn = { Exception.class })
public Reimbursement createReimbursementRejectMoveLine(String[] reject, Company company, int seq, Move move, LocalDate rejectDate) throws AxelorException {
    String refReject = reject[1];
    // String amountReject = reject[2];
    InterbankCodeLine causeReject = rejectImportService.getInterbankCodeLine(reject[3], 0);
    MoveLineRepository moveLineRepo = Beans.get(MoveLineRepository.class);
    Reimbursement reimbursement = reimbursementRepo.all().filter("UPPER(self.ref) = ?1 AND self.company = ?2", refReject, company).fetchOne();
    if (reimbursement == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.REIMBURSEMENT_3), refReject, company.getName());
    }
    Partner partner = reimbursement.getPartner();
    BigDecimal amount = reimbursement.getAmountReimbursed();
    // Création de la ligne au crédit
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, company.getAccountConfig().getCustomerAccount(), amount, false, rejectDate, seq, refReject, null);
    move.getMoveLineList().add(creditMoveLine);
    moveLineRepo.save(creditMoveLine);
    moveRepo.save(move);
    creditMoveLine.setInterbankCodeLine(causeReject);
    reimbursement.setRejectedOk(true);
    reimbursement.setRejectDate(rejectDate);
    reimbursement.setRejectMoveLine(creditMoveLine);
    reimbursement.setInterbankCodeLine(causeReject);
    reimbursementRepo.save(reimbursement);
    return reimbursement;
}
Also used : AxelorException(com.axelor.exception.AxelorException) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) MoveLine(com.axelor.apps.account.db.MoveLine) Reimbursement(com.axelor.apps.account.db.Reimbursement) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

InterbankCodeLine (com.axelor.apps.account.db.InterbankCodeLine)5 MoveLine (com.axelor.apps.account.db.MoveLine)2 Partner (com.axelor.apps.base.db.Partner)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 Journal (com.axelor.apps.account.db.Journal)1 Move (com.axelor.apps.account.db.Move)1 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)1 PaymentVoucher (com.axelor.apps.account.db.PaymentVoucher)1 Reimbursement (com.axelor.apps.account.db.Reimbursement)1 MoveLineRepository (com.axelor.apps.account.db.repo.MoveLineRepository)1 BankStatementLineAFB120 (com.axelor.apps.bankpayment.db.BankStatementLineAFB120)1 PaymentScheduleLineBankPaymentService (com.axelor.apps.bankpayment.service.PaymentScheduleLineBankPaymentService)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 Currency (com.axelor.apps.base.db.Currency)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1