More interim updates
[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 my $author=$input->param('author');
51 my $copyrightdate=$input->param('copyrightdate');
52 my $isbn=$input->param('ISBN');
53 my $itemtype=$input->param('format');
54 my $ordnum=$input->param('ordnum');
55 my $basketno=$input->param('basket');
56 my $quantity=$input->param('quantity');
57 my $listprice=$input->param('list_price');
58 my $series=$input->param('Series');
59 if ($listprice eq ''){
60   $listprice=0;
61 }
62 my $supplier=$input->param('supplier');
63 my $notes=$input->param('notes');
64 my $bookfund=$input->param('bookfund');
65 my $who=$loggedinuser;
66 my $bibnum;
67 my $bibitemnum;
68 my $rrp=$input->param('rrp');
69 my $ecost=$input->param('ecost');
70 my $gst=$input->param('GST');
71 my $orderexists=$input->param('orderexists');
72 my $budget=$input->param('budget');
73 my $cost=$input->param('cost');
74 my $sub=$input->param('sub');
75 my $invoice=$input->param('invoice');
76 my $publishercode = $input->param('publishercode');
77 if ($quantity ne '0'){
78         #check to see if biblio exists
79         if ($existing eq 'no'){
80                 #if it doesnt create it
81                 $bibnum = &newbiblio({ title     => $title?$title:"",
82                                                 author    => $author?$author:"",
83                                                 copyrightdate => $copyrightdate?$copyrightdate:"",
84                                                 series => $series?$series:"",
85                                                         });
86                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
87                                                                 itemtype     => $itemtype?$itemtype:"",
88                                                                 isbn        => $isbn?$isbn:"",
89                                                                 publishercode => $publishercode?$publishercode:"",
90                                                                 });
91                         if ($title) {
92                                 newsubtitle($bibnum,$title);
93                         }
94         } else {
95                 $bibnum=$input->param('biblio');
96                 $bibitemnum=$input->param('bibitemnum');
97                 my $oldtype=$input->param('oldtype');
98                 if ($bibitemnum eq '' || $itemtype ne $oldtype){
99                         $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
100                                                                         itemtype => $itemtype?$itemtype:"",
101                                                                         isbn => $isbn?$isbn:"" ,
102                                                                         publishercode => $publishercode?$publishercode:"",
103                                                                         });
104                 } else {
105                         &modbibitem({biblioitemnumber => $bibitemnum,
106                                                         isbn            => $isbn,
107                                                         publishercode   => $publishercode,
108                         });
109                 }
110                 &modbiblio({
111                         biblionumber  => $bibnum,
112                         title         => $title?$title:"",
113                         author        => $author?$author:"",
114                         copyrightdate => $copyrightdate?$copyrightdate:"",
115                         series        => $series?$series:"" },
116                         );
117         }
118         if ($orderexists ne '') {
119                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice);
120         }else {
121                 neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice);
122         }
123 } else {
124         $bibnum=$input->param('biblio');
125         delorder($bibnum,$ordnum);
126 }
127
128 print $input->redirect("basket.pl?basket=$basketno");