Bug 13994: Add a back link to error message in Reports
[koha.git] / acqui / histsearch.pl
blob5add9e17fec30cd79e97012450989c100151e4a9
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::Dates;
59 use C4::Debug;
60 use C4::Branch;
61 use C4::Koha;
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 $from_placed_on = C4::Dates->new($input->param('from'));
74 my $to_placed_on = C4::Dates->new($input->param('to'));
75 my $budget = $input->param( 'budget' );
76 my $orderstatus = $input->param( 'orderstatus' );
77 my $ordernumber = $input->param( 'ordernumber' );
78 my $search_children_too = $input->param( 'search_children_too' );
79 my @created_by = $input->param('created_by');
81 if ( not $input->param('from') ) {
82 # FIXME Dirty but we can't sent a Date::Calc to C4::Dates ?
83 # We would use a function like Add_Delta_YM(-1, 0, 0);
84 $$from_placed_on{dmy_arrayref}[5] -= 1;
87 my $dbh = C4::Context->dbh;
88 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
90 template_name => "acqui/histsearch.tt",
91 query => $input,
92 type => "intranet",
93 authnotrequired => 0,
94 flagsrequired => { acquisition => '*' },
95 debug => 1,
99 my ( $from_iso, $to_iso, $d );
100 if ( $d = $input->param('from') ) {
101 $from_iso = C4::Dates->new($d)->output('iso');
103 if ( $d = $input->param('iso') ) {
104 $to_iso = C4::Dates->new($d)->output('iso');
107 my $order_loop;
108 # If we're supplied any value then we do a search. Otherwise we don't.
109 if ($do_search) {
110 $order_loop = GetHistory(
111 title => $title,
112 author => $author,
113 isbn => $isbn,
114 ean => $ean,
115 name => $name,
116 from_placed_on => $from_iso,
117 to_placed_on => $to_iso,
118 basket => $basket,
119 booksellerinvoicenumber => $booksellerinvoicenumber,
120 basketgroupname => $basketgroupname,
121 budget => $budget,
122 orderstatus => $orderstatus,
123 ordernumber => $ordernumber,
124 search_children_too => $search_children_too,
125 created_by => \@created_by,
129 my $from_date = $from_placed_on ? $from_placed_on->output('syspref') : undef;
130 my $to_date = $to_placed_on ? $to_placed_on->output('syspref') : undef;
132 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
133 my $bp_loop = $budgetperiods;
134 for my $bp ( @{$budgetperiods} ) {
135 my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
136 for my $budget ( @{$hierarchy} ) {
137 $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
139 $$bp{hierarchy} = $hierarchy;
142 $template->param(
143 order_loop => $order_loop,
144 numresults => $order_loop ? scalar(@$order_loop) : undef,
145 title => $title,
146 author => $author,
147 isbn => $isbn,
148 ean => $ean,
149 name => $name,
150 basket => $basket,
151 booksellerinvoicenumber => $booksellerinvoicenumber,
152 basketgroupname => $basketgroupname,
153 ordernumber => $ordernumber,
154 search_children_too => $search_children_too,
155 from_placed_on => $from_date,
156 to_placed_on => $to_date,
157 orderstatus => $orderstatus,
158 budget_id => $budget,
159 bp_loop => $bp_loop,
160 search_done => $do_search,
161 debug => $debug || $input->param('debug') || 0,
162 uc(C4::Context->preference("marcflavour")) => 1
165 output_html_with_http_headers $input, $cookie, $template->output;