Lines 122-131
if it is an order from an existing suggestion : the id of this suggestion.
Link Here
|
122 |
use strict; |
122 |
use strict; |
123 |
use warnings; |
123 |
use warnings; |
124 |
use CGI; |
124 |
use CGI; |
125 |
use C4::Auth; # get_template_and_user |
125 |
use C4::Auth; # get_template_and_user |
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
126 |
use C4::Acquisition; # NewOrder DelOrder ModOrder |
127 |
use C4::Suggestions; # ModStatus |
127 |
use C4::Suggestions; # ModStatus |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
128 |
use C4::Biblio; # AddBiblio TransformKohaToMarc |
|
|
129 |
use C4::Bookseller qw/GetBookSellerFromId/; |
129 |
use C4::Items; |
130 |
use C4::Items; |
130 |
use C4::Output; |
131 |
use C4::Output; |
131 |
|
132 |
|
Lines 193-235
my $user = $input->remote_user;
Link Here
|
193 |
# delete biblio if delbiblio has been set to 1 by the librarian |
194 |
# delete biblio if delbiblio has been set to 1 by the librarian |
194 |
my $bibitemnum; |
195 |
my $bibitemnum; |
195 |
if ( $orderinfo->{quantity} ne '0' ) { |
196 |
if ( $orderinfo->{quantity} ne '0' ) { |
|
|
197 |
|
198 |
# Getting bookseller's name |
199 |
if ($$orderinfo{booksellerid}) { |
200 |
my $bookseller = GetBookSellerFromId($$orderinfo{booksellerid}); |
201 |
$$orderinfo{supplierreference} = $bookseller->{name}; |
202 |
} |
203 |
|
204 |
# Do we have to add order informations to the marc record? |
205 |
my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); |
206 |
my $record; |
207 |
my $existingbiblio; # Was the order made on an existing biblio? |
208 |
my $ordermodif; # Is this an order modification? |
209 |
|
196 |
#TODO:check to see if biblio exists |
210 |
#TODO:check to see if biblio exists |
197 |
unless ( $$orderinfo{biblionumber} ) { |
211 |
unless ( $$orderinfo{biblionumber} ) { |
198 |
#if it doesnt create it |
212 |
#if it doesnt create it |
199 |
my $record = TransformKohaToMarc( |
213 |
my $tmprecord = TransformKohaToMarc( |
200 |
{ |
214 |
{ "biblio.title" => "$$orderinfo{title}", |
201 |
"biblio.title" => "$$orderinfo{title}", |
215 |
"biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", |
202 |
"biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", |
216 |
"biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", |
203 |
"biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", |
217 |
"biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", |
204 |
"biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", |
218 |
"biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", |
205 |
"biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", |
219 |
"biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", |
206 |
"biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", |
220 |
"biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", |
207 |
"biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", |
221 |
"biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", |
208 |
"biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", |
222 |
"biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", |
209 |
"biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", |
223 |
"biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "", |
210 |
"biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", |
224 |
"aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", |
211 |
}); |
225 |
"aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", |
|
|
226 |
"aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", |
227 |
"aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", |
228 |
"aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", |
229 |
"aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", |
230 |
"aqorders.notes" => $$orderinfo{notes} ? $$orderinfo{notes} : "", |
231 |
"aqorders.supplierreference" => $$orderinfo{supplierreference}?$$orderinfo{supplierreference}:"", |
232 |
"aqorders.sort1" => $$orderinfo{sort1} ? $$orderinfo{sort1} : "", |
233 |
"aqorders.sort2" => $$orderinfo{sort2} ? $$orderinfo{sort2} : "" |
234 |
} |
235 |
); |
212 |
|
236 |
|
213 |
# create the record in catalogue, with framework '' |
237 |
# create the record in catalogue, with framework '' |
214 |
my ($biblionumber,$bibitemnum) = AddBiblio($record,''); |
238 |
my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' ); |
|
|
239 |
|
215 |
# change suggestion status if applicable |
240 |
# change suggestion status if applicable |
216 |
if ($$orderinfo{suggestionid}) { |
241 |
if ($$orderinfo{suggestionid}) { |
217 |
ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} ); |
242 |
ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} ); |
218 |
} |
243 |
} |
219 |
$orderinfo->{biblioitemnumber}=$bibitemnum; |
244 |
$orderinfo->{biblioitemnumber} = $bibitemnum; |
220 |
$orderinfo->{biblionumber}=$biblionumber; |
245 |
$orderinfo->{biblionumber} = $biblionumber; |
|
|
246 |
} else { |
247 |
$existingbiblio = 1; |
221 |
} |
248 |
} |
222 |
|
249 |
|
223 |
# if we already have $ordernumber, then it's an ordermodif |
250 |
# Getting record |
224 |
if ($$orderinfo{ordernumber}) { |
251 |
$record = GetMarcBiblio($$orderinfo{biblionumber}); |
225 |
ModOrder( $orderinfo); |
252 |
|
226 |
} |
253 |
|
227 |
else { # else, it's a new line |
254 |
|
|
|
255 |
# if we already have $ordernumber, then it's an ordermodif |
256 |
if ( $$orderinfo{ordernumber} ) { |
257 |
ModOrder($orderinfo); |
258 |
$ordermodif = 1; |
259 |
|
260 |
} else { # else, it's a new line |
228 |
@$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); |
261 |
@$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); |
|
|
262 |
|
263 |
# We have to add the ordernumber in the designated subfield |
264 |
if ($ordertag && $record && !$ordermodif) { |
265 |
|
266 |
# If it's a new line, but we don't have any $ordertag field yet, |
267 |
if (!$record->field($ordertag)) { |
268 |
# We add a new $ordertag field, with the ordernumber as subfield (other fields will be populated later) |
269 |
$record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$record->field($ordertag)); |
270 |
} else { |
271 |
# Else, it's a new line, and we already have a $ordertag field |
272 |
foreach ($record->field($ordertag)) { |
273 |
# If there's a $ordertag field without ordernumber, we create it |
274 |
if (!$_->subfield($ordersubtag)) { |
275 |
$_->update($ordersubtag, $$orderinfo{ordernumber}); |
276 |
} |
277 |
} |
278 |
} |
279 |
ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ'); |
280 |
} |
281 |
|
282 |
|
229 |
} |
283 |
} |
230 |
|
284 |
|
231 |
# now, add items if applicable |
285 |
if ($record) { |
232 |
if (C4::Context->preference('AcqCreateItem') eq 'ordering') { |
286 |
|
|
|
287 |
# If we have to add order infos to the marc record |
288 |
if ($ordertag) { |
289 |
|
290 |
# If the order was made on an existing biblio and it is not a modification, we add the field |
291 |
$record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio); |
292 |
|
293 |
foreach ($record->field($ordertag)) { |
294 |
# Looking for the matching one |
295 |
if ($_->subfield($ordersubtag) eq $$orderinfo{ordernumber}) { |
296 |
|
297 |
# Replacing or creating subfields |
298 |
my ($t, $st); |
299 |
for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) { |
300 |
($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ'); |
301 |
$_->update($st, $$orderinfo{$tablefield}) if ($$orderinfo{$tablefield} and $st); |
302 |
} |
303 |
ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ'); |
304 |
} |
305 |
} |
306 |
|
307 |
} |
308 |
|
309 |
} |
310 |
|
311 |
|
312 |
# now, add items if applicable |
313 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
233 |
|
314 |
|
234 |
my @tags = $input->param('tag'); |
315 |
my @tags = $input->param('tag'); |
235 |
my @subfields = $input->param('subfield'); |
316 |
my @subfields = $input->param('subfield'); |