Bug 25266: Fix error when no later order
[koha-ffzg.git] / acqui / histsearch.pl
index a1c7fe6..1f097d8 100755 (executable)
@@ -56,7 +56,7 @@ use C4::Output;
 use C4::Acquisition;
 use C4::Debug;
 use C4::Koha;
-use Koha::AdditionalField;
+use Koha::AdditionalFields;
 use Koha::DateUtils;
 
 my $input = new CGI;
@@ -89,21 +89,31 @@ my $filters = {
     ordernumber             => scalar $input->param('ordernumber'),
     search_children_too     => scalar $input->param('search_children_too'),
     created_by              => [ $input->multi_param('created_by') ],
+    managing_library        => scalar $input->param('managing_library'),
 };
+
 my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string;
 my $to_placed_on   = eval { dt_from_string( scalar $input->param('to')   ) } || dt_from_string;
 unless ( $input->param('from') ) {
     # Fill the form with year-1
-    $from_placed_on->subtract( years => 1 );
+    $from_placed_on->set_time_zone('floating')->subtract( years => 1 );
+}
+$filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } );
+$filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } );
+my @additional_fields = Koha::AdditionalFields->search( { tablename => 'aqbasket', searchable => 1 } );
+$template->param( available_additional_fields => \@additional_fields );
+my @additional_field_filters;
+foreach my $additional_field (@additional_fields) {
+    my $value = $input->param('additional_field_' . $additional_field->id);
+    if (defined $value and $value ne '') {
+        push @additional_field_filters, {
+            id => $additional_field->id,
+            value => $value,
+        };
+    }
 }
-$filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ),
-$filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ),
-$filters->{additional_fields} = Koha::AdditionalField->get_filters_from_query({
-    tablename => 'aqbasket',
-    query => $input,
-} );
-
-$template->param( available_additional_fields => scalar Koha::AdditionalField->all( { tablename => 'aqbasket', searchable => 1 } ) );
+$filters->{additional_fields} = \@additional_field_filters;
+
 
 my $order_loop;
 # If we're supplied any value then we do a search. Otherwise we don't.