private Document document() throws HttpException {
Document doc = MonadUtils.newSourceDocument();
Element source = doc.getDocumentElement();
Element billsElement = toXml(doc);
source.appendChild(billsElement);
billsElement.appendChild(batch.toXml(doc, new XmlTree("contract",
new XmlTree("party"))));
for (Bill bill : (List<Bill>) Hiber
.session()
.createQuery(
"from Bill bill where bill.batch = :batch order by bill.reference, bill.startDate.date")
.setEntity("batch", batch).list()) {
billsElement.appendChild(bill.toXml(doc,
new XmlTree("supply").put("type")));
}
for (BillType type : (List<BillType>) Hiber.session()
.createQuery("from BillType type order by type.code").list()) {
source.appendChild(type.toXml(doc));
}