Search in sources :

Example 6 with Move

use of com.axelor.apps.account.db.Move 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;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) PaymentService(com.axelor.apps.account.service.payment.PaymentService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) PaymentScheduleRepository(com.axelor.apps.account.db.repo.PaymentScheduleRepository) RoundingMode(java.math.RoundingMode) Journal(com.axelor.apps.account.db.Journal) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) PaymentScheduleLineRepository(com.axelor.apps.account.db.repo.PaymentScheduleLineRepository) LocalDate(java.time.LocalDate) PaymentMode(com.axelor.apps.account.db.PaymentMode) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) BankDetails(com.axelor.apps.base.db.BankDetails) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 7 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class IrrecoverableService method createIrrecoverableInvoiceLineMove.

@Transactional(rollbackOn = { Exception.class })
public void createIrrecoverableInvoiceLineMove(Irrecoverable irrecoverable, Invoice invoice) throws AxelorException {
    BigDecimal prorataRate = this.getProrataRate(invoice, invoice.getRejectMoveLine() != null);
    // Ajout de l'écriture générée
    Move move = this.createIrrecoverableMove(invoice, prorataRate, invoice.getRejectMoveLine() != null, 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);
    invoice.setIrrecoverableStatusSelect(InvoiceRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
    if (invoice.getCanceledPaymentSchedule() != null && this.isAllInvoicePassedInIrrecoverable(invoice.getCanceledPaymentSchedule())) {
        invoice.getCanceledPaymentSchedule().setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 8 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class IrrecoverableService method passInIrrecoverable.

/**
 * Procédure permettant de
 *
 * @param irrecoverable
 * @throws AxelorException
 */
public int passInIrrecoverable(Irrecoverable irrecoverable) throws AxelorException {
    irrecoverable.setMoveSet(new HashSet<Move>());
    EntityTransaction transaction = JPA.em().getTransaction();
    int anomaly = 0;
    this.testCompanyField(irrecoverable.getCompany());
    int i = 0;
    if (irrecoverable.getInvoiceSet() != null && irrecoverable.getInvoiceSet().size() != 0) {
        for (Invoice invoice : irrecoverable.getInvoiceSet()) {
            i++;
            if (!transaction.isActive()) {
                transaction.begin();
            }
            try {
                log.debug("Facture : {}", invoice.getInvoiceId());
                this.createIrrecoverableInvoiceLineMove(irrecoverable, invoice);
                irrecoverableRepo.save(irrecoverable);
                if (i % 50 == 0) {
                    JPA.flush();
                    JPA.clear();
                }
            } catch (AxelorException e) {
                anomaly++;
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Invoice") + " %s", invoice.getInvoiceId()), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
                log.error("Bug(Anomalie) généré(e) pour la facture : {}", invoice.getInvoiceId());
            } catch (Exception e) {
                anomaly++;
                TraceBackService.trace(new Exception(String.format(I18n.get("Invoice") + " %s", invoice.getInvoiceId()), e), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
                log.error("Bug(Anomalie) généré(e) pour la facture : {}", invoice.getInvoiceId());
            } finally {
                if (!transaction.isActive()) {
                    transaction.begin();
                }
            }
        }
    }
    if (irrecoverable.getPaymentScheduleLineSet() != null && irrecoverable.getPaymentScheduleLineSet().size() != 0) {
        for (PaymentScheduleLine paymentScheduleLine : irrecoverable.getPaymentScheduleLineSet()) {
            i++;
            if (!transaction.isActive()) {
                transaction.begin();
            }
            try {
                log.debug("Ligne d'échéancier : {}", paymentScheduleLine.getName());
                this.createMoveForPaymentScheduleLineReject(irrecoverable, paymentScheduleLine);
                irrecoverableRepo.save(irrecoverable);
                if (i % 50 == 0) {
                    JPA.flush();
                    JPA.clear();
                }
            } catch (AxelorException e) {
                anomaly++;
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.IRRECOVERABLE_1), paymentScheduleLine.getName()), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
                log.error("Bug(Anomalie) généré(e) pour la ligne d'échéancier : {}", paymentScheduleLine.getName());
            } catch (Exception e) {
                anomaly++;
                TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.IRRECOVERABLE_1), paymentScheduleLine.getName()), e), ExceptionOriginRepository.IRRECOVERABLE, irrecoverable.getId());
                log.error("Bug(Anomalie) généré(e) pour la ligne d'échéancier : {}", paymentScheduleLine.getName());
            } finally {
                if (!transaction.isActive()) {
                    transaction.begin();
                }
            }
        }
    }
    if (!transaction.isActive()) {
        transaction.begin();
    }
    irrecoverable.setStatusSelect(IrrecoverableRepository.STATUS_VALIDATED);
    irrecoverableRepo.save(irrecoverable);
    transaction.commit();
    return anomaly;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) AxelorException(com.axelor.exception.AxelorException)

Example 9 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class IrrecoverableService method createIrrecoverableReport.

/**
 * Procédure permettant de passer en irrécouvrables les factures et échéances rejetées récupéré
 * sur l'objet Irrécouvrable
 *
 * @param irrecoverable Un objet Irrécouvrable
 */
@Transactional
public void createIrrecoverableReport(Irrecoverable irrecoverable) {
    Set<Invoice> invoiceSet = irrecoverable.getInvoiceSet();
    Set<PaymentScheduleLine> paymentScheduleLineSet = irrecoverable.getPaymentScheduleLineSet();
    irrecoverable.setMoveSet(new HashSet<Move>());
    List<Partner> payerPartnerList = this.getPayerPartnerList(invoiceSet);
    EntityTransaction transaction = JPA.em().getTransaction();
    int i = 0;
    if (payerPartnerList != null && payerPartnerList.size() != 0) {
        for (Partner payerPartner : payerPartnerList) {
            if (!transaction.isActive()) {
                transaction.begin();
            }
            i++;
            try {
                log.debug("Tiers : {}", payerPartner.getName());
                this.createIrrecoverableCustomerLine(irrecoverable, payerPartner, this.getInvoiceList(payerPartner, invoiceSet), this.getPaymentScheduleLineList(payerPartner, paymentScheduleLineSet));
                irrecoverableRepo.save(irrecoverable);
                transaction.commit();
                if (i % 50 == 0) {
                    JPA.flush();
                    JPA.clear();
                }
            } catch (Exception e) {
                TraceBackService.trace(e);
                log.error("Bug(Anomalie) généré(e) pour le tiers : {}", payerPartner.getName());
            } finally {
                if (!transaction.isActive()) {
                    transaction.begin();
                }
            }
        }
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) Move(com.axelor.apps.account.db.Move) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 10 with Move

use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.

the class MoveLineExportServiceImpl method updateMoveList.

public void updateMoveList(List<Move> moveList, AccountingReport accountingReport, LocalDate localDate, String exportNumber) {
    int i = 0;
    int moveListSize = moveList.size();
    for (Move move : moveList) {
        this.updateMove(moveRepo.find(move.getId()), accountingReportRepo.find(accountingReport.getId()), localDate, exportNumber);
        if (i % 10 == 0) {
            JPA.clear();
        }
        if (i++ % 100 == 0) {
            log.debug("Process : {} / {}", i, moveListSize);
        }
    }
}
Also used : Move(com.axelor.apps.account.db.Move)

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