Bug 17600: Standardize our EXPORT_OK
[srvgit] / acqui / invoices.pl
index 2d11746..b0e1db2 100755 (executable)
@@ -26,16 +26,15 @@ Search for invoices
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use C4::Auth;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
 
-use C4::Acquisition qw/GetInvoices/;
-use C4::Budgets;
-use Koha::DateUtils;
+use C4::Acquisition qw( GetInvoices GetInvoice );
+use C4::Budgets qw( GetBudget GetBudgets CanUserUseBudget );
+use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Acquisition::Booksellers;
 
 my $input = CGI->new;
@@ -44,9 +43,7 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
         template_name   => 'acqui/invoices.tt',
         query           => $input,
         type            => 'intranet',
-        authnotrequired => 0,
         flagsrequired   => { 'acquisition' => '*' },
-        debug           => 1,
     }
 );
 
@@ -90,7 +87,7 @@ if ( $op and $op eq 'do_search' ) {
 }
 
 # Build suppliers list
-my @suppliers      = Koha::Acquisition::Booksellers->search;
+my @suppliers      = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } );
 my $suppliers_loop = [];
 my $suppliername;
 foreach (@suppliers) {
@@ -113,9 +110,20 @@ foreach my $budget (@$budgets) {
     push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
 }
 
+my (@openedinvoices, @closedinvoices);
+for my $sub ( @{$invoices} ) {
+    unless ( $sub->{closedate} ) {
+        push @openedinvoices, $sub
+    } else {
+        push @closedinvoices, $sub
+    }
+}
+
 $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
 
 $template->param(
+    openedinvoices => \@openedinvoices,
+    closedinvoices => \@closedinvoices,
     do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
     invoices => $invoices,
     invoicenumber   => $invoicenumber,