Search in sources :

Example 6 with PaymentScheduleLine

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

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

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

the class IrrecoverableService method getPaymentScheduleLineList.

/**
 * Fonction permettant de récupérer les échéances rejetées à passer en irrécouvrable d'un tiers
 *
 * @param payerPartner Un tiers payeur
 * @param allPaymentScheduleLineList La liste des échéances rejetées à passer en irrécouvrable de
 *     la société
 * @return
 */
public List<PaymentScheduleLine> getPaymentScheduleLineList(Partner payerPartner, Set<PaymentScheduleLine> allPaymentScheduleLineList) {
    List<PaymentScheduleLine> paymentScheduleLineList = new ArrayList<PaymentScheduleLine>();
    for (PaymentScheduleLine paymentScheduleLine : allPaymentScheduleLineList) {
        if (paymentScheduleLine.getPaymentSchedule().getPartner().equals(payerPartner)) {
            paymentScheduleLineList.add(paymentScheduleLine);
        }
    }
    log.debug("Nombre d'échéances à passer en irrécouvrable pour le tiers : {}", paymentScheduleLineList.size());
    return paymentScheduleLineList;
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) ArrayList(java.util.ArrayList)

Example 9 with PaymentScheduleLine

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

the class IrrecoverableService method notPassInIrrecoverable.

/**
 * Procédure permettant d'annuler le passage en irrécouvrable d'une échéancier de lissage de
 * paiement La procédure annulera aussi le passage en irrécouvrable des lignes d'écriture de rejet
 * d'échéance en irrécouvrable, ainsi que des 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 notPassInIrrecoverable(PaymentSchedule paymentSchedule) throws AxelorException {
    paymentSchedule.setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_NOT_IRRECOUVRABLE);
    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.notPassInIrrecoverable(moveLine, false);
    }
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        this.notPassInIrrecoverable(invoice);
    }
    paymentScheduleRepo.save(paymentSchedule);
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) 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 10 with PaymentScheduleLine

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

the class CfonbExportService method exportCFONB.

/**
 * Méthode permettant d'exporter les prélèvements de facture et d'échéance de paiement au format
 * CFONB
 *
 * @param paymentScheduleExport
 * @param paymentScheduleLineList
 * @param invoiceList
 * @param company
 * @throws AxelorException
 */
public void exportCFONB(ZonedDateTime processingDateTime, LocalDate scheduleDate, List<PaymentScheduleLine> paymentScheduleLineList, List<Invoice> invoiceList, Company company, BankDetails bankDetails) throws AxelorException {
    if ((paymentScheduleLineList == null || paymentScheduleLineList.isEmpty()) && (invoiceList == null || invoiceList.isEmpty())) {
        return;
    }
    this.testCompanyExportCFONBField(company);
    // paramètre obligatoire : au minimum
    // un enregistrement emetteur par date de règlement (code 03)
    // un enregistrement destinataire (code 06)
    // un enregistrement total (code 08)
    String senderCFONB = this.createSenderMonthlyExportCFONB(scheduleDate, bankDetails);
    List<String> multiRecipientCFONB = new ArrayList<String>();
    // Echéanciers
    for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
        paymentScheduleLine = paymentScheduleLineRepo.find(paymentScheduleLine.getId());
        multiRecipientCFONB.add(this.createRecipientCFONB(paymentScheduleLine, false));
    }
    // Factures
    for (Invoice invoice : invoiceList) {
        invoice = invoiceRepo.find(invoice.getId());
        multiRecipientCFONB.add(this.createRecipientCFONB(company, invoice));
    }
    BigDecimal amount = this.getTotalAmountPaymentSchedule(paymentScheduleLineList).add(this.getTotalAmountInvoice(invoiceList));
    String totalCFONB = this.createPaymentScheduleTotalCFONB(company, amount);
// cfonbToolService.testLength(senderCFONB, totalCFONB, multiRecipientCFONB, company);
// List<String> cFONB = this.createCFONBExport(senderCFONB, multiRecipientCFONB, totalCFONB);
// Mise en majuscule des enregistrement
// cFONB = this.toUpperCase(cFONB);
// this.createCFONBFile(cFONB, processingDateTime,
// company.getAccountConfig().getPaymentScheduleExportFolderPathCFONB(), "prelevement");
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Aggregations

PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)29 Transactional (com.google.inject.persist.Transactional)12 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)10 ArrayList (java.util.ArrayList)8 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)7 BigDecimal (java.math.BigDecimal)6 LocalDate (java.time.LocalDate)5 MoveLine (com.axelor.apps.account.db.MoveLine)4 BankDetails (com.axelor.apps.base.db.BankDetails)4 Company (com.axelor.apps.base.db.Company)4 Partner (com.axelor.apps.base.db.Partner)4 Move (com.axelor.apps.account.db.Move)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 EntityTransaction (javax.persistence.EntityTransaction)2 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1