Search in sources :

Example 6 with Journal

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

the class MoveLineExportServiceImpl method exportMoveLineAllTypeSelectFILE2.

/**
 * Méthode réalisant l'export SI - des fichiers détails
 *
 * @param mlr
 * @param fileName
 * @throws AxelorException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public void exportMoveLineAllTypeSelectFILE2(AccountingReport accountingReport, String fileName) throws AxelorException, IOException {
    log.info("In export service FILE 2 :");
    Company company = accountingReport.getCompany();
    String companyCode = "";
    String moveLineQueryStr = "";
    int typeSelect = accountingReport.getReportType().getTypeSelect();
    if (company != null) {
        companyCode = company.getCode();
        moveLineQueryStr += String.format(" AND self.move.company = %s", company.getId());
    }
    if (accountingReport.getJournal() != null) {
        moveLineQueryStr += String.format(" AND self.move.journal = %s", accountingReport.getJournal().getId());
    } else {
        moveLineQueryStr += String.format(" AND self.move.journal.journalType = %s", accountingReportService.getJournalType(accountingReport).getId());
    }
    if (accountingReport.getPeriod() != null) {
        moveLineQueryStr += String.format(" AND self.move.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 (typeSelect != 8) {
        moveLineQueryStr += " AND self.account.useForPartnerBalance = false ";
    }
    moveLineQueryStr += String.format("AND self.move.accountingOk = true AND self.move.ignoreInAccountingOk = false AND self.move.accountingReport = %s", accountingReport.getId());
    moveLineQueryStr += String.format(" AND (self.move.statusSelect = %s OR self.move.statusSelect = %s) ", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED);
    Query queryDate = JPA.em().createQuery("SELECT self.date from MoveLine self where self.account != null AND (self.debit > 0 OR self.credit > 0) " + moveLineQueryStr + " group by self.date ORDER BY self.date");
    List<LocalDate> dates = queryDate.getResultList();
    log.debug("dates : {}", dates);
    List<String[]> allMoveLineData = new ArrayList<>();
    for (LocalDate localDate : dates) {
        Query queryExportRef = JPA.em().createQuery("SELECT DISTINCT self.move.exportNumber from MoveLine self where self.account != null " + "AND (self.debit > 0 OR self.credit > 0) AND self.date = '" + localDate.toString() + "'" + moveLineQueryStr);
        List<String> exportRefs = queryExportRef.getResultList();
        for (String exportRef : exportRefs) {
            if (exportRef != null && !exportRef.isEmpty()) {
                int sequence = 1;
                Query query = JPA.em().createQuery("SELECT self.account.id from MoveLine self where self.account != null AND (self.debit > 0 OR self.credit > 0) " + "AND self.date = '" + localDate.toString() + "' AND self.move.exportNumber = '" + exportRef + "'" + moveLineQueryStr + " group by self.account.id");
                List<Long> accountIds = query.getResultList();
                log.debug("accountIds : {}", accountIds);
                for (Long accountId : accountIds) {
                    if (accountId != null) {
                        String accountCode = accountRepo.find(accountId).getCode();
                        List<MoveLine> moveLines = moveLineRepo.all().filter("self.account.id = ?1 AND (self.debit > 0 OR self.credit > 0) AND self.date = '" + localDate.toString() + "' AND self.move.exportNumber = '" + exportRef + "'" + moveLineQueryStr, accountId).fetch();
                        log.debug("movelines  : {} ", moveLines);
                        if (!moveLines.isEmpty()) {
                            List<MoveLine> moveLineList = moveLineService.consolidateMoveLines(moveLines);
                            List<MoveLine> sortMoveLineList = this.sortMoveLineByDebitCredit(moveLineList);
                            for (MoveLine moveLine3 : sortMoveLineList) {
                                Journal journal = moveLine3.getMove().getJournal();
                                LocalDate date = moveLine3.getDate();
                                String[] items = null;
                                if (typeSelect == 9) {
                                    items = new String[13];
                                } else {
                                    items = new String[12];
                                }
                                items[0] = companyCode;
                                items[1] = journal.getExportCode();
                                items[2] = moveLine3.getMove().getExportNumber();
                                items[3] = String.format("%s", sequence);
                                sequence++;
                                items[4] = accountCode;
                                BigDecimal totAmt = moveLine3.getCredit().subtract(moveLine3.getDebit());
                                String moveLineSign = "C";
                                if (totAmt.compareTo(BigDecimal.ZERO) < 0) {
                                    moveLineSign = "D";
                                    totAmt = totAmt.negate();
                                }
                                items[5] = moveLineSign;
                                items[6] = totAmt.toString();
                                String analyticAccounts = "";
                                for (AnalyticMoveLine analyticDistributionLine : moveLine3.getAnalyticMoveLineList()) {
                                    analyticAccounts = analyticAccounts + analyticDistributionLine.getAnalyticAccount().getCode() + "/";
                                }
                                if (typeSelect == 9) {
                                    items[7] = "";
                                    items[8] = analyticAccounts;
                                    items[9] = String.format("%s DU %s", journal.getCode(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
                                } else {
                                    items[7] = analyticAccounts;
                                    items[8] = String.format("%s DU %s", journal.getCode(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
                                }
                                allMoveLineData.add(items);
                            }
                        }
                    }
                }
            }
        }
    }
    writeMoveLineToCsvFile(company, fileName, this.createHeaderForDetailFile(typeSelect), allMoveLineData, 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) BigDecimal(java.math.BigDecimal) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 7 with Journal

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

the class PaymentScheduleLineServiceImpl method createPaymentMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
    Preconditions.checkNotNull(paymentScheduleLine);
    Preconditions.checkNotNull(companyBankDetails);
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    Company company = paymentSchedule.getCompany();
    Partner partner = paymentSchedule.getPartner();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    BigDecimal amount = paymentScheduleLine.getInTaxAmount();
    String name = paymentScheduleLine.getName();
    LocalDate todayDate = appBaseService.getTodayDate(company);
    Account account = accountingSituationService.getCustomerAccount(partner, company);
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
    move.addMoveLineListItem(creditMoveLine);
    creditMoveLine = moveLineRepo.save(creditMoveLine);
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
    move.addMoveLineListItem(debitMoveLine);
    debitMoveLine = moveLineRepo.save(debitMoveLine);
    moveService.getMoveValidateService().validate(move);
    // Reconcile
    if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
        List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
        if (moveToolService.isSameAccount(debitMoveLineList, account)) {
            List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
            paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
        }
    }
    paymentScheduleLine.setDirectDebitAmount(amount);
    paymentScheduleLine.setInTaxAmountPaid(amount);
    paymentScheduleLine.setAdvanceOrPaymentMove(move);
    paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
    paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
    paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) PaymentService(com.axelor.apps.account.service.payment.PaymentService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) PaymentScheduleRepository(com.axelor.apps.account.db.repo.PaymentScheduleRepository) RoundingMode(java.math.RoundingMode) Journal(com.axelor.apps.account.db.Journal) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) PaymentScheduleLineRepository(com.axelor.apps.account.db.repo.PaymentScheduleLineRepository) LocalDate(java.time.LocalDate) PaymentMode(com.axelor.apps.account.db.PaymentMode) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) BankDetails(com.axelor.apps.base.db.BankDetails) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 8 with Journal

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

the class ChequeRejectionService method createChequeRejectionMove.

/**
 * Méthode permettant de créer une écriture de rejet de chèque (L'extourne de l'écriture de
 * paiement)
 *
 * @param chequeRejection Un rejet de cheque brouillon
 * @param company Une société
 * @return L'écriture de rejet de chèque
 * @throws AxelorException
 */
public Move createChequeRejectionMove(ChequeRejection chequeRejection, Company company) throws AxelorException {
    this.testCompanyField(company);
    Journal journal = company.getAccountConfig().getRejectJournal();
    PaymentVoucher paymentVoucher = chequeRejection.getPaymentVoucher();
    Move paymentMove = paymentVoucher.getGeneratedMove();
    Partner partner = paymentVoucher.getPartner();
    InterbankCodeLine interbankCodeLine = chequeRejection.getInterbankCodeLine();
    String description = chequeRejection.getDescription();
    LocalDate rejectionDate = chequeRejection.getRejectionDate();
    // Move
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, rejectionDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    int ref = 1;
    for (MoveLine moveLine : paymentMove.getMoveLineList()) {
        if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
            // Debit MoveLine
            MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getCredit(), true, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(debitMoveLine);
            debitMoveLine.setInterbankCodeLine(interbankCodeLine);
            debitMoveLine.setDescription(description);
        } else {
            // Credit MoveLine
            MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getDebit(), false, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(creditMoveLine);
            creditMoveLine.setInterbankCodeLine(interbankCodeLine);
            creditMoveLine.setDescription(description);
        }
        ref++;
    }
    move.setRejectOk(true);
    moveService.getMoveValidateService().validate(move);
    return move;
}
Also used : Move(com.axelor.apps.account.db.Move) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher)

Example 9 with Journal

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

the class FixedAssetLineMoveServiceImpl method generateDisposalMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateDisposalMove(FixedAssetLine fixedAssetLine) throws AxelorException {
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    Journal journal = fixedAsset.getJournal();
    Company company = fixedAsset.getCompany();
    Partner partner = fixedAsset.getPartner();
    LocalDate date = fixedAssetLine.getDepreciationDate();
    // Creating move
    Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
    if (move != null) {
        List<MoveLine> moveLines = new ArrayList<MoveLine>();
        String origin = fixedAsset.getReference();
        Account chargeAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
        Account depreciationAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
        Account purchaseAccount = fixedAsset.getPurchaseAccount();
        BigDecimal chargeAmount = fixedAssetLine.getResidualValue();
        BigDecimal cumulativeDepreciationAmount = fixedAssetLine.getCumulativeDepreciation();
        // Creating accounting debit move line for charge account
        MoveLine chargeAccountDebitMoveLine = new MoveLine(move, partner, chargeAccount, date, null, 1, chargeAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(chargeAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), chargeAccountDebitMoveLine);
        // Creating accounting debit move line for deprecation account
        MoveLine deprecationAccountDebitMoveLine = new MoveLine(move, partner, depreciationAccount, date, null, 1, cumulativeDepreciationAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(deprecationAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), deprecationAccountDebitMoveLine);
        // Creating accounting credit move line
        MoveLine creditMoveLine = new MoveLine(move, partner, purchaseAccount, date, null, 2, BigDecimal.ZERO, fixedAsset.getGrossValue(), fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(creditMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
        move.getMoveLineList().addAll(moveLines);
    }
    moveRepo.save(move);
    fixedAsset.setDisposalMove(move);
}
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) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) FixedAsset(com.axelor.apps.account.db.FixedAsset) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 10 with Journal

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

the class ImportJournal method importAccountType.

public Object importAccountType(Object bean, Map<String, Object> values) {
    assert bean instanceof Journal;
    Journal journal = (Journal) bean;
    // Only 'Manual misc ops' Journal
    String importId = journal.getImportId();
    if (!"24".equals(importId)) {
        return bean;
    }
    Set<AccountType> accountTypesSet = new HashSet<AccountType>(Beans.get(AccountTypeRepository.class).all().fetch());
    journal.setValidAccountTypeSet(accountTypesSet);
    return journal;
}
Also used : Journal(com.axelor.apps.account.db.Journal) AccountType(com.axelor.apps.account.db.AccountType) AccountTypeRepository(com.axelor.apps.account.db.repo.AccountTypeRepository) HashSet(java.util.HashSet)

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