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
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.
30 this script allows to add an order.
35 =item neworderbiblio.pl to add an order from nothing.
37 =item neworderempty.pl to add an order from an existing biblio.
39 =item newordersuggestion.pl to add an order from an existing suggestion.
45 All of the cgi parameters below are related to the new order.
50 the number of this new order.
53 the number of this new basket
56 the bookseller the librarian has to pay.
61 the title of the record ordered.
64 the author of the record ordered.
66 =item C<copyrightdate>
67 the copyrightdate of the record ordered.
70 the ISBN of the record ordered.
75 the quantity to order.
78 the price of this order.
80 =item C<uncertainprice>
81 uncertain price, can't close basket until prices of all orders are known.
84 the branch where this order will be received.
92 budget_id used to pay this order.
94 =item C<sort1> & C<sort2>
109 the number of the invoice for this order.
111 =item C<publishercode>
113 =item C<suggestionid>
114 if it is an order from an existing suggestion : the id of this suggestion.
125 use C4::Auth; # get_template_and_user
126 use C4::Acquisition; # NewOrder DelOrder ModOrder
127 use C4::Suggestions; # ModStatus
128 use C4::Biblio; # AddBiblio TransformKohaToMarc
132 ### "-------------------- addorder.pl ----------"
134 # FIXME: This needs to do actual error checking and possibly return user to the same form,
135 # not just blindly call C4 functions and print a redirect.
140 # get_template_and_user used only to check auth & get user id
141 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
143 template_name => "acqui/booksellers.tmpl",
146 authnotrequired => 0,
147 flagsrequired => { acquisition => 'order_manage' },
153 my $orderinfo = $input->Vars;
154 $orderinfo->{'list_price'} ||= 0;
155 $orderinfo->{'uncertainprice'} ||= 0;
156 $orderinfo->{subscriptionid} ||= undef;
158 my $user = $input->remote_user;
160 # create, modify or delete biblio
161 # create if $quantity>=0 and $existing='no'
162 # modify if $quantity>=0 and $existing='yes'
163 # delete if $quantity has been set to 0 by the librarian
164 # delete biblio if delbiblio has been set to 1 by the librarian
165 if ( $orderinfo->{quantity} ne '0' ) {
166 #TODO:check to see if biblio exists
167 unless ( $$orderinfo{biblionumber} ) {
168 #if it doesnt create it
169 my $record = TransformKohaToMarc(
171 "biblio.title" => "$$orderinfo{title}",
172 "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "",
173 "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "",
174 "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "",
175 "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "",
176 "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "",
177 "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
178 "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
179 "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
180 "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
181 "aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "",
182 "aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "",
183 "aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "",
184 "aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "",
185 "aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "",
186 "aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "",
187 "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "",
190 # create the record in catalogue, with framework ''
191 my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
192 # change suggestion status if applicable
193 if ($$orderinfo{suggestionid}) {
194 ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
196 $orderinfo->{biblionumber}=$biblionumber;
199 $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
201 # if we already have $ordernumber, then it's an ordermodif
202 if ($$orderinfo{ordernumber}) {
203 ModOrder( $orderinfo);
205 else { # else, it's a new line
206 @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
209 # now, add items if applicable
210 if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
212 my @tags = $input->param('tag');
213 my @subfields = $input->param('subfield');
214 my @field_values = $input->param('field_value');
215 my @serials = $input->param('serial');
216 my @itemid = $input->param('itemid');
217 my @ind_tag = $input->param('ind_tag');
218 my @indicator = $input->param('indicator');
219 #Rebuilding ALL the data for items into a hash
220 # parting them on $itemid.
224 my $range=scalar(@itemid);
225 for (my $i=0; $i<$range; $i++){
226 unless ($itemhash{$itemid[$i]}){
229 push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
230 push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
231 push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
232 push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
233 push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
235 foreach my $item (keys %itemhash){
237 my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
238 $itemhash{$item}->{'subfields'},
239 $itemhash{$item}->{'field_values'},
240 $itemhash{$item}->{'ind_tag'},
241 $itemhash{$item}->{'indicator'},
243 my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
244 my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$$orderinfo{biblionumber});
245 NewOrderItem($itemnumber, $$orderinfo{ordernumber});
252 else { # qty=0, delete the line
253 my $biblionumber = $input->param('biblionumber');
254 DelOrder( $biblionumber, $$orderinfo{ordernumber} );
255 if ($orderinfo->{delbiblio} == 1){
256 DelBiblio($biblionumber);
259 my $basketno=$$orderinfo{basketno};
260 my $booksellerid=$$orderinfo{booksellerid};
261 if (my $import_batch_id=$$orderinfo{import_batch_id}) {
262 print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=$basketno&booksellerid=$booksellerid");
263 } elsif ( defined $orderinfo->{invoiceid} ) {
264 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=" . $orderinfo->{invoiceid});
266 print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");