Bug 21757: (folow-up) Restore patron brief detail page
[koha.git] / acqui / histsearch.pl
blobf5dca499c80473e2e7b4f1ffed539776a034c581
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::AdditionalFields;
60 use Koha::DateUtils;
62 my $input = new CGI;
63 my $do_search = $input->param('do_search') || 0;
65 my $dbh = C4::Context->dbh;
66 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
68 template_name => "acqui/histsearch.tt",
69 query => $input,
70 type => "intranet",
71 authnotrequired => 0,
72 flagsrequired => { acquisition => '*' },
73 debug => 1,
77 my $filters = {
78 basket => scalar $input->param('basket'),
79 title => scalar $input->param('title'),
80 author => scalar $input->param('author'),
81 isbn => scalar $input->param('isbn'),
82 name => scalar $input->param('name'),
83 ean => scalar $input->param('ean'),
84 basketgroupname => scalar $input->param('basketgroupname'),
85 budget => scalar $input->param('budget'),
86 booksellerinvoicenumber => scalar $input->param('booksellerinvoicenumber'),
87 budget => scalar $input->param('budget'),
88 orderstatus => scalar $input->param('orderstatus'),
89 ordernumber => scalar $input->param('ordernumber'),
90 search_children_too => scalar $input->param('search_children_too'),
91 created_by => [ $input->multi_param('created_by') ],
93 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
94 my $to_placed_on = eval { dt_from_string( scalar $input->param('to') ) } || dt_from_string;
95 unless ( $input->param('from') ) {
96 # Fill the form with year-1
97 $from_placed_on->subtract( years => 1 );
99 $filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
100 $filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
101 my @additional_fields = Koha::AdditionalFields->search( { tablename => 'aqbasket', searchable => 1 } );
102 $template->param( available_additional_fields => \@additional_fields );
103 my @additional_field_filters;
104 foreach my $additional_field (@additional_fields) {
105 my $value = $input->param('additional_field_' . $additional_field->id);
106 if (defined $value and $value ne '') {
107 push @additional_field_filters, {
108 id => $additional_field->id,
109 value => $value,
113 $filters->{additional_fields} = \@additional_field_filters;
116 my $order_loop;
117 # If we're supplied any value then we do a search. Otherwise we don't.
118 if ($do_search) {
119 $order_loop = GetHistory(%$filters);
122 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
123 my $bp_loop = $budgetperiods;
124 for my $bp ( @{$budgetperiods} ) {
125 my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
126 for my $budget ( @{$hierarchy} ) {
127 $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
129 $$bp{hierarchy} = $hierarchy;
132 $template->param(
133 order_loop => $order_loop,
134 filters => $filters,
135 bp_loop => $bp_loop,
136 search_done => $do_search,
139 output_html_with_http_headers $input, $cookie, $template->output;