Bug 24860: (QA follow-up) Fix typo in holds queue viewer
[koha-ffzg.git] / admin / aqplan.pl
index fd3f2e6..cbded1c 100755 (executable)
 
 use Modern::Perl;
 use CGI qw ( -utf8 );
-use List::Util qw/min/;
-use Date::Calc qw/Delta_YMD Easter_Sunday Today Decode_Date_EU/;
-use Date::Manip qw/ ParseDate UnixDate DateCalc/;
+use Date::Calc qw( Delta_YMD );
+use Date::Manip qw( DateCalc UnixDate );
 use Text::CSV_XS;
 
-use C4::Acquisition;
-use C4::Budgets;
+use C4::Budgets qw(
+    CanUserUseBudget
+    GetBudgetAuthCats
+    GetBudgetHierarchy
+    GetBudgetPeriod
+    GetBudgetsPlanCell
+    GetCols
+    GetPeriodsCount
+    HideCols
+    ModBudgetPlan
+);
 use C4::Context;
-use C4::Output;
-use C4::Koha;
-use C4::Auth;
-use C4::Debug;
+use C4::Output qw( output_html_with_http_headers );
+use C4::Auth qw( get_template_and_user );
 use Koha::Acquisition::Currencies;
 
-our $input = new CGI;
+our $input = CGI->new;
 ####  $input
 
 my $dbh = C4::Context->dbh;
@@ -45,9 +51,7 @@ my ( $template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user
     {   template_name   => "admin/aqplan.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { acquisition => 'planning_manage' },
-        debug           => 0,
     }
 );
 
@@ -84,16 +88,16 @@ $template->param(
 
 # ------- get periods stuff ------------------
 
-my $borrower_id         = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'};
-my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}->{'branchcode'};
+
+my $borrower_branchcode = my $branch_code = C4::Context->userenv->{'branch'};
 
 my $authcat      = $input->param('authcat');
-my $show_active  = $input->param('show_active');
+my $show_active  = $input->param('show_active') // 0;
 my $show_actual  = $input->param('show_actual');
 my $show_percent = $input->param('show_percent');
-my $output       = $input->param("output");
+my $output       = $input->param("output") // q{};
 our $basename     = $input->param("basename");
-our $del          = $input->param("sep");
+our $del          = C4::Context->csv_delimiter(scalar $input->param("sep"));
 
 my $show_mine       = $input->param('show_mine') ;
 
@@ -106,9 +110,13 @@ if ( $budget_period_locked == 1  && not defined  $show_actual ) {
 $authcat = 'Asort1' if  not defined $authcat; # defaults to Asort if no authcat given
 
 my $budget_id = $input->param('budget_id');
-my $op        = $input->param("op");
+my $op        = $input->param("op") // q{};
 
-my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' );
+my $budgets_ref = GetBudgetHierarchy(
+    $budget_period_id,
+    $show_mine ? $borrower_branchcode : '',
+    $show_mine ? $borrowernumber      : ''
+);
 
 # build categories list
 my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
@@ -299,7 +307,7 @@ foreach my $n (@names) {
 #         DEFAULT DISPLAY BEGINS
 
 my $CGIextChoice = ( 'CSV' ); # FIXME translation
-my $CGIsepChoice = ( C4::Context->preference("delimiter") );
+my $CGIsepChoice = ( C4::Context->csv_delimiter );
 
 my ( @budget_lines, %cell_hash );
 
@@ -315,7 +323,7 @@ foreach my $budget (@budgets) {
     if ( $period->{budget_period_locked} == 1 ) {
         $budget_lock = 1;
     } elsif ( $budget->{budget_permission} == 1 ) {
-        $budget_lock = 1 if $borrower_id != $budget->{'budget_owner_id'};
+        $budget_lock = 1 if $borrowernumber != $budget->{'budget_owner_id'};
     } elsif ( $budget->{budget_permission} == 2 ) {
         $budget_lock = 1 if $borrower_branchcode ne $budget->{budget_branchcode};
     }
@@ -350,8 +358,8 @@ foreach my $budget (@budgets) {
         );
 
         my ( $actual, $estimated, $display ) = GetBudgetsPlanCell( \%cell, $period, $budget );
-        $cell{actual_amount}    = sprintf( "%.2f", $actual );
-        $cell{estimated_amount} = sprintf( "%.2f", $estimated );
+        $cell{actual_amount}    = sprintf( "%.2f", $actual // 0 );
+        $cell{estimated_amount} = sprintf( "%.2f", $estimated // 0 );
         $cell{display}          = $authvals_row[$i]{display};
         $cell{colnum}           = $i;