Lines 38-43
use C4::ImportBatch qw(
Link Here
|
38 |
GetImportBatchNoMatchAction |
38 |
GetImportBatchNoMatchAction |
39 |
GetImportBatchItemAction |
39 |
GetImportBatchItemAction |
40 |
GetImportBatch |
40 |
GetImportBatch |
|
|
41 |
GetImportBatchRangeDesc |
42 |
GetNumberOfNonZ3950ImportBatches |
41 |
); |
43 |
); |
42 |
use C4::Search qw( FindDuplicate ); |
44 |
use C4::Search qw( FindDuplicate ); |
43 |
use C4::Acquisition qw( NewBasket ); |
45 |
use C4::Acquisition qw( NewBasket ); |
Lines 168-186
sub _get_MarcFieldsToOrder_syspref_data {
Link Here
|
168 |
|
170 |
|
169 |
sub _get_MarcItemFieldsToOrder_syspref_data { |
171 |
sub _get_MarcItemFieldsToOrder_syspref_data { |
170 |
my ($record) = @_; |
172 |
my ($record) = @_; |
171 |
my $syspref = C4::Context->preference('MarcItemFieldsToOrder'); |
173 |
my $syspref = C4::Context->yaml_preference('MarcItemFieldsToOrder'); |
172 |
$syspref = "$syspref\n\n"; |
|
|
173 |
my $yaml = eval { YAML::XS::Load( Encode::encode_utf8($syspref) ); }; |
174 |
if ($@) { |
175 |
warn "Unable to parse $syspref syspref : $@"; |
176 |
return (); |
177 |
} |
178 |
my @result; |
174 |
my @result; |
179 |
my @tags_list; |
175 |
my @tags_list; |
180 |
|
176 |
|
181 |
# Check tags in syspref definition |
177 |
# Check tags in syspref definition |
182 |
for my $field_name ( keys %$yaml ) { |
178 |
for my $field_name ( keys %$syspref ) { |
183 |
my @fields = split /\|/, $yaml->{$field_name}; |
179 |
my @fields = split /\|/, $syspref->{$field_name}; |
184 |
for my $field (@fields) { |
180 |
for my $field (@fields) { |
185 |
my ( $f, $sf ) = split /\$/, $field; |
181 |
my ( $f, $sf ) = split /\$/, $field; |
186 |
next unless $f and $sf; |
182 |
next unless $f and $sf; |
Lines 207-227
sub _get_MarcItemFieldsToOrder_syspref_data {
Link Here
|
207 |
if ( $tags_count->{count} ) { |
203 |
if ( $tags_count->{count} ) { |
208 |
for ( my $i = 0 ; $i < $tags_count->{count} ; $i++ ) { |
204 |
for ( my $i = 0 ; $i < $tags_count->{count} ; $i++ ) { |
209 |
my $r; |
205 |
my $r; |
210 |
for my $field_name ( keys %$yaml ) { |
206 |
for my $field_name ( keys %$syspref ) { |
211 |
my @fields = split /\|/, $yaml->{$field_name}; |
207 |
my @fields = split /\|/, $syspref->{$field_name}; |
212 |
for my $field (@fields) { |
208 |
for my $field (@fields) { |
213 |
my ( $f, $sf ) = split /\$/, $field; |
209 |
my ( $f, $sf ) = split /\$/, $field; |
214 |
next unless $f and $sf; |
210 |
next unless $f and $sf; |
215 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield($sf) : undef; |
211 |
my $v = $fields_hash->{$f}[$i] ? $fields_hash->{$f}[$i]->subfield($sf) : undef; |
216 |
$r->{$field_name} = $v if ( defined $v ); |
212 |
$r->{$field_name} = $v if ( defined $v ); |
217 |
last if $yaml->{$field}; |
213 |
last if $syspref->{$field}; |
218 |
} |
214 |
} |
219 |
} |
215 |
} |
220 |
push @result, $r; |
216 |
push @result, $r; |
221 |
} |
217 |
} |
222 |
} |
218 |
} |
223 |
|
219 |
|
224 |
return $result[0]; |
220 |
return \@result; |
225 |
} |
221 |
} |
226 |
|
222 |
|
227 |
=head3 _verify_number_of_fields |
223 |
=head3 _verify_number_of_fields |
Lines 526-532
sub import_batches_list {
Link Here
|
526 |
}; |
522 |
}; |
527 |
} |
523 |
} |
528 |
|
524 |
|
529 |
=head3 |
525 |
=head3 import_biblios_list |
530 |
|
526 |
|
531 |
For an import batch, this function reads the files and creates all the relevant data pertaining to that file |
527 |
For an import batch, this function reads the files and creates all the relevant data pertaining to that file |
532 |
It then returns this to the template to be shown in the UI |
528 |
It then returns this to the template to be shown in the UI |
Lines 626-657
sub import_biblios_list {
Link Here
|
626 |
my @itemlist = (); |
622 |
my @itemlist = (); |
627 |
my $all_items_quantity = 0; |
623 |
my $all_items_quantity = 0; |
628 |
my $alliteminfos = _get_MarcItemFieldsToOrder_syspref_data($marcrecord); |
624 |
my $alliteminfos = _get_MarcItemFieldsToOrder_syspref_data($marcrecord); |
629 |
if ( !$alliteminfos || %$alliteminfos != -1 ) { |
625 |
if ( $alliteminfos != -1 ) { |
630 |
|
626 |
foreach my $iteminfos (@$alliteminfos) { |
631 |
# Quantity is required, default to one if not supplied |
627 |
# Quantity is required, default to one if not supplied |
632 |
my $quantity = delete $alliteminfos->{quantity} || 1; |
628 |
my $quantity = delete $iteminfos->{quantity} || 1; |
633 |
|
629 |
|
634 |
# Handle incorrectly named original parameters for MarcItemFieldsToOrder |
630 |
# Handle incorrectly named original parameters for MarcItemFieldsToOrder |
635 |
$alliteminfos->{location} = delete $alliteminfos->{loc} if $alliteminfos->{loc}; |
631 |
$iteminfos->{location} = delete $iteminfos->{loc} if $iteminfos->{loc}; |
636 |
$alliteminfos->{copynumber} = delete $alliteminfos->{copyno} if $alliteminfos->{copyno}; |
632 |
$iteminfos->{copynumber} = delete $iteminfos->{copyno} if $iteminfos->{copyno}; |
637 |
|
633 |
|
638 |
# Convert budget code to a budget id |
634 |
# Convert budget code to a budget id |
639 |
my $item_budget_code = delete $alliteminfos->{budget_code}; |
635 |
my $item_budget_code = delete $iteminfos->{budget_code}; |
640 |
if ($item_budget_code) { |
636 |
if ($item_budget_code) { |
641 |
my $item_budget = GetBudgetByCode($item_budget_code); |
637 |
my $item_budget = GetBudgetByCode($item_budget_code); |
642 |
$alliteminfos->{budget_id} = $item_budget->{budget_id} || $budget_id; |
638 |
$iteminfos->{budget_id} = $item_budget->{budget_id} || $budget_id; |
643 |
} |
639 |
} |
644 |
|
640 |
|
645 |
# Clone the item data for the needed quantity |
641 |
# Clone the item data for the needed quantity |
646 |
# Add the incremented item id for each item in that quantity |
642 |
# Add the incremented item id for each item in that quantity |
647 |
for ( my $i = 0 ; $i < $quantity ; $i++ ) { |
643 |
for ( my $i = 0 ; $i < $quantity ; $i++ ) { |
648 |
my $itemrecord = {%$alliteminfos}; |
644 |
my $itemrecord = {%$iteminfos}; |
649 |
$itemrecord->{item_id} = $item_id++; |
645 |
$itemrecord->{item_id} = $item_id++; |
650 |
|
646 |
|
651 |
# Rename price field to match UI |
647 |
# Rename price field to match UI |
652 |
$itemrecord->{itemprice} = delete $itemrecord->{price} if $itemrecord->{price}; |
648 |
$itemrecord->{itemprice} = delete $itemrecord->{price} if $itemrecord->{price}; |
653 |
$all_items_quantity++; |
649 |
$all_items_quantity++; |
654 |
push @itemlist, $itemrecord; |
650 |
push @itemlist, $itemrecord; |
|
|
651 |
} |
655 |
} |
652 |
} |
656 |
|
653 |
|
657 |
$cellrecord{'iteminfos'} = \@itemlist; |
654 |
$cellrecord{'iteminfos'} = \@itemlist; |
658 |
- |
|
|