CRITICAL bug in acquisition (another one...) : when MARC=ON, and an order line is...
[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::Suggestions;
30 use C4::Biblio;
31 use C4::Output;
32 use C4::Interface::CGI::Output;
33 use C4::Database;
34 use HTML::Template;
35
36 #use Date::Manip;
37
38 my $input = new CGI;
39 # get_template_and_user used only to check auth & get user id
40 my ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "acqui/order.tmpl",
42                              query => $input,
43                              type => "intranet",
44                              authnotrequired => 0,
45                              flagsrequired => {acquisition => 1},
46                              debug => 1,
47                              });
48
49 # get CGI parameters
50 my $ordnum=$input->param('ordnum');
51 my $basketno=$input->param('basketno');
52 my $booksellerid = $input->param('booksellerid');
53 my $existing=$input->param('existing'); # existing biblio, (not basket or order)
54 my $title=$input->param('title');
55 my $author=$input->param('author');
56 my $copyrightdate=$input->param('copyrightdate');
57 my $isbn=$input->param('ISBN');
58 my $itemtype=$input->param('format');
59 my $quantity=$input->param('quantity');
60 my $listprice=$input->param('list_price');
61 if ($listprice eq ''){
62         $listprice=0;
63 }
64 my $series=$input->param('Series');
65 # my $supplier=$input->param('supplier');
66 my $notes=$input->param('notes');
67 my $bookfund=$input->param('bookfund');
68 my $sort1=$input->param('sort1');
69 my $sort2=$input->param('sort2');
70 my $rrp=$input->param('rrp');
71 my $ecost=$input->param('ecost');
72 my $gst=$input->param('GST');
73 my $budget=$input->param('budget');
74 my $cost=$input->param('cost');
75 my $sub=$input->param('sub');
76 my $invoice=$input->param('invoice');
77 my $publishercode = $input->param('publishercode');
78 my $suggestionid= $input->param('suggestionid');
79
80 # create, modify or delete biblio
81 # create if $quantity>=0 and $existing='no'
82 # modify if $quantity>=0 and $existing='yes'
83 # delete if $quantity has been se to 0 by the librarian
84 my $bibnum;
85 my $bibitemnum;
86 if ($quantity ne '0'){
87         #check to see if biblio exists
88         if ($existing eq 'no'){
89                 #if it doesnt create it
90                 $bibnum = &newbiblio({ title     => $title?$title:"",
91                                                 author    => $author?$author:"",
92                                                 copyrightdate => $copyrightdate?$copyrightdate:"",
93                                                 series => $series?$series:"",
94                                                         });
95                 $bibitemnum = &newbiblioitem({ biblionumber => $bibnum,
96                                                                 itemtype     => $itemtype?$itemtype:"",
97                                                                 isbn        => $isbn?$isbn:"",
98                                                                 publishercode => $publishercode?$publishercode:"",
99                                                                 });
100                         if ($title) {
101                                 newsubtitle($bibnum,$title);
102                         }
103                 # change suggestion status if applicable
104                 if ($suggestionid) {
105                         changestatus($suggestionid,'ORDERED');
106                 }
107         } else {
108                 $bibnum=$input->param('biblio');
109                 $bibitemnum=$input->param('bibitemnum');
110                 my $oldtype=$input->param('oldtype');
111 #               &modbibitem({biblioitemnumber => $bibitemnum,
112 #                                               isbn            => $isbn,
113 #                                               publishercode   => $publishercode,
114 #               });
115 #               &modbiblio({
116 #                       biblionumber  => $bibnum,
117 #                       title         => $title?$title:"",
118 #                       author        => $author?$author:"",
119 #                       copyrightdate => $copyrightdate?$copyrightdate:"",
120 #                       series        => $series?$series:"" },
121 #                       );
122         }
123         if ($ordnum) {
124 #               warn "MODORDER $title / $ordnum / $quantity / $bookfund";
125                 modorder($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$booksellerid,$loggedinuser,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice,$sort1,$sort2);
126         }else {
127 #       warn "new order : ";
128                 $basketno=neworder($basketno,$bibnum,$title,$quantity,$listprice,$booksellerid,$loggedinuser,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice,$sort1,$sort2);
129         }
130 } else {
131         $bibnum=$input->param('biblio');
132         delorder($bibnum,$ordnum);
133 }
134 print $input->redirect("basket.pl?basket=$basketno");