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