Search in sources :

Example 11 with Journal

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

the class ImportMove method importFECMove.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Object importFECMove(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof MoveLine;
    MoveLine moveLine = (MoveLine) bean;
    try {
        moveLine.setCounter(1);
        if (values.get("EcritureNum") == null) {
            return null;
        }
        String moveReference = values.get("EcritureNum").toString();
        MoveLine mvLine = moveLineRepo.all().filter("self.name LIKE '" + moveReference + "-%'").order("-counter").fetchOne();
        if (mvLine != null) {
            int counter = mvLine.getCounter() + 1;
            moveLine.setCounter(counter);
        }
        if (values.get("EcritureDate") != null) {
            LocalDate moveLineDate = LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE);
            moveLine.setDate(moveLineDate);
        }
        Move move = moveRepository.all().filter("self.reference = ?", moveReference).fetchOne();
        if (move == null) {
            move = new Move();
            move.setReference(moveReference);
            if (values.get("ValidDate") != null) {
                move.setStatusSelect(MoveRepository.STATUS_VALIDATED);
                move.setValidationDate(LocalDate.parse(values.get("ValidDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            } else {
                move.setStatusSelect(MoveRepository.STATUS_ACCOUNTED);
            }
            move.setCompany(getCompany(values));
            move.setCompanyCurrency(move.getCompany().getCurrency());
            move.setDate(LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            move.setPeriod(Beans.get(PeriodService.class).getPeriod(move.getDate(), move.getCompany(), YearRepository.TYPE_FISCAL));
            if (values.get("Idevise") != null) {
                move.setCurrency(Beans.get(CurrencyRepository.class).findByCode(values.get("Idevise").toString()));
                move.setCurrencyCode(values.get("Idevise").toString());
            }
            if (values.get("JournalCode") != null) {
                Journal journal = Beans.get(JournalRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("JournalCode").toString(), move.getCompany().getId()).fetchOne();
                move.setJournal(journal);
            }
            if (values.get("CompAuxNum") != null) {
                Partner partner = Beans.get(PartnerRepository.class).all().filter("self.partnerSeq = ?", values.get("CompAuxNum").toString()).fetchOne();
                move.setPartner(partner);
            }
            moveRepository.save(move);
        }
        if (values.get("CompteNum") != null) {
            Account account = Beans.get(AccountRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("CompteNum").toString(), move.getCompany().getId()).fetchOne();
            moveLine.setAccount(account);
        }
        moveLine.setMove(move);
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
    }
    return moveLine;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) JournalRepository(com.axelor.apps.account.db.repo.JournalRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 12 with Journal

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

the class JournalController method computeBalance.

public void computeBalance(ActionRequest request, ActionResponse response) {
    Journal journal = request.getContext().asType(Journal.class);
    Map<String, BigDecimal> resultMap = journalService.computeBalance(journal);
    response.setValue("$balance", resultMap.get("balance"));
    response.setValue("$totalDebit", resultMap.get("debit"));
    response.setValue("$totalCredit", resultMap.get("credit"));
}
Also used : Journal(com.axelor.apps.account.db.Journal) BigDecimal(java.math.BigDecimal)

Example 13 with Journal

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

the class PaymentVoucherController method askPaymentVoucher.

public void askPaymentVoucher(ActionRequest request, ActionResponse response) {
    PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
    if (paymentVoucher.getHasAutoInput()) {
        PaymentMode paymentMode = paymentVoucher.getPaymentMode();
        Company company = paymentVoucher.getCompany();
        BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
        try {
            Journal journal = Beans.get(PaymentModeService.class).getPaymentModeJournal(paymentMode, company, companyBankDetails);
            if (journal.getExcessPaymentOk()) {
                response.setAlert(I18n.get("No items have been selected. Do you want to continue?"));
            }
        } catch (Exception e) {
            TraceBackService.trace(response, e);
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 14 with Journal

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

the class MoveSequenceService method setSequence.

public void setSequence(Move move) throws AxelorException {
    Journal journal = move.getJournal();
    if (journal.getSequence() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_5), journal.getName());
    }
    move.setReference(sequenceService.getSequenceNumber(journal.getSequence(), move.getDate()));
}
Also used : AxelorException(com.axelor.exception.AxelorException) Journal(com.axelor.apps.account.db.Journal)

Example 15 with Journal

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

the class MoveServiceImpl method createMoveUseDebit.

@Override
public Move createMoveUseDebit(Invoice invoice, List<MoveLine> debitMoveLines, MoveLine invoiceCustomerMoveLine) throws AxelorException {
    Company company = invoice.getCompany();
    Partner partner = invoice.getPartner();
    Account account = invoice.getPartnerAccount();
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfigService.getAccountConfig(company));
    log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
    BigDecimal remainingAmount = invoice.getInTaxTotal().abs();
    log.debug("Montant à payer avec l'avoir récupéré : {}", remainingAmount);
    Move oDmove = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    if (oDmove != null) {
        BigDecimal totalDebitAmount = moveToolService.getTotalDebitAmount(debitMoveLines);
        BigDecimal amount = totalDebitAmount.min(invoiceCustomerMoveLine.getCredit());
        // Création de la ligne au débit
        MoveLine debitMoveLine = moveLineService.createMoveLine(oDmove, partner, account, amount, true, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
        oDmove.getMoveLineList().add(debitMoveLine);
        // Emploie des dûs sur les lignes de credit qui seront créées au fil de l'eau
        paymentService.createExcessPaymentWithAmount(debitMoveLines, amount, oDmove, 2, partner, company, null, account, appAccountService.getTodayDate(company));
        moveValidateService.validate(oDmove);
        // Création de la réconciliation
        Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, invoiceCustomerMoveLine, amount, false);
        if (reconcile != null) {
            reconcileService.confirmReconcile(reconcile, true);
        }
    }
    return oDmove;
}
Also used : Account(com.axelor.apps.account.db.Account) 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) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

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