X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Faqplan.pl;h=cbded1ca64b11f7749b13da40a1d62eca5f47d0c;hb=17e20f4ec4a1674a2faac9df9ad5231ffd9ddaf1;hp=bdd5dda95bb2994260c1a5d13d1e5a44e408f4c8;hpb=934de70eec747f901904721fc12024051cf52f4c;p=koha-ffzg.git diff --git a/admin/aqplan.pl b/admin/aqplan.pl index bdd5dda95b..cbded1ca64 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -3,42 +3,46 @@ # Copyright 2008-2009 BibLibre SARL # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . #script to administer the aqbudgets0 table #written 20/02/2002 by paul.poulain@free.fr # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html) -use strict; -#use warnings; FIXME - Bug 2505 +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 C4::Dates qw/format_date format_date_in_iso/; +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::Input; -use C4::Debug; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user ); +use Koha::Acquisition::Currencies; -my $input = new CGI; +our $input = CGI->new; #### $input my $dbh = C4::Context->dbh; @@ -47,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, } ); @@ -58,17 +60,19 @@ 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; +if ( $active_currency ) { + $template->param( symbol => $active_currency->symbol, + currency => $active_currency->currency, + ); +} $template->param( period_button_only => 1 ) if $count == 0; # authcats_loop populates the YUI planning button my $auth_cats_loop = GetBudgetAuthCats($budget_period_id); -my $budget_period_id = $period->{'budget_period_id'}; +$budget_period_id = $period->{'budget_period_id'}; my $budget_period_startdate = $period->{'budget_period_startdate'}; my $budget_period_enddate = $period->{'budget_period_enddate'}; my $budget_period_locked = $period->{'budget_period_locked'}; @@ -84,21 +88,20 @@ $template->param( # ------- get periods stuff ------------------ -my $borrower_id = $template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'}; -my $borrower_branchcode = $template->{VARS}->{'USER_INFO'}[0]->{'branchcode'}; -my $periods; +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 $basename = $input->param("basename"); -my $del = $input->param("sep"); +my $output = $input->param("output") // q{}; +our $basename = $input->param("basename"); +our $del = C4::Context->csv_delimiter(scalar $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; @@ -107,11 +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 $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 ? $borrower_branchcode : '', + $show_mine ? $borrowernumber : '' +); # build categories list my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' "); @@ -131,7 +136,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 +147,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 +166,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 +214,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' ) ); @@ -221,7 +224,7 @@ elsif ( $authcat eq 'MONTHS' ) { #calc number of months between my $months = ( $Dy * 12 ) + $Dm; - my $start_month = @start_date[1]; + my $start_month = $start_date[1]; my $end_month = ( $Dy * 12 ) + $Dm; for my $mth ( 0 ... $months ) { @@ -304,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 ); @@ -320,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}; } @@ -330,7 +333,7 @@ foreach my $budget (@budgets) { or $authcat eq 'BRANCHES' or $authcat eq 'MONTHS' ) { - # but skip budgets that dont match the current auth-category + # but skip budgets that don't match the current auth-category next if ( $budget->{'sort1_authcat'} ne $authcat && $budget->{'sort2_authcat'} ne $authcat ); } @@ -355,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; @@ -373,7 +376,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 ), @@ -400,7 +403,6 @@ if ( $output eq "file" ) { exit(1); } -my $branchloop = C4::Branch::GetBranchesLoop(); $template->param( authvals_row => \@authvals_row, budget_lines => \@budget_lines, @@ -417,7 +419,6 @@ $template->param( authvals => \@authvals_row, hide_cols_loop => \@hide_cols, - branchloop => $branchloop, ); output_html_with_http_headers $input, $cookie, $template->output; @@ -449,8 +450,7 @@ sub _print_to_csv { print "$str\n"; foreach my $row (@$results) { - $row->{'budget_name_indent'} =~ s/ / /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'};