Search in sources :

Example 21 with Journal

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

the class BankReconciliationService method getJournal.

public Journal getJournal(BankReconciliation bankReconciliation) {
    Journal journal = null;
    String journalIds = String.join(",", getAccountManagementJournals(bankReconciliation));
    if (bankReconciliation.getBankDetails().getJournal() != null) {
        journal = bankReconciliation.getBankDetails().getJournal();
    } else if (!Strings.isNullOrEmpty(journalIds) && (journalIds.split(",").length) == 1) {
        journal = Beans.get(JournalRepository.class).find(Long.parseLong(journalIds));
    }
    return journal;
}
Also used : JournalRepository(com.axelor.apps.account.db.repo.JournalRepository) Journal(com.axelor.apps.account.db.Journal)

Example 22 with Journal

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

the class BankOrderMoveServiceImpl method generateReceiverMove.

protected Move generateReceiverMove(BankOrderLine bankOrderLine) throws AxelorException {
    Partner partner = bankOrderLine.getPartner();
    Company receiverCompany = bankOrderLine.getReceiverCompany();
    BankDetails receiverBankDetails = bankOrderLine.getReceiverBankDetails();
    Journal receiverJournal = paymentModeService.getPaymentModeJournal(paymentMode, receiverCompany, receiverBankDetails);
    Account receiverBankAccount = paymentModeService.getPaymentModeAccount(paymentMode, receiverCompany, receiverBankDetails);
    Move receiverMove = moveService.getMoveCreateService().createMove(receiverJournal, receiverCompany, this.getCurrency(bankOrderLine), partner, this.getDate(bankOrderLine), paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    MoveLine bankMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, receiverBankAccount, bankOrderLine.getBankOrderAmount(), isDebit, receiverMove.getDate(), 1, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
    receiverMove.addMoveLineListItem(bankMoveLine);
    MoveLine partnerMoveLine = moveService.getMoveLineService().createMoveLine(receiverMove, partner, getPartnerAccount(partner, receiverCompany, receiverMove.getCompany()), bankOrderLine.getBankOrderAmount(), !isDebit, receiverMove.getDate(), 2, bankOrderLine.getReceiverReference(), bankOrderLine.getReceiverLabel());
    receiverMove.addMoveLineListItem(partnerMoveLine);
    return receiverMove;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner)

Example 23 with Journal

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

the class PaymentVoucherConfirmService method createMoveAndConfirm.

/**
 * Confirm payment voucher and create move.
 *
 * @param paymentVoucher
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createMoveAndConfirm(PaymentVoucher paymentVoucher) throws AxelorException {
    Partner payerPartner = paymentVoucher.getPartner();
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    LocalDate paymentDate = paymentVoucher.getPaymentDate();
    boolean scheduleToBePaid = false;
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    // If paid by a moveline check if all the lines selected have the same account + company
    // Excess payment
    boolean allRight = paymentVoucherControlService.checkIfSameAccount(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine());
    // Check if allright=true (means companies and accounts in lines are all the same and same as in
    // move line selected for paying
    log.debug("allRight : {}", allRight);
    if (allRight) {
        scheduleToBePaid = this.toPayWithExcessPayment(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine(), scheduleToBePaid, paymentDate);
    }
    if (paymentVoucher.getMoveLine() == null || (paymentVoucher.getMoveLine() != null && !allRight) || (scheduleToBePaid && !allRight && paymentVoucher.getMoveLine() != null)) {
        // Manage all the cases in the same way. As if a move line (Excess payment) is selected, we
        // cancel it first
        Move move = moveService.getMoveCreateService().createMoveWithPaymentVoucher(journal, company, paymentVoucher, payerPartner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        move.setPaymentVoucher(paymentVoucher);
        move.setTradingName(paymentVoucher.getTradingName());
        paymentVoucher.setGeneratedMove(move);
        // Create move lines for payment lines
        BigDecimal paidLineTotal = BigDecimal.ZERO;
        int moveLineNo = 1;
        boolean isDebitToPay = paymentVoucherToolService.isDebitToPay(paymentVoucher);
        for (PayVoucherElementToPay payVoucherElementToPay : this.getPayVoucherElementToPayList(paymentVoucher)) {
            MoveLine moveLineToPay = payVoucherElementToPay.getMoveLine();
            log.debug("PV moveLineToPay debit : {}", moveLineToPay.getDebit());
            log.debug("PV moveLineToPay amountPaid : {}", moveLineToPay.getAmountPaid());
            BigDecimal amountToPay = payVoucherElementToPay.getAmountToPayCurrency();
            if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
                paidLineTotal = paidLineTotal.add(amountToPay);
                this.payMoveLine(move, moveLineNo++, payerPartner, moveLineToPay, amountToPay, payVoucherElementToPay, isDebitToPay, paymentDate);
            }
        }
        // Create move line for the payment amount
        MoveLine moveLine = null;
        // in the else case we create a classical balance on the bank account of the payment mode
        if (paymentVoucher.getMoveLine() != null) {
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), paymentVoucher.getMoveLine().getAccount(), paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            Reconcile reconcile = reconcileService.createReconcile(moveLine, paymentVoucher.getMoveLine(), moveLine.getDebit(), !isDebitToPay);
            if (reconcile != null) {
                reconcileService.confirmReconcile(reconcile, true);
            }
        } else {
            moveLine = moveLineService.createMoveLine(move, payerPartner, paymentModeAccount, paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
        }
        move.getMoveLineList().add(moveLine);
        // Then Use Excess payment on old invoices / moveLines
        if (paymentVoucher.getPaidAmount().compareTo(paidLineTotal) > 0) {
            BigDecimal remainingPaidAmount = paymentVoucher.getRemainingAmount();
            // TODO rajouter le process d'imputation automatique
            // if(paymentVoucher.getHasAutoInput())  {
            // 
            // List<MoveLine> debitMoveLines =
            // Lists.newArrayList(pas.getDebitLinesToPay(contractLine,
            // paymentVoucher.getPaymentScheduleToPay()));
            // pas.createExcessPaymentWithAmount(debitMoveLines, remainingPaidAmount,
            // move, moveLineNo,
            // paymentVoucher.getPayerPartner(), company, contractLine, null,
            // paymentDate, updateCustomerAccount);
            // }
            // else  {
            Account partnerAccount = Beans.get(AccountCustomerService.class).getPartnerAccount(payerPartner, company, paymentVoucherToolService.isPurchase(paymentVoucher));
            moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), partnerAccount, remainingPaidAmount, !isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
            move.getMoveLineList().add(moveLine);
            if (isDebitToPay) {
                reconcileService.balanceCredit(moveLine);
            }
        }
        moveService.getMoveValidateService().validate(move);
        paymentVoucher.setGeneratedMove(move);
    }
    paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_CONFIRMED);
    deleteUnPaidLines(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) AccountCustomerService(com.axelor.apps.account.service.AccountCustomerService) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 24 with Journal

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

the class PaymentVoucherConfirmService method confirmPaymentVoucher.

/**
 * Confirms the payment voucher if the selected lines PiToPay 2nd O2M belongs to different
 * companies -> error I - Payment with an amount If we pay a classical moveLine (invoice, reject
 * ..) -> just create a payment If we pay a schedule 2 payments are created 1st reconciled with
 * the invoice and the second reconciled with the schedule II - Payment with an excess Payment If
 * we pay a moveLine having the same account, we just reconcile If we pay a with different account
 * -> 1- switch money to the good account 2- reconcile then
 *
 * @param paymentVoucher
 */
@Transactional(rollbackOn = { Exception.class })
public void confirmPaymentVoucher(PaymentVoucher paymentVoucher) throws AxelorException {
    log.debug("In confirmPaymentVoucherService ....");
    paymentVoucherSequenceService.setReference(paymentVoucher);
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    paymentVoucherControlService.checkPaymentVoucherField(paymentVoucher, company, paymentModeAccount, journal);
    if (paymentVoucher.getRemainingAmount().compareTo(BigDecimal.ZERO) > 0 && !journal.getExcessPaymentOk()) {
        throw new AxelorException(paymentVoucher, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_AMOUNT_EXCEEDING), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    // TODO VEIRIFER QUE LES ELEMENTS A PAYER NE CONCERNE QU'UNE SEULE DEVISE
    // TODO RECUPERER DEVISE DE LA PREMIERE DETTE
    // Currency currencyToPay = null;
    AppAccountService appAccountService = Beans.get(AppAccountService.class);
    if (appAccountService.getAppAccount().getPaymentVouchersOnInvoice() && paymentVoucher.getPaymentMode().getValidatePaymentByDepositSlipPublication()) {
        waitForDepositSlip(paymentVoucher);
    } else {
        createMoveAndConfirm(paymentVoucher);
    }
    paymentVoucherSequenceService.setReceiptNo(paymentVoucher, company, journal);
    paymentVoucherRepository.save(paymentVoucher);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) Transactional(com.google.inject.persist.Transactional)

Example 25 with Journal

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

the class InvoicePaymentValidateServiceImpl method createMoveForInvoicePayment.

/**
 * Method to create a payment move for an invoice Payment
 *
 * <p>Create a move and reconcile it with the invoice move
 *
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createMoveForInvoicePayment(InvoicePayment invoicePayment) throws AxelorException {
    Invoice invoice = invoicePayment.getInvoice();
    Company company = invoice.getCompany();
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    Partner partner = invoice.getPartner();
    LocalDate paymentDate = invoicePayment.getPaymentDate();
    BigDecimal paymentAmount = invoicePayment.getAmount();
    BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails();
    Account customerAccount;
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    boolean isDebitInvoice = moveService.getMoveToolService().isDebitCustomer(invoice, true);
    MoveLine invoiceMoveLine = moveService.getMoveToolService().getInvoiceCustomerMoveLineByLoop(invoice);
    if (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        customerAccount = accountConfigService.getAdvancePaymentAccount(accountConfig);
    } else {
        if (invoiceMoveLine == null) {
            return null;
        }
        customerAccount = invoiceMoveLine.getAccount();
    }
    String origin = invoicePayment.getInvoice().getInvoiceId();
    if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_CHEQUE || invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_IPO_CHEQUE) {
        origin = invoicePayment.getChequeNumber() != null ? invoicePayment.getChequeNumber() : origin;
    } else if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_BANK_CARD) {
        origin = invoicePayment.getInvoicePaymentRef() != null ? invoicePayment.getInvoicePaymentRef() : origin;
    }
    if (invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
        origin = invoicePayment.getInvoice().getSupplierInvoiceNb();
    }
    Move move = moveService.getMoveCreateService().createMove(journal, company, invoicePayment.getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    move.setTradingName(invoice.getTradingName());
    move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, isDebitInvoice, paymentDate, null, 1, origin, invoicePayment.getDescription()));
    MoveLine customerMoveLine = moveLineService.createMoveLine(move, partner, customerAccount, paymentAmount, !isDebitInvoice, paymentDate, null, 2, origin, invoicePayment.getDescription());
    move.addMoveLineListItem(customerMoveLine);
    moveService.getMoveValidateService().validate(move);
    if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
        Reconcile reconcile = reconcileService.reconcile(invoiceMoveLine, customerMoveLine, true, false);
        invoicePayment.setReconcile(reconcile);
    }
    invoicePayment.setMove(move);
    invoicePaymentRepository.save(invoicePayment);
    return invoicePayment;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Aggregations

Journal (com.axelor.apps.account.db.Journal)35 Company (com.axelor.apps.base.db.Company)26 Move (com.axelor.apps.account.db.Move)24 MoveLine (com.axelor.apps.account.db.MoveLine)21 Account (com.axelor.apps.account.db.Account)18 Transactional (com.google.inject.persist.Transactional)18 BigDecimal (java.math.BigDecimal)18 Partner (com.axelor.apps.base.db.Partner)17 LocalDate (java.time.LocalDate)16 ArrayList (java.util.ArrayList)10 AccountConfig (com.axelor.apps.account.db.AccountConfig)9 BankDetails (com.axelor.apps.base.db.BankDetails)9 PaymentMode (com.axelor.apps.account.db.PaymentMode)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 AxelorException (com.axelor.exception.AxelorException)6 Query (javax.persistence.Query)5 Invoice (com.axelor.apps.account.db.Invoice)4 JournalType (com.axelor.apps.account.db.JournalType)4 Reconcile (com.axelor.apps.account.db.Reconcile)4 FixedAsset (com.axelor.apps.account.db.FixedAsset)2