merging of rel-1-2 and main branch
[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 #use Date::Manip;
11
12 my $input = new CGI;
13 #print $input->header;
14 #print startpage();
15 #print startmenu('acquisitions');
16 #print $input->dump;
17 my $existing=$input->param('existing');
18 my $title=$input->param('title');
19 $title=~ s/\'/\\\'/g;
20 my $author=$input->param('author');
21 $author=~ s/\'/\\\'/g;
22 my $copyright=$input->param('copyright');
23 my $isbn=$input->param('ISBN');
24 my $itemtype=$input->param('format');
25 my $ordnum=$input->param('ordnum');
26 my $basketno=$input->param('basket');
27 my $quantity=$input->param('quantity');
28 my $listprice=$input->param('list_price');
29 my $series=$input->param('Series');
30 if ($listprice eq ''){
31   $listprice=0;
32 }
33 my $supplier=$input->param('supplier');
34 my $notes=$input->param('notes');
35 my $bookfund=$input->param('bookfund');
36 my $who=$input->remote_user;
37 my $bibnum;
38 my $bibitemnum;
39 my $rrp=$input->param('rrp');
40 my $ecost=$input->param('ecost');
41 my $gst=$input->param('GST');
42 my $orderexists=$input->param('orderexists');
43
44 #check to see if biblio exists
45 if ($quantity ne '0'){
46
47   if ($existing eq 'no'){
48     #if it doesnt create it
49     $bibnum = &newbiblio({ title     => $title?$title:"",
50                            author    => $author?$author:"",
51                            copyright => $copyright?$copyright:"",
52                                     series => $series?$series:"",
53                                      });
54     $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
55                                    itemtype     => $itemtype?$itemtype:"",
56                                    isbn        => $isbn?$isbn:""
57                                                    });
58         if ($title) {
59                 newsubtitle($bibnum,$title);
60         }
61 #unuseful (already added 4 line before
62 #     modbiblio({ biblionumber  => $bibnum,
63 #               title         => $title?$title:"",
64 #               author        => $author?$author:"",
65 #               copyrightdate => $copyright?$copyright:"",
66 #               series        => $series?$series:"" });
67   } else {
68     $bibnum=$input->param('biblio');
69     $bibitemnum=$input->param('bibitemnum');
70     my $oldtype=$input->param('oldtype');
71     if ($bibitemnum eq '' || $itemtype ne $oldtype){
72       $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
73                                                          itemtype => $itemtype?$itemtype:"",
74                                                          isbn => $isbn?$isbn:"" });
75     }
76     &modbiblio({
77         biblionumber  => $bibnum,
78         title         => $title?$title:"",
79         author        => $author?$author:"",
80         copyrightdate => $copyright?$copyright:"",
81         series        => $series?$series:"" });
82   }
83   if ($orderexists ne '') {
84     modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
85   }else {
86     neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
87   }
88 } else {
89   $bibnum=$input->param('biblio');
90   delorder($bibnum,$ordnum);
91 }
92
93 print $input->redirect("newbasket.pl?id=$supplier&basket=$basketno");