Code Cleaning Members.
[koha_gimpoz] / circ / circulation.pl
index 69a106c..5d1474b 100755 (executable)
 
 use strict;
 use CGI;
-use C4::Circulation::Circ2;
-use C4::Members;
 use C4::Output;
 use C4::Print;
 use C4::Auth;
+use C4::Date;
 use C4::Interface::CGI::Output;
 use C4::Branch; # GetBranches
 use C4::Koha;   # GetPrinter
@@ -40,9 +39,10 @@ use Date::Calc qw(
   Date_to_Days
 );
 
+use C4::Circulation;
+use C4::Members;
 use C4::Biblio;
 use C4::Reserves2;
-use C4::Circulation::Date;
 
 #
 # PARAMETERS READING
@@ -65,7 +65,7 @@ my $printer = GetPrinter($query, $printers);
 
 my $findborrower = $query->param('findborrower');
 $findborrower =~ s|,| |g;
-$findborrower =~ s|'| |g;
+#$findborrower =~ s|'| |g;
 my $borrowernumber = $query->param('borrowernumber');
 
 # new op dev the branch and the printer are now defined by the userenv
@@ -97,16 +97,8 @@ my $print          = $query->param('print');
 #     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
 #     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
 # }
-
-my %env
-  ; # FIXME env is used as an "environment" variable. Could be dropped probably...
-
 #
-$env{'branchcode'}   = $branch;
-$env{'printer'}      = $printer;
-$env{'organisation'} = $organisation;
 
-# $env{'queue'}=$printer;
 
 my @datearr = localtime( time() );
 
@@ -136,7 +128,7 @@ if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
 }
 
 if ( $print eq 'yes' && $borrowernumber ne '' ) {
-    printslip( \%env, $borrowernumber );
+    printslip( $borrowernumber );
     $query->param( 'borrowernumber', '' );
     $borrowernumber = '';
 }
@@ -149,7 +141,7 @@ my $borrowerslist;
 my $message;
 if ($findborrower) {
     my ( $count, $borrowers ) =
-      BornameSearch( \%env, $findborrower, 'cardnumber', 'web' );
+      SearchBorrower($findborrower, 'cardnumber', 'web' );
     my @borrowers = @$borrowers;
     if ( $#borrowers == -1 ) {
         $query->param( 'findborrower', '' );
@@ -170,8 +162,8 @@ my $borrower;
 my @lines;
 
 if ($borrowernumber) {
-    $borrower = getpatroninformation( \%env, $borrowernumber, 0 );
-    my ( $od, $issue, $fines ) = borrdata2( \%env, $borrowernumber );
+    $borrower = GetMemberDetails( $borrowernumber, 0 );
+    my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
 
     # Warningdate is the date that the warning starts appearing
     my ( $today_year,   $today_month,   $today_day )   = Today();
@@ -217,17 +209,17 @@ if ($barcode) {
     $barcode = cuecatbarcodedecode($barcode);
     my ( $datedue, $invalidduedate ) = fixdate( $year, $month, $day );
     if ($issueconfirmed) {
-        issuebook( \%env, $borrower, $barcode, $datedue, $cancelreserve );
+        AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
         $inprocess = 1;
     }
     else {
         my ( $error, $question ) =
-          canbookbeissued( \%env, $borrower, $barcode, $year, $month, $day,
+          CanBookBeIssued( $borrower, $barcode, $year, $month, $day,
             $inprocess );
         my $noerror    = 1;
         my $noquestion = 1;
 #         Get the item title for more information
-    my $getmessageiteminfo  = getiteminformation( undef, $barcode );
+    my $getmessageiteminfo  = GetBiblioFromItemNumber( undef, $barcode );
     
         foreach my $impossible ( keys %$error ) {
             $template->param(
@@ -250,13 +242,13 @@ if ($barcode) {
             year  => $year
         );
         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
-            issuebook( \%env, $borrower, $barcode, $datedue );
+            AddIssue( $borrower, $barcode, $datedue );
             $inprocess = 1;
         }
     }
     
 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
-        my ( $od, $issue, $fines ) = borrdata2( \%env, $borrowernumber );
+        my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
         $template->param(
         issuecount   => $issue,
         );
@@ -264,7 +256,7 @@ if ($barcode) {
 
 # reload the borrower info for the sake of reseting the flags.....
 if ($borrowernumber) {
-    $borrower = getpatroninformation( \%env, $borrowernumber, 0 );
+    $borrower = GetMemberDetails( $borrowernumber, 0 );
 }
 
 ##################################################################################
@@ -281,11 +273,10 @@ if ($borrowernumber) {
     foreach my $num_res (@borrowerreserv) {
         my %getreserv;
         my %getWaitingReserveInfo;
-        my %env;
-        my $getiteminfo  = getiteminformation( $num_res->{'itemnumber'} );
+        my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
         my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
         my ( $transfertwhen, $transfertfrom, $transfertto ) =
-          checktransferts( $num_res->{'itemnumber'} );
+          GetTransfers( $num_res->{'itemnumber'} );
 
         $getreserv{waiting}       = 0;
         $getreserv{transfered}    = 0;
@@ -377,73 +368,69 @@ if ($borrower) {
 # get each issue of the borrower & separate them in todayissues & previous issues
     my @todaysissues;
     my @previousissues;
-    my $issueslist = getissues($borrower);
+    my $issueslist = GetBorrowerIssues($borrower);
 
     # split in 2 arrays for today & previous
     my $dbh = C4::Context->dbh;
-    foreach my $it ( keys %$issueslist ) {
-        my $issuedate = $issueslist->{$it}->{'timestamp'};
+    foreach my $it ( @$issueslist ) {
+        my $issuedate = $it->{'timestamp'};
         $issuedate =~ s/-//g;
         $issuedate = substr( $issuedate, 0, 8 );
 
         # to let perl sort this correctly
-        $issueslist->{$it}->{'timestamp'} =~ s/(-|\:| )//g;
+        $it->{'timestamp'} =~ s/(-|\:| )//g;
 
         if ( $todaysdate == $issuedate ) {
             (
-                $issueslist->{$it}->{'charge'},
-                $issueslist->{$it}->{'itemtype_charge'}
+                $it->{'charge'},
+                $it->{'itemtype_charge'}
               )
-              = calc_charges(
-                $dbh,
-                $issueslist->{$it}->{'itemnumber'},
+              = GetIssuingCharges(
+                $it->{'itemnumber'},
                 $borrower->{'borrowernumber'}
               );
-            $issueslist->{$it}->{'charge'} =
-              sprintf( "%.2f", $issueslist->{$it}->{'charge'} );
+            $it->{'charge'} =
+              sprintf( "%.2f", $it->{'charge'} );
             (
-                $issueslist->{$it}->{'can_renew'},
-                $issueslist->{$it}->{'can_renew_error'}
+                $it->{'can_renew'},
+                $it->{'can_renew_error'}
               )
-              = renewstatus(
-                \%env,
+              = CanBookBeRenewed(
                 $borrower->{'borrowernumber'},
-                $issueslist->{$it}->{'itemnumber'}
+                $it->{'itemnumber'}
               );
             my ( $restype, $reserves ) =
-              CheckReserves( $issueslist->{$it}->{'itemnumber'} );
+              CheckReserves( $it->{'itemnumber'} );
             if ($restype) {
-                $issueslist->{$it}->{'can_renew'} = 0;
+                $it->{'can_renew'} = 0;
             }
-            push @todaysissues, $issueslist->{$it};
+            push @todaysissues, $it;
         }
         else {
             (
-                $issueslist->{$it}->{'charge'},
-                $issueslist->{$it}->{'itemtype_charge'}
+                $it->{'charge'},
+                $it->{'itemtype_charge'}
               )
-              = calc_charges(
-                $dbh,
-                $issueslist->{$it}->{'itemnumber'},
+              = GetIssuingCharges(
+                $it->{'itemnumber'},
                 $borrower->{'borrowernumber'}
               );
-            $issueslist->{$it}->{'charge'} =
-              sprintf( "%.2f", $issueslist->{$it}->{'charge'} );
+            $it->{'charge'} =
+              sprintf( "%.2f", $it->{'charge'} );
             (
-                $issueslist->{$it}->{'can_renew'},
-                $issueslist->{$it}->{'can_renew_error'}
+                $it->{'can_renew'},
+                $it->{'can_renew_error'}
               )
-              = renewstatus(
-                \%env,
+              = CanBookBeRenewed(
                 $borrower->{'borrowernumber'},
-                $issueslist->{$it}->{'itemnumber'}
+                $it->{'itemnumber'}
               );
             my ( $restype, $reserves ) =
-              CheckReserves( $issueslist->{$it}->{'itemnumber'} );
+              CheckReserves( $it->{'itemnumber'} );
             if ($restype) {
-                $issueslist->{$it}->{'can_renew'} = 0;
+                $it->{'can_renew'} = 0;
             }
-            push @previousissues, $issueslist->{$it};
+            push @previousissues, $it;
         }
     }
     my $od;    # overdues
@@ -642,14 +629,15 @@ foreach $flag ( sort keys %$flags ) {
             );
 
             my $items = $flags->{$flag}->{'itemlist'};
-            {
-                my @itemswaiting;
-                foreach my $item (@$items) {
-                    my ($iteminformation) =
-                        getiteminformation( $item->{'itemnumber'}, 0 );
-                    push @itemswaiting, $iteminformation;
-                }
-            }
+# useless ???
+#             {
+#                 my @itemswaiting;
+#                 foreach my $item (@$items) {
+#                     my ($iteminformation) =
+#                         getiteminformation( $item->{'itemnumber'}, 0 );
+#                     push @itemswaiting, $iteminformation;
+#                 }
+#             }
             if ( $query->param('module') ne 'returns' ) {
                 $template->param( nonreturns => 'true' );
             }