Search in sources :

Example 1 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class AccountClearanceService method validateAccountClearance.

@Transactional(rollbackOn = { Exception.class })
public void validateAccountClearance(AccountClearance accountClearance) throws AxelorException {
    Company company = accountClearance.getCompany();
    AccountConfig accountConfig = company.getAccountConfig();
    Tax tax = accountConfig.getStandardRateTax();
    BigDecimal taxRate = taxService.getTaxRate(tax, appBaseService.getTodayDateTime().toLocalDate());
    Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
    Account profitAccount = accountConfig.getProfitAccount();
    Journal journal = accountConfig.getAccountClearanceJournal();
    Set<MoveLine> moveLineList = accountClearance.getMoveLineSet();
    for (MoveLine moveLine : moveLineList) {
        Move move = this.createAccountClearanceMove(moveLine, taxRate, taxAccount, profitAccount, company, journal, accountClearance);
        moveService.getMoveValidateService().validate(move);
    }
    accountClearance.setStatusSelect(AccountClearanceRepository.STATUS_VALIDATED);
    accountClearance.setDateTime(appBaseService.getTodayDateTime());
    accountClearance.setName(sequenceService.getSequenceNumber(SequenceRepository.ACCOUNT_CLEARANCE, company));
    accountClearanceRepo.save(accountClearance);
}
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) Tax(com.axelor.apps.account.db.Tax) Journal(com.axelor.apps.account.db.Journal) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 2 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class AccountCustomerService method updateAccountingSituationCustomerAccount.

@Transactional(rollbackOn = { Exception.class })
public AccountingSituation updateAccountingSituationCustomerAccount(AccountingSituation accountingSituation, boolean updateCustAccount, boolean updateDueCustAccount, boolean updateDueDebtRecoveryCustAccount) throws AxelorException {
    Partner partner = accountingSituation.getPartner();
    Company company = accountingSituation.getCompany();
    log.debug("Update customer account (Partner : {}, Company : {}, Update balance : {}, balance due : {}, balance due debt recovery : {})", partner.getName(), company.getName(), updateCustAccount, updateDueCustAccount, updateDueDebtRecoveryCustAccount);
    if (updateCustAccount) {
        accountingSituation.setBalanceCustAccount(this.getBalance(partner, company));
    }
    if (updateDueCustAccount) {
        accountingSituation.setBalanceDueCustAccount(this.getBalanceDue(partner, company, null));
    }
    if (updateDueDebtRecoveryCustAccount) {
        accountingSituation.setBalanceDueDebtRecoveryCustAccount(this.getBalanceDueDebtRecovery(partner, company, null));
    }
    accountingSituation.setCustAccountMustBeUpdateOk(false);
    accSituationRepo.save(accountingSituation);
    return accountingSituation;
}
Also used : Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 3 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1006FILE1.

/**
 * Méthode réalisant l'export SI - des en-têtes pour les journaux de type vente
 *
 * @param mlr
 * @param replay
 * @throws AxelorException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void exportMoveLineTypeSelect1006FILE1(AccountingReport accountingReport, boolean replay) throws AxelorException, IOException {
    log.info("In export service Type 1006 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 = company.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<? extends 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()) {
                BigDecimal sumDebit = this.getSumDebit("self.account.useForPartnerBalance = true AND self.debit != 0.00 AND self.move in ?1 " + moveLineQueryStr, moveList);
                if (sumDebit.compareTo(BigDecimal.ZERO) > 0) {
                    String exportNumber = this.getSaleExportNumber(company);
                    Move firstMove = moveList.get(0);
                    String periodCode = firstMove.getPeriod().getFromDate().format(DateTimeFormatter.ofPattern("yyyyMM"));
                    this.updateMoveList((List<Move>) 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] = sumDebit.toString();
                    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)) + "ventes.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) BigDecimal(java.math.BigDecimal) Move(com.axelor.apps.account.db.Move) JournalType(com.axelor.apps.account.db.JournalType) Transactional(com.google.inject.persist.Transactional)

Example 4 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1007FILE1.

/**
 * Méthode réalisant l'export SI - des en-têtes pour les journaux de type avoir
 *
 * @param mlr
 * @param replay
 * @throws AxelorException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void exportMoveLineTypeSelect1007FILE1(AccountingReport accountingReport, boolean replay) throws AxelorException, IOException {
    log.info("In export service 1007 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 (accountingReport.getCompany() != null) {
        companyCode = accountingReport.getCompany().getCode();
        moveQueryStr += String.format(" AND self.company = %s", accountingReport.getCompany().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()) {
                BigDecimal sumCredit = this.getSumCredit("self.account.useForPartnerBalance = true AND self.credit != 0.00 AND self.move in ?1 " + moveLineQueryStr, moveList);
                if (sumCredit.compareTo(BigDecimal.ZERO) > 0) {
                    String exportNumber = this.getRefundExportNumber(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] = sumCredit.toString();
                    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)) + "avoirs.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) BigDecimal(java.math.BigDecimal) Move(com.axelor.apps.account.db.Move) JournalType(com.axelor.apps.account.db.JournalType) Transactional(com.google.inject.persist.Transactional)

Example 5 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1000.

/**
 * Méthode réalisant l'export des FEC (Fichiers des écritures Comptables)
 *
 * @throws AxelorException
 * @throws IOException
 */
@Transactional(rollbackOn = { Exception.class })
public MetaFile exportMoveLineTypeSelect1000(AccountingReport accountingReport, boolean administration, boolean replay) throws AxelorException, IOException {
    log.info("In Export type 1000 service : ");
    List<String[]> allMoveLineData = new ArrayList<>();
    Company company = accountingReport.getCompany();
    LocalDate interfaceDate = accountingReport.getDate();
    String moveLineQueryStr = String.format("(self.move.statusSelect = %s", MoveRepository.STATUS_VALIDATED);
    if (!administration) {
        moveLineQueryStr += String.format(" OR self.move.statusSelect = %s", MoveRepository.STATUS_ACCOUNTED);
    }
    moveLineQueryStr += ")";
    moveLineQueryStr += String.format(" AND self.move.company = %s", company.getId());
    if (accountingReport.getYear() != null) {
        moveLineQueryStr += String.format(" AND self.move.period.year = %s", accountingReport.getYear().getId());
    }
    if (accountingReport.getPeriod() != null) {
        moveLineQueryStr += String.format(" AND self.move.period = %s", accountingReport.getPeriod().getId());
    } else {
        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());
    }
    moveLineQueryStr += " AND self.move.ignoreInAccountingOk = false";
    if (!administration) {
        moveLineQueryStr += " AND self.move.journal.notExportOk = false";
        if (replay) {
            moveLineQueryStr += String.format(" AND self.move.accountingOk = true AND self.move.accountingReport.id = %s", accountingReport.getId());
        } else {
            moveLineQueryStr += " AND self.move.accountingOk = false";
        }
    }
    List<MoveLine> moveLineList = moveLineRepo.all().filter(moveLineQueryStr).order("move.validationDate").order("date").order("name").fetch();
    if (!moveLineList.isEmpty()) {
        List<Move> moveList = new ArrayList<>();
        for (MoveLine moveLine : moveLineList) {
            String[] items = new String[18];
            Move move = moveLine.getMove();
            if (!moveList.contains(move)) {
                moveList.add(move);
            }
            Journal journal = move.getJournal();
            items[0] = journal.getCode();
            items[1] = journal.getName();
            items[2] = moveLine.getMove().getReference();
            items[3] = moveLine.getDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            items[4] = moveLine.getAccount().getCode();
            items[5] = moveLine.getAccount().getName();
            items[6] = "";
            items[7] = "";
            Partner partner = moveLine.getPartner();
            if (partner != null) {
                items[6] = partner.getPartnerSeq();
                items[7] = partner.getName();
            }
            items[8] = moveLine.getOrigin();
            if (moveLine.getOriginDate() != null) {
                items[9] = moveLine.getOriginDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            }
            items[10] = moveLine.getDescription();
            items[11] = moveLine.getDebit().toString().replace('.', ',');
            items[12] = moveLine.getCredit().toString().replace('.', ',');
            ReconcileGroup reconcileGroup = moveLine.getReconcileGroup();
            if (reconcileGroup != null && reconcileGroup.getStatusSelect() == ReconcileGroupRepository.STATUS_FINAL) {
                items[13] = reconcileGroup.getCode();
                items[14] = reconcileGroup.getDateOfLettering().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD)).toString();
            } else {
                items[13] = "";
                items[14] = "";
            }
            if (move.getValidationDate() != null) {
                items[15] = move.getValidationDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            }
            items[16] = moveLine.getCurrencyAmount().toString().replace('.', ',');
            if (moveLine.getCurrencyAmount().compareTo(BigDecimal.ZERO) > 0 && moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
                items[16] = "-" + items[16];
            }
            if (move.getCurrency() != null) {
                items[17] = move.getCurrency().getCode();
            }
            allMoveLineData.add(items);
        }
        if (!administration) {
            String exportNumber = this.getSaleExportNumber(company);
            this.updateMoveList(moveList, accountingReport, interfaceDate, exportNumber);
        }
    }
    accountingReport = accountingReportRepo.find(accountingReport.getId());
    String fileName = this.setFileName(accountingReport);
    accountingReportRepo.save(accountingReport);
    return writeMoveLineToCsvFile(company, fileName, this.createHeaderForJournalEntry(), allMoveLineData, accountingReport);
}
Also used : Company(com.axelor.apps.base.db.Company) ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15