4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
22 # use warnings; # FIXME
28 use C4::Overdues qw/GetOverduesByBorrowers/;
29 use C4::Dates qw/format_date format_date_in_iso/;
30 use Date::Calc qw/Today/;
34 my $order = $input->param( 'order' ) || '';
35 my $showall = $input->param('showall');
37 my $bornamefilter = $input->param( 'borname');
38 my $borcatfilter = $input->param( 'borcat' );
39 my $itemtypefilter = $input->param('itemtype');
40 my $borflagsfilter = $input->param('borflags') || "";
41 my $branchfilter = $input->param( 'branch' );
42 my $op = $input->param( 'op' ) || '';
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46 template_name => "circ/overdue.tmpl",
50 flagsrequired => { reports => 1, circulate => "circulate_remaining_permissions" },
55 my $dbh = C4::Context->dbh;
58 $req = $dbh->prepare( "select categorycode, description from categories order by description");
61 while (my ($catcode, $description) =$req->fetchrow) {
64 selected => $catcode eq $borcatfilter ? 1 : 0,
65 catname => $description,
69 $req = $dbh->prepare( "select itemtype, description from itemtypes order by description");
72 while (my ($itemtype, $description) =$req->fetchrow) {
75 selected => $itemtype eq $itemtypefilter ? 1 : 0,
76 itemtypename => $description,
79 my $onlymine=C4::Context->preference('IndependantBranches') &&
80 C4::Context->userenv &&
81 C4::Context->userenv->{flags}!=1 &&
82 C4::Context->userenv->{branch};
84 $branchfilter = C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
87 branchloop => GetBranchesLoop($branchfilter, $onlymine),
88 branchfilter => $branchfilter,
89 borcatloop => \@borcatloop,
90 itemtypeloop => \@itemtypeloop,
91 borname => $bornamefilter,
94 csv_param_string => $input->query_string(),
95 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
96 dateduefrom => $input->param( 'dateduefrom' ),
97 datedueto => $input->param( 'datedueto' ),
100 my @sort_roots = qw(borrower title barcode date_due);
101 push @sort_roots, map {$_ . " desc"} @sort_roots;
102 my @order_loop = ({selected => $order ? 0 : 1}); # initial blank row
103 foreach (@sort_roots) {
105 $tmpl_name =~ s/\s/_/g;
107 selected => $order eq $_ ? 1 : 0,
110 'order_' . $tmpl_name => 1,
113 $template->param(ORDER_LOOP => \@order_loop);
115 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Today());
117 $bornamefilter =~s/\*/\%/g;
118 $bornamefilter =~s/\?/\_/g;
120 my $dateduefrom = format_date_in_iso($input->param( 'dateduefrom' ));
121 my $datedueto = format_date_in_iso($input->param( 'datedueto' ));
123 my @overduedata = @{GetOverduesByBorrowers($branchfilter, $borcatfilter, $itemtypefilter, $borflagsfilter, $bornamefilter, $order, $dateduefrom, $datedueto)};
126 todaysdate => format_date($todaysdate),
127 overdueloop => \@overduedata
130 # download the complete CSV
132 binmode(STDOUT, ":utf8");
133 my $csv = build_csv(\@overduedata);
134 print $input->header(-type => 'application/vnd.sun.xml.calc',
135 -encoding => 'utf-8',
136 -attachment=>"overdues.csv",
137 -filename=>"overdues.csv" );
142 output_html_with_http_headers $input, $cookie, $template->output;
146 my $overdues = shift;
148 return "" if scalar(@$overdues) == 0;
167 my $csv = Text::CSV_XS->new({
169 sep_char => C4::Context->preference("delimiter") ?
170 C4::Context->preference("delimiter") : ';' ,
172 $csv->combine(@keys);
173 push @lines, $csv->string();
175 # ... and rest of report
176 foreach my $overdue ( @{ $overdues } ) {
178 foreach my $issue ( @{$overdue->{overdues} }){
179 $issues .= "$issue->{title} / $issue->{author} / $issue->{itemcallnumber} / $issue->{barcode} / ".format_date($issue->{issuedate}). " - " . format_date($issue->{date_due}) . " \r\n";
181 push @lines, $csv->string() if $csv->combine(
182 $overdue->{borrowernumber},
184 $overdue->{firstname},
191 $overdue->{branchcode},
196 return join("\n", @lines) . "\n";