catalogue.pm deals only with acquisitions.
[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::Acquisition;
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 $sort1=$input->param('sort1');
66 my $sort2=$input->param('sort2');
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 my $budget=$input->param('budget');
75 my $cost=$input->param('cost');
76 my $sub=$input->param('sub');
77 my $invoice=$input->param('invoice');
78 my $publishercode = $input->param('publishercode');
79 if ($quantity ne '0'){
80         #check to see if biblio exists
81         if ($existing eq 'no'){
82                 #if it doesnt create it
83                 $bibnum = &newbiblio({ title     => $title?$title:"",
84                                                 author    => $author?$author:"",
85                                                 copyrightdate => $copyrightdate?$copyrightdate:"",
86                                                 series => $series?$series:"",
87                                                         });
88                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
89                                                                 itemtype     => $itemtype?$itemtype:"",
90                                                                 isbn        => $isbn?$isbn:"",
91                                                                 publishercode => $publishercode?$publishercode:"",
92                                                                 });
93                         if ($title) {
94                                 newsubtitle($bibnum,$title);
95                         }
96         } else {
97                 $bibnum=$input->param('biblio');
98                 $bibitemnum=$input->param('bibitemnum');
99                 my $oldtype=$input->param('oldtype');
100                 if ($bibitemnum eq '' || $itemtype ne $oldtype){
101                         $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
102                                                                         itemtype => $itemtype?$itemtype:"",
103                                                                         isbn => $isbn?$isbn:"" ,
104                                                                         publishercode => $publishercode?$publishercode:"",
105                                                                         });
106                 } else {
107                         &modbibitem({biblioitemnumber => $bibitemnum,
108                                                         isbn            => $isbn,
109                                                         publishercode   => $publishercode,
110                         });
111                 }
112                 &modbiblio({
113                         biblionumber  => $bibnum,
114                         title         => $title?$title:"",
115                         author        => $author?$author:"",
116                         copyrightdate => $copyrightdate?$copyrightdate:"",
117                         series        => $series?$series:"" },
118                         );
119         }
120         if ($orderexists ne '') {
121                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice,$sort1,$sort2);
122         }else {
123                 neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice,$sort1,$sort2);
124         }
125 } else {
126         $bibnum=$input->param('biblio');
127         delorder($bibnum,$ordnum);
128 }
129
130 print $input->redirect("basket.pl?basket=$basketno");