road to 1.9.2 :
[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
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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use C4::Output;
25 use C4::Catalogue;
26 use C4::Biblio;
27 use CGI;
28 use C4::Search;
29
30 my $input=new CGI;
31
32 my $user=$input->remote_user;
33 my $biblionumber = $input->param('biblio');
34 my $ordnum=$input->param('ordnum');
35 my $quantrec=$input->param('quantityrec');
36 my $quantity=$input->param('quantity');
37 my $notes=$input->param('notes');
38 my $cost=$input->param('cost');
39 my $invoiceno=$input->param('invoice');
40 my $bibitemno=$input->param('biblioitemnum');
41 my $data=bibitemdata($bibitemno);
42 my $publisher=$data->{'publishercode'};
43 my $pubdate=$data->{'publicationdate'};
44 my $class=$data->{'classification'};
45 my $dewey=$data->{'dewey'};
46 my $subclass=$data->{'subclass'};
47
48 my $size=$data->{'size'};
49 my $illus=$data->{'illus'};
50 my $pages=$data->{'pages'};
51 my $replacement=$input->param('rrp');
52 my $branch=$input->param('branch');
53 my $bookfund=$input->param('bookfund');
54 my $itemtype=$input->param('format');
55 my $isbn=$input->param('ISBN');
56 my $bookseller = $input->param('bookseller');
57 my $id         = $bookseller;
58 my $biblio = {
59         biblionumber  => $biblionumber,
60         title         => $input->param('title')?$input->param('title'):"",
61         author        => $input->param('author')?$input->param('author'):"",
62         copyrightdate => $input->param('copyright')?$input->param('copyright'):"",
63         series        => $input->param('Series')?$input->param('Series'):""
64 }; # my $biblio
65
66 if ($quantrec != 0){
67         $cost /= $quantrec;
68 }
69
70 my $gst=$input->param('gst');
71 my $freight=$input->param('freight');
72 my $volinf=$input->param('volinf');
73 my $loan=0;
74 if ($itemtype =~ /REF/){
75         $loan=1;
76 }
77
78 if ($itemtype =~ /PER/){
79         $class="Periodical";
80         $bibitemno = &newbiblioitem({
81                 biblionumber   => $biblionumber,
82                 itemtype       => $itemtype?$itemtype:"",
83                 isbn           => $isbn?$isbn:"",
84                 volumeddesc    => $volinf?$volinf:"",
85                 classification => $class?$class:"" });
86 }
87 warn "qty : $quantity";
88 if ($quantity != 0){
89         receiveorder($biblionumber,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund);
90         modbiblio($biblio);
91         &modbibitem({
92                 biblioitemnumber => $bibitemno,
93                 biblionumber     => $biblionumber,
94                 itemtype         => $itemtype?$itemtype:"",
95                 isbn             => $isbn?$isbn:"",
96                 publisher        => $publisher?$publisher:"",
97                 publicationyear  => $pubdate?$pubdate:"",
98                 class            => $class?$class:"",
99                 dewey            => $dewey?$dewey:"",
100                 subclass         => $subclass?$subclass:"",
101                 illus            => $illus?$illus:"",
102                 pages            => $pages?$pages:"",
103                 volumeddesc      => $volinf?$volinf:"",
104                 notes            => $notes?$notes:"",
105                 size             => $size?$size:"" });
106         my $barcode=$input->param('barcode');
107         my @barcodes;
108         if ($barcode =~ /\,/){
109                 @barcodes=split(/\,/,$barcode);
110         }elsif ($barcode =~ /\|/){
111                 @barcodes=split(/\|/,$barcode);
112         } else {
113                 $barcodes[0]=$barcode;
114         }
115         my ($error) = newitems({ biblioitemnumber => $bibitemno,
116                                         biblionumber     => $biblionumber,
117                                         replacementprice => $replacement,
118                                         price            => $cost,
119                                         booksellerid     => $bookseller,
120                                         homebranch       => $branch,
121                                         loan             => $loan },
122                                 @barcodes);
123         if ($error eq ''){
124         if ($itemtype ne 'PER'){
125                 print $input->redirect("/cgi-bin/koha/acqui/receive.pl?invoice=$invoiceno&id=$id&freight=$freight&gst=$gst");
126         } else {
127                 print $input->redirect("/acquisitions/");
128         }
129         } else {
130                 print $input->header;
131                 print $error;
132         }
133 } else {
134         print $input->header;
135         delorder($biblionumber,$ordnum);
136         print $input->redirect("/acquisitions/");
137 }