Bug 31963: Only show hold fee msg on OPAC if patron will be charged
[koha-ffzg.git] / C4 / Reserves.pm
index 90d4e56..d96d6ce 100644 (file)
@@ -39,12 +39,11 @@ use Koha::Calendar;
 use Koha::CirculationRules;
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string output_pref );
-use Koha::Hold;
 use Koha::Holds;
 use Koha::ItemTypes;
 use Koha::Items;
 use Koha::Libraries;
-use Koha::Old::Hold;
+use Koha::Old::Holds;
 use Koha::Patrons;
 use Koha::Plugins;
 
@@ -194,10 +193,7 @@ sub AddReserve {
     my $itemtype       = $params->{itemtype};
     my $non_priority   = $params->{non_priority};
 
-    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
-        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
-
-    $patron_expiration_date = output_pref({ str => $patron_expiration_date, dateonly => 1, dateformat => 'iso' });
+    $resdate ||= dt_from_string;
 
     # if we have an item selectionned, and the pickup branch is the same as the holdingbranch
     # of the document, we force the value $priority and $found .
@@ -777,10 +773,13 @@ SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?
         my ( $notissued, $reserved );
         ( $notissued ) = $dbh->selectrow_array( $issue_qry, undef,
             ( $biblionumber ) );
-        if( $notissued ) {
+        if( $notissued == 0 ) {
+            # all items are issued
             ( $reserved ) = $dbh->selectrow_array( $holds_qry, undef,
                 ( $biblionumber, $borrowernumber ) );
             $fee = 0 if $reserved == 0;
+        } else {
+            $fee = 0;
         }
     }
     return $fee;
@@ -1124,7 +1123,7 @@ sub ModReserve {
             if C4::Context->preference('HoldsLog');
 
         # The only column that can be updated for a found hold is the expiration date
-        $hold->expirationdate(dt_from_string($date))->store();
+        $hold->expirationdate($date)->store();
     }
     elsif ($rank =~ /^\d+/ and $rank > 0) {
         logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
@@ -1148,7 +1147,6 @@ sub ModReserve {
 
         if ( defined( $suspend_until ) ) {
             if ( $suspend_until ) {
-                $suspend_until = eval { dt_from_string( $suspend_until ) };
                 $hold->suspend_hold( $suspend_until );
             } else {
                 # If the hold is suspended leave the hold suspended, but convert it to an indefinite hold.
@@ -1523,8 +1521,6 @@ be cleared when it is unsuspended.
 sub ToggleSuspend {
     my ( $reserve_id, $suspend_until ) = @_;
 
-    $suspend_until = dt_from_string($suspend_until) if ($suspend_until);
-
     my $hold = Koha::Holds->find( $reserve_id );
 
     if ( $hold->is_suspended ) {
@@ -1558,9 +1554,6 @@ sub SuspendAll {
     my $suspend_until  = $params{'suspend_until'}  || undef;
     my $suspend = defined( $params{'suspend'} ) ? $params{'suspend'} : 1;
 
-    $suspend_until = eval { dt_from_string($suspend_until) }
-      if ( defined($suspend_until) );
-
     return unless ( $borrowernumber || $biblionumber );
 
     my $params;
@@ -1875,7 +1868,6 @@ The following tables are availalbe witin the notice:
 
 sub _koha_notify_reserve {
     my $reserve_id = shift;
-    my $notify_library = shift;
 
     my $hold = Koha::Holds->find($reserve_id);
     my $borrowernumber = $hold->borrowernumber;
@@ -1891,15 +1883,14 @@ sub _koha_notify_reserve {
     } );
 
     my $library = Koha::Libraries->find( $hold->branchcode );
-    my $admin_email_address = $library->from_email_address;
-    $library = $library->unblessed;
+    my $inbound_email_address = $library->inbound_email_address;
 
     my %letter_params = (
         module => 'reserves',
         branchcode => $hold->branchcode,
         lang => $patron->lang,
         tables => {
-            'branches'       => $library,
+            'branches'       => $library->unblessed,
             'borrowers'      => $patron->unblessed,
             'biblio'         => $hold->biblionumber,
             'biblioitems'    => $hold->biblionumber,
@@ -1923,7 +1914,7 @@ sub _koha_notify_reserve {
         C4::Letters::EnqueueLetter( {
             letter => $letter,
             borrowernumber => $borrowernumber,
-            from_address => $admin_email_address,
+            from_address => $inbound_email_address,
             message_transport_type => $mtt,
         } );
     };
@@ -1944,37 +1935,6 @@ sub _koha_notify_reserve {
         &$send_notification('print', 'HOLD');
     }
 
-    if ($notify_library) {
-        my $letter = C4::Letters::GetPreparedLetter(
-            module      => 'reserves',
-            letter_code => 'HOLD_CHANGED',
-            branchcode  => $hold->branchcode,
-            substitute  => { today => output_pref( dt_from_string ) },
-            tables      => {
-                'branches'    => $library,
-                'borrowers'   => $patron->unblessed,
-                'biblio'      => $hold->biblionumber,
-                'biblioitems' => $hold->biblionumber,
-                'reserves'    => $hold->unblessed,
-                'items'       => $hold->itemnumber,
-            },
-        );
-
-        my $email =
-             C4::Context->preference('ExpireReservesAutoFillEmail')
-          || $library->{branchemail}
-          || C4::Context->preference('KohaAdminEmailAddress');
-
-        C4::Letters::EnqueueLetter(
-            {
-                letter                 => $letter,
-                borrowernumber         => $borrowernumber,
-                message_transport_type => 'email',
-                from_address           => $email,
-                to_address             => $email,
-            }
-        );
-    }
 }
 
 =head2 _koha_notify_hold_changed
@@ -2008,8 +1968,7 @@ sub _koha_notify_hold_changed {
 
     my $email =
          C4::Context->preference('ExpireReservesAutoFillEmail')
-      || $library->branchemail
-      || C4::Context->preference('KohaAdminEmailAddress');
+      || $library->inbound_email_address;
 
     C4::Letters::EnqueueLetter(
         {