Bug 15758: Koha::Libraries - Remove GetBranches
[srvgit] / circ / circulation.pl
index 0562df5..ff32c0c 100755 (executable)
@@ -30,7 +30,6 @@ use DateTime::Duration;
 use C4::Output;
 use C4::Print;
 use C4::Auth qw/:DEFAULT get_session haspermission/;
-use C4::Branch; # GetBranches
 use C4::Koha;   # GetPrinter
 use C4::Circulation;
 use C4::Utils::DataTables::Members;
@@ -44,7 +43,7 @@ use C4::Context;
 use CGI::Session;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
 use Koha::Patron;
-use Koha::Patron::Debarments qw(GetDebarments IsDebarred);
+use Koha::Patron::Debarments qw(GetDebarments);
 use Koha::DateUtils;
 use Koha::Database;
 use Koha::Patron::Messages;
@@ -81,7 +80,7 @@ if (!C4::Context->userenv){
 my $barcodes = [];
 my $barcode =  $query->param('barcode');
 # Barcode given by user could be '0'
-if ( $barcode || $barcode eq '0' ) {
+if ( $barcode || ( defined($barcode) && $barcode eq '0' ) ) {
     $barcodes = [ $barcode ];
 } else {
     my $filefh = $query->upload('uploadfile');
@@ -125,8 +124,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
     }
 );
 
-my $branches = GetBranches();
-
 my $force_allow_issue = $query->param('forceallow') || 0;
 if (!C4::Auth::haspermission( C4::Context->userenv->{id} , { circulate => 'force_checkout' } )) {
     $force_allow_issue = 0;
@@ -164,10 +161,10 @@ for my $barcode ( @$barcodes ) {
 
 my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
-$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }
+$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso', timeformat => '24hr' }); }
     if ( $duedatespec );
-my $restoreduedatespec  = $query->param('restoreduedatespec') || $session->param('stickyduedate') || $duedatespec;
-if ($restoreduedatespec eq "highholds_empty") {
+my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
+if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
     undef $restoreduedatespec;
 }
 my $issueconfirmed = $query->param('issueconfirmed');
@@ -184,7 +181,7 @@ if ( @$barcodes ) {
         $stickyduedate  = $query->param('stickyduedate');
         $duedatespec    = $query->param('duedatespec');
     }
-    $session->param('auto_renew', $query->param('auto_renew'));
+    $session->param('auto_renew', scalar $query->param('auto_renew'));
 }
 else {
     $session->clear('auto_renew');
@@ -299,7 +296,8 @@ if ($borrowernumber) {
         finetotal    => $fines
     );
 
-    if ( IsDebarred($borrowernumber) ) {
+    my $patron = Koha::Patrons->find( $borrowernumber );
+    if ( $patron and $patron->is_debarred ) {
         $template->param(
             'userdebarred'    => $borrower->{debarred},
             'debarredcomment' => $borrower->{debarredcomment},
@@ -407,7 +405,7 @@ if (@$barcodes) {
         }
         unless($confirm_required) {
             my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
-            $template->param( issue => $issue );
+            $template_params->{issue} = $issue;
             $session->clear('auto_renew');
             $inprocess = 1;
         }
@@ -557,10 +555,9 @@ $amountold =~ s/^.*\$//;    # remove upto the $, if any
 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
 
 if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
-    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
-    my $cnt = scalar(@$catcodes);
-    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
-    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
+    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
+    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
+    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
 }
 
 my $librarian_messages = Koha::Patron::Messages->search(
@@ -626,12 +623,10 @@ if ($restoreduedatespec || $stickyduedate) {
 $template->param(
     librarian_messages => $librarian_messages,
     patron_messages   => $patron_messages,
-    findborrower      => $findborrower,
     borrower          => $borrower,
     borrowernumber    => $borrowernumber,
     categoryname      => $borrower->{'description'},
     branch            => $branch,
-    branchname        => GetBranchName($borrower->{'branchcode'}),
     was_renewed       => scalar $query->param('was_renewed') ? 1 : 0,
     expiry            => $borrower->{'dateexpiry'},
     roadtype          => $roadtype,
@@ -646,6 +641,7 @@ $template->param(
     is_child          => ($borrowernumber && $borrower->{'category_type'} eq 'C'),
     $view             => 1,
     batch_allowed     => $batch_allowed,
+    batch             => $batch,
     AudioAlerts           => C4::Context->preference("AudioAlerts"),
     fast_cataloging   => $fast_cataloging,
     CircAutoPrintQuickSlip   => C4::Context->preference("CircAutoPrintQuickSlip"),
@@ -660,19 +656,16 @@ $template->param(
 my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
 $template->param( picture => 1 ) if $patron_image;
 
-# get authorised values with type of BOR_NOTES
-
-my $canned_notes = GetAuthorisedValues("BOR_NOTES");
-
+my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
 $template->param(
     debt_confirmed            => $debt_confirmed,
     SpecifyDueDate            => $duedatespec_allow,
     CircAutocompl             => C4::Context->preference("CircAutocompl"),
-    canned_bor_notes_loop     => $canned_notes,
     debarments                => GetDebarments({ borrowernumber => $borrowernumber }),
     todaysdate                => output_pref( { dt => dt_from_string()->set(hour => 23)->set(minute => 59), dateformat => 'sql' } ),
-    modifications             => Koha::Patron::Modifications->GetModifications({ borrowernumber => $borrowernumber }),
+    has_modifications         => $has_modifications,
     override_high_holds       => $override_high_holds,
+    nopermission              => scalar $query->param('nopermission'),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;