Lines 236-243
sub _create_basket_for_file {
Link Here
|
236 |
my $filename = $args->{filename}; |
236 |
my $filename = $args->{filename}; |
237 |
my $vendor_id = $args->{vendor_id}; |
237 |
my $vendor_id = $args->{vendor_id}; |
238 |
|
238 |
|
|
|
239 |
my $basket_name = _check_file_for_basket_name($args); |
240 |
|
239 |
# aqbasketname.basketname has a max length of 50 characters so long file names will need to be truncated |
241 |
# aqbasketname.basketname has a max length of 50 characters so long file names will need to be truncated |
240 |
my $basketname = length($filename) > 50 ? substr( $filename, 0, 50 ) : $filename; |
242 |
my $basketname = length($basket_name) > 50 ? substr( $basket_name, 0, 50 ) : $basket_name; |
241 |
|
243 |
|
242 |
my $basketno = NewBasket( |
244 |
my $basketno = NewBasket( |
243 |
$vendor_id, 0, $basketname, q{}, |
245 |
$vendor_id, 0, $basketname, q{}, |
Lines 543-565
sub add_items_from_import_record {
Link Here
|
543 |
sub match_file_to_account { |
545 |
sub match_file_to_account { |
544 |
my ( $self, $args ) = @_; |
546 |
my ( $self, $args ) = @_; |
545 |
|
547 |
|
546 |
my $match = 0; |
548 |
my $profile = $args->{profile}; |
547 |
my $filename = $args->{filename}; |
|
|
548 |
my $filepath = $args->{filepath}; |
549 |
my $profile = $args->{profile}; |
550 |
my $format = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML'; |
551 |
|
549 |
|
552 |
my ( $errors, $marcrecords ); |
550 |
my $match = 0; |
553 |
if ( $format eq 'MARCXML' ) { |
551 |
my $match_record = _retrieve_first_record_from_batch($args); |
554 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); |
|
|
555 |
} elsif ( $format eq 'ISO2709' ) { |
556 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( |
557 |
$filepath, $profile->record_type, |
558 |
$profile->encoding |
559 |
); |
560 |
} |
561 |
|
552 |
|
562 |
my $match_record = @{$marcrecords}[0]; |
|
|
563 |
my ( $field, $subfield ) = split /\$/, $profile->match_field; |
553 |
my ( $field, $subfield ) = split /\$/, $profile->match_field; |
564 |
|
554 |
|
565 |
my $field_value = $match_record->subfield( $field, $subfield ) || ''; |
555 |
my $field_value = $match_record->subfield( $field, $subfield ) || ''; |
Lines 572-577
sub match_file_to_account {
Link Here
|
572 |
return $match; |
562 |
return $match; |
573 |
} |
563 |
} |
574 |
|
564 |
|
|
|
565 |
=head3 _check_file_for_basket_name |
566 |
|
567 |
my $basket_name = _check_file_for_basket_name({ |
568 |
filename => $filename, |
569 |
filepath => $filepath, |
570 |
profile => $profile |
571 |
}); |
572 |
|
573 |
Checks to see if the account has a basket name field assigned. |
574 |
If yes, it retrieves this value to use as the name. |
575 |
If not, to uses the filename. |
576 |
|
577 |
=cut |
578 |
|
579 |
sub _check_file_for_basket_name { |
580 |
my ( $self, $args ) = @_; |
581 |
|
582 |
my $profile = $args->{profile}; |
583 |
my $filename = $args->{filename}; |
584 |
return $filename if !$profile->basket_name_field; |
585 |
|
586 |
my $first_record = _retrieve_first_record_from_batch($args); |
587 |
|
588 |
my ( $field, $subfield ) = split /\$/, $profile->basket_name_field; |
589 |
|
590 |
my $field_value = $first_record->subfield( $field, $subfield ) || ''; |
591 |
|
592 |
return $field_value ? $field_value : $filename; |
593 |
} |
594 |
|
575 |
=head3 import_batches_list |
595 |
=head3 import_batches_list |
576 |
|
596 |
|
577 |
Fetches import batches matching the batch to be added to the basket and returns these to the template |
597 |
Fetches import batches matching the batch to be added to the basket and returns these to the template |
Lines 1251-1254
sub _create_item_fields_from_syspref {
Link Here
|
1251 |
return $item_fields; |
1271 |
return $item_fields; |
1252 |
} |
1272 |
} |
1253 |
|
1273 |
|
|
|
1274 |
=head3 _retrieve_first_record_from_batch |
1275 |
|
1276 |
=cut |
1277 |
|
1278 |
sub _retrieve_first_record_from_batch { |
1279 |
my ($args) = @_; |
1280 |
|
1281 |
my $filename = $args->{filename}; |
1282 |
my $filepath = $args->{filepath}; |
1283 |
my $profile = $args->{profile}; |
1284 |
my $format = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML'; |
1285 |
|
1286 |
my ( $errors, $marcrecords ); |
1287 |
if ( $format eq 'MARCXML' ) { |
1288 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); |
1289 |
} elsif ( $format eq 'ISO2709' ) { |
1290 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( |
1291 |
$filepath, $profile->record_type, |
1292 |
$profile->encoding |
1293 |
); |
1294 |
} |
1295 |
|
1296 |
my $first_record = @{$marcrecords}[0]; |
1297 |
return $first_record; |
1298 |
|
1299 |
} |
1300 |
|
1254 |
1; |
1301 |
1; |