booksellers page, some changes
[koha.git] / acqui / neworderempty.pl
blob3a9043c0f6b928cd79f278c83e12738e1c09fd2c
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; # GetBookSellerFromId
73 use C4::Acquisition;
74 use C4::Suggestions; # GetSuggestion
75 use C4::Biblio; # GetBiblioData
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'); # FIXME: else ERROR!
84 my $title = $input->param('title');
85 my $author = $input->param('author');
86 my $copyright = $input->param('copyright');
87 my $bookseller = GetBookSellerFromId($booksellerid); # FIXME: else ERROR!
88 my $ordnum = $input->param('ordnum');
89 my $biblionumber = $input->param('biblionumber');
90 my $basketno = $input->param('basketno');
91 my $purchaseorder= $input->param('purchaseordernumber');
92 my $suggestionid = $input->param('suggestionid');
93 # my $donation = $input->param('donation');
94 my $close = $input->param('close');
95 my $data;
96 my $new;
98 if ( $ordnum eq '' ) { # create order
99 $new = 'yes';
101 # $ordnum=newordernum;
102 if ( $biblionumber && !$suggestionid ) {
103 $data = GetBiblioData($biblionumber);
106 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
107 # otherwise, retrieve suggestion information.
108 if ($suggestionid) {
109 $data = ($biblionumber) ? GetBiblioData($biblionumber) : GetSuggestion($suggestionid);
112 else { #modify order
113 $data = GetOrder($ordnum);
114 $biblionumber = $data->{'biblionumber'};
115 #get basketno and supplierno. too!
116 my $data2 = GetBasket( $data->{'basketno'} );
117 $basketno = $data2->{'basketno'};
118 $booksellerid = $data2->{'booksellerid'};
121 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
123 template_name => "acqui/neworderempty.tmpl",
124 query => $input,
125 type => "intranet",
126 authnotrequired => 0,
127 flagsrequired => { acquisition => 1 },
128 debug => 1,
132 # get currencies (for change rates calcs if needed)
133 my @rates = GetCurrencies();
134 my $count = scalar @rates;
136 my @loop_currency = ();
137 for ( my $i = 0 ; $i < $count ; $i++ ) {
138 my %line;
139 $line{currency} = $rates[$i]->{'currency'};
140 $line{rate} = $rates[$i]->{'rate'};
141 push @loop_currency, \%line;
144 # build itemtype list
145 my $itemtypes = GetItemTypes;
147 my @itemtypesloop;
148 foreach my $thisitemtype (sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'}} keys %$itemtypes) {
149 push @itemtypesloop, { itemtype => $itemtypes->{$thisitemtype}->{'itemtype'} , desc => $itemtypes->{$thisitemtype}->{'description'} } ;
152 # build branches list
153 my $onlymine=C4::Context->preference('IndependantBranches') &&
154 C4::Context->userenv &&
155 C4::Context->userenv->{flags}!=1 &&
156 C4::Context->userenv->{branch};
157 my $branches = GetBranches($onlymine);
158 my @branchloop;
159 foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) {
160 my %row = (
161 value => $thisbranch,
162 branchname => $branches->{$thisbranch}->{'branchname'},
164 $row{'selected'} = 1 if( $thisbranch eq $data->{branchcode}) ;
165 push @branchloop, \%row;
167 $template->param( branchloop => \@branchloop , itypeloop => \@itemtypesloop );
169 # build bookfund list
170 my $borrower= GetMember('borrowernumber' => $loggedinuser);
171 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
173 my @select_bookfund;
174 my %select_bookfunds;
176 my @bookfund = GetBookFunds($homebranch);
177 my $count2 = scalar @bookfund;
179 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
180 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
181 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
182 $bookfund[$i]->{'bookfundname'};
184 my $CGIbookfund = CGI::scrolling_list(
185 -name => 'bookfund',
186 -id => 'bookfund',
187 -values => \@select_bookfund,
188 -default => ($data->{'bookfundid'} ? $data->{'bookfundid'} : $select_bookfund[0]),
189 -labels => \%select_bookfunds,
190 #-size => 1,
191 -multiple => 0
194 my $bookfundname;
195 my $bookfundid;
196 if ($close) {
197 $bookfundid = $data->{'bookfundid'};
198 $bookfundname = $select_bookfunds{$bookfundid};
201 #Build sort lists
202 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
203 if ($CGIsort1) {
204 $template->param( CGIsort1 => $CGIsort1 );
205 } else {
206 $template->param( sort1 => $data->{'sort1'} );
209 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
210 if ($CGIsort2) {
211 $template->param( CGIsort2 => $CGIsort2 );
212 } else {
213 $template->param( sort2 => $data->{'sort2'} );
216 #do a biblioitems lookup on bib
217 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
218 my $bibitemscount = scalar @bibitems;
220 if ( $bibitemscount > 0 ) {
221 # warn "NEWBIBLIO: bibitems for $biblio exists\n";
222 my @bibitemloop;
223 for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
224 my %line;
225 $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
226 $line{isbn} = $bibitems[$i]->{'isbn'};
227 $line{itemtype} = $bibitems[$i]->{'itemtype'};
228 $line{volumeddesc} = $bibitems[$i]->{'volumeddesc'};
229 push( @bibitemloop, \%line );
231 $template->param( bibitemloop => \@bibitemloop );
233 $template->param( bibitemexists => "1" );
236 # fill template
237 $template->param(
238 close => $close,
239 bookfundid => $bookfundid,
240 bookfundname => $bookfundname
242 if ($close);
244 $template->param(
245 existing => $biblionumber,
246 ordnum => $ordnum,
247 basketno => $basketno,
248 booksellerid => $booksellerid,
249 suggestionid => $suggestionid,
250 biblionumber => $biblionumber,
251 authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
252 biblioitemnumber => $data->{'biblioitemnumber'},
253 itemtype => $data->{'itemtype'},
254 itemtype_desc => $itemtypes->{$data->{'itemtype'}}->{description},
255 discount => $bookseller->{'discount'},
256 listincgst => $bookseller->{'listincgst'},
257 listprice => $bookseller->{'listprice'},
258 gstreg => $bookseller->{'gstreg'},
259 invoiceinc => $bookseller->{'invoiceincgst'},
260 invoicedisc => $bookseller->{'invoicedisc'},
261 nocalc => $bookseller->{'nocalc'},
262 name => $bookseller->{'name'},
263 currency => $bookseller->{'listprice'},
264 gstrate => C4::Context->preference("gist") || 0,
265 loop_currencies => \@loop_currency,
266 orderexists => ( $new eq 'yes' ) ? 0 : 1,
267 title => $data->{'title'},
268 author => $data->{'author'},
269 copyrightdate => $data->{'copyrightdate'},
270 CGIbookfund => $CGIbookfund,
271 isbn => $data->{'isbn'},
272 seriestitle => $data->{'seriestitle'},
273 quantity => $data->{'quantity'},
274 listprice => $data->{'listprice'},
275 rrp => $data->{'rrp'},
276 total => $data->{ecost}*$data->{quantity},
277 invoice => $data->{'booksellerinvoicenumber'},
278 ecost => $data->{'ecost'},
279 purchaseordernumber => $data->{'purchaseordernumber'},
280 notes => $data->{'notes'},
281 publishercode => $data->{'publishercode'},
282 # donation => $donation
285 output_html_with_http_headers $input, $cookie, $template->output;