Add and change preferences, change tab names in sysprefs editor
[koha.git] / acqui / addorder.pl
blob58b48677e5e42b08920152d052577260a410144f
1 #!/usr/bin/perl
3 #script to add an order into the system
4 #written 29/2/00 by chris@katipo.co.nz
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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.
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.
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
24 =head1 NAME
26 addorder.pl
28 =head1 DESCRIPTION
30 this script allows to add an order.
31 It is called by :
33 =item neworderbiblio.pl to add an order from nothing.
35 =item neworderempty.pl to add an order from an existing biblio.
37 =item newordersuggestion.pl to add an order from an existing suggestion.
39 =head1 CGI PARAMETERS
41 All of the cgi parameters below are related to the new order.
43 =over 4
45 =item C<ordnum>
46 the number of this new order.
48 =item C<basketno>
49 the number of this new basket
51 =item C<booksellerid>
52 the bookseller the librarian has to pay.
54 =item C<existing>
56 =item C<title>
57 the title of the record ordered.
59 =item C<author>
60 the author of the record ordered.
62 =item C<copyrightdate>
63 the copyrightdate of the record ordered.
65 =item C<ISBN>
66 the ISBN of the record ordered.
68 =item C<format>
70 =item C<quantity>
71 the quantity to order.
73 =item C<list_price>
74 the price of this order.
76 =item C<branch>
77 the branch where this order will be received.
79 =item C<series>
81 =item C<notes>
82 Notes on this basket.
84 =item C<bookfund>
85 bookfund use to pay this order.
87 =item C<sort1> & C<sort2>
89 =item C<rrp>
91 =item C<ecost>
93 =item C<GST>
95 =item C<budget>
97 =item C<cost>
99 =item C<sub>
101 =item C<invoice>
102 the number of the invoice for this order.
104 =item C<publishercode>
106 =item C<suggestionid>
107 if it is an order from an existing suggestion : the id of this suggestion.
109 =item C<donation>
111 =back
113 =cut
115 use strict;
116 use CGI;
117 use C4::Auth; # get_template_and_user
118 use C4::Acquisition; # NewOrder DelOrder ModOrder
119 use C4::Suggestions; # ModStatus
120 use C4::Biblio; # AddBiblio TransformKohaToMarc
121 use C4::Output;
123 # FIXME: This needs to do actual error checking and possibly return user to the same form,
124 # not just blindly call C4 functions and print a redirect.
126 my $input = new CGI;
128 # get_template_and_user used only to check auth & get user id
129 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
131 template_name => "acqui/booksellers.tmpl",
132 query => $input,
133 type => "intranet",
134 authnotrequired => 0,
135 flagsrequired => { acquisition => 1 },
136 debug => 1,
140 # get CGI parameters
141 my $ordnum = $input->param('ordnum');
142 my $basketno = $input->param('basketno');
143 my $booksellerid = $input->param('booksellerid');
144 my $existing = $input->param('existing'); # existing biblio, (not basket or order)
145 my $title = $input->param('title');
146 my $author = $input->param('author');
147 my $copyrightdate = $input->param('copyrightdate');
148 my $isbn = $input->param('ISBN');
149 my $itemtype = $input->param('format');
150 my $quantity = $input->param('quantity'); # FIXME: else ERROR!
151 my $listprice = $input->param('list_price') || 0;
152 my $branch = $input->param('branch');
153 my $series = $input->param('series');
154 my $notes = $input->param('notes');
155 my $bookfund = $input->param('bookfund');
156 my $sort1 = $input->param('sort1');
157 my $sort2 = $input->param('sort2');
158 my $rrp = $input->param('rrp');
159 my $ecost = $input->param('ecost');
160 my $gst = $input->param('GST');
161 my $budget = $input->param('budget');
162 my $cost = $input->param('cost');
163 my $sub = $input->param('sub');
164 my $purchaseorder = $input->param('purchaseordernumber');
165 my $invoice = $input->param('invoice');
166 my $publishercode = $input->param('publishercode');
167 my $suggestionid = $input->param('suggestionid');
168 my $biblionumber = $input->param('biblionumber');
170 # create, modify or delete biblio
171 # create if $quantity>=0 and $existing='no'
172 # modify if $quantity>=0 and $existing='yes'
173 # delete if $quantity has been set to 0 by the librarian
174 my $bibitemnum;
175 if ( $quantity ne '0' ) {
176 #check to see if biblio exists
177 if ( $existing eq 'no' ) {
179 #if it doesnt create it
180 my $record = TransformKohaToMarc(
182 "biblio.title" => "$title",
183 "biblio.author" => "$author",
184 "biblio.copyrightdate" => $copyrightdate ? $copyrightdate : "",
185 "biblio.series" => $series ? $series : "",
186 "biblioitems.itemtype" => $itemtype ? $itemtype : "",
187 "biblioitems.isbn" => $isbn ? $isbn : "",
188 "biblioitems.publishercode" => $publishercode ? $publishercode : "",
190 # create the record in catalogue, with framework ''
191 ($biblionumber,$bibitemnum) = AddBiblio($record,'');
193 # change suggestion status if applicable
194 if ($suggestionid) {
195 ModStatus( $suggestionid, 'ORDERED', '', $biblionumber );
198 # if we already have $ordnum, then it's an ordermodif
199 if ($ordnum) {
200 ModOrder(
201 $title, $ordnum, $quantity, $listprice,
202 $biblionumber, $basketno, $booksellerid, $loggedinuser,
203 $notes, $bookfund, $bibitemnum, $rrp,
204 $ecost, $gst, $budget, $cost,
205 $invoice, $sort1, $sort2, $purchaseorder, $branch
208 else { # else, it's a new line
209 ( $basketno, $ordnum ) = NewOrder(
210 $basketno, $biblionumber, $title, $quantity,
211 $listprice, $booksellerid, $loggedinuser, $notes,
212 $bookfund, $bibitemnum, $rrp, $ecost,
213 $gst, $budget, $cost, $sub,
214 $invoice, $sort1, $sort2, $purchaseorder,
215 $branch
219 else { # qty=0, delete the line
220 $biblionumber = $input->param('biblionumber');
221 DelOrder( $biblionumber, $ordnum );
223 print $input->redirect("basket.pl?basketno=$basketno");