Search in sources :

Example 1 with AxelorException

use of com.axelor.exception.AxelorException 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 2 with AxelorException

use of com.axelor.exception.AxelorException 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 3 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class IrrecoverableService method passInIrrecoverable.

/**
 * Procédure permettant de passer une facture en irrécouvrable
 *
 * @param invoice Une facture
 * @param generateEvent Un évènement à t'il déjà été créé par un autre objet ?
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(Invoice invoice, boolean generateEvent) throws AxelorException {
    invoice.setIrrecoverableStatusSelect(InvoiceRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
    if (generateEvent) {
        Company company = invoice.getCompany();
        ManagementObject managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
        invoice.setManagementObject(managementObject);
        MoveLine moveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
        if (moveLine == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
        }
        this.passInIrrecoverable(moveLine, managementObject, false);
    }
    invoiceRepo.save(invoice);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ManagementObject(com.axelor.apps.account.db.ManagementObject) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 4 with AxelorException

use of com.axelor.exception.AxelorException 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 5 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class SubrogationReleaseServiceImpl method transmitRelease.

@Override
@Transactional(rollbackOn = { Exception.class })
public void transmitRelease(SubrogationRelease subrogationRelease) throws AxelorException {
    SequenceService sequenceService = Beans.get(SequenceService.class);
    String sequenceNumber = sequenceService.getSequenceNumber("subrogationRelease", subrogationRelease.getCompany());
    if (Strings.isNullOrEmpty(sequenceNumber)) {
        throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.SUBROGATION_RELEASE_MISSING_SEQUENCE), subrogationRelease.getCompany().getName());
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    subrogationRelease.setSequenceNumber(sequenceNumber);
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_TRANSMITTED);
    subrogationRelease.setTransmissionDate(appBaseService.getTodayDate(subrogationRelease.getCompany()));
}
Also used : AxelorException(com.axelor.exception.AxelorException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) Transactional(com.google.inject.persist.Transactional)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27