invoice number problems fixed, "fast receive" now works
[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::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 my $budget=$input->param('budget');
75 my $cost=$input->param('cost');
76 my$sub=$input->param('sub');
77 my $invoice=$input->param('invoice');
78
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                                                 copyright => $copyright?$copyright:"",
86                                                 series => $series?$series:"",
87                                                         });
88                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
89                                                                 itemtype     => $itemtype?$itemtype:"",
90                                                                 isbn        => $isbn?$isbn:""
91                                                                 });
92                         if ($title) {
93                                 newsubtitle($bibnum,$title);
94                         }
95         } else {
96                 $bibnum=$input->param('biblio');
97                 $bibitemnum=$input->param('bibitemnum');
98                 my $oldtype=$input->param('oldtype');
99                 if ($bibitemnum eq '' || $itemtype ne $oldtype){
100                         $bibitemnum= &newbiblioitem({ biblionumber => $bibnum,
101                                                                         itemtype => $itemtype?$itemtype:"",
102                                                                         isbn => $isbn?$isbn:"" });
103                 }
104                 &modbiblio({
105                         biblionumber  => $bibnum,
106                         title         => $title?$title:"",
107                         author        => $author?$author:"",
108                         copyrightdate => $copyright?$copyright:"",
109                         series        => $series?$series:"" });
110         }
111         if ($orderexists ne '') {
112                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice);
113         }else {
114                 neworder($bibnum,$title,$ordnum,$basketno,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice);
115         }
116 } else {
117         $bibnum=$input->param('biblio');
118         delorder($bibnum,$ordnum);
119 }
120
121 print $input->redirect("basket.pl?basket=$basketno");