bugfixes + adding buttons to switch between normal and MARC view of a record
[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 $biblio = {
57         biblionumber  => $biblionumber,
58         title         => $input->param('title')?$input->param('title'):"",
59         author        => $input->param('author')?$input->param('author'):"",
60         copyrightdate => $input->param('copyright')?$input->param('copyright'):"",
61         series        => $input->param('Series')?$input->param('Series'):""
62 }; # my $biblio
63
64 if ($quantrec != 0){
65         $cost /= $quantrec;
66 }
67
68 my $gst=$input->param('gst');
69 my $freight=$input->param('freight');
70 my $volinf=$input->param('volinf');
71 my $id = $input->param('id');
72 my $loan=0;
73 if ($itemtype =~ /REF/){
74         $loan=1;
75 }
76
77 if ($itemtype =~ /PER/){
78         $class="Periodical";
79         $bibitemno = &newbiblioitem({
80                 biblionumber   => $biblionumber,
81                 itemtype       => $itemtype?$itemtype:"",
82                 isbn           => $isbn?$isbn:"",
83                 volumeddesc    => $volinf?$volinf:"",
84                 classification => $class?$class:"" });
85 }
86 if ($quantity != 0){
87         warn "receive : $biblionumber,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund";
88         receiveorder($biblionumber,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund);
89         modbiblio($biblio);
90         &modbibitem({
91                 biblioitemnumber => $bibitemno,
92                 biblionumber     => $biblionumber,
93                 itemtype         => $itemtype?$itemtype:"",
94                 isbn             => $isbn?$isbn:"",
95                 publisher        => $publisher?$publisher:"",
96                 publicationyear  => $pubdate?$pubdate:"",
97                 class            => $class?$class:"",
98                 dewey            => $dewey?$dewey:"",
99                 subclass         => $subclass?$subclass:"",
100                 illus            => $illus?$illus:"",
101                 pages            => $pages?$pages:"",
102                 volumeddesc      => $volinf?$volinf:"",
103                 notes            => $notes?$notes:"",
104                 size             => $size?$size:"" });
105         my $barcode=$input->param('barcode');
106         my @barcodes;
107 #       if ($barcode =~ /\,/){
108                 @barcodes=split(/\,| |\|/,$barcode);
109 #       }elsif ($barcode =~ /\|/){
110 #               @barcodes=split(/\|/,$barcode);
111 #       } else {
112 #               $barcodes[0]=$barcode;
113 #       }
114         my ($error) = newitems({ biblioitemnumber => $bibitemno,
115                                         biblionumber     => $biblionumber,
116                                         replacementprice => $replacement,
117                                         price            => $cost,
118                                         booksellerid     => $id,
119                                         homebranch       => $branch,
120                                         loan             => $loan },
121                                 @barcodes);
122         if ($error eq ''){
123                 if ($itemtype ne 'PER'){
124                         print $input->redirect("/cgi-bin/koha/acqui/receive.pl?invoice=$invoiceno&id=$id&freight=$freight&gst=$gst");
125                 } else {
126                         print $input->redirect("/acquisitions/");
127                 }
128         } else {
129                 print $input->header;
130                 print $error;
131         }
132 } else {
133         print $input->header;
134         delorder($biblionumber,$ordnum);
135         print $input->redirect("/acquisitions/");
136 }