add new lenny dependency libmodule-install-perl to the apt-get-debian-lenny.sh script
[koha.git] / acqui / orderreceive.pl
1 #!/usr/bin/perl
2
3
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
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
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 =head1 NAME
25
26 orderreceive.pl
27
28 =head1 DESCRIPTION
29 This script shows all order already receive and all pendings orders.
30 It permit to write a new order as 'received'.
31
32 =head1 CGI PARAMETERS
33
34 =over 4
35
36 =item supplierid
37 to know on what supplier this script has to display receive order.
38
39 =item receive
40
41 =item invoice
42 the number of this invoice.
43
44 =item freight
45
46 =item biblio
47 The biblionumber of this order.
48
49 =item datereceived
50
51 =item catview
52
53 =item gst
54
55 =back
56
57 =cut
58
59 use strict;
60 #use warnings; FIXME - Bug 2505
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::Dates qw/format_date/;
68 use C4::Bookseller;
69 use C4::Members;
70 use C4::Branch;    # GetBranches
71 use C4::Items;
72 use C4::Biblio;
73
74
75 my $input      = new CGI;
76
77 my $dbh          = C4::Context->dbh;
78 my $supplierid   = $input->param('supplierid');
79 my $ordernumber       = $input->param('ordernumber');
80 my $search       = $input->param('receive');
81 my $invoice      = $input->param('invoice');
82 my $freight      = $input->param('freight');
83 my $datereceived = $input->param('datereceived');
84
85
86 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
87
88 my $bookseller = GetBookSellerFromId($supplierid);
89 my $gst= $input->param('gst') || $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
90 my $results = SearchOrder($ordernumber,$search);
91
92
93 my $count   = scalar @$results;
94 my $order       = GetOrder($ordernumber);
95
96
97 my $date = @$results[0]->{'entrydate'};
98
99 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
100     {
101         template_name   => "acqui/orderreceive.tmpl",
102         query           => $input,
103         type            => "intranet",
104         authnotrequired => 0,
105         flagsrequired   => {acquisition => 'order_receive'},
106         debug           => 1,
107     }
108 );
109
110 # prepare the form for receiving
111 if ( $count == 1 ) {
112     if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
113         # prepare empty item form
114         my $cell = PrepareItemrecordDisplay('','','','ACQ');
115         unless ($cell) {
116             $cell = PrepareItemrecordDisplay('','','','');
117             $template->param('NoACQframework' => 1);
118         }
119         my @itemloop;
120         push @itemloop,$cell;
121         
122         $template->param(items => \@itemloop);
123     }
124
125     if ( @$results[0]->{'quantityreceived'} == 0 ) {
126         @$results[0]->{'quantityreceived'} = '';
127     }
128     if ( @$results[0]->{'unitprice'} == 0 ) {
129         @$results[0]->{'unitprice'} = '';
130     }
131     $template->param(
132         count                 => 1,
133         biblionumber          => @$results[0]->{'biblionumber'},
134         ordernumber           => @$results[0]->{'ordernumber'},
135         biblioitemnumber      => @$results[0]->{'biblioitemnumber'},
136         supplierid            => @$results[0]->{'booksellerid'},
137         freight               => $freight,
138         gst                   => $gst,
139         name                  => $bookseller->{'name'},
140         date                  => format_date($date),
141         title                 => @$results[0]->{'title'},
142         author                => @$results[0]->{'author'},
143         copyrightdate         => @$results[0]->{'copyrightdate'},
144         isbn                  => @$results[0]->{'isbn'},
145         seriestitle           => @$results[0]->{'seriestitle'},
146         bookfund              => @$results[0]->{'bookfundid'},
147         quantity              => @$results[0]->{'quantity'},
148         quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
149         quantityreceived      => @$results[0]->{'quantityreceived'},
150         rrp                   => @$results[0]->{'rrp'},
151         ecost                 => @$results[0]->{'ecost'},
152         unitprice             => @$results[0]->{'unitprice'},
153         invoice               => $invoice,
154         datereceived          => $datereceived->output(),
155         datereceived_iso          => $datereceived->output('iso'),
156         notes                       =>              $order->{notes}
157     );
158 }
159 else {
160     my @loop;
161     for ( my $i = 0 ; $i < $count ; $i++ ) {
162         my %line = %{ @$results[$i] };
163
164         $line{invoice}      = $invoice;
165         $line{datereceived} = $datereceived->output();
166         $line{freight}      = $freight;
167         $line{gst}          = $gst;
168         $line{title}        = @$results[$i]->{'title'};
169         $line{author}       = @$results[$i]->{'author'};
170         $line{supplierid}   = $supplierid;
171         push @loop, \%line;
172     }
173
174     $template->param(
175         loop         => \@loop,
176         supplierid   => $supplierid,
177     );
178 }
179 my $op = $input->param('op');
180 if ($op eq 'edit'){
181     $template->param(edit   =>   1);
182 }
183 output_html_with_http_headers $input, $cookie, $template->output;