*** empty log message ***
[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::Auth;
27 use C4::Output;
28 use C4::Catalogue;
29 use C4::Biblio;
30 use C4::Output;
31 use C4::Interface::CGI::Output;
32 use C4::Database;
33 use HTML::Template;
34
35 #use Date::Manip;
36
37 my $input = new CGI;
38 # get_template_and_user used only to check auth & get user id
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "acqui/order.tmpl",
41                              query => $input,
42                              type => "intranet",
43                              authnotrequired => 0,
44                              flagsrequired => {acquisition => 1},
45                              debug => 1,
46                              });
47
48 my $existing=$input->param('existing');
49 my $title=$input->param('title');
50 $title=~ s/\'/\\\'/g;
51 my $author=$input->param('author');
52 $author=~ s/\'/\\\'/g;
53 my $copyright=$input->param('copyright');
54 my $isbn=$input->param('ISBN');
55 my $itemtype=$input->param('format');
56 my $ordnum=$input->param('ordnum');
57 my $basketno=$input->param('basket');
58 my $quantity=$input->param('quantity');
59 my $listprice=$input->param('list_price');
60 my $series=$input->param('Series');
61 if ($listprice eq ''){
62   $listprice=0;
63 }
64 my $supplier=$input->param('supplier');
65 my $notes=$input->param('notes');
66 my $bookfund=$input->param('bookfund');
67 my $who=$loggedinuser;
68 my $bibnum;
69 my $bibitemnum;
70 my $rrp=$input->param('rrp');
71 my $ecost=$input->param('ecost');
72 my $gst=$input->param('GST');
73 my $orderexists=$input->param('orderexists');
74
75 if ($quantity ne '0'){
76         #check to see if biblio exists
77         if ($existing eq 'no'){
78                 #if it doesnt create it
79                 $bibnum = &newbiblio({ title     => $title?$title:"",
80                                                 author    => $author?$author:"",
81                                                 copyright => $copyright?$copyright:"",
82                                                 series => $series?$series:"",
83                                                         });
84                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
85                                                                 itemtype     => $itemtype?$itemtype:"",
86                                                                 isbn        => $isbn?$isbn:""
87                                                                 });
88                         if ($title) {
89                                 newsubtitle($bibnum,$title);
90                         }
91         } else {
92                 $bibnum=$input->param('biblio');
93                 $bibitemnum=$input->param('bibitemnum');
94                 my $oldtype=$input->param('oldtype');
95                 if ($bibitemnum eq '' || $itemtype ne $oldtype){
96                         $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
97                                                                         itemtype => $itemtype?$itemtype:"",
98                                                                         isbn => $isbn?$isbn:"" });
99                 }
100                 &modbiblio({
101                         biblionumber  => $bibnum,
102                         title         => $title?$title:"",
103                         author        => $author?$author:"",
104                         copyrightdate => $copyright?$copyright:"",
105                         series        => $series?$series:"" });
106         }
107         if ($orderexists ne '') {
108                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
109         }else {
110                 neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst);
111         }
112 } else {
113         $bibnum=$input->param('biblio');
114         delorder($bibnum,$ordnum);
115 }
116
117 print $input->redirect("basket.pl?basket=$basketno");