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