- # check for item barcode # being unique
- my $exists = GetItemnumberFromBarcode($record->subfield($barcodetagfield,$barcodetagsubfield)) if ($record->subfield($barcodetagfield,$barcodetagsubfield));
- # push @errors,"barcode_not_unique" if($exists);
- # if barcode exists, don't create, but report The problem.
- if ($exists){
- push @errors,"barcode_not_unique" if($exists);
- push @errseq,{"serialseq"=>$serialseqs[$index]};
- } else {
- my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$itemhash{$item}->{'bibnum'});
- AddItem2Serial($itemhash{$item}->{'serial'},$itemnumber);
+ if ( $index >= 0 && $status[$index] == 2 ) {
+ my $xml = TransformHtmlToXml(
+ $itemhash{$item}->{'tags'},
+ $itemhash{$item}->{'subfields'},
+ $itemhash{$item}->{'field_values'},
+ $itemhash{$item}->{'indicator'},
+ $itemhash{$item}->{'ind_tag'}
+ );
+
+ # warn $xml;
+ my $bib_record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
+ if ( $item =~ /^N/ ) {
+
+ #New Item
+
+ # if autoBarcode is set to 'incremental', calculate barcode...
+ my ( $barcodetagfield, $barcodetagsubfield ) =
+ GetMarcFromKohaField(
+ 'items.barcode',
+ GetFrameworkCode(
+ $serialdatalist[0]->{'biblionumber'}
+ )
+ );
+ if ( C4::Context->preference("autoBarcode") eq
+ 'incremental' )
+ {
+ if ( !$bib_record->field($barcodetagfield)
+ ->subfield($barcodetagsubfield) )
+ {
+ my $sth_barcode = $dbh->prepare(
+ "select max(abs(barcode)) from items");
+ $sth_barcode->execute;
+ my ($newbarcode) = $sth_barcode->fetchrow;
+
+# OK, we have the new barcode, add the entry in MARC record # FIXME -> should be using barcode plugin here.
+ $bib_record->field($barcodetagfield)
+ ->update( $barcodetagsubfield => ++$newbarcode );
+ }
+ }
+
+ # check for item barcode # being unique
+ my $exists;
+ if (
+ $bib_record->subfield(
+ $barcodetagfield, $barcodetagsubfield
+ )
+ )
+ {
+ $exists = GetItemnumberFromBarcode(
+ $bib_record->subfield(
+ $barcodetagfield, $barcodetagsubfield
+ )
+ );
+ }
+
+ # push @errors,"barcode_not_unique" if($exists);
+ # if barcode exists, don't create, but report The problem.
+ if ($exists) {
+ push @errors, 'barcode_not_unique';
+ push @errseq, { serialseq => $serialseqs[$index] };
+ }
+ else {
+ my ( $biblionumber, $bibitemnum, $itemnumber ) =
+ AddItemFromMarc( $bib_record,
+ $itemhash{$item}->{bibnum} );
+ AddItem2Serial( $itemhash{$item}->{serial},
+ $itemnumber );
+ }
+ }
+ else {
+
+ #modify item
+ my ( $oldbiblionumber, $oldbibnum, $itemnumber ) =
+ ModItemFromMarc( $bib_record,
+ $itemhash{$item}->{'bibnum'}, $item );
+ }