Search in sources :

Example 86 with Move

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) Transactional(com.google.inject.persist.Transactional)

Example 87 with 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);
}
Also used : Company(com.axelor.apps.base.db.Company) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) Move(com.axelor.apps.account.db.Move) JournalType(com.axelor.apps.account.db.JournalType) Transactional(com.google.inject.persist.Transactional)

Example 88 with Move

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;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Notification(com.axelor.apps.account.db.Notification) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 89 with Move

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);
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) Transactional(com.google.inject.persist.Transactional)

Example 90 with Move

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);
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) LocalDate(java.time.LocalDate) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) BankReconciliation(com.axelor.apps.bankpayment.db.BankReconciliation)

Aggregations

Move (com.axelor.apps.account.db.Move)101 MoveLine (com.axelor.apps.account.db.MoveLine)51 Transactional (com.google.inject.persist.Transactional)37 Company (com.axelor.apps.base.db.Company)36 AxelorException (com.axelor.exception.AxelorException)34 BigDecimal (java.math.BigDecimal)33 Partner (com.axelor.apps.base.db.Partner)31 LocalDate (java.time.LocalDate)28 Journal (com.axelor.apps.account.db.Journal)25 Account (com.axelor.apps.account.db.Account)22 ArrayList (java.util.ArrayList)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)18 Reconcile (com.axelor.apps.account.db.Reconcile)14 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)11 Invoice (com.axelor.apps.account.db.Invoice)11 List (java.util.List)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)5 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)5 MoveService (com.axelor.apps.account.service.move.MoveService)5