View | Details | Raw Unified | Return to bug 20817
Collapse All | Expand All

(-)a/C4/Items.pm (-3 / +8 lines)
Lines 1262-1268 sub _find_value { Link Here
1262
1262
1263
=head2 PrepareItemrecordDisplay
1263
=head2 PrepareItemrecordDisplay
1264
1264
1265
  PrepareItemrecordDisplay($bibnum,$itemumber,$defaultvalues,$frameworkcode);
1265
  PrepareItemrecordDisplay($bibnum,$itemumber,$defaultvalues,$frameworkcode, $use_defaults);
1266
1266
1267
Returns a hash with all the fields for Display a given item data in a template
1267
Returns a hash with all the fields for Display a given item data in a template
1268
1268
Lines 1270-1280 $defaultvalues should either contain a hashref of values for the new item, or be Link Here
1270
1270
1271
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
1271
The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum is not provided
1272
1272
1273
If $use_defaults is true, the returned item values will be generated from the default values only.
1274
1273
=cut
1275
=cut
1274
1276
1275
sub PrepareItemrecordDisplay {
1277
sub PrepareItemrecordDisplay {
1276
1278
1277
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_;
1279
    my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode, $use_defaults ) = @_;
1278
1280
1279
    my $dbh = C4::Context->dbh;
1281
    my $dbh = C4::Context->dbh;
1280
    $frameworkcode = C4::Biblio::GetFrameworkCode($bibnum) if $bibnum;
1282
    $frameworkcode = C4::Biblio::GetFrameworkCode($bibnum) if $bibnum;
Lines 1294-1300 sub PrepareItemrecordDisplay { Link Here
1294
    # return nothing if we don't have found an existing framework.
1296
    # return nothing if we don't have found an existing framework.
1295
    return q{} unless $tagslib;
1297
    return q{} unless $tagslib;
1296
    my $itemrecord;
1298
    my $itemrecord;
1297
    if ($itemnum) {
1299
    if ($use_defaults) {
1300
        $itemrecord = $defaultvalues->{'itemrecord'};
1301
    }
1302
    elsif ($itemnum) {
1298
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
1303
        $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum );
1299
    }
1304
    }
1300
    my @loop_data;
1305
    my @loop_data;
(-)a/Koha/Acquisition/Utils.pm (+176 lines)
Line 0 Link Here
1
package Koha::Acquisition::Utils;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use YAML::XS;
21
22
use C4::Context;
23
24
=head1 NAME
25
26
Koha::Acquisition::Utils - Additional Koha functions for dealing with orders and acquisitions
27
28
=head2 SUBROUTINES
29
30
=head3 GetMarcFieldsToOrderValues($syspref_name, $record, $field_list)
31
32
my $data = Koha::Acquisition::Utils::GetMarcFieldsToOrderValues('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', etc.]);
33
34
The return value is a hashref of key value pairs, where the keys are the field list parameters,
35
and the values are extracted from the MARC record based on the key to MARC field mapping from the
36
system preference MarcFieldsToOrder.
37
38
=cut
39
40
sub GetMarcFieldsToOrderValues {
41
    my ($record, $field_list) = @_;
42
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
43
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
44
    my $yaml = eval {
45
        YAML::XS::Load($syspref);
46
    };
47
    if ( $@ ) {
48
        warn "Unable to parse $syspref syspref : $@";
49
        return ();
50
    }
51
    my $r;
52
    for my $field_name ( @$field_list ) {
53
        next unless exists $yaml->{$field_name};
54
        my @fields = split /\|/, $yaml->{$field_name};
55
        for my $field ( @fields ) {
56
            my ( $f, $sf ) = split /\$/, $field;
57
            next unless $f and $sf;
58
            if ( my $v = $record->subfield( $f, $sf ) ) {
59
                $r->{$field_name} = $v;
60
            }
61
            last if $yaml->{$field};
62
        }
63
    }
64
    return $r;
65
}
66
67
=head3 GetMarcItemFieldsToOrderValues($syspref_name, $record, $field_list)
68
69
my $data = GetMarcItemFieldsToOrderValues('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code']);
70
71
The return value is a hashref of key value pairs, where the keys are the field list parameters,
72
and the values are extracted from the MARC record based on the key to MARC field mapping from the
73
system preference MarcFieldsToOrder.
74
75
The largest difference between GetMarcFieldsToOrderValues and GetMarcItemFieldsToOrderValues is that the former deals
76
with singular marc fields, while the latter works on multiple matching marc fields and returns -1 if it cannot
77
find a matching number of all fields to be looked up.
78
79
=cut
80
81
sub GetMarcItemFieldsToOrderValues {
82
    my ($record, $field_list) = @_;
83
    my $syspref = C4::Context->preference('MarcItemFieldsToOrder');
84
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
85
    my $yaml = eval {
86
        YAML::XS::Load($syspref);
87
    };
88
    if ( $@ ) {
89
        warn "Unable to parse $syspref syspref : $@";
90
        return ();
91
    }
92
    my @result;
93
    my @tags_list;
94
95
    # Check tags in syspref definition
96
    for my $field_name ( @$field_list ) {
97
        next unless exists $yaml->{$field_name};
98
        my @fields = split /\|/, $yaml->{$field_name};
99
        for my $field ( @fields ) {
100
            my ( $f, $sf ) = split /\$/, $field;
101
            next unless $f and $sf;
102
            push @tags_list, $f;
103
        }
104
    }
105
    @tags_list = List::MoreUtils::uniq(@tags_list);
106
107
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
108
    # Return if the number of these fields in the record is not the same.
109
    return -1 if $tags_count == -1;
110
111
    # Gather the fields
112
    my $fields_hash;
113
    foreach my $tag (@tags_list) {
114
        my @tmp_fields;
115
        foreach my $field ($record->field($tag)) {
116
            push @tmp_fields, $field;
117
        }
118
        $fields_hash->{$tag} = \@tmp_fields;
119
    }
120
121
    for (my $i = 0; $i < $tags_count; $i++) {
122
        my $r;
123
        for my $field_name ( @$field_list ) {
124
            next unless exists $yaml->{$field_name};
125
            my @fields = split /\|/, $yaml->{$field_name};
126
            for my $field ( @fields ) {
127
                my ( $f, $sf ) = split /\$/, $field;
128
                next unless $f and $sf;
129
                my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef;
130
                $r->{$field_name} = $v if (defined $v);
131
                last if $yaml->{$field};
132
            }
133
        }
134
        push @result, $r;
135
    }
136
    return \@result;
137
}
138
139
=head3 equal_number_of_fields($tags_list, $record)
140
141
$value = equal_number_of_fields(\@tags_list, $record);
142
143
Returns -1 if the number of instances of the given tags are not equal.
144
145
For example, if you need to verify there are equal 975$i's and 975$a's,
146
this will let you know.
147
148
=cut
149
150
sub equal_number_of_fields {
151
    my ($tags_list, $record) = @_;
152
    my $tag_fields_count;
153
    for my $tag (@$tags_list) {
154
        my @fields = $record->field($tag);
155
        $tag_fields_count->{$tag} = scalar @fields;
156
    }
157
158
    my $tags_count;
159
    foreach my $key ( keys %$tag_fields_count ) {
160
        if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok
161
            $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence
162
            return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist
163
        }
164
    }
165
166
    return $tags_count;
167
}
168
169
1;
170
__END__
171
172
=head1 AUTHOR
173
174
Koha Development Team <http://koha-community.org/>
175
176
=cut
(-)a/acqui/addorderiso2709.pl (-110 / +9 lines)
Lines 44-57 use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc ); Link Here
44
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode );
44
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode );
45
use C4::Suggestions;    # GetSuggestion
45
use C4::Suggestions;    # GetSuggestion
46
use C4::Members;
46
use C4::Members;
47
47
use C4::Output;
48
use Koha::Number::Price;
48
use C4::Search qw/FindDuplicate/;
49
use Koha::Libraries;
49
use C4::Suggestions;    # GetSuggestion
50
use Koha::Acquisition::Baskets;
50
use Koha::Acquisition::Baskets;
51
use Koha::Acquisition::Booksellers;
51
use Koha::Acquisition::Currencies;
52
use Koha::Acquisition::Currencies;
52
use Koha::Acquisition::Orders;
53
use Koha::Acquisition::Orders;
53
use Koha::Acquisition::Booksellers;
54
use Koha::Acquisition::Utils;
54
use Koha::Import::Records;
55
use Koha::Import::Records;
56
use Koha::Libraries;
57
use Koha::Number::Price;
55
use Koha::Patrons;
58
use Koha::Patrons;
56
59
57
my $input = CGI->new;
60
my $input = CGI->new;
Lines 489-495 sub import_biblios_list { Link Here
489
        );
492
        );
490
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
493
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
491
494
492
        my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2','replacementprice']);
495
        my $infos = Koha::Acquisition::Utils::GetMarcFieldsToOrderValues( $marcrecord, [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice' ] );
493
        my $price = $infos->{price};
496
        my $price = $infos->{price};
494
        my $replacementprice = $infos->{replacementprice};
497
        my $replacementprice = $infos->{replacementprice};
495
        my $quantity = $infos->{quantity};
498
        my $quantity = $infos->{quantity};
Lines 508-514 sub import_biblios_list { Link Here
508
        # Items
511
        # Items
509
        my @itemlist = ();
512
        my @itemlist = ();
510
        my $all_items_quantity = 0;
513
        my $all_items_quantity = 0;
511
        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']);
514
        my $alliteminfos = Koha::Acquisition::Utils::GetMarcItemFieldsToOrderValues( $marcrecord, [ 'homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code' ] );
512
        if ($alliteminfos != -1) {
515
        if ($alliteminfos != -1) {
513
            foreach my $iteminfos (@$alliteminfos) {
516
            foreach my $iteminfos (@$alliteminfos) {
514
                my $item_homebranch = $iteminfos->{homebranch};
517
                my $item_homebranch = $iteminfos->{homebranch};
Lines 643-749 sub add_matcher_list { Link Here
643
    }
646
    }
644
    $template->param(available_matchers => \@matchers);
647
    $template->param(available_matchers => \@matchers);
645
}
648
}
646
647
sub get_infos_syspref {
648
    my ($syspref_name, $record, $field_list) = @_;
649
    my $syspref = C4::Context->preference($syspref_name);
650
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
651
    my $yaml = eval {
652
        YAML::XS::Load(Encode::encode_utf8($syspref));
653
    };
654
    if ( $@ ) {
655
        warn "Unable to parse $syspref syspref : $@";
656
        return ();
657
    }
658
    my $r;
659
    for my $field_name ( @$field_list ) {
660
        next unless exists $yaml->{$field_name};
661
        my @fields = split /\|/, $yaml->{$field_name};
662
        for my $field ( @fields ) {
663
            my ( $f, $sf ) = split /\$/, $field;
664
            next unless $f and $sf;
665
            if ( my $v = $record->subfield( $f, $sf ) ) {
666
                $r->{$field_name} = $v;
667
            }
668
            last if $yaml->{$field};
669
        }
670
    }
671
    return $r;
672
}
673
674
sub equal_number_of_fields {
675
    my ($tags_list, $record) = @_;
676
    my $tag_fields_count;
677
    for my $tag (@$tags_list) {
678
        my @fields = $record->field($tag);
679
        $tag_fields_count->{$tag} = scalar @fields;
680
    }
681
682
    my $tags_count;
683
    foreach my $key ( keys %$tag_fields_count ) {
684
        if ( $tag_fields_count->{$key} > 0 ) { # Having 0 of a field is ok
685
            $tags_count //= $tag_fields_count->{$key}; # Start with the count from the first occurrence
686
            return -1 if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist
687
        }
688
    }
689
690
    return $tags_count;
691
}
692
693
sub get_infos_syspref_on_item {
694
    my ($syspref_name, $record, $field_list) = @_;
695
    my $syspref = C4::Context->preference($syspref_name);
696
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
697
    my $yaml = eval {
698
        YAML::XS::Load(Encode::encode_utf8($syspref));
699
    };
700
    if ( $@ ) {
701
        warn "Unable to parse $syspref syspref : $@";
702
        return ();
703
    }
704
    my @result;
705
    my @tags_list;
706
707
    # Check tags in syspref definition
708
    for my $field_name ( @$field_list ) {
709
        next unless exists $yaml->{$field_name};
710
        my @fields = split /\|/, $yaml->{$field_name};
711
        for my $field ( @fields ) {
712
            my ( $f, $sf ) = split /\$/, $field;
713
            next unless $f and $sf;
714
            push @tags_list, $f;
715
        }
716
    }
717
    @tags_list = List::MoreUtils::uniq(@tags_list);
718
719
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
720
    # Return if the number of these fields in the record is not the same.
721
    return -1 if $tags_count == -1;
722
723
    # Gather the fields
724
    my $fields_hash;
725
    foreach my $tag (@tags_list) {
726
        my @tmp_fields;
727
        foreach my $field ($record->field($tag)) {
728
            push @tmp_fields, $field;
729
        }
730
        $fields_hash->{$tag} = \@tmp_fields;
731
    }
732
733
    for (my $i = 0; $i < $tags_count; $i++) {
734
        my $r;
735
        for my $field_name ( @$field_list ) {
736
            next unless exists $yaml->{$field_name};
737
            my @fields = split /\|/, $yaml->{$field_name};
738
            for my $field ( @fields ) {
739
                my ( $f, $sf ) = split /\$/, $field;
740
                next unless $f and $sf;
741
                my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield( $sf ) : undef;
742
                $r->{$field_name} = $v if (defined $v);
743
                last if $yaml->{$field};
744
            }
745
        }
746
        push @result, $r;
747
    }
748
    return \@result;
749
}
(-)a/acqui/neworderempty.pl (-2 / +96 lines)
Lines 66-72 the item's id in the breeding reservoir Link Here
66
66
67
use Modern::Perl;
67
use Modern::Perl;
68
use CGI qw ( -utf8 );
68
use CGI qw ( -utf8 );
69
use C4::Context;
70
69
71
use C4::Auth qw( get_template_and_user );
70
use C4::Auth qw( get_template_and_user );
72
use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget );
71
use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget );
Lines 85-90 use C4::Biblio qw( Link Here
85
use C4::Output qw( output_and_exit output_html_with_http_headers );
84
use C4::Output qw( output_and_exit output_html_with_http_headers );
86
use C4::Members;
85
use C4::Members;
87
use C4::Search qw( FindDuplicate );
86
use C4::Search qw( FindDuplicate );
87
use C4::Items qw( PrepareItemrecordDisplay );
88
88
89
#needed for z3950 import:
89
#needed for z3950 import:
90
use C4::ImportBatch qw( SetImportRecordStatus SetMatchedBiblionumber GetImportRecordMarc );
90
use C4::ImportBatch qw( SetImportRecordStatus SetMatchedBiblionumber GetImportRecordMarc );
Lines 92-101 use C4::ImportBatch qw( SetImportRecordStatus SetMatchedBiblionumber GetImportRe Link Here
92
use Koha::Acquisition::Booksellers;
92
use Koha::Acquisition::Booksellers;
93
use Koha::Acquisition::Currencies qw( get_active );
93
use Koha::Acquisition::Currencies qw( get_active );
94
use Koha::Biblios;
94
use Koha::Biblios;
95
use Koha::Acquisition::Utils;
95
use Koha::BiblioFrameworks;
96
use Koha::BiblioFrameworks;
96
use Koha::DateUtils qw( dt_from_string );
97
use Koha::DateUtils qw( dt_from_string );
97
use Koha::MarcSubfieldStructures;
98
use Koha::ItemTypes;
98
use Koha::ItemTypes;
99
use Koha::MarcSubfieldStructures;
99
use Koha::Patrons;
100
use Koha::Patrons;
100
use Koha::RecordProcessor;
101
use Koha::RecordProcessor;
101
use Koha::Subscriptions;
102
use Koha::Subscriptions;
Lines 321-326 if ( not $ordernumber or $biblionumber ) { Link Here
321
    }
322
    }
322
}
323
}
323
324
325
my $usebreedingid = $input->param('use_breedingid');
326
if ( $usebreedingid ) {
327
    my $item_list = staged_items_field( $usebreedingid );
328
    $listprice = $item_list->{'price'};
329
    $budget_id = $item_list->{'budget_id'};
330
    $data->{replacementprice} = $item_list->{'replacementprice'};
331
    $data->{'sort1'} = $item_list->{'sort1'};
332
    $data->{'sort2'} = $item_list->{'sort2'};
333
    $data->{'discount'} = $item_list->{'discount'};
334
    $data->{quantity}       = $item_list->{quantity};
335
    $template->param( item_list => $item_list->{'iteminfos'} );
336
}
337
324
$template->param( catalog_details => \@catalog_details, );
338
$template->param( catalog_details => \@catalog_details, );
325
339
326
my $suggestion;
340
my $suggestion;
Lines 608-610 sub Load_Duplicate { Link Here
608
622
609
  output_html_with_http_headers $input, $cookie, $template->output;
623
  output_html_with_http_headers $input, $cookie, $template->output;
610
}
624
}
625
626
sub staged_items_field {
627
    my ($breedingid) = @_;
628
    my %cellrecord = ();
629
630
    my ($marcrecord, $encoding) = MARCfindbreeding($breedingid);
631
    die("Could not find the selected record in the reservoir, bailing") unless $marcrecord;
632
633
    my $infos = Koha::Acquisition::Utils::GetMarcFieldsToOrderValues( $marcrecord, [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice' ] );
634
    my $price = $infos->{price};
635
    my $replacementprice = $infos->{replacementprice};
636
    my $quantity = $infos->{quantity};
637
    my $budget_code = $infos->{budget_code};
638
    my $discount = $infos->{discount};
639
    my $sort1 = $infos->{sort1};
640
    my $sort2 = $infos->{sort2};
641
    my $budget_id;
642
    if($budget_code) {
643
        my $biblio_budget = GetBudgetByCode($budget_code);
644
        if($biblio_budget) {
645
            $budget_id = $biblio_budget->{budget_id};
646
        }
647
    }
648
    # Items
649
    my @itemlist = ();
650
    my $all_items_quantity = 0;
651
    my $alliteminfos = Koha::Acquisition::Utils::GetMarcItemFieldsToOrderValues( $marcrecord, [ 'homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code' ] );
652
    if ($alliteminfos != -1) {
653
        foreach my $iteminfos (@$alliteminfos) {
654
            my %itemrecord=(
655
                'homebranch' => _trim( $iteminfos->{homebranch} ),
656
                'holdingbranch' => _trim( $iteminfos->{holdingbranch} ),
657
                'itype' => _trim( $iteminfos->{itype} ),
658
                'itemnotes_nonpublic' => $iteminfos->{nonpublic_note},
659
                'itemnotes' => $iteminfos->{public_note},
660
                'location' => _trim( $iteminfos->{loc} ),
661
                'ccode' => _trim( $iteminfos->{ccode} ),
662
                'notforloan' => _trim( $iteminfos->{notforloan} ),
663
                'uri' => $iteminfos->{uri},
664
                'copynumber' => $iteminfos->{copyno},
665
                'price' => $iteminfos->{price},
666
                'replacementprice' => $iteminfos->{replacementprice},
667
                'itemcallnumber' => $iteminfos->{itemcallnumber},
668
            );
669
670
            my $item_quantity = $iteminfos->{quantity} || 1;
671
672
            for (my $i = 0; $i < $item_quantity; $i++) {
673
                my %defaultvalues=(
674
                    'itemrecord'=> C4::Items::Item2Marc( \%itemrecord),
675
                    'branchcode'=>_trim($iteminfos->{homebranch})
676
                );
677
                $all_items_quantity++;
678
                my $itemprocessed = PrepareItemrecordDisplay('', '', \%defaultvalues , 'ACQ', 1);
679
                push @itemlist, $itemprocessed->{'iteminformation'};
680
            }
681
        }
682
        $cellrecord{'iteminfos'} = \@itemlist;
683
    } else {
684
        $cellrecord{'item_error'} = 1;
685
    }
686
    $cellrecord{price} = $price || '';
687
    $cellrecord{replacementprice} = $replacementprice || '';
688
    $cellrecord{quantity} = $quantity || '';
689
    $cellrecord{budget_id} = $budget_id || '';
690
    $cellrecord{discount} = $discount || '';
691
    $cellrecord{sort1} = $sort1 || '';
692
    $cellrecord{sort2} = $sort2 || '';
693
    unless ($alliteminfos == -1 && scalar(@$alliteminfos) == 0) {
694
        $cellrecord{quantity} = $all_items_quantity;
695
    }
696
697
    return (\%cellrecord);
698
}
699
700
sub _trim {
701
    my $string = shift // q{};
702
    $string =~ s/^\s+|\s+$//g;
703
    return $string;
704
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-2 / +67 lines)
Lines 5-10 Link Here
5
[% USE Price %]
5
[% USE Price %]
6
[% USE ItemTypes %]
6
[% USE ItemTypes %]
7
[% SET footerjs = 1 %]
7
[% SET footerjs = 1 %]
8
9
[% IF item_list %]
10
    [% SET footerjs = 0 %]
11
[% END %]
12
8
[% INCLUDE 'doc-head-open.inc' %]
13
[% INCLUDE 'doc-head-open.inc' %]
9
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
14
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
10
[% INCLUDE 'doc-head-close.inc' %]
15
[% INCLUDE 'doc-head-close.inc' %]
Lines 322-328 Link Here
322
              <div class="dialog message">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
327
              <div class="dialog message">The autoBarcode system preference is set to [% Koha.Preference('autoBarcode') | html %] and items with blank barcodes will have barcodes generated upon save to database</div>
323
          [% END %]
328
          [% END %]
324
329
325
          <div id="outeritemblock"></div>
330
          <div id="outeritemblock">
331
              [% FOREACH item IN item_list %]
332
                [% SET itemID = loop.count %]
333
                <div id="itemblock[% itemID | html %]" >
334
                    <ol>
335
                        [% FOREACH iteminfo IN item %]
336
                            [% IF ( iteminfo.hidden ) %]
337
                                <li style="[% iteminfo.hidden | html %];">
338
                            [% ELSE %]
339
                                <li>
340
                            [% END %]
341
                            <div class="subfield_line" id="subfield[% iteminfo.serialid | html %][% iteminfo.countitems | html %][% iteminfo.subfield | html %][% iteminfo.random | html %]">
342
                                [% IF (iteminfo.mandatory) %]
343
                                    <label class="required">[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
344
                                [% ELSE %]
345
                                    <label>[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
346
                                [% END %]
347
                                [% IF ( iteminfo.marc_value.type == 'select' ) %]
348
                                    <select name="field_value">
349
                                        [% FOREACH value IN iteminfo.marc_value.values %]
350
                                            [% IF ( value == iteminfo.marc_value.default ) %]
351
                                                <option value="[% value | html %]" selected="selected">[% iteminfo.marc_value.labels.$value | html %]</option>
352
                                            [% ELSE %]
353
                                                <option value="[% value | html %]">[% iteminfo.marc_value.labels.$value | html %]</option>
354
                                            [% END %]
355
                                        [% END %]
356
                                    </select>
357
                                [% ELSE %]
358
                                    [% iteminfo.marc_value | $raw %]
359
                                [% END %]
360
                                <input type="hidden" name="itemid" value="[% itemID | html %]" />
361
                                <input type="hidden" name="kohafield" value="[% iteminfo.kohafield | html %]" />
362
                                <input type="hidden" name="tag" value="[% iteminfo.tag | html %]" />
363
                                <input type="hidden" name="subfield" value="[% iteminfo.subfield | html %]" />
364
                                <input type="hidden" name="mandatory" value="[% iteminfo.mandatory | html %]" />
365
                                [% IF (iteminfo.mandatory) %] <span class="required">Required</span>[% END %]
366
                            </div>
367
                                </li>
368
                        [% END %]
369
                    </ol>
370
                    <fieldset class="action">
371
                        <input class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,'[% UniqueItemFields | html %]')" value="Add item" type="button">
372
                        <input class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="Clear" type="button">
373
                        <input class="addItemControl" name="buttonPlusMulti" onclick="javascript:this.nextElementSibling.style.display='inline'; return false;" style="cursor:pointer; margin:0 1em;" value="Add multiple items" type="button">
374
                        <span id="add_multiple_copies" style="display:none">
375
                            <input class="addItemControl" id="multiValue" name="multiValue" placeholder="Number of items to add" type="text" inputmode="numeric" pattern="[0-9]*">
376
                            <input class="addItemControl" name="buttonAddMulti&quot;" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,'[% UniqueItemFields | html %]')" value="Add" type="button">
377
                            <div class="dialog message">NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied</div>
378
                        </span>
379
                    </fieldset>
380
                </div>
381
            [% END %]
382
          </div>
326
383
327
      </fieldset>
384
      </fieldset>
328
      [% END %][%# | html UNLESS subscriptionid %]
385
      [% END %][%# | html UNLESS subscriptionid %]
Lines 630-636 Link Here
630
        }
687
        }
631
688
632
        $(document).ready(function(){
689
        $(document).ready(function(){
633
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
690
            var events = $('#outeritemblock > div').filter(function () {
691
                var el = BindPluginEvents(this.innerHTML);
692
                return el;
693
            });
694
695
            [% IF AcqCreateItemOrdering and not basket.is_standing and not item_list %]
634
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
696
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
635
            [% END %]
697
            [% END %]
636
698
Lines 727-732 Link Here
727
    </script>
789
    </script>
728
[% END %]
790
[% END %]
729
791
792
[% UNLESS ( footerjs ) %]
793
    [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %]
794
[% END %]
730
[% INCLUDE 'intranet-bottom.inc' %]
795
[% INCLUDE 'intranet-bottom.inc' %]
731
796
732
[% BLOCK display_subfield %]
797
[% BLOCK display_subfield %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty_duplicate.tt (-1 / +2 lines)
Lines 52-57 Link Here
52
<input type="hidden" name="basketno" value="[% basketno | html %]" />
52
<input type="hidden" name="basketno" value="[% basketno | html %]" />
53
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
53
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
54
<input type="submit" value="Use existing" />
54
<input type="submit" value="Use existing" />
55
<input type="hidden" name="use_breedingid" value="[% breedingid | html %]" />
55
</form>
56
</form>
56
</div>
57
</div>
57
</div>
58
</div>
Lines 76-82 Link Here
76
<input type="hidden" name="basketno" value="[% basketno | html %]" />
77
<input type="hidden" name="basketno" value="[% basketno | html %]" />
77
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
78
<input type="hidden" name="breedingid" value="[% breedingid | html %]" />
78
<input type="hidden" name="use_external_source" value="1" />
79
<input type="hidden" name="use_external_source" value="1" />
79
<input type="submit" value="Create new" />
80
<input type="hidden" name="use_breedingid" value="[% breedingid | html%]" />
80
</form>
81
</form>
81
</div>
82
</div>
82
</div>
83
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-1 / +1 lines)
Lines 11-17 function addItem( node, unique_item_fields ) { Link Here
11
    }
11
    }
12
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
12
    if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
13
        if ( current_qty < max_qty ) {
13
        if ( current_qty < max_qty ) {
14
            if ( current_qty < max_qty - 1 )
14
            if ( current_qty < max_qty - 1 && $('#outeritemblock > div:visible').length == 1 )
15
                cloneItemBlock(index, unique_item_fields);
15
                cloneItemBlock(index, unique_item_fields);
16
            addItemInList(index, unique_item_fields);
16
            addItemInList(index, unique_item_fields);
17
            $("#" + index).find("input[name='buttonPlus']").val( __("Update item") );
17
            $("#" + index).find("input[name='buttonPlus']").val( __("Update item") );
(-)a/t/Acquisition/Utils.t (-1 / +158 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use utf8;
20
21
use Test::More tests => 4;
22
use Test::MockModule;
23
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use MARC::Record;
28
29
use_ok('Koha::Acquisition::Utils');
30
31
my $schema = Koha::Database->schema;
32
$schema->storage->txn_begin;
33
my $builder = t::lib::TestBuilder->new;
34
my $dbh = C4::Context->dbh;
35
36
subtest "GetMarcFieldsToOrderValues" => sub {
37
    plan tests => 4;
38
39
    my $record = MARC::Record->new;
40
    $record->append_fields(
41
        MARC::Field->new( '500', '', '', a => 'Test 1' ),
42
        MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ),
43
        MARC::Field->new( '520', '', '', a => 'Test 3' ),
44
        MARC::Field->new( '541', '', '', a => 'Test 4' ),
45
    );
46
47
    my $MarcFieldsToOrder = q{
48
test1: 500$a
49
test2: 505$a
50
test3: 520$a
51
test4: 541$a
52
    };
53
    t::lib::Mocks::mock_preference('MarcFieldsToOrder', $MarcFieldsToOrder);
54
    my $data = Koha::Acquisition::Utils::GetMarcFieldsToOrderValues(
55
        $record,
56
        [ 'test1', 'test2', 'test3', 'test4' ]
57
    );
58
59
    is( $data->{test1}, "Test 1", "Got test 1 correctly" );
60
    is( $data->{test2}, "Test 2", "Got test 2 correctly" );
61
    is( $data->{test3}, "Test 3", "Got test 3 correctly" );
62
    is( $data->{test4}, "Test 4", "Got test 4 correctly" );
63
};
64
65
subtest "GetMarcItemFieldsToOrderValues" => sub {
66
    plan tests => 13;
67
68
    my $record = MARC::Record->new;
69
    $record->append_fields(
70
        MARC::Field->new( '500', '', '', a => 'Test 1' ),
71
        MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ),
72
        MARC::Field->new( '975', '', '', a => 'Test 3', b => "Test 4" ),
73
        MARC::Field->new( '975', '', '', a => 'Test 5', b => "Test 6" ),
74
        MARC::Field->new( '975', '', '', a => 'Test 7', b => "Test 8" ),
75
        MARC::Field->new( '976', '', '', a => 'Test 9', b => "Test 10" ),
76
        MARC::Field->new( '976', '', '', a => 'Test 11', b => "Test 12" ),
77
        MARC::Field->new( '976', '', '', a => 'Test 13', b => "Test 14" ),
78
    );
79
80
    my $MarcItemFieldsToOrder = q{
81
testA: 975$a
82
testB: 975$b
83
testC: 976$a
84
testD: 976$b
85
    };
86
    t::lib::Mocks::mock_preference('MarcItemFieldsToOrder', $MarcItemFieldsToOrder);
87
    my $data = Koha::Acquisition::Utils::GetMarcItemFieldsToOrderValues(
88
        $record,
89
        [ 'testA', 'testB', 'testC', 'testD' ]
90
    );
91
92
    is( $data->[0]->{testA}, "Test 3", 'Got first 975$a correctly' );
93
    is( $data->[0]->{testB}, "Test 4", 'Got first 975$b correctly' );
94
    is( $data->[1]->{testA}, "Test 5", 'Got second 975$a correctly' );
95
    is( $data->[1]->{testB}, "Test 6", 'Got second 975$b correctly' );
96
    is( $data->[2]->{testA}, "Test 7", 'Got third 975$a correctly' );
97
    is( $data->[2]->{testB}, "Test 8", 'Got third 975$b correctly' );
98
99
    is( $data->[0]->{testC}, "Test 9", 'Got first 976$a correctly' );
100
    is( $data->[0]->{testD}, "Test 10", 'Got first 976$b correctly' );
101
    is( $data->[1]->{testC}, "Test 11", 'Got second 976$a correctly' );
102
    is( $data->[1]->{testD}, "Test 12", 'Got second 976$b correctly' );
103
    is( $data->[2]->{testC}, "Test 13", 'Got third 976$a correctly' );
104
    is( $data->[2]->{testD}, "Test 14", 'Got third 976$b correctly' );
105
106
    # Test with bad record where fields are not one-to-one
107
    $record->append_fields(
108
        MARC::Field->new( '500', '', '', a => 'Test 1' ),
109
        MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ),
110
        MARC::Field->new( '975', '', '', a => 'Test 3', b => "Test 4" ),
111
        MARC::Field->new( '975', '', '', b => "Test 6" ),
112
        MARC::Field->new( '975', '', '', b => 'Test 7' ),
113
        MARC::Field->new( '976', '', '', a => 'Test 9', b => "Test 10" ),
114
        MARC::Field->new( '976', '', '', a => 'Test 11', b => "Test 12" ),
115
    );
116
117
    $data = Koha::Acquisition::Utils::GetMarcItemFieldsToOrderValues(
118
        $record,
119
        [ 'testA', 'testB', 'testC', 'testD' ]
120
    );
121
    is( $data, -1, "Got -1 if record fields are not one-to-one");
122
};
123
124
subtest "equal_number_of_fields" => sub {
125
    plan tests => 2;
126
127
    my $record = MARC::Record->new;
128
    $record->append_fields(
129
        MARC::Field->new( '500', '', '', a => 'Test 1' ),
130
        MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ),
131
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
132
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
133
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
134
        MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ),
135
        MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ),
136
        MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ),
137
    );
138
139
    my $data = Koha::Acquisition::Utils::equal_number_of_fields( [ '975', '976' ], $record );
140
    is( $data, '3', "Got correct number of fields in return value" );
141
142
    # Test with non-matching field sets
143
    $record->append_fields(
144
        MARC::Field->new( '500', '', '', a => 'Test 1' ),
145
        MARC::Field->new( '505', '', '', a => 'Test 2', u => 'http://example.com' ),
146
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
147
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
148
        MARC::Field->new( '975', '', '', a => 'Test a', b => "Test b" ),
149
        MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ),
150
        MARC::Field->new( '976', '', '', a => 'Test a', b => "Test b" ),
151
    );
152
153
    $data = Koha::Acquisition::Utils::equal_number_of_fields( [ '975', '976' ], $record );
154
    is( $data, '-1', "Got -1 in return value" );
155
};
156
157
$schema->storage->txn_rollback;
158
C4::Context->clear_syspref_cache();

Return to bug 20817