Patch to acqui system to use new newbiblioitem() parameters
[wip/koha-chris_n.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 use C4::Output;
7 use C4::Acquisitions;
8 use CGI;
9 use C4::Search;
10
11 my $input=new CGI;
12 #print $input->header;
13
14 my $user=$input->remote_user;
15 #print $input->dump;
16 my $biblionumber = $input->param('biblio');
17 my $ordnum=$input->param('ordnum');
18 my $quantrec=$input->param('quantityrec');
19 my $quantity=$input->param('quantity');
20 my $notes=$input->param('notes');
21 my $cost=$input->param('cost');
22 my $invoiceno=$input->param('invoice');
23 my $bibitemno=$input->param('biblioitemnum');
24 my $data=bibitemdata($bibitemno);
25 my $publisher=$data->{'publishercode'};
26 my $pubdate=$data->{'publicationdate'};
27 my $class=$data->{'classification'};
28 my $dewey=$data->{'dewey'};
29 my $subclass=$data->{'subclass'};
30
31 my $size=$data->{'size'};
32 my $illus=$data->{'illus'};
33 my $pages=$data->{'pages'};
34 my $replacement=$input->param('rrp');
35 my $branch=$input->param('branch');
36 my $bookfund=$input->param('bookfund');
37 my $itemtype=$input->param('format');
38 my $isbn=$input->param('ISBN');
39 my $bookseller = $input->param('bookseller');
40 my $id         = $bookseller;
41 my $biblio = {
42     biblionumber  => $biblionumber,
43     title         => $input->param('title')?$input->param('title'):"",
44     author        => $input->param('author')?$input->param('author'):"",
45     copyrightdate => $input->param('copyright')?$input->param('copyright'):"",
46     series        => $input->param('Series')?$input->param('Series'):""
47 }; # my $biblio
48
49 if ($quantrec != 0){
50   $cost=$cost / $quantrec;
51 }
52
53 my $gst=$input->param('gst');
54 my $freight=$input->param('freight');
55 my $volinf=$input->param('volinf');
56 my $loan=0;
57 if ($itemtype =~ /REF/){
58   $loan=1;
59 }
60
61 if ($itemtype =~ /PER/){
62 #  print "$bibitemno";
63   $class="Periodical";
64   $bibitemno = &newbiblioitem({
65       biblionumber   => $biblionumber,
66       itemtype       => $itemtype?$itemtype:"",
67       isbn           => $isbn?$isbn:"",
68       volumeddesc    => $volinf?$volinf:"",
69       classification => $class?$class:"" });
70 #  print "here $bibitemno";
71 }
72 if ($quantity != 0){
73   receiveorder($biblionumber,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund);
74   modbiblio($biblio);
75   &modbibitem({
76       biblioitemnumber => $bibitemno,
77       itemtype         => $itemtype?$itemtype:"",
78       isbn             => $isbn?$isbn:"",
79       publisher        => $publisher?$publisher:"",
80       publicationyear  => $pubdate?$pubdate:"",
81       class            => $class?$class:"",
82       dewey            => $dewey?$dewey:"",
83       subclass         => $subclass?$subclass:"",
84       illus            => $illus?$illus:"",
85       pages            => $pages?$pages:"",
86       volumeddesc      => $volinf?$volinf:"",
87       notes            => $notes?$notes:"",
88       size             => $size?$size:"" });
89
90   my $barcode=$input->param('barcode');
91   my @barcodes;
92   if ($barcode =~ /\,/){
93     @barcodes=split(/\,/,$barcode);
94   }elsif ($barcode =~ /\|/){
95     @barcodes=split(/\|/,$barcode);
96   } else {
97     $barcodes[0]=$barcode;
98   #  print $input->header;
99   #  print @barcodes;
100   #  print $barcode;
101   }
102   my ($error) = newitems({ biblioitemnumber => $bibitemno,
103                            biblionumber     => $biblionumber,
104                            replacementprice => $replacement,
105                            price            => $cost,
106                            booksellerid     => $bookseller,
107                            homebranch       => $branch,
108                            loan             => $loan },
109                          @barcodes);
110   if ($error eq ''){
111     if ($itemtype ne 'PER'){
112       print $input->redirect("/cgi-bin/koha/acqui/receive.pl?invoice=$invoiceno&id=$id&freight=$freight&gst=$gst");
113     } else {
114       print $input->redirect("/acquisitions/");
115     }
116   } else {
117     print $input->header;
118     print $error;
119   }
120 } else {
121   print $input->header;
122   delorder($biblionumber,$ordnum);
123        print $input->redirect("/acquisitions/");
124 }