| 354 | | my $record = $U->simplereq( |
| 355 | | 'open-ils.cat', |
| 356 | | 'open-ils.cat.biblio.record.xml.import', |
| 357 | | $auth, $li->marc, $li->source_label); |
| 358 | | |
| 359 | | return $record and $e->rollback if $U->event_code($record); |
| 360 | | $logger->info("acq created new lineitem bib record ".$record->id); |
| 361 | | |
| 362 | | return $record->id unless $$options{volumes}; |
| 363 | | |
| 364 | | for my $vol (@{$$options{volumes}}) { |
| 365 | | my $volume = Fieldmapper::asset::call_number->new; |
| 366 | | $volume->isnew(1); |
| 367 | | $volume->record($record->id); |
| 368 | | $volume->$_($vol->{$_}) for keys %$vol; |
| 369 | | $volume->copies([]); |
| 370 | | |
| 371 | | if($vol->{copies}) { |
| 372 | | for my $cp (@{$vol->{copies}}) { |
| 373 | | my $copy = Fieldmapper::asset::copy->new; |
| 374 | | $copy->isnew(1); |
| 375 | | $copy->$_($cp->{$_}) for keys %$cp; |
| 376 | | $copy->loan_duration(2) unless $copy->loan_duration; |
| 377 | | $copy->fine_level(2) unless $copy->fine_level; |
| 378 | | $copy->status(OILS_COPY_STATUS_ON_ORDER) unless $copy->status; |
| 379 | | push(@{$volume->copies}, $copy); |
| 380 | | } |
| 381 | | } |
| | 353 | # ----------------------------------------------------------------- |
| | 354 | # first, create the bib record if necessary |
| | 355 | # ----------------------------------------------------------------- |
| | 356 | unless($li->eg_bib_id) { |
| | 357 | my $record = $U->simplereq( |
| | 358 | 'open-ils.cat', |
| | 359 | 'open-ils.cat.biblio.record.xml.import', |
| | 360 | $auth, $li->marc, $li->source_label); |
| | 361 | |
| | 362 | if($U->event_code($record)) { |
| | 363 | $e->rollback; |
| | 364 | return $record; |
| | 365 | } |
| | 366 | |
| | 367 | $li->eg_bib_id($record->id); |
| | 368 | $e->update_acq_lineitem($li) or return $e->die_event; |
| | 369 | } |
| | 370 | |
| | 371 | my $li_details = $e->search_acq_lineitem_detail({lineitem => $li_id}, {idlist=>1}); |
| | 372 | |
| | 373 | # ----------------------------------------------------------------- |
| | 374 | # for each lineitem_detail, create the volume if necessary, create |
| | 375 | # a copy, and link them all together. |
| | 376 | # ----------------------------------------------------------------- |
| | 377 | my %volcache; |
| | 378 | for my $li_detail_id (@{$li_details}) { |
| | 379 | |
| | 380 | my $li_detail = $e->retrieve_acq_lineitem_detail($li_detail_id) |
| | 381 | or return $e->die_event; |
| | 382 | |
| | 383 | my $volume = $volcache{$li_detail->cn_label}; |
| | 384 | unless($volume and $volume->owning_lib == $li_detail->owning_lib) { |
| | 385 | $volume = $U->simplereq( |
| | 386 | 'open-ils.cat', |
| | 387 | 'open-ils.cat.call_number.find_or_create', |
| | 388 | $auth, $li_detail->cn_label, $li->eg_bib_id, $li_detail->owning_lib); |
| | 389 | } |
| | 390 | |
| | 391 | if($U->event_code($volume)) { |
| | 392 | $e->rollback; |
| | 393 | return $volume; |
| | 394 | } |
| | 395 | |
| | 396 | my $copy = Fieldmapper::asset::copy->new; |
| | 397 | $copy->isnew(1); |
| | 398 | $copy->loan_duration(2); |
| | 399 | $copy->fine_level(2); |
| | 400 | $copy->status(OILS_COPY_STATUS_ON_ORDER); |
| | 401 | $copy->barcode($li_detail->barcode); |
| | 402 | $copy->location($li_detail->location); |
| 385 | | 'open-ils.cat.asset.volume.fleshed.batch.update', $auth, [$volume]); |
| 386 | | return $stat and $e->rollback if $U->event_code($stat); |
| 387 | | $logger->info("acq created new lineitem volume ".$volume->label); |
| 388 | | } |
| 389 | | |
| 390 | | $li->eg_bib_id($record->id); |
| 391 | | $e->update_acq_lineitem($li) or return $e->die_event; |
| | 406 | 'open-ils.cat.asset.copy.fleshed.batch.update', $auth, [$copy]); |
| | 407 | |
| | 408 | if($U->event_code($stat)) { |
| | 409 | $e->rollback; |
| | 410 | return $stat; |
| | 411 | } |
| | 412 | |
| | 413 | my $new_copy = $e->retrieve_asset_copy({deleted=>'f', barcode=>$copy->barcode}) |
| | 414 | or return $e->die_event; |
| | 415 | |
| | 416 | $li_detail->eg_copy_id($new_copy->id); |
| | 417 | $e->update_acq_lineitem_detail($li_detail) |
| | 418 | or return $e->die_event; |
| | 419 | } |
| | 420 | |