reordering code
[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
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 my $existing=$input->param('existing');
33 my $title=$input->param('title');
34 $title=~ s/\'/\\\'/g;
35 my $author=$input->param('author');
36 $author=~ s/\'/\\\'/g;
37 my $copyright=$input->param('copyright');
38 my $isbn=$input->param('ISBN');
39 my $itemtype=$input->param('format');
40 my $ordnum=$input->param('ordnum');
41 my $basketno=$input->param('basket');
42 my $quantity=$input->param('quantity');
43 my $listprice=$input->param('list_price');
44 my $series=$input->param('Series');
45 if ($listprice eq ''){
46   $listprice=0;
47 }
48 my $supplier=$input->param('supplier');
49 my $notes=$input->param('notes');
50 my $bookfund=$input->param('bookfund');
51 my $who=$input->remote_user;
52 my $bibnum;
53 my $bibitemnum;
54 my $rrp=$input->param('rrp');
55 my $ecost=$input->param('ecost');
56 my $gst=$input->param('GST');
57 my $orderexists=$input->param('orderexists');
58
59 if ($quantity ne '0'){
60         #check to see if biblio exists
61         if ($existing eq 'no'){
62                 #if it doesnt create it
63                 $bibnum = &newbiblio({ title     => $title?$title:"",
64                                                 author    => $author?$author:"",
65                                                 copyright => $copyright?$copyright:"",
66                                                 series => $series?$series:"",
67                                                         });
68                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
69                                                                 itemtype     => $itemtype?$itemtype:"",
70                                                                 isbn        => $isbn?$isbn:""
71                                                                 });
72                         if ($title) {
73                                 newsubtitle($bibnum,$title);
74                         }
75         } else {
76                 $bibnum=$input->param('biblio');
77                 $bibitemnum=$input->param('bibitemnum');
78                 my $oldtype=$input->param('oldtype');
79                 if ($bibitemnum eq '' || $itemtype ne $oldtype){
80                         $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
81                                                                         itemtype => $itemtype?$itemtype:"",
82                                                                         isbn => $isbn?$isbn:"" });
83                 }
84                 &modbiblio({
85                         biblionumber  => $bibnum,
86                         title         => $title?$title:"",
87                         author        => $author?$author:"",
88                         copyrightdate => $copyright?$copyright:"",
89                         series        => $series?$series:"" });
90         }
91         if ($orderexists ne '') {
92                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
93         }else {
94                 neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
95         }
96 } else {
97         $bibnum=$input->param('biblio');
98         delorder($bibnum,$ordnum);
99 }
100
101 print $input->redirect("newbasket.pl?id=$supplier&basket=$basketno");