]> git.koha-community.org Git - koha.git/blob - acqui/newbiblio.pl
moving overdue report to reports directory
[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::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 $close= $input->param('close');
49 my $data;
50 my $new;
51 my $dbh = C4::Context->dbh;
52 if ($ordnum eq ''){ # create order
53         $new='yes';
54 #       $ordnum=newordernum;
55         if ($biblio && !$suggestionid) {
56                         $data=bibdata($biblio);
57         }
58         # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
59         # otherwise, retrieve suggestion information.
60         if ($suggestionid) {
61                 if ($biblio) {
62                         $data=bibdata($biblio);
63                 } else {
64                         $data = getsuggestion($suggestionid);
65                 }
66         }
67         if ($data->{'title'} eq ''){
68                 $data->{'title'}=$title;
69                 $data->{'author'}=$author;
70                 $data->{'copyrightdate'}=$copyright;
71         }
72 }else { #modify order
73         $data=getsingleorder($ordnum);
74         $biblio=$data->{'biblionumber'};
75 }
76 my ($template, $loggedinuser, $cookie)
77     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
78                              query => $input,
79                              type => "intranet",
80                              authnotrequired => 0,
81                              flagsrequired => {acquisition => 1},
82                              debug => 1,
83                              });
84
85
86 # get currencies (for change rates calcs if needed
87 my ($count,$rates)=getcurrencies();
88 my @loop_currency = ();
89 for (my $i=0;$i<$count;$i++){
90         my %line;
91         $line{currency} = $rates->[$i]->{'currency'};
92         $line{rate} = $rates->[$i]->{'rate'};
93         push @loop_currency, \%line;
94 }
95
96 # build itemtype list
97 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
98 $sth->execute;
99 my  @itemtype;
100 my %itemtypes;
101 while (my ($value,$lib) = $sth->fetchrow_array) {
102         push @itemtype, $value;
103         $itemtypes{$value}=$lib;
104 }
105 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
106                         -values   => \@itemtype,
107                         -default  => $data->{'itemtype'},
108                         -labels   => \%itemtypes,
109                         -size     => 1,
110                         -multiple => 0 );
111 $sth->finish;
112
113 # build branches list
114 my @branches;
115 my @select_branch;
116 my %select_branches;
117 my ($count2,@branches)=branches();
118 for (my $i=0;$i<$count2;$i++){
119         if ((!C4::Context->preference('IndependantBranches'))||(C4::Context->preference('IndependantBranches') && (C4::Context->userenv->{flags} ==1))
120         ||((C4::Context->preference('IndependantBranches') && (C4::Context->userenv->{flags} !=1) && (C4::Context->userenv->{branch} eq $branches[$i]->{'branchcode'})))){
121                 push @select_branch, $branches[$i]->{'branchcode'};#
122                 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
123         }
124 }
125 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
126                         -values   => \@select_branch,
127                         -default  => $data->{'branchcode'},
128                         -labels   => \%select_branches,
129                         -size     => 1,
130                         -multiple => 0 );
131
132 # build bookfund list
133 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
134 $sthtemp->execute($loggedinuser);
135 my ($flags, $homebranch)=$sthtemp->fetchrow;
136
137 my @bookfund;
138 my @select_bookfund;
139 my %select_bookfunds;
140 ($count2,@bookfund)=bookfunds($homebranch);
141 for (my $i=0;$i<$count2;$i++){
142         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
143         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
144 }
145 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
146                         -values   => \@select_bookfund,
147                         -default  => $data->{'bookfundid'},
148                         -labels   => \%select_bookfunds,
149                         -size     => 1,
150                         -multiple => 0 );
151 my $bookfundname;
152 my $bookfundid;
153 if ($close){
154         $bookfundid=$data->{'bookfundid'};
155         $bookfundname= $select_bookfunds{$bookfundid};
156 }
157
158 #Build sort lists
159 my $CGIsort1 = buildCGIsort("Asort1","sort1",$data->{'sort1'});
160 if ($CGIsort1) {
161         $template->param(CGIsort1 => $CGIsort1);
162 } else {
163         $template->param( sort1 => $data->{'sort1'});
164 }
165
166 my $CGIsort2 = buildCGIsort("Asort2","sort2",$data->{'sort2'});
167 if ($CGIsort2) {
168         $template->param(CGIsort2 =>$CGIsort2);
169 } else {
170         $template->param( sort2 => $data->{'sort2'});
171 }
172
173 # fill template
174 $template->param( close=> $close, bookfundid=>$bookfundid, bookfundname=>$bookfundname) if ($close);
175
176
177 $template->param( existing => $biblio,
178                                                 title => $title,
179                                                 ordnum => $ordnum,
180                                                 basketno => $basketno,
181                                                 booksellerid => $booksellerid,
182                                                 suggestionid => $suggestionid,
183                                                 biblio => $biblio,
184                                                 biblioitemnumber => $data->{'biblioitemnumber'},
185                                                 itemtype => $data->{'itemtype'},
186                                                 discount => $booksellers[0]->{'discount'},
187                                                 listincgst => $booksellers[0]->{'listincgst'},
188                                                 listprice => $booksellers[0]->{'listprice'},
189                                                 gstreg => $booksellers[0]->{'gstreg'},
190                                                 invoiceinc => $booksellers[0]->{'invoiceincgst'},
191                                                 invoicedisc => $booksellers[0]->{'invoicedisc'},
192                                                 nocalc => $booksellers[0]->{'nocalc'},
193                                                 name => $booksellers[0]->{'name'},
194                                                 currency => $booksellers[0]->{'listprice'},
195                                                 gstrate => C4::Context->preference("gist") ,
196                                                 loop_currencies => \@loop_currency,
197                                                 orderexists => ($new eq 'yes')?0:1,
198                                                 title => $data->{'title'},
199                                                 author => $data->{'author'},
200                                                 copyrightdate => $data->{'copyrightdate'},
201                                                 CGIitemtype => $CGIitemtype,
202                                                 CGIbranch => $CGIbranch,
203                                                 CGIbookfund => $CGIbookfund,
204                                                 isbn => $data->{'isbn'},
205                                                 seriestitle => $data->{'seriestitle'},
206                                                 quantity => $data->{'quantity'},
207                                                 listprice => $data->{'listprice'},
208                                                 rrp => $data->{'rrp'},
209                                                 invoice => $data->{'booksellerinvoicenumber'},
210                                                 ecost => $data->{'ecost'},
211                                                 notes => $data->{'notes'},
212                                                 publishercode => $data->{'publishercode'});
213
214 output_html_with_http_headers $input, $cookie, $template->output;