Search in sources :

Example 56 with MoveLine

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

the class MoveCancelService method cancel.

@Transactional(rollbackOn = { Exception.class })
public void cancel(Move move) throws AxelorException {
    if (move == null) {
        return;
    }
    for (MoveLine moveLine : move.getMoveLineList()) {
        if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountPaid().compareTo(BigDecimal.ZERO) != 0) {
            throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_1));
        }
    }
    if (move.getPeriod() == null || move.getPeriod().getStatusSelect() == PeriodRepository.STATUS_CLOSED) {
        throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_2));
    }
    if (move.getStatusSelect().equals(MoveRepository.STATUS_VALIDATED)) {
        throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_4));
    }
    try {
        if (move.getStatusSelect() == MoveRepository.STATUS_NEW || accountConfigService.getAccountConfig(move.getCompany()).getAllowRemovalValidatedMove()) {
            moveRepository.remove(move);
        } else {
            move.setStatusSelect(MoveRepository.STATUS_CANCELED);
            moveRepository.save(move);
        }
    } catch (Exception e) {
        throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_CANCEL_3));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 57 with MoveLine

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

the class MoveCreateService method createMove.

/**
 * Creating a new generic accounting move
 *
 * @param journal
 * @param company
 * @param currency
 * @param partner
 * @param date
 * @param paymentMode
 * @param technicalOriginSelect
 * @param ignoreInDebtRecoveryOk
 * @param ignoreInAccountingOk
 * @return
 * @throws AxelorException
 */
public Move createMove(Journal journal, Company company, Currency currency, Partner partner, LocalDate date, PaymentMode paymentMode, int technicalOriginSelect, int functionalOriginSelect, boolean ignoreInDebtRecoveryOk, boolean ignoreInAccountingOk, boolean autoYearClosureMove) throws AxelorException {
    log.debug("Creating a new generic accounting move (journal : {}, company : {}", new Object[] { journal.getName(), company.getName() });
    Move move = new Move();
    move.setJournal(journal);
    move.setCompany(company);
    move.setIgnoreInDebtRecoveryOk(ignoreInDebtRecoveryOk);
    move.setIgnoreInAccountingOk(ignoreInAccountingOk);
    move.setAutoYearClosureMove(autoYearClosureMove);
    if (autoYearClosureMove) {
        move.setPeriod(periodService.getPeriod(date, company, YearRepository.TYPE_FISCAL));
        if (move.getPeriod() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), date.toString());
        }
    } else {
        move.setPeriod(periodService.getActivePeriod(date, company, YearRepository.TYPE_FISCAL));
    }
    move.setDate(date);
    move.setMoveLineList(new ArrayList<MoveLine>());
    Currency companyCurrency = companyConfigService.getCompanyCurrency(company);
    if (companyCurrency != null) {
        move.setCompanyCurrency(companyCurrency);
        move.setCompanyCurrencyCode(companyCurrency.getCode());
    }
    if (currency == null) {
        currency = move.getCompanyCurrency();
    }
    if (currency != null) {
        move.setCurrency(currency);
        move.setCurrencyCode(currency.getCode());
    }
    move.setPartner(partner);
    move.setPaymentMode(paymentMode);
    move.setTechnicalOriginSelect(technicalOriginSelect);
    move.setFunctionalOriginSelect(functionalOriginSelect);
    moveRepository.save(move);
    move.setReference(Beans.get(SequenceService.class).getDraftSequenceNumber(move));
    return move;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) Currency(com.axelor.apps.base.db.Currency) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 58 with MoveLine

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

the class MoveDueService method getInvoiceDue.

public List<MoveLine> getInvoiceDue(Invoice invoice, boolean useOthersInvoiceDue) throws AxelorException {
    Company company = invoice.getCompany();
    Partner partner = invoice.getPartner();
    List<MoveLine> debitMoveLines = Lists.newArrayList();
    // Ajout de la facture d'origine
    MoveLine originalInvoice = this.getOrignalInvoiceFromRefund(invoice);
    if (originalInvoice != null) {
        debitMoveLines.add(originalInvoice);
    }
    // Récupérer les dûs du tiers pour le même compte que celui de l'avoir
    List<? extends MoveLine> othersDebitMoveLines = null;
    if (useOthersInvoiceDue) {
        if (debitMoveLines != null && debitMoveLines.size() != 0) {
            othersDebitMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.debit > 0 AND self.amountRemaining > 0 " + " AND self.partner = ?5 AND self NOT IN (?6) ORDER BY self.date ASC ", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, partner, debitMoveLines).fetch();
        } else {
            othersDebitMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.debit > 0 AND self.amountRemaining > 0 " + " AND self.partner = ?5 ORDER BY self.date ASC ", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, partner).fetch();
        }
        debitMoveLines.addAll(othersDebitMoveLines);
    }
    log.debug("Nombre de ligne à payer avec l'avoir récupéré : {}", debitMoveLines.size());
    return debitMoveLines;
}
Also used : Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner)

Example 59 with MoveLine

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

the class PaymentVoucherCreateService method createPaymentVoucherIPO.

@Transactional(rollbackOn = { Exception.class })
public PaymentVoucher createPaymentVoucherIPO(Invoice invoice, LocalDate date, BigDecimal amount, PaymentMode paymentMode) throws AxelorException {
    MoveLine customerMoveLine = moveToolService.getCustomerMoveLineByQuery(invoice);
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - facture : {}", invoice.getInvoiceId());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - mode de paiement : {}", paymentMode.getCode());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - société : {}", invoice.getCompany().getName());
    log.debug("Création d'une saisie paiement par TIP ou TIP chèque - tiers payeur : {}", invoice.getPartner().getName());
    PaymentVoucher paymentVoucher = this.createPaymentVoucher(invoice.getCompany(), null, paymentMode, date, invoice.getPartner(), amount, null, invoice, null, null, null);
    paymentVoucher.setHasAutoInput(true);
    List<PayVoucherElementToPay> lines = new ArrayList<PayVoucherElementToPay>();
    lines.add(payVoucherElementToPayService.createPayVoucherElementToPay(paymentVoucher, 1, invoice, customerMoveLine, customerMoveLine.getDebit(), customerMoveLine.getAmountRemaining(), amount));
    paymentVoucher.setPayVoucherElementToPayList(lines);
    paymentVoucherRepository.save(paymentVoucher);
    paymentVoucherConfirmService.confirmPaymentVoucher(paymentVoucher);
    return paymentVoucher;
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) Transactional(com.google.inject.persist.Transactional)

Example 60 with MoveLine

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

the class InvoicePaymentCreateServiceImpl method determineIfReconcileFromInvoice.

/**
 * We try to get to the status of the invoice from the reconcile to see if this move was created
 * from a payment for an advance payment invoice.
 *
 * @param move
 * @return the found advance invoice if the move is from a payment that comes from this invoice.
 *     null in other cases
 */
protected Invoice determineIfReconcileFromInvoice(Move move) {
    List<MoveLine> moveLineList = move.getMoveLineList();
    if (moveLineList == null || moveLineList.size() != 2) {
        return null;
    }
    InvoicePaymentRepository invoicePaymentRepo = Beans.get(InvoicePaymentRepository.class);
    for (MoveLine moveLine : moveLineList) {
        // search for the reconcile between the debit line
        if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            Reconcile reconcile = Beans.get(ReconcileRepository.class).all().filter("self.debitMoveLine = ?", moveLine).fetchOne();
            if (reconcile == null) {
                return null;
            }
            // associated payment
            if (reconcile.getCreditMoveLine() == null || reconcile.getCreditMoveLine().getMove() == null) {
                continue;
            }
            Move candidatePaymentMove = reconcile.getCreditMoveLine().getMove();
            InvoicePayment invoicePayment = invoicePaymentRepo.all().filter("self.move = :_move").bind("_move", candidatePaymentMove).fetchOne();
            // payment, then return true.
            if (invoicePayment != null && invoicePayment.getInvoice() != null && invoicePayment.getInvoice().getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
                return invoicePayment.getInvoice();
            }
        }
    }
    return null;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) InvoicePaymentRepository(com.axelor.apps.account.db.repo.InvoicePaymentRepository) Reconcile(com.axelor.apps.account.db.Reconcile)

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