use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class MoveLineExportServiceImpl method exportMoveLineAllTypeSelectFILE2.
/**
* Méthode réalisant l'export SI - des fichiers détails
*
* @param mlr
* @param fileName
* @throws AxelorException
* @throws IOException
*/
@SuppressWarnings("unchecked")
public void exportMoveLineAllTypeSelectFILE2(AccountingReport accountingReport, String fileName) throws AxelorException, IOException {
log.info("In export service FILE 2 :");
Company company = accountingReport.getCompany();
String companyCode = "";
String moveLineQueryStr = "";
int typeSelect = accountingReport.getReportType().getTypeSelect();
if (company != null) {
companyCode = company.getCode();
moveLineQueryStr += String.format(" AND self.move.company = %s", company.getId());
}
if (accountingReport.getJournal() != null) {
moveLineQueryStr += String.format(" AND self.move.journal = %s", accountingReport.getJournal().getId());
} else {
moveLineQueryStr += String.format(" AND self.move.journal.journalType = %s", accountingReportService.getJournalType(accountingReport).getId());
}
if (accountingReport.getPeriod() != null) {
moveLineQueryStr += String.format(" AND self.move.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 (typeSelect != 8) {
moveLineQueryStr += " AND self.account.useForPartnerBalance = false ";
}
moveLineQueryStr += String.format("AND self.move.accountingOk = true AND self.move.ignoreInAccountingOk = false AND self.move.accountingReport = %s", accountingReport.getId());
moveLineQueryStr += String.format(" AND (self.move.statusSelect = %s OR self.move.statusSelect = %s) ", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED);
Query queryDate = JPA.em().createQuery("SELECT self.date from MoveLine self where self.account != null AND (self.debit > 0 OR self.credit > 0) " + moveLineQueryStr + " group by self.date ORDER BY self.date");
List<LocalDate> dates = queryDate.getResultList();
log.debug("dates : {}", dates);
List<String[]> allMoveLineData = new ArrayList<>();
for (LocalDate localDate : dates) {
Query queryExportRef = JPA.em().createQuery("SELECT DISTINCT self.move.exportNumber from MoveLine self where self.account != null " + "AND (self.debit > 0 OR self.credit > 0) AND self.date = '" + localDate.toString() + "'" + moveLineQueryStr);
List<String> exportRefs = queryExportRef.getResultList();
for (String exportRef : exportRefs) {
if (exportRef != null && !exportRef.isEmpty()) {
int sequence = 1;
Query query = JPA.em().createQuery("SELECT self.account.id from MoveLine self where self.account != null AND (self.debit > 0 OR self.credit > 0) " + "AND self.date = '" + localDate.toString() + "' AND self.move.exportNumber = '" + exportRef + "'" + moveLineQueryStr + " group by self.account.id");
List<Long> accountIds = query.getResultList();
log.debug("accountIds : {}", accountIds);
for (Long accountId : accountIds) {
if (accountId != null) {
String accountCode = accountRepo.find(accountId).getCode();
List<MoveLine> moveLines = moveLineRepo.all().filter("self.account.id = ?1 AND (self.debit > 0 OR self.credit > 0) AND self.date = '" + localDate.toString() + "' AND self.move.exportNumber = '" + exportRef + "'" + moveLineQueryStr, accountId).fetch();
log.debug("movelines : {} ", moveLines);
if (!moveLines.isEmpty()) {
List<MoveLine> moveLineList = moveLineService.consolidateMoveLines(moveLines);
List<MoveLine> sortMoveLineList = this.sortMoveLineByDebitCredit(moveLineList);
for (MoveLine moveLine3 : sortMoveLineList) {
Journal journal = moveLine3.getMove().getJournal();
LocalDate date = moveLine3.getDate();
String[] items = null;
if (typeSelect == 9) {
items = new String[13];
} else {
items = new String[12];
}
items[0] = companyCode;
items[1] = journal.getExportCode();
items[2] = moveLine3.getMove().getExportNumber();
items[3] = String.format("%s", sequence);
sequence++;
items[4] = accountCode;
BigDecimal totAmt = moveLine3.getCredit().subtract(moveLine3.getDebit());
String moveLineSign = "C";
if (totAmt.compareTo(BigDecimal.ZERO) < 0) {
moveLineSign = "D";
totAmt = totAmt.negate();
}
items[5] = moveLineSign;
items[6] = totAmt.toString();
String analyticAccounts = "";
for (AnalyticMoveLine analyticDistributionLine : moveLine3.getAnalyticMoveLineList()) {
analyticAccounts = analyticAccounts + analyticDistributionLine.getAnalyticAccount().getCode() + "/";
}
if (typeSelect == 9) {
items[7] = "";
items[8] = analyticAccounts;
items[9] = String.format("%s DU %s", journal.getCode(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
} else {
items[7] = analyticAccounts;
items[8] = String.format("%s DU %s", journal.getCode(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
}
allMoveLineData.add(items);
}
}
}
}
}
}
}
writeMoveLineToCsvFile(company, fileName, this.createHeaderForDetailFile(typeSelect), allMoveLineData, accountingReport);
}
use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class AnalyticMoveLineServiceImpl method createAnalyticMoveLine.
public AnalyticMoveLine createAnalyticMoveLine(AnalyticDistributionLine analyticDistributionLine, BigDecimal total, int typeSelect, LocalDate date) {
AnalyticMoveLine analyticMoveLine = new AnalyticMoveLine();
analyticMoveLine.setOriginalPieceAmount(total);
analyticMoveLine.setAnalyticAccount(analyticDistributionLine.getAnalyticAccount());
analyticMoveLine.setAnalyticAxis(analyticDistributionLine.getAnalyticAxis());
analyticMoveLine.setAnalyticJournal(analyticDistributionLine.getAnalyticJournal());
AnalyticJournal analyticJournal = analyticDistributionLine.getAnalyticJournal();
Company company = analyticJournal == null ? null : analyticJournal.getCompany();
if (company != null) {
analyticMoveLine.setCurrency(company.getCurrency());
}
analyticMoveLine.setDate(date);
analyticMoveLine.setPercentage(analyticDistributionLine.getPercentage());
analyticMoveLine.setAmount(computeAmount(analyticMoveLine));
analyticMoveLine.setTypeSelect(typeSelect);
return analyticMoveLine;
}
use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class AnalyticMoveLineMngtRepository method copy.
@Override
public AnalyticMoveLine copy(AnalyticMoveLine entity, boolean deep) {
AnalyticMoveLine copy = super.copy(entity, deep);
copy.setMoveLine(null);
copy.setInvoiceLine(null);
return copy;
}
use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class MoveManagementRepository method save.
@Override
public Move save(Move move) {
try {
if (move.getStatusSelect() == MoveRepository.STATUS_ACCOUNTED) {
Beans.get(MoveValidateService.class).checkPreconditions(move);
}
Beans.get(MoveSequenceService.class).setDraftSequence(move);
List<MoveLine> moveLineList = move.getMoveLineList();
if (moveLineList != null) {
for (MoveLine moveLine : moveLineList) {
List<AnalyticMoveLine> analyticMoveLineList = moveLine.getAnalyticMoveLineList();
if (analyticMoveLineList != null) {
for (AnalyticMoveLine analyticMoveLine : analyticMoveLineList) {
analyticMoveLine.setAccount(moveLine.getAccount());
analyticMoveLine.setAccountType(moveLine.getAccount().getAccountType());
}
}
}
}
return super.save(move);
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
}
use of com.axelor.apps.account.db.AnalyticMoveLine in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method createAndSetMove.
protected Move createAndSetMove(Expense expense) throws AxelorException {
LocalDate moveDate = expense.getMoveDate();
if (moveDate == null) {
moveDate = appAccountService.getTodayDate(expense.getCompany());
expense.setMoveDate(moveDate);
}
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
Account account = null;
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
if (partner == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
}
Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
List<MoveLine> moveLines = new ArrayList<>();
Set<AnalyticAccount> analyticAccounts = new HashSet<>();
BigDecimal exTaxTotal = null;
int moveLineId = 1;
int expenseLineId = 1;
Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
analyticAccounts.clear();
Product product = expenseLine.getExpenseProduct();
account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
if (account == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
}
exTaxTotal = expenseLine.getUntaxedAmount();
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
analyticDistributionLine.setExpenseLine(null);
moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
}
moveLines.add(moveLine);
expenseLineId++;
}
moveLineService.consolidateMoveLines(moveLines);
account = accountConfigService.getExpenseTaxAccount(accountConfig);
BigDecimal taxTotal = BigDecimal.ZERO;
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
exTaxTotal = expenseLine.getTotalTax();
taxTotal = taxTotal.add(exTaxTotal);
}
if (taxTotal.signum() != 0) {
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
moveLines.add(moveLine);
}
move.getMoveLineList().addAll(moveLines);
moveService.getMoveValidateService().validate(move);
expense.setMove(move);
return move;
}
Aggregations