Search in sources :

Example 26 with Journal

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

the class ExpenseServiceImpl method createMoveForExpensePayment.

public Move createMoveForExpensePayment(Expense expense) throws AxelorException {
    Company company = expense.getCompany();
    PaymentMode paymentMode = expense.getPaymentMode();
    Partner partner = expense.getUser().getPartner();
    LocalDate paymentDate = expense.getPaymentDate();
    BigDecimal paymentAmount = expense.getInTaxTotal();
    BankDetails companyBankDetails = company.getDefaultBankDetails();
    Account employeeAccount;
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    MoveLine expenseMoveLine = this.getExpenseEmployeeMoveLineByLoop(expense);
    if (expenseMoveLine == null) {
        return null;
    }
    employeeAccount = expenseMoveLine.getAccount();
    Move move = moveService.getMoveCreateService().createMove(journal, company, expense.getMove().getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, false, paymentDate, null, 1, expense.getExpenseSeq(), null));
    MoveLine employeeMoveLine = moveLineService.createMoveLine(move, partner, employeeAccount, paymentAmount, true, paymentDate, null, 2, expense.getExpenseSeq(), null);
    employeeMoveLine.setTaxAmount(expense.getTaxTotal());
    move.addMoveLineListItem(employeeMoveLine);
    moveService.getMoveValidateService().validate(move);
    expense.setPaymentMove(move);
    Beans.get(ReconcileService.class).reconcile(expenseMoveLine, employeeMoveLine, true, false);
    expenseRepository.save(expense);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) ReconcileService(com.axelor.apps.account.service.ReconcileService) 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) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 27 with Journal

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

the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.

@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
    SaleOrder saleOrder = advancePayment.getSaleOrder();
    Company company = saleOrder.getCompany();
    PaymentMode paymentMode = advancePayment.getPaymentMode();
    Partner clientPartner = saleOrder.getClientPartner();
    LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
    BankDetails bankDetails = saleOrder.getCompanyBankDetails();
    String ref = saleOrder.getSaleOrderSeq();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
    Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
    moveService.getMoveValidateService().validate(move);
    advancePayment.setMove(move);
    advancePaymentRepository.save(advancePayment);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 28 with Journal

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

the class JournalManagementRepository method copy.

@Override
public Journal copy(Journal entity, boolean deep) {
    Journal copy = super.copy(entity, deep);
    copy.setStatusSelect(JournalRepository.STATUS_INACTIVE);
    copy.setSequence(null);
    return copy;
}
Also used : Journal(com.axelor.apps.account.db.Journal)

Example 29 with Journal

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

the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.

@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
    MoveService moveService = Beans.get(MoveService.class);
    MoveRepository moveRepository = Beans.get(MoveRepository.class);
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    Company company = subrogationRelease.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
    Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
    if (subrogationRelease.getAccountingDate() == null) {
        subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
        boolean isRefund = false;
        if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
            isRefund = true;
        }
        LocalDate date = subrogationRelease.getAccountingDate();
        Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        MoveLine creditMoveLine, debitMoveLine;
        debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        move.addMoveLineListItem(debitMoveLine);
        move.addMoveLineListItem(creditMoveLine);
        move = moveRepository.save(move);
        moveService.getMoveValidateService().validate(move);
        invoice.setSubrogationRelease(subrogationRelease);
        invoice.setSubrogationReleaseMove(move);
        subrogationRelease.addMoveListItem(move);
    }
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) MoveService(com.axelor.apps.account.service.move.MoveService) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AccountConfig(com.axelor.apps.account.db.AccountConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Move(com.axelor.apps.account.db.Move) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 30 with Journal

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

the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1008FILE1.

/**
 * Méthode réalisant l'export SI - des en-têtes pour les journaux de type trésorerie
 *
 * @param mlr
 * @param replay
 * @throws AxelorException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void exportMoveLineTypeSelect1008FILE1(AccountingReport accountingReport, boolean replay) throws AxelorException, IOException {
    log.info("In export service 1008 FILE 1:");
    Company company = accountingReport.getCompany();
    String dateQueryStr = String.format(" WHERE self.company = %s", company.getId());
    JournalType journalType = accountingReportService.getJournalType(accountingReport);
    if (accountingReport.getJournal() != null) {
        dateQueryStr += String.format(" AND self.journal = %s", accountingReport.getJournal().getId());
    } else {
        dateQueryStr += String.format(" AND self.journal.journalType = %s", journalType.getId());
    }
    if (accountingReport.getPeriod() != null) {
        dateQueryStr += String.format(" AND self.period = %s", accountingReport.getPeriod().getId());
    }
    if (replay) {
        dateQueryStr += String.format(" AND self.accountingOk = true AND self.accountingReport = %s", accountingReport.getId());
    } else {
        dateQueryStr += " AND self.accountingOk = false ";
    }
    dateQueryStr += " AND self.ignoreInAccountingOk = false AND self.journal.notExportOk = false ";
    dateQueryStr += String.format(" AND (self.statusSelect = %s OR self.statusSelect = %s) ", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED);
    Query dateQuery = JPA.em().createQuery("SELECT self.date from Move self" + dateQueryStr + "group by self.date order by self.date");
    List<LocalDate> allDates = dateQuery.getResultList();
    log.debug("allDates : {}", allDates);
    List<String[]> allMoveData = new ArrayList<>();
    String companyCode = "";
    String reference = "";
    String moveQueryStr = "";
    String moveLineQueryStr = "";
    if (accountingReport.getRef() != null) {
        reference = accountingReport.getRef();
    }
    if (company != null) {
        companyCode = accountingReport.getCompany().getCode();
        moveQueryStr += String.format(" AND self.company = %s", company.getId());
    }
    if (accountingReport.getPeriod() != null) {
        moveQueryStr += String.format(" AND self.period = %s", accountingReport.getPeriod().getId());
    }
    if (accountingReport.getDateFrom() != null) {
        moveLineQueryStr += String.format(" AND self.date >= '%s'", accountingReport.getDateFrom().toString());
    }
    if (accountingReport.getDateTo() != null) {
        moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDateTo().toString());
    }
    if (accountingReport.getDate() != null) {
        moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDate().toString());
    }
    if (replay) {
        moveQueryStr += String.format(" AND self.accountingOk = true AND self.accountingReport = %s", accountingReport.getId());
    } else {
        moveQueryStr += " AND self.accountingOk = false ";
    }
    moveQueryStr += String.format(" AND self.statusSelect = %s ", MoveRepository.STATUS_VALIDATED);
    LocalDate interfaceDate = accountingReport.getDate();
    for (LocalDate dt : allDates) {
        List<Journal> journalList = journalRepo.all().filter("self.journalType = ?1 AND self.notExportOk = false", journalType).fetch();
        if (accountingReport.getJournal() != null) {
            journalList = new ArrayList<>();
            journalList.add(accountingReport.getJournal());
        }
        for (Journal journal : journalList) {
            List<Move> moveList = moveRepo.all().filter("self.date = ?1 AND self.ignoreInAccountingOk = false AND self.journal.notExportOk = false AND self.journal = ?2" + moveQueryStr, dt, journal).fetch();
            String journalCode = journal.getExportCode();
            if (!moveList.isEmpty()) {
                long moveLineListSize = moveLineRepo.all().filter("self.move in ?1 AND (self.debit > 0 OR self.credit > 0) " + moveLineQueryStr, moveList).count();
                if (moveLineListSize > 0) {
                    String exportNumber = this.getTreasuryExportNumber(company);
                    Move firstMove = moveList.get(0);
                    String periodCode = firstMove.getPeriod().getFromDate().format(DateTimeFormatter.ofPattern("yyyyMM"));
                    this.updateMoveList(moveList, accountingReport, interfaceDate, exportNumber);
                    String[] items = new String[8];
                    items[0] = companyCode;
                    items[1] = journalCode;
                    items[2] = exportNumber;
                    items[3] = interfaceDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
                    items[4] = "0";
                    items[5] = reference;
                    items[6] = dt.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
                    items[7] = periodCode;
                    allMoveData.add(items);
                }
            }
        }
    }
    String fileName = "entete" + appAccountService.getTodayDateTime().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDDHHMMSS)) + "tresorerie.dat";
    writeMoveLineToCsvFile(company, fileName, this.createHeaderForHeaderFile(accountingReport.getReportType().getTypeSelect()), allMoveData, accountingReport);
}
Also used : Company(com.axelor.apps.base.db.Company) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) Move(com.axelor.apps.account.db.Move) JournalType(com.axelor.apps.account.db.JournalType) 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