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