- foreach my $bc (@barcode) {
- my $item_hash = {
- "items.replacementprice" => $replacement,
- "items.price" => $cost,
- "items.booksellerid" => $supplierid,
- "items.homebranch" => $branch[$cnt],
- "items.holdingbranch" => $branch[$cnt],
- "items.barcode" => $barcode[$cnt],
- "items.ccode" => $ccode[$cnt],
- "items.itype" => $itemtype[$cnt],
- "items.location" => $location[$cnt],
- "items.enumchron" => $enumchron[$cnt], # FIXME : No integration here with serials module.
- "items.loan" => 0,
- };
- $item_hash->{'items.cn_source'} = C4::Context->preference('DefaultClassificationSource') if(C4::Context->preference('DefaultClassificationSource') );
- # FIXME : cn_sort is populated by Items::_set_derived_columns_for_add , which is never called with AddItemFromMarc . Bug 2403
- my $itemRecord = TransformKohaToMarc($item_hash);
- $cnt++;
- $item_hash = TransformMarcToKoha(undef,$itemRecord,'','items');
- # FIXME: possible race condition. duplicate barcode check should happen in AddItem, but for now we have to do it here.
- my %err = CheckItemPreSave($item_hash);
- if(%err) {
- for my $err_cnd (keys %err) {
- $error_url_str .= "&error=" . $err_cnd . "&error_param=" . $err{$err_cnd};
- }
- $quantityrec--;
- } else {
- AddItemFromMarc($itemRecord,$biblionumber);
- }
- }
-
+ # now, add items if applicable
+ if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
+
+ my @tags = $input->param('tag');
+ my @subfields = $input->param('subfield');
+ my @field_values = $input->param('field_value');
+ my @serials = $input->param('serial');
+ my @itemid = $input->param('itemid');
+ my @ind_tag = $input->param('ind_tag');
+ my @indicator = $input->param('indicator');
+ #Rebuilding ALL the data for items into a hash
+ # parting them on $itemid.
+ my %itemhash;
+ my $countdistinct;
+ my $range=scalar(@itemid);
+ for (my $i=0; $i<$range; $i++){
+ unless ($itemhash{$itemid[$i]}){
+ $countdistinct++;
+ }
+ push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i];
+ push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i];
+ push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i];
+ push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i];
+ push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i];
+ }
+ foreach my $item (keys %itemhash){
+ my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'},
+ $itemhash{$item}->{'subfields'},
+ $itemhash{$item}->{'field_values'},
+ $itemhash{$item}->{'ind_tag'},
+ $itemhash{$item}->{'indicator'},'ITEM');
+ my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
+ my (undef,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber);
+ NewOrderItem($itemnumber, $ordernumber);
+ }
+ }
+