LUA example: Create a script report

In this example we’ll create a small script report to see how this system works.

First, add a new report from the options, select the script type and click Set to open the editor. When you add the new report, remember to set all the parameters so it displays correctly.

--create the basic filter interface

filtertable.clear()

 

filtertable.addcategoryrow("Date")

filtertable.adddaterow("INIZIO","Start")

filtertable.adddaterow("FINE","End")

filtertable.addsubtablerow("CLIENTE","Customer","clienti","")

 

--create the actual report grid

reporttable.clearcolumns()

reporttable.clearrows()

reporttable.adddatecolumn("data","Date",150,true)

reporttable.addtextcolumn("cliente","Customer",200,true)

First, in the interface script, we add all the commands that create the search filters and the columns used to show the data.

The following lines go in the processing script instead. While the interface script runs only once, the processing script runs every time we click the Process button.

datainizio = filtertable.getvalue("INIZIO")

datafine = filtertable.getvalue("FINE")

 

--run a basic search on a date range

igiorno = tostring(utility.dateday(datainizio))

imese = tostring(utility.datemonth(datainizio))

ianno = tostring(utility.dateyear(datainizio))

 

fgiorno = utility.dateday(datafine)

fmese = utility.datemonth(datafine)

fanno = utility.dateyear(datafine)

First I get the date values from the filter table and prepare them for use in the search.


stringasql = "SELECT * FROM fatture WHERE eli=0 AND year(data) >=" .. ianno .. " AND month(data) >=" .. imese .. " AND day(data) >=" .. igiorno

stringasql = stringasql .. " AND year(data) <=" .. fanno .. " AND month(data) <=" .. fmese .. " AND day(data) <=" .. fgiorno

 

--get the remaining filters

rigacliente = filtertable.getvalue("CLIENTE")

if rigacliente ~= nil then

stringasql = stringasql .. " AND gguid_nominativo='" .. rigacliente.getvalue("gguid") .. "'"

end

We prepare the SQL string for the search, checking whether a customer has been selected in the filter table. If so, we add it to the SQL search string.


reporttable.clearrows()

tabella = database.getsql(stringasql)

righe = tabella.getrows()

for i = 1,tabella.countrows() do

--output.print(righe[i].getvalue("data"))

riga = reporttable.adddatarow()

riga.setvalue("data",righe[i].getvalue("data"))

riga.setvalue("cliente",righe[i].getvalue("nominativo"))

end

We run the search and start filling the report table with the values found.