more items work; handle unlinked subfields (DB rev => 048)
[koha.git] / acqui / neworderempty.pl
blob809301560d2b55b600b7d2c552a1c02d47c0c5a5
1 #!/usr/bin/perl
3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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.
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.
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
24 =head1 NAME
26 neworderempty.pl
28 =head1 DESCRIPTION
29 this script allows to create a new record to order it. This record shouldn't exist
30 on database.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item booksellerid
37 the bookseller the librarian has to buy a new book.
39 =item title
40 the title of this new record.
42 =item author
43 the author of this new record.
45 =item copyright
46 the copyright of this new record.
48 =item ordnum
49 the number of this order.
51 =item biblio
53 =item basketno
54 the basket number for this new order.
56 =item suggestionid
57 if this order comes from a suggestion.
59 =item close
61 =back
63 =cut
65 use strict;
66 use CGI;
67 use C4::Context;
68 use C4::Input;
70 use C4::Auth;
71 use C4::Bookfund;
72 use C4::Bookseller;
73 use C4::Acquisition;
74 use C4::Suggestions;
75 use C4::Biblio;
76 use C4::Output;
77 use C4::Input;
78 use C4::Koha;
79 use C4::Branch; # GetBranches
80 use C4::Members;
82 my $input = new CGI;
83 my $booksellerid = $input->param('booksellerid');
84 my $title = $input->param('title');
85 my $author = $input->param('author');
86 my $copyright = $input->param('copyright');
87 my @booksellers = GetBookSeller($booksellerid);
88 my $count = scalar @booksellers;
89 my $ordnum = $input->param('ordnum');
90 my $biblionumber = $input->param('biblionumber');
91 my $basketno = $input->param('basketno');
92 my $purchaseorder= $input->param('purchaseordernumber');
93 my $suggestionid = $input->param('suggestionid');
94 # my $donation = $input->param('donation');
95 my $close = $input->param('close');
96 my $data;
97 my $new;
98 my $dbh = C4::Context->dbh;
100 if ( $ordnum eq '' ) { # create order
101 $new = 'yes';
103 # $ordnum=newordernum;
104 if ( $biblionumber && !$suggestionid ) {
105 $data = GetBiblioData($biblionumber);
108 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
109 # otherwise, retrieve suggestion information.
110 if ($suggestionid) {
111 if ($biblionumber) {
112 $data = GetBiblioData($biblionumber);
114 else {
115 $data = GetSuggestion($suggestionid);
119 else { #modify order
120 $data = GetOrder($ordnum);
121 $biblionumber = $data->{'biblionumber'};
122 #get basketno and suppleirno. too!
123 my $data2 = GetBasket( $data->{'basketno'} );
124 $basketno = $data2->{'basketno'};
125 $booksellerid = $data2->{'booksellerid'};
128 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
130 template_name => "acqui/neworderempty.tmpl",
131 query => $input,
132 type => "intranet",
133 authnotrequired => 0,
134 flagsrequired => { acquisition => 1 },
135 debug => 1,
139 # get currencies (for change rates calcs if needed)
140 my @rates = GetCurrencies();
141 $count = scalar @rates;
143 my @loop_currency = ();
144 for ( my $i = 0 ; $i < $count ; $i++ ) {
145 my %line;
146 $line{currency} = $rates[$i]->{'currency'};
147 $line{rate} = $rates[$i]->{'rate'};
148 push @loop_currency, \%line;
151 # build itemtype list
152 my $itemtypes = GetItemTypes;
154 my @itemtypesloop;
155 foreach my $thisitemtype (sort keys %$itemtypes) {
156 push @itemtypesloop, { itemtype => $itemtypes->{$thisitemtype}->{'itemtype'} , desc => $itemtypes->{$thisitemtype}->{'description'} } ;
159 # build branches list
160 my $onlymine=C4::Context->preference('IndependantBranches') &&
161 C4::Context->userenv &&
162 C4::Context->userenv->{flags}!=1 &&
163 C4::Context->userenv->{branch};
164 my $branches = GetBranches($onlymine);
165 my @branchloop;
166 foreach my $thisbranch ( sort keys %$branches ) {
167 my %row = (
168 value => $thisbranch,
169 branchname => $branches->{$thisbranch}->{'branchname'},
171 push @branchloop, \%row;
173 $template->param( branchloop => \@branchloop , itypeloop => \@itemtypesloop );
175 # build bookfund list
176 my $borrower= GetMember($loggedinuser);
177 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
179 my $count2;
180 my @bookfund;
181 my @select_bookfund;
182 my %select_bookfunds;
184 @bookfund = GetBookFunds($homebranch);
185 $count2 = scalar @bookfund;
187 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
188 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
189 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
190 $bookfund[$i]->{'bookfundname'};
192 my $CGIbookfund = CGI::scrolling_list(
193 -name => 'bookfund',
194 -id => 'bookfund',
195 -values => \@select_bookfund,
196 -default => $data->{'bookfundid'},
197 -labels => \%select_bookfunds,
198 -size => 1,
199 -tabindex=>'',
200 -multiple => 0
203 my $bookfundname;
204 my $bookfundid;
205 if ($close) {
206 $bookfundid = $data->{'bookfundid'};
207 $bookfundname = $select_bookfunds{$bookfundid};
210 #Build sort lists
211 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
212 if ($CGIsort1) {
213 $template->param( CGIsort1 => $CGIsort1 );
215 else {
216 $template->param( sort1 => $data->{'sort1'} );
219 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
220 if ($CGIsort2) {
221 $template->param( CGIsort2 => $CGIsort2 );
223 else {
224 $template->param( sort2 => $data->{'sort2'} );
227 my $bibitemsexists;
229 #do a biblioitems lookup on bib
230 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
231 my $bibitemscount = scalar @bibitems;
233 if ( $bibitemscount > 0 ) {
234 # warn "NEWBIBLIO: bibitems for $biblio exists\n";
235 $bibitemsexists = 1;
237 my @bibitemloop;
238 for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
239 my %line;
240 $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
241 $line{isbn} = $bibitems[$i]->{'isbn'};
242 $line{itemtype} = $bibitems[$i]->{'itemtype'};
243 $line{volumeddesc} = $bibitems[$i]->{'volumeddesc'};
244 push( @bibitemloop, \%line );
246 $template->param( bibitemloop => \@bibitemloop );
248 $template->param( bibitemexists => "1" );
251 # fill template
252 $template->param(
253 close => $close,
254 bookfundid => $bookfundid,
255 bookfundname => $bookfundname
257 if ($close);
259 $template->param(
260 existing => $biblionumber,
261 ordnum => $ordnum,
262 basketno => $basketno,
263 booksellerid => $booksellerid,
264 suggestionid => $suggestionid,
265 biblionumber => $biblionumber,
266 authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
267 biblioitemnumber => $data->{'biblioitemnumber'},
268 itemtype => $data->{'itemtype'},
269 itemtype_desc => $itemtypes->{$data->{'itemtype'}}->{description},
270 discount => $booksellers[0]->{'discount'},
271 listincgst => $booksellers[0]->{'listincgst'},
272 listprice => $booksellers[0]->{'listprice'},
273 gstreg => $booksellers[0]->{'gstreg'},
274 invoiceinc => $booksellers[0]->{'invoiceincgst'},
275 invoicedisc => $booksellers[0]->{'invoicedisc'},
276 nocalc => $booksellers[0]->{'nocalc'},
277 name => $booksellers[0]->{'name'},
278 currency => $booksellers[0]->{'listprice'},
279 gstrate => C4::Context->preference("gist"),
280 loop_currencies => \@loop_currency,
281 orderexists => ( $new eq 'yes' ) ? 0 : 1,
282 title => $data->{'title'},
283 author => $data->{'author'},
284 copyrightdate => $data->{'copyrightdate'},
285 CGIbookfund => $CGIbookfund,
286 isbn => $data->{'isbn'},
287 seriestitle => $data->{'seriestitle'},
288 quantity => $data->{'quantity'},
289 listprice => $data->{'listprice'},
290 rrp => $data->{'rrp'},
291 total => $data->{ecost}*$data->{quantity},
292 invoice => $data->{'booksellerinvoicenumber'},
293 ecost => $data->{'ecost'},
294 purchaseordernumber => $data->{'purchaseordernumber'},
295 notes => $data->{'notes'},
296 publishercode => $data->{'publishercode'},
297 # donation => $donation
300 output_html_with_http_headers $input, $cookie, $template->output;