Revert "Bug 7143 - Bug for tracking changes to the about page"
[koha.git] / acqui / histsearch.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2004 Biblibre
6 # Parts copyright 2011 Catalyst IT Ltd.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 qw ( -utf8 );
55 use C4::Auth;    # get_template_and_user
56 use C4::Output;
57 use C4::Acquisition;
58 use C4::Debug;
59 use C4::Branch;
60 use C4::Koha;
61 use Koha::DateUtils;
62
63 my $input = new CGI;
64 my $title                   = $input->param( 'title');
65 my $author                  = $input->param('author');
66 my $isbn                    = $input->param('isbn');
67 my $name                    = $input->param( 'name' );
68 my $ean                     = $input->param('ean');
69 my $basket                  = $input->param( 'basket' );
70 my $basketgroupname             = $input->param('basketgroupname');
71 my $booksellerinvoicenumber = $input->param( 'booksellerinvoicenumber' );
72 my $do_search               = $input->param('do_search') || 0;
73 my $budget                  = $input->param( 'budget' );
74 my $orderstatus             = $input->param( 'orderstatus' );
75 my $ordernumber             = $input->param( 'ordernumber' );
76 my $search_children_too     = $input->param( 'search_children_too' );
77 my @created_by              = $input->multi_param('created_by');
78
79 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
80 my $to_placed_on   = eval { dt_from_string( scalar $input->param('to')   ) } || dt_from_string;
81 unless ( $input->param('from') ) {
82     # Fill the form with year-1
83     $from_placed_on->subtract( years => 1 );
84 }
85
86 my $dbh = C4::Context->dbh;
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
88     {
89         template_name   => "acqui/histsearch.tt",
90         query           => $input,
91         type            => "intranet",
92         authnotrequired => 0,
93         flagsrequired   => { acquisition => '*' },
94         debug           => 1,
95     }
96 );
97
98 my $order_loop;
99 # If we're supplied any value then we do a search. Otherwise we don't.
100 if ($do_search) {
101     $order_loop = GetHistory(
102         title => $title,
103         author => $author,
104         isbn   => $isbn,
105         ean   => $ean,
106         name => $name,
107         from_placed_on => output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
108         to_placed_on   => output_pref( { dt => $to_placed_on,   dateformat => 'iso', dateonly => 1 } ),
109         basket => $basket,
110         booksellerinvoicenumber => $booksellerinvoicenumber,
111         basketgroupname => $basketgroupname,
112         budget => $budget,
113         orderstatus => $orderstatus,
114         ordernumber => $ordernumber,
115         search_children_too => $search_children_too,
116         created_by => \@created_by,
117     );
118 }
119
120 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
121 my $bp_loop = $budgetperiods;
122 for my $bp ( @{$budgetperiods} ) {
123     my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
124     for my $budget ( @{$hierarchy} ) {
125         $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
126     }
127     $$bp{hierarchy} = $hierarchy;
128 }
129
130 $template->param(
131     order_loop              => $order_loop,
132     numresults              => $order_loop ? scalar(@$order_loop) : undef,
133     title                   => $title,
134     author                  => $author,
135     isbn                    => $isbn,
136     ean                     => $ean,
137     name                    => $name,
138     basket                  => $basket,
139     booksellerinvoicenumber => $booksellerinvoicenumber,
140     basketgroupname         => $basketgroupname,
141     ordernumber             => $ordernumber,
142     search_children_too     => $search_children_too,
143     from_placed_on          => $from_placed_on,
144     to_placed_on            => $to_placed_on,
145     orderstatus             => $orderstatus,
146     budget_id               => $budget,
147     bp_loop                 => $bp_loop,
148     search_done             => $do_search,
149     debug                   => $debug || $input->param('debug') || 0,
150     uc(C4::Context->preference("marcflavour")) => 1
151 );
152
153 output_html_with_http_headers $input, $cookie, $template->output;