|
Lines 44-57
use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc );
Link Here
|
| 44 |
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode ); |
44 |
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode ); |
| 45 |
use C4::Suggestions; # GetSuggestion |
45 |
use C4::Suggestions; # GetSuggestion |
| 46 |
use C4::Members; |
46 |
use C4::Members; |
| 47 |
|
47 |
use C4::Output; |
| 48 |
use Koha::Number::Price; |
48 |
use C4::Search qw/FindDuplicate/; |
| 49 |
use Koha::Libraries; |
49 |
use C4::Suggestions; # GetSuggestion |
| 50 |
use Koha::Acquisition::Baskets; |
50 |
use Koha::Acquisition::Baskets; |
|
|
51 |
use Koha::Acquisition::Booksellers; |
| 51 |
use Koha::Acquisition::Currencies; |
52 |
use Koha::Acquisition::Currencies; |
| 52 |
use Koha::Acquisition::Orders; |
53 |
use Koha::Acquisition::Orders; |
| 53 |
use Koha::Acquisition::Booksellers; |
54 |
use Koha::Acquisition::Utils; |
| 54 |
use Koha::Import::Records; |
55 |
use Koha::Import::Records; |
|
|
56 |
use Koha::Libraries; |
| 57 |
use Koha::Number::Price; |
| 55 |
use Koha::Patrons; |
58 |
use Koha::Patrons; |
| 56 |
|
59 |
|
| 57 |
my $input = CGI->new; |
60 |
my $input = CGI->new; |
|
Lines 489-495
sub import_biblios_list {
Link Here
|
| 489 |
); |
492 |
); |
| 490 |
my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; |
493 |
my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; |
| 491 |
|
494 |
|
| 492 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']); |
495 |
my $infos = Koha::Acquisition::Utils::get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']); |
| 493 |
my $price = $infos->{price}; |
496 |
my $price = $infos->{price}; |
| 494 |
my $replacementprice = $infos->{replacementprice}; |
497 |
my $replacementprice = $infos->{replacementprice}; |
| 495 |
my $quantity = $infos->{quantity}; |
498 |
my $quantity = $infos->{quantity}; |
|
Lines 508-514
sub import_biblios_list {
Link Here
|
| 508 |
# Items |
511 |
# Items |
| 509 |
my @itemlist = (); |
512 |
my @itemlist = (); |
| 510 |
my $all_items_quantity = 0; |
513 |
my $all_items_quantity = 0; |
| 511 |
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']); |
514 |
my $alliteminfos = C4::Acquisition::Utils::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']); |
| 512 |
if ($alliteminfos != -1) { |
515 |
if ($alliteminfos != -1) { |
| 513 |
foreach my $iteminfos (@$alliteminfos) { |
516 |
foreach my $iteminfos (@$alliteminfos) { |
| 514 |
my $item_homebranch = $iteminfos->{homebranch}; |
517 |
my $item_homebranch = $iteminfos->{homebranch}; |
|
Lines 643-749
sub add_matcher_list {
Link Here
|
| 643 |
} |
646 |
} |
| 644 |
$template->param(available_matchers => \@matchers); |
647 |
$template->param(available_matchers => \@matchers); |
| 645 |
} |
648 |
} |
| 646 |
|
|
|
| 647 |
sub get_infos_syspref { |
| 648 |
my ($syspref_name, $record, $field_list) = @_; |
| 649 |
my $syspref = C4::Context->preference($syspref_name); |
| 650 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
| 651 |
my $yaml = eval { |
| 652 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
| 653 |
}; |
| 654 |
if ( $@ ) { |
| 655 |
warn "Unable to parse $syspref syspref : $@"; |
| 656 |
return (); |
| 657 |
} |
| 658 |
my $r; |
| 659 |
for my $field_name ( @$field_list ) { |
| 660 |
next unless exists $yaml->{$field_name}; |
| 661 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 662 |
for my $field ( @fields ) { |
| 663 |
my ( $f, $sf ) = split /\$/, $field; |
| 664 |
next unless $f and $sf; |
| 665 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
| 666 |
$r->{$field_name} = $v; |
| 667 |
} |
| 668 |
last if $yaml->{$field}; |
| 669 |
} |
| 670 |
} |
| 671 |
return $r; |
| 672 |
} |
| 673 |
|
| 674 |
sub equal_number_of_fields { |
| 675 |
my ($tags_list, $record) = @_; |
| 676 |
my $tag_fields_count; |
| 677 |
for my $tag (@$tags_list) { |
| 678 |
my @fields = $record->field($tag); |
| 679 |
$tag_fields_count->{$tag} = scalar @fields; |
| 680 |
} |
| 681 |
|
| 682 |
my $tags_count; |
| 683 |
foreach my $key ( keys %$tag_fields_count ) { |
| 684 |
if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok |
| 685 |
$tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence |
| 686 |
return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
return $tags_count; |
| 691 |
} |
| 692 |
|
| 693 |
sub get_infos_syspref_on_item { |
| 694 |
my ($syspref_name, $record, $field_list) = @_; |
| 695 |
my $syspref = C4::Context->preference($syspref_name); |
| 696 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
| 697 |
my $yaml = eval { |
| 698 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
| 699 |
}; |
| 700 |
if ( $@ ) { |
| 701 |
warn "Unable to parse $syspref syspref : $@"; |
| 702 |
return (); |
| 703 |
} |
| 704 |
my @result; |
| 705 |
my @tags_list; |
| 706 |
|
| 707 |
# Check tags in syspref definition |
| 708 |
for my $field_name ( @$field_list ) { |
| 709 |
next unless exists $yaml->{$field_name}; |
| 710 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 711 |
for my $field ( @fields ) { |
| 712 |
my ( $f, $sf ) = split /\$/, $field; |
| 713 |
next unless $f and $sf; |
| 714 |
push @tags_list, $f; |
| 715 |
} |
| 716 |
} |
| 717 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
| 718 |
|
| 719 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
| 720 |
# Return if the number of these fields in the record is not the same. |
| 721 |
return -1 if $tags_count == -1; |
| 722 |
|
| 723 |
# Gather the fields |
| 724 |
my $fields_hash; |
| 725 |
foreach my $tag (@tags_list) { |
| 726 |
my @tmp_fields; |
| 727 |
foreach my $field ($record->field($tag)) { |
| 728 |
push @tmp_fields, $field; |
| 729 |
} |
| 730 |
$fields_hash->{$tag} = \@tmp_fields; |
| 731 |
} |
| 732 |
|
| 733 |
for (my $i = 0; $i < $tags_count; $i++) { |
| 734 |
my $r; |
| 735 |
for my $field_name ( @$field_list ) { |
| 736 |
next unless exists $yaml->{$field_name}; |
| 737 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 738 |
for my $field ( @fields ) { |
| 739 |
my ( $f, $sf ) = split /\$/, $field; |
| 740 |
next unless $f and $sf; |
| 741 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef; |
| 742 |
$r->{$field_name} = $v if (defined $v); |
| 743 |
last if $yaml->{$field}; |
| 744 |
} |
| 745 |
} |
| 746 |
push @result, $r; |
| 747 |
} |
| 748 |
return \@result; |
| 749 |
} |