Nervatura Report

Python and Javascript version
Ver.No: {{=response.verNo}}

  1. Function Overview
  2. Object Overview
  3. Function Details
  4. Object Properties
  5. Deploying Report Templates


1. Function Overview

Name Restriction Return type Parameters
Report Object orientation, unit, format
loadDefinition Boolean xml
loadJsonDefinition Javascript
Boolean data
setData Boolean key, value
createReport Boolean
save2Html Python
HTML details
save2Pdf PDF
save2PdfFile PDF filename
save2DataUrl Javascript
PDF
save2Xml XML
getXmlTemplate Javascript
XML
insertElement Object parent, ename, index, values
editElement Boolean element, values
deleteElement Boolean element, parent

2. Object Overview

Name Properties
report orientation, unit, format, template, images_folder, decode, encode
template document, style, margins, elements
row height, hgap, visible, columns
cell name, value, width, border, align, multiline, link, font-family, font-style, font-size, color, border-color, background-color
image src, file, link, width, height, compression
barcode code-type, value, visible-value, wide, narrow
separator gap
vgap height
hline width, gap
html
datagrid width, name, databind, merge, border, color, border-color, background-color, header-color, footer-color, font-size, columns
column fieldname, width, label, align, thousands, digit, footer, header-align, footer-align

3. Function Details

Report(orientation::String='P', unit::String='mm', format::String='A4')::Object

Class constructor.
orientation: 'P','portrait','L','landscape'
unit: 'pt','mm','cm','in'
format: 'A3','A4','A5','letter','legal'

The result value is an report object.

loadDefinition(xml::String)::Boolean

Load to the report an XML definition.
xml: valid XML string

True if the load successfully.

loadJsonDefinition(data::String/Object)::Boolean

Load to the report an JSON definition.
data: valid JSON string or object

True if the load successfully. Only Javascript!

setData(key::String, value::String/Object/List)::Boolean

Set the template data.

key: dictonary/object key
value:
  • dictonary in list (table) -> table.row.fieldname Example: customer.0.custnumber
  • dictonary -> key.fieldname Example: labels.custnumber
  • simple string
  • special values: page and pages (Python)

True if the load successfully.

createReport::Boolean

The report template processing, databind replacement.

True if the load successfully.

save2Html(details::Boolean)::HTML

Show an HTML Preview.
details: only details section, no page header and footer

HTML string Only Python!

save2Pdf::PDF

Create a PDF output.

PDF file

save2PdfFile(filename::String)::PDF

Save to the PDF file.
filename: full filename and path (Python) or filename (Javascript)

PDF file

save2DataUrl::PDF

Create a PDF data to the new browser window.

PDF file Only Javascript!

save2Xml::XML

Create an XML output. Only the values of cells and datagrid rows from header and details. The node name of the cell name (except when name="label"), or datagrid name/column fieldname.

XML file

getXmlTemplate::XML

Create the current XML template (without data).Create the current XML template (without data).

XML file Only Javascript!

insertElement(parent::Object, ename::String='row', index::Integer=-1, values::Object={})::Object

Inserts an element in the template.
parent: The parent object
ename: An element type: 'row', 'datagrid', 'vgap', 'hline', 'html', 'column', 'cell', 'image', 'separator', 'barcode'
index: Optional. Default: the last child object
values: Optional. Object attributes. Example: {border: 'LBR', 'border-color': 218}.

The result value is an element object.

Examples:

Python:
rpt = Report()
details = rpt.report["elements"]["details"]
rpt.insertElement(details, "vgap", -1, {"height": 2})
row_data = rpt.insertElement(details, "row")
rpt.insertElement(row_data, "cell",-1,{"name": "label", "width": "50%", "font-style": "bold", "value": "labels.left_text", "border": "LT", "border-color": 218, "background-color": 245})

Javascript:
var rpt = new report();
var details = rpt.report.elements.details;
rpt.insertElement(details, "vgap", -1, {height: 2});
row_data = rpt.insertElement(details, "row");
rpt.insertElement(row_data, "cell",-1,{name: "label", width: "50%", "font-style": "bold", value: "labels.left_text", border: "LT", "border-color": 218, "background-color": 245});

editElement(element::Object, values::Object={})::Boolean

Edit an item from the template.
element: The element object
values: Optional. Object attributes. Example: {border: 'LBR', 'border-color': 218}.

True if the successfully.

deleteElement(element::Object, parent::Object=None)::Boolean

Delete an item from the template.
element: The element object
parent: Optional(recommended).

True if the successfully.

4. Object Properties

report{orientation::String='P', unit::String='mm', format::String='A4', template::Object, images_folder::String=None, decode::String='utf-8', encode::String='latin_1'}
orientation: 'P','portrait','L','landscape'
unit: 'pt','mm','cm','in'
format: 'A3','A4','A5','letter','legal'
template
images_folder: Deprecated! Only Python!
decode, encode: only PDF output, default value 'utf-8' and 'latin_1' Only Python!
template{document::Object, style::Object, margins::Object, elements::Object}
document:
  • title::String='Nervatura Report'
  • author::String=''
  • creator::String=''
  • subject::String=''
  • keywords::String=''
style:
  • font-family::String: 'times' (default), 'helvetica', 'courier'
  • font-style::String: '' (default), 'bold', 'italic', 'bolditalic'
  • font-size::Integer: 12 (default)
  • color::String: value in hexadecimal (example: '#A0522D') or in decimal (example: '10506797')
  • border-color, background-color::Integer: gray color (in range from 0 'black' to 255 'white')
margins:
  • left-margin, right-margin, top-margin::Integer: 12 (default)
  • bottom-margin::Integer: 12 (default) Only Javascript!
elements:
row{height::Float=None, hgap::Integer=0, visible::String=None, columns::List=[]}
Horizontal logical group. The last element width extends up to the right margin.
height
hgap: default gap between these two elements
visible: table data source name - only if there is data
columns: cell, image, barcode, separator
cell{name::String='head', value::String='', width::String='0', border::String='0', align::String='left', multiline::String='false', link::String=None, font-family::String='times', font-style::String='', font-size::Integer=12, color::String=0, border-color::Integer=0, background-color::Integer=255}
name: XML output node name (only details section, default 'head' and except when name='label')
value: static text or databind value
width
border: 0(no border, default) and 1(frame) or some or all of the following characters: L(left); T(top); R(right); B(bottom)
align: left (default value); right; center; justify (Only multiline and Python!)
multiline: if 'true', print text with line breaks (default 'false')
link: URL Only Python!
font-family: 'times' (default), 'helvetica', 'courier'
font-style: '' (default), 'bold', 'italic', 'bolditalic'
font-size: 12 (default)
color: value in hexadecimal (example: #A0522D) or in decimal (example: 10506797)
border-color, background-color gray color (in range from 0 to 255)
image{src::String=None, file::String=None, link::String=None, width::String=None, height::Float=None, compression::String='medium'}
src: an inlined image (jpg/png), encoded in base64 (or a valid databind key)
file: path or URL of the image Only Python!
link: URL Only Python!
width
height Only Javascript!
compression: 'fast', 'medium', 'slow' Only Javascript!
barcode{code-type::String='code39', value::String='', visible-value::Integer=0, wide::Float=None, narrow::Float=None}
code-type: 'i2of5' (Interleaved 2of5) or 'code39' (Code 39)
value: barcode text
visible-value: 1 (show barcode text) or 0 (default)
wide, narrow: optional
separator{gap::Integer=0}
Vertical separator line.
gap: greater than 0 = double line
vgap{height::Float=None}
Vertical gap.
height
hline{width::String='100%', gap::Integer=0}
Horizontal line.
width: if missing or 0, then extends up to the right margin
gap: greater than 0 = double line
html
Basic HTML elements rendering. Experimental!
datagrid{width::String='100%', name::String='items', databind::String, merge::Integer=0, border::Integer=1, color::String='0', border-color::Integer=0, background-color::Integer=255, header-color::Integer=None, footer-color::Integer=None, font-size::Integer=12, columns::List=[]}
Create a table from python/javascript list (dictonary/object items).
width
name: XML output node name (only details section)
databind: table data source name
merge: 1(all fields will be displayed in a single column) or 0(default)
border: 0(no border) or 1(frame, default)
color: value in hexadecimal (example: #A0522D) or in decimal (example: 10506797)
border-color, background-color, header-background, footer-background gray color (in range from 0 to 255)
font-size
columns: column
column{fieldname::String, width::String=None, label::String=None, align::String='left', thousands::String=None, digit::Integer=None, footer::String=None, header-align::String='left', footer-align::String='left'}
fieldname: dictonary key (special value: counter)
width: value in percent
label: column caption
align, header-align, footer-align: left (default value); right; center; justify (Python!)
thousands: character, only number format
digit: number, only number format
footer: static text or databind value

5. Deploying Report Templates

Complete Examples: Genshi VAT Report, Nervatura VAT Report, Nervatura Invoice

<report reportkey, nervatype, transtype, direction, repname, description, label, filetype >
reportkey: unique report identifier
nervatype: report or customer, employee, event, place, product, project, tool, trans
transtype: invoice, receipt, order, offer, worksheet, rent, delivery, store, inventory, waybill, production, formula, bank, cash (only nervatype=trans)
direction: out, in, transfer (only nervatype=trans)
repname: report short name
description: report description
label: group label (only nervatype=report)
filetype: ntr (Nervatura Report), xls (Excel workbook), html (HTML document), gshi(Genshi template)

Examples:

<report reportkey="ntr_cash_in_en" nervatype="trans" transtype="cash" direction="in" repname="Petty Cash Voucher EN" description="Deposit Voucher" filetype="ntr">
...
</report>

<reportkey="xls_vat_en" nervatype="report" repname="VAT Summary - MS Excel" description="Recoverable and payable VAT summary grouped by currency. MS Excel output." label="Invoice" filetype="xls">
...
</report>

<dataset name, engine ><![CDATA[]]></dataset>
name: logical name
engine: empty (all) or sqlite, mysql, postgres, mssql
text: a valid SQL statement. Parameters: @fieldname (nervatype=report) or @id

Examples:

<dataset name="head" engine=""><![CDATA[select ...]]></dataset>

<dataset name="fieldvalue" engine="mysql"><![CDATA[select ...]]></dataset>

<field fieldname, fieldtype, wheretype, description, orderby, dataset, defvalue ><![CDATA[]]></field>
Only nervatype=report!

fieldname: logical name
fieldtype: bool, date, integer, float, valuelist, string
wheretype: in, where
description: label
orderby: field order by
dataset: a valid dataset name
defvalue: default parameter value
valuelist: if fieldtype=valuelist: valid values are listed, separated by |
text: a valid SQL statement. Parameters: @fieldname

Examples:

<field fieldname="date_from" fieldtype="date" wheretype="in" description="From date" orderby="0" defvalue="-360"/>

<field fieldname="customer" fieldtype="string" wheretype="where" description="Customer/Supplier" orderby="6" ><![CDATA[ custname.value like @customer]]></field>

<message secname, fieldname ><![CDATA[]]></message>
secname: report (report template) or a valid dataset name
fieldname: logical name
text: label

Examples:

<message secname="report" fieldname="transdate"><![CDATA[Invoice Date]]></message>

<message secname="head" fieldname="lb_address"><![CDATA[Address]]></message>

<template><![CDATA[]]></template>
text: report template