template for report writing.
with 2 nice reports.
pls test.
documentation of the template syntax coming soon
This commit is contained in:
tipaul 2004-03-30 16:09:04 +00:00
parent 01458df59c
commit 7c2c39dea5
6 changed files with 402 additions and 2 deletions

View file

@ -0,0 +1,50 @@
<!-- TMPL_INCLUDE NAME="reports-top.inc" -->
<div id="mainbloc">
<!-- TMPL_IF name="do_it" -->
<!-- TMPL_LOOP name="mainloop" -->
<h1>Koha : Issues by borrower category <!--TMPL_IF name="borrower_category" --> for category = <!-- TMPL_VAR name="borrower_category" --><!-- /TMPL_IF --></h1>
<table>
<tr>
<th>&nbsp;</th>
<!-- TMPL_LOOP name="categorycodeloop" -->
<th><!-- TMPL_VAR name="categorycode" --></th>
<!-- /TMPL_LOOP -->
<th>TOTAL</th>
</tr>
<!-- TMPL_LOOP name="loopborrowertype" -->
<tr>
<!-- TMPL_IF name="hilighted" --><td class="hilighted"><!-- TMPL_ELSE --><td><!-- /TMPL_IF -->
<!-- TMPL_VAR name="itemtype" --></td>
<!-- TMPL_LOOP name="loopitemtype" -->
<!-- TMPL_IF name="hilighted" --><td class="numberhilighted"><!-- TMPL_ELSE --><td class="number"><!-- /TMPL_IF -->
<!-- TMPL_VAR name="issues" -->
</td>
<!-- /TMPL_LOOP -->
<!-- TMPL_IF name="hilighted" --><td class="numberhilighted"><!-- TMPL_ELSE --><td class="number"><!-- /TMPL_IF -->
<!-- TMPL_VAR name="totalitemtype" -->
</td>
</tr>
<!-- /TMPL_LOOP name="loopitemtype" -->
<tr>
<th>TOTAL</th>
<!-- TMPL_LOOP name="loopborrowertotal" -->
<th>
<!-- TMPL_VAR name="issues" -->
</th>
<!-- /TMPL_LOOP -->
<th>&nbsp;</th>
</tr>
</table>
<!-- /TMPL_LOOP -->
<!-- TMPL_ELSE -->
<h1>Issues by borrower category</h1>
<form method="post">
<p>Select a borrower category (or don't if you want to see global status) <input type="text" name="value"></p>
<p>Select a branch : <!-- TMPL_VAR name="CGIbranch" --></p>
<input type="submit" value="OK" class="button">
<input type="hidden" name="report_name" value="<!--TMPL_VAR name="report_name" -->">
<input type="hidden" name="do_it" value="1">
</form>
<!-- /TMPL_IF -->
</div>
<!-- TMPL_INCLUDE NAME="reports-bottom.inc" -->

View file

@ -0,0 +1,32 @@
<!-- TMPL_INCLUDE NAME="reports-top.inc" -->
<div id="mainbloc">
<!-- TMPL_IF name="do_it" -->
<!-- TMPL_LOOP name="mainloop" -->
<h1>Koha : Reports on itemtypes <!--TMPL_IF name="branch" --> for branch = <!-- TMPL_VAR name="branch" --><!-- /TMPL_IF --></h1>
<table>
<tr>
<th>Item type</th>
<th>count</th>
</tr>
<!-- TMPL_LOOP name="loopitemtype" -->
<tr>
<td><!-- TMPL_VAR name="itemtype" --></td>
<td><!-- TMPL_VAR name="count" --></td>
</tr>
<!-- /TMPL_LOOP name="loopitemtype" -->
<tr>
<th>TOTAL</th>
<th><!-- TMPL_VAR name="total" --></th>
</table>
<!-- /TMPL_LOOP -->
<!-- TMPL_ELSE -->
<h1>View catalogue group by itemtypes</h1>
<form method="post">
Select a branch (or don't if you want the report for all branches) <!-- TMPL_VAR name="CGIbranch" -->
<input type="submit" value="OK" class="button">
<input type="hidden" name="report_name" value="<!--TMPL_VAR name="report_name" -->">
<input type="hidden" name="do_it" value="1">
</form>
<!-- /TMPL_IF -->
</div>
<!-- TMPL_INCLUDE NAME="reports-bottom.inc" -->

View file

@ -1,12 +1,16 @@
<!-- TMPL_INCLUDE NAME="reports-top.inc" -->
<!--------------------------MAIN BODY OF PAGE-------------------------->
<h1>Reports</h1><br/>
<div id="mainbloc">
<h1>Reports</h1>
<ul>
<li><a href="/cgi-bin/koha/stats.pl?time=yesterday">Till Reconciliation:</a> Daily Report (yesterday)</li>
<li><a href="/cgi-bin/koha/stats.pl?time=today">Till Reconciliation:</a> Daily Report (today)</li>
<li><a href="/cgi-bin/koha/overdue.pl">Overdue items</a></li>
<li><a href="/cgi-bin/koha/reports/inventory.pl">Inventory/Stocktaking</a></li>
<li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalogue by itemtype</a></li>
<li><a href="/cgi-bin/koha/reports/manager.pl?report_name=issues_by_borrower_category">Issues by borrower category</a></li>
</ul>
</div>
<!-- TMPL_INCLUDE NAME="reports-bottom.inc" -->

View file

@ -0,0 +1,170 @@
#!/usr/bin/perl
# $Id$
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use C4::Auth;
use CGI;
use C4::Context;
use HTML::Template;
use C4::Search;
use C4::Output;
use C4::Koha;
=head1 NAME
plugin that shows a table with issues for categories and borrower
=head1 DESCRIPTION
this result is quite complex to build...
the 2D array contains :
* item types on lines
* borrowers types on rows
If no issues are done, the array must be filled by 0 anyway.
So, the script works as this :
1- parse the itemtype table to get itemtype descriptions and set itemtype total to 0
2- for each borrower category :
** create an array with total = 0 for each itemtype defined in 1
** calculate the total for each itemtype (SQL request)
The big hash has the following structure :
$itemtypes{itemtype}
->{results}
->{borrowercategorycode} => the total of issues for each cell of the table.
->{total} => the total for the itemtype
->{description} => the itemtype description
the borrowertype hash contains description and total for each borrowercategory.
the hashes are then translated to hash / arrays to be returned to manager.pl & send to the template
=over2
=cut
sub set_parameters {
my ($template) = @_;
my $dbh = C4::Context->dbh;
my $branches=getbranches();
my @branches;
my @select_branch;
my %select_branches;
push @select_branch,"";
$select_branches{""} = "";
foreach my $branch (keys %$branches) {
push @select_branch, $branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
}
my $CGIbranch=CGI::scrolling_list( -name => 'value',
-id => 'value',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0 );
$template->param(CGIbranch => $CGIbranch);
return $template;
}
sub calculate {
my ($parameters) = @_;
my @results =();
# extract parameters
my $borrower_category = @$parameters[0];
my $branch = @$parameters[1];
my $dbh = C4::Context->dbh;
# build the SQL query & execute it
# 1st, loop every itemtypes.
my $sth = $dbh->prepare("select itemtype,description from itemtypes");
$sth->execute;
my %itemtypes;
while (my ($itemtype,$description) = $sth->fetchrow) {
$itemtypes{$itemtype}->{description} = $description;
$itemtypes{$itemtype}->{total} = 0;
}
# now, parse each category. Before filling the result array, fill it with 0 to have every itemtype column.
my $sth = $dbh->prepare("SELECT itemtype, count( * )
FROM issues, borrowers, biblioitems, items
WHERE issues.borrowernumber = borrowers.borrowernumber
AND items.itemnumber = issues.itemnumber
AND biblioitems.biblionumber = items.biblionumber
AND borrowers.categorycode = ?
GROUP BY biblioitems.itemtype");
my $sthcategories = $dbh->prepare("select categorycode,description from categories");
$sthcategories->execute;
my %borrowertype;
my @categorycodeloop;
while (my ($categorycode,$description) = $sthcategories->fetchrow) {
$borrowertype{$categorycode}->{description} = $description;
$borrowertype{$categorycode}->{total} = 0;
my %categorycode;
$categorycode{categorycode} = $description;
push @categorycodeloop,\%categorycode;
foreach my $itemtype (keys %itemtypes) {
$itemtypes{$itemtype}->{results}->{$categorycode} = 0;
}
$sth->execute($categorycode);
while (my ($itemtype, $total) = $sth->fetchrow) {
$itemtypes{$itemtype}->{results}->{$categorycode} = $total;
$borrowertype{$categorycode}->{total} += $total;
$itemtypes{$itemtype}->{total} += $total;
}
}
my $grantotal = 0;
# build the result
my @mainloop;
my @itemtypeloop;
my @loopborrowertype;
my %globalline;
my $hilighted=-1;
foreach my $itemtype (keys %itemtypes) {
my @loopitemtype;
foreach my $categorycode (keys %{$itemtypes{$itemtype}->{results}}) {
my %cell;
$cell{issues} = $itemtypes{$itemtype}->{results}->{$categorycode};
push @loopitemtype,\%cell;
}
my %line;
$line{loopitemtype} = \@loopitemtype;
$line{itemtype} = $itemtypes{$itemtype}->{description};
$line{hilighted} = 1 if $hilighted eq 1;
$line{totalitemtype} = $itemtypes{$itemtype}->{total};
$hilighted = -$hilighted;
push @loopborrowertype, \%line;
}
# the header of the table
$globalline{loopborrowertype} = \@loopborrowertype;
# the core of the table
$globalline{categorycodeloop} = \@categorycodeloop;
# the foot (totals by borrower type)
my @loopborrowertotal;
foreach my $categorycode (keys %borrowertype) {
my %line;
$line{issues} = $borrowertype{$categorycode}->{total};
push @loopborrowertotal, \%line;
}
$globalline{loopborrowertotal} = \@loopborrowertotal;
# $globalline{total} = $grantotal;
# $globalline{borrower_category} = $borrower_category;
push @mainloop,\%globalline;
return \@mainloop;
}
1;

92
reports/itemtypes.plugin Normal file
View file

@ -0,0 +1,92 @@
#!/usr/bin/perl
# $Id$
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use C4::Auth;
use CGI;
use C4::Context;
use HTML::Template;
use C4::Search;
use C4::Output;
use C4::Koha;
=head1
=cut
sub set_parameters {
my ($template) = @_;
my $dbh = C4::Context->dbh;
my $branches=getbranches();
my @branches;
my @select_branch;
my %select_branches;
push @select_branch,"";
$select_branches{""} = "";
foreach my $branch (keys %$branches) {
push @select_branch, $branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
}
my $CGIbranch=CGI::scrolling_list( -name => 'value',
-id => 'value',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0 );
$template->param(CGIbranch => $CGIbranch);
return $template;
}
sub calculate {
my ($parameters) = @_;
my @results =();
my $branch = @$parameters[0];
my $dbh = C4::Context->dbh;
my $sth;
if ($branch) {
$sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems, items
where biblioitems.itemtype=itemtypes.itemtype
and items.biblionumber=biblioitems.biblionumber
and items.holdingbranch=?
group by biblioitems.itemtype");
$sth->execute($branch);
} else {
$sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems where biblioitems.itemtype=itemtypes.itemtype group by biblioitems.itemtype");
$sth->execute;
}
my ($description,$biblioitems,$total);
my $grantotal = 0;
while (($description,$biblioitems,$total) = $sth->fetchrow) {
my %line;
$line{itemtype} = $description;
$line{count} = $total;
$grantotal += $total;
push @results,\%line;
}
my @mainloop;
my %globalline;
$globalline{loopitemtype} = \@results;
$globalline{total} = $grantotal;
$globalline{branch} = $branch;
push @mainloop,\%globalline;
return \@mainloop;
}
1;

52
reports/manager.pl Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
use C4::Auth;
use C4::Context;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Circulation::Circ2;
use HTML::Template;
my $input = new CGI;
my $report_name=$input->param("report_name");
my $do_it=$input->param('do_it');
my $fullreportname = "reports/".$report_name.".tmpl";
my @values = $input->param("value");
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => $fullreportname,
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {editcatalogue => 1},
debug => 1,
});
$template->param(do_it => $do_it,
report_name => $report_name);
my $plugin = "./".$report_name.".plugin";
require $plugin;
if ($do_it) {
my $results = calculate(\@values);
$template->param(mainloop => $results);
} else {
$template = set_parameters($template);
}
output_html_with_http_headers $input, $cookie, $template->output;