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