use of com.axelor.apps.account.db.JournalType 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);
}
Aggregations