Lines 306-311
if ( not $ordernumber or $biblionumber ) {
Link Here
|
306 |
} |
306 |
} |
307 |
} |
307 |
} |
308 |
|
308 |
|
|
|
309 |
our $usebreedingid = $input->param('use_breedingid'); |
310 |
if ( $usebreedingid ) { |
311 |
my $item_list = staged_items_field( $usebreedingid ); |
312 |
$listprice = $item_list->{'price'}; |
313 |
$template->param( item_list => $item_list->{'iteminfos'} ); |
314 |
} |
315 |
|
309 |
$template->param( catalog_details => \@catalog_details, ); |
316 |
$template->param( catalog_details => \@catalog_details, ); |
310 |
|
317 |
|
311 |
my $suggestion; |
318 |
my $suggestion; |
Lines 599-601
sub Load_Duplicate {
Link Here
|
599 |
|
606 |
|
600 |
output_html_with_http_headers $input, $cookie, $template->output; |
607 |
output_html_with_http_headers $input, $cookie, $template->output; |
601 |
} |
608 |
} |
|
|
609 |
|
610 |
sub staged_items_field { |
611 |
my ($breedingid) = @_; |
612 |
my %cellrecord = (); |
613 |
|
614 |
my ($marcrecord, $encoding) = MARCfindbreeding($breedingid); |
615 |
die("Could not find the selected record in the reservoir, bailing") unless $marcrecord; |
616 |
|
617 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
618 |
my $price = $infos->{price}; |
619 |
my $quantity = $infos->{quantity}; |
620 |
my $budget_code = $infos->{budget_code}; |
621 |
my $discount = $infos->{discount}; |
622 |
my $sort1 = $infos->{sort1}; |
623 |
my $sort2 = $infos->{sort2}; |
624 |
my $budget_id; |
625 |
if($budget_code) { |
626 |
my $biblio_budget = GetBudgetByCode($budget_code); |
627 |
if($biblio_budget) { |
628 |
$budget_id = $biblio_budget->{budget_id}; |
629 |
} |
630 |
} |
631 |
# Items |
632 |
my @itemlist = (); |
633 |
my $all_items_quantity = 0; |
634 |
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']); |
635 |
if ($alliteminfos != -1) { |
636 |
foreach my $iteminfos (@$alliteminfos) { |
637 |
my %itemrecord=( |
638 |
'homebranch' => _trim( $iteminfos->{homebranch} ), |
639 |
'holdingbranch' => _trim( $iteminfos->{holdingbranch} ), |
640 |
'itype' => _trim( $iteminfos->{itype} ), |
641 |
'itemnotes_nonpublic' => $iteminfos->{nonpublic_note}, |
642 |
'itemnotes' => $iteminfos->{public_note}, |
643 |
'location' => _trim( $iteminfos->{loc} ), |
644 |
'ccode' => _trim( $iteminfos->{ccode} ), |
645 |
'notforloan' => _trim( $iteminfos->{notforloan} ), |
646 |
'uri' => $iteminfos->{uri}, |
647 |
'copynumber' => $iteminfos->{copyno}, |
648 |
'price' => $iteminfos->{price}, |
649 |
'replacementprice' => $iteminfos->{replacementprice}, |
650 |
'itemcallnumber' => $iteminfos->{itemcallnumber}, |
651 |
); |
652 |
|
653 |
my $item_quantity = $iteminfos->{quantity} || 1; |
654 |
|
655 |
for (my $i = 0; $i < $item_quantity; $i++) { |
656 |
my %defaultvalues=( |
657 |
'itemrecord'=> C4::Items::Item2Marc( \%itemrecord), |
658 |
'branchcode'=>_trim($iteminfos->{homebranch}) |
659 |
); |
660 |
$all_items_quantity++; |
661 |
my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ'); |
662 |
push @itemlist, $itemprocessed->{'iteminformation'}; |
663 |
|
664 |
} |
665 |
} |
666 |
|
667 |
$cellrecord{'iteminfos'} = \@itemlist; |
668 |
} else { |
669 |
$cellrecord{'item_error'} = 1; |
670 |
} |
671 |
$cellrecord{price} = $price || ''; |
672 |
$cellrecord{quantity} = $quantity || ''; |
673 |
$cellrecord{budget_id} = $budget_id || ''; |
674 |
$cellrecord{discount} = $discount || ''; |
675 |
$cellrecord{sort1} = $sort1 || ''; |
676 |
$cellrecord{sort2} = $sort2 || ''; |
677 |
unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) { |
678 |
$cellrecord{quantity} = $all_items_quantity; |
679 |
} |
680 |
|
681 |
return (\%cellrecord); |
682 |
} |
683 |
|
684 |
sub get_infos_syspref { |
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 $r; |
696 |
for my $field_name ( @$field_list ) { |
697 |
next unless exists $yaml->{$field_name}; |
698 |
my @fields = split /\|/, $yaml->{$field_name}; |
699 |
for my $field ( @fields ) { |
700 |
my ( $f, $sf ) = split /\$/, $field; |
701 |
next unless $f and $sf; |
702 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
703 |
$r->{$field_name} = $v; |
704 |
} |
705 |
last if $yaml->{$field}; |
706 |
} |
707 |
} |
708 |
return $r; |
709 |
} |
710 |
sub equal_number_of_fields { |
711 |
my ($tags_list, $record) = @_; |
712 |
my $tag_fields_count; |
713 |
for my $tag (@$tags_list) { |
714 |
my @fields = $record->field($tag); |
715 |
$tag_fields_count->{$tag} = scalar @fields; |
716 |
} |
717 |
|
718 |
my $tags_count; |
719 |
foreach my $key ( keys %$tag_fields_count ) { |
720 |
if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok |
721 |
$tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence |
722 |
return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
723 |
} |
724 |
} |
725 |
|
726 |
return $tags_count; |
727 |
} |
728 |
|
729 |
sub get_infos_syspref_on_item { |
730 |
my ($syspref_name, $record, $field_list) = @_; |
731 |
my $syspref = C4::Context->preference($syspref_name); |
732 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
733 |
my $yaml = eval { |
734 |
YAML::Load($syspref); |
735 |
}; |
736 |
if ( $@ ) { |
737 |
warn "Unable to parse $syspref syspref : $@"; |
738 |
return (); |
739 |
} |
740 |
my @result; |
741 |
my @tags_list; |
742 |
|
743 |
# Check tags in syspref definition |
744 |
for my $field_name ( @$field_list ) { |
745 |
next unless exists $yaml->{$field_name}; |
746 |
my @fields = split /\|/, $yaml->{$field_name}; |
747 |
for my $field ( @fields ) { |
748 |
my ( $f, $sf ) = split /\$/, $field; |
749 |
next unless $f and $sf; |
750 |
push @tags_list, $f; |
751 |
} |
752 |
} |
753 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
754 |
|
755 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
756 |
# Return if the number of these fields in the record is not the same. |
757 |
return -1 if $tags_count == -1; |
758 |
|
759 |
# Gather the fields |
760 |
my $fields_hash; |
761 |
foreach my $tag (@tags_list) { |
762 |
my @tmp_fields; |
763 |
foreach my $field ($record->field($tag)) { |
764 |
push @tmp_fields, $field; |
765 |
} |
766 |
$fields_hash->{$tag} = \@tmp_fields; |
767 |
} |
768 |
|
769 |
for (my $i = 0; $i < $tags_count; $i++) { |
770 |
my $r; |
771 |
for my $field_name ( @$field_list ) { |
772 |
next unless exists $yaml->{$field_name}; |
773 |
my @fields = split /\|/, $yaml->{$field_name}; |
774 |
for my $field ( @fields ) { |
775 |
my ( $f, $sf ) = split /\$/, $field; |
776 |
next unless $f and $sf; |
777 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef; |
778 |
$r->{$field_name} = $v if (defined $v); |
779 |
last if $yaml->{$field}; |
780 |
} |
781 |
} |
782 |
push @result, $r; |
783 |
} |
784 |
return \@result; |
785 |
} |
786 |
|
787 |
sub _trim { |
788 |
return $_[0] unless $_[0]; |
789 |
$_[0] =~ s/^\s+//; |
790 |
$_[0] =~ s/\s+$//; |
791 |
$_[0]; |
792 |
} |