* updates to make acquisition compatible with suggestions & serials
[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::Database;
28 use C4::Auth;
29 use C4::Acquisition;
30 use C4::Suggestions;
31 use C4::Search;
32 use C4::Output;
33 use C4::Interface::CGI::Output;
34 use HTML::Template;
35
36 my $input=new CGI;
37 my $booksellerid=$input->param('booksellerid');
38 my $title=$input->param('title');
39 my $author=$input->param('author');
40 my $copyright=$input->param('copyright');
41 my ($count,@booksellers)=bookseller($booksellerid);
42 my $ordnum=$input->param('ordnum');
43 my $biblio=$input->param('biblio');
44 my $basketno=$input->param('basketno');
45 my $suggestionid = $input->param('suggestionid');
46 my $data;
47 my $new;
48 my $dbh = C4::Context->dbh;
49 if ($ordnum eq ''){ # create order
50         $new='yes';
51 #       $ordnum=newordernum;
52         if ($biblio && !$suggestionid) {
53                         $data=bibdata($biblio);
54         }
55         # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
56         # otherwise, retrieve suggestion information.
57         if ($suggestionid) {
58                 if ($biblio) {
59                         $data=bibdata($biblio);
60                 } else {
61                         $data = getsuggestion($suggestionid);
62                 }
63         }
64         if ($data->{'title'} eq ''){
65                 $data->{'title'}=$title;
66                 $data->{'author'}=$author;
67                 $data->{'copyrightdate'}=$copyright;
68         }
69 }else { #modify order
70         $data=getsingleorder($ordnum);
71         $biblio=$data->{'biblionumber'};
72 }
73 my ($template, $loggedinuser, $cookie)
74     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
75                              query => $input,
76                              type => "intranet",
77                              authnotrequired => 0,
78                              flagsrequired => {acquisition => 1},
79                              debug => 1,
80                              });
81
82
83 # get currencies (for change rates calcs if needed
84 my ($count,$rates)=getcurrencies();
85 my @loop_currency = ();
86 for (my $i=0;$i<$count;$i++){
87         my %line;
88         $line{currency} = $rates->[$i]->{'currency'};
89         $line{rate} = $rates->[$i]->{'rate'};
90         push @loop_currency, \%line;
91 }
92
93 # build itemtype list
94 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
95 $sth->execute;
96 my  @itemtype;
97 my %itemtypes;
98 while (my ($value,$lib) = $sth->fetchrow_array) {
99         push @itemtype, $value;
100         $itemtypes{$value}=$lib;
101 }
102 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
103                         -values   => \@itemtype,
104                         -default  => $data->{'itemtype'},
105                         -labels   => \%itemtypes,
106                         -size     => 1,
107                         -multiple => 0 );
108 $sth->finish;
109
110 # build branches list
111 my @branches;
112 my @select_branch;
113 my %select_branches;
114 my ($count2,@branches)=branches();
115 for (my $i=0;$i<$count2;$i++){
116         push @select_branch, $branches[$i]->{'branchcode'};#
117         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
118 }
119 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
120                         -values   => \@select_branch,
121                         -default  => $data->{'branchcode'},
122                         -labels   => \%select_branches,
123                         -size     => 1,
124                         -multiple => 0 );
125
126 # build bookfund list
127 my @bookfund;
128 my @select_bookfund;
129 my %select_bookfunds;
130 ($count2,@bookfund)=bookfunds();
131 for (my $i=0;$i<$count2;$i++){
132         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
133         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
134 }
135 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
136                         -values   => \@select_bookfund,
137                         -default  => $data->{'bookfundid'},
138                         -labels   => \%select_bookfunds,
139                         -size     => 1,
140                         -multiple => 0 );
141
142 # fill template
143 $template->param( existing => $biblio,
144                                                 title => $title,
145                                                 ordnum => $ordnum,
146                                                 basketno => $basketno,
147                                                 booksellerid => $booksellerid,
148                                                 suggestionid => $suggestionid,
149                                                 biblio => $biblio,
150                                                 biblioitemnumber => $data->{'biblioitemnumber'},
151                                                 itemtype => $data->{'itemtype'},
152                                                 discount => $booksellers[0]->{'discount'},
153                                                 listincgst => $booksellers[0]->{'listincgst'},
154                                                 listprice => $booksellers[0]->{'listprice'},
155                                                 gstreg => $booksellers[0]->{'gstreg'},
156                                                 name => $booksellers[0]->{'name'},
157                                                 currency => $booksellers[0]->{'listprice'},
158                                                 gstrate => C4::Context->preference("gist") ,
159                                                 loop_currencies => \@loop_currency,
160                                                 orderexists => ($new eq 'yes')?0:1,
161                                                 title => $data->{'title'},
162                                                 author => $data->{'author'},
163                                                 copyrightdate => $data->{'copyrightdate'},
164                                                 CGIitemtype => $CGIitemtype,
165                                                 CGIbranch => $CGIbranch,
166                                                 CGIbookfund => $CGIbookfund,
167                                                 isbn => $data->{'isbn'},
168                                                 seriestitle => $data->{'seriestitle'},
169                                                 quantity => $data->{'quantity'},
170                                                 listprice => $data->{'listprice'},
171                                                 rrp => $data->{'rrp'},
172                                                 ecost => $data->{'ecost'},
173                                                 notes => $data->{'notes'},
174                                                 sort1 => $data->{'sort1'},
175                                                 sort2 => $data->{'sort2'},
176                                                 publishercode => $data->{'publishercode'});
177
178 output_html_with_http_headers $input, $cookie, $template->output;