Bug 14868 - Update swagger.min.json
[koha.git] / admin / aqplan.pl
index f55acc2..c6946d6 100755 (executable)
@@ -26,7 +26,6 @@ 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 C4::Dates qw/format_date format_date_in_iso/;
 use Text::CSV_XS;
 
 use C4::Acquisition;
@@ -35,8 +34,8 @@ use C4::Context;
 use C4::Output;
 use C4::Koha;
 use C4::Auth;
-use C4::Input;
 use C4::Debug;
+use Koha::Acquisition::Currencies;
 
 my $input = new CGI;
 ####  $input
@@ -58,9 +57,9 @@ my $budget_period_id = $input->param('budget_period_id');
 # IF PERIOD_ID IS DEFINED,  GET THE PERIOD - ELSE GET THE ACTIVE PERIOD BY DEFAULT
 my $period = GetBudgetPeriod($budget_period_id);
 my $count  = GetPeriodsCount();
-my $cur    = GetCurrency;
-$template->param( symbol => $cur->{symbol},
-                  currency => $cur->{currency}
+my $active_currency = Koha::Acquisition::Currencies->get_active;
+$template->param( symbol => $active_currency->symbol,
+                  currency => $active_currency->currency,
                );
 $template->param( period_button_only => 1 ) if $count == 0;
 
@@ -84,10 +83,9 @@ $template->param(
 
 # ------- get periods stuff ------------------
 
-my $borrower_id         = $template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'};
-my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}[0]->{'branchcode'};
+my $borrower_id         = $template->{VARS}->{'USER_INFO'}->{'borrowernumber'};
+my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}->{'branchcode'};
 
-my $periods;
 my $authcat      = $input->param('authcat');
 my $show_active  = $input->param('show_active');
 my $show_actual  = $input->param('show_actual');
@@ -98,7 +96,7 @@ my $del          = $input->param("sep");
 
 my $show_mine       = $input->param('show_mine') ;
 
-my @hide_cols      = $input->param('hide_cols');
+my @hide_cols      = $input->multi_param('hide_cols');
 
 if ( $budget_period_locked == 1  && not defined  $show_actual ) {
      $show_actual  = 1;
@@ -109,9 +107,7 @@ $authcat = 'Asort1' if  not defined $authcat; # defaults to Asort if no authcat
 my $budget_id = $input->param('budget_id');
 my $op        = $input->param("op");
 
-my $budget_branchcode;
-
-my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}[0]->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'}:'' );
+my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' );
 
 # build categories list
 my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
@@ -131,7 +127,7 @@ while ( my ($category) = $sth->fetchrow_array ) {
 push( @category_list, 'MONTHS' );
 push( @category_list, 'ITEMTYPES' );
 push( @category_list, 'BRANCHES' );
-push( @category_list, $$_{'authcat'} ) foreach @$auth_cats_loop;
+push( @category_list, $_ ) foreach @$auth_cats_loop;
 
 #reorder the list
 @category_list = sort { $a cmp $b } @category_list;
@@ -142,11 +138,10 @@ $template->param( authcat_dropbox => {
     });
 
 my @budgets = @$budgets_ref;
-my $CGISort;
 my @authvals;
 my %labels;
 
-my @names = $input->param();
+my @names = $input->multi_param();
 # ------------------------------------------------------------
 if ( $op eq 'save' ) {
     #get budgets
@@ -162,7 +157,6 @@ if ( $op eq 'save' ) {
     my %seen;
     @buds        = grep { !$seen{$_}++ } @buds;
     @auth_values = grep { !$seen{$_}++ } @auth_values;
-    my @budget_ids;
     my @budget_lines;
 
     foreach my $budget (@buds) {
@@ -211,7 +205,7 @@ if ( $authcat =~ m/^Asort/ ) {
     $sth->finish;
     @authvals = sort { $a <=> $b } @authvals;
 }
-elsif ( $authcat eq 'MONTHS' ) {
+elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) {
 
     # build months
     my @start_date = UnixDate( $budget_period_startdate, ( '%Y', '%m', '%d' ) );
@@ -373,7 +367,7 @@ foreach my $budget (@budgets) {
 
     %budget_line = (
         lines                   => \@cells_line,
-        budget_name_indent      => $budget->{budget_name_indent},
+        budget_name             => $budget->{budget_name},
         budget_amount           => $budget->{budget_amount},
         budget_alloc            => $budget->{budget_alloc},
         budget_act_remain       => sprintf( "%.2f", $budget_act_remain ),
@@ -449,8 +443,7 @@ sub _print_to_csv {
     print "$str\n";
 
     foreach my $row (@$results) {
-        $row->{'budget_name_indent'} =~ s/&nbsp;/ /g;
-        my @col = ( $row->{'budget_name_indent'}, $row->{'budget_amount'} );
+        my @col = ( $row->{'budget_name'}, $row->{'budget_amount'} );
         my $l = $row->{'lines'};
         foreach my $line (@$l) {
             push @col, $line->{'estimated_amount'};