long is the road to 1.4.0
[koha.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
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 strict;
25 use CGI;
26 use C4::Output;
27 use C4::Catalogue;
28 use C4::Biblio;
29 #use Date::Manip;
30
31 my $input = new CGI;
32 #print $input->header;
33 #print startpage();
34 #print startmenu('acquisitions');
35 #print $input->dump;
36 my $existing=$input->param('existing');
37 my $title=$input->param('title');
38 $title=~ s/\'/\\\'/g;
39 my $author=$input->param('author');
40 $author=~ s/\'/\\\'/g;
41 my $copyright=$input->param('copyright');
42 my $isbn=$input->param('ISBN');
43 my $itemtype=$input->param('format');
44 my $ordnum=$input->param('ordnum');
45 my $basketno=$input->param('basket');
46 my $quantity=$input->param('quantity');
47 my $listprice=$input->param('list_price');
48 my $series=$input->param('Series');
49 if ($listprice eq ''){
50   $listprice=0;
51 }
52 my $supplier=$input->param('supplier');
53 my $notes=$input->param('notes');
54 my $bookfund=$input->param('bookfund');
55 my $who=$input->remote_user;
56 my $bibnum;
57 my $bibitemnum;
58 my $rrp=$input->param('rrp');
59 my $ecost=$input->param('ecost');
60 my $gst=$input->param('GST');
61 my $orderexists=$input->param('orderexists');
62
63 print STDERR "quantity = $quantity // existing = $existing\n";
64 #check to see if biblio exists
65 if ($quantity ne '0'){
66   if ($existing eq 'no'){
67     #if it doesnt create it
68     $bibnum = &newbiblio({ title     => $title?$title:"",
69                            author    => $author?$author:"",
70                            copyright => $copyright?$copyright:"",
71                                     series => $series?$series:"",
72                                      });
73     $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
74                                    itemtype     => $itemtype?$itemtype:"",
75                                    isbn        => $isbn?$isbn:""
76                                                    });
77         if ($title) {
78                 newsubtitle($bibnum,$title);
79         }
80 #unuseful (already added 4 line before
81 #     modbiblio({ biblionumber  => $bibnum,
82 #               title         => $title?$title:"",
83 #               author        => $author?$author:"",
84 #               copyrightdate => $copyright?$copyright:"",
85 #               series        => $series?$series:"" });
86   } else {
87 print STDERR "inside loop\n";
88     $bibnum=$input->param('biblio');
89     $bibitemnum=$input->param('bibitemnum');
90     my $oldtype=$input->param('oldtype');
91 print STDERR  "bibitemnum : $bibitemnum itemtype:$itemtype oldtype:$oldtype\n";
92     if ($bibitemnum eq '' || $itemtype ne $oldtype){
93       $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
94                                                          itemtype => $itemtype?$itemtype:"",
95                                                          isbn => $isbn?$isbn:"" });
96       print STDERR "newbiblioitem\n";
97     }
98 print STDERR "modbiblio\n";
99     &modbiblio({
100         biblionumber  => $bibnum,
101         title         => $title?$title:"",
102         author        => $author?$author:"",
103         copyrightdate => $copyright?$copyright:"",
104         series        => $series?$series:"" });
105   }
106   if ($orderexists ne '') {
107     modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
108   }else {
109     neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
110   }
111 } else {
112   $bibnum=$input->param('biblio');
113   delorder($bibnum,$ordnum);
114 }
115
116 print $input->redirect("newbasket.pl?id=$supplier&basket=$basketno");