Search in sources :

Example 1 with ManagementObject

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

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

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

the class IrrecoverableService method passInIrrecoverable.

/**
 * Procédure permettant de passer en irrécouvrable une ligne d'écriture
 *
 * @param moveLine Une ligne d'écriture
 * @param generateEvent Un évènement à t'il déjà été créé par un autre objet ?
 * @param passInvoice La procédure doit-elle passer aussi en irrécouvrable la facture ?
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(MoveLine moveLine, boolean generateEvent, boolean passInvoice) throws AxelorException {
    moveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
    ManagementObject managementObject = null;
    if (generateEvent) {
        Company company = moveLine.getMove().getCompany();
        managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
        moveLine.setManagementObject(managementObject);
    }
    if (moveLine.getMove().getInvoice() != null && passInvoice) {
        this.passInIrrecoverable(moveLine.getMove().getInvoice(), managementObject);
    }
    moveLineRepo.save(moveLine);
}
Also used : Company(com.axelor.apps.base.db.Company) ManagementObject(com.axelor.apps.account.db.ManagementObject) Transactional(com.google.inject.persist.Transactional)

Example 4 with ManagementObject

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

the class IrrecoverableService method createManagementObject.

/**
 * Fonction permettant de créer un objet de gestion
 *
 * @param code
 * @param message
 * @return
 */
public ManagementObject createManagementObject(String code, String message) {
    ManagementObject managementObject = managementObjectRepo.all().filter("self.code = ?1 AND self.name = ?2", code, message).fetchOne();
    if (managementObject != null) {
        return managementObject;
    }
    managementObject = new ManagementObject();
    managementObject.setCode(code);
    managementObject.setName(message);
    return managementObject;
}
Also used : ManagementObject(com.axelor.apps.account.db.ManagementObject)

Aggregations

ManagementObject (com.axelor.apps.account.db.ManagementObject)4 Company (com.axelor.apps.base.db.Company)3 Transactional (com.google.inject.persist.Transactional)3 MoveLine (com.axelor.apps.account.db.MoveLine)2 Invoice (com.axelor.apps.account.db.Invoice)1 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)1 AxelorException (com.axelor.exception.AxelorException)1 ArrayList (java.util.ArrayList)1