| Lines 3-11
          
      
      
        Link Here | 
        
          | 3 | #A script that lets the user populate a basket from an iso2709 file | 3 | #A script that lets the user populate a basket from an iso2709 file | 
        
          | 4 | #the script first displays a list of import batches, then when a batch is selected displays all the biblios in it. | 4 | #the script first displays a list of import batches, then when a batch is selected displays all the biblios in it. | 
        
          | 5 | #The user can then pick which biblios he wants to order | 5 | #The user can then pick which biblios he wants to order | 
            
              | 6 | #written by john.soros@biblibre.com 01/12/2008 |  |  | 
        
          | 7 |  | 6 |  | 
          
            
              | 8 | # Copyright 2008 - 2009 BibLibre SARL | 7 | # Copyright 2008 - 2011 BibLibre SARL | 
        
          | 9 | # | 8 | # | 
        
          | 10 | # This file is part of Koha. | 9 | # This file is part of Koha. | 
        
          | 11 | # | 10 | # | 
  
    | Lines 25-44
          
      
      
        Link Here | 
        
          | 25 | use strict; | 24 | use strict; | 
        
          | 26 | use warnings; | 25 | use warnings; | 
        
          | 27 | use CGI; | 26 | use CGI; | 
            
              |  |  | 27 | use Number::Format qw(:all); | 
            
              | 28 |  | 
        
          | 28 | use C4::Context; | 29 | use C4::Context; | 
        
          | 29 | use C4::Auth; | 30 | use C4::Auth; | 
        
          | 30 | use C4::Input; | 31 | use C4::Input; | 
        
          | 31 | use C4::Output; | 32 | use C4::Output; | 
          
            
              | 32 | use C4::ImportBatch qw/GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportRecordMatches GetImportBibliosRange GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction GetImportRecordMarc GetImportBatch/; | 33 | use C4::ImportBatch; | 
        
          | 33 | use C4::Matcher; | 34 | use C4::Matcher; | 
        
          | 34 | use C4::Search qw/FindDuplicate BiblioAddAuthorities/; | 35 | use C4::Search qw/FindDuplicate BiblioAddAuthorities/; | 
          
            
              | 35 | use C4::Acquisition qw/NewOrder/; | 36 | use C4::Acquisition; | 
        
          | 36 | use C4::Biblio; | 37 | use C4::Biblio; | 
        
          | 37 | use C4::Items; | 38 | use C4::Items; | 
          
            
              | 38 | use C4::Koha qw/GetItemTypes/; | 39 | use C4::Koha; | 
            
              | 39 | use C4::Budgets qw/GetBudgets/; | 40 | use C4::Budgets; | 
            
              | 40 | use C4::Acquisition qw/NewOrderItem GetBasket/; | 41 | use C4::Acquisition; | 
        
          | 41 | use C4::Bookseller qw/GetBookSellerFromId/; | 42 | use C4::Bookseller qw/GetBookSellerFromId/; | 
            
              |  |  | 43 | use C4::Dates; | 
            
              | 44 | use C4::Suggestions;    # GetSuggestion | 
            
              | 45 | use C4::Branch;         # GetBranches | 
            
              | 46 | use C4::Members; | 
        
          | 42 |  | 47 |  | 
        
          | 43 | my $input = new CGI; | 48 | my $input = new CGI; | 
        
          | 44 | my ($template, $loggedinuser, $cookie) = get_template_and_user({ | 49 | my ($template, $loggedinuser, $cookie) = get_template_and_user({ | 
  
    | Lines 53-58
          my $cgiparams = $input->Vars;
      
      
        Link Here | 
        
          | 53 | my $op = $cgiparams->{'op'}; | 58 | my $op = $cgiparams->{'op'}; | 
        
          | 54 | my $booksellerid  = $input->param('booksellerid'); | 59 | my $booksellerid  = $input->param('booksellerid'); | 
        
          | 55 | my $bookseller = GetBookSellerFromId($booksellerid); | 60 | my $bookseller = GetBookSellerFromId($booksellerid); | 
            
              |  |  | 61 | my $data; | 
        
          | 56 |  | 62 |  | 
        
          | 57 | $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", | 63 | $template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl", | 
        
          | 58 |                 booksellerid => $booksellerid, | 64 |                 booksellerid => $booksellerid, | 
  
    | Lines 69-85
          if (! $cgiparams->{'basketno'}){
      
      
        Link Here | 
        
          | 69 |     die "Basketnumber required to order from iso2709 file import"; | 75 |     die "Basketnumber required to order from iso2709 file import"; | 
        
          | 70 | } | 76 | } | 
        
          | 71 |  | 77 |  | 
            
              |  |  | 78 | # | 
            
              | 79 | # 1st step = choose the file to import into acquisition | 
            
              | 80 | # | 
        
          | 72 | if ($op eq ""){ | 81 | if ($op eq ""){ | 
        
          | 73 |     $template->param("basketno" => $cgiparams->{'basketno'}); | 82 |     $template->param("basketno" => $cgiparams->{'basketno'}); | 
        
          | 74 | #display batches | 83 | #display batches | 
        
          | 75 |     import_batches_list($template); | 84 |     import_batches_list($template); | 
            
              |  |  | 85 | # | 
            
              | 86 | # 2nd step = display the content of the choosen file | 
            
              | 87 | # | 
        
          | 76 | } elsif ($op eq "batch_details"){ | 88 | } elsif ($op eq "batch_details"){ | 
        
          | 77 | #display lines inside the selected batch | 89 | #display lines inside the selected batch | 
            
              |  |  | 90 |     # get currencies (for change rates calcs if needed) | 
            
              | 91 |     my $active_currency = GetCurrency(); | 
            
              | 92 |     my $default_currency; | 
            
              | 93 |     if (! $data->{currency} ) { # New order no currency set | 
            
              | 94 |         if ( $bookseller->{listprice} ) { | 
            
              | 95 |             $default_currency = $bookseller->{listprice}; | 
            
              | 96 |         } | 
            
              | 97 |         else { | 
            
              | 98 |             $default_currency = $active_currency->{currency}; | 
            
              | 99 |         } | 
            
              | 100 |     } | 
            
              | 101 |     my @rates = GetCurrencies(); | 
            
              | 102 |  | 
            
              | 103 |     # ## @rates | 
            
              | 104 |  | 
            
              | 105 |     my @loop_currency = (); | 
            
              | 106 |     for my $curr ( @rates ) { | 
            
              | 107 |         my $selected; | 
            
              | 108 |         if ($data->{currency} ) { | 
            
              | 109 |             $selected = $curr->{currency} eq $data->{currency}; | 
            
              | 110 |         } | 
            
              | 111 |         else { | 
            
              | 112 |             $selected = $curr->{currency} eq $default_currency; | 
            
              | 113 |         } | 
            
              | 114 |         push @loop_currency, { | 
            
              | 115 |             currcode => $curr->{currency}, | 
            
              | 116 |             rate     => $curr->{rate}, | 
            
              | 117 |             selected => $selected, | 
            
              | 118 |         } | 
            
              | 119 |     } | 
            
              | 120 |  | 
        
          | 78 |     $template->param("batch_details" => 1, | 121 |     $template->param("batch_details" => 1, | 
          
            
              | 79 |                      "basketno"      => $cgiparams->{'basketno'}); | 122 |                      "basketno"      => $cgiparams->{'basketno'}, | 
            
              |  |  | 123 |                      loop_currencies  => \@loop_currency, | 
            
              | 124 |                      ); | 
        
          | 80 |     import_biblios_list($template, $cgiparams->{'import_batch_id'}); | 125 |     import_biblios_list($template, $cgiparams->{'import_batch_id'}); | 
          
            
              | 81 |      | 126 |     if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber ) { | 
            
              | 82 | } elsif ($op eq 'import_records'){ | 127 |         # prepare empty item form | 
            
              |  |  | 128 |         my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' ); | 
            
              | 129 |  | 
            
              | 130 |         #     warn "==> ".Data::Dumper::Dumper($cell); | 
            
              | 131 |         unless ($cell) { | 
            
              | 132 |             $cell = PrepareItemrecordDisplay( '', '', '', '' ); | 
            
              | 133 |             $template->param( 'NoACQframework' => 1 ); | 
            
              | 134 |         } | 
            
              | 135 |         my @itemloop; | 
            
              | 136 |         push @itemloop, $cell; | 
            
              | 137 |  | 
            
              | 138 |         $template->param( items => \@itemloop ); | 
            
              | 139 |     } | 
            
              | 140 | # | 
            
              | 141 | # 3rd step = import the records | 
            
              | 142 | # | 
            
              | 143 | } elsif ( $op eq 'import_records' ) { | 
            
              | 144 |     my $num=FormatNumber(); | 
        
          | 83 | #import selected lines | 145 | #import selected lines | 
        
          | 84 |     $template->param('basketno' => $cgiparams->{'basketno'}); | 146 |     $template->param('basketno' => $cgiparams->{'basketno'}); | 
        
          | 85 | # Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards | 147 | # Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards | 
  
    | Lines 95-235
          if ($op eq ""){
      
      
        Link Here | 
        
          | 95 |     my $import_batch_id = $cgiparams->{'import_batch_id'}; | 157 |     my $import_batch_id = $cgiparams->{'import_batch_id'}; | 
        
          | 96 |     my $biblios = GetImportBibliosRange($import_batch_id); | 158 |     my $biblios = GetImportBibliosRange($import_batch_id); | 
        
          | 97 |     for my $biblio (@$biblios){ | 159 |     for my $biblio (@$biblios){ | 
          
            
              | 98 |         if($cgiparams->{'order-'.$biblio->{'import_record_id'}}){ | 160 |         # 1st insert the biblio, or find it through matcher | 
            
              | 99 |             my ($marcblob, $encoding) = GetImportRecordMarc($biblio->{'import_record_id'}); | 161 |         my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); | 
            
              | 100 |             my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; | 162 |         my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; | 
            
              | 101 |             my ($duplicatetitle, $biblionumber); | 163 |         my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 ); | 
            
              | 102 |             if(!(($biblionumber,$duplicatetitle) = FindDuplicate($marcrecord))){ | 164 |         my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0; | 
            
              | 103 | #FIXME: missing: marc21 support (should be same with different field) | 165 |  | 
            
              | 104 |                 if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) { | 166 |         unless ( $biblionumber ) { | 
            
              | 105 |                     my $itemtypeid = "itemtype-" . $biblio->{'import_record_id'}; | 167 |             # add the biblio | 
            
              | 106 |                     $marcrecord->field(200)->update("b" => $cgiparams->{$itemtypeid}); | 168 |             my $bibitemnum; | 
            
              | 107 |                 } | 169 |  | 
            
              | 108 |                 # add the biblio | 170 |             # remove ISBN - | 
            
              | 109 |                 my $bibitemnum; | 171 |             my ( $isbnfield, $isbnsubfield ) = GetMarcFromKohaField( 'biblioitems.isbn', '' );                 | 
            
              | 110 |                 # remove ISBN - | 172 |             if ( $marcrecord->field($isbnfield) ) { | 
            
              | 111 |                 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn',''); | 173 |                 foreach my $field ( $marcrecord->field($isbnfield) ) { | 
            
              | 112 |                 if ( $marcrecord->field($isbnfield) ) { | 174 |                     foreach my $subfield ( $field->subfield($isbnsubfield) ) { | 
            
              | 113 |                     foreach my $field ( $marcrecord->field($isbnfield) ) { | 175 |                         my $newisbn = $field->subfield($isbnsubfield); | 
            
              | 114 |                         foreach my $subfield ( $field->subfield($isbnsubfield) ) { | 176 |                         $newisbn =~ s/-//g; | 
            
              | 115 |                             my $newisbn = $field->subfield($isbnsubfield); | 177 |                         $field->update( $isbnsubfield => $newisbn ); | 
            
              | 116 |                             $newisbn =~ s/-//g; |  |  | 
            
              | 117 |                             $field->update( $isbnsubfield => $newisbn ); | 
            
              | 118 |                         } | 
        
          | 119 |                     } | 178 |                     } | 
        
          | 120 |                 } | 179 |                 } | 
            
              | 121 |  |  |  | 
            
              | 122 |                 ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ); | 
            
              | 123 |             } else { | 
            
              | 124 |                 warn("Duplicate item found: ", $biblionumber, "; Duplicate: ", $duplicatetitle); | 
        
          | 125 |             } | 180 |             } | 
            
              |  |  | 181 |             ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ); | 
            
              | 182 |             # 2nd add authorities if applicable | 
        
          | 126 |             if (C4::Context->preference("BiblioAddsAuthorities")){ | 183 |             if (C4::Context->preference("BiblioAddsAuthorities")){ | 
        
          | 127 |                 my ($countlinked,$countcreated)=BiblioAddAuthorities($marcrecord, $cgiparams->{'frameworkcode'}); | 184 |                 my ($countlinked,$countcreated)=BiblioAddAuthorities($marcrecord, $cgiparams->{'frameworkcode'}); | 
        
          | 128 |             } | 185 |             } | 
          
            
              | 129 |             my $patron = C4::Members->GetMember(borrowernumber => $loggedinuser); | 186 |         } else { | 
            
              | 130 |             my $branch = C4::Branch->GetBranchDetail($patron->{branchcode}); | 187 |             SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); | 
            
              | 131 |             my ($invoice); | 188 |         } | 
            
              | 132 |             my %orderinfo = ("biblionumber", $biblionumber, | 189 |         # 3rd add order | 
            
              | 133 |                             "basketno", $cgiparams->{'basketno'}, | 190 |         my $patron = C4::Members->GetMember( borrowernumber => $loggedinuser ); | 
            
              | 134 |                             "quantity", $cgiparams->{'quantityrec-' . $biblio->{'import_record_id'}}, | 191 |         my $branch = C4::Branch->GetBranchDetail( $patron->{branchcode} ); | 
            
              | 135 |                             "branchcode", $branch, | 192 |         my ($invoice); | 
            
              | 136 |                             "booksellerinvoicenumber", $invoice, | 193 |         # get quantity in the MARC record (1 if none) | 
            
              | 137 |                             "budget_id", $budget_id, | 194 |         my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; | 
            
              | 138 |                             "uncertainprice", 1, | 195 |         my %orderinfo = ( | 
            
              | 139 |                             ); | 196 |             "biblionumber", $biblionumber, "basketno", $cgiparams->{'basketno'}, | 
            
              | 140 |             # get the price if there is one. | 197 |             "quantity", $quantity, "branchcode", $branch,  | 
            
              | 141 |             # filter by storing only the 1st number | 198 |             "booksellerinvoicenumber", $invoice,  | 
            
              | 142 |             # we suppose the currency is correct, as we have no possibilities to get it. | 199 |             "budget_id", $budget_id, "uncertainprice", 1, | 
            
              | 143 |             if ($marcrecord->subfield("345","d")) { | 200 |             "sort1", $cgiparams->{'sort1'},"sort2", $cgiparams->{'sort2'}, | 
            
              | 144 |               $orderinfo{'listprice'} = $marcrecord->subfield("345","d"); | 201 |             "notes", $cgiparams->{'notes'}, "budget_id", $cgiparams->{'budget_id'}, | 
            
              | 145 |               if ($orderinfo{'listprice'} =~ /^([\d\.,]*)/) { | 202 |             "currency",$cgiparams->{'currency'}, | 
            
              | 146 |                   $orderinfo{'listprice'} = $1; | 203 |         ); | 
            
              | 147 |                   $orderinfo{'listprice'} =~ s/,/\./; | 204 |         # get the price if there is one. | 
            
              | 148 |                   my $basket = GetBasket($orderinfo{basketno}); | 205 |         # filter by storing only the 1st number | 
            
              | 149 |                   my $bookseller = GetBookSellerFromId($basket->{booksellerid}); | 206 |         # we suppose the currency is correct, as we have no possibilities to get it. | 
            
              | 150 |                   # '//' is like '||' but tests for defined, rather than true | 207 |         my $price= GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); | 
            
              | 151 |                   my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; | 208 |         if ($price){ | 
            
              | 152 |                   $orderinfo{'unitprice'} = $orderinfo{listprice} - ($orderinfo{listprice} * ($bookseller->{discount} / 100)); | 209 |             $price = $num->unformat_number($price); | 
            
              | 153 |                   $orderinfo{'ecost'} = $orderinfo{unitprice}; | 210 |         } | 
            
              | 154 |               } else { | 211 |         if ($price){ | 
            
              | 155 |                   $orderinfo{'listprice'} = 0; | 212 |             $orderinfo{'listprice'} = $price; | 
            
              | 156 |               } | 213 |             eval "use C4::Acquisition qw/GetBasket/;"; | 
            
              | 157 |               $orderinfo{'rrp'} = $orderinfo{'listprice'}; | 214 |             eval "use C4::Bookseller qw/GetBookSellerFromId/;"; | 
            
              | 158 |             } | 215 |             my $basket     = GetBasket( $orderinfo{basketno} ); | 
            
              | 159 |             elsif ($marcrecord->subfield("010","d")) { | 216 |             my $bookseller = GetBookSellerFromId( $basket->{booksellerid} ); | 
            
              | 160 |               $orderinfo{'listprice'} = $marcrecord->subfield("010","d"); | 217 |             my $gst        = $bookseller->{gstrate} || C4::Context->preference("gist") || 0; | 
            
              | 161 |               if ($orderinfo{'listprice'} =~ /^([\d\.,]*)/) { | 218 |             $orderinfo{'unitprice'} = $orderinfo{listprice} - ( $orderinfo{listprice} * ( $bookseller->{discount} / 100 ) ); | 
            
              | 162 |                   $orderinfo{'listprice'} = $1; | 219 |             $orderinfo{'ecost'} = $orderinfo{unitprice}; | 
            
              | 163 |                   $orderinfo{'listprice'} =~ s/,/\./; | 220 |         } else { | 
            
              | 164 |                   my $basket = GetBasket($orderinfo{basketno}); | 221 |             $orderinfo{'listprice'} = 0; | 
            
              | 165 |                   my $bookseller = GetBookSellerFromId($basket->{booksellerid}); | 222 |         } | 
            
              | 166 |                   my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; | 223 |         $orderinfo{'rrp'} = $orderinfo{'listprice'}; | 
            
              | 167 |                   $orderinfo{'unitprice'} = $orderinfo{listprice} - ($orderinfo{listprice} * ($bookseller->{discount} / 100)); | 224 |  | 
            
              | 168 |                   $orderinfo{'ecost'} = $orderinfo{unitprice}; | 225 |         # remove uncertainprice flag if we have found a price in the MARC record | 
            
              | 169 |               } else { | 226 |         $orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; | 
            
              | 170 |                   $orderinfo{'listprice'} = 0; | 227 |         my $basketno; | 
            
              | 171 |               } | 228 |         ( $basketno, $ordernumber ) = NewOrder( \%orderinfo ); | 
            
              | 172 |               $orderinfo{'rrp'} = $orderinfo{'listprice'}; | 229 |  | 
            
              | 173 |             } | 230 |         # 4th, add items if applicable | 
            
              | 174 |             # remove uncertainprice flag if we have found a price in the MARC record | 231 |         # parse the item sent by the form, and create an item just for the import_record_id we are dealing with | 
            
              | 175 |             $orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; | 232 |         # this is not optimised, but it's working ! | 
            
              | 176 |             my $basketno; | 233 |         if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { | 
            
              | 177 |             ( $basketno, $ordernumber ) = NewOrder(\%orderinfo); | 234 |             my @tags         = $input->param('tag'); | 
            
              | 178 |  | 235 |             my @subfields    = $input->param('subfield'); | 
            
              | 179 |             # now, add items if applicable | 236 |             my @field_values = $input->param('field_value'); | 
            
              | 180 |             # parse all items sent by the form, and create an item just for the import_record_id we are dealing with | 237 |             my @serials      = $input->param('serial'); | 
            
              | 181 |             # this is not optimised, but it's working ! | 238 |             my @ind_tag   = $input->param('ind_tag'); | 
            
              | 182 |             if (C4::Context->preference('AcqCreateItem') eq 'ordering') { | 239 |             my @indicator = $input->param('indicator'); | 
            
              | 183 |                 my @tags         = $input->param('tag'); | 240 |             my $item; | 
            
              | 184 |                 my @subfields    = $input->param('subfield'); | 241 |             push @{ $item->{tags} },         $tags[0]; | 
            
              | 185 |                 my @field_values = $input->param('field_value'); | 242 |             push @{ $item->{subfields} },    $subfields[0]; | 
            
              | 186 |                 my @serials      = $input->param('serial'); | 243 |             push @{ $item->{field_values} }, $field_values[0]; | 
            
              | 187 |                 my @itemids       = $input->param('itemid'); # hint : in iso2709, the itemid contains the import_record_id, not an item id. It is used to get the right item, as we have X biblios. | 244 |             push @{ $item->{ind_tag} },      $ind_tag[0]; | 
            
              | 188 |                 my @ind_tag      = $input->param('ind_tag'); | 245 |             push @{ $item->{indicator} },    $indicator[0]; | 
            
              | 189 |                 my @indicator    = $input->param('indicator'); | 246 |             my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@ind_tag, \@indicator ); | 
            
              | 190 |                 #Rebuilding ALL the data for items into a hash | 247 |             my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); | 
            
              | 191 |                 # parting them on $itemid. | 248 |             for (my $qtyloop=1;$qtyloop <=$quantity;$qtyloop++) { | 
            
              | 192 |                 my %itemhash; | 249 |                 my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); | 
            
              | 193 |                 my $range=scalar(@itemids); | 250 |                 NewOrderItem( $itemnumber, $ordernumber ); | 
            
              | 194 |                  |  |  | 
            
              | 195 |                 my $i = 0; | 
            
              | 196 |                 my @items; | 
            
              | 197 |                 for my $itemid (@itemids){ | 
            
              | 198 |                     my $realitemid;     #javascript generated random itemids, in the form itemid-randomnumber, $realitemid is the itemid, while $itemid is the itemide parsed from the html | 
            
              | 199 |                     if ($itemid =~ m/(\d+)-.*/){ | 
            
              | 200 |                         my @splits = split(/-/, $itemid); | 
            
              | 201 |                         $realitemid = $splits[0]; | 
            
              | 202 |                     } | 
            
              | 203 |                     if ( ( $realitemid && $cgiparams->{'order-'. $realitemid} && $realitemid eq $biblio->{import_record_id}) || ($itemid && $cgiparams->{'order-'. $itemid} && $itemid eq $biblio->{import_record_id}) ){ | 
            
              | 204 |                         my ($item, $found); | 
            
              | 205 |                         for my $tmpitem (@items){ | 
            
              | 206 |                             if ($tmpitem->{itemid} eq $itemid){ | 
            
              | 207 |                                 $item = $tmpitem; | 
            
              | 208 |                                 $found = 1; | 
            
              | 209 |                             } | 
            
              | 210 |                         } | 
            
              | 211 |                         push @{$item->{tags}}, $tags[$i]; | 
            
              | 212 |                         push @{$item->{subfields}}, $subfields[$i]; | 
            
              | 213 |                         push @{$item->{field_values}}, $field_values[$i]; | 
            
              | 214 |                         push @{$item->{ind_tag}}, $ind_tag[$i]; | 
            
              | 215 |                         push @{$item->{indicator}}, $indicator[$i]; | 
            
              | 216 |                         $item->{itemid} = $itemid; | 
            
              | 217 |                         if (! $found){ | 
            
              | 218 |                              push @items, $item; | 
            
              | 219 |                         } | 
            
              | 220 |                     } | 
            
              | 221 |                     ++$i | 
            
              | 222 |                 } | 
            
              | 223 |                 foreach my $item (@items){ | 
            
              | 224 |                         my $xml = TransformHtmlToXml( $item->{'tags'}, | 
            
              | 225 |                                                 $item->{'subfields'}, | 
            
              | 226 |                                                 $item->{'field_values'}, | 
            
              | 227 |                                                 $item->{'ind_tag'}, | 
            
              | 228 |                                                 $item->{'indicator'}); | 
            
              | 229 |                         my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); | 
            
              | 230 |                         my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber); | 
            
              | 231 |                         NewOrderItem( $itemnumber, $ordernumber); | 
            
              | 232 |                 } | 
        
          | 233 |             } | 251 |             } | 
        
          | 234 |         } | 252 |         } | 
        
          | 235 |     } | 253 |     } | 
  
    | Lines 237-242
          if ($op eq ""){
      
      
        Link Here | 
        
          | 237 |     print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}); | 255 |     print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}); | 
        
          | 238 |     exit; | 256 |     exit; | 
        
          | 239 | } | 257 | } | 
            
              |  |  | 258 |  | 
            
              | 259 | my $budgets = GetBudgets(); | 
            
              | 260 | my $budget_id = @$budgets[0]->{'budget_id'}; | 
            
              | 261 | # build bookfund list | 
            
              | 262 | my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); | 
            
              | 263 | my ( $flags, $homebranch ) = ( $borrower->{'flags'}, $borrower->{'branchcode'} ); | 
            
              | 264 | my $budget = GetBudget($budget_id); | 
            
              | 265 |  | 
            
              | 266 | # build budget list | 
            
              | 267 | my $budget_loop = []; | 
            
              | 268 | my $budgets = GetBudgetHierarchy( q{}, $borrower->{branchcode}, $borrower->{borrowernumber} ); | 
            
              | 269 | foreach my $r ( @{$budgets} ) { | 
            
              | 270 |     if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { | 
            
              | 271 |         next; | 
            
              | 272 |     } | 
            
              | 273 |     push @{$budget_loop}, | 
            
              | 274 |       { b_id  => $r->{budget_id}, | 
            
              | 275 |         b_txt => $r->{budget_name}, | 
            
              | 276 |         b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0, | 
            
              | 277 |       }; | 
            
              | 278 | } | 
            
              | 279 | $template->param( budget_loop    => $budget_loop,); | 
            
              | 280 |  | 
            
              | 281 | my $CGIsort1; | 
            
              | 282 | if ($budget) {    # its a mod .. | 
            
              | 283 |     if ( defined $budget->{'sort1_authcat'} ) {    # with custom  Asort* planning values | 
            
              | 284 |         $CGIsort1 = GetAuthvalueDropbox( 'sort1', $budget->{'sort1_authcat'}, $data->{'sort1'} ); | 
            
              | 285 |     } | 
            
              | 286 | } elsif ( scalar(@$budgets) ) { | 
            
              | 287 |     $CGIsort1 = GetAuthvalueDropbox( 'sort1', @$budgets[0]->{'sort1_authcat'}, '' ); | 
            
              | 288 | } else { | 
            
              | 289 |     $CGIsort1 = GetAuthvalueDropbox( 'sort1', '', '' ); | 
            
              | 290 | } | 
            
              | 291 |  | 
            
              | 292 | # if CGIsort is successfully fetched, the use it | 
            
              | 293 | # else - failback to plain input-field | 
            
              | 294 | if ($CGIsort1) { | 
            
              | 295 |     $template->param( CGIsort1 => $CGIsort1 ); | 
            
              | 296 | } else { | 
            
              | 297 |     $template->param( sort1 => $data->{'sort1'} ); | 
            
              | 298 | } | 
            
              | 299 |  | 
            
              | 300 | my $CGIsort2; | 
            
              | 301 | if ($budget) { | 
            
              | 302 |     if ( defined $budget->{'sort2_authcat'} ) { | 
            
              | 303 |         $CGIsort2 = GetAuthvalueDropbox( 'sort2', $budget->{'sort2_authcat'}, $data->{'sort2'} ); | 
            
              | 304 |     } | 
            
              | 305 | } elsif ( scalar(@$budgets) ) { | 
            
              | 306 |     $CGIsort2 = GetAuthvalueDropbox( 'sort2', @$budgets[0]->{sort2_authcat}, '' ); | 
            
              | 307 | } else { | 
            
              | 308 |     $CGIsort2 = GetAuthvalueDropbox( 'sort2', '', '' ); | 
            
              | 309 | } | 
            
              | 310 |  | 
            
              | 311 | if ($CGIsort2) { | 
            
              | 312 |     $template->param( CGIsort2 => $CGIsort2 ); | 
            
              | 313 | } else { | 
            
              | 314 |     $template->param( sort2 => $data->{'sort2'} ); | 
            
              | 315 | } | 
            
              | 316 |  | 
        
          | 240 | output_html_with_http_headers $input, $cookie, $template->output; | 317 | output_html_with_http_headers $input, $cookie, $template->output; | 
        
          | 241 |  | 318 |  | 
        
          | 242 |  | 319 |  | 
  
    | Lines 268-279
          sub import_biblios_list {
      
      
        Link Here | 
        
          | 268 |     my $batch = GetImportBatch($import_batch_id,'staged'); | 345 |     my $batch = GetImportBatch($import_batch_id,'staged'); | 
        
          | 269 |     my $biblios = GetImportBibliosRange($import_batch_id,'','','staged'); | 346 |     my $biblios = GetImportBibliosRange($import_batch_id,'','','staged'); | 
        
          | 270 |     my @list = (); | 347 |     my @list = (); | 
          
            
              | 271 | # # Itemtype is mandatory for adding a biblioitem, we just add a default, the user needs to modify this aftewards | 348 |  | 
            
              | 272 | #     my $itemtypehash = GetItemTypes(); |  |  | 
            
              | 273 | #     my @itemtypes; | 
            
              | 274 | #     for my $key (sort { $itemtypehash->{$a}->{description} cmp $itemtypehash->{$b}->{description} } keys %$itemtypehash) { | 
            
              | 275 | #         push(@itemtypes, $itemtypehash->{$key}); | 
            
              | 276 | #     } | 
        
          | 277 |     foreach my $biblio (@$biblios) { | 349 |     foreach my $biblio (@$biblios) { | 
        
          | 278 |         my $citation = $biblio->{'title'}; | 350 |         my $citation = $biblio->{'title'}; | 
        
          | 279 |         $citation .= " $biblio->{'author'}" if $biblio->{'author'}; | 351 |         $citation .= " $biblio->{'author'}" if $biblio->{'author'}; | 
  
    | Lines 293-310
          sub import_biblios_list {
      
      
        Link Here | 
        
          | 293 |             match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0, | 365 |             match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0, | 
        
          | 294 |             match_citation => $#$match > -1 ? $match->[0]->{'title'} . ' ' . $match->[0]->{'author'} : '', | 366 |             match_citation => $#$match > -1 ? $match->[0]->{'title'} . ' ' . $match->[0]->{'author'} : '', | 
        
          | 295 |             match_score => $#$match > -1 ? $match->[0]->{'score'} : 0, | 367 |             match_score => $#$match > -1 ? $match->[0]->{'score'} : 0, | 
            
              | 296 | #             itemtypes => \@itemtypes, |  |  | 
        
          | 297 |         ); | 368 |         ); | 
            
              | 298 | #         if (C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber) { |  |  | 
            
              | 299 | #             # prepare empty item form | 
            
              | 300 | #             my $cell = PrepareItemrecordDisplay(); | 
            
              | 301 | #             my @itemloop; | 
            
              | 302 | #             push @itemloop,$cell; | 
            
              | 303 | #             $cellrecord{'items'} = \@itemloop; | 
            
              | 304 | #         } | 
        
          | 305 |         push @list, \%cellrecord; | 369 |         push @list, \%cellrecord; | 
            
              | 306 |  |  |  | 
            
              | 307 |  | 
        
          | 308 |     } | 370 |     } | 
        
          | 309 |     my $num_biblios = $batch->{'num_biblios'}; | 371 |     my $num_biblios = $batch->{'num_biblios'}; | 
        
          | 310 |     my $overlay_action = GetImportBatchOverlayAction($import_batch_id); | 372 |     my $overlay_action = GetImportBatchOverlayAction($import_batch_id); |