adding 'gettext' as this is requred by the translation utility
[koha.git] / acqui / neworderempty.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
24 =head1 NAME
25
26 neworderempty.pl
27
28 =head1 DESCRIPTION
29 this script allows to create a new record to order it. This record shouldn't exist
30 on database.
31
32 =head1 CGI PARAMETERS
33
34 =over 4
35
36 =item booksellerid
37 the bookseller the librarian has to buy a new book.
38
39 =item title
40 the title of this new record.
41
42 =item author
43 the author of this new record.
44
45 =item copyright
46 the copyright of this new record.
47
48 =item ordnum
49 the number of this order.
50
51 =item biblio
52
53 =item basketno
54 the basket number for this new order.
55
56 =item suggestionid
57 if this order comes from a suggestion.
58
59 =item close
60
61 =back
62
63 =cut
64
65 use strict;
66 use CGI;
67 use C4::Context;
68 use C4::Input;
69
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;
81
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;
97 my $dbh = C4::Context->dbh;
98
99 if ( $ordnum eq '' ) {    # create order
100     $new = 'yes';
101
102     #   $ordnum=newordernum;
103     if ( $biblionumber && !$suggestionid ) {
104         $data = GetBiblioData($biblionumber);
105     }
106
107 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
108 # otherwise, retrieve suggestion information.
109     if ($suggestionid) {
110                 $data = ($biblionumber) ? GetBiblioData($biblionumber) : GetSuggestion($suggestionid);
111     }
112 }
113 else {    #modify order
114     $data   = GetOrder($ordnum);
115     $biblionumber = $data->{'biblionumber'};
116     #get basketno and supplierno. too!
117     my $data2 = GetBasket( $data->{'basketno'} );
118     $basketno     = $data2->{'basketno'};
119     $booksellerid = $data2->{'booksellerid'};
120 }
121
122 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
123     {
124         template_name   => "acqui/neworderempty.tmpl",
125         query           => $input,
126         type            => "intranet",
127         authnotrequired => 0,
128         flagsrequired   => { acquisition => 1 },
129         debug           => 1,
130     }
131 );
132
133 # get currencies (for change rates calcs if needed)
134 my @rates = GetCurrencies();
135 my $count = scalar @rates;
136
137 my @loop_currency = ();
138 for ( my $i = 0 ; $i < $count ; $i++ ) {
139     my %line;
140     $line{currency} = $rates[$i]->{'currency'};
141     $line{rate}     = $rates[$i]->{'rate'};
142     push @loop_currency, \%line;
143 }
144
145 # build itemtype list
146 my $itemtypes = GetItemTypes;
147
148 my @itemtypesloop;
149 foreach my $thisitemtype (sort keys %$itemtypes) {
150     push @itemtypesloop, { itemtype => $itemtypes->{$thisitemtype}->{'itemtype'} , desc =>  $itemtypes->{$thisitemtype}->{'description'} } ;
151 }
152
153 # build branches list
154 my $onlymine=C4::Context->preference('IndependantBranches') && 
155              C4::Context->userenv && 
156              C4::Context->userenv->{flags}!=1 && 
157              C4::Context->userenv->{branch};
158 my $branches = GetBranches($onlymine);
159 my @branchloop;
160 foreach my $thisbranch ( sort keys %$branches ) {
161      my %row = (
162         value      => $thisbranch,
163         branchname => $branches->{$thisbranch}->{'branchname'},
164     );
165         $row{'selected'} = 1 if( $thisbranch eq $data->{branchcode}) ;
166     push @branchloop, \%row;
167 }
168 $template->param( branchloop => \@branchloop , itypeloop => \@itemtypesloop );
169
170 # build bookfund list
171 my $borrower= GetMember($loggedinuser);
172 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
173
174 my @select_bookfund;
175 my %select_bookfunds;
176
177 my @bookfund = GetBookFunds($homebranch);
178 my $count2 = scalar @bookfund;
179
180 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
181     push @select_bookfund, $bookfund[$i]->{'bookfundid'};
182     $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
183       $bookfund[$i]->{'bookfundname'};
184 }
185 my $CGIbookfund = CGI::scrolling_list(
186     -name     => 'bookfund',
187         -id       => 'bookfund',
188     -values   => \@select_bookfund,
189     -default  => $data->{'bookfundid'},
190     -labels   => \%select_bookfunds,
191         #-size     => 1,
192         -tabindex =>'',
193     -multiple => 0
194 );
195
196 my $bookfundname;
197 my $bookfundid;
198 if ($close) {
199     $bookfundid   = $data->{'bookfundid'};
200     $bookfundname = $select_bookfunds{$bookfundid};
201 }
202
203 #Build sort lists
204 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
205 if ($CGIsort1) {
206     $template->param( CGIsort1 => $CGIsort1 );
207 } else {
208     $template->param( sort1 => $data->{'sort1'} );
209 }
210
211 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
212 if ($CGIsort2) {
213     $template->param( CGIsort2 => $CGIsort2 );
214 } else {
215     $template->param( sort2 => $data->{'sort2'} );
216 }
217
218 #do a biblioitems lookup on bib
219 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
220 my $bibitemscount = scalar @bibitems;
221
222 if ( $bibitemscount > 0 ) {
223     # warn "NEWBIBLIO: bibitems for $biblio exists\n";
224     my @bibitemloop;
225     for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
226         my %line;
227         $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
228         $line{isbn}             = $bibitems[$i]->{'isbn'};
229         $line{itemtype}         = $bibitems[$i]->{'itemtype'};
230         $line{volumeddesc}      = $bibitems[$i]->{'volumeddesc'};
231         push( @bibitemloop, \%line );
232
233         $template->param( bibitemloop => \@bibitemloop );
234     }
235     $template->param( bibitemexists => "1" );
236 }
237
238 # fill template
239 $template->param(
240     close        => $close,
241     bookfundid   => $bookfundid,
242     bookfundname => $bookfundname
243   )
244   if ($close);
245
246 $template->param(
247     existing         => $biblionumber,
248     ordnum           => $ordnum,
249     basketno         => $basketno,
250     booksellerid     => $booksellerid,
251     suggestionid     => $suggestionid,
252     biblionumber     => $biblionumber,
253     authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
254         biblioitemnumber => $data->{'biblioitemnumber'},
255     itemtype         => $data->{'itemtype'},
256     itemtype_desc    => $itemtypes->{$data->{'itemtype'}}->{description},
257     discount         => $bookseller->{'discount'},
258     listincgst       => $bookseller->{'listincgst'},
259     listprice        => $bookseller->{'listprice'},
260     gstreg           => $bookseller->{'gstreg'},
261     invoiceinc       => $bookseller->{'invoiceincgst'},
262     invoicedisc      => $bookseller->{'invoicedisc'},
263     nocalc           => $bookseller->{'nocalc'},
264     name             => $bookseller->{'name'},
265     currency         => $bookseller->{'listprice'},
266     gstrate          => C4::Context->preference("gist"),
267     loop_currencies  => \@loop_currency,
268     orderexists      => ( $new eq 'yes' ) ? 0 : 1,
269     title            => $data->{'title'},
270     author           => $data->{'author'},
271     copyrightdate    => $data->{'copyrightdate'},
272     CGIbookfund      => $CGIbookfund,
273     isbn             => $data->{'isbn'},
274     seriestitle      => $data->{'seriestitle'},
275     quantity         => $data->{'quantity'},
276     listprice        => $data->{'listprice'},
277     rrp              => $data->{'rrp'},
278     total            => $data->{ecost}*$data->{quantity},
279     invoice          => $data->{'booksellerinvoicenumber'},
280     ecost            => $data->{'ecost'},
281     purchaseordernumber => $data->{'purchaseordernumber'},
282     notes            => $data->{'notes'},
283     publishercode    => $data->{'publishercode'},
284 #     donation         => $donation
285 );
286
287 output_html_with_http_headers $input, $cookie, $template->output;