Lines 66-95
the item's id in the breeding reservoir
Link Here
|
66 |
|
66 |
|
67 |
use Modern::Perl; |
67 |
use Modern::Perl; |
68 |
use CGI qw ( -utf8 ); |
68 |
use CGI qw ( -utf8 ); |
69 |
use C4::Context; |
|
|
70 |
|
69 |
|
|
|
70 |
use C4::Acquisition; |
71 |
use C4::Auth; |
71 |
use C4::Auth; |
|
|
72 |
use C4::Biblio; # GetBiblioData GetMarcPrice |
72 |
use C4::Budgets; |
73 |
use C4::Budgets; |
73 |
|
74 |
use C4::Context; |
74 |
use C4::Acquisition; |
|
|
75 |
use C4::Contract; |
75 |
use C4::Contract; |
76 |
use C4::Suggestions; # GetSuggestion |
76 |
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; # needed for z3950 import: |
77 |
use C4::Biblio; # GetBiblioData GetMarcPrice |
|
|
78 |
use C4::Items; #PrepareItemRecord |
77 |
use C4::Items; #PrepareItemRecord |
79 |
use C4::Output; |
|
|
80 |
use C4::Koha; |
78 |
use C4::Koha; |
81 |
use C4::Members; |
79 |
use C4::Members; |
82 |
use C4::Search qw/FindDuplicate/; |
80 |
use C4::Output; |
83 |
|
81 |
use C4::Search qw/ FindDuplicate /; |
84 |
#needed for z3950 import: |
82 |
use C4::Suggestions; # GetSuggestion |
85 |
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; |
|
|
86 |
|
87 |
use Koha::Acquisition::Booksellers; |
83 |
use Koha::Acquisition::Booksellers; |
88 |
use Koha::Acquisition::Currencies; |
84 |
use Koha::Acquisition::Currencies; |
|
|
85 |
use Koha::Acquisition::Utils; |
89 |
use Koha::BiblioFrameworks; |
86 |
use Koha::BiblioFrameworks; |
90 |
use Koha::DateUtils qw( dt_from_string ); |
87 |
use Koha::DateUtils qw( dt_from_string ); |
91 |
use Koha::MarcSubfieldStructures; |
|
|
92 |
use Koha::ItemTypes; |
88 |
use Koha::ItemTypes; |
|
|
89 |
use Koha::MarcSubfieldStructures; |
93 |
use Koha::Patrons; |
90 |
use Koha::Patrons; |
94 |
use Koha::RecordProcessor; |
91 |
use Koha::RecordProcessor; |
95 |
use Koha::Subscriptions; |
92 |
use Koha::Subscriptions; |
Lines 622-628
sub staged_items_field {
Link Here
|
622 |
my ($marcrecord, $encoding) = MARCfindbreeding($breedingid); |
619 |
my ($marcrecord, $encoding) = MARCfindbreeding($breedingid); |
623 |
die("Could not find the selected record in the reservoir, bailing") unless $marcrecord; |
620 |
die("Could not find the selected record in the reservoir, bailing") unless $marcrecord; |
624 |
|
621 |
|
625 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice']); |
622 |
my $infos = Koha::Acquisition::Utils::get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice']); |
626 |
my $price = $infos->{price}; |
623 |
my $price = $infos->{price}; |
627 |
my $replacementprice = $infos->{replacementprice}; |
624 |
my $replacementprice = $infos->{replacementprice}; |
628 |
my $quantity = $infos->{quantity}; |
625 |
my $quantity = $infos->{quantity}; |
Lines 640-646
sub staged_items_field {
Link Here
|
640 |
# Items |
637 |
# Items |
641 |
my @itemlist = (); |
638 |
my @itemlist = (); |
642 |
my $all_items_quantity = 0; |
639 |
my $all_items_quantity = 0; |
643 |
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']); |
640 |
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']); |
644 |
if ($alliteminfos != -1) { |
641 |
if ($alliteminfos != -1) { |
645 |
foreach my $iteminfos (@$alliteminfos) { |
642 |
foreach my $iteminfos (@$alliteminfos) { |
646 |
my %itemrecord=( |
643 |
my %itemrecord=( |
Lines 689-801
sub staged_items_field {
Link Here
|
689 |
return (\%cellrecord); |
686 |
return (\%cellrecord); |
690 |
} |
687 |
} |
691 |
|
688 |
|
692 |
sub get_infos_syspref { |
|
|
693 |
my ($syspref_name, $record, $field_list) = @_; |
694 |
my $syspref = C4::Context->preference($syspref_name); |
695 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
696 |
my $yaml = eval { |
697 |
YAML::Load($syspref); |
698 |
}; |
699 |
if ( $@ ) { |
700 |
warn "Unable to parse $syspref syspref : $@"; |
701 |
return (); |
702 |
} |
703 |
my $r; |
704 |
for my $field_name ( @$field_list ) { |
705 |
next unless exists $yaml->{$field_name}; |
706 |
my @fields = split /\|/, $yaml->{$field_name}; |
707 |
for my $field ( @fields ) { |
708 |
my ( $f, $sf ) = split /\$/, $field; |
709 |
next unless $f and $sf; |
710 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
711 |
$r->{$field_name} = $v; |
712 |
} |
713 |
last if $yaml->{$field}; |
714 |
} |
715 |
} |
716 |
return $r; |
717 |
} |
718 |
|
719 |
sub equal_number_of_fields { |
720 |
my ($tags_list, $record) = @_; |
721 |
my $tag_fields_count; |
722 |
for my $tag (@$tags_list) { |
723 |
my @fields = $record->field($tag); |
724 |
$tag_fields_count->{$tag} = scalar @fields; |
725 |
} |
726 |
|
727 |
my $tags_count; |
728 |
foreach my $key ( keys %$tag_fields_count ) { |
729 |
if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok |
730 |
$tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence |
731 |
return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
732 |
} |
733 |
} |
734 |
|
735 |
return $tags_count; |
736 |
} |
737 |
|
738 |
sub get_infos_syspref_on_item { |
739 |
my ($syspref_name, $record, $field_list) = @_; |
740 |
my $syspref = C4::Context->preference($syspref_name); |
741 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
742 |
my $yaml = eval { |
743 |
YAML::Load($syspref); |
744 |
}; |
745 |
if ( $@ ) { |
746 |
warn "Unable to parse $syspref syspref : $@"; |
747 |
return (); |
748 |
} |
749 |
my @result; |
750 |
my @tags_list; |
751 |
|
752 |
# Check tags in syspref definition |
753 |
for my $field_name ( @$field_list ) { |
754 |
next unless exists $yaml->{$field_name}; |
755 |
my @fields = split /\|/, $yaml->{$field_name}; |
756 |
for my $field ( @fields ) { |
757 |
my ( $f, $sf ) = split /\$/, $field; |
758 |
next unless $f and $sf; |
759 |
push @tags_list, $f; |
760 |
} |
761 |
} |
762 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
763 |
|
764 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
765 |
# Return if the number of these fields in the record is not the same. |
766 |
return -1 if $tags_count == -1; |
767 |
|
768 |
# Gather the fields |
769 |
my $fields_hash; |
770 |
foreach my $tag (@tags_list) { |
771 |
my @tmp_fields; |
772 |
foreach my $field ($record->field($tag)) { |
773 |
push @tmp_fields, $field; |
774 |
} |
775 |
$fields_hash->{$tag} = \@tmp_fields; |
776 |
} |
777 |
|
778 |
for (my $i = 0; $i < $tags_count; $i++) { |
779 |
my $r; |
780 |
for my $field_name ( @$field_list ) { |
781 |
next unless exists $yaml->{$field_name}; |
782 |
my @fields = split /\|/, $yaml->{$field_name}; |
783 |
for my $field ( @fields ) { |
784 |
my ( $f, $sf ) = split /\$/, $field; |
785 |
next unless $f and $sf; |
786 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef; |
787 |
$r->{$field_name} = $v if (defined $v); |
788 |
last if $yaml->{$field}; |
789 |
} |
790 |
} |
791 |
push @result, $r; |
792 |
} |
793 |
return \@result; |
794 |
} |
795 |
|
689 |
|
796 |
sub _trim { |
690 |
sub _trim { |
797 |
return $_[0] unless $_[0]; |
691 |
my $string = shift; |
798 |
$_[0] =~ s/^\s+//; |
692 |
return unless $string; |
799 |
$_[0] =~ s/\s+$//; |
693 |
$string =~ s/^\s+|\s+$//g |
800 |
$_[0]; |
694 |
return $string; |
801 |
} |
695 |
} |
802 |
- |
|
|