Search in sources :

Example 61 with Move

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

the class MoveController method filterPartner.

public void filterPartner(ActionRequest request, ActionResponse response) {
    Move move = request.getContext().asType(Move.class);
    if (move != null) {
        String domain = Beans.get(MoveService.class).filterPartner(move);
        response.setAttr("partner", "domain", domain);
    }
}
Also used : MoveService(com.axelor.apps.account.service.move.MoveService) ExtractContextMoveService(com.axelor.apps.account.service.extract.ExtractContextMoveService) Move(com.axelor.apps.account.db.Move)

Example 62 with Move

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

the class MoveServiceImpl method createMoveUseInvoiceDue.

/**
 * Méthode permettant d'employer les dûs sur l'avoir On récupère prioritairement les dûs
 * (factures) selectionné sur l'avoir, puis les autres dûs du tiers
 *
 * <p>2 cas : - le compte des dûs est le même que celui de l'avoir : alors on lettre directement -
 * le compte n'est pas le même : on créée une O.D. de passage sur le bon compte
 *
 * @param invoice
 * @return
 * @throws AxelorException
 */
@Override
public Move createMoveUseInvoiceDue(Invoice invoice) throws AxelorException {
    Company company = invoice.getCompany();
    Move move = null;
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    // Récupération des dûs
    List<MoveLine> debitMoveLines = moveDueService.getInvoiceDue(invoice, accountConfig.getAutoReconcileOnInvoice());
    if (!debitMoveLines.isEmpty()) {
        MoveLine invoiceCustomerMoveLine = moveToolService.getCustomerMoveLineByLoop(invoice);
        // Si c'est le même compte sur les trop-perçus et sur la facture, alors on lettre directement
        if (moveToolService.isSameAccount(debitMoveLines, invoiceCustomerMoveLine.getAccount())) {
            List<MoveLine> creditMoveLineList = new ArrayList<MoveLine>();
            creditMoveLineList.add(invoiceCustomerMoveLine);
            paymentService.useExcessPaymentOnMoveLines(debitMoveLines, creditMoveLineList);
        } else // Sinon on créée une O.D. pour passer du compte de la facture à un autre compte sur les
        // trop-perçus
        {
            this.createMoveUseDebit(invoice, debitMoveLines, invoiceCustomerMoveLine);
        }
        // Gestion du passage en 580
        reconcileService.balanceCredit(invoiceCustomerMoveLine);
        invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
    }
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ArrayList(java.util.ArrayList) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 63 with Move

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

the class MoveValidateService method validateMultiple.

public boolean validateMultiple(List<? extends Move> moveList) {
    boolean error = false;
    if (moveList == null) {
        return error;
    }
    try {
        for (Move move : moveList) {
            validate(moveRepository.find(move.getId()));
            JPA.clear();
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
        error = true;
        JPA.clear();
    }
    return error;
}
Also used : Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException)

Example 64 with Move

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

the class InvoicePaymentCancelServiceImpl method cancel.

/**
 * Method to cancel an invoice Payment
 *
 * <p>Cancel the eventual Move and Reconcile Compute the total amount paid on the linked invoice
 * Change the status to cancel
 *
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void cancel(InvoicePayment invoicePayment) throws AxelorException {
    Move paymentMove = invoicePayment.getMove();
    Reconcile reconcile = invoicePayment.getReconcile();
    log.debug("cancel : reconcile : {}", reconcile);
    if (reconcile != null && reconcile.getStatusSelect() == ReconcileRepository.STATUS_CONFIRMED) {
        reconcileService.unreconcile(reconcile);
    }
    if (paymentMove != null && invoicePayment.getTypeSelect() == InvoicePaymentRepository.TYPE_PAYMENT) {
        invoicePayment.setMove(null);
        moveCancelService.cancel(paymentMove);
    } else {
        this.updateCancelStatus(invoicePayment);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 65 with Move

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

Move (com.axelor.apps.account.db.Move)101 MoveLine (com.axelor.apps.account.db.MoveLine)51 Transactional (com.google.inject.persist.Transactional)37 Company (com.axelor.apps.base.db.Company)36 AxelorException (com.axelor.exception.AxelorException)34 BigDecimal (java.math.BigDecimal)33 Partner (com.axelor.apps.base.db.Partner)31 LocalDate (java.time.LocalDate)28 Journal (com.axelor.apps.account.db.Journal)25 Account (com.axelor.apps.account.db.Account)22 ArrayList (java.util.ArrayList)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)18 Reconcile (com.axelor.apps.account.db.Reconcile)14 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)11 Invoice (com.axelor.apps.account.db.Invoice)11 List (java.util.List)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)5 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)5 MoveService (com.axelor.apps.account.service.move.MoveService)5