Bug 29844: Fix ->search occurrences
[srvgit] / acqui / neworderempty.pl
index d9505d1..204448a 100755 (executable)
@@ -68,24 +68,30 @@ use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
 
-use C4::Auth;
-use C4::Budgets;
-
-use C4::Acquisition;
-use C4::Contract;
-use C4::Suggestions;   # GetSuggestion
-use C4::Biblio;                        # GetBiblioData GetMarcPrice
-use C4::Items; #PrepareItemRecord
-use C4::Output;
-use C4::Koha;
+use C4::Auth qw( get_template_and_user );
+use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget );
+
+use C4::Acquisition qw( GetOrder GetBasket FillWithDefaultValues GetOrderUsers );
+use C4::Contract qw( GetContract );
+use C4::Suggestions qw( GetSuggestion GetSuggestionInfo );
+use C4::Biblio qw(
+    AddBiblio
+    GetBiblioData
+    GetMarcBiblio
+    GetMarcFromKohaField
+    GetMarcPrice
+    GetMarcStructure
+    IsMarcStructureInternal
+);
+use C4::Output qw( output_and_exit output_html_with_http_headers );
 use C4::Members;
-use C4::Search qw/FindDuplicate/;
+use C4::Search qw( FindDuplicate );
 
 #needed for z3950 import:
-use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
+use C4::ImportBatch qw( SetImportRecordStatus SetMatchedBiblionumber GetImportRecordMarc );
 
 use Koha::Acquisition::Booksellers;
-use Koha::Acquisition::Currencies;
+use Koha::Acquisition::Currencies qw( get_active );
 use Koha::BiblioFrameworks;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::MarcSubfieldStructures;
@@ -94,7 +100,7 @@ use Koha::Patrons;
 use Koha::RecordProcessor;
 use Koha::Subscriptions;
 
-our $input           = new CGI;
+our $input           = CGI->new;
 my $booksellerid    = $input->param('booksellerid');   # FIXME: else ERROR!
 my $budget_id       = $input->param('budget_id') || 0;
 my $title           = $input->param('title');
@@ -115,9 +121,7 @@ our ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
         template_name   => "acqui/neworderempty.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { acquisition => 'order_manage' },
-        debug           => 1,
     }
 );
 
@@ -136,6 +140,16 @@ my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
 output_and_exit( $input, $cookie, $template, 'unknown_basket') unless $basketobj;
 output_and_exit( $input, $cookie, $template, 'unknown_vendor') unless $bookseller;
 
+$template->param(
+    ordernumber  => $ordernumber,
+    basketno     => $basketno,
+    basket       => $basket,
+    booksellerid => $basket->{'booksellerid'},
+    name         => $bookseller->name,
+);
+output_and_exit( $input, $cookie, $template, 'order_cannot_be_edited' )
+    if $ordernumber and $basketobj->closedate;
+
 my $contract = GetContract({
     contractnumber => $basket->{contractnumber}
 });
@@ -170,6 +184,8 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){
     # get the price if there is one.
     $listprice = GetMarcPrice($marcrecord, $marcflavour);
     SetImportRecordStatus($params->{'breedingid'}, 'imported');
+
+    SetMatchedBiblionumber( $params->{breedingid}, $biblionumber );
 }
 
 
@@ -310,7 +326,7 @@ $template->param( catalog_details => \@catalog_details, );
 my $suggestion;
 $suggestion = GetSuggestionInfo($suggestionid) if $suggestionid;
 
-my @currencies = Koha::Acquisition::Currencies->search;
+my @currencies = Koha::Acquisition::Currencies->search->as_list;
 my $active_currency = Koha::Acquisition::Currencies->get_active;
 
 # build bookfund list
@@ -351,7 +367,7 @@ if ($basketobj->effective_create_items eq 'ordering' && !$ordernumber) {
 
 # Get the item types list, but only if item_level_itype is YES. Otherwise, it will be in the item, no need to display it in the biblio
 my @itemtypes;
-@itemtypes = Koha::ItemTypes->search unless C4::Context->preference('item-level_itypes');
+@itemtypes = Koha::ItemTypes->search->as_list unless C4::Context->preference('item-level_itypes');
 
 if ( defined $from_subscriptionid ) {
     # Get the last received order for this subscription
@@ -396,10 +412,10 @@ if ( defined $from_subscriptionid ) {
 my (undef, $barcode_subfield) = GetMarcFromKohaField( 'items.barcode' );
 
 
-# get option values for gist syspref
+# get option values for TaxRates syspref
 my @gst_values = map {
     option => $_ + 0.0
-}, split( '\|', C4::Context->preference("gist") );
+}, split( '\|', C4::Context->preference("TaxRates") );
 
 my $quantity = $input->param('rr_quantity_to_order') ?
       $input->param('rr_quantity_to_order') :
@@ -409,10 +425,7 @@ $quantity //= 0;
 # fill template
 $template->param(
     existing         => $biblionumber,
-    ordernumber           => $ordernumber,
     # basket informations
-    basketno             => $basketno,
-    basket               => $basket,
     basketname           => $basket->{'basketname'},
     basketnote           => $basket->{'note'},
     booksellerid         => $basket->{'booksellerid'},
@@ -437,7 +450,6 @@ $template->param(
     order_vendornote     => $data->{'order_vendornote'},
     listincgst       => $bookseller->listincgst,
     invoiceincgst    => $bookseller->invoiceincgst,
-    name             => $bookseller->name,
     cur_active_sym   => $active_currency->symbol,
     cur_active       => $active_currency->currency,
     currencies       => \@currencies,
@@ -583,9 +595,7 @@ sub Load_Duplicate {
         template_name   => "acqui/neworderempty_duplicate.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { acquisition => 'order_manage' },
-#        debug           => 1,
     }
   );