Bug 8805 - Add a biblio-zebra-indexdefs.xsl for NORMARC
[koha.git] / acqui / histsearch.pl
blobe89bcae394f4314835516cf32e1c4f98e7500954
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;
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 $from_placed_on = C4::Dates->new($input->param('from'));
72 my $to_placed_on = C4::Dates->new($input->param('to'));
73 if ( not $input->param('from') ) {
74 # FIXME Dirty but we can't sent a Date::Calc to C4::Dates ?
75 # We would use a function like Add_Delta_YM(-1, 0, 0);
76 $$from_placed_on{dmy_arrayref}[5] -= 1;
79 my $dbh = C4::Context->dbh;
80 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82 template_name => "acqui/histsearch.tmpl",
83 query => $input,
84 type => "intranet",
85 authnotrequired => 0,
86 flagsrequired => { acquisition => 'group_manage', acquisition => 'order_manage', acquisition => 'order_receive' },
87 debug => 1,
91 my ( $from_iso, $to_iso, $d );
92 if ( $d = $input->param('from') ) {
93 $from_iso = C4::Dates->new($d)->output('iso');
95 if ( $d = $input->param('iso') ) {
96 $to_iso = C4::Dates->new($d)->output('iso');
99 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived );
100 # If we're supplied any value then we do a search. Otherwise we don't.
101 if ($do_search) {
102 ( $order_loop, $total_qty, $total_price, $total_qtyreceived ) = GetHistory(
103 title => $title,
104 author => $author,
105 isbn => $isbn,
106 ean => $ean,
107 name => $name,
108 from_placed_on => $from_iso,
109 to_placed_on => $to_iso,
110 basket => $basket,
111 booksellerinvoicenumber => $booksellerinvoicenumber,
112 basketgroupname => $basketgroupname,
116 my $from_date = $from_placed_on ? $from_placed_on->output('syspref') : undef;
117 my $to_date = $to_placed_on ? $to_placed_on->output('syspref') : undef;
119 $template->param(
120 suggestions_loop => $order_loop,
121 total_qty => $total_qty,
122 total_qtyreceived => $total_qtyreceived,
123 total_price => sprintf( "%.2f", $total_price ),
124 numresults => $order_loop ? scalar(@$order_loop) : undef,
125 title => $title,
126 author => $author,
127 isbn => $isbn,
128 ean => $ean,
129 name => $name,
130 basket => $basket,
131 booksellerinvoicenumber => $booksellerinvoicenumber,
132 basketgroupname => $basketgroupname,
133 from_placed_on => $from_date,
134 to_placed_on => $to_date,
135 DHTMLcalendar_dateformat=> C4::Dates->DHTMLcalendar(),
136 dateformat => C4::Dates->new()->format(),
137 debug => $debug || $input->param('debug') || 0,
138 uc(C4::Context->preference("marcflavour")) => 1
141 output_html_with_http_headers $input, $cookie, $template->output;