Bug 12395: Make received orders table consistent with pending orders table
[koha.git] / acqui / histsearch.pl
blobb30eda31ddb28526e1bff4ae1b8894dca2ae33ab
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 Modern::Perl;
53 use CGI qw ( -utf8 );
54 use C4::Auth; # get_template_and_user
55 use C4::Output;
56 use C4::Acquisition;
57 use C4::Debug;
58 use C4::Koha;
59 use Koha::DateUtils;
61 my $input = new CGI;
62 my $title = $input->param( 'title');
63 my $author = $input->param('author');
64 my $isbn = $input->param('isbn');
65 my $name = $input->param( 'name' );
66 my $ean = $input->param('ean');
67 my $basket = $input->param( 'basket' );
68 my $basketgroupname = $input->param('basketgroupname');
69 my $booksellerinvoicenumber = $input->param( 'booksellerinvoicenumber' );
70 my $do_search = $input->param('do_search') || 0;
71 my $budget = $input->param( 'budget' );
72 my $orderstatus = $input->param( 'orderstatus' );
73 my $ordernumber = $input->param( 'ordernumber' );
74 my $search_children_too = $input->param( 'search_children_too' );
75 my @created_by = $input->multi_param('created_by');
77 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
78 my $to_placed_on = eval { dt_from_string( scalar $input->param('to') ) } || dt_from_string;
79 unless ( $input->param('from') ) {
80 # Fill the form with year-1
81 $from_placed_on->subtract( years => 1 );
84 my $dbh = C4::Context->dbh;
85 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
87 template_name => "acqui/histsearch.tt",
88 query => $input,
89 type => "intranet",
90 authnotrequired => 0,
91 flagsrequired => { acquisition => '*' },
92 debug => 1,
96 my $order_loop;
97 # If we're supplied any value then we do a search. Otherwise we don't.
98 if ($do_search) {
99 $order_loop = GetHistory(
100 title => $title,
101 author => $author,
102 isbn => $isbn,
103 ean => $ean,
104 name => $name,
105 from_placed_on => output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
106 to_placed_on => output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
107 basket => $basket,
108 booksellerinvoicenumber => $booksellerinvoicenumber,
109 basketgroupname => $basketgroupname,
110 budget => $budget,
111 orderstatus => $orderstatus,
112 ordernumber => $ordernumber,
113 search_children_too => $search_children_too,
114 created_by => \@created_by,
118 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
119 my $bp_loop = $budgetperiods;
120 for my $bp ( @{$budgetperiods} ) {
121 my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
122 for my $budget ( @{$hierarchy} ) {
123 $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
125 $$bp{hierarchy} = $hierarchy;
128 $template->param(
129 order_loop => $order_loop,
130 numresults => $order_loop ? scalar(@$order_loop) : undef,
131 title => $title,
132 author => $author,
133 isbn => $isbn,
134 ean => $ean,
135 name => $name,
136 basket => $basket,
137 booksellerinvoicenumber => $booksellerinvoicenumber,
138 basketgroupname => $basketgroupname,
139 ordernumber => $ordernumber,
140 search_children_too => $search_children_too,
141 from_placed_on => $from_placed_on,
142 to_placed_on => $to_placed_on,
143 orderstatus => $orderstatus,
144 budget_id => $budget,
145 bp_loop => $bp_loop,
146 search_done => $do_search,
147 debug => $debug || $input->param('debug') || 0,
148 uc(C4::Context->preference("marcflavour")) => 1
151 output_html_with_http_headers $input, $cookie, $template->output;