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