use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class IrrecoverableService method createMoveForPaymentScheduleLineReject.
@Transactional(rollbackOn = { Exception.class })
public void createMoveForPaymentScheduleLineReject(Irrecoverable irrecoverable, PaymentScheduleLine paymentScheduleLine) throws AxelorException {
Move move = this.createIrrecoverableMove(paymentScheduleLine.getRejectMoveLine(), irrecoverable.getName());
if (move == null) {
throw new AxelorException(irrecoverable, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
moveService.getMoveValidateService().validate(move);
irrecoverable.getMoveSet().add(move);
}
use of com.axelor.apps.account.db.Move 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);
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class NotificationServiceImpl method createPaymentMove.
@Transactional(rollbackOn = { Exception.class })
protected Move createPaymentMove(NotificationItem notificationItem) throws AxelorException {
Notification notification = notificationItem.getNotification();
Invoice invoice = notificationItem.getInvoice();
Company company = invoice.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = getJournal(accountConfig);
SubrogationRelease subrogationRelease = getSubrogationRelease(notificationItem);
String origin = computeOrigin(subrogationRelease, invoice);
BigDecimal amountPaid = notificationItem.getAmountPaid();
if (amountPaid.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Move paymentMove = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), notification.getPaymentDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine, debitMoveLine;
Account account = getAccount(accountConfig, notificationItem);
debitMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), account, amountPaid, true, notification.getPaymentDate(), null, 1, origin, invoice.getInvoiceId());
creditMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), invoice.getPartnerAccount(), amountPaid, false, notification.getPaymentDate(), null, 2, origin, invoice.getInvoiceId());
paymentMove.addMoveLineListItem(debitMoveLine);
paymentMove.addMoveLineListItem(creditMoveLine);
paymentMove = moveRepository.save(paymentMove);
moveService.getMoveValidateService().validate(paymentMove);
MoveLine invoiceMoveLine = findInvoiceAccountMoveLine(invoice);
MoveLine subrogationReleaseMoveLine = findSubrogationReleaseAccountMoveLine(invoice);
if (invoiceMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) {
reconcileService.reconcile(invoiceMoveLine, creditMoveLine, true, true);
if (subrogationReleaseMoveLine != null && notificationItem.getTypeSelect() == NotificationRepository.TYPE_PAYMENT_TO_THE_FACTORE) {
reconcileService.reconcile(debitMoveLine, subrogationReleaseMoveLine, true, false);
}
}
notificationItem.setMove(paymentMove);
if (subrogationRelease != null) {
subrogationReleaseService.clear(subrogationRelease);
}
return paymentMove;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class ChequeRejectionService method validateChequeRejection.
/**
* procédure de validation du rejet de chèque
*
* @param chequeRejection Un rejet de chèque brouillon
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void validateChequeRejection(ChequeRejection chequeRejection) throws AxelorException {
Company company = chequeRejection.getCompany();
this.testCompanyField(company);
this.setSequence(chequeRejection);
Move move = this.createChequeRejectionMove(chequeRejection, company);
chequeRejection.setMove(move);
chequeRejection.setStatusSelect(ChequeRejectionRepository.STATUS_VALIDATED);
chequeRejectionRepository.save(chequeRejection);
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class BankReconciliationValidateService method validate.
protected void validate(BankReconciliationLine bankReconciliationLine) throws AxelorException {
BigDecimal debit = bankReconciliationLine.getDebit();
BigDecimal credit = bankReconciliationLine.getCredit();
if (debit.compareTo(BigDecimal.ZERO) == 0 && credit.compareTo(BigDecimal.ZERO) == 0) {
return;
}
BankReconciliation bankReconciliation = bankReconciliationLine.getBankReconciliation();
Company company = bankReconciliation.getCompany();
LocalDate effectDate = bankReconciliationLine.getEffectDate();
Partner partner = bankReconciliationLine.getPartner();
String reference = bankReconciliationLine.getReference();
String name = bankReconciliationLine.getName();
if (name != null && name.length() > 255) {
name = name.substring(0, 255);
}
BigDecimal amount = debit.add(credit);
String origin = bankReconciliation.getName() + reference != null ? " - " + reference : "";
boolean isDebit = debit.compareTo(BigDecimal.ZERO) > 0;
Move move = moveService.getMoveCreateService().createMove(bankReconciliation.getJournal(), company, null, partner, effectDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine partnerMoveLine = moveLineService.createMoveLine(move, partner, bankReconciliationLine.getAccount(), amount, isDebit, effectDate, effectDate, 1, origin, name);
move.addMoveLineListItem(partnerMoveLine);
MoveLine cashMoveLine = moveLineService.createMoveLine(move, partner, bankReconciliation.getCashAccount(), amount, !isDebit, effectDate, effectDate, 2, origin, name);
cashMoveLine.setBankReconciledAmount(amount);
move.addMoveLineListItem(cashMoveLine);
moveRepository.save(move);
moveService.getMoveValidateService().validate(move);
bankReconciliationLine.setMoveLine(cashMoveLine);
bankReconciliationLine.setIsPosted(true);
updateBankReconciledAmounts(bankReconciliationLine);
}
Aggregations