Bug 6679 Followup for acqui/histsearch.pl
[koha.git] / acqui / histsearch.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Parts copyright 2011 Catalyst IT Ltd.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20
21 =head1 NAME
22
23 histsearch.pl
24
25 =head1 DESCRIPTION
26
27 this script offer a interface to search among order.
28
29 =head1 CGI PARAMETERS
30
31 =over 4
32
33 =item title
34 if the script has to filter the results on title.
35
36 =item author
37 if the script has to filter the results on author.
38
39 =item name
40 if the script has to filter the results on supplier.
41
42 =item fromplacedon
43 to filter on started date.
44
45 =item toplacedon
46 to filter on ended date.
47
48 =back
49
50 =cut
51
52 use strict;
53 #use warnings; FIXME - Bug 2505
54 use CGI;
55 use C4::Auth;    # get_template_and_user
56 use C4::Output;
57 use C4::Acquisition;
58 use C4::Dates;
59 use C4::Debug;
60
61 my $input = new CGI;
62 my $title                   = $input->param( 'title');
63 my $author                  = $input->param('author');
64 my $name                    = $input->param( 'name' );
65 my $basket                  = $input->param( 'basket' );
66 my $booksellerinvoicenumber = $input->param( 'booksellerinvoicenumber' );
67 my $from_placed_on          = $input->param('from');
68 $from_placed_on             = C4::Dates->new($from_placed_on) if $from_placed_on;
69 my $to_placed_on            = $input->param('to');
70 $to_placed_on               = C4::Dates->new($to_placed_on) if $to_placed_on;
71
72 my $dbh = C4::Context->dbh;
73 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74     {
75         template_name   => "acqui/histsearch.tmpl",
76         query           => $input,
77         type            => "intranet",
78         authnotrequired => 0,
79         flagsrequired   => { acquisition => 1 },
80         debug           => 1,
81     }
82 );
83
84 my ( $from_iso, $to_iso, $d );
85 if ( $d = $input->param('from') ) {
86     $from_iso = C4::Dates->new($d)->output('iso');
87 }
88 if ( $d = $input->param('iso') ) {
89     $to_iso = C4::Dates->new($d)->output('iso');
90 }
91
92 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived );
93 # If we're supplied any value then we do a search. Otherwise we don't.
94 my $do_search = $title || $author || $name || $basket || $booksellerinvoicenumber ||
95     $from_placed_on || $to_placed_on;
96 if ($do_search) {
97     ( $order_loop, $total_qty, $total_price, $total_qtyreceived ) = GetHistory(
98         title => $title,
99         author => $author,
100         name => $name,
101         from_placed_on => $from_iso,
102         to_placed_on => $to_iso,
103         basket => $basket,
104         booksellerinvoicenumber => $booksellerinvoicenumber,
105     );
106 }
107
108 my $from_date = $from_placed_on ? $from_placed_on->output('syspref') : undef;
109 my $to_date = $to_placed_on ? $to_placed_on->output('syspref') : undef;
110
111 $template->param(
112     suggestions_loop        => $order_loop,
113     total_qty               => $total_qty,
114     total_qtyreceived       => $total_qtyreceived,
115     total_price             => sprintf( "%.2f", $total_price ),
116     numresults              => $order_loop ? scalar(@$order_loop) : undef,
117     title                   => $title,
118     author                  => $author,
119     name                    => $name,
120     basket                  => $basket,
121     booksellerinvoicenumber => $booksellerinvoicenumber,
122     from_placed_on          => $from_date,
123     to_placed_on            => $to_date,
124     DHTMLcalendar_dateformat=> C4::Dates->DHTMLcalendar(),
125         dateformat              => C4::Dates->new()->format(),
126     debug                   => $debug || $input->param('debug') || 0,
127 );
128
129 output_html_with_http_headers $input, $cookie, $template->output;