Adding systempreference itemcallnumber support
[koha.git] / acqui / finishreceive.pl
1 #!/usr/bin/perl
2
3 #script to add a new item and to mark orders as received
4 #written 1/3/00 by chris@katipo.co.nz
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 # use warnings; # FIXME
25 use CGI;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Context;
29 use C4::Acquisition;
30 use C4::Biblio;
31 use C4::Items;
32 use C4::Search;
33
34 my $input = new CGI;
35 my $flagsrequired = { acquisition => 1 };
36 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired, 'intranet');
37 my $user             = $input->remote_user;     # FIXME: surely outmoded now
38 my $biblionumber     = $input->param('biblionumber');
39 my $biblioitemnumber = $input->param('biblioitemnumber');
40 my $ordnum           = $input->param('ordnum');
41 my $origquantityrec  = $input->param('origquantityrec');
42 my $quantityrec      = $input->param('quantityrec');
43 my $quantity         = $input->param('quantity');
44 my $cost             = $input->param('cost');
45 my $invoiceno        = $input->param('invoice');
46 my $datereceived     = $input->param('datereceived');
47 my $replacement      = $input->param('rrp');
48 my $gst              = $input->param('gst');
49 my $freight          = $input->param('freight');
50 my $supplierid       = $input->param('supplierid');
51 my @branch           = $input->param('homebranch');
52 my @barcode          = $input->param('barcode');
53 my @ccode            = $input->param('ccode');
54 my @itemtype         = $input->param('itemtype');
55 my @location         = $input->param('location');
56 my @enumchron        = $input->param('volinf');
57 my $cnt              = 0;
58 my $error_url_str;
59
60 if ($quantityrec > $origquantityrec) {
61     foreach my $bc (@barcode) {
62         if ($bc) {
63             my $item_hash = {
64                 "items.replacementprice" => $replacement,
65                 "items.price"            => $cost,
66                 "items.booksellerid"     => $supplierid,
67                 "items.homebranch"       => $branch[$cnt],
68                 "items.holdingbranch"    => $branch[$cnt],
69                 "items.barcode"          => $barcode[$cnt],
70                 "items.ccode"            => $ccode[$cnt],
71                 "items.itype"            => $itemtype[$cnt],
72                 "items.location"         => $location[$cnt],
73                 "items.enumchron"        => $enumchron[$cnt],    # FIXME : No integration here with serials module.
74                 "items.loan"             => 0,
75             };
76             $item_hash->{'items.cn_source'} = C4::Context->preference('DefaultClassificationSource') if (C4::Context->preference('DefaultClassificationSource'));
77
78             # FIXME : cn_sort is populated by Items::_set_derived_columns_for_add , which is never called with AddItemFromMarc .  Bug 2403
79             my $itemRecord = TransformKohaToMarc($item_hash);
80             $cnt++;
81             $item_hash = TransformMarcToKoha(undef, $itemRecord, '', 'items');
82
83             # FIXME: possible race condition.  duplicate barcode check should happen in AddItem, but for now we have to do it here.
84             my %err = CheckItemPreSave($item_hash);
85             if (%err) {
86                 for my $err_cnd (keys %err) {
87                     $error_url_str .= "&error=" . $err_cnd . "&error_param=" . $err{$err_cnd};
88                 }
89                 $quantityrec--;
90             } else {
91                 AddItemFromMarc($itemRecord, $biblionumber);
92             }
93         }
94     }
95
96     # save the quantity received.
97     if ($quantityrec > 0) {
98         $datereceived = ModReceiveOrder($biblionumber, $ordnum, $quantityrec, $user, $cost, $invoiceno, $freight, $replacement, undef, $datereceived);
99     }
100 }
101 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
102