use of com.axelor.apps.sale.service.PartnerSaleService in project axelor-open-suite by axelor.
the class PartnerSaleController method displayValues.
public void displayValues(ActionRequest request, ActionResponse response) {
Partner customer = request.getContext().asType(Partner.class);
try {
customer = Beans.get(PartnerRepository.class).find(customer.getId());
SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
if (productList.isEmpty()) {
response.setAttr("$saleDetailsByProduct", "hidden", true);
return;
}
response.setAttr("$saleDetailsByProduct", "hidden", false);
HashMap<String, BigDecimal> qtyAndPrice;
for (Product product : productList) {
qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", product.getName());
map.put("$quantitySold", qtyAndPrice.get("qty"));
map.put("$totalPrice", qtyAndPrice.get("price"));
map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
saleDetailsByProduct.add(map);
}
response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations