bugfixing pending reserves
[koha_fer] / circ / transferstodo.pl
index bb2f8e0..1837e33 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -25,7 +24,7 @@ use C4::Output;
 use CGI;
 use C4::Branch; # GetBranches
 use C4::Auth;
-use C4::Date;
+use C4::Dates qw/format_date/;
 use C4::Circulation;
 use C4::Reserves;
 use C4::Members;
@@ -36,6 +35,7 @@ use Date::Calc qw(
 );
 use C4::Koha;
 use C4::Biblio;
+use C4::Items;
 
 my $input = new CGI;
 
@@ -53,19 +53,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 # set the userenv branch
 my $default = C4::Context->userenv->{'branch'};
 
-my @datearr    = localtime( time() );
-my $todaysdate =
-    ( 1900 + $datearr[5] ) . '-'
-  . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
-  . sprintf( "%0.2d", $datearr[3] );
-
 my $item = $input->param('itemnumber');
 my $fbr  = $input->param('fbr');
 my $tbr  = $input->param('tbr');
 
 # If we have a return of the form dotransfer, we launch the subroutine dotransfer
 if ($item) {
-    C4::Circulation::Circ2::dotransfer( $item, $fbr, $tbr );
+    C4::Circulation::Circ2::ModItemTransfer( $item, $fbr, $tbr );
 }
 
 # get the all the branches for reference
@@ -75,17 +69,16 @@ my @branchesloop;
 foreach my $br ( keys %$branches ) {
     my @reservloop;
     my %branchloop;
-    $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
-    $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
     my @getreserves =
       GetReservesToBranch( $branches->{$br}->{'branchcode'} );
     if (@getreserves) {
+        $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
+        $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
         foreach my $num (@getreserves) {
             my %getreserv;
             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
 #             use Data::Dumper;
 #             warn Dumper($gettitle);
-            warn "ITEM : ".$gettitle->{'title'};
             my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
             if ( $gettitle->{'holdingbranch'} eq $default ) {
                 my $getborrower =
@@ -118,7 +111,6 @@ foreach my $br ( keys %$branches ) {
                 $getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
                 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
                 push( @reservloop, \%getreserv );
-                warn "=".$getreserv{'title'}.">>".$gettitle->{'title'};
             }
         }
 
@@ -126,25 +118,18 @@ foreach my $br ( keys %$branches ) {
         if (@reservloop) {
             $branchloop{'reserv'} = \@reservloop;
         }
-
         #              else, we unset the value of the branchcode .
         else {
             $branchloop{'branchcode'} = 0;
         }
     }
-    else {
-
-#      if we don't have a retrun from reservestobranch we unset branchname and branchcode
-        $branchloop{'branchname'} = 0;
-        $branchloop{'branchcode'} = 0;
-    }
-    push( @branchesloop, \%branchloop );
+    push( @branchesloop, \%branchloop ) if %branchloop;
 }
 
 $template->param(
     branchesloop => \@branchesloop,
-    show_date    => format_date($todaysdate)
+    show_date    => format_date(C4::Dates->today('iso')),
+       dateformat    => C4::Context->preference("dateformat"),
 );
 
-print "Content-Type: text/html\n\n", $template->output;
-
+output_html_with_http_headers $input, $cookie, $template->output;