A new acquisition to handle different tax values to each item, receiving multiple...
[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 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23
24 =head1 NAME
25
26 addorder.pl
27
28 =head1 DESCRIPTION
29
30 this script allows to add an order.
31 It is called by :
32
33 =item neworderbiblio.pl to add an order from nothing.
34
35 =item neworderempty.pl to add an order from an existing biblio.
36
37 =item newordersuggestion.pl to add an order from an existing suggestion.
38
39 =head1 CGI PARAMETERS
40
41 All of the cgi parameters below are related to the new order.
42
43 =over 4
44
45 =item C<ordnum>
46 the number of this new order.
47
48 =item C<basketno>
49 the number of this new basket
50
51 =item C<booksellerid>
52 the bookseller the librarian has to pay.
53
54 =item C<existing>
55
56 =item C<title>
57 the title of the record ordered.
58
59 =item C<author>
60 the author of the record ordered.
61
62 =item C<copyrightdate>
63 the copyrightdate of the record ordered.
64
65 =item C<ISBN>
66 the ISBN of the record ordered.
67
68 =item C<format>
69
70 =item C<quantity>
71 the quantity to order.
72
73 =item C<list_price>
74 the price of this order.
75
76 =item C<branch>
77 the branch where this order will be received.
78
79 =item C<series>
80
81 =item C<notes>
82 Notes on this basket.
83
84 =item C<bookfund>
85 bookfund use to pay this order.
86
87 =item C<sort1> & C<sort2>
88
89 =item C<rrp>
90
91 =item C<ecost>
92
93 =item C<gst>
94
95 =item C<budget>
96
97 =item C<cost>
98
99 =item C<sub>
100
101 =item C<invoice>
102 the number of the invoice for this order.
103
104 =item C<publishercode>
105
106 =item C<suggestionid>
107 if it is an order from an existing suggestion : the id of this suggestion.
108
109 =item C<donation>
110
111 =back
112
113 =cut
114
115 use strict;
116 use CGI;
117 use C4::Auth;
118 use C4::Acquisition;
119 use C4::Suggestions;
120 use C4::Biblio;
121 use C4::Interface::CGI::Output;
122
123 my $input = new CGI;
124 # get_template_and_user used only to check auth & get user id
125 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
126     {
127         template_name   => "acqui/booksellers.tmpl",
128         query           => $input,
129         type            => "intranet",
130         authnotrequired => 0,
131         flagsrequired   => { acquisition => 1 },
132         debug           => 1,
133     }
134 );
135
136
137 # get CGI parameters
138 my $ordnum       = $input->param('ordnum');
139 my $basketno     = $input->param('basketno');
140 my $booksellerid = $input->param('booksellerid');
141 my $existing     = $input->param('existing');    # existing biblio, (not basket or order)
142 my $title         = $input->param('title');
143 my $author        = $input->param('author');
144 my $copyrightdate = $input->param('copyrightdate');
145 my $isbn          = $input->param('ISBN');
146 my $itemtype      = $input->param('format');
147 my $quantity      = $input->param('quantity');
148 my $listprice     = $input->param('list_price');
149 my $branch        = $input->param('branch');
150 my $discount=$input->param('discount');
151 if ( $listprice eq '' ) {
152     $listprice = 0;
153 }
154 my $series = $input->param('series');
155 my $notes         = $input->param('notes');
156 my $bookfundid      = $input->param('bookfundid');
157 my $sort1         = $input->param('sort1');
158 my $sort2         = $input->param('sort2');
159 my $rrp           = $input->param('rrp');
160 my $ecost         = $input->param('ecost');
161 my $gst           = $input->param('gstrate');
162 my $budget        = $input->param('budget');
163 my $unitprice         = $input->param('unitprice');
164 my $sub           = $input->param('sub');
165 my $purchaseordernumber       = $input->param('purchaseordernumber');
166 my $publishercode = $input->param('publishercode');
167 my $suggestionid  = $input->param('suggestionid');
168 my $donation      = $input->param('donation');
169 my $user          = $input->remote_user;
170 my $biblionumber=$input->param('biblionumber');
171 my $createbibitem = $input->param('createbibitem');
172
173 # create, modify or delete biblio
174 # create if $quantity>=0 and $existing='no'
175 # modify if $quantity>=0 and $existing='yes'
176 # delete if $quantity has been se to 0 by the librarian
177 my $dbh=C4::Context->dbh;
178
179 if ($quantity ne '0'){
180     #check to see if biblio exists
181     if ( $existing eq 'no' ) {
182         #if it doesnt its created on template
183         # change suggestion status if applicable
184         if ($suggestionid) {
185 my $data=GetSuggestion($suggestionid);
186
187  my $biblio={title=>$data->{title},author=>$data->{author},publishercode=>$data->{publishercode},copyrightdate=>$data->{copyrightdate},isbn=>$data->{isbn},place=>$data->{place},};
188 my $xmlhash=XMLkoha2marc($dbh,$biblio,"biblios");
189 $biblionumber = NEWnewbiblio($dbh,$xmlhash,"");
190
191             ModStatus( $suggestionid, 'ORDERED', '', $biblionumber,$input );
192 warn "modstatus";
193         }
194     }## biblio didnot exist now created
195
196     
197
198    
199     if ($ordnum) {
200
201         #               warn "MODORDER $title / $ordnum / $quantity / $bookfund";
202         ModOrder(
203             $title,   $ordnum,   $quantity,     $listprice,
204             $biblionumber,  $basketno, $booksellerid, $loggedinuser,
205             $notes,   $bookfundid,    $rrp,
206             $ecost,   $gst,      $budget,       $unitprice,
207             $purchaseordernumber, $sort1,    $sort2,$discount,$branch
208         );
209     }
210     else {
211         ( $basketno, $ordnum ) = NewOrder(
212             $basketno,  $biblionumber,       $title,        $quantity,
213             $listprice, $booksellerid, $loggedinuser, $notes,
214             $bookfundid,    $rrp,          $ecost,
215             $gst,       $budget,       $unitprice,         $sub,
216             $purchaseordernumber,   $sort1,        $sort2, $discount,$branch
217         );
218     }
219
220 }
221 else {
222 #    $biblionumber = $input->param('biblionumber');
223     DelOrder( $biblionumber, $ordnum,$loggedinuser );
224 }
225 warn "goingout";
226 print $input->redirect("basket.pl?basketno=$basketno");