Lines 46-58
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget Get
Link Here
|
46 |
use C4::Acquisition qw( populate_order_with_prices ); |
46 |
use C4::Acquisition qw( populate_order_with_prices ); |
47 |
use C4::Suggestions; # GetSuggestion |
47 |
use C4::Suggestions; # GetSuggestion |
48 |
use C4::Members; |
48 |
use C4::Members; |
49 |
|
49 |
use C4::Output; |
50 |
use Koha::Number::Price; |
50 |
use C4::Search qw/FindDuplicate/; |
51 |
use Koha::Libraries; |
51 |
use C4::Suggestions; # GetSuggestion |
|
|
52 |
use Koha::Acquisition::Utils; |
52 |
use Koha::Acquisition::Baskets; |
53 |
use Koha::Acquisition::Baskets; |
|
|
54 |
use Koha::Acquisition::Booksellers; |
53 |
use Koha::Acquisition::Currencies; |
55 |
use Koha::Acquisition::Currencies; |
54 |
use Koha::Acquisition::Orders; |
56 |
use Koha::Acquisition::Orders; |
55 |
use Koha::Acquisition::Booksellers; |
57 |
use Koha::Libraries; |
|
|
58 |
use Koha::Number::Price; |
56 |
use Koha::Patrons; |
59 |
use Koha::Patrons; |
57 |
|
60 |
|
58 |
my $input = CGI->new; |
61 |
my $input = CGI->new; |
Lines 515-521
sub import_biblios_list {
Link Here
|
515 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
518 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
516 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
519 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
517 |
|
520 |
|
518 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']); |
521 |
my $infos = Koha::Acquisition::Utils::get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']); |
519 |
my $price = $infos->{price}; |
522 |
my $price = $infos->{price}; |
520 |
my $replacementprice = $infos->{replacementprice}; |
523 |
my $replacementprice = $infos->{replacementprice}; |
521 |
my $quantity = $infos->{quantity}; |
524 |
my $quantity = $infos->{quantity}; |
Lines 534-540
sub import_biblios_list {
Link Here
|
534 |
# Items |
537 |
# Items |
535 |
my @itemlist = (); |
538 |
my @itemlist = (); |
536 |
my $all_items_quantity = 0; |
539 |
my $all_items_quantity = 0; |
537 |
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']); |
540 |
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']); |
538 |
if ($alliteminfos != -1) { |
541 |
if ($alliteminfos != -1) { |
539 |
foreach my $iteminfos (@$alliteminfos) { |
542 |
foreach my $iteminfos (@$alliteminfos) { |
540 |
my $item_homebranch = $iteminfos->{homebranch}; |
543 |
my $item_homebranch = $iteminfos->{homebranch}; |
Lines 669-775
sub add_matcher_list {
Link Here
|
669 |
} |
672 |
} |
670 |
$template->param(available_matchers => \@matchers); |
673 |
$template->param(available_matchers => \@matchers); |
671 |
} |
674 |
} |
672 |
|
|
|
673 |
sub get_infos_syspref { |
674 |
my ($syspref_name, $record, $field_list) = @_; |
675 |
my $syspref = C4::Context->preference($syspref_name); |
676 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
677 |
my $yaml = eval { |
678 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
679 |
}; |
680 |
if ( $@ ) { |
681 |
warn "Unable to parse $syspref syspref : $@"; |
682 |
return (); |
683 |
} |
684 |
my $r; |
685 |
for my $field_name ( @$field_list ) { |
686 |
next unless exists $yaml->{$field_name}; |
687 |
my @fields = split /\|/, $yaml->{$field_name}; |
688 |
for my $field ( @fields ) { |
689 |
my ( $f, $sf ) = split /\$/, $field; |
690 |
next unless $f and $sf; |
691 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
692 |
$r->{$field_name} = $v; |
693 |
} |
694 |
last if $yaml->{$field}; |
695 |
} |
696 |
} |
697 |
return $r; |
698 |
} |
699 |
|
700 |
sub equal_number_of_fields { |
701 |
my ($tags_list, $record) = @_; |
702 |
my $tag_fields_count; |
703 |
for my $tag (@$tags_list) { |
704 |
my @fields = $record->field($tag); |
705 |
$tag_fields_count->{$tag} = scalar @fields; |
706 |
} |
707 |
|
708 |
my $tags_count; |
709 |
foreach my $key ( keys %$tag_fields_count ) { |
710 |
if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok |
711 |
$tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence |
712 |
return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
713 |
} |
714 |
} |
715 |
|
716 |
return $tags_count; |
717 |
} |
718 |
|
719 |
sub get_infos_syspref_on_item { |
720 |
my ($syspref_name, $record, $field_list) = @_; |
721 |
my $syspref = C4::Context->preference($syspref_name); |
722 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
723 |
my $yaml = eval { |
724 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
725 |
}; |
726 |
if ( $@ ) { |
727 |
warn "Unable to parse $syspref syspref : $@"; |
728 |
return (); |
729 |
} |
730 |
my @result; |
731 |
my @tags_list; |
732 |
|
733 |
# Check tags in syspref definition |
734 |
for my $field_name ( @$field_list ) { |
735 |
next unless exists $yaml->{$field_name}; |
736 |
my @fields = split /\|/, $yaml->{$field_name}; |
737 |
for my $field ( @fields ) { |
738 |
my ( $f, $sf ) = split /\$/, $field; |
739 |
next unless $f and $sf; |
740 |
push @tags_list, $f; |
741 |
} |
742 |
} |
743 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
744 |
|
745 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
746 |
# Return if the number of these fields in the record is not the same. |
747 |
return -1 if $tags_count == -1; |
748 |
|
749 |
# Gather the fields |
750 |
my $fields_hash; |
751 |
foreach my $tag (@tags_list) { |
752 |
my @tmp_fields; |
753 |
foreach my $field ($record->field($tag)) { |
754 |
push @tmp_fields, $field; |
755 |
} |
756 |
$fields_hash->{$tag} = \@tmp_fields; |
757 |
} |
758 |
|
759 |
for (my $i = 0; $i < $tags_count; $i++) { |
760 |
my $r; |
761 |
for my $field_name ( @$field_list ) { |
762 |
next unless exists $yaml->{$field_name}; |
763 |
my @fields = split /\|/, $yaml->{$field_name}; |
764 |
for my $field ( @fields ) { |
765 |
my ( $f, $sf ) = split /\$/, $field; |
766 |
next unless $f and $sf; |
767 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef; |
768 |
$r->{$field_name} = $v if (defined $v); |
769 |
last if $yaml->{$field}; |
770 |
} |
771 |
} |
772 |
push @result, $r; |
773 |
} |
774 |
return \@result; |
775 |
} |