'Request Form
@param r: the S3Request instance
@param attr: controller attributes'

def request_form(self, r, **attr):

    T = current.T
    s3db = current.s3db
    resource = s3db.resource(r.tablename, id=r.id, components=['req_item'])
    header_fields = ['req_ref', 'date', 'date_required', (T('Deliver    to'), 'site_id'), (T('Reason    for    Request'), 'purpose'), 'requester_id', 'site_id$site_id:inv_warehouse.contact', 'comments']
    header_data = resource.select(header_fields, start=0, limit=1, represent=True, show_links=False, raw_data=True)
    if (not header_data):
        r.error(404, current.ERROR.BAD_RECORD)
    pdf_header = self.request_form_header(header_data)
    header_row = header_data.rows[0]
    pdf_filename = header_row['_row']['req_req.req_ref']
    component = resource.components['req_item']
    body_fields = ['item_id', 'item_pack_id', 'quantity', 'comments']
    aggregate = [('sum', 'req_req_item.quantity')]
    json_data = self._json_data(component, body_fields, aggregate=aggregate)
    from s3 import S3GroupedItemsTable
    output = S3GroupedItemsTable(component, data=json_data, totals_label=T('Total'), title=T('Logistics    Requisition'), pdf_header=pdf_header, pdf_footer=self.request_form_footer)
    return output.pdf(r, filename=pdf_filename)
