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);
}
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations