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