Merging Katipo changes
[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::Koha;
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32 use C4::Date;
33
34 my $input=new CGI;
35 my $supplierid=$input->param('supplierid');
36 my $dbh = C4::Context->dbh;
37
38 my $search=$input->param('recieve');
39 my $invoice=$input->param('invoice');
40 my $freight=$input->param('freight');
41 my $biblio=$input->param('biblio');
42 my $catview=$input->param('catview');
43 my $gst=$input->param('gst');
44 my ($count,@results)=ordersearch($search,$supplierid,$biblio,$catview);
45 # warn "C:$count for ordersearch($search,$supplierid,$biblio,$catview);";
46 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'});
47 my $date = $results[0]->{'entrydate'};
48
49 my ($template, $loggedinuser, $cookie)
50     = get_template_and_user({template_name => "acqui/acquire.tmpl",
51                              query => $input,
52                              type => "intranet",
53                              authnotrequired => 0,
54                              flagsrequired => {acquisition => 1},
55                              debug => 1,
56                              });
57 $template->param($count);
58 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
59 $sthtemp->execute($loggedinuser);
60 my ($flags, $homebranch)=$sthtemp->fetchrow;
61
62 if ($count == 1){
63         my $sth;
64
65         my $branches = getbranches;
66         my @branchloop;
67         foreach my $thisbranch (sort keys %$branches) {
68                 my %row =(value => $thisbranch,
69                                         branchname => $branches->{$thisbranch}->{'branchname'},
70                                 );
71                 push @branchloop, \%row;
72         }
73
74         my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
75                 # See whether barcodes should be automatically allocated.
76                 # Defaults to 0, meaning "no".
77         my $barcode;
78         if ($auto_barcode eq '1') {
79                 $sth=$dbh->prepare("Select max(barcode) from items");
80                 $sth->execute;
81                 my $data=$sth->fetchrow_hashref;
82                 $barcode = $results[0]->{'barcode'}+1;
83                 $sth->finish;
84         }
85
86         if ($results[0]->{'quantityreceived'} == 0){
87         $results[0]->{'quantityreceived'}='';
88         }
89         if ($results[0]->{'unitprice'} == 0){
90         $results[0]->{'unitprice'}='';
91         }
92         $template->param(
93                 branchloop => \@branchloop,
94                 count => 1,
95                 biblionumber => $results[0]->{'biblionumber'},
96                 ordernumber => $results[0]->{'ordernumber'},
97                 biblioitemnumber => $results[0]->{'biblioitemnumber'},
98                 supplierid => $results[0]->{'booksellerid'},
99                 freight => $freight,
100                 gst => $gst,
101                 catview => ($catview ne 'yes'?1:0),
102                 name => $booksellers[0]->{'name'},
103                 date => format_date($date),
104                 title => $results[0]->{'title'},
105                 author => $results[0]->{'author'},
106                 copyrightdate => format_date($results[0]->{'copyrightdate'}),
107                 itemtype => $results[0]->{'itemtype'},
108                 isbn => $results[0]->{'isbn'},
109                 seriestitle => $results[0]->{'seriestitle'},
110                 barcode => $barcode,
111                 bookfund => $results[0]->{'bookfundid'},
112                 quantity => $results[0]->{'quantity'},
113                 quantityreceived => $results[0]->{'quantityreceived'},
114                 rrp => $results[0]->{'rrp'},
115                 ecost => $results[0]->{'ecost'},
116                 unitprice => $results[0]->{'unitprice'},
117                 invoice => $invoice,
118                 notes => $results[0]->{'notes'},
119         );
120 } else {
121         my @loop;
122         for (my $i=0;$i<$count;$i++){
123                 my %line;
124                 $line{isbn} = $results[$i]->{'isbn'};
125                 $line{basketno} = $results[$i]->{'basketno'};
126                 $line{quantity} = $results[$i]->{'quantity'};
127                 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
128                 $line{ordernumber} = $results[$i]->{'ordernumber'};
129                 $line{biblionumber} = $results[$i]->{'biblionumber'};
130                 $line{invoice} = $invoice;
131                 $line{freight} = $freight;
132                 $line{gst} = $gst;
133                 $line{title} = $results[$i]->{'title'};
134                 $line{author} = $results[$i]->{'author'};
135                 $line{supplierid} = $supplierid;
136                 push @loop,\%line;
137         }
138         $template->param( loop => \@loop,
139                                                 date => format_date($date),
140                                                 name => $booksellers[0]->{'name'},
141                                                 supplierid => $supplierid,
142                                                 invoice => $invoice,
143 );
144
145 }
146 output_html_with_http_headers $input, $cookie, $template->output;