Bug 32779: Add tests
[koha.git] / acqui / newordersuggestion.pl
1 #!/usr/bin/perl
2
3 # Copyright 2006 Biblibre
4 # Parts Copyright 2011 PTFS Europe
5 #
6 # This file is part of Koha.
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 newordersuggestion.pl
24
25 =head1 DESCRIPTION
26
27 this script allow to add an order from a existing suggestion.
28 The suggestion must have 'ACCEPTED' as status.
29
30 =head1 CGI PARAMETERS
31
32 =over 4
33
34 =item basketno
35
36     the number of this basket.
37
38 =item booksellerid
39
40     the bookseller who sells this record.
41
42 =item title
43
44     to filter on title when searching among ACCEPTED suggestion.
45
46 =item author
47
48     to filter on author when searching among ACCEPTED suggestion.
49
50 =item note
51
52     to filter on note when searching among ACCEPTED suggestion.
53
54 =item copyrightdate
55
56 =item publishercode
57
58 =item volumedesc
59
60 =item publicationyear
61
62 the publication year of this record.
63
64 =item place
65
66 =item isbn
67
68 the isbn of this suggestion.
69
70 =item duplicateNumber
71
72 is the biblionumber to put to the new suggestion.
73
74 =item suggestionid
75
76 the id of the suggestion to select.
77
78 =item op
79
80 can be equal to
81     * connectDuplicate :
82         then call to the function : ConnectSuggestionAndBiblio.
83         i.e set the biblionumber of this suggestion.
84     * else :
85         is the default value.
86
87 =back
88
89 =cut
90
91 use Modern::Perl;
92
93 use CGI qw ( -utf8 );
94 use C4::Auth qw( get_template_and_user );
95 use C4::Output qw( output_html_with_http_headers );
96 use C4::Suggestions qw( ConnectSuggestionAndBiblio );
97 use C4::Budgets;
98
99 use Koha::Acquisition::Booksellers;
100 use Koha::Suggestions;
101
102 my $input = CGI->new;
103
104 # getting the CGI params
105 my $basketno        = $input->param('basketno');
106 my $booksellerid      = $input->param('booksellerid');
107 my $author          = $input->param('author');
108 my $title           = $input->param('title');
109 my $publishercode   = $input->param('publishercode');
110 my $op              = $input->param('op');
111 my $suggestionid    = $input->param('suggestionid');
112 my $duplicateNumber = $input->param('duplicateNumber');
113 my $uncertainprice = $input->param('uncertainprice');
114
115 $op = 'else' unless $op;
116
117 my $dbh = C4::Context->dbh;
118 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
119     {
120         template_name   => "acqui/newordersuggestion.tt",
121         type            => "intranet",
122         query           => $input,
123         flagsrequired   => { acquisition => 'order_manage' },
124     }
125 );
126
127 if ( $op eq 'connectDuplicate' ) {
128     ConnectSuggestionAndBiblio( $suggestionid, $duplicateNumber );
129 }
130
131 my $suggestions = [ Koha::Suggestions->search_limited(
132     {
133         ( $author        ? ( author        => $author )        : () ),
134         ( $title         ? ( title         => $title )         : () ),
135         ( $publishercode ? ( publishercode => $publishercode ) : () ),
136         STATUS => 'ACCEPTED'
137     },
138     { prefetch => ['managedby', 'suggestedby'] },
139 )->as_list ];
140
141 my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
142 $template->param(
143     suggestions             => $suggestions,
144     basketno                => $basketno,
145     booksellerid              => $booksellerid,
146     name                    => $vendor->name,
147     "op_$op"                => 1,
148 );
149
150 output_html_with_http_headers $input, $cookie, $template->output;