Bug 5207 - Details on editing SAX Parser ini file.
[koha.git] / acqui / addorder.pl
blob94560c4eacf0a5bdde550d5fa9f89b62b5ed324a
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
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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<ordernumber>
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<uncertainprice>
77 uncertain price, can't close basket until prices of all orders are known.
79 =item C<branch>
80 the branch where this order will be received.
82 =item C<series>
84 =item C<notes>
85 Notes on this basket.
87 =item C<budget_id>
88 budget_id used to pay this order.
90 =item C<sort1> & C<sort2>
92 =item C<rrp>
94 =item C<ecost>
96 =item C<GST>
98 =item C<budget>
100 =item C<cost>
102 =item C<sub>
104 =item C<invoice>
105 the number of the invoice for this order.
107 =item C<publishercode>
109 =item C<suggestionid>
110 if it is an order from an existing suggestion : the id of this suggestion.
112 =item C<donation>
114 =back
116 =cut
118 use strict;
119 use warnings;
120 use CGI;
121 use C4::Auth; # get_template_and_user
122 use C4::Acquisition; # NewOrder DelOrder ModOrder
123 use C4::Suggestions; # ModStatus
124 use C4::Biblio; # AddBiblio TransformKohaToMarc
125 use C4::Items;
126 use C4::Output;
128 ### "-------------------- addorder.pl ----------"
130 # FIXME: This needs to do actual error checking and possibly return user to the same form,
131 # not just blindly call C4 functions and print a redirect.
133 my $input = new CGI;
134 ### $input
136 # get_template_and_user used only to check auth & get user id
137 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
139 template_name => "acqui/booksellers.tmpl",
140 query => $input,
141 type => "intranet",
142 authnotrequired => 0,
143 flagsrequired => { acquisition => 'order_manage' },
144 debug => 1,
148 # get CGI parameters
149 my $orderinfo = $input->Vars;
150 $orderinfo->{'list_price'} ||= 0;
151 #my $ordernumber = $input->param('ordernumber');
152 #my $basketno = $input->param('basketno');
153 #my $booksellerid = $input->param('booksellerid');
154 #my $existing = $input->param('existing'); # existing biblio, (not basket or order)
155 #my $title = $input->param('title');
156 #my $author = $input->param('author');
157 #my $publicationyear= $input->param('publicationyear');
158 #my $isbn = $input->param('ISBN');
159 #my $itemtype = $input->param('format');
160 #my $quantity = $input->param('quantity'); # FIXME: else ERROR!
161 #my $branch = $input->param('branch');
162 #my $series = $input->param('series');
163 #my $notes = $input->param('notes');
164 #my $budget_id = $input->param('budget_id');
165 #my $sort1 = $input->param('sort1');
166 #my $sort2 = $input->param('sort2');
167 #my $rrp = $input->param('rrp');
168 #my $ecost = $input->param('ecost');
169 #my $gst = $input->param('GST');
170 #my $budget = $input->param('budget');
171 #my $cost = $input->param('cost');
172 #my $sub = $input->param('sub');
173 #my $purchaseorder = $input->param('purchaseordernumber');
174 #my $invoice = $input->param('invoice');
175 #my $publishercode = $input->param('publishercode');
176 #my $suggestionid = $input->param('suggestionid');
177 #my $biblionumber = $input->param('biblionumber');
178 #my $uncertainprice = $input->param('uncertainprice');
179 #my $import_batch_id= $input->param('import_batch_id');
181 #my $createbibitem = $input->param('createbibitem');
183 my $user = $input->remote_user;
184 # create, modify or delete biblio
185 # create if $quantity>=0 and $existing='no'
186 # modify if $quantity>=0 and $existing='yes'
187 # delete if $quantity has been set to 0 by the librarian
188 my $bibitemnum;
189 if ( $orderinfo->{quantity} ne '0' ) {
190 #TODO:check to see if biblio exists
191 unless ( $$orderinfo{biblionumber} ) {
192 #if it doesnt create it
193 my $record = TransformKohaToMarc(
195 "biblio.title" => "$$orderinfo{title}",
196 "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "",
197 "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "",
198 "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "",
199 "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "",
200 "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
201 "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
204 # create the record in catalogue, with framework ''
205 my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
206 # change suggestion status if applicable
207 if ($$orderinfo{suggestionid}) {
208 ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, status=>'ORDERED', biblionumber=>$biblionumber} );
210 $orderinfo->{biblioitemnumber}=$bibitemnum;
211 $orderinfo->{biblionumber}=$biblionumber;
214 # if we already have $ordernumber, then it's an ordermodif
215 if ($$orderinfo{ordernumber}) {
216 ModOrder( $orderinfo);
218 else { # else, it's a new line
219 @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
222 # now, add items if applicable
223 if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
225 my @tags = $input->param('tag');
226 my @subfields = $input->param('subfield');
227 my @field_values = $input->param('field_value');
228 my @serials = $input->param('serial');
229 my @itemid = $input->param('itemid');
230 my @ind_tag = $input->param('ind_tag');
231 my @indicator = $input->param('indicator');
232 #Rebuilding ALL the data for items into a hash
233 # parting them on $itemid.
235 my %itemhash;
236 my $countdistinct;
237 my $range=scalar(@itemid);
238 for (my $i=0; $i<$range; $i++){
239 unless ($itemhash{$itemid[$i]}){
240 $countdistinct++;
242 push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
243 push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
244 push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
245 push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
246 push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
248 foreach my $item (keys %itemhash){
250 my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
251 $itemhash{$item}->{'subfields'},
252 $itemhash{$item}->{'field_values'},
253 $itemhash{$item}->{'ind_tag'},
254 $itemhash{$item}->{'indicator'},
255 'ITEM');
256 my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
257 my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$$orderinfo{biblionumber});
258 NewOrderItem($itemnumber, $$orderinfo{ordernumber});
265 else { # qty=0, delete the line
266 my $biblionumber = $input->param('biblionumber');
267 DelOrder( $biblionumber, $$orderinfo{ordernumber} );
269 my $basketno=$$orderinfo{basketno};
270 my $booksellerid=$$orderinfo{booksellerid};
271 if (my $import_batch_id=$$orderinfo{import_batch_id}) {
272 print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=$basketno&booksellerid=$booksellerid");
273 } else {
274 print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");