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