Search in sources :

Example 6 with Invoice

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

the class PaymentScheduleServiceImpl method cancelPaymentSchedule.

/**
 * Methode qui annule un échéancier
 *
 * @param paymentSchedule
 */
@Override
public void cancelPaymentSchedule(PaymentSchedule paymentSchedule) {
    // L'échéancier est passé à annulé
    paymentSchedule.setStatusSelect(PaymentScheduleRepository.STATUS_CANCELED);
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        // Si l'échéance n'est pas complètement payée
        if (paymentScheduleLine.getInTaxAmountPaid().compareTo(paymentScheduleLine.getInTaxAmount()) != 0) {
            // L'échéance est passée à cloturé
            paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_CLOSED);
        }
    }
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        // L'échéancier n'est plus selectionné sur la facture
        invoice.setPaymentSchedule(null);
        // L'échéancier est assigné dans un nouveau champs afin de garder un lien invisble pour
        // l'utilisateur, mais utilisé pour le passage en irrécouvrable
        invoice.setCanceledPaymentSchedule(paymentSchedule);
        invoice.setSchedulePaymentOk(false);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine)

Example 7 with Invoice

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

the class IrrecoverableService method passInIrrecoverable.

/**
 * Procédure permettant de passer un échéancier de lissage de paiement en irrécouvrable La
 * procédure passera aussi les lignes d'écriture de rejet d'échéance en irrécouvrable, ainsi que
 * les factures pas complètement payée selectionnées sur l'échéancier
 *
 * @param paymentSchedule Un échéancier de paiement
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(PaymentSchedule paymentSchedule) throws AxelorException {
    Company company = paymentSchedule.getCompany();
    paymentSchedule.setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
    ManagementObject managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
    paymentSchedule.setManagementObject(managementObject);
    List<MoveLine> paymentScheduleLineRejectMoveLineList = new ArrayList<MoveLine>();
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        if (paymentScheduleLine.getRejectMoveLine() != null && paymentScheduleLine.getRejectMoveLine().getAmountRemaining().compareTo(BigDecimal.ZERO) > 0) {
            paymentScheduleLineRejectMoveLineList.add(paymentScheduleLine.getRejectMoveLine());
        }
    }
    for (MoveLine moveLine : paymentScheduleLineRejectMoveLineList) {
        this.passInIrrecoverable(moveLine, managementObject, true);
    }
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        if (invoice.getCompanyInTaxTotalRemaining().compareTo(BigDecimal.ZERO) > 0) {
            this.passInIrrecoverable(invoice, managementObject);
        }
    }
    paymentScheduleService.cancelPaymentSchedule(paymentSchedule);
    paymentScheduleRepo.save(paymentSchedule);
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) ManagementObject(com.axelor.apps.account.db.ManagementObject) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 8 with Invoice

use of com.axelor.apps.account.db.Invoice 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 Invoice

use of com.axelor.apps.account.db.Invoice 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 Invoice

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

the class IrrecoverableService method getInvoiceList.

/**
 * Fonction permettant de récupérer les factures à passer en irrécouvrable d'un tiers
 *
 * @param partner Un tiers
 * @param allInvoiceList La liste des factures à passer en irrécouvrable de la société
 * @return
 */
public List<Invoice> getInvoiceList(Partner partner, Set<Invoice> allInvoiceList) {
    List<Invoice> invoiceList = new ArrayList<Invoice>();
    for (Invoice invoice : allInvoiceList) {
        if (invoice.getPartner().equals(partner)) {
            invoiceList.add(invoice);
        }
    }
    log.debug("Nombre de facture à passer en irrécouvrable pour le tiers : {}", invoiceList.size());
    return invoiceList;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14