Lines 25-30
use Modern::Perl;
Link Here
|
25 |
use CGI qw ( -utf8 ); |
25 |
use CGI qw ( -utf8 ); |
26 |
use Carp; |
26 |
use Carp; |
27 |
use YAML qw/Load/; |
27 |
use YAML qw/Load/; |
|
|
28 |
use List::MoreUtils qw/uniq/; |
28 |
|
29 |
|
29 |
use C4::Context; |
30 |
use C4::Context; |
30 |
use C4::Auth; |
31 |
use C4::Auth; |
Lines 194-248
if ($op eq ""){
Link Here
|
194 |
} else { |
195 |
} else { |
195 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
196 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
196 |
} |
197 |
} |
197 |
# 3rd add order |
198 |
|
198 |
my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser ); |
199 |
# Add items from MarcItemFieldsToOrder |
199 |
# get quantity in the MARC record (1 if none) |
200 |
my @homebranches = $input->multi_param('homebranch'); |
200 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
201 |
my $count = scalar @homebranches; |
201 |
my %orderinfo = ( |
202 |
my @holdingbranches = $input->multi_param('holdingbranch'); |
202 |
biblionumber => $biblionumber, |
203 |
my @itypes = $input->multi_param('itype'); |
203 |
basketno => $cgiparams->{'basketno'}, |
204 |
my @nonpublic_notes = $input->multi_param('nonpublic_note'); |
204 |
quantity => $c_quantity, |
205 |
my @public_notes = $input->multi_param('public_note'); |
205 |
branchcode => $patron->{branchcode}, |
206 |
my @locs = $input->multi_param('loc'); |
206 |
budget_id => $c_budget_id, |
207 |
my @ccodes = $input->multi_param('ccodes'); |
207 |
uncertainprice => 1, |
208 |
my @notforloans = $input->multi_param('notforloans'); |
208 |
sort1 => $c_sort1, |
209 |
my @uris = $input->multi_param('uri'); |
209 |
sort2 => $c_sort2, |
210 |
my @copynos = $input->multi_param('copyno'); |
210 |
order_internalnote => $cgiparams->{'all_order_internalnote'}, |
211 |
my @budget_codes = $input->multi_param('budget_code'); |
211 |
order_vendornote => $cgiparams->{'all_order_vendornote'}, |
212 |
my @itemprices = $input->multi_param('itemprice'); |
212 |
currency => $cgiparams->{'all_currency'}, |
213 |
my $itemcreation = 0; |
213 |
); |
214 |
for (my $i = 0; $i < $count; $i++) { |
214 |
# get the price if there is one. |
215 |
$itemcreation = 1; |
215 |
my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
216 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ |
216 |
if ($price){ |
217 |
homebranch => $homebranches[$i], |
217 |
# in France, the cents separator is the , but sometimes, ppl use a . |
218 |
holdingbranch => $holdingbranches[$i], |
218 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
219 |
itemnotes_nonpublic => $nonpublic_notes[$i], |
219 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
220 |
itemnotes => $public_notes[$i], |
220 |
$price = Koha::Number::Price->new($price)->unformat; |
221 |
location => $locs[$i], |
221 |
$orderinfo{tax_rate} = $bookseller->{tax_rate}; |
222 |
ccode => $ccodes[$i], |
222 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
223 |
notforloan => $notforloans[$i], |
223 |
if ( $bookseller->{listincgst} ) { |
224 |
uri => $uris[$i], |
224 |
if ( $c_discount ) { |
225 |
copynumber => $copynos[$i], |
225 |
$orderinfo{ecost} = $price; |
226 |
price => $itemprices[$i], |
226 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
227 |
}, $biblionumber); |
227 |
} else { |
228 |
} |
228 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
229 |
if ($itemcreation == 1) { |
229 |
$orderinfo{rrp} = $price; |
230 |
# Group orderlines from MarcItemFieldsToOrder |
|
|
231 |
my $budget_hash; |
232 |
for (my $i = 0; $i < $count; $i++) { |
233 |
$budget_hash->{$budget_codes[$i]}->{quantity} += 1; |
234 |
$budget_hash->{$budget_codes[$i]}->{price} = $itemprices[$i]; |
235 |
} |
236 |
|
237 |
# Create orderlines from MarcItemFieldsToOrder |
238 |
while(my ($budget_id, $infos) = each $budget_hash) { |
239 |
if ($budget_id) { |
240 |
my %orderinfo = ( |
241 |
biblionumber => $biblionumber, |
242 |
basketno => $cgiparams->{'basketno'}, |
243 |
quantity => $infos->{quantity}, |
244 |
budget_id => $budget_id, |
245 |
currency => $cgiparams->{'all_currency'}, |
246 |
); |
247 |
|
248 |
my $price = $infos->{price}; |
249 |
if ($price){ |
250 |
# in France, the cents separator is the , but sometimes, ppl use a . |
251 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
252 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
253 |
$price = Koha::Number::Price->new($price)->unformat; |
254 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
255 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
256 |
if ( $bookseller->{listincgst} ) { |
257 |
if ( $c_discount ) { |
258 |
$orderinfo{ecost} = $price; |
259 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
260 |
} else { |
261 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
262 |
$orderinfo{rrp} = $price; |
263 |
} |
264 |
} else { |
265 |
if ( $c_discount ) { |
266 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
267 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
268 |
} else { |
269 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
270 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
271 |
} |
272 |
} |
273 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
274 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
275 |
$orderinfo{total} = $orderinfo{ecost} * $infos->{quantity}; |
276 |
} else { |
277 |
$orderinfo{listprice} = 0; |
278 |
} |
279 |
|
280 |
# remove uncertainprice flag if we have found a price in the MARC record |
281 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
282 |
my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; |
230 |
} |
283 |
} |
231 |
} else { |
284 |
} |
232 |
if ( $c_discount ) { |
285 |
} else { |
233 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{tax_rate} ); |
286 |
# 3rd add order |
234 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
287 |
my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser ); |
|
|
288 |
# get quantity in the MARC record (1 if none) |
289 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
290 |
my %orderinfo = ( |
291 |
biblionumber => $biblionumber, |
292 |
basketno => $cgiparams->{'basketno'}, |
293 |
quantity => $c_quantity, |
294 |
branchcode => $patron->{branchcode}, |
295 |
budget_id => $c_budget_id, |
296 |
uncertainprice => 1, |
297 |
sort1 => $c_sort1, |
298 |
sort2 => $c_sort2, |
299 |
order_internalnote => $cgiparams->{'all_order_internalnote'}, |
300 |
order_vendornote => $cgiparams->{'all_order_vendornote'}, |
301 |
currency => $cgiparams->{'all_currency'}, |
302 |
); |
303 |
# get the price if there is one. |
304 |
my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
305 |
if ($price){ |
306 |
# in France, the cents separator is the , but sometimes, ppl use a . |
307 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
308 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
309 |
$price = Koha::Number::Price->new($price)->unformat; |
310 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
311 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
312 |
if ( $bookseller->{listincgst} ) { |
313 |
if ( $c_discount ) { |
314 |
$orderinfo{ecost} = $price; |
315 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
316 |
} else { |
317 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
318 |
$orderinfo{rrp} = $price; |
319 |
} |
235 |
} else { |
320 |
} else { |
236 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{tax_rate} ); |
321 |
if ( $c_discount ) { |
237 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
322 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
|
|
323 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
324 |
} else { |
325 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
326 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
327 |
} |
238 |
} |
328 |
} |
|
|
329 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
330 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
331 |
$orderinfo{total} = $orderinfo{ecost} * $c_quantity; |
332 |
} else { |
333 |
$orderinfo{listprice} = 0; |
239 |
} |
334 |
} |
240 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
|
|
241 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
242 |
$orderinfo{total} = $orderinfo{ecost} * $c_quantity; |
243 |
} else { |
244 |
$orderinfo{listprice} = 0; |
245 |
} |
246 |
|
335 |
|
247 |
# remove uncertainprice flag if we have found a price in the MARC record |
336 |
# remove uncertainprice flag if we have found a price in the MARC record |
248 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
337 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
Lines 282-290
if ($op eq ""){
Link Here
|
282 |
for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) { |
371 |
for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) { |
283 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
372 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
284 |
$order->add_item( $itemnumber ); |
373 |
$order->add_item( $itemnumber ); |
|
|
374 |
} |
375 |
} else { |
376 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
285 |
} |
377 |
} |
286 |
} else { |
|
|
287 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
288 |
} |
378 |
} |
289 |
$imported++; |
379 |
$imported++; |
290 |
} |
380 |
} |
Lines 315-320
foreach my $r ( @{$budgets_hierarchy} ) {
Link Here
|
315 |
push @{$budget_loop}, |
405 |
push @{$budget_loop}, |
316 |
{ b_id => $r->{budget_id}, |
406 |
{ b_id => $r->{budget_id}, |
317 |
b_txt => $r->{budget_name}, |
407 |
b_txt => $r->{budget_name}, |
|
|
408 |
b_code => $r->{budget_code}, |
318 |
b_sort1_authcat => $r->{'sort1_authcat'}, |
409 |
b_sort1_authcat => $r->{'sort1_authcat'}, |
319 |
b_sort2_authcat => $r->{'sort2_authcat'}, |
410 |
b_sort2_authcat => $r->{'sort2_authcat'}, |
320 |
b_active => $r->{budget_period_active}, |
411 |
b_active => $r->{budget_period_active}, |
Lines 366-371
sub import_biblios_list {
Link Here
|
366 |
return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/; |
457 |
return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/; |
367 |
my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status}); |
458 |
my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status}); |
368 |
my @list = (); |
459 |
my @list = (); |
|
|
460 |
my $item_id = 1; |
461 |
my $item_error = 0; |
462 |
|
463 |
my $ccodes = GetKohaAuthorisedValues("items.ccode"); |
464 |
my $locations = GetKohaAuthorisedValues("items.location"); |
465 |
# location list |
466 |
my @locations; |
467 |
foreach (sort keys %$locations) { |
468 |
push @locations, { code => $_, description => "$_ - " . $locations->{$_} }; |
469 |
} |
470 |
my @ccodes; |
471 |
foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) { |
472 |
push @ccodes, { code => $_, description => $ccodes->{$_} }; |
473 |
} |
474 |
|
475 |
|
369 |
|
476 |
|
370 |
foreach my $biblio (@$biblios) { |
477 |
foreach my $biblio (@$biblios) { |
371 |
my $citation = $biblio->{'title'}; |
478 |
my $citation = $biblio->{'title'}; |
Lines 389-395
sub import_biblios_list {
Link Here
|
389 |
); |
496 |
); |
390 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
497 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
391 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
498 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
392 |
my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
499 |
|
|
|
500 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
393 |
my $price = $infos->{price}; |
501 |
my $price = $infos->{price}; |
394 |
my $quantity = $infos->{quantity}; |
502 |
my $quantity = $infos->{quantity}; |
395 |
my $budget_code = $infos->{budget_code}; |
503 |
my $budget_code = $infos->{budget_code}; |
Lines 403-421
sub import_biblios_list {
Link Here
|
403 |
$budget_id = $biblio_budget->{budget_id}; |
511 |
$budget_id = $biblio_budget->{budget_id}; |
404 |
} |
512 |
} |
405 |
} |
513 |
} |
406 |
$cellrecord{price} = $price || ''; |
|
|
407 |
$cellrecord{quantity} = $quantity || ''; |
408 |
$cellrecord{budget_id} = $budget_id || ''; |
409 |
$cellrecord{discount} = $discount || ''; |
410 |
$cellrecord{sort1} = $sort1 || ''; |
411 |
$cellrecord{sort2} = $sort2 || ''; |
412 |
|
514 |
|
|
|
515 |
# Items |
516 |
my @itemlist = (); |
517 |
my $all_items_quantity = 0; |
518 |
my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'quantity', 'budget_code']); |
519 |
if ($alliteminfos != -1) { |
520 |
foreach my $iteminfos (@$alliteminfos) { |
521 |
my $item_homebranch = $iteminfos->{homebranch}; |
522 |
my $item_holdingbranch = $iteminfos->{holdingbranch}; |
523 |
my $item_itype = $iteminfos->{itype}; |
524 |
my $item_nonpublic_note = $iteminfos->{nonpublic_note}; |
525 |
my $item_public_note = $iteminfos->{public_note}; |
526 |
my $item_loc = $iteminfos->{loc}; |
527 |
my $item_ccode = $iteminfos->{ccode}; |
528 |
my $item_notforloan = $iteminfos->{notforloan}; |
529 |
my $item_uri = $iteminfos->{uri}; |
530 |
my $item_copyno = $iteminfos->{copyno}; |
531 |
my $item_quantity = $iteminfos->{quantity} || 1; |
532 |
my $item_budget_code = $iteminfos->{budget_code}; |
533 |
my $item_price = $iteminfos->{price}; |
534 |
|
535 |
for (my $i = 0; $i < $item_quantity; $i++) { |
536 |
|
537 |
my %itemrecord = ( |
538 |
'item_id' => $item_id++, |
539 |
'homebranch' => $item_homebranch, |
540 |
'holdingbranch' => $item_holdingbranch, |
541 |
'itype' => $item_itype, |
542 |
'nonpublic_note' => $item_nonpublic_note, |
543 |
'public_note' => $item_public_note, |
544 |
'loc' => $item_loc, |
545 |
'ccode' => $item_ccode, |
546 |
'notforloan' => $item_notforloan, |
547 |
'uri' => $item_uri, |
548 |
'copyno' => $item_copyno, |
549 |
'quantity' => $item_quantity, |
550 |
'budget_code' => $item_budget_code || $budget_code, |
551 |
'itemprice' => $item_price || $price, |
552 |
); |
553 |
$all_items_quantity++; |
554 |
push @itemlist, \%itemrecord; |
555 |
|
556 |
} |
557 |
} |
558 |
|
559 |
$cellrecord{'iteminfos'} = \@itemlist; |
560 |
} else { |
561 |
$item_error = 1; |
562 |
} |
413 |
push @list, \%cellrecord; |
563 |
push @list, \%cellrecord; |
|
|
564 |
|
565 |
if ($alliteminfos == -1 || scalar(@$alliteminfos) == 0) { |
566 |
$cellrecord{price} = $price || ''; |
567 |
$cellrecord{quantity} = $quantity || ''; |
568 |
$cellrecord{budget_id} = $budget_id || ''; |
569 |
$cellrecord{discount} = $discount || ''; |
570 |
$cellrecord{sort1} = $sort1 || ''; |
571 |
$cellrecord{sort2} = $sort2 || ''; |
572 |
} else { |
573 |
$cellrecord{quantity} = $all_items_quantity; |
574 |
} |
575 |
|
414 |
} |
576 |
} |
415 |
my $num_records = $batch->{'num_records'}; |
577 |
my $num_records = $batch->{'num_records'}; |
416 |
my $overlay_action = GetImportBatchOverlayAction($import_batch_id); |
578 |
my $overlay_action = GetImportBatchOverlayAction($import_batch_id); |
417 |
my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id); |
579 |
my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id); |
418 |
my $item_action = GetImportBatchItemAction($import_batch_id); |
580 |
my $item_action = GetImportBatchItemAction($import_batch_id); |
|
|
581 |
my @itypes = Koha::ItemTypes->search; |
419 |
$template->param(biblio_list => \@list, |
582 |
$template->param(biblio_list => \@list, |
420 |
num_results => $num_records, |
583 |
num_results => $num_records, |
421 |
import_batch_id => $import_batch_id, |
584 |
import_batch_id => $import_batch_id, |
Lines 424-430
sub import_biblios_list {
Link Here
|
424 |
"nomatch_action_${nomatch_action}" => 1, |
587 |
"nomatch_action_${nomatch_action}" => 1, |
425 |
nomatch_action => $nomatch_action, |
588 |
nomatch_action => $nomatch_action, |
426 |
"item_action_${item_action}" => 1, |
589 |
"item_action_${item_action}" => 1, |
427 |
item_action => $item_action |
590 |
item_action => $item_action, |
|
|
591 |
item_error => $item_error, |
592 |
branchloop => GetBranchesLoop(), |
593 |
locationloop => \@locations, |
594 |
itypeloop => \@itypes, |
595 |
ccodeloop => \@ccodes, |
428 |
); |
596 |
); |
429 |
batch_info($template, $batch); |
597 |
batch_info($template, $batch); |
430 |
} |
598 |
} |
Lines 471-484
sub add_matcher_list {
Link Here
|
471 |
} |
639 |
} |
472 |
|
640 |
|
473 |
sub get_infos_syspref { |
641 |
sub get_infos_syspref { |
474 |
my ($record, $field_list) = @_; |
642 |
my ($syspref_name, $record, $field_list) = @_; |
475 |
my $syspref = C4::Context->preference('MarcFieldsToOrder'); |
643 |
my $syspref = C4::Context->preference($syspref_name); |
476 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
644 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
477 |
my $yaml = eval { |
645 |
my $yaml = eval { |
478 |
YAML::Load($syspref); |
646 |
YAML::Load($syspref); |
479 |
}; |
647 |
}; |
480 |
if ( $@ ) { |
648 |
if ( $@ ) { |
481 |
warn "Unable to parse MarcFieldsToOrder syspref : $@"; |
649 |
warn "Unable to parse $syspref syspref : $@"; |
482 |
return (); |
650 |
return (); |
483 |
} |
651 |
} |
484 |
my $r; |
652 |
my $r; |
Lines 496-498
sub get_infos_syspref {
Link Here
|
496 |
} |
664 |
} |
497 |
return $r; |
665 |
return $r; |
498 |
} |
666 |
} |
|
|
667 |
|
668 |
sub equal_number_of_fields { |
669 |
my ($tags_list, $record) = @_; |
670 |
my $refcount = 0; |
671 |
my $count = 0; |
672 |
for my $tag (@$tags_list) { |
673 |
return -1 if $count != $refcount; |
674 |
$count = 0; |
675 |
for my $field ($record->field($tag)) { |
676 |
$count++; |
677 |
} |
678 |
$refcount = $count if ($refcount == 0); |
679 |
} |
680 |
return -1 if $count != $refcount; |
681 |
return $count; |
682 |
} |
683 |
|
684 |
sub get_infos_syspref_on_item { |
685 |
my ($syspref_name, $record, $field_list) = @_; |
686 |
my $syspref = C4::Context->preference($syspref_name); |
687 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
688 |
my $yaml = eval { |
689 |
YAML::Load($syspref); |
690 |
}; |
691 |
if ( $@ ) { |
692 |
warn "Unable to parse $syspref syspref : $@"; |
693 |
return (); |
694 |
} |
695 |
my @result; |
696 |
my @tags_list; |
697 |
|
698 |
# Check tags in syspref definition |
699 |
for my $field_name ( @$field_list ) { |
700 |
next unless exists $yaml->{$field_name}; |
701 |
my @fields = split /\|/, $yaml->{$field_name}; |
702 |
for my $field ( @fields ) { |
703 |
my ( $f, $sf ) = split /\$/, $field; |
704 |
next unless $f and $sf; |
705 |
push @tags_list, $f; |
706 |
} |
707 |
} |
708 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
709 |
|
710 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
711 |
# Return if the number of theses fields in the record is not the same. |
712 |
return -1 if $tags_count == -1; |
713 |
|
714 |
# Gather the fields |
715 |
my $fields_hash; |
716 |
foreach my $tag (@tags_list) { |
717 |
my @tmp_fields; |
718 |
foreach my $field ($record->field($tag)) { |
719 |
push @tmp_fields, $field; |
720 |
} |
721 |
$fields_hash->{$tag} = \@tmp_fields; |
722 |
} |
723 |
|
724 |
for (my $i = 0; $i < $tags_count; $i++) { |
725 |
my $r; |
726 |
for my $field_name ( @$field_list ) { |
727 |
next unless exists $yaml->{$field_name}; |
728 |
my @fields = split /\|/, $yaml->{$field_name}; |
729 |
for my $field ( @fields ) { |
730 |
my ( $f, $sf ) = split /\$/, $field; |
731 |
next unless $f and $sf; |
732 |
my $v = $fields_hash->{$f}[$i]->subfield( $sf ); |
733 |
$r->{$field_name} = $v if (defined $v); |
734 |
last if $yaml->{$field}; |
735 |
} |
736 |
} |
737 |
push @result, $r; |
738 |
} |
739 |
return \@result; |
740 |
} |