From 7d8b369ba4066d485e5aa7739b1b073f0db80b45 Mon Sep 17 00:00:00 2001
From: Paul Poulain
Date: Tue, 15 Dec 2009 19:55:58 +0100
Subject: [PATCH] Improved guided reports (#3929)
added runtime parameters for guided reports. Online help:
Can I have run-time defined parameters?
Yes, you can: there is a specific syntax that Koha will understand as 'ask for values when running the report'. The syntax is <<Question to ask|authorised_value>>.
The << and >> are just delimiters. You must put << at the beginning and >> at the end of your parameter
The Question to ask will be displayed on the left of the string to enter.
The authorised_value can be omitted if not applicable. If it contains an authorised value category, or branches or itemtype or categorycode, a list with the Koha authorised values will be displayed instead of a free field
Note that you can have more than one parameter in a given SQL
Note that entering nothing at run time won't probably work as you expect. It will be considered as "value empty" not as "ignore this parameter". For example entering nothing for : "title=<<Enter title>>" will display results with title='' (no title). If you want to have to have something not mandatory, use "title like <<Enter title>>" and enter a % at run time instead of nothing
Sample :
SELECT surname,firstname FROM borrowers WHERE branchcode=<<Enter patrons library|branches>> AND surname like <<Enter filter for patron surname (% if none)>>
---
C4/Reports/Guided.pm | 25 ++-
.../modules/help/reports/guided_reports.tmpl | 14 +-
.../modules/reports/guided_reports_start.tmpl | 20 ++-
reports/guided_reports.pl | 155 +++++++++++++++---
4 files changed, 179 insertions(+), 35 deletions(-)
diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm
index 0c969e3253..d8277b7e31 100644
--- a/C4/Reports/Guided.pm
+++ b/C4/Reports/Guided.pm
@@ -75,17 +75,27 @@ $keys{'5'} = ['borrowers.borrowernumber=accountlines.borrowernumber'];
# have to do someting here to know if its dropdown, free text, date etc
our %criteria;
+# reports on circulation
$criteria{'1'} = [
'statistics.type', 'borrowers.categorycode',
'statistics.branch',
'biblioitems.publicationyear|date',
'items.dateaccessioned|date'
];
+# reports on catalogue
$criteria{'2'} =
- [ 'items.itemnumber|textrange', 'items.biblionumber|textrange', 'items.barcode|textrange', 'biblio.frameworkcode', 'items.holdingbranch', 'items.homebranch', 'biblio.datecreated|daterange', 'biblio.timestamp|daterange', 'items.onloan|daterange', 'items.ccode', 'items.itemcallnumber|textrange', 'items.itemlost', 'items.location' ];
-$criteria{'3'} = ['borrowers.branchcode'];
+ [ 'items.itemnumber|textrange', 'items.biblionumber|textrange', 'items.barcode|textrange',
+ 'biblio.frameworkcode', 'items.holdingbranch', 'items.homebranch',
+ 'biblio.datecreated|daterange', 'biblio.timestamp|daterange', 'items.onloan|daterange',
+ 'items.ccode', 'items.itemcallnumber|textrange', 'items.itype',
+ 'items.itemlost', 'items.location' ];
+# reports on borrowers
+$criteria{'3'} = ['borrowers.branchcode', 'borrowers.categorycode'];
+# reports on acquisition
$criteria{'4'} = ['aqorders.datereceived|date'];
-$criteria{'5'} = ['borrowers.branchcode'];
+
+# reports on accounting
+$criteria{'5'} = ['borrowers.branchcode', 'borrowers.categorycode'];
# Adds itemtypes to criteria, according to the syspref
if (C4::Context->preference('item-level_itypes')) {
@@ -245,7 +255,6 @@ sub _build_query {
my $dbh = C4::Context->dbh();
my $joinedtables = join( ',', @$tables );
my $joinedcolumns = join( ',', @$columns );
- my $joinedkeys = join( ' AND ', @$keys );
my $query =
"SELECT $totals $joinedcolumns FROM $tables->[0] ";
for (my $i=1;$i<@$tables;$i++){
@@ -342,6 +351,14 @@ sub get_criteria {
my $sth = $dbh->prepare($query);
$sth->execute();
my @values;
+ # push the runtime choosing option
+ my $list;
+ $list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch';
+ $list='categorycode' if $column eq 'categorycode';
+ $list='itemtype' if $column eq 'itype';
+ $list='ccode' if $column eq 'ccode';
+ # TODO : improve to let the librarian choose the description at runtime
+ push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" };
while ( my $row = $sth->fetchrow_hashref() ) {
push @values, $row;
if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 };
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/reports/guided_reports.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/help/reports/guided_reports.tmpl
index 63bf22e868..b6c7b3e1fb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/reports/guided_reports.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/reports/guided_reports.tmpl
@@ -52,5 +52,17 @@
Yes, you can: there is a specific syntax that Koha will understand as 'ask for values when running the report'. The syntax is <<Question to ask|authorised_value>>.
+
+
The << and >> are just delimiters. You must put << at the beginning and >> at the end of your parameter
+
The Question to ask will be displayed on the left of the string to enter.
+
The authorised_value can be omitted if not applicable. If it contains an authorised value category, or branches or itemtype or categorycode, a list with the Koha authorised values will be displayed instead of a free field
+
+
Note that you can have more than one parameter in a given SQL
+
Note that entering nothing at run time won't probably work as you expect. It will be considered as "value empty" not as "ignore this parameter". For example entering nothing for : "title=<<Enter title>>" will display results with title='' (no title). If you want to have to have something not mandatory, use "title like <<Enter title>>" and enter a % at run time instead of nothing
+
Sample :
+
SELECT surname,firstname FROM borrowers WHERE branchcode=<<Enter patrons library|branches>> AND surname like <<Enter filter for patron surname (% if none)>>