Bug 12705 - News not possible for one sublanguage if two sublanguages are installed
[koha.git] / acqui / histsearch.pl
blobb474ac1d1dba8e247c550e00f07682900460f181
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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
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' );
80 if ( not $input->param('from') ) {
81 # FIXME Dirty but we can't sent a Date::Calc to C4::Dates ?
82 # We would use a function like Add_Delta_YM(-1, 0, 0);
83 $$from_placed_on{dmy_arrayref}[5] -= 1;
86 my $dbh = C4::Context->dbh;
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
89 template_name => "acqui/histsearch.tt",
90 query => $input,
91 type => "intranet",
92 authnotrequired => 0,
93 flagsrequired => { acquisition => '*' },
94 debug => 1,
98 my ( $from_iso, $to_iso, $d );
99 if ( $d = $input->param('from') ) {
100 $from_iso = C4::Dates->new($d)->output('iso');
102 if ( $d = $input->param('iso') ) {
103 $to_iso = C4::Dates->new($d)->output('iso');
106 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived );
107 # If we're supplied any value then we do a search. Otherwise we don't.
108 if ($do_search) {
109 ( $order_loop, $total_qty, $total_price, $total_qtyreceived ) = GetHistory(
110 title => $title,
111 author => $author,
112 isbn => $isbn,
113 ean => $ean,
114 name => $name,
115 from_placed_on => $from_iso,
116 to_placed_on => $to_iso,
117 basket => $basket,
118 booksellerinvoicenumber => $booksellerinvoicenumber,
119 basketgroupname => $basketgroupname,
120 budget => $budget,
121 orderstatus => $orderstatus,
122 ordernumber => $ordernumber,
123 search_children_too => $search_children_too,
127 my $from_date = $from_placed_on ? $from_placed_on->output('syspref') : undef;
128 my $to_date = $to_placed_on ? $to_placed_on->output('syspref') : undef;
130 my $budgetperiods = C4::Budgets::GetBudgetPeriods;
131 my $bp_loop = $budgetperiods;
132 for my $bp ( @{$budgetperiods} ) {
133 my $hierarchy = C4::Budgets::GetBudgetHierarchy( $$bp{budget_period_id} );
134 for my $budget ( @{$hierarchy} ) {
135 $$budget{budget_display_name} = sprintf("%s", ">" x $$budget{depth} . $$budget{budget_name});
137 $$bp{hierarchy} = $hierarchy;
140 $template->param(
141 order_loop => $order_loop,
142 total_qty => $total_qty,
143 total_qtyreceived => $total_qtyreceived,
144 total_price => sprintf( "%.2f", $total_price ),
145 numresults => $order_loop ? scalar(@$order_loop) : undef,
146 title => $title,
147 author => $author,
148 isbn => $isbn,
149 ean => $ean,
150 name => $name,
151 basket => $basket,
152 booksellerinvoicenumber => $booksellerinvoicenumber,
153 basketgroupname => $basketgroupname,
154 ordernumber => $ordernumber,
155 search_children_too => $search_children_too,
156 from_placed_on => $from_date,
157 to_placed_on => $to_date,
158 orderstatus => $orderstatus,
159 budget_id => $budget,
160 bp_loop => $bp_loop,
161 search_done => $do_search,
162 debug => $debug || $input->param('debug') || 0,
163 uc(C4::Context->preference("marcflavour")) => 1
166 output_html_with_http_headers $input, $cookie, $template->output;