]> git.koha-community.org Git - koha.git/blob - acqui/histsearch.pl
Bug 30756: Further adjustments to Koha_Authority.t
[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 Modern::Perl;
53 use CGI qw ( -utf8 );
54 use C4::Auth qw( get_template_and_user );
55 use C4::Output qw( output_html_with_http_headers );
56 use C4::Acquisition qw( GetHistory );
57 use Koha::AdditionalFields;
58 use Koha::DateUtils qw( dt_from_string output_pref );
59
60 my $input = CGI->new;
61 my $do_search               = $input->param('do_search') || 0;
62
63 my $dbh = C4::Context->dbh;
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65     {
66         template_name   => "acqui/histsearch.tt",
67         query           => $input,
68         type            => "intranet",
69         flagsrequired   => { acquisition => '*' },
70     }
71 );
72
73 my $filters = {
74     basket                  => scalar $input->param('basket'),
75     title                   => scalar $input->param('title'),
76     author                  => scalar $input->param('author'),
77     isbn                    => scalar $input->param('isbn'),
78     name                    => scalar $input->param('name'),
79     internalnote            => scalar $input->param('internalnote'),
80     vendornote              => scalar $input->param('vendornote'),
81     ean                     => scalar $input->param('ean'),
82     basketgroupname         => scalar $input->param('basketgroupname'),
83     budget                  => scalar $input->param('budget'),
84     booksellerinvoicenumber => scalar $input->param('booksellerinvoicenumber'),
85     budget                  => scalar $input->param('budget'),
86     orderstatus             => scalar $input->param('orderstatus'),
87     is_standing             => scalar $input->param('is_standing'),
88     ordernumber             => scalar $input->param('ordernumber'),
89     search_children_too     => scalar $input->param('search_children_too'),
90     created_by              => [ $input->multi_param('created_by') ],
91     managing_library        => scalar $input->param('managing_library'),
92 };
93
94 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
95 my $to_placed_on   = eval { dt_from_string( scalar $input->param('to')   ) } || dt_from_string;
96 unless ( $input->param('from') ) {
97     # Fill the form with year-1
98     $from_placed_on->set_time_zone('floating')->subtract( years => 1 );
99 }
100 $filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } );
101 $filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } );
102 my $additional_fields = Koha::AdditionalFields->search( { tablename => 'aqbasket', searchable => 1 } );
103 $template->param( available_additional_fields => $additional_fields );
104 my @additional_field_filters;
105 while ( my $additional_field = $additional_fields->next ) {
106     my $value = $input->param('additional_field_' . $additional_field->id);
107     if (defined $value and $value ne '') {
108         push @additional_field_filters, {
109             id => $additional_field->id,
110             value => $value,
111         };
112     }
113 }
114 $filters->{additional_fields} = \@additional_field_filters;
115
116
117 my $order_loop;
118 # If we're supplied any value then we do a search. Otherwise we don't.
119 if ($do_search) {
120     $order_loop = GetHistory(%$filters);
121 }
122
123 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
124 my $bp_loop = $budgetperiods;
125 for my $bp ( @{$budgetperiods} ) {
126     my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
127     for my $budget ( @{$hierarchy} ) {
128         $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
129     }
130     $$bp{hierarchy} = $hierarchy;
131 }
132
133 $template->param(
134     order_loop  => $order_loop,
135     filters     => $filters,
136     bp_loop     => $bp_loop,
137     search_done => $do_search,
138 );
139
140 output_html_with_http_headers $input, $cookie, $template->output;