use of com.axelor.apps.account.db.ReconcileGroup 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.ReconcileGroup in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method findOrMergeGroup.
@Override
public Optional<ReconcileGroup> findOrMergeGroup(Reconcile reconcile) {
List<ReconcileGroup> otherReconcileGroupList;
MoveLine debitMoveLine = reconcile.getDebitMoveLine();
MoveLine creditMoveLine = reconcile.getCreditMoveLine();
otherReconcileGroupList = new ArrayList<>();
if (debitMoveLine.getReconcileGroup() != null) {
otherReconcileGroupList.add(debitMoveLine.getReconcileGroup());
}
if (creditMoveLine.getReconcileGroup() != null) {
otherReconcileGroupList.add(creditMoveLine.getReconcileGroup());
}
otherReconcileGroupList = otherReconcileGroupList.stream().distinct().collect(Collectors.toList());
if (otherReconcileGroupList.isEmpty()) {
return Optional.empty();
} else if (otherReconcileGroupList.size() == 1) {
return Optional.of(otherReconcileGroupList.get(0));
} else {
return Optional.of(mergeReconcileGroups(otherReconcileGroupList));
}
}
use of com.axelor.apps.account.db.ReconcileGroup in project axelor-open-suite by axelor.
the class ReconcileGroupController method unletter.
public void unletter(ActionRequest request, ActionResponse response) {
ReconcileGroup reconcileGroup = Beans.get(ReconcileGroupRepository.class).find(request.getContext().asType(ReconcileGroup.class).getId());
if (reconcileGroup != null) {
try {
Beans.get(ReconcileGroupService.class).unletter(reconcileGroup);
} catch (AxelorException e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
}
response.setReload(true);
}
use of com.axelor.apps.account.db.ReconcileGroup in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method remove.
@Override
public void remove(Reconcile reconcile) throws AxelorException {
ReconcileGroup reconcileGroup = reconcile.getReconcileGroup();
// update move lines
List<MoveLine> moveLineToRemoveList = moveLineRepository.findByReconcileGroup(reconcileGroup).fetch();
moveLineToRemoveList.forEach(moveLine -> moveLine.setReconcileGroup(null));
List<Reconcile> reconcileList = this.getReconcileList(reconcileGroup);
reconcileList.stream().map(Reconcile::getDebitMoveLine).forEach(moveLine -> moveLine.setReconcileGroup(reconcileGroup));
reconcileList.stream().map(Reconcile::getCreditMoveLine).forEach(moveLine -> moveLine.setReconcileGroup(reconcileGroup));
// update status
updateStatus(reconcileGroup);
}
use of com.axelor.apps.account.db.ReconcileGroup in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method createReconcileGroup.
@Override
@Transactional
public ReconcileGroup createReconcileGroup(Company company) {
ReconcileGroup reconcileGroup = new ReconcileGroup();
reconcileGroup.setCompany(company);
return reconcileGroupRepository.save(reconcileGroup);
}
Aggregations