newsubtitle called only if title exist
[wip/koha-chris_n.git] / acqui / addorder.pl
1 #!/usr/bin/perl
2
3 #script to add an order into the system
4 #written 29/2/00 by chris@katipo.co.nz
5
6 use strict;
7 use CGI;
8 use C4::Output;
9 use C4::Acquisitions;
10
11 my $input = new CGI;
12 my $existing=$input->param('existing');
13 my $title=$input->param('title');
14 $title=~ s/\'/\\\'/g;
15 my $author=$input->param('author');
16 $author=~ s/\'/\\\'/g;
17 my $copyright=$input->param('copyright');
18 my $isbn=$input->param('ISBN');
19 my $itemtype=$input->param('format');
20 my $ordnum=$input->param('ordnum');
21 my $basketno=$input->param('basket');
22 my $quantity=$input->param('quantity');
23 my $listprice=$input->param('list_price');
24 my $series=$input->param('Series');
25 if ($listprice eq ''){
26   $listprice=0;
27 }
28 my $supplier=$input->param('supplier');
29 my $notes=$input->param('notes');
30 my $bookfund=$input->param('bookfund');
31 my $who=$input->remote_user;
32 my $bibnum;
33 my $bibitemnum;
34 my $rrp=$input->param('rrp');
35 my $ecost=$input->param('ecost');
36 my $gst=$input->param('GST');
37 my $orderexists=$input->param('orderexists');
38
39 #check to see if biblio exists
40 if ($quantity ne '0'){
41
42   if ($existing eq 'no'){
43     #if it doesnt create it
44     $bibnum = &newbiblio({ title     => $title?$title:"",
45                            author    => $author?$author:"",
46                            copyright => $copyright?$copyright:"" });
47     $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
48                                    itemtype     => $itemtype?$itemtype:"",
49                                    isben        => $isbn?$isbn:"" });
50         if ($title) {
51                 newsubtitle($bibnum,$title);
52         }
53     modbiblio({ biblionumber  => $bibnum,
54                 title         => $title?$title:"",
55                 author        => $author?$author:"",
56                 copyrightdate => $copyright?$copyright:"",
57                 series        => $series?$series:"" });
58   } else {
59     $bibnum=$input->param('biblio');
60     $bibitemnum=$input->param('bibitemnum');
61     my $oldtype=$input->param('oldtype');
62     if ($bibitemnum eq '' || $itemtype ne $oldtype){
63       $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
64                                                          itemtype => $itemtype?$itemtype:"",
65                                                          isben => $isbn?$isbn:"" });
66     }
67     &modbiblio({
68         biblionumber  => $bibnum,
69         title         => $title?$title:"",
70         author        => $author?$author:"",
71         copyrightdate => $copyright?$copyright:"",
72         series        => $series?$series:"" });
73   }
74   if ($orderexists ne '') {
75     modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
76   }else {
77     neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
78   }
79 } else {
80   $bibnum=$input->param('biblio');
81   delorder($bibnum,$ordnum);
82 }
83
84 print $input->redirect("newbasket.pl?id=$supplier&basket=$basketno");