Search in sources :

Example 71 with Invoice

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

the class StockMoveInvoiceController method generateMultiSupplierInvoice.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void generateMultiSupplierInvoice(ActionRequest request, ActionResponse response) {
    try {
        List<Map> stockMoveMap = (List<Map>) request.getContext().get("supplierStockMoveToInvoice");
        List<Long> stockMoveIdList = new ArrayList<>();
        List<StockMove> stockMoveList = new ArrayList<>();
        for (Map map : stockMoveMap) {
            stockMoveIdList.add(((Number) map.get("id")).longValue());
        }
        for (Long stockMoveId : stockMoveIdList) {
            stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
        }
        Beans.get(StockMoveMultiInvoiceService.class).checkForAlreadyInvoicedStockMove(stockMoveList);
        Entry<List<Long>, String> result = Beans.get(StockMoveMultiInvoiceService.class).generateMultipleInvoices(stockMoveIdList);
        List<Long> invoiceIdList = result.getKey();
        String warningMessage = result.getValue();
        if (!invoiceIdList.isEmpty()) {
            ActionViewBuilder viewBuilder;
            viewBuilder = ActionView.define("Suppl. Invoices");
            viewBuilder.model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").domain("self.id IN (" + Joiner.on(",").join(invoiceIdList) + ")").context("_operationTypeSelect", InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)));
            response.setView(viewBuilder.map());
        }
        if (warningMessage != null && !warningMessage.isEmpty()) {
            response.setFlash(warningMessage);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 72 with Invoice

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

the class StockMoveInvoiceController method openInvoicingWizard.

public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
    try {
        response.setReload(true);
        StockMove stockMove = request.getContext().asType(StockMove.class);
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
        List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
        Company company = stockMove.getCompany();
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
        if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
            // open wizard view for partial invoicing
            response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
        } else if (!stockMoveLines.isEmpty()) {
            // invoice everything if config is disabled.
            Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
            if (invoice != null) {
                response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
            }
        } else {
            response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService) Map(java.util.Map) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 73 with Invoice

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

the class PurchaseOrderInvoiceController method generateInvoice.

public void generateInvoice(ActionRequest request, ActionResponse response) {
    PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
    purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(purchaseOrder.getId());
    try {
        Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
        if (invoice != null) {
            response.setReload(true);
            response.setView(ActionView.define(I18n.get(IExceptionMessage.PO_INVOICE_2)).model(Invoice.class.getName()).add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").domain("self.purchaseOrder.id = " + String.valueOf(invoice.getId())).domain("self.operationTypeSelect = " + String.valueOf(invoice.getOperationTypeSelect())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("_showRecord", String.valueOf(invoice.getId())).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService)

Example 74 with Invoice

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

the class BatchBankPaymentServiceImpl method createBankOrders.

@Transactional(rollbackOn = { Exception.class })
protected void createBankOrders(Batch batch, Collection<PaymentScheduleLine> paymentScheduleLines) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLines) {
        PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
        MoveLine creditMoveLine = paymentScheduleLine.getAdvanceMoveLine();
        for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
            MoveLine debitMoveLine = moveService.getMoveLineService().getDebitCustomerMoveLine(invoice);
            Reconcile reconcile = reconcileRepo.findByMoveLines(debitMoveLine, creditMoveLine);
            if (reconcile == null) {
                continue;
            }
            createBankOrders(batch, reconcile);
        }
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) 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 75 with Invoice

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

the class InvoicePaymentValidateServiceBankPayImpl method setInvoicePaymentStatus.

@Override
protected void setInvoicePaymentStatus(InvoicePayment invoicePayment) throws AxelorException {
    Invoice invoice = invoicePayment.getInvoice();
    PaymentMode paymentMode = invoicePayment.getPaymentMode();
    if (paymentMode == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_PAYMENT_MODE_MISSING), invoice.getInvoiceId());
    }
    int typeSelect = paymentMode.getTypeSelect();
    int inOutSelect = paymentMode.getInOutSelect();
    if ((typeSelect == PaymentModeRepository.TYPE_DD && inOutSelect == PaymentModeRepository.IN) || (typeSelect == PaymentModeRepository.TYPE_TRANSFER && inOutSelect == PaymentModeRepository.OUT) && paymentMode.getGenerateBankOrder()) {
        invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_PENDING);
    } else {
        invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) PaymentMode(com.axelor.apps.account.db.PaymentMode)

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