X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Faqbudgetperiods.pl;h=0a05a5539bfaeb1fba8df5e2c7ce9964c51f66ea;hb=7211fd22bad5b3a3939cca6fe766ee65a7c62b13;hp=653f9161b1f5077beeb4be815d5b4885ab0c3b5a;hpb=1538e9ecf47642c4974693ff499c3e95e4d71977;p=koha.git diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 653f9161b1..0a05a5539b 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -71,12 +71,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} = dt_from_string( scalar $input->param('budget_period_startdate') ); +$budget_period_hashref->{budget_period_enddate} = dt_from_string( scalar $input->param('budget_period_enddate') ); -my $activepagesize = 20; -my $inactivepagesize = 20; $searchfield =~ s/\,//g; my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( @@ -93,9 +91,11 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user( # This is used in incbudgets-active-currency.inc my $active_currency = Koha::Acquisition::Currencies->get_active; -$template->param( symbol => $active_currency->symbol, - currency => $active_currency->currency - ); +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' ) { @@ -129,21 +129,31 @@ elsif ( $op eq 'add_validate' ) { #-------------------------------------------------- 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); - $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'; } @@ -161,8 +171,8 @@ 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 = dt_from_string scalar $input->param('budget_period_startdate'); + my $budget_period_enddate = dt_from_string scalar $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'); @@ -200,8 +210,6 @@ 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) { @@ -261,18 +269,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_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( @@ -280,28 +286,20 @@ $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_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 $branchloop = C4::Branch::GetBranchesLoop(); 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, - branchloop => $branchloop, ); $template->param($op=>1);