X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Faqbudget.pl;h=33edc1cd760755cdfa9aa3451a9c91ce87cb19bf;hb=697f775c08e6a61527a4ed9afe55eed71909acca;hp=d8bfdd97f6c29366435ef6d2dea1e3a3103c44a4;hpb=3bec20f948c71dc71017747ee32ce43ec9564623;p=koha.git diff --git a/admin/aqbudget.pl b/admin/aqbudget.pl index d8bfdd97f6..33edc1cd76 100755 --- a/admin/aqbudget.pl +++ b/admin/aqbudget.pl @@ -38,25 +38,24 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +# use warnings; FIXME use CGI; -use HTML::Template; +use C4::Branch; # GetBranches use List::Util qw/min/; - -use C4::Date; +use C4::Dates qw/format_date format_date_in_iso/; use C4::Auth; use C4::Acquisition; use C4::Context; use C4::Output; -use C4::Interface::CGI::Output; -use C4::Search; use C4::Koha; my $input = new CGI; my $script_name="/cgi-bin/koha/admin/aqbudget.pl"; -my $bookfundid=$input->param('bookfundid'); -my $aqbudgetid=$input->param('aqbudgetid'); +my $bookfundid = $input->param('bookfundid'); +my $aqbudgetid = $input->param('aqbudgetid'); +my $branchcodeid = $input->param('branchcode'); +my $op = $input->param('op') || ''; my $pagesize = 20; -my $op = $input->param('op'); my ($template, $borrowernumber, $cookie) = get_template_and_user( @@ -71,7 +70,7 @@ my ($template, $borrowernumber, $cookie) $template->param( action => $script_name, - DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(), + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), script_name => $script_name, $op || 'else' => 1, ); @@ -85,8 +84,6 @@ my ($flags, $homebranch)=$sthtemp->fetchrow; # called by default. Used to create form to add or modify a record if ($op eq 'add_form') { my ($query, $dataaqbudget, $dataaqbookfund, $sth); - my $dbh = C4::Context->dbh; - #---- if primkey exists, it's a modify action, so read values to modify... if ($aqbudgetid) { $query = ' @@ -98,13 +95,14 @@ SELECT aqbudgetid, budgetamount, aqbudget.branchcode FROM aqbudget - INNER JOIN aqbookfund ON aqbudget.bookfundid = aqbookfund.bookfundid - WHERE aqbudgetid = ? + INNER JOIN aqbookfund ON (aqbudget.bookfundid = aqbookfund.bookfundid) + WHERE aqbudgetid = ? AND + (aqbookfund.branchcode = aqbudget.branchcode OR + (aqbudget.branchcode IS NULL and aqbookfund.branchcode="")) '; $sth=$dbh->prepare($query); $sth->execute($aqbudgetid); $dataaqbudget=$sth->fetchrow_hashref; - $sth->finish; } $query = ' @@ -113,24 +111,26 @@ SELECT aqbookfund.branchcode, aqbookfund.bookfundname FROM aqbookfund LEFT JOIN branches ON aqbookfund.branchcode = branches.branchcode - WHERE bookfundid = ? + WHERE bookfundid = ? AND aqbookfund.branchcode=? '; $sth=$dbh->prepare($query); $sth->execute( defined $aqbudgetid ? $dataaqbudget->{bookfundid} : $bookfundid, + $branchcodeid ); $dataaqbookfund=$sth->fetchrow_hashref; - $sth->finish; if (defined $aqbudgetid) { $template->param( bookfundid => $dataaqbudget->{'bookfundid'}, + branchcode => $dataaqbudget->{'branchcode'}, bookfundname => $dataaqbudget->{'bookfundname'} ); } else { $template->param( bookfundid => $bookfundid, + branchcode => $dataaqbookfund->{'branchcode'}, bookfundname => $dataaqbookfund->{bookfundname}, ); } @@ -157,21 +157,19 @@ SELECT branchcode, $branch->{selected} = $dataaqbudget->{branchcode} eq $row->{branchcode} ? 1 : 0; } - push @branches, $branch; } - $sth->finish; $template->param( - dateformat => display_date_format(), + dateformat => C4::Dates->new()->visual(), aqbudgetid => $dataaqbudget->{'aqbudgetid'}, startdate => format_date($dataaqbudget->{'startdate'}), - enddate => format_date($dataaqbudget->{'enddate'}), + enddate => format_date($dataaqbudget->{'enddate'}), budgetamount => $dataaqbudget->{'budgetamount'}, branches => \@branches, ); - if (defined $dataaqbookfund->{branchcode}) { + if ( $dataaqbookfund->{branchcode}) { $template->param( disable_branchselection => 1, branch => $dataaqbookfund->{branchcode}, @@ -199,10 +197,9 @@ UPDATE aqbudget format_date_in_iso($input->param('startdate')), format_date_in_iso($input->param('enddate')), $input->param('budgetamount'), - $input->param('branch') || undef, + $input->param('branch') || '', $aqbudgetid, ); - $sth->finish; } else { $query = ' @@ -218,38 +215,33 @@ INSERT format_date_in_iso($input->param('startdate')), format_date_in_iso($input->param('enddate')), $input->param('budgetamount'), - $input->param('branch') || undef, + $input->param('branch') || '', ); - $sth->finish; } - $input->redirect("aqbudget.pl"); - + print $input->redirect("aqbudget.pl"); # FIXME: unnecessary redirect + exit; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { - my $dbh = C4::Context->dbh; my $sth=$dbh->prepare("select aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget where aqbudgetid=?"); $sth->execute($aqbudgetid); my $data=$sth->fetchrow_hashref; - $sth->finish; $template->param(bookfundid => $bookfundid); $template->param(aqbudgetid => $data->{'aqbudgetid'}); - $template->param(startdate => format_date($data->{'startdate'})); - $template->param(enddate => format_date($data->{'enddate'})); + $template->param(startdate => format_date($data->{'startdate'})); + $template->param(enddate => format_date($data->{'enddate'})); $template->param(budgetamount => $data->{'budgetamount'}); # END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ($op eq 'delete_confirmed') { - my $dbh = C4::Context->dbh; my $aqbudgetid=uc($input->param('aqbudgetid')); my $sth=$dbh->prepare("delete from aqbudget where aqbudgetid=?"); $sth->execute($aqbudgetid); - $sth->finish; - print $input->redirect("aqbookfund.pl"); - return; + print $input->redirect("aqbookfund.pl"); + exit; # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT @@ -267,10 +259,9 @@ SELECT bookfundid, bookfundname while (my $row = $sth->fetchrow_hashref) { $bookfundname_of{ $row->{bookfundid} } = $row->{bookfundname}; } - $sth->finish; # filters - my $branches = getbranches(); + my $branches = GetBranches(); my @branchloop; foreach my $branchcode (sort keys %{$branches}) { my $row = { @@ -282,7 +273,6 @@ SELECT bookfundid, bookfundname and $input->param('filter_branchcode') eq $branchcode) { $row->{selected} = 1; } - push @branchloop, $row; } @@ -298,10 +288,8 @@ SELECT bookfundid and $input->param('filter_bookfundid') eq $row->{bookfundid}) { $row->{selected} = 1; } - push @bookfundids_loop, $row; } - $sth->finish; $template->param( filter_bookfundids => \@bookfundids_loop, @@ -386,7 +374,6 @@ SELECT aqbudgetid, while (my $row = $sth->fetchrow_hashref){ push @results, $row; } - $sth->finish; # filter budgets depending on the pagination my $page = $input->param('page') || 1; @@ -399,20 +386,15 @@ SELECT aqbudgetid, scalar @results - 1, ); - my $toggle = 0; my @loop; foreach my $result (@results[$first .. $last]) { - push( - @loop, - { - %{$result}, - toggle => $toggle++%2, - bookfundname => $bookfundname_of{ $result->{'bookfundid'} }, - branchname => $branches->{ $result->{branchcode} }->{branchname}, - startdate => format_date($result->{startdate}), - enddate => format_date($result->{enddate}), - } - ); + push @loop, { + %{$result}, + bookfundname => $bookfundname_of{ $result->{'bookfundid'} }, + branchname => $branches->{ $result->{branchcode} }->{branchname}, + startdate => format_date($result->{startdate}), + enddate => format_date($result->{enddate}), + }; } $template->param( @@ -425,6 +407,5 @@ SELECT aqbudgetid, ) ); } #---- END $OP eq DEFAULT - output_html_with_http_headers $input, $cookie, $template->output;