Allow Library select on new bookfund and term update.
[koha_gimpoz] / admin / aqbudget.pl
index 6a6fa0f..cafbc0b 100755 (executable)
 
 use strict;
 use CGI;
+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::Interface::CGI::Output;
-use C4::Search;
-use C4::Koha;
 use C4::Output;
+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 $pagesize = 20;
 my $op = $input->param('op');
 
@@ -69,7 +69,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,
 );
@@ -96,7 +96,8 @@ SELECT aqbudgetid,
        budgetamount,
        aqbudget.branchcode
   FROM aqbudget
-    INNER JOIN aqbookfund ON aqbudget.bookfundid = aqbookfund.bookfundid
+    INNER JOIN aqbookfund ON (aqbudget.bookfundid = aqbookfund.bookfundid AND
+      aqbudget.branchcode = aqbookfund.branchcode)
   WHERE aqbudgetid = ?
 ';
         $sth=$dbh->prepare($query);
@@ -111,11 +112,12 @@ 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;
@@ -123,12 +125,14 @@ SELECT aqbookfund.branchcode,
     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},
         );
     }
@@ -161,15 +165,15 @@ SELECT branchcode,
     $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},
@@ -197,7 +201,7 @@ 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;
@@ -216,7 +220,7 @@ 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;
     }
@@ -336,7 +340,7 @@ SELECT aqbudgetid,
        budgetamount,
        branchcode
   FROM aqbudget
-  WHERE 1 = 1';
+  WHERE 1 = 1';                        # What's the point?
 
     my @bindings;
 
@@ -423,9 +427,5 @@ SELECT aqbudgetid,
         )
     );
 } #---- 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;