synch'ing 2.2 and head
[wip/koha-chris_n.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
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use C4::Input;
28 use C4::Database;
29 use C4::Auth;
30 use C4::Acquisition;
31 use C4::Suggestions;
32 use C4::Search;
33 use C4::Output;
34 use C4::Input;
35 use C4::Interface::CGI::Output;
36 use HTML::Template;
37
38 my $input=new CGI;
39 my $booksellerid=$input->param('booksellerid');
40 my $title=$input->param('title');
41 my $author=$input->param('author');
42 my $copyright=$input->param('copyright');
43 my ($count,@booksellers)=bookseller($booksellerid);
44 my $ordnum=$input->param('ordnum');
45 my $biblio=$input->param('biblio');
46 my $basketno=$input->param('basketno');
47 my $suggestionid = $input->param('suggestionid');
48 my $data;
49 my $new;
50 my $dbh = C4::Context->dbh;
51 if ($ordnum eq ''){ # create order
52         $new='yes';
53 #       $ordnum=newordernum;
54         if ($biblio && !$suggestionid) {
55                         $data=bibdata($biblio);
56         }
57         # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
58         # otherwise, retrieve suggestion information.
59         if ($suggestionid) {
60                 if ($biblio) {
61                         $data=bibdata($biblio);
62                 } else {
63                         $data = getsuggestion($suggestionid);
64                 }
65         }
66         if ($data->{'title'} eq ''){
67                 $data->{'title'}=$title;
68                 $data->{'author'}=$author;
69                 $data->{'copyrightdate'}=$copyright;
70         }
71 }else { #modify order
72         $data=getsingleorder($ordnum);
73         $biblio=$data->{'biblionumber'};
74 }
75 my ($template, $loggedinuser, $cookie)
76     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
77                              query => $input,
78                              type => "intranet",
79                              authnotrequired => 0,
80                              flagsrequired => {acquisition => 1},
81                              debug => 1,
82                              });
83
84
85 # get currencies (for change rates calcs if needed
86 my ($count,$rates)=getcurrencies();
87 my @loop_currency = ();
88 for (my $i=0;$i<$count;$i++){
89         my %line;
90         $line{currency} = $rates->[$i]->{'currency'};
91         $line{rate} = $rates->[$i]->{'rate'};
92         push @loop_currency, \%line;
93 }
94
95 # build itemtype list
96 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
97 $sth->execute;
98 my  @itemtype;
99 my %itemtypes;
100 while (my ($value,$lib) = $sth->fetchrow_array) {
101         push @itemtype, $value;
102         $itemtypes{$value}=$lib;
103 }
104 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
105                         -values   => \@itemtype,
106                         -default  => $data->{'itemtype'},
107                         -labels   => \%itemtypes,
108                         -size     => 1,
109                         -multiple => 0 );
110 $sth->finish;
111
112 # build branches list
113 my @branches;
114 my @select_branch;
115 my %select_branches;
116 my ($count2,@branches)=branches();
117 for (my $i=0;$i<$count2;$i++){
118         push @select_branch, $branches[$i]->{'branchcode'};#
119         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
120 }
121 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
122                         -values   => \@select_branch,
123                         -default  => $data->{'branchcode'},
124                         -labels   => \%select_branches,
125                         -size     => 1,
126                         -multiple => 0 );
127
128 # build bookfund list
129 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
130 $sthtemp->execute($loggedinuser);
131 my ($flags, $homebranch)=$sthtemp->fetchrow;
132
133 my @bookfund;
134 my @select_bookfund;
135 my %select_bookfunds;
136 ($count2,@bookfund)=bookfunds($homebranch);
137 for (my $i=0;$i<$count2;$i++){
138         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
139         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
140 }
141 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
142                         -values   => \@select_bookfund,
143                         -default  => $data->{'bookfundid'},
144                         -labels   => \%select_bookfunds,
145                         -size     => 1,
146                         -multiple => 0 );
147
148 #Build sort lists
149 my $CGIsort1 = buildCGIsort("Asort1","sort1",$data->{'sort1'});
150 if ($CGIsort1) {
151         $template->param(CGIsort1 => $CGIsort1);
152 } else {
153         $template->param( sort1 => $data->{'sort1'});
154 }
155
156 my $CGIsort2 = buildCGIsort("Asort2","sort2",$data->{'sort2'});
157 if ($CGIsort2) {
158         $template->param(CGIsort2 =>$CGIsort2);
159 } else {
160         $template->param( sort2 => $data->{'sort2'});
161 }
162
163 # fill template
164 $template->param( existing => $biblio,
165                                                 title => $title,
166                                                 ordnum => $ordnum,
167                                                 basketno => $basketno,
168                                                 booksellerid => $booksellerid,
169                                                 suggestionid => $suggestionid,
170                                                 biblio => $biblio,
171                                                 biblioitemnumber => $data->{'biblioitemnumber'},
172                                                 itemtype => $data->{'itemtype'},
173                                                 discount => $booksellers[0]->{'discount'},
174                                                 listincgst => $booksellers[0]->{'listincgst'},
175                                                 listprice => $booksellers[0]->{'listprice'},
176                                                 gstreg => $booksellers[0]->{'gstreg'},
177                                                 invoiceinc => $booksellers[0]->{'invoiceincgst'},                              
178                                                 invoicedisc => $booksellers[0]->{'invoicedisc'},                               
179                                                 nocalc => $booksellers[0]->{'nocalc'},
180                                                 name => $booksellers[0]->{'name'},
181                                                 currency => $booksellers[0]->{'listprice'},
182                                                 gstrate => C4::Context->preference("gist") ,
183                                                 loop_currencies => \@loop_currency,
184                                                 orderexists => ($new eq 'yes')?0:1,
185                                                 title => $data->{'title'},
186                                                 author => $data->{'author'},
187                                                 copyrightdate => $data->{'copyrightdate'},
188                                                 CGIitemtype => $CGIitemtype,
189                                                 CGIbranch => $CGIbranch,
190                                                 CGIbookfund => $CGIbookfund,
191                                                 isbn => $data->{'isbn'},
192                                                 seriestitle => $data->{'seriestitle'},
193                                                 quantity => $data->{'quantity'},
194                                                 listprice => $data->{'listprice'},
195                                                 rrp => $data->{'rrp'},
196                                                 invoice => $data->{'booksellerinvoicenumber'},
197                                                 ecost => $data->{'ecost'},
198                                                 notes => $data->{'notes'},
199                                                 publishercode => $data->{'publishercode'});
200
201 output_html_with_http_headers $input, $cookie, $template->output;