Bug 30572: Dbrev for search_marc_to_field.sort
[koha-ffzg.git] / acqui / addorderiso2709.pl
index c445fb8..658adb0 100755 (executable)
 
 use Modern::Perl;
 use CGI qw ( -utf8 );
-use Carp;
 use YAML::XS;
-use List::MoreUtils qw/uniq/;
+use List::MoreUtils;
 use Encode;
 
 use C4::Context;
-use C4::Auth;
-use C4::Output;
-use C4::ImportBatch;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+use C4::ImportBatch qw( GetImportRecordsRange GetImportRecordMarc GetImportRecordMatches SetImportRecordStatus SetMatchedBiblionumber SetImportBatchStatus GetImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction );
 use C4::Matcher;
-use C4::Search qw/FindDuplicate/;
-use C4::Acquisition;
-use C4::Biblio;
-use C4::Items;
-use C4::Koha;
-use C4::Budgets;
-use C4::Acquisition;
+use C4::Search qw( FindDuplicate );
+use C4::Acquisition qw( populate_order_with_prices );
+use C4::Biblio qw(
+    AddBiblio
+    GetMarcFromKohaField
+    GetMarcPrice
+    GetMarcQuantity
+    TransformHtmlToXml
+);
+use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc );
+use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget GetBudgetByCode );
+use C4::Acquisition qw( populate_order_with_prices );
 use C4::Suggestions;    # GetSuggestion
 use C4::Members;
 
@@ -92,23 +96,22 @@ if ($op eq ""){
 #
 } elsif ($op eq "batch_details"){
 #display lines inside the selected batch
-    # get currencies (for change rates calcs if needed)
-    my @currencies = Koha::Acquisition::Currencies->search;
 
     $template->param("batch_details" => 1,
                      "basketno"      => $cgiparams->{'basketno'},
-                     currencies => \@currencies,
+                     # get currencies (for change rates calcs if needed)
+                     currencies => Koha::Acquisition::Currencies->search,
                      bookseller => $bookseller,
                      "allmatch" => $allmatch,
                      );
     import_biblios_list($template, $cgiparams->{'import_batch_id'});
     if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) {
         # prepare empty item form
-        my $cell = PrepareItemrecordDisplay( '', '', '', 'ACQ' );
+        my $cell = PrepareItemrecordDisplay( '', '', undef, 'ACQ' );
 
         #     warn "==> ".Data::Dumper::Dumper($cell);
         unless ($cell) {
-            $cell = PrepareItemrecordDisplay( '', '', '', '' );
+            $cell = PrepareItemrecordDisplay( '', '', undef, '' );
             $template->param( 'NoACQframework' => 1 );
         }
         my @itemloop;
@@ -162,6 +165,8 @@ if ($op eq ""){
         $c_discount = $c_discount / 100 if $c_discount > 1;
         my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
         my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
+        my $c_replacement_price = shift( @orderreplacementprices );
+        my $c_price = shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
 
         # Insert the biblio, or find it through matcher
         unless ( $biblionumber ) {
@@ -322,24 +327,23 @@ if ($op eq ""){
                 order_internalnote => $cgiparams->{'all_order_internalnote'},
                 order_vendornote   => $cgiparams->{'all_order_vendornote'},
                 currency           => $cgiparams->{'all_currency'},
-                replacementprice   => shift( @orderreplacementprices ),
+                replacementprice   => $c_replacement_price,
             );
             # get the price if there is one.
-            my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
-            if ($price){
+            if ($c_price){
                 # in France, the cents separator is the , but sometimes, ppl use a .
                 # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
-                $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
-                $price = Koha::Number::Price->new($price)->unformat;
+                $c_price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
+                $c_price = Koha::Number::Price->new($c_price)->unformat;
                 $orderinfo{tax_rate} = $bookseller->tax_rate;
                 my $c = $c_discount ? $c_discount : $bookseller->discount / 100;
                 $orderinfo{discount} = $c;
                 if ( $c_discount ) {
-                    $orderinfo{ecost} = $price;
+                    $orderinfo{ecost} = $c_price;
                     $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
                 } else {
-                    $orderinfo{ecost} = $price * ( 1 - $c );
-                    $orderinfo{rrp}   = $price;
+                    $orderinfo{ecost} = $c_price * ( 1 - $c );
+                    $orderinfo{rrp}   = $c_price;
                 }
                 $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
                 $orderinfo{unitprice} = $orderinfo{ecost};
@@ -372,15 +376,7 @@ if ($op eq ""){
             my @subfields    = $input->multi_param('subfield');
             my @field_values = $input->multi_param('field_value');
             my @serials      = $input->multi_param('serial');
-            my @ind_tag   = $input->multi_param('ind_tag');
-            my @indicator = $input->multi_param('indicator');
-            my $item;
-            push @{ $item->{tags} },         $tags[0];
-            push @{ $item->{subfields} },    $subfields[0];
-            push @{ $item->{field_values} }, $field_values[0];
-            push @{ $item->{ind_tag} },      $ind_tag[0];
-            push @{ $item->{indicator} },    $indicator[0];
-            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag );
+            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values );
             my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
             for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
                 my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
@@ -614,7 +610,6 @@ sub import_biblios_list {
     my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
     my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
     my $item_action = GetImportBatchItemAction($import_batch_id);
-    my @itypes = Koha::ItemTypes->search;
     $template->param(biblio_list => \@list,
                         num_results => $num_records,
                         import_batch_id => $import_batch_id,
@@ -625,9 +620,9 @@ sub import_biblios_list {
                         "item_action_${item_action}" => 1,
                         item_action => $item_action,
                         item_error => $item_error,
-                        libraries => scalar Koha::Libraries->search(),
+                        libraries => Koha::Libraries->search,
                         locationloop => \@locations,
-                        itypeloop => \@itypes,
+                        itemtypes => Koha::ItemTypes->search,
                         ccodeloop => \@ccodes,
                         notforloanloop => \@notforloans,
                     );