Search in sources :

Example 66 with Invoice

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

the class ClientViewController method showClientMyRefund.

public void showClientMyRefund(ActionRequest request, ActionResponse response) {
    try {
        ClientViewService clientViewService = Beans.get(ClientViewService.class);
        User clientUser = clientViewService.getClientUser();
        if (clientUser.getPartner() == null) {
            response.setError(I18n.get(ITranslation.CLIENT_PORTAL_NO_PARTNER));
        } else {
            Filter filter = clientViewService.getRefundOfUser(clientUser).get(0);
            if (filter != null) {
                response.setView(ActionView.define(I18n.get("My refund")).model(Invoice.class.getName()).add("grid", "invoice-refund-grid").add("form", "invoice-form").param("search-filters", "customer-refunds-filters").domain(filter.getQuery()).map());
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ClientViewService(com.axelor.apps.portal.service.ClientViewService) User(com.axelor.auth.db.User) Invoice(com.axelor.apps.account.db.Invoice) Filter(com.axelor.rpc.filter.Filter)

Example 67 with Invoice

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

the class ClientViewController method showClientMyTotalRemaining.

public void showClientMyTotalRemaining(ActionRequest request, ActionResponse response) {
    try {
        ClientViewService clientViewService = Beans.get(ClientViewService.class);
        User clientUser = clientViewService.getClientUser();
        if (clientUser.getPartner() == null) {
            response.setError(I18n.get(ITranslation.CLIENT_PORTAL_NO_PARTNER));
        } else {
            Filter filter = clientViewService.getTotalRemainingOfUser(clientUser).get(0);
            if (filter != null) {
                response.setView(ActionView.define(I18n.get("Total remaining")).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").domain(filter.getQuery()).map());
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ClientViewService(com.axelor.apps.portal.service.ClientViewService) User(com.axelor.auth.db.User) Invoice(com.axelor.apps.account.db.Invoice) Filter(com.axelor.rpc.filter.Filter)

Example 68 with Invoice

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

the class InvoiceGeneratorContract method createInvoiceHeader.

@Override
protected Invoice createInvoiceHeader() throws AxelorException {
    Invoice invoice = super.createInvoiceHeader();
    ContractVersion version = contract.getCurrentContractVersion();
    if (contract.getIsInvoicingManagement() && version.getIsPeriodicInvoicing()) {
        invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_PERIODIC_INVOICE);
        invoice.setSubscriptionFromDate(contract.getInvoicePeriodStartDate());
        invoice.setSubscriptionToDate(contract.getInvoicePeriodEndDate());
    } else if (contract.getEndDate() == null || contract.getEndDate().isAfter(appBaseService.getTodayDate(company))) {
        invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_INVOICE);
    } else {
        invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_CLOSING_INVOICE);
    }
    invoice.setContract(contract);
    if (contract.getInvoicingDate() != null) {
        invoice.setInvoiceDate(contract.getInvoicingDate());
    } else {
        invoice.setInvoiceDate(appBaseService.getTodayDate(company));
    }
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Example 69 with Invoice

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

the class StockMoveInvoiceController method generateInvoiceConcatInStockMoveCheckMissingFields.

/**
 * Called from mass invoicing out stock move form view. Call method to check for missing fields.
 * If there are missing fields, show a wizard. Else call {@link
 * StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
 * generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatInStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        List<Long> stockMoveIdList = new ArrayList<>();
        List<Map> stockMoveMap = (List<Map>) request.getContext().get("supplierStockMoveToInvoice");
        for (Map map : stockMoveMap) {
            stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
        }
        for (Long stockMoveId : stockMoveIdList) {
            stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
        }
        Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateSupplierInvoice(stockMoveList);
        boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
        boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
        boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
        Partner partner = stockMoveList.get(0).getPartner();
        if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
            ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-suppl-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
            if (paymentConditionToCheck) {
                confirmView.context("contextPaymentConditionToCheck", "true");
            } else {
                confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
            }
            if (paymentModeToCheck) {
                confirmView.context("contextPaymentModeToCheck", "true");
            } else {
                confirmView.context("paymentMode", mapResult.get("paymentMode"));
            }
            if (contactPartnerToCheck) {
                confirmView.context("contextContactPartnerToCheck", "true");
                confirmView.context("contextPartnerId", partner.getId().toString());
            } else {
                confirmView.context("contactPartner", mapResult.get("contactPartner"));
            }
            confirmView.context("supplierStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
            response.setView(confirmView.map());
        } else {
            Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList);
            invoice.ifPresent(inv -> response.setView(ActionView.define("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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        }
    } 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) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner)

Example 70 with Invoice

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

the class StockMoveInvoiceController method generateInvoiceConcatInStockMove.

/**
 * Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
 * call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiIncomingStockMove(List,
 * PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatInStockMove(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        String stockMoveListStr = (String) request.getContext().get("supplierStockMoveToInvoice");
        for (String stockMoveId : stockMoveListStr.split(",")) {
            stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
        }
        PaymentCondition paymentCondition = null;
        PaymentMode paymentMode = null;
        Partner contactPartner = null;
        if (request.getContext().get("paymentCondition") != null) {
            paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
        }
        if (request.getContext().get("paymentMode") != null) {
            paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
        }
        if (request.getContext().get("contactPartner") != null) {
            contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
        }
        Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
        invoice.ifPresent(inv -> response.setView(ActionView.define("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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) 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) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) 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