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