|
Lines 99-105
sub create_order_lines_from_file {
Link Here
|
| 99 |
my $basket_id = _create_basket_for_file( |
99 |
my $basket_id = _create_basket_for_file( |
| 100 |
{ |
100 |
{ |
| 101 |
filename => $filename, |
101 |
filename => $filename, |
| 102 |
vendor_id => $vendor_id |
102 |
filepath => $filepath, |
|
|
103 |
vendor_id => $vendor_id, |
| 104 |
profile => $profile |
| 103 |
} |
105 |
} |
| 104 |
); |
106 |
); |
| 105 |
|
107 |
|
|
Lines 223-229
sub import_record_and_create_order_lines {
Link Here
|
| 223 |
|
225 |
|
| 224 |
my $basket_id = _create_basket_for_file({ |
226 |
my $basket_id = _create_basket_for_file({ |
| 225 |
filename => $filename, |
227 |
filename => $filename, |
| 226 |
vendor_id => $vendor_id |
228 |
vendor_id => $vendor_id, |
|
|
229 |
profile => $profile |
| 227 |
}); |
230 |
}); |
| 228 |
|
231 |
|
| 229 |
Creates a basket ready to receive order lines based on the imported file |
232 |
Creates a basket ready to receive order lines based on the imported file |
|
Lines 236-243
sub _create_basket_for_file {
Link Here
|
| 236 |
my $filename = $args->{filename}; |
239 |
my $filename = $args->{filename}; |
| 237 |
my $vendor_id = $args->{vendor_id}; |
240 |
my $vendor_id = $args->{vendor_id}; |
| 238 |
|
241 |
|
|
|
242 |
my $basket_name = _check_file_for_basket_name($args); |
| 243 |
|
| 239 |
# aqbasketname.basketname has a max length of 50 characters so long file names will need to be truncated |
244 |
# 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; |
245 |
my $basketname = length($basket_name) > 50 ? substr( $basket_name, 0, 50 ) : $basket_name; |
| 241 |
|
246 |
|
| 242 |
my $basketno = NewBasket( |
247 |
my $basketno = NewBasket( |
| 243 |
$vendor_id, 0, $basketname, q{}, |
248 |
$vendor_id, 0, $basketname, q{}, |
|
Lines 543-565
sub add_items_from_import_record {
Link Here
|
| 543 |
sub match_file_to_account { |
548 |
sub match_file_to_account { |
| 544 |
my ( $self, $args ) = @_; |
549 |
my ( $self, $args ) = @_; |
| 545 |
|
550 |
|
| 546 |
my $match = 0; |
551 |
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 |
|
552 |
|
| 552 |
my ( $errors, $marcrecords ); |
553 |
my $match = 0; |
| 553 |
if ( $format eq 'MARCXML' ) { |
554 |
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 |
|
555 |
|
| 562 |
my $match_record = @{$marcrecords}[0]; |
|
|
| 563 |
my ( $field, $subfield ) = split /\$/, $profile->match_field; |
556 |
my ( $field, $subfield ) = split /\$/, $profile->match_field; |
| 564 |
|
557 |
|
| 565 |
my $field_value = $match_record->subfield( $field, $subfield ) || ''; |
558 |
my $field_value = $match_record->subfield( $field, $subfield ) || ''; |
|
Lines 572-577
sub match_file_to_account {
Link Here
|
| 572 |
return $match; |
565 |
return $match; |
| 573 |
} |
566 |
} |
| 574 |
|
567 |
|
|
|
568 |
=head3 _check_file_for_basket_name |
| 569 |
|
| 570 |
my $basket_name = _check_file_for_basket_name({ |
| 571 |
filename => $filename, |
| 572 |
filepath => $filepath, |
| 573 |
profile => $profile |
| 574 |
}); |
| 575 |
|
| 576 |
Checks to see if the account has a basket name field assigned. |
| 577 |
If yes, it retrieves this value to use as the name. |
| 578 |
If not, to uses the filename. |
| 579 |
|
| 580 |
=cut |
| 581 |
|
| 582 |
sub _check_file_for_basket_name { |
| 583 |
my ($args) = @_; |
| 584 |
|
| 585 |
my $profile = $args->{profile}; |
| 586 |
|
| 587 |
my $filename = $args->{filename}; |
| 588 |
return $filename if !$profile->basket_name_field; |
| 589 |
|
| 590 |
my $first_record = _retrieve_first_record_from_batch($args); |
| 591 |
|
| 592 |
my ( $field, $subfield ) = split /\$/, $profile->basket_name_field; |
| 593 |
|
| 594 |
my $field_value = $first_record->subfield( $field, $subfield ) || ''; |
| 595 |
|
| 596 |
return $field_value ? $field_value : $filename; |
| 597 |
} |
| 598 |
|
| 575 |
=head3 import_batches_list |
599 |
=head3 import_batches_list |
| 576 |
|
600 |
|
| 577 |
Fetches import batches matching the batch to be added to the basket and returns these to the template |
601 |
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; |
1275 |
return $item_fields; |
| 1252 |
} |
1276 |
} |
| 1253 |
|
1277 |
|
|
|
1278 |
=head3 _retrieve_first_record_from_batch |
| 1279 |
|
| 1280 |
=cut |
| 1281 |
|
| 1282 |
sub _retrieve_first_record_from_batch { |
| 1283 |
my ($args) = @_; |
| 1284 |
|
| 1285 |
my $filename = $args->{filename}; |
| 1286 |
my $filepath = $args->{filepath}; |
| 1287 |
my $profile = $args->{profile}; |
| 1288 |
my $format = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML'; |
| 1289 |
|
| 1290 |
my ( $errors, $marcrecords ); |
| 1291 |
if ( $format eq 'MARCXML' ) { |
| 1292 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); |
| 1293 |
} elsif ( $format eq 'ISO2709' ) { |
| 1294 |
( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( |
| 1295 |
$filepath, $profile->record_type, |
| 1296 |
$profile->encoding |
| 1297 |
); |
| 1298 |
} |
| 1299 |
|
| 1300 |
my $first_record = @{$marcrecords}[0]; |
| 1301 |
return $first_record; |
| 1302 |
|
| 1303 |
} |
| 1304 |
|
| 1254 |
1; |
1305 |
1; |