Search in sources :

Example 21 with InvoicePayment

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

the class InvoiceManagementRepository method save.

@Override
public Invoice save(Invoice invoice) {
    try {
        List<InvoicePayment> invoicePayments = invoice.getInvoicePaymentList();
        if (CollectionUtils.isNotEmpty(invoicePayments)) {
            LocalDate latestPaymentDate = invoicePayments.stream().filter(invoicePayment -> invoicePayment.getStatusSelect() == InvoicePaymentRepository.STATUS_VALIDATED).map(InvoicePayment::getPaymentDate).max(LocalDate::compareTo).orElse(null);
            invoice.setPaymentDate(latestPaymentDate);
        }
        invoice = super.save(invoice);
        Beans.get(InvoiceService.class).setDraftSequence(invoice);
        return invoice;
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) Beans(com.axelor.inject.Beans) PersistenceException(javax.persistence.PersistenceException) CollectionUtils(org.apache.commons.collections.CollectionUtils) LocalDate(java.time.LocalDate) Map(java.util.Map) TraceBackService(com.axelor.exception.service.TraceBackService) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) Invoice(com.axelor.apps.account.db.Invoice) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) PersistenceException(javax.persistence.PersistenceException) LocalDate(java.time.LocalDate) PersistenceException(javax.persistence.PersistenceException)

Example 22 with InvoicePayment

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

the class BankOrderServiceImpl method validatePayment.

@Override
@Transactional(rollbackOn = { Exception.class })
public void validatePayment(BankOrder bankOrder) throws AxelorException {
    List<InvoicePayment> invoicePaymentList = invoicePaymentRepo.findByBankOrder(bankOrder).fetch();
    InvoicePaymentValidateServiceBankPayImpl invoicePaymentValidateServiceBankPayImpl = Beans.get(InvoicePaymentValidateServiceBankPayImpl.class);
    for (InvoicePayment invoicePayment : invoicePaymentList) {
        if (invoicePayment != null && invoicePayment.getStatusSelect() != InvoicePaymentRepository.STATUS_VALIDATED && invoicePayment.getInvoice() != null) {
            if (bankOrderLineOriginService.existBankOrderLineOrigin(bankOrder, invoicePayment.getInvoice())) {
                invoicePaymentValidateServiceBankPayImpl.validateFromBankOrder(invoicePayment, true);
            }
        }
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) InvoicePaymentValidateServiceBankPayImpl(com.axelor.apps.bankpayment.service.invoice.payment.InvoicePaymentValidateServiceBankPayImpl) Transactional(com.google.inject.persist.Transactional)

Example 23 with InvoicePayment

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

the class PaymentScheduleLineBankPaymentServiceImpl method cancelInvoicePayments.

@Transactional(rollbackOn = { Exception.class })
protected void cancelInvoicePayments(PaymentScheduleLine paymentScheduleLine) throws AxelorException {
    MoveLineService moveLineService = moveService.getMoveLineService();
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    MoveLine creditMoveLine = paymentScheduleLine.getAdvanceMoveLine();
    Set<Invoice> invoiceSet = MoreObjects.firstNonNull(paymentSchedule.getInvoiceSet(), Collections.emptySet());
    for (Invoice invoice : invoiceSet) {
        MoveLine debitMoveLine = moveLineService.getDebitCustomerMoveLine(invoice);
        Reconcile reconcile = reconcileRepo.findByMoveLines(debitMoveLine, creditMoveLine);
        if (reconcile == null) {
            continue;
        }
        for (InvoicePayment invoicePayment : invoicePaymentRepo.findByReconcile(reconcile).fetch()) {
            invoicePaymentCancelService.cancel(invoicePayment);
        }
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) MoveLineService(com.axelor.apps.account.service.move.MoveLineService) Invoice(com.axelor.apps.account.db.Invoice) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) MoveLine(com.axelor.apps.account.db.MoveLine) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 24 with InvoicePayment

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

the class ReconcileServiceImpl method updateInvoicePaymentsCanceled.

public void updateInvoicePaymentsCanceled(Reconcile reconcile) throws AxelorException {
    log.debug("updateInvoicePaymentsCanceled : reconcile : {}", reconcile);
    List<InvoicePayment> invoicePaymentList = Beans.get(InvoicePaymentRepository.class).all().filter("self.reconcile = ?1", reconcile).fetch();
    for (InvoicePayment invoicePayment : invoicePaymentList) {
        invoicePaymentCancelService.updateCancelStatus(invoicePayment);
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) InvoicePaymentRepository(com.axelor.apps.account.db.repo.InvoicePaymentRepository)

Example 25 with InvoicePayment

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

the class BatchBankPaymentServiceImpl method createBankOrders.

@Transactional(rollbackOn = { Exception.class })
protected void createBankOrders(Batch batch, Reconcile reconcile) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    for (InvoicePayment invoicePayment : invoicePaymentRepo.findByReconcile(reconcile).fetch()) {
        if (invoicePayment.getBankOrder() != null) {
            continue;
        }
        invoicePaymentValidateService.validate(invoicePayment, true);
        if (invoicePayment.getBankOrder() == null) {
            throw new AxelorException(invoicePayment, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get("Failed to create bank order from invoice payment"));
        }
        invoicePayment.getBankOrder().setBatch(batch);
        bankOrderRepo.save(invoicePayment.getBankOrder());
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Aggregations

InvoicePayment (com.axelor.apps.account.db.InvoicePayment)31 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)9 Transactional (com.google.inject.persist.Transactional)9 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 MoveLine (com.axelor.apps.account.db.MoveLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 Move (com.axelor.apps.account.db.Move)5 InvoicePaymentToolService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService)4 LocalDate (java.time.LocalDate)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)3 InvoicePaymentCreateService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService)3 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)3 Map (java.util.Map)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 Reconcile (com.axelor.apps.account.db.Reconcile)2 InvoicePaymentRepository (com.axelor.apps.account.db.repo.InvoicePaymentRepository)2 Company (com.axelor.apps.base.db.Company)2