Search in sources :

Example 61 with Invoice

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

the class InvoicePaymentCreateServiceImpl method getInvoiceIdsToPay.

@Override
public List<Long> getInvoiceIdsToPay(List<Long> invoiceIdList) throws AxelorException {
    Company company = null;
    Currency currency = null;
    List<Long> invoiceToPay = new ArrayList<>();
    Boolean isActivatePassedForPayment = Beans.get(AppAccountService.class).getAppAccount().getActivatePassedForPayment();
    for (Long invoiceId : invoiceIdList) {
        Invoice invoice = Beans.get(InvoiceRepository.class).find(invoiceId);
        if ((invoice.getStatusSelect() != InvoiceRepository.STATUS_VENTILATED && invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) || (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE && invoice.getStatusSelect() != InvoiceRepository.STATUS_VALIDATED)) {
            continue;
        }
        if (invoice.getAmountRemaining().compareTo(BigDecimal.ZERO) <= 0) {
            continue;
        }
        if (company == null) {
            company = invoice.getCompany();
        }
        if (currency == null) {
            currency = invoice.getCurrency();
        }
        if (invoice.getCompany() == null || company == null || !invoice.getCompany().equals(company)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_COMPANY));
        }
        if (invoice.getCurrency() == null || currency == null || !invoice.getCurrency().equals(currency)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_CURRENCY));
        }
        if (isActivatePassedForPayment && invoice.getPfpValidateStatusSelect() != InvoiceRepository.PFP_STATUS_VALIDATED) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_MASS_PAYMENT_ERROR_PFP_LITIGATION));
        }
        invoiceToPay.add(invoiceId);
    }
    return invoiceToPay;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Currency(com.axelor.apps.base.db.Currency) ArrayList(java.util.ArrayList) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository)

Example 62 with Invoice

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

the class PaymentVoucherConfirmService method waitForDepositSlip.

private void waitForDepositSlip(PaymentVoucher paymentVoucher) {
    for (PayVoucherElementToPay payVoucherElementToPay : paymentVoucher.getPayVoucherElementToPayList()) {
        Invoice invoice = payVoucherElementToPay.getMoveLine().getMove().getInvoice();
        boolean hasPendingPayments = payVoucherElementToPay.getRemainingAmountAfterPayment().signum() <= 0;
        invoice.setHasPendingPayments(hasPendingPayments);
    }
    paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_WAITING_FOR_DEPOSIT_SLIP);
}
Also used : PayVoucherElementToPay(com.axelor.apps.account.db.PayVoucherElementToPay) Invoice(com.axelor.apps.account.db.Invoice)

Example 63 with Invoice

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

the class ClientViewServiceImpl method getTotalRemainingIndicator.

protected String getTotalRemainingIndicator(User user) {
    List<Filter> filters = getTotalRemainingOfUser(user);
    List<Invoice> invoiceList = Filter.and(filters).build(Invoice.class).fetch();
    if (!invoiceList.isEmpty()) {
        BigDecimal total = invoiceList.stream().map(Invoice::getAmountRemaining).reduce((x, y) -> x.add(y)).orElse(BigDecimal.ZERO);
        return total.toString() + invoiceList.get(0).getCurrency().getSymbol();
    }
    return BigDecimal.ZERO.toString();
}
Also used : ProjectTask(com.axelor.apps.project.db.ProjectTask) Filter(com.axelor.rpc.filter.Filter) Ticket(com.axelor.apps.helpdesk.db.Ticket) UserService(com.axelor.apps.base.service.user.UserService) TicketRepository(com.axelor.apps.helpdesk.db.repo.TicketRepository) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) ProjectRepository(com.axelor.apps.project.db.repo.ProjectRepository) ProjectTaskRepository(com.axelor.apps.project.db.repo.ProjectTaskRepository) Map(java.util.Map) I18n(com.axelor.i18n.I18n) Project(com.axelor.apps.project.db.Project) SaleOrder(com.axelor.apps.sale.db.SaleOrder) JpaSecurity(com.axelor.db.JpaSecurity) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Invoice(com.axelor.apps.account.db.Invoice) List(java.util.List) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) DateTimeFormatter(java.time.format.DateTimeFormatter) User(com.axelor.auth.db.User) Invoice(com.axelor.apps.account.db.Invoice) Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) BigDecimal(java.math.BigDecimal)

Example 64 with Invoice

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

the class InvoiceController method exportAnnex.

public void exportAnnex(ActionRequest request, ActionResponse response) throws AxelorException {
    Invoice invoice = Beans.get(InvoiceRepository.class).find(request.getContext().asType(Invoice.class).getId());
    try {
        List<String> reportInfo = Beans.get(InvoiceServiceProjectImpl.class).editInvoiceAnnex(invoice, invoice.getId().toString(), false);
        if (reportInfo == null || reportInfo.isEmpty()) {
            return;
        }
        response.setView(ActionView.define(reportInfo.get(0)).add("html", reportInfo.get(1)).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceServiceProjectImpl(com.axelor.apps.businessproject.service.InvoiceServiceProjectImpl) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) AxelorException(com.axelor.exception.AxelorException)

Example 65 with Invoice

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

the class InvoiceController method fillEstimatedPaymentDate.

public void fillEstimatedPaymentDate(ActionRequest request, ActionResponse response) {
    Invoice invoice = request.getContext().asType(Invoice.class);
    try {
        LocalDate estimatedPaymentDate = Beans.get(InvoiceEstimatedPaymentService.class).computeEstimatedPaymentDate(invoice);
        response.setValue("estimatedPaymentDate", estimatedPaymentDate);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : InvoiceEstimatedPaymentService(com.axelor.apps.cash.management.service.InvoiceEstimatedPaymentService) Invoice(com.axelor.apps.account.db.Invoice) LocalDate(java.time.LocalDate)

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