Bug 5466 On new orders get currency from vendor
[koha.git] / reserve / placerequest.pl
1 #!/usr/bin/perl
2
3 #script to place reserves/requests
4 #writen 2/1/00 by chris@katipo.oc.nz
5
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 use strict;
25 use warnings;
26
27 use CGI;
28 use C4::Biblio;
29 use C4::Items;
30 use C4::Output;
31 use C4::Reserves;
32 use C4::Circulation;
33 use C4::Members;
34 use C4::Auth qw/checkauth/;
35
36 my $input = CGI->new();
37
38 my ($user, $cookie, $sesion_id, $flags) = checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
39
40 my @bibitems=$input->param('biblioitem');
41 # FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
42 #       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
43 #       we can remove this line, the AddReserve of constrainttype 'o',
44 #       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
45 my @reqbib=$input->param('reqbib'); 
46 my $biblionumber=$input->param('biblionumber');
47 my $borrower=$input->param('member');
48 my $notes=$input->param('notes');
49 my $branch=$input->param('pickup');
50 my $startdate=$input->param('reserve_date') || '';
51 my @rank=$input->param('rank-request');
52 my $type=$input->param('type');
53 my $title=$input->param('title');
54 my $borrowernumber=GetMember('cardnumber'=>$borrower);
55 my $checkitem=$input->param('checkitem');
56 my $expirationdate = $input->param('expiration_date');
57
58 my $multi_hold = $input->param('multi_hold');
59 my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/');
60 my $bad_bibs = $input->param('bad_bibs');
61
62 my %bibinfos = ();
63 my @biblionumbers = split '/', $biblionumbers;
64 foreach my $bibnum (@biblionumbers) {
65     my %bibinfo = ();
66     $bibinfo{title} = $input->param("title_$bibnum");
67     $bibinfo{rank} = $input->param("rank_$bibnum");
68     $bibinfos{$bibnum} = \%bibinfo;
69 }
70
71 my $found;
72
73 # if we have an item selectionned, and the pickup branch is the same as the holdingbranch
74 # of the document, we force the value $rank and $found .
75 if ($checkitem ne ''){
76     $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
77     my $item = $checkitem;
78     $item = GetItem($item);
79     if ( $item->{'holdingbranch'} eq $branch ){
80         $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
81     }
82 }
83
84 if ($type eq 'str8' && $borrowernumber ne ''){
85
86     foreach my $biblionumber (keys %bibinfos) {
87         my $count=@bibitems;
88         @bibitems=sort @bibitems;
89         my $i2=1;
90         my @realbi;
91         $realbi[0]=$bibitems[0];
92         for (my $i=1;$i<$count;$i++) {
93             my $i3=$i2-1;
94             if ($realbi[$i3] ne $bibitems[$i]) {
95                 $realbi[$i2]=$bibitems[$i];
96                 $i2++;
97             }
98         }
99         my $const;
100
101         if ($multi_hold) {
102             my $bibinfo = $bibinfos{$biblionumber};
103             AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'a',[$biblionumber],
104                        $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
105         } else {
106             if ($input->param('request') eq 'any'){
107                 # place a request on 1st available
108                 AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
109             } elsif ($reqbib[0] ne ''){
110                 # FIXME : elsif probably never reached, (see top of the script)
111                 # place a request on a given item
112                 AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'o',\@reqbib,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
113             } else {
114                 AddReserve($branch,$borrowernumber->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
115             }
116         }
117     }
118
119     if ($multi_hold) {
120         if ($bad_bibs) {
121             $biblionumbers .= $bad_bibs;
122         }
123         print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
124     } else {
125         print $input->redirect("request.pl?biblionumber=$biblionumber");
126     }
127 } elsif ($borrowernumber eq ''){
128         print $input->header();
129         print "Invalid card number please try again";
130         print $input->Dump;
131 }