From 1894ea54b2a105895ce43978201c4553f8f8ec17 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Wed, 3 Jun 2009 14:57:16 +0200 Subject: [PATCH] improvement/bugfix : search budget MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * there can be more than 1 active period. This has been added to deal with temporary budgets (like "10000€ to spent in the next 3 months") * all active budgets are retrieved * budget available for everyone now displayed correctly also : * fixing some hardcoded values * removing a warn --- C4/Budgets.pm | 12 ++++++++---- acqui/acqui-home.pl | 2 +- acqui/neworderempty.pl | 2 +- admin/aqbudgetperiods.pl | 24 ++++++------------------ 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 106a61cafa..a84c2fde6e 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -492,8 +492,13 @@ sub GetBudgetHierarchy { my $query = qq| SELECT * FROM aqbudgets - WHERE budget_period_id = ? |; - push @bind_params, $budget_period_id; + JOIN aqbudgetperiods USING (budget_period_id) + WHERE budget_period_active=1 |; + # show only period X if requested + if ($budget_period_id) { + $query .= "AND aqbudgets.budget_period_id = ?"; + push @bind_params, $budget_period_id; + } # show only budgets owned by me, my branch or everyone if ($owner) { if ($branchcode) { @@ -501,7 +506,7 @@ sub GetBudgetHierarchy { push @bind_params, $owner; push @bind_params, $branchcode; } else { - $query .= ' AND budget_owner_id = ?'; + $query .= ' AND budget_owner_id = ? OR budget_owner_id IS NULL'; push @bind_params, $owner; } } else { @@ -510,7 +515,6 @@ sub GetBudgetHierarchy { push @bind_params, $branchcode; } } - warn "Q : $query"; my $sth = $dbh->prepare($query); $sth->execute(@bind_params); my $results = $sth->fetchall_arrayref({}); diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index f94ecc9d8d..4ebf874624 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -129,7 +129,7 @@ if ( $cur_format eq 'FR' ) { my $period = GetBudgetPeriod; my $budget_period_id = $period->{budget_period_id}; my $budget_branchcode = $period->{budget_branchcode}; -my $moo = GetBudgetHierarchy( $budget_period_id, $homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} ); +my $moo = GetBudgetHierarchy('',$homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} ); my @results = @$moo; my $period_total = 0; my $toggle = 0; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index ddbde36e6a..32b70a598a 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -233,7 +233,7 @@ my $budget = GetBudget($budget_id); # build budget list my %labels; my @values; -my $budgets = GetBudgetHierarchy('1','',$borrower->{'borrowernumber'}); +my $budgets = GetBudgetHierarchy('','',$borrower->{'borrowernumber'}); foreach my $r (@$budgets) { $labels{"$r->{budget_id}"} = $r->{budget_name}; next if sprintf ("%00d", $r->{budget_amount}) == 0; diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 08d3a36445..8a01fad61f 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -155,6 +155,7 @@ elsif ( $op eq 'add_validate' ) { , budget_period_description = ? , budget_period_total = ? , budget_period_locked = ? + , budget_period_active = ? WHERE budget_period_id = ? '; @@ -165,12 +166,10 @@ elsif ( $op eq 'add_validate' ) { $input->param('budget_period_description') ? $input->param('budget_period_description') : undef, $input->param('budget_period_total') ? $input->param('budget_period_total') : undef, $input->param('budget_period_locked') ? $input->param('budget_period_locked') : undef, + $input->param('budget_period_active') ? $input->param('budget_period_active') : undef, $input->param('budget_period_id'), ); - # IF PASSED ACTIVE - THEN SET IT IN DB TOO. - set_active($budget_period_id) if ( $budget_period_active == 1 ); - } else { # ELSE ITS AN ADD my $query = " INSERT INTO aqbudgetperiods ( @@ -179,8 +178,9 @@ elsif ( $op eq 'add_validate' ) { , budget_period_enddate , budget_period_total , budget_period_description - , budget_period_locked ) - VALUES (?,?,?,?,?,? ); + , budget_period_locked + , budget_period_active) + VALUES (?,?,?,?,?,?,? ); "; my $sth = $dbh->prepare($query); $sth->execute( @@ -190,9 +190,9 @@ elsif ( $op eq 'add_validate' ) { $input->param('budget_period_total') ? $input->param('budget_period_total') : undef, $input->param('budget_period_description') ? $input->param('budget_period_description') : undef, $input->param('budget_period_locked') ? $input->param('budget_period_locked') : undef, + $input->param('budget_period_active') ? $input->param('budget_period_active') : undef, ); $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef ); - set_active($budget_period_id) if ( $budget_period_active == 1 ); } print "Content-Type: text/html\n\n"; #YUCK @@ -267,15 +267,3 @@ else { } output_html_with_http_headers $input, $cookie, $template->output; - -sub set_active { - my $sth = $dbh->do( - "UPDATE aqbudgetperiods - SET budget_period_active = 0 " - ); - my $sth = $dbh->do( - "UPDATE aqbudgetperiods - SET budget_period_active = 1 - WHERE budget_period_id = $budget_period_id" - ); -} -- 2.20.1