this.coreManager = coreManager;
}
@Get("json")
public SgwtRestResponseBase getRepresent(){
SgwtRestFetchResponseBase resp = null;
Integer poId = RequestUtil.getInteger(getQuery().getValues("poId"));
List<PurchasingOrderDetail> details = coreManager.getPurchasingOrderDetails(poId);
List<DisplayPurchasingOrderDetail> resultList = new ArrayList<DisplayPurchasingOrderDetail>();
for (PurchasingOrderDetail purchasingOrderDetail : details) {
Stock stock = null;
ProductMeasurement productMeasurement = null;
if(purchasingOrderDetail.getProduct().getStock() != null && !purchasingOrderDetail.getProduct().getStock().isEmpty()){
stock = purchasingOrderDetail.getProduct().getStock().iterator().next();
}
if(purchasingOrderDetail.getProduct().getProductMeasurement() != null && !purchasingOrderDetail.getProduct().getProductMeasurement().isEmpty()){
productMeasurement = purchasingOrderDetail.getProduct().getProductMeasurement().iterator().next();
}
DisplayPurchasingOrderDetail det = mapper.map(purchasingOrderDetail, DisplayPurchasingOrderDetail.class);
if(stock != null){
det.getProduct().setStock(mapper.map(stock, DisplayStock.class));
}
if(productMeasurement != null){
det.getProduct().setProductMeasurement(mapper.map(productMeasurement, DisplayProductMeasurement.class));
}
if(purchasingOrderDetail.getPurchasingOrder().getStatus().equals(Status.COMPLETED)){
det.setCostPrice(purchasingOrderDetail.getCostPriceOnCompleted());
}else{
det.setCostPrice(purchasingOrderDetail.getProduct().getBuying().getCostPrice());
}
resultList.add(det);
}
resp = new SgwtRestFetchResponseBase(resultList);
return resp;
}