Managing branch independancy when creating a new biblio.
[koha.git] / acqui / acquire.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to recieve orders
6 #written by chris@katipo.co.nz 24/2/2000
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25 use strict;
26 use CGI;
27 use C4::Context;
28 use C4::Acquisition;
29 use C4::Biblio;
30 use C4::Output;
31 use C4::Search;
32 use C4::Auth;
33 use C4::Interface::CGI::Output;
34 use C4::Database;
35 use HTML::Template;
36 use C4::Date;
37
38 my $input=new CGI;
39 my $supplierid=$input->param('supplierid');
40 my $dbh = C4::Context->dbh;
41
42 my $search=$input->param('recieve');
43 my $invoice=$input->param('invoice');
44 my $freight=$input->param('freight');
45 my $biblio=$input->param('biblio');
46 my $catview=$input->param('catview');
47 my $gst=$input->param('gst');
48 my ($count,@results)=ordersearch($search,$supplierid,$biblio,$catview);
49 # warn "C:$count for ordersearch($search,$supplierid,$biblio,$catview);";
50 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'});
51 my $date = $results[0]->{'entrydate'};
52
53 my ($template, $loggedinuser, $cookie)
54     = get_template_and_user({template_name => "acqui/acquire.tmpl",
55                              query => $input,
56                              type => "intranet",
57                              authnotrequired => 0,
58                              flagsrequired => {acquisition => 1},
59                              debug => 1,
60                              });
61 $template->param($count);
62 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
63 $sthtemp->execute($loggedinuser);
64 my ($flags, $homebranch)=$sthtemp->fetchrow;
65
66 if ($count == 1){
67         my $sth;
68 #       my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
69 #       $sth->execute;
70 #       my  @itemtype;
71 #       my %itemtypes;
72 #       push @itemtype, "";
73 #       $itemtypes{''} = "Please choose";
74 #       while (my ($value,$lib) = $sth->fetchrow_array) {
75 #               push @itemtype, $value;
76 #               $itemtypes{$value}=$lib;
77 #       }
78
79 #       my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
80 #                               -values   => \@itemtype,
81 #                               -default  => $results[0]->{'itemtype'},
82 #                               -labels   => \%itemtypes,
83 #                               -size     => 1,
84 #                               -multiple => 0 );
85 #       $sth->finish;
86
87         my @branches;
88         my @select_branch;
89         my %select_branches;
90         my ($count2,@branches)=branches();
91         for (my $i=0;$i<$count2;$i++){
92                 push @select_branch, $branches[$i]->{'branchcode'};#
93                 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
94         }
95         my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
96                                 -values   => \@select_branch,
97                                 -default  => $results[0]->{'branchcode'},
98                                 -labels   => \%select_branches,
99                                 -size     => 1,
100                                 -multiple => 0 );
101
102         my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
103                 # See whether barcodes should be automatically allocated.
104                 # Defaults to 0, meaning "no".
105         my $barcode;
106         if ($auto_barcode eq '1') {
107                 $sth=$dbh->prepare("Select max(barcode) from items");
108                 $sth->execute;
109                 my $data=$sth->fetchrow_hashref;
110                 $barcode = $results[0]->{'barcode'}+1;
111                 $sth->finish;
112         }
113
114 #       my @bookfund;
115 #       my @select_bookfund;
116 #       my %select_bookfunds;
117 #       ($count2,@bookfund)=bookfunds();
118 #       for (my $i=0;$i<$count2;$i++){
119 #               push @select_bookfund, $bookfund[$i]->{'bookfundid'};
120 #               $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
121 #       }
122 #       my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
123 #                               -values   => \@select_bookfund,
124 #                               -default  => $results[0]->{'bookfundid'},
125 #                               -labels   => \%select_bookfunds,
126 #                               -size     => 1,
127 #                               -multiple => 0 );
128
129         if ($results[0]->{'quantityreceived'} == 0){
130         $results[0]->{'quantityreceived'}='';
131         }
132         if ($results[0]->{'unitprice'} == 0){
133         $results[0]->{'unitprice'}='';
134         }
135         $template->param(
136                 count => 1,
137                 biblionumber => $results[0]->{'biblionumber'},
138                 ordernumber => $results[0]->{'ordernumber'},
139                 biblioitemnumber => $results[0]->{'biblioitemnumber'},
140                 supplierid => $results[0]->{'booksellerid'},
141                 freight => $freight,
142                 gst => $gst,
143                 catview => ($catview ne 'yes'?1:0),
144                 name => $booksellers[0]->{'name'},
145                 date => format_date($date),
146                 title => $results[0]->{'title'},
147                 author => $results[0]->{'author'},
148                 copyrightdate => format_date($results[0]->{'copyrightdate'}),
149                 itemtype => $results[0]->{'itemtype'},
150                 CGIbranch => $CGIbranch,
151                 isbn => $results[0]->{'isbn'},
152                 seriestitle => $results[0]->{'seriestitle'},
153                 barcode => $barcode,
154                 bookfund => $results[0]->{'bookfundid'},
155                 quantity => $results[0]->{'quantity'},
156                 quantityreceived => $results[0]->{'quantityreceived'},
157                 rrp => $results[0]->{'rrp'},
158                 ecost => $results[0]->{'ecost'},
159                 unitprice => $results[0]->{'unitprice'},
160                 invoice => $invoice,
161                 notes => $results[0]->{'notes'},
162         );
163 } else {
164         my @loop;
165         for (my $i=0;$i<$count;$i++){
166                 my %line;
167                 $line{isbn} = $results[$i]->{'isbn'};
168                 $line{basketno} = $results[$i]->{'basketno'};
169                 $line{quantity} = $results[$i]->{'quantity'};
170                 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
171                 $line{ordernumber} = $results[$i]->{'ordernumber'};
172                 $line{biblionumber} = $results[$i]->{'biblionumber'};
173                 $line{invoice} = $invoice;
174                 $line{freight} = $freight;
175                 $line{gst} = $gst;
176                 $line{title} = $results[$i]->{'title'};
177                 $line{author} = $results[$i]->{'author'};
178                 $line{supplierid} = $supplierid;
179                 push @loop,\%line;
180         }
181         $template->param( loop => \@loop,
182                                                 date => format_date($date),
183                                                 name => $booksellers[0]->{'name'},
184                                                 supplierid => $supplierid,
185                                                 invoice => $invoice,
186 );
187
188 }
189 output_html_with_http_headers $input, $cookie, $template->output;