use of com.axelor.apps.account.db.MoveLine 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.MoveLine 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.MoveLine 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.MoveLine 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.MoveLine in project axelor-open-suite by axelor.
the class PaymentScheduleLineServiceImpl method createPaymentMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
Preconditions.checkNotNull(paymentScheduleLine);
Preconditions.checkNotNull(companyBankDetails);
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String name = paymentScheduleLine.getName();
LocalDate todayDate = appBaseService.getTodayDate(company);
Account account = accountingSituationService.getCustomerAccount(partner, company);
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
move.addMoveLineListItem(creditMoveLine);
creditMoveLine = moveLineRepo.save(creditMoveLine);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
move.addMoveLineListItem(debitMoveLine);
debitMoveLine = moveLineRepo.save(debitMoveLine);
moveService.getMoveValidateService().validate(move);
// Reconcile
if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
if (moveToolService.isSameAccount(debitMoveLineList, account)) {
List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
}
}
paymentScheduleLine.setDirectDebitAmount(amount);
paymentScheduleLine.setInTaxAmountPaid(amount);
paymentScheduleLine.setAdvanceOrPaymentMove(move);
paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
return move;
}
Aggregations