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