this file has been changed by parcel.pl
[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 $donation = $input->param('donation');
50 my $close        = $input->param('close');
51 my $data;
52 my $new;
53 my $dbh = C4::Context->dbh;
54
55 if ( $ordnum eq '' ) {    # create order
56     $new = 'yes';
57
58     #   $ordnum=newordernum;
59     if ( $biblio && !$suggestionid ) {
60         $data = bibdata($biblio);
61     }
62
63 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
64 # otherwise, retrieve suggestion information.
65     if ($suggestionid) {
66         if ($biblio) {
67             $data = bibdata($biblio);
68         }
69         else {
70             $data = GetSuggestion($suggestionid);
71         }
72     }
73     if ( $data->{'title'} eq '' ) {
74         $data->{'title'}         = $title;
75         $data->{'author'}        = $author;
76         $data->{'copyrightdate'} = $copyright;
77     }
78 }
79 else {    #modify order
80     $data   = getsingleorder($ordnum);
81     $biblio = $data->{'biblionumber'};
82     #get basketno and suppleirno. too!
83     my $data2 = getbasket( $data->{'basketno'} );
84     $basketno     = $data2->{'basketno'};
85     $booksellerid = $data2->{'booksellerid'};
86 }
87
88 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
89     {
90         template_name   => "acqui/newbiblio.tmpl",
91         query           => $input,
92         type            => "intranet",
93         authnotrequired => 0,
94         flagsrequired   => { acquisition => 1 },
95         debug           => 1,
96     }
97 );
98
99 # get currencies (for change rates calcs if needed
100 my ( $count, $rates ) = getcurrencies();
101 my @loop_currency = ();
102 for ( my $i = 0 ; $i < $count ; $i++ ) {
103     my %line;
104     $line{currency} = $rates->[$i]->{'currency'};
105     $line{rate}     = $rates->[$i]->{'rate'};
106     push @loop_currency, \%line;
107 }
108
109 # build itemtype list
110 my $sth =
111   $dbh->prepare(
112     "Select itemtype,description from itemtypes order by description");
113 $sth->execute;
114 my @itemtype;
115 my %itemtypes;
116 while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
117     push @itemtype, $value;
118     $itemtypes{$value} = $lib;
119 }
120 my $CGIitemtype = CGI::scrolling_list(
121     -name     => 'format',
122     -values   => \@itemtype,
123     -default  => $data->{'itemtype'},
124     -labels   => \%itemtypes,
125     -size     => 1,
126     -multiple => 0
127 );
128 $sth->finish;
129
130 # build branches list
131 my $branches = getbranches;
132 my @branchloop;
133 foreach my $thisbranch ( sort keys %$branches ) {
134     my %row = (
135         value      => $thisbranch,
136         branchname => $branches->{$thisbranch}->{'branchname'},
137     );
138     push @branchloop, \%row;
139 }
140 $template->param( branchloop => \@branchloop );
141
142 # build bookfund list
143 my $sthtemp =
144   $dbh->prepare(
145     "Select flags, branchcode from borrowers where borrowernumber = ?");
146 $sthtemp->execute($loggedinuser);
147 my ( $flags, $homebranch ) = $sthtemp->fetchrow;
148
149 my $count2;
150 my @bookfund;
151 my @select_bookfund;
152 my %select_bookfunds;
153 ( $count2, @bookfund ) = bookfunds($homebranch);
154 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
155     push @select_bookfund, $bookfund[$i]->{'bookfundid'};
156     $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
157       $bookfund[$i]->{'bookfundname'};
158 }
159 my $CGIbookfund = CGI::scrolling_list(
160     -name     => 'bookfund',
161     -values   => \@select_bookfund,
162     -default  => $data->{'bookfundid'},
163     -labels   => \%select_bookfunds,
164     -size     => 1,
165     -multiple => 0
166 );
167 my $bookfundname;
168 my $bookfundid;
169 if ($close) {
170     $bookfundid   = $data->{'bookfundid'};
171     $bookfundname = $select_bookfunds{$bookfundid};
172 }
173
174 #Build sort lists
175 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
176 if ($CGIsort1) {
177     $template->param( CGIsort1 => $CGIsort1 );
178 }
179 else {
180     $template->param( sort1 => $data->{'sort1'} );
181 }
182
183 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
184 if ($CGIsort2) {
185     $template->param( CGIsort2 => $CGIsort2 );
186 }
187 else {
188     $template->param( sort2 => $data->{'sort2'} );
189 }
190
191 my $bibitemsexists;
192
193 #do a biblioitems lookup on bib
194 ( my $bibitemscount, my @bibitems ) = getbiblioitembybiblionumber($biblio);
195 if ( $bibitemscount > 0 ) {
196     # warn "NEWBIBLIO: bibitems for $biblio exists\n";
197     # warn Dumper $bibitemscount, @bibitems;
198     $bibitemsexists = 1;
199
200     my @bibitemloop;
201     for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
202         my %line;
203         $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
204         $line{isbn}             = $bibitems[$i]->{'isbn'};
205         $line{itemtype}         = $bibitems[$i]->{'itemtype'};
206         $line{volumeddesc}      = $bibitems[$i]->{'volumeddesc'};
207         push( @bibitemloop, \%line );
208
209         $template->param( bibitemloop => \@bibitemloop );
210     }
211     $template->param( bibitemexists => "1" );
212 }
213
214 # fill template
215 $template->param(
216     close        => $close,
217     bookfundid   => $bookfundid,
218     bookfundname => $bookfundname
219   )
220   if ($close);
221
222 $template->param(
223     existing         => $biblio,
224     title            => $title,
225     ordnum           => $ordnum,
226     basketno         => $basketno,
227     booksellerid     => $booksellerid,
228     suggestionid     => $suggestionid,
229     biblio           => $biblio,
230     biblioitemnumber => $data->{'biblioitemnumber'},
231     itemtype         => $data->{'itemtype'},
232     discount         => $booksellers[0]->{'discount'},
233     listincgst       => $booksellers[0]->{'listincgst'},
234     listprice        => $booksellers[0]->{'listprice'},
235     gstreg           => $booksellers[0]->{'gstreg'},
236     invoiceinc       => $booksellers[0]->{'invoiceincgst'},
237     invoicedisc      => $booksellers[0]->{'invoicedisc'},
238     nocalc           => $booksellers[0]->{'nocalc'},
239     name             => $booksellers[0]->{'name'},
240     currency         => $booksellers[0]->{'listprice'},
241     gstrate          => C4::Context->preference("gist"),
242     loop_currencies  => \@loop_currency,
243     orderexists      => ( $new eq 'yes' ) ? 0 : 1,
244     title            => $data->{'title'},
245     author           => $data->{'author'},
246     copyrightdate    => $data->{'copyrightdate'},
247     CGIitemtype      => $CGIitemtype,
248     CGIbookfund      => $CGIbookfund,
249     isbn             => $data->{'isbn'},
250     seriestitle      => $data->{'seriestitle'},
251     quantity         => $data->{'quantity'},
252     listprice        => $data->{'listprice'},
253     rrp              => $data->{'rrp'},
254     invoice          => $data->{'booksellerinvoicenumber'},
255     ecost            => $data->{'ecost'},
256     notes            => $data->{'notes'},
257     publishercode    => $data->{'publishercode'},
258     donation         => $donation
259 );
260
261 output_html_with_http_headers $input, $cookie, $template->output;