Bug 17403: Internal Server Error while deleting patron
[koha.git] / acqui / histsearch.pl
blob9261379493fccd46cd69961f26c4c240df852350
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2004 Biblibre
6 # Parts copyright 2011 Catalyst IT Ltd.
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.
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.
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>.
21 =head1 NAME
23 histsearch.pl
25 =head1 DESCRIPTION
27 this script offer a interface to search among order.
29 =head1 CGI PARAMETERS
31 =over 4
33 =item title
34 if the script has to filter the results on title.
36 =item author
37 if the script has to filter the results on author.
39 =item name
40 if the script has to filter the results on supplier.
42 =item fromplacedon
43 to filter on started date.
45 =item toplacedon
46 to filter on ended date.
48 =back
50 =cut
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::Koha;
60 use Koha::DateUtils;
62 my $input = new CGI;
63 my $title = $input->param( 'title');
64 my $author = $input->param('author');
65 my $isbn = $input->param('isbn');
66 my $name = $input->param( 'name' );
67 my $ean = $input->param('ean');
68 my $basket = $input->param( 'basket' );
69 my $basketgroupname = $input->param('basketgroupname');
70 my $booksellerinvoicenumber = $input->param( 'booksellerinvoicenumber' );
71 my $do_search = $input->param('do_search') || 0;
72 my $budget = $input->param( 'budget' );
73 my $orderstatus = $input->param( 'orderstatus' );
74 my $ordernumber = $input->param( 'ordernumber' );
75 my $search_children_too = $input->param( 'search_children_too' );
76 my @created_by = $input->multi_param('created_by');
78 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
79 my $to_placed_on = eval { dt_from_string( scalar $input->param('to') ) } || dt_from_string;
80 unless ( $input->param('from') ) {
81 # Fill the form with year-1
82 $from_placed_on->subtract( years => 1 );
85 my $dbh = C4::Context->dbh;
86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
88 template_name => "acqui/histsearch.tt",
89 query => $input,
90 type => "intranet",
91 authnotrequired => 0,
92 flagsrequired => { acquisition => '*' },
93 debug => 1,
97 my $order_loop;
98 # If we're supplied any value then we do a search. Otherwise we don't.
99 if ($do_search) {
100 $order_loop = GetHistory(
101 title => $title,
102 author => $author,
103 isbn => $isbn,
104 ean => $ean,
105 name => $name,
106 from_placed_on => output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
107 to_placed_on => output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
108 basket => $basket,
109 booksellerinvoicenumber => $booksellerinvoicenumber,
110 basketgroupname => $basketgroupname,
111 budget => $budget,
112 orderstatus => $orderstatus,
113 ordernumber => $ordernumber,
114 search_children_too => $search_children_too,
115 created_by => \@created_by,
119 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
120 my $bp_loop = $budgetperiods;
121 for my $bp ( @{$budgetperiods} ) {
122 my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
123 for my $budget ( @{$hierarchy} ) {
124 $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
126 $$bp{hierarchy} = $hierarchy;
129 $template->param(
130 order_loop => $order_loop,
131 numresults => $order_loop ? scalar(@$order_loop) : undef,
132 title => $title,
133 author => $author,
134 isbn => $isbn,
135 ean => $ean,
136 name => $name,
137 basket => $basket,
138 booksellerinvoicenumber => $booksellerinvoicenumber,
139 basketgroupname => $basketgroupname,
140 ordernumber => $ordernumber,
141 search_children_too => $search_children_too,
142 from_placed_on => $from_placed_on,
143 to_placed_on => $to_placed_on,
144 orderstatus => $orderstatus,
145 budget_id => $budget,
146 bp_loop => $bp_loop,
147 search_done => $do_search,
148 debug => $debug || $input->param('debug') || 0,
149 uc(C4::Context->preference("marcflavour")) => 1
152 output_html_with_http_headers $input, $cookie, $template->output;