X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=admin%2Faqbudgetperiods.pl;h=861f303da305caf99503f7ce761ae08aef0951a9;hb=1a1529d20572c8eb7e65ad7bbd41f688d5f86f07;hp=8ab29ecfbc1c451065372c7fde950a7a3d742ae4;hpb=110c665a4b641258bf53c443db4fb77a408f0757;p=koha-ffzg.git diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 8ab29ecfbc..861f303da3 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -5,18 +5,18 @@ # # 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 . =head1 admin/aqbudgetperiods.pl @@ -46,22 +46,21 @@ script to administer the budget periods table use Modern::Perl; -use Number::Format qw(format_price); -use CGI; -use List::Util qw/min/; -use Koha::DateUtils; +use CGI qw ( -utf8 ); +use JSON qw( encode_json ); use Koha::Database; use C4::Koha; use C4::Context; -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; -use C4::Budgets; -use C4::Debug; +use C4::Budgets qw( GetBudgetPeriod GetBudgetHierarchy GetBudgetPeriods ModBudgetPeriod AddBudgetPeriod GetBudgets DelBudgetPeriod CloneBudgetPeriod MoveOrders ); +use C4::Log qw(logaction); +use Koha::Acquisition::Currencies; my $dbh = C4::Context->dbh; -my $input = new CGI; +my $input = CGI->new; my $searchfield = $input->param('searchfield') // ''; my $budget_period_id = $input->param('budget_period_id'); @@ -71,12 +70,10 @@ my $op = $input->param('op')||"else"; # get only the columns of aqbudgetperiods in budget_period_hashref my @columns = Koha::Database->new()->schema->source('Aqbudgetperiod')->columns; -my $budget_period_hashref = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) ) : () } keys( %{$input->Vars()} ) } ; -$budget_period_hashref->{budget_period_startdate} = dt_from_string( $input->param('budget_period_startdate') ); -$budget_period_hashref->{budget_period_enddate} = dt_from_string( $input->param('budget_period_enddate') ); +my $budget_period_hashref = { map { join(' ',@columns) =~ /$_/ ? ( $_ => scalar $input->param($_) ) : () } keys( %{$input->Vars()} ) } ; +$budget_period_hashref->{budget_period_startdate} = $input->param('budget_period_startdate'); +$budget_period_hashref->{budget_period_enddate} = $input->param('budget_period_enddate'); -my $activepagesize = 20; -my $inactivepagesize = 20; $searchfield =~ s/\,//g; my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( @@ -84,38 +81,19 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( template_name => "admin/aqbudgetperiods.tt", query => $input, type => "intranet", - authnotrequired => 0, flagsrequired => { acquisition => 'period_manage' }, - debug => 1, } ); -my $cur = GetCurrency(); -$template->param( symbol => $cur->{symbol}, - currency => $cur->{currency} - ); -my $cur_format = C4::Context->preference("CurrencyFormat"); -my $num; - -if ( $cur_format eq 'US' ) { - $num = new Number::Format( - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ',', - 'mon_decimal_point' => '.' - ); -} elsif ( $cur_format eq 'FR' ) { - $num = new Number::Format( - 'decimal_fill' => '2', - 'decimal_point' => ',', - 'int_curr_symbol' => '', - 'mon_thousands_sep' => ' ', - 'thousands_sep' => ' ', - 'mon_decimal_point' => ',' - ); +# This is used in incbudgets-active-currency.inc +my $active_currency = Koha::Acquisition::Currencies->get_active; +if ( $active_currency ) { + $template->param( symbol => $active_currency->symbol, + currency => $active_currency->currency + ); } - # ADD OR MODIFY A BUDGET PERIOD - BUILD SCREEN if ( $op eq 'add_form' ) { ## add or modify a budget period (preparation) @@ -125,14 +103,6 @@ if ( $op eq 'add_form' ) { my $budgetperiod_hash=GetBudgetPeriod($budget_period_id); # get dropboxes - my $editnum = new Number::Format( - 'int_curr_symbol' => '', - 'thousands_sep' => '', - 'mon_thousands_sep' => '', - 'mon_decimal_point' => '.' - ); - - $$budgetperiod_hash{budget_period_total}= $editnum->format_price($$budgetperiod_hash{'budget_period_total'}); $template->param( %$budgetperiod_hash ); @@ -143,43 +113,75 @@ elsif ( $op eq 'add_validate' ) { ## add or modify a budget period (confirmation) ## update budget period data - if ( $budget_period_id ne '' ) { - $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked); - my $status=ModBudgetPeriod($budget_period_hashref); - } - else { # ELSE ITS AN ADD - my $budget_period_id=AddBudgetPeriod($budget_period_hashref); - } - $op='else'; + if ( $budget_period_id ne '' ) { + # Grab the previous values so we can log them + my $budgetperiod_old=GetBudgetPeriod($budget_period_id); + $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked); + my $status=ModBudgetPeriod($budget_period_hashref); + # Log the budget modification + if (C4::Context->preference("AcquisitionLog")) { + my $diff = 0 - ($budgetperiod_old->{budget_period_total} - $budget_period_hashref->{budget_period_total}); + my $infos = { + budget_period_startdate => $input->param('budget_period_startdate'), + budget_period_enddate => $input->param('budget_period_enddate'), + budget_period_total => $budget_period_hashref->{budget_period_total}, + budget_period_startdate_old => $budgetperiod_old->{budget_period_startdate}, + budget_period_enddate_old => $budgetperiod_old->{budget_period_enddate}, + budget_period_total_old => $budgetperiod_old->{budget_period_total}, + budget_period_total_change => $diff + }; + logaction( + 'ACQUISITIONS', + 'MODIFY_BUDGET', + $budget_period_id, + encode_json($infos) + ); + } + } + else { # ELSE ITS AN ADD + my $budget_period_id=AddBudgetPeriod($budget_period_hashref); + } + $op='else'; } #-------------------------------------------------- elsif ( $op eq 'delete_confirm' ) { ## delete a budget period (preparation) - my $dbh = C4::Context->dbh; - ## $total = number of records linked to the record that must be deleted + my $funds = GetBudgets({ budget_period_id => $budget_period_id }); + my $fund_count = scalar @$funds; + if ( $fund_count > 0 ) { + $template->param( funds_exist => 1 ); + } + + #$total = number of records linked to the record that must be deleted my $total = 0; my $data = GetBudgetPeriod( $budget_period_id); - - $$data{'budget_period_total'}=$num->format_price( $data->{'budget_period_total'}); $template->param( - %$data + %$data ); } elsif ( $op eq 'delete_confirmed' ) { -## delete the budget period record - - my $data = GetBudgetPeriod( $budget_period_id); - DelBudgetPeriod($budget_period_id); + ## confirm no funds have been added to budget + my $funds = GetBudgets({ budget_period_id => $budget_period_id }); + my $fund_count = scalar @$funds; + if ( $fund_count > 0 ) { + $template->param( failed_delete_funds_exist => 1 ); + } else { + ## delete the budget period record + my $data = GetBudgetPeriod( $budget_period_id); + DelBudgetPeriod($budget_period_id); + } $op='else'; } # display the form for duplicating elsif ( $op eq 'duplicate_form'){ + my $budgetperiod = GetBudgetPeriod($budget_period_id); $template->param( 'duplicate_form' => '1', 'budget_period_id' => $budget_period_id, + 'budgetperiod' => $budgetperiod, ); } @@ -187,16 +189,22 @@ elsif ( $op eq 'duplicate_form'){ elsif ( $op eq 'duplicate_budget' ){ die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' ); - my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate'); - my $budget_period_enddate = dt_from_string $input->param('budget_period_enddate'); + my $budget_period_startdate = $input->param('budget_period_startdate'); + my $budget_period_enddate = $input->param('budget_period_enddate'); + my $budget_period_description = $input->param('budget_period_description'); + my $amount_change_percentage = $input->param('amount_change_percentage'); + my $amount_change_round_increment = $input->param('amount_change_round_increment'); my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive'); my $reset_all_budgets = $input->param('reset_all_budgets'); - my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod( + my $new_budget_period_id = CloneBudgetPeriod( { budget_period_id => $budget_period_id, budget_period_startdate => $budget_period_startdate, budget_period_enddate => $budget_period_enddate, + budget_period_description => $budget_period_description, + amount_change_percentage => $amount_change_percentage, + amount_change_round_increment => $amount_change_round_increment, mark_original_budget_as_inactive => $mark_original_budget_as_inactive, reset_all_budgets => $reset_all_budgets, } @@ -211,7 +219,7 @@ elsif ( $op eq 'close_form' ) { my $budget_period = GetBudgetPeriod($budget_period_id); my $active_budget_periods = - C4::Budgets::GetBudgetPeriods( { budget_period_active => 1 } ); + GetBudgetPeriods( { budget_period_active => 1 } ); # Remove the budget period from the list $active_budget_periods = @@ -220,14 +228,16 @@ elsif ( $op eq 'close_form' ) { my $budgets_to_move = GetBudgetHierarchy($budget_period_id); - # C4::Context->userenv->{branchcode}, $show_mine ? $borrower_id : '') - my $number_of_unreceived_orders = 0; for my $budget (@$budgets_to_move) { # We want to move funds from this budget my $unreceived_orders = C4::Acquisition::SearchOrders( - { budget_id => $budget->{budget_id}, } ); + { + budget_id => $budget->{budget_id}, + pending => 1, + } + ); $budget->{unreceived_orders} = $unreceived_orders; $number_of_unreceived_orders += scalar(@$unreceived_orders); } @@ -244,13 +254,26 @@ elsif ( $op eq 'close_form' ) { } elsif ( $op eq 'close_confirmed' ) { - my $to_budget_period_id = $input->param('to_budget_period_id'); - my $report = C4::Budgets::MoveOrders( + my $to_budget_period_id = $input->param('to_budget_period_id'); + my $move_remaining_unspent = $input->param('move_remaining_unspent'); + my $report = MoveOrders( { - from_budget_period_id => $budget_period_id, - to_budget_period_id => $to_budget_period_id, + from_budget_period_id => $budget_period_id, + to_budget_period_id => $to_budget_period_id, + move_remaining_unspent => $move_remaining_unspent, } ); + + my $from_budget_period = GetBudgetPeriod($budget_period_id); + my $to_budget_period = GetBudgetPeriod($to_budget_period_id); + $template->param( + closed => 1, + budget_period_id => $from_budget_period->{budget_period_id}, + budget_period_description => $from_budget_period->{budget_period_description}, + from_budget_period => $from_budget_period, + to_budget_period => $to_budget_period, + report => $report, + ); } # DEFAULT - DISPLAY AQPERIODS TABLE @@ -264,19 +287,16 @@ my $results = GetBudgetPeriods( { budget_period_active => 1 }, { -asc => 'budget_period_description' }, ); -my $first = ( $activepage - 1 ) * $activepagesize; -my $last = min( $first + $activepagesize - 1, scalar @{$results} - 1, ); + my @period_active_loop; -foreach my $result ( @{$results}[ $first .. $last ] ) { +foreach my $result ( @{$results} ) { my $budgetperiod = $result; - $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} ); $budgetperiod->{budget_active} = 1; + my $funds = GetBudgets({ budget_period_id => $budgetperiod->{budget_period_id} }); + $budgetperiod->{count} = scalar @$funds; push( @period_active_loop, $budgetperiod ); } -my $url = "aqbudgetperiods.pl"; -$url .= "?ipage=$inactivepage" if($inactivepage != 1); -my $active_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), $activepagesize), $activepage, "apage"); # Get inactive budget periods $results = GetBudgetPeriods( @@ -284,25 +304,19 @@ $results = GetBudgetPeriods( { -desc => 'budget_period_enddate' }, ); -$first = ( $inactivepage - 1 ) * $inactivepagesize; -$last = min( $first + $inactivepagesize - 1, scalar @{$results} - 1, ); my @period_inactive_loop; -foreach my $result ( @{$results}[ $first .. $last ] ) { +foreach my $result ( @{$results} ) { my $budgetperiod = $result; - $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} ); $budgetperiod->{budget_active} = 1; + my $funds = GetBudgets({ budget_period_id => $budgetperiod->{budget_period_id} }); + $budgetperiod->{count} = scalar @$funds; push( @period_inactive_loop, $budgetperiod ); } -$url = "aqbudgetperiods.pl?tab=2"; -$url .= "&apage=$activepage" if($activepage != 1); -my $inactive_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), $inactivepagesize), $inactivepage, "ipage"); my $tab = $input->param('tab') ? $input->param('tab') - 1 : 0; $template->param( period_active_loop => \@period_active_loop, period_inactive_loop => \@period_inactive_loop, - active_pagination_bar => $active_pagination_bar, - inactive_pagination_bar => $inactive_pagination_bar, tab => $tab, );