use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method createMoveForExpensePayment.
public Move createMoveForExpensePayment(Expense expense) throws AxelorException {
Company company = expense.getCompany();
PaymentMode paymentMode = expense.getPaymentMode();
Partner partner = expense.getUser().getPartner();
LocalDate paymentDate = expense.getPaymentDate();
BigDecimal paymentAmount = expense.getInTaxTotal();
BankDetails companyBankDetails = company.getDefaultBankDetails();
Account employeeAccount;
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
MoveLine expenseMoveLine = this.getExpenseEmployeeMoveLineByLoop(expense);
if (expenseMoveLine == null) {
return null;
}
employeeAccount = expenseMoveLine.getAccount();
Move move = moveService.getMoveCreateService().createMove(journal, company, expense.getMove().getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, false, paymentDate, null, 1, expense.getExpenseSeq(), null));
MoveLine employeeMoveLine = moveLineService.createMoveLine(move, partner, employeeAccount, paymentAmount, true, paymentDate, null, 2, expense.getExpenseSeq(), null);
employeeMoveLine.setTaxAmount(expense.getTaxTotal());
move.addMoveLineListItem(employeeMoveLine);
moveService.getMoveValidateService().validate(move);
expense.setPaymentMove(move);
Beans.get(ReconcileService.class).reconcile(expenseMoveLine, employeeMoveLine, true, false);
expenseRepository.save(expense);
return move;
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.
@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
SaleOrder saleOrder = advancePayment.getSaleOrder();
Company company = saleOrder.getCompany();
PaymentMode paymentMode = advancePayment.getPaymentMode();
Partner clientPartner = saleOrder.getClientPartner();
LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
BankDetails bankDetails = saleOrder.getCompanyBankDetails();
String ref = saleOrder.getSaleOrderSeq();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
moveService.getMoveValidateService().validate(move);
advancePayment.setMove(move);
advancePaymentRepository.save(advancePayment);
return move;
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class JournalManagementRepository method copy.
@Override
public Journal copy(Journal entity, boolean deep) {
Journal copy = super.copy(entity, deep);
copy.setStatusSelect(JournalRepository.STATUS_INACTIVE);
copy.setSequence(null);
return copy;
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.
@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
MoveService moveService = Beans.get(MoveService.class);
MoveRepository moveRepository = Beans.get(MoveRepository.class);
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
Company company = subrogationRelease.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
if (subrogationRelease.getAccountingDate() == null) {
subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
}
this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
boolean isRefund = false;
if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
isRefund = true;
}
LocalDate date = subrogationRelease.getAccountingDate();
Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine, debitMoveLine;
debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
move.addMoveLineListItem(debitMoveLine);
move.addMoveLineListItem(creditMoveLine);
move = moveRepository.save(move);
moveService.getMoveValidateService().validate(move);
invoice.setSubrogationRelease(subrogationRelease);
invoice.setSubrogationReleaseMove(move);
subrogationRelease.addMoveListItem(move);
}
subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
use of com.axelor.apps.account.db.Journal in project axelor-open-suite by axelor.
the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1008FILE1.
/**
* Méthode réalisant l'export SI - des en-têtes pour les journaux de type trésorerie
*
* @param mlr
* @param replay
* @throws AxelorException
* @throws IOException
*/
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void exportMoveLineTypeSelect1008FILE1(AccountingReport accountingReport, boolean replay) throws AxelorException, IOException {
log.info("In export service 1008 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 = accountingReport.getCompany().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();
if (!moveList.isEmpty()) {
long moveLineListSize = moveLineRepo.all().filter("self.move in ?1 AND (self.debit > 0 OR self.credit > 0) " + moveLineQueryStr, moveList).count();
if (moveLineListSize > 0) {
String exportNumber = this.getTreasuryExportNumber(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] = "0";
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)) + "tresorerie.dat";
writeMoveLineToCsvFile(company, fileName, this.createHeaderForHeaderFile(accountingReport.getReportType().getTypeSelect()), allMoveData, accountingReport);
}
Aggregations