perltidy before commit.
[koha.git] / acqui / newbiblio.pl
1 #!/usr/bin/perl
2
3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use CGI;
25 use C4::Context;
26 use C4::Input;
27 use C4::Database;
28 use C4::Auth;
29 use C4::Acquisition;
30 use C4::Suggestions;
31 use C4::Biblio;
32 use C4::Search;
33 use C4::Output;
34 use C4::Input;
35 use C4::Koha;
36 use C4::Interface::CGI::Output;
37 use HTML::Template;
38
39 my $input        = new CGI;
40 my $booksellerid = $input->param('booksellerid');
41 my $title        = $input->param('title');
42 my $author       = $input->param('author');
43 my $copyright    = $input->param('copyright');
44 my ( $count, @booksellers ) = bookseller($booksellerid);
45 my $ordnum       = $input->param('ordnum');
46 my $biblio       = $input->param('biblio');
47 my $basketno     = $input->param('basketno');
48 my $suggestionid = $input->param('suggestionid');
49 my $close        = $input->param('close');
50 my $data;
51 my $new;
52 my $dbh = C4::Context->dbh;
53
54 if ( $ordnum eq '' ) {    # create order
55     $new = 'yes';
56
57     #   $ordnum=newordernum;
58     if ( $biblio && !$suggestionid ) {
59         $data = bibdata($biblio);
60     }
61
62 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
63 # otherwise, retrieve suggestion information.
64     if ($suggestionid) {
65         if ($biblio) {
66             $data = bibdata($biblio);
67         }
68         else {
69             $data = getsuggestion($suggestionid);
70         }
71     }
72     if ( $data->{'title'} eq '' ) {
73         $data->{'title'}         = $title;
74         $data->{'author'}        = $author;
75         $data->{'copyrightdate'} = $copyright;
76     }
77 }
78 else {    #modify order
79     $data   = getsingleorder($ordnum);
80     $biblio = $data->{'biblionumber'};
81 }
82 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
83     {
84         template_name   => "acqui/newbiblio.tmpl",
85         query           => $input,
86         type            => "intranet",
87         authnotrequired => 0,
88         flagsrequired   => { acquisition => 1 },
89         debug           => 1,
90     }
91 );
92
93 # get currencies (for change rates calcs if needed
94 my ( $count, $rates ) = getcurrencies();
95 my @loop_currency = ();
96 for ( my $i = 0 ; $i < $count ; $i++ ) {
97     my %line;
98     $line{currency} = $rates->[$i]->{'currency'};
99     $line{rate}     = $rates->[$i]->{'rate'};
100     push @loop_currency, \%line;
101 }
102
103 # build itemtype list
104 my $sth =
105   $dbh->prepare(
106     "Select itemtype,description from itemtypes order by description");
107 $sth->execute;
108 my @itemtype;
109 my %itemtypes;
110 while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
111     push @itemtype, $value;
112     $itemtypes{$value} = $lib;
113 }
114 my $CGIitemtype = CGI::scrolling_list(
115     -name     => 'format',
116     -values   => \@itemtype,
117     -default  => $data->{'itemtype'},
118     -labels   => \%itemtypes,
119     -size     => 1,
120     -multiple => 0
121 );
122 $sth->finish;
123
124 # build branches list
125 my $branches = getbranches;
126 my @branchloop;
127 foreach my $thisbranch ( sort keys %$branches ) {
128     my %row = (
129         value      => $thisbranch,
130         branchname => $branches->{$thisbranch}->{'branchname'},
131     );
132     push @branchloop, \%row;
133 }
134 $template->param( branchloop => \@branchloop );
135
136 # build bookfund list
137 my $sthtemp =
138   $dbh->prepare(
139     "Select flags, branchcode from borrowers where borrowernumber = ?");
140 $sthtemp->execute($loggedinuser);
141 my ( $flags, $homebranch ) = $sthtemp->fetchrow;
142
143 my $count2;
144 my @bookfund;
145 my @select_bookfund;
146 my %select_bookfunds;
147 ( $count2, @bookfund ) = bookfunds($homebranch);
148 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
149     push @select_bookfund, $bookfund[$i]->{'bookfundid'};
150     $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
151       $bookfund[$i]->{'bookfundname'};
152 }
153 my $CGIbookfund = CGI::scrolling_list(
154     -name     => 'bookfund',
155     -values   => \@select_bookfund,
156     -default  => $data->{'bookfundid'},
157     -labels   => \%select_bookfunds,
158     -size     => 1,
159     -multiple => 0
160 );
161 my $bookfundname;
162 my $bookfundid;
163 if ($close) {
164     $bookfundid   = $data->{'bookfundid'};
165     $bookfundname = $select_bookfunds{$bookfundid};
166 }
167
168 #Build sort lists
169 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
170 if ($CGIsort1) {
171     $template->param( CGIsort1 => $CGIsort1 );
172 }
173 else {
174     $template->param( sort1 => $data->{'sort1'} );
175 }
176
177 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
178 if ($CGIsort2) {
179     $template->param( CGIsort2 => $CGIsort2 );
180 }
181 else {
182     $template->param( sort2 => $data->{'sort2'} );
183 }
184
185 # fill template
186 $template->param(
187     close        => $close,
188     bookfundid   => $bookfundid,
189     bookfundname => $bookfundname
190   )
191   if ($close);
192
193 $template->param(
194     existing         => $biblio,
195     title            => $title,
196     ordnum           => $ordnum,
197     basketno         => $basketno,
198     booksellerid     => $booksellerid,
199     suggestionid     => $suggestionid,
200     biblio           => $biblio,
201     biblioitemnumber => $data->{'biblioitemnumber'},
202     itemtype         => $data->{'itemtype'},
203     discount         => $booksellers[0]->{'discount'},
204     listincgst       => $booksellers[0]->{'listincgst'},
205     listprice        => $booksellers[0]->{'listprice'},
206     gstreg           => $booksellers[0]->{'gstreg'},
207     invoiceinc       => $booksellers[0]->{'invoiceincgst'},
208     invoicedisc      => $booksellers[0]->{'invoicedisc'},
209     nocalc           => $booksellers[0]->{'nocalc'},
210     name             => $booksellers[0]->{'name'},
211     currency         => $booksellers[0]->{'listprice'},
212     gstrate          => C4::Context->preference("gist"),
213     loop_currencies  => \@loop_currency,
214     orderexists      => ( $new eq 'yes' ) ? 0 : 1,
215     title            => $data->{'title'},
216     author           => $data->{'author'},
217     copyrightdate    => $data->{'copyrightdate'},
218     CGIitemtype      => $CGIitemtype,
219     CGIbookfund      => $CGIbookfund,
220     isbn             => $data->{'isbn'},
221     seriestitle      => $data->{'seriestitle'},
222     quantity         => $data->{'quantity'},
223     listprice        => $data->{'listprice'},
224     rrp              => $data->{'rrp'},
225     invoice          => $data->{'booksellerinvoicenumber'},
226     ecost            => $data->{'ecost'},
227     notes            => $data->{'notes'},
228     publishercode    => $data->{'publishercode'}
229 );
230
231 output_html_with_http_headers $input, $cookie, $template->output;