purchaseOrderTotal = purchaseOrderTotal.plus(purchaseOrderItem.getPriceSubtotal());
taxTotal = taxTotal.plus(purchaseOrderItem.getTaxSubtotal());
}
// Create top-level resource
Representation purchaseOrderRepresentation = new DefaultRepresentationFactory()
.newRepresentation(basePath)
// Do not reveal the supplier to non-admins
.withLink("supplier","/supplier")
.withProperty("currency_symbol", currencySymbol)
.withProperty("currency_code", currencyCode)
.withProperty("price_total", purchaseOrderTotal.getAmount().toPlainString())
.withProperty("tax_total", taxTotal.getAmount().toPlainString())
.withProperty("item_total", purchaseOrder.getItemTotal())
.withProperty("quantity_total", purchaseOrder.getQuantityTotal())
// End of build
;
// Create sub-resources based on items
for (PurchaseOrderItem purchaseOrderItem : purchaseOrder.getPurchaseOrderItems()) {
Representation publicPurchaseOrderItemRepresentation = supplierPurchaseOrderItemRepresentation.get(purchaseOrderItem);
purchaseOrderRepresentation.withRepresentation("purchaseOrderItems", publicPurchaseOrderItemRepresentation);
}
return purchaseOrderRepresentation;
}