From 494df5d41223a9bcde3b0ddb060ae072e35c835c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 26 Aug 2015 11:45:37 -0400 Subject: [PATCH] Bug 14733 - Tidy AddReserve --- C4/Reserves.pm | 95 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 43 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 75d9ffc..529f1aa 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -152,25 +152,30 @@ BEGIN { sub AddReserve { my ( - $branch, $borrowernumber, $biblionumber, - $bibitems, $priority, $resdate, $expdate, $notes, - $title, $checkitem, $found + $branch, $borrowernumber, $biblionumber, $bibitems, $priority, $resdate, + $expdate, $notes, $title, $checkitem, $found ) = @_; - my $fee = - GetReserveFee($borrowernumber, $biblionumber, - $bibitems ); - my $dbh = C4::Context->dbh; - $resdate = format_date_in_iso( $resdate ) if ( $resdate ); - $resdate = C4::Dates->today( 'iso' ) unless ( $resdate ); + + my $fee = GetReserveFee( $borrowernumber, $biblionumber, $bibitems ); + + my $dbh = C4::Context->dbh; + + $resdate = format_date_in_iso($resdate) if ($resdate); + $resdate = C4::Dates->today('iso') unless ($resdate); + if ($expdate) { - $expdate = format_date_in_iso( $expdate ); - } else { - undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00' + $expdate = format_date_in_iso($expdate); } - if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) { - # Make room in reserves for this before those of a later reserve date - $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority ); + else { + undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00' } + + if ( C4::Context->preference('AllowHoldDateInFuture') ) { + + # Make room in reserves for this before those of a later reserve date + $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority ); + } + my $waitingdate; # If the reserv had the waiting status, we had the value of the resdate @@ -181,16 +186,15 @@ sub AddReserve { #eval { # updates take place here if ( $fee > 0 ) { - my $nextacctno = &getnextacctno( $borrowernumber ); + my $nextacctno = &getnextacctno($borrowernumber); my $query = qq{ - INSERT INTO accountlines - (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) - VALUES - (?,?,now(),?,?,'Res',?) - }; + INSERT INTO accountlines + (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) + VALUES + (?,?,now(),?,?,'Res',?) + }; my $usth = $dbh->prepare($query); - $usth->execute( $borrowernumber, $nextacctno, $fee, - "Reserve Charge - $title", $fee ); + $usth->execute( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ); } my $query = qq{ @@ -200,7 +204,7 @@ sub AddReserve { VALUES (?,?,?,?,?, ?,?,?,?,?) - }; + }; my $sth = $dbh->prepare($query); $sth->execute( $borrowernumber, $biblionumber, $resdate, $branch, $priority, @@ -208,32 +212,37 @@ sub AddReserve { ); my $reserve_id = $sth->{mysql_insertid}; - _FixPriority({ biblionumber => $biblionumber}); + _FixPriority( { biblionumber => $biblionumber } ); # Send e-mail to librarian if syspref is active - if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){ - my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); - my $branch_details = C4::Branch::GetBranchDetail($borrower->{branchcode}); - if ( my $letter = C4::Letters::GetPreparedLetter ( - module => 'reserves', - letter_code => 'HOLDPLACED', - branchcode => $branch, - tables => { - 'branches' => $branch_details, - 'borrowers' => $borrower, - 'biblio' => $biblionumber, - 'items' => $checkitem, - }, - ) ) { - - my $admin_email_address =$branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress'); + if ( C4::Context->preference("emailLibrarianWhenHoldIsPlaced") ) { + my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); + my $branch_details = C4::Branch::GetBranchDetail( $borrower->{branchcode} ); + + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'reserves', + letter_code => 'HOLDPLACED', + branchcode => $branch, + tables => { + 'branches' => $branch_details, + 'borrowers' => $borrower, + 'biblio' => $biblionumber, + 'items' => $checkitem, + }, + ) + ) + { + my $admin_email_address = + $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress'); C4::Letters::EnqueueLetter( - { letter => $letter, + { + letter => $letter, borrowernumber => $borrowernumber, message_transport_type => 'email', from_address => $admin_email_address, - to_address => $admin_email_address, + to_address => $admin_email_address, } ); } -- 1.7.2.5