if you just replace su by a space in subjects, you'll replace jesus by je s, which...
[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;
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;
81
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 $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         if ($biblionumber) {
111             $data = GetBiblioData($biblionumber);
112         }
113         else {
114             $data = GetSuggestion($suggestionid);
115         }
116     }
117 }
118 else {    #modify order
119     $data   = GetOrder($ordnum);
120     $biblionumber = $data->{'biblionumber'};
121     #get basketno and suppleirno. too!
122     my $data2 = GetBasket( $data->{'basketno'} );
123     $basketno     = $data2->{'basketno'};
124     $booksellerid = $data2->{'booksellerid'};
125 }
126
127 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
128     {
129         template_name   => "acqui/neworderempty.tmpl",
130         query           => $input,
131         type            => "intranet",
132         authnotrequired => 0,
133         flagsrequired   => { acquisition => 1 },
134         debug           => 1,
135     }
136 );
137
138 # get currencies (for change rates calcs if needed)
139 my @rates = GetCurrencies();
140 $count = scalar @rates;
141
142 my @loop_currency = ();
143 for ( my $i = 0 ; $i < $count ; $i++ ) {
144     my %line;
145     $line{currency} = $rates[$i]->{'currency'};
146     $line{rate}     = $rates[$i]->{'rate'};
147     push @loop_currency, \%line;
148 }
149
150 # build itemtype list
151 my $itemtypes = GetItemTypes;
152
153 my @itemtypesloop;
154 my %itemtypesloop;
155 foreach my $thisitemtype (sort keys %$itemtypes) {
156     push @itemtypesloop, $itemtypes->{$thisitemtype}->{'itemtype'};
157     $itemtypesloop{$itemtypes->{$thisitemtype}->{'itemtype'}} =        $itemtypes->{$thisitemtype}->{'description'};
158 }
159
160 my $CGIitemtype = CGI::scrolling_list(
161     -name     => 'format',
162     -values   => \@itemtypesloop,
163     -default  => $data->{'itemtype'},
164     -labels   => \%itemtypesloop,
165     -size     => 1,
166         -tabindex=>'',
167     -multiple => 0
168 );
169
170 # build branches list
171 my $onlymine=C4::Context->preference('IndependantBranches') && 
172              C4::Context->userenv && 
173              C4::Context->userenv->{flags}!=1 && 
174              C4::Context->userenv->{branch};
175 my $branches = GetBranches($onlymine);
176 my @branchloop;
177 foreach my $thisbranch ( sort keys %$branches ) {
178      my %row = (
179         value      => $thisbranch,
180         branchname => $branches->{$thisbranch}->{'branchname'},
181     );
182     push @branchloop, \%row;
183 }
184 $template->param( branchloop => \@branchloop );
185
186 # build bookfund list
187 my $borrower= GetMember($loggedinuser);
188 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
189
190 my $count2;
191 my @bookfund;
192 my @select_bookfund;
193 my %select_bookfunds;
194
195 @bookfund = GetBookFunds($homebranch);
196 $count2 = scalar @bookfund;
197
198 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
199     push @select_bookfund, $bookfund[$i]->{'bookfundid'};
200     $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
201       $bookfund[$i]->{'bookfundname'};
202 }
203 my $CGIbookfund = CGI::scrolling_list(
204     -name     => 'bookfund',
205     -values   => \@select_bookfund,
206     -default  => $data->{'bookfundid'},
207     -labels   => \%select_bookfunds,
208     -size     => 1,
209         -tabindex=>'',
210     -multiple => 0
211 );
212
213 my $bookfundname;
214 my $bookfundid;
215 if ($close) {
216     $bookfundid   = $data->{'bookfundid'};
217     $bookfundname = $select_bookfunds{$bookfundid};
218 }
219
220 #Build sort lists
221 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
222 if ($CGIsort1) {
223     $template->param( CGIsort1 => $CGIsort1 );
224 }
225 else {
226     $template->param( sort1 => $data->{'sort1'} );
227 }
228
229 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
230 if ($CGIsort2) {
231     $template->param( CGIsort2 => $CGIsort2 );
232 }
233 else {
234     $template->param( sort2 => $data->{'sort2'} );
235 }
236
237 my $bibitemsexists;
238
239 #do a biblioitems lookup on bib
240 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
241 my $bibitemscount = scalar @bibitems;
242
243 if ( $bibitemscount > 0 ) {
244     # warn "NEWBIBLIO: bibitems for $biblio exists\n";
245     $bibitemsexists = 1;
246
247     my @bibitemloop;
248     for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
249         my %line;
250         $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
251         $line{isbn}             = $bibitems[$i]->{'isbn'};
252         $line{itemtype}         = $bibitems[$i]->{'itemtype'};
253         $line{volumeddesc}      = $bibitems[$i]->{'volumeddesc'};
254         push( @bibitemloop, \%line );
255
256         $template->param( bibitemloop => \@bibitemloop );
257     }
258     $template->param( bibitemexists => "1" );
259 }
260
261 # fill template
262 $template->param(
263     close        => $close,
264     bookfundid   => $bookfundid,
265     bookfundname => $bookfundname
266   )
267   if ($close);
268
269 $template->param(
270     existing         => $biblionumber,
271     ordnum           => $ordnum,
272     basketno         => $basketno,
273     booksellerid     => $booksellerid,
274     suggestionid     => $suggestionid,
275     biblionumber           => $biblionumber,
276     biblioitemnumber => $data->{'biblioitemnumber'},
277     itemtype         => $data->{'itemtype'},
278     discount         => $booksellers[0]->{'discount'},
279     listincgst       => $booksellers[0]->{'listincgst'},
280     listprice        => $booksellers[0]->{'listprice'},
281     gstreg           => $booksellers[0]->{'gstreg'},
282     invoiceinc       => $booksellers[0]->{'invoiceincgst'},
283     invoicedisc      => $booksellers[0]->{'invoicedisc'},
284     nocalc           => $booksellers[0]->{'nocalc'},
285     name             => $booksellers[0]->{'name'},
286     currency         => $booksellers[0]->{'listprice'},
287     gstrate          => C4::Context->preference("gist"),
288     loop_currencies  => \@loop_currency,
289     orderexists      => ( $new eq 'yes' ) ? 0 : 1,
290     title            => $data->{'title'},
291     author           => $data->{'author'},
292     copyrightdate    => $data->{'copyrightdate'},
293     CGIitemtype      => $CGIitemtype,
294     CGIbookfund      => $CGIbookfund,
295     isbn             => $data->{'isbn'},
296     seriestitle      => $data->{'seriestitle'},
297     quantity         => $data->{'quantity'},
298     listprice        => $data->{'listprice'},
299     rrp              => $data->{'rrp'},
300     total            => $data->{ecost}*$data->{quantity},
301     invoice          => $data->{'booksellerinvoicenumber'},
302     ecost            => $data->{'ecost'},
303     notes            => $data->{'notes'},
304     publishercode    => $data->{'publishercode'},
305 #     donation         => $donation
306 );
307
308 output_html_with_http_headers $input, $cookie, $template->output;