warning the user about the redirect after the install has completed,
[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 daterecieved
51
52 =item catview
53
54 =item gst
55
56 =back
57
58 =cut
59
60 use strict;
61 use CGI;
62 use C4::Context;
63 use C4::Koha;   # GetKohaAuthorisedValues GetItemTypes
64 use C4::Acquisition;
65 use C4::Auth;
66 use C4::Output;
67 use C4::Date;
68 use C4::Bookseller;
69 use C4::Members;
70 use C4::Branch;    # GetBranches
71
72 my $input      = new CGI;
73 my $supplierid = $input->param('supplierid');
74 my $dbh        = C4::Context->dbh;
75
76 my $search       = $input->param('recieve');
77 my $invoice      = $input->param('invoice');
78 my $freight      = $input->param('freight');
79 my $biblionumber       = $input->param('biblionumber');
80 my $daterecieved = $input->param('daterecieved') || format_date(join "-",Date::Calc::Today());
81 my $catview      = $input->param('catview');
82 my $gst          = $input->param('gst');
83
84 my @results = SearchOrder( $search, $supplierid, $biblionumber, $catview );
85 my $count   = scalar @results;
86
87 my @booksellers = GetBookSeller( $results[0]->{'booksellerid'} );
88
89 my $date = $results[0]->{'entrydate'};
90
91 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
92     {
93         template_name   => "acqui/orderreceive.tmpl",
94         query           => $input,
95         type            => "intranet",
96         authnotrequired => 0,
97         flagsrequired   => { acquisition => 1 },
98         debug           => 1,
99     }
100 );
101 $template->param($count);
102
103 if ( $count == 1 ) {
104
105     my $itemtypes = GetItemTypes;
106     my @itemtypesloop;
107     foreach my $thisitemtype (sort keys %$itemtypes) {
108         my %row = (
109                     value => $thisitemtype,
110                     description => $itemtypes->{$thisitemtype}->{'description'},
111                   );
112         push @itemtypesloop, \%row;
113     }
114     
115     $template->param(itemtypeloop => \@itemtypesloop);
116
117
118     my $locations = GetKohaAuthorisedValues( 'items.location' );
119     if ($locations) {
120         my @location_codes = keys %$locations;
121         my $CGIlocation    = CGI::scrolling_list(
122             -name     => 'location',
123             -id       => 'location',
124             -values   => \@location_codes,
125             -default  => $results[0]->{'itemtype'},
126             -labels   => $locations,
127             -size     => 1,
128             -tabindex => '',
129             -multiple => 0
130         );
131         $template->param( CGIlocation => $CGIlocation );
132     }
133     my $onlymine=C4::Context->preference('IndependantBranches') && 
134                 C4::Context->userenv && 
135                 C4::Context->userenv->{flags} !=1  && 
136                 C4::Context->userenv->{branch};
137     my $branches = GetBranches($onlymine);
138     my @branchloop;
139     foreach my $thisbranch ( sort keys %$branches ) {
140         my %row = (
141             value      => $thisbranch,
142             branchname => $branches->{$thisbranch}->{'branchname'},
143         );
144         push @branchloop, \%row;
145     }
146
147     my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
148
149     # See whether barcodes should be automatically allocated.
150     # Defaults to 0, meaning "no".
151     my $barcode;
152     if ( $auto_barcode ) {
153         my $sth = $dbh->prepare("Select max(barcode) from items");
154         $sth->execute;
155         my $data = $sth->fetchrow_hashref;
156         $barcode = $results[0]->{'barcode'} + 1;
157         $sth->finish;
158     }
159
160     if ( $results[0]->{'quantityreceived'} == 0 ) {
161         $results[0]->{'quantityreceived'} = '';
162     }
163     if ( $results[0]->{'unitprice'} == 0 ) {
164         $results[0]->{'unitprice'} = '';
165     }
166     $results[0]->{'copyrightdate'} =
167       format_date( $results[0]->{'copyrightdate'} );
168     $template->param(
169         branchloop            => \@branchloop,
170         count                 => 1,
171         biblionumber          => $results[0]->{'biblionumber'},
172         ordernumber           => $results[0]->{'ordernumber'},
173         biblioitemnumber      => $results[0]->{'biblioitemnumber'},
174         supplierid            => $results[0]->{'booksellerid'},
175         freight               => $freight,
176         gst                   => $gst,
177         catview               => ( $catview ne 'yes' ? 1 : 0 ),
178         name                  => $booksellers[0]->{'name'},
179         date                  => format_date($date),
180         title                 => $results[0]->{'title'},
181         author                => $results[0]->{'author'},
182         copyrightdate         => format_date( $results[0]->{'copyrightdate'} ),
183         itemtype              => $results[0]->{'itemtype'},
184         isbn                  => $results[0]->{'isbn'},
185         seriestitle           => $results[0]->{'seriestitle'},
186         barcode               => $barcode,
187         bookfund              => $results[0]->{'bookfundid'},
188         quantity              => $results[0]->{'quantity'},
189         quantityreceivedplus1 => $results[0]->{'quantityreceived'} + 1,
190         quantityreceived      => $results[0]->{'quantityreceived'},
191         rrp                   => $results[0]->{'rrp'},
192         ecost                 => $results[0]->{'ecost'},
193         unitprice             => $results[0]->{'unitprice'},
194         invoice               => $invoice,
195         daterecieved          => $daterecieved,
196         notes                 => $results[0]->{'notes'},
197         intranetcolorstylesheet =>
198           C4::Context->preference("intranetcolorstylesheet"),
199         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
200         IntranetNav        => C4::Context->preference("IntranetNav"),
201     );
202 }
203 else {
204     my @loop;
205     for ( my $i = 0 ; $i < $count ; $i++ ) {
206         my %line = %{ $results[$i] };
207
208         $line{invoice}      = $invoice;
209         $line{daterecieved} = $daterecieved;
210         $line{freight}      = $freight;
211         $line{gst}          = $gst;
212         $line{title}        = $results[$i]->{'title'};
213         $line{author}       = $results[$i]->{'author'};
214         $line{supplierid}   = $supplierid;
215         push @loop, \%line;
216     }
217     $template->param(
218         loop                    => \@loop,
219         date                    => format_date($date),
220         daterecieved            => $daterecieved,
221         name                    => $booksellers[0]->{'name'},
222         supplierid              => $supplierid,
223         invoice                 => $invoice,
224         daterecieved            => $daterecieved,
225         intranetcolorstylesheet =>
226           C4::Context->preference("intranetcolorstylesheet"),
227         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
228         IntranetNav        => C4::Context->preference("IntranetNav"),
229     );
230
231 }
232 output_html_with_http_headers $input, $cookie, $template->output;