Bug 32843: Fix cataloguing/value_builder/unimarc_field_124a.pl
[koha-ffzg.git] / admin / aqplan.pl
index f01e5e8..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,8 +88,8 @@ $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') // 0;
@@ -93,7 +97,7 @@ my $show_actual  = $input->param('show_actual');
 my $show_percent = $input->param('show_percent');
 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') ;
 
@@ -108,7 +112,11 @@ $authcat = 'Asort1' if  not defined $authcat; # defaults to Asort if no authcat
 my $budget_id = $input->param('budget_id');
 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};
     }