replacing links to bookfunds into budgets
[koha.git] / acqui / orderreceive.pl
blobbcf6f7476927bb6039dc6e197b58456dfda1f5e9
1 #!/usr/bin/perl
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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.
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.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 NAME
26 orderreceive.pl
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'.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item supplierid
37 to know on what supplier this script has to display receive order.
39 =item receive
41 =item invoice
42 the number of this invoice.
44 =item freight
46 =item biblio
47 The biblionumber of this order.
49 =item datereceived
51 =item catview
53 =item gst
55 =back
57 =cut
59 use strict;
60 # use warnings; # FIXME
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;
75 my $input = new CGI;
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');
86 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
88 my $bookseller = GetBookSellerFromId($supplierid);
89 my $gst= $input->param('gst') || $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
90 my $results = SearchOrder($ordernumber,$search);
93 my $count = scalar @$results;
94 my $order = GetOrder($ordernumber);
97 my $date = @$results[0]->{'entrydate'};
99 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101 template_name => "acqui/orderreceive.tmpl",
102 query => $input,
103 type => "intranet",
104 authnotrequired => 0,
105 flagsrequired => {acquisition => 'order_receive'},
106 debug => 1,
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();
115 my @itemloop;
116 push @itemloop,$cell;
118 $template->param(items => \@itemloop);
121 if ( @$results[0]->{'quantityreceived'} == 0 ) {
122 @$results[0]->{'quantityreceived'} = '';
124 if ( @$results[0]->{'unitprice'} == 0 ) {
125 @$results[0]->{'unitprice'} = '';
127 $template->param(
128 count => 1,
129 biblionumber => @$results[0]->{'biblionumber'},
130 ordernumber => @$results[0]->{'ordernumber'},
131 biblioitemnumber => @$results[0]->{'biblioitemnumber'},
132 supplierid => @$results[0]->{'booksellerid'},
133 freight => $freight,
134 gst => $gst,
135 name => $bookseller->{'name'},
136 date => format_date($date),
137 title => @$results[0]->{'title'},
138 author => @$results[0]->{'author'},
139 copyrightdate => @$results[0]->{'copyrightdate'},
140 isbn => @$results[0]->{'isbn'},
141 seriestitle => @$results[0]->{'seriestitle'},
142 bookfund => @$results[0]->{'bookfundid'},
143 quantity => @$results[0]->{'quantity'},
144 quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
145 quantityreceived => @$results[0]->{'quantityreceived'},
146 rrp => @$results[0]->{'rrp'},
147 ecost => @$results[0]->{'ecost'},
148 unitprice => @$results[0]->{'unitprice'},
149 invoice => $invoice,
150 datereceived => $datereceived->output(),
151 datereceived_iso => $datereceived->output('iso'),
152 notes => $order->{notes}
155 else {
156 my @loop;
157 for ( my $i = 0 ; $i < $count ; $i++ ) {
158 my %line = %{ @$results[$i] };
160 $line{invoice} = $invoice;
161 $line{datereceived} = $datereceived->output();
162 $line{freight} = $freight;
163 $line{gst} = $gst;
164 $line{title} = @$results[$i]->{'title'};
165 $line{author} = @$results[$i]->{'author'};
166 $line{supplierid} = $supplierid;
167 push @loop, \%line;
170 $template->param(
171 loop => \@loop,
172 supplierid => $supplierid,
175 my $op = $input->param('op');
176 if ($op eq 'edit'){
177 $template->param(edit => 1);
179 output_html_with_http_headers $input, $cookie, $template->output;