Bug 14882: Librarians are not warned if patron owe more than maxoutstanding when...
[koha.git] / reserve / request.pl
index 7d9c5e6..fefe4b0 100755 (executable)
@@ -7,18 +7,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 request.pl
 
@@ -39,7 +39,7 @@ use C4::Biblio;
 use C4::Items;
 use C4::Koha;
 use C4::Circulation;
-use C4::Dates qw/format_date/;
+use Koha::DateUtils;
 use C4::Utils::DataTables::Members;
 use C4::Members;
 use C4::Search;                # enabled_staff_search_views
@@ -82,7 +82,7 @@ my $maxreserves;
 my $warnings;
 my $messages;
 
-my $date = C4::Dates->today('iso');
+my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
 my $action = $input->param('action');
 $action ||= q{};
 
@@ -116,7 +116,7 @@ if ($findborrower) {
         );
         my $borrowers = $results->{patrons};
         if ( scalar @$borrowers == 1 ) {
-            $borrowernumber_hold = $borrower->[0]->{borrowernumber};
+            $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
         } elsif ( @$borrowers ) {
             $template->param( borrowers => $borrowers );
         } else {
@@ -175,7 +175,8 @@ if ($borrowernumber_hold && !$action) {
                 expiry              => $expiry,
                 diffbranch          => $diffbranch,
                 messages            => $messages,
-                warnings            => $warnings
+                warnings            => $warnings,
+                amount_outstanding  => GetMemberAccountRecords($borrowerinfo->{borrowernumber}),
     );
 }
 
@@ -201,6 +202,7 @@ foreach my $biblionumber (@biblionumbers) {
     my $dat = GetBiblioData($biblionumber);
 
     my $canReserve = CanBookBeReserved( $borrowerinfo->{borrowernumber}, $biblionumber );
+    $canReserve //= '';
     if ( $canReserve eq 'OK' ) {
 
         #All is OK and we can continue
@@ -347,7 +349,7 @@ foreach my $biblionumber (@biblionumbers) {
             # change the background color
             my $issues= GetItemIssue($itemnumber);
             if ( $issues->{'date_due'} ) {
-                $item->{date_due} = format_sqldatetime($issues->{date_due});
+                $item->{date_due} = $issues->{date_due_sql};
                 $item->{backgroundcolor} = 'onloan';
             }
 
@@ -357,7 +359,7 @@ foreach my $biblionumber (@biblionumbers) {
                 my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
 
                 $item->{backgroundcolor} = 'reserved';
-                $item->{reservedate}     = format_date($reservedate);
+                $item->{reservedate}     = output_pref({ dt => dt_from_string( $reservedate ), dateonly => 1 });
                 $item->{ReservedForBorrowernumber}     = $reservedfor;
                 $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
                 $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
@@ -392,7 +394,7 @@ foreach my $biblionumber (@biblionumbers) {
               GetTransfers($itemnumber);
 
             if ( defined $transfertwhen && $transfertwhen ne '' ) {
-                $item->{transfertwhen} = format_date($transfertwhen);
+                $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
                 $item->{transfertfrom} =
                   $branches->{$transfertfrom}{branchname};
                 $item->{transfertto} = $branches->{$transfertto}{branchname};
@@ -417,19 +419,11 @@ foreach my $biblionumber (@biblionumbers) {
             my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
 
             my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
-            my $policy_holdallowed = 1;
 
             $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
 
-            if ( $branchitemrule->{'holdallowed'} == 0 ||
-                 ( $branchitemrule->{'holdallowed'} == 1 &&
-                     $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
-                $policy_holdallowed = 0;
-            }
-            
             if (
-                   $policy_holdallowed
-                && !$item->{cantreserve}
+                   !$item->{cantreserve}
                 && IsAvailableForItemLevelRequest($item, $borrowerinfo)
                 && CanItemBeReserved(
                     $borrowerinfo->{borrowernumber}, $itemnumber
@@ -523,9 +517,9 @@ foreach my $biblionumber (@biblionumbers) {
            $reserve{'hidename'} = 1;
            $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
        }
-        $reserve{'expirationdate'} = format_date( $res->{'expirationdate'} )
+        $reserve{'expirationdate'} = output_pref({ dt => dt_from_string( $res->{'expirationdate'} ), dateonly => 1 })
             unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' );
-        $reserve{'date'}           = format_date( $res->{'reservedate'} );
+        $reserve{'date'}           = output_pref({ dt => dt_from_string( $res->{'reservedate'} ), dateonly => 1 });
         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
         $reserve{'biblionumber'}   = $res->{'biblionumber'};
         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
@@ -534,8 +528,6 @@ foreach my $biblionumber (@biblionumbers) {
         $reserve{'notes'}          = $res->{'reservenotes'};
         $reserve{'wait'}           =
           ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
-        $reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
-        $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
         $reserve{'voldesc'}         = $res->{'volumeddesc'};
         $reserve{'ccode'}           = $res->{'ccode'};
         $reserve{'barcode'}         = $res->{'barcode'};