use of com.axelor.apps.account.db.JournalType 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);
}
use of com.axelor.apps.account.db.JournalType 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);
}
use of com.axelor.apps.account.db.JournalType in project axelor-open-suite by axelor.
the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1009FILE1.
/**
* Méthode réalisant l'export SI - des en-têtes pour les journaux de type achat
*
* @param mlr
* @param replay
* @throws AxelorException
* @throws IOException
*/
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void exportMoveLineTypeSelect1009FILE1(AccountingReport accountingReport, boolean replay) throws AxelorException, IOException {
log.info("In export service 1009 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<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();
int moveListSize = moveList.size();
if (moveListSize > 0) {
int i = 0;
for (Move move : moveList) {
List<MoveLine> moveLineList = moveLineRepo.all().filter("self.account.useForPartnerBalance = true AND self.credit != 0.00 AND self.move in ?1" + moveLineQueryStr, moveList).fetch();
if (!moveLineList.isEmpty()) {
String exportNumber = this.getPurchaseExportNumber(company);
String periodCode = move.getPeriod().getFromDate().format(DateTimeFormatter.ofPattern("yyyyMM"));
BigDecimal totalCredit = this.getSumCredit(moveLineList);
String invoiceId = "";
String dueDate = "";
if (move.getInvoice() != null) {
invoiceId = move.getInvoice().getInvoiceId();
dueDate = move.getInvoice().getDueDate().toString();
}
MoveLine firstMoveLine = moveLineList.get(0);
String[] items = new String[11];
items[0] = companyCode;
items[1] = journalCode;
items[2] = exportNumber;
items[3] = interfaceDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
items[4] = invoiceId;
items[5] = dueDate;
items[6] = firstMoveLine.getAccount().getCode();
items[7] = totalCredit.toString();
items[8] = reference;
items[9] = dt.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
items[10] = periodCode;
allMoveData.add(items);
this.updateMove(move, accountingReport, interfaceDate, exportNumber);
if (i % 10 == 0) {
JPA.clear();
}
if (i++ % 100 == 0) {
log.debug("Process : {} / {}", i, moveListSize);
}
}
}
}
}
}
String fileName = "entete" + appAccountService.getTodayDateTime().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDDHHMMSS)) + "achats.dat";
writeMoveLineToCsvFile(company, fileName, this.createHeaderForHeaderFile(accountingReport.getReportType().getTypeSelect()), allMoveData, accountingReport);
}
use of com.axelor.apps.account.db.JournalType in project axelor-open-suite by axelor.
the class AccountingReportServiceImpl method buildQuery.
public String buildQuery(AccountingReport accountingReport) throws AxelorException {
this.initQuery();
if (accountingReport.getCompany() != null) {
this.addParams("self.move.company = ?%d", accountingReport.getCompany());
}
if (accountingReport.getCurrency() != null) {
this.addParams("self.move.companyCurrency = ?%d", accountingReport.getCurrency());
}
if (accountingReport.getDateFrom() != null) {
this.addParams("self.date >= ?%d", accountingReport.getDateFrom());
}
if (accountingReport.getDateTo() != null) {
this.addParams("self.date <= ?%d", accountingReport.getDateTo());
}
if (accountingReport.getDate() != null) {
this.addParams("self.date <= ?%d", accountingReport.getDate());
}
if (accountingReport.getJournal() != null) {
this.addParams("self.move.journal = ?%d", accountingReport.getJournal());
}
if (accountingReport.getPeriod() != null) {
this.addParams("self.move.period = ?%d", accountingReport.getPeriod());
}
if (accountingReport.getAccountSet() != null && !accountingReport.getAccountSet().isEmpty()) {
this.addParams("(self.account in (?%d) or self.account.parentAccount in (?%d) " + "or self.account.parentAccount.parentAccount in (?%d) or self.account.parentAccount.parentAccount.parentAccount in (?%d) " + "or self.account.parentAccount.parentAccount.parentAccount.parentAccount in (?%d) or self.account.parentAccount.parentAccount.parentAccount.parentAccount.parentAccount in (?%d) " + "or self.account.parentAccount.parentAccount.parentAccount.parentAccount.parentAccount.parentAccount in (?%d))", accountingReport.getAccountSet());
}
if (accountingReport.getPartnerSet() != null && !accountingReport.getPartnerSet().isEmpty()) {
this.addParams("self.partner in (?%d)", accountingReport.getPartnerSet());
}
if (accountingReport.getYear() != null) {
this.addParams("self.move.period.year = ?%d", accountingReport.getYear());
}
if (accountingReport.getPaymentMode() != null) {
this.addParams("self.move.paymentMode = ?%d", accountingReport.getPaymentMode());
}
if (accountingReport.getReportType() != null) {
if (accountingReport.getReportType().getTypeSelect() == AccountingReportRepository.REPORT_CHEQUE_DEPOSIT) {
this.addParams("self.amountPaid > 0 AND self.credit > 0");
}
if (accountingReport.getReportType().getTypeSelect() == AccountingReportRepository.REPORT_AGED_BALANCE) {
this.addParams("(self.account is null OR self.account.reconcileOk = 'true')");
this.addParams("self.amountRemaining > 0 AND self.debit > 0");
}
if (accountingReport.getReportType().getTypeSelect() == AccountingReportRepository.REPORT_PARNER_GENERAL_LEDGER) {
this.addParams("self.account.useForPartnerBalance = 'true'");
}
if (accountingReport.getReportType().getTypeSelect() == AccountingReportRepository.REPORT_BALANCE) {
this.addParams("(self.account is null OR self.account.reconcileOk = 'true')");
}
if (accountingReport.getReportType().getTypeSelect() == AccountingReportRepository.REPORT_CASH_PAYMENTS) {
this.addParams("self.move.paymentMode.typeSelect = ?%d", PaymentModeRepository.TYPE_CASH);
this.addParams("self.credit > 0");
this.addParams("(self.account is null OR self.account.reconcileOk = 'true')");
}
}
if (this.compareReportType(accountingReport, AccountingReportRepository.REPORT_PAYMENT_DIFFERENCES)) {
this.addParams("self.account = ?%d", Beans.get((AccountConfigService.class)).getAccountConfig(accountingReport.getCompany()).getCashPositionVariationAccount());
}
if (this.compareReportType(accountingReport, AccountingReportRepository.REPORT_VAT_STATEMENT_INVOICE)) {
this.addParams("self.taxLine is not null");
this.addParams("self.taxLine.tax.typeSelect = ?%d", TaxRepository.TAX_TYPE_DEBIT);
}
this.addParams("self.move.ignoreInAccountingOk = 'false'");
this.addParams("(self.move.statusSelect = " + MoveRepository.STATUS_ACCOUNTED + " OR self.move.statusSelect = " + MoveRepository.STATUS_VALIDATED + ")");
// FOR EXPORT ONLY :
if (accountingReport.getReportType() != null) {
if (accountingReport.getReportType().getTypeSelect() > AccountingReportRepository.EXPORT_PAYROLL_JOURNAL_ENTRY) {
this.addParams("(self.move.accountingOk = false OR (self.move.accountingOk = true and self.move.accountingReport = ?%d))", accountingReport);
}
if (accountingReport.getReportType().getTypeSelect() >= AccountingReportRepository.EXPORT_PAYROLL_JOURNAL_ENTRY) {
this.addParams("self.move.journal.notExportOk = false ");
}
if (accountingReport.getReportType().getTypeSelect() > AccountingReportRepository.EXPORT_PAYROLL_JOURNAL_ENTRY) {
JournalType journalType = this.getJournalType(accountingReport);
if (journalType != null) {
this.addParams("self.move.journal.journalType = ?%d", journalType);
}
}
if (accountingReport.getReportType().getTypeSelect() >= AccountingReportRepository.REPORT_PARNER_GENERAL_LEDGER && accountingReport.getDisplayOnlyNotCompletelyLetteredMoveLines()) {
this.addParams("self.amountRemaining > 0");
}
}
log.debug("Query : {}", this.query);
return this.query;
}
use of com.axelor.apps.account.db.JournalType in project axelor-open-suite by axelor.
the class AccountingReportController method getJournalType.
/**
* @param request
* @param response
*/
public void getJournalType(ActionRequest request, ActionResponse response) {
AccountingReport accountingReport = request.getContext().asType(AccountingReport.class);
try {
JournalType journalType = Beans.get(AccountingReportService.class).getJournalType(accountingReport);
if (journalType != null) {
String domainQuery = "self.journalType.id = " + journalType.getId();
response.setAttr("journal", "domain", domainQuery);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations