Lines 507-515
sub import_biblios_list {
Link Here
|
507 |
my $sort1 = $infos->{sort1}; |
507 |
my $sort1 = $infos->{sort1}; |
508 |
my $sort2 = $infos->{sort2}; |
508 |
my $sort2 = $infos->{sort2}; |
509 |
my $budget_id; |
509 |
my $budget_id; |
510 |
if($budget_code) { |
510 |
|
|
|
511 |
if ($budget_code) { |
511 |
my $biblio_budget = GetBudgetByCode($budget_code); |
512 |
my $biblio_budget = GetBudgetByCode($budget_code); |
512 |
if($biblio_budget) { |
513 |
if ($biblio_budget) { |
513 |
$budget_id = $biblio_budget->{budget_id}; |
514 |
$budget_id = $biblio_budget->{budget_id}; |
514 |
} |
515 |
} |
515 |
} |
516 |
} |
Lines 517-572
sub import_biblios_list {
Link Here
|
517 |
# Items |
518 |
# Items |
518 |
my @itemlist = (); |
519 |
my @itemlist = (); |
519 |
my $all_items_quantity = 0; |
520 |
my $all_items_quantity = 0; |
520 |
my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code']); |
521 |
my $alliteminfos = get_marc_item_fields_to_order($marcrecord); |
521 |
if ($alliteminfos != -1) { |
522 |
if ($alliteminfos != -1) { |
522 |
foreach my $iteminfos (@$alliteminfos) { |
523 |
foreach my $iteminfos (@$alliteminfos) { |
523 |
my $item_homebranch = $iteminfos->{homebranch}; |
524 |
# Quantity is required, default to one if not supplied |
524 |
my $item_holdingbranch = $iteminfos->{holdingbranch}; |
525 |
my $quantity = delete $iteminfos->{quantity} || 1; |
525 |
my $item_itype = $iteminfos->{itype}; |
526 |
|
526 |
my $item_nonpublic_note = $iteminfos->{nonpublic_note}; |
527 |
# Handle incorrectly named original parameters for MarcItemFieldsToOrder |
527 |
my $item_public_note = $iteminfos->{public_note}; |
528 |
$iteminfos->{location} = delete $iteminfos->{loc} if $iteminfos->{loc}; |
528 |
my $item_loc = $iteminfos->{loc}; |
529 |
$iteminfos->{copynumber} = delete $iteminfos->{copyno} if $iteminfos->{copyno}; |
529 |
my $item_ccode = $iteminfos->{ccode}; |
530 |
|
530 |
my $item_notforloan = $iteminfos->{notforloan}; |
531 |
# Convert budge code to a budget id |
531 |
my $item_uri = $iteminfos->{uri}; |
532 |
my $item_budget_code = delete $iteminfos->{budget_code}; |
532 |
my $item_copyno = $iteminfos->{copyno}; |
533 |
if ( $item_budget_code ) { |
533 |
my $item_quantity = $iteminfos->{quantity} || 1; |
534 |
my $item_budget = GetBudgetByCode( $item_budget_code ); |
534 |
my $item_budget_code = $iteminfos->{budget_code}; |
535 |
$iteminfos->{budget_id} = $item_budget->{budget_id} || $budget_id; |
535 |
my $item_budget_id; |
|
|
536 |
if ( $iteminfos->{budget_code} ) { |
537 |
my $item_budget = GetBudgetByCode( $iteminfos->{budget_code} ); |
538 |
if ( $item_budget ) { |
539 |
$item_budget_id = $item_budget->{budget_id}; |
540 |
} |
541 |
} |
536 |
} |
542 |
my $item_price = $iteminfos->{price}; |
|
|
543 |
my $item_replacement_price = $iteminfos->{replacementprice}; |
544 |
my $item_callnumber = $iteminfos->{itemcallnumber}; |
545 |
|
546 |
for (my $i = 0; $i < $item_quantity; $i++) { |
547 |
|
548 |
my %itemrecord = ( |
549 |
'item_id' => $item_id++, |
550 |
'biblio_count' => $biblio_count, |
551 |
'homebranch' => $item_homebranch, |
552 |
'holdingbranch' => $item_holdingbranch, |
553 |
'itype' => $item_itype, |
554 |
'nonpublic_note' => $item_nonpublic_note, |
555 |
'public_note' => $item_public_note, |
556 |
'loc' => $item_loc, |
557 |
'ccode' => $item_ccode, |
558 |
'notforloan' => $item_notforloan, |
559 |
'uri' => $item_uri, |
560 |
'copyno' => $item_copyno, |
561 |
'quantity' => $item_quantity, |
562 |
'budget_id' => $item_budget_id || $budget_id, |
563 |
'itemprice' => $item_price || $price, |
564 |
'replacementprice' => $item_replacement_price || $replacementprice, |
565 |
'itemcallnumber' => $item_callnumber, |
566 |
); |
567 |
$all_items_quantity++; |
568 |
push @itemlist, \%itemrecord; |
569 |
|
537 |
|
|
|
538 |
# Clone the item data for the needed quantity |
539 |
# Add the incremented item id for each item in that quantity |
540 |
for (my $i = 0; $i < $quantity; $i++) { |
541 |
my $itemrecord = { %$iteminfos }; |
542 |
$itemrecord->{item_id} = $item_id++; |
543 |
$all_items_quantity++; |
544 |
push @itemlist, $itemrecord; |
570 |
} |
545 |
} |
571 |
} |
546 |
} |
572 |
|
547 |
|
Lines 699-707
sub equal_number_of_fields {
Link Here
|
699 |
return $tags_count; |
674 |
return $tags_count; |
700 |
} |
675 |
} |
701 |
|
676 |
|
702 |
sub get_infos_syspref_on_item { |
677 |
sub get_marc_item_fields_to_order { |
703 |
my ($syspref_name, $record, $field_list) = @_; |
678 |
my ($record) = @_; |
704 |
my $syspref = C4::Context->preference($syspref_name); |
679 |
|
|
|
680 |
my $syspref = C4::Context->preference('MarcItemFieldsToOrder'); |
705 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
681 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
706 |
my $yaml = eval { |
682 |
my $yaml = eval { |
707 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
683 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
Lines 710-721
sub get_infos_syspref_on_item {
Link Here
|
710 |
warn "Unable to parse $syspref syspref : $@"; |
686 |
warn "Unable to parse $syspref syspref : $@"; |
711 |
return (); |
687 |
return (); |
712 |
} |
688 |
} |
|
|
689 |
|
713 |
my @result; |
690 |
my @result; |
714 |
my @tags_list; |
691 |
my @tags_list; |
715 |
|
692 |
|
716 |
# Check tags in syspref definition |
693 |
# Check tags in syspref definition |
717 |
for my $field_name ( @$field_list ) { |
694 |
for my $field_name ( keys %$yaml ) { |
718 |
next unless exists $yaml->{$field_name}; |
|
|
719 |
my @fields = split /\|/, $yaml->{$field_name}; |
695 |
my @fields = split /\|/, $yaml->{$field_name}; |
720 |
for my $field ( @fields ) { |
696 |
for my $field ( @fields ) { |
721 |
my ( $f, $sf ) = split /\$/, $field; |
697 |
my ( $f, $sf ) = split /\$/, $field; |
Lines 741-748
sub get_infos_syspref_on_item {
Link Here
|
741 |
|
717 |
|
742 |
for (my $i = 0; $i < $tags_count; $i++) { |
718 |
for (my $i = 0; $i < $tags_count; $i++) { |
743 |
my $r; |
719 |
my $r; |
744 |
for my $field_name ( @$field_list ) { |
720 |
for my $field_name ( keys %$yaml ) { |
745 |
next unless exists $yaml->{$field_name}; |
|
|
746 |
my @fields = split /\|/, $yaml->{$field_name}; |
721 |
my @fields = split /\|/, $yaml->{$field_name}; |
747 |
for my $field ( @fields ) { |
722 |
for my $field ( @fields ) { |
748 |
my ( $f, $sf ) = split /\$/, $field; |
723 |
my ( $f, $sf ) = split /\$/, $field; |
749 |
- |
|
|