Search in sources :

Example 26 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderProjectController method fillProject.

public void fillProject(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        if (saleOrder.getSaleOrderLineList() == null || (saleOrder.getSaleOrderLineList() != null && saleOrder.getSaleOrderLineList().isEmpty())) {
            response.setAlert(I18n.get(IExceptionMessage.SALE_ORDER_GENERATE_FILL_PROJECT_ERROR_2));
            return;
        }
        String generatorType = (String) request.getContext().get("_projectGeneratorType");
        LocalDateTime startDate = getElementStartDate(request.getContext());
        ProjectGeneratorFactory factory = ProjectGeneratorFactory.getFactory(ProjectGeneratorType.valueOf(generatorType));
        ActionViewBuilder view = factory.fill(saleOrder.getProject(), saleOrder, startDate);
        response.setReload(true);
        response.setView(view.map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
        response.setReload(true);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ProjectGeneratorFactory(com.axelor.apps.businessproject.service.projectgenerator.ProjectGeneratorFactory) SaleOrder(com.axelor.apps.sale.db.SaleOrder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 27 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderProjectController method generateProject.

public void generateProject(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        if (saleOrder.getSaleOrderLineList() == null || saleOrder.getSaleOrderLineList().isEmpty()) {
            response.setAlert(I18n.get(IExceptionMessage.SALE_ORDER_GENERATE_FILL_PROJECT_ERROR_2));
            return;
        }
        String generatorType = (String) request.getContext().get("_projectGeneratorType");
        LocalDateTime startDate = getElementStartDate(request.getContext());
        ProjectGeneratorType projectGeneratorType = ProjectGeneratorType.valueOf(generatorType);
        ProjectGeneratorFactory factory = ProjectGeneratorFactory.getFactory(projectGeneratorType);
        Project project;
        if (projectGeneratorType.equals(ProjectGeneratorType.PROJECT_ALONE)) {
            project = factory.create(saleOrder);
        } else {
            project = factory.generate(saleOrder, startDate);
        }
        response.setReload(true);
        response.setView(ActionView.define("Project").model(Project.class.getName()).add("form", "project-form").param("forceEdit", "true").context(CONTEXT_SHOW_RECORD, String.valueOf(project.getId())).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
        response.setReload(true);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ProjectGeneratorFactory(com.axelor.apps.businessproject.service.projectgenerator.ProjectGeneratorFactory) Project(com.axelor.apps.project.db.Project) ProjectGeneratorType(com.axelor.apps.project.db.ProjectGeneratorType) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 28 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class ClientViewServiceImpl method getLastOrderIndicator.

protected String getLastOrderIndicator(User user) {
    List<Filter> filters = getLastOrderOfUser(user);
    SaleOrder saleOrder = Filter.and(filters).build(SaleOrder.class).order("-confirmationDateTime").fetchOne();
    if (saleOrder == null) {
        return I18n.get(CLIENT_PORTAL_NO_DATE);
    }
    return saleOrder.getConfirmationDateTime() != null ? saleOrder.getConfirmationDateTime().format(DATE_FORMATTER) : I18n.get(CLIENT_PORTAL_NO_DATE);
}
Also used : Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 29 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class ForecastRecapServiceImpl method getOrderAmount.

protected BigDecimal getOrderAmount(ForecastRecap forecastRecap, ForecastRecapLineType forecastRecapLineType, Model forecastModel) {
    BigDecimal sumAmountInvoices;
    BigDecimal orderTotal;
    int operationTypeRefund;
    int operationTypeInvoice;
    if (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER) {
        operationTypeRefund = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
        operationTypeInvoice = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
        SaleOrder saleOrder = (SaleOrder) forecastModel;
        orderTotal = saleOrder.getInTaxTotal();
    } else {
        operationTypeRefund = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
        operationTypeInvoice = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
        PurchaseOrder purchaseOrder = (PurchaseOrder) forecastModel;
        orderTotal = purchaseOrder.getInTaxTotal();
    }
    TypedQuery<BigDecimal> sumAmountInvoiceQuery = JPA.em().createQuery("SELECT SUM(CASE WHEN operationTypeSelect = :operationTypeInvoice " + "THEN invoice.inTaxTotal " + "ELSE (invoice.inTaxTotal * -1) " + "END) " + "FROM Invoice invoice " + "WHERE ((invoice.statusSelect IN (:invoiceStatusSelect) " + "AND operationTypeSelect = :operationTypeInvoice) " + "OR (invoice.statusSelect IN (:refundStatusSelect) " + "AND operationTypeSelect = :operationTypeRefund )) " + (forecastRecapLineType.getElementSelect() == ForecastRecapLineTypeRepository.ELEMENT_SALE_ORDER ? "AND invoice.saleOrder.id = :orderId" : "AND invoice.purchaseOrder.id = :orderId"), BigDecimal.class).setParameter("orderId", forecastModel.getId()).setParameter("operationTypeInvoice", operationTypeInvoice).setParameter("invoiceStatusSelect", invoiceStatusMap.get(operationTypeInvoice)).setParameter("operationTypeRefund", operationTypeRefund).setParameter("refundStatusSelect", invoiceStatusMap.get(operationTypeRefund));
    sumAmountInvoices = Optional.ofNullable(sumAmountInvoiceQuery.getSingleResult()).orElse(BigDecimal.ZERO);
    return orderTotal.subtract(sumAmountInvoices);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 30 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class ProjectController method generateQuotation.

public void generateQuotation(ActionRequest request, ActionResponse response) {
    try {
        Project project = request.getContext().asType(Project.class);
        SaleOrder order = Beans.get(ProjectBusinessService.class).generateQuotation(project);
        response.setView(ActionView.define(I18n.get("Sale quotation")).model(SaleOrder.class.getName()).add("form", "sale-order-form").param("forceTitle", "true").context("_showRecord", String.valueOf(order.getId())).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : InvoicingProject(com.axelor.apps.businessproject.db.InvoicingProject) Project(com.axelor.apps.project.db.Project) ProjectBusinessService(com.axelor.apps.businessproject.service.ProjectBusinessService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)129 AxelorException (com.axelor.exception.AxelorException)53 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)35 BigDecimal (java.math.BigDecimal)24 Context (com.axelor.rpc.Context)20 Transactional (com.google.inject.persist.Transactional)19 ArrayList (java.util.ArrayList)19 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)18 Company (com.axelor.apps.base.db.Company)16 Partner (com.axelor.apps.base.db.Partner)15 IOException (java.io.IOException)13 BirtException (org.eclipse.birt.core.exception.BirtException)13 Invoice (com.axelor.apps.account.db.Invoice)12 List (java.util.List)12 Currency (com.axelor.apps.base.db.Currency)11 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 Product (com.axelor.apps.base.db.Product)8 StockMove (com.axelor.apps.stock.db.StockMove)8