# 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(
$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,
);
# 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 = '
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 = '
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},
);
}
$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},
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 = '
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
while (my $row = $sth->fetchrow_hashref) {
$bookfundname_of{ $row->{bookfundid} } = $row->{bookfundname};
}
- $sth->finish;
# filters
my $branches = GetBranches();
and $input->param('filter_branchcode') eq $branchcode) {
$row->{selected} = 1;
}
-
push @branchloop, $row;
}
and $input->param('filter_bookfundid') eq $row->{bookfundid}) {
$row->{selected} = 1;
}
-
push @bookfundids_loop, $row;
}
- $sth->finish;
$template->param(
filter_bookfundids => \@bookfundids_loop,
while (my $row = $sth->fetchrow_hashref){
push @results, $row;
}
- $sth->finish;
# filter budgets depending on the pagination
my $page = $input->param('page') || 1;
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(
)
);
} #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
- intranetstylesheet => C4::Context->preference("intranetstylesheet"),
- IntranetNav => C4::Context->preference("IntranetNav"),
- );
output_html_with_http_headers $input, $cookie, $template->output;