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

(-)a/Koha/MarcOrder.pm (-60 / +21 lines)
Lines 127-176 sub import_record_and_create_order_lines { Link Here
127
    };
127
    };
128
}
128
}
129
129
130
=head3 _get_MarcFieldsToOrder_syspref_data
130
=head3 _get_syspref_mappings
131
131
132
    my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data('MarcFieldsToOrder', $marcrecord, $fields);
132
    my $syspref_info = _get_syspref_mappings( $marcrecord, $syspref_name );
133
133
134
    Fetches data from a marc record based on the mappings in the syspref MarcFieldsToOrder using the fields selected in $fields (array).
134
    Fetches data from a marc record based on the mappings in the syspref MarcFieldsToOrder or MarcItemFieldsToOrder using the fields selected in $fields (array).
135
135
136
=cut
136
=cut
137
137
138
sub _get_MarcFieldsToOrder_syspref_data {
138
sub _get_syspref_mappings {
139
    my ( $syspref_name, $record, $field_list ) = @_;
139
    my ($record, $syspref_to_read) = @_;
140
    my $syspref = C4::Context->preference($syspref_name);
140
    my $syspref = C4::Context->yaml_preference($syspref_to_read);
141
    $syspref = "$syspref\n\n";
142
    my $yaml = eval { YAML::XS::Load( Encode::encode_utf8($syspref) ); };
143
    if ($@) {
144
        warn "Unable to parse $syspref syspref : $@";
145
        return ();
146
    }
147
    my $r;
148
    for my $field_name (@$field_list) {
149
        next unless exists $yaml->{$field_name};
150
        my @fields = split /\|/, $yaml->{$field_name};
151
        for my $field (@fields) {
152
            my ( $f, $sf ) = split /\$/, $field;
153
            next unless $f and $sf;
154
            if ( my $v = $record->subfield( $f, $sf ) ) {
155
                $r->{$field_name} = $v;
156
            }
157
            last if $yaml->{$field};
158
        }
159
    }
160
    return $r;
161
}
162
163
=head3 _get_MarcItemFieldsToOrder_syspref_data
164
165
    my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data('MarcItemFieldsToOrder', $marcrecord, $fields);
166
167
    Fetches data from a marc record based on the mappings in the syspref MarcItemFieldsToOrder using the fields selected in $fields (array).
168
169
=cut
170
171
sub _get_MarcItemFieldsToOrder_syspref_data {
172
    my ($record) = @_;
173
    my $syspref = C4::Context->yaml_preference('MarcItemFieldsToOrder');
174
    my @result;
141
    my @result;
175
    my @tags_list;
142
    my @tags_list;
176
143
Lines 216-223 sub _get_MarcItemFieldsToOrder_syspref_data { Link Here
216
            push @result, $r;
183
            push @result, $r;
217
        }
184
        }
218
    }
185
    }
219
186
    return \@result if $syspref_to_read eq 'MarcItemFieldsToOrder';
220
    return \@result;
187
    return $result[0] if $syspref_to_read eq 'MarcFieldsToOrder';
221
}
188
}
222
189
223
=head3 _verify_number_of_fields
190
=head3 _verify_number_of_fields
Lines 365-376 sub add_items_from_import_record { Link Here
365
    my $marcrecord         = $record_result->{marcrecord};
332
    my $marcrecord         = $record_result->{marcrecord};
366
333
367
    if ( $agent eq 'cron' ) {
334
    if ( $agent eq 'cron' ) {
368
        my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data(
335
        my $marc_fields_to_order      = _get_syspref_mappings( $marcrecord, 'MarcFieldsToOrder' );
369
            'MarcFieldsToOrder', $marcrecord,
336
        my $marc_item_fields_to_order = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' );
370
            [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2' ]
371
        );
372
373
        my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data($marcrecord);
374
337
375
        my $item_fields = {
338
        my $item_fields = {
376
            homebranch       => $marc_item_fields_to_order->{homebranch},
339
            homebranch       => $marc_item_fields_to_order->{homebranch},
Lines 598-614 sub import_biblios_list { Link Here
598
        );
561
        );
599
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
562
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
600
563
601
        my $infos = _get_MarcFieldsToOrder_syspref_data(
564
        my $infos = _get_syspref_mappings( $marcrecord, 'MarcFieldsToOrder' );
602
            'MarcFieldsToOrder', $marcrecord,
565
603
            [ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice' ]
566
        my $price            = $infos->{price} || undef;
604
        );
567
        my $replacementprice = $infos->{replacementprice} || undef;
605
        my $price            = $infos->{price};
568
        my $quantity         = $infos->{quantity} || undef;
606
        my $replacementprice = $infos->{replacementprice};
569
        my $budget_code      = $infos->{budget_code} || undef;
607
        my $quantity         = $infos->{quantity};
570
        my $discount         = $infos->{discount} || undef;
608
        my $budget_code      = $infos->{budget_code};
571
        my $sort1            = $infos->{sort1} || undef;
609
        my $discount         = $infos->{discount};
572
        my $sort2            = $infos->{sort2} || undef;
610
        my $sort1            = $infos->{sort1};
611
        my $sort2            = $infos->{sort2};
612
        my $budget_id;
573
        my $budget_id;
613
574
614
        if ($budget_code) {
575
        if ($budget_code) {
Lines 621-627 sub import_biblios_list { Link Here
621
        # Items
582
        # Items
622
        my @itemlist           = ();
583
        my @itemlist           = ();
623
        my $all_items_quantity = 0;
584
        my $all_items_quantity = 0;
624
        my $alliteminfos       = _get_MarcItemFieldsToOrder_syspref_data($marcrecord);
585
        my $alliteminfos = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' );
586
625
        if ( $alliteminfos != -1 ) {
587
        if ( $alliteminfos != -1 ) {
626
            foreach my $iteminfos (@$alliteminfos) {
588
            foreach my $iteminfos (@$alliteminfos) {
627
                # Quantity is required, default to one if not supplied
589
                # Quantity is required, default to one if not supplied
628
- 

Return to bug 35026