From 096881e2e2dc0092b336a2f9720e78e569e87fdd Mon Sep 17 00:00:00 2001 From: Matthias Le Gac Date: Tue, 2 Apr 2024 16:26:17 -0400 Subject: [PATCH] Bug 9762: Change how to pass the param --- C4/Circulation.pm | 143 +++++++++++++++++++++++++++++++++++++++++++- circ/circulation.pl | 1 + 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 80cead8a96..e99ed6f14d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -779,6 +779,7 @@ sub CanBookBeIssued { my $onsite_checkout = $params->{onsite_checkout} || 0; my $override_high_holds = $params->{override_high_holds} || 0; + my $issueconfirmed = $params->{issueconfirmed} || 0; my $item_object = !$barcode ? undef : $params->{item} // Koha::Items->find( { barcode => $barcode } ); @@ -801,9 +802,21 @@ sub CanBookBeIssued { my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_object, $patron) ); my $now = dt_from_string(); + my $message; + my @message_log; + $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron ); if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now $needsconfirmation{INVALID_DATE} = $duedate; + if ($issueconfirmed) { + if ($message) { + $message = "$message + sticky due date is invalid or due date in the past"; + } else { + $message = "sticky due date is invalid or due date in the past"; + } + push( @message_log, "sticky due date is invalid or due date in the past" ); + } + } my $fees = Koha::Charges::Fees->new( @@ -848,6 +861,14 @@ sub CanBookBeIssued { } if ( $patron->is_debarred ) { $issuingimpossible{DEBARRED} = 1; + if ($issueconfirmed) { + if ($message) { + $message = "$message + borrower is restricted"; + } else { + $message = "borrower is restricted"; + } + push( @message_log, "borrower is restricted" ); + } } if ( $patron->is_expired ) { @@ -920,10 +941,26 @@ sub CanBookBeIssued { } else { if ( $patron_borrowing_status->{noissuescharge}->{overlimit} && $allowfineoverride ) { $needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + borrower had amend"; + } else { + $message = "borrower had amend"; + } + push( @message_log, "borrower had amend" ); + } } elsif ( $patron_borrowing_status->{noissuescharge}->{overlimit} && !$allowfineoverride ) { $issuingimpossible{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge}; } elsif ( $patron_borrowing_status->{noissuescharge}->{charge} > 0 && $allfinesneedoverride ) { $needsconfirmation{DEBT} = $patron_borrowing_status->{noissuescharge}->{charge}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + borrower had amend"; + } else { + $message = "borrower had amend"; + } + push( @message_log, "borrower had amend" ); + } } } @@ -1008,6 +1045,14 @@ sub CanBookBeIssued { $needsconfirmation{issued_surname} = $patron->surname; $needsconfirmation{issued_cardnumber} = $patron->cardnumber; $needsconfirmation{issued_borrowernumber} = $patron->borrowernumber; + if ($issueconfirmed) { + if ($message) { + $message = "$message + item is checked out for someone else "; + } else { + $message = "item is checked out for someone else"; + } + push( @message_log, "item is checked out for someone else" ); + } } } } @@ -1031,6 +1076,14 @@ sub CanBookBeIssued { $needsconfirmation{current_loan_count} = $toomany->{count}; $needsconfirmation{max_loans_allowed} = $toomany->{max_allowed}; $needsconfirmation{circulation_rule_TOO_MANY} = $toomany->{circulation_rule}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + too many checkout"; + } else { + $message = "too many checkout"; + } + push( @message_log, "too many checkout" ); + } } else { $issuingimpossible{TOO_MANY} = $toomany->{reason}; $issuingimpossible{current_loan_count} = $toomany->{count}; @@ -1058,6 +1111,14 @@ sub CanBookBeIssued { }else{ $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1; $needsconfirmation{item_notforloan} = $item_object->notforloan; + if ($issueconfirmed) { + if ($message) { + $message = "$message + item not for loan"; + } else { + $message = "item not for loan"; + } + push( @message_log, "item not for loan" ); + } } } else { @@ -1104,6 +1165,14 @@ sub CanBookBeIssued { my $code = $av->count ? $av->next->lib : ''; $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' ); $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' ); + if ($issueconfirmed) { + if ($message) { + $message = "$message + item lost"; + } else { + $message = "item lost"; + } + push( @message_log, "item lost" ); + } } if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; @@ -1200,6 +1269,18 @@ sub CanBookBeIssued { $needsconfirmation{'resbranchcode'} = $res->{branchcode}; $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'}; $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + if ($issueconfirmed) { + if ($message) { + $message = + "$message + item is on reserve and waiting, but has been reserved by some other patron."; + } else { + $message = "item is on reserve and waiting, but has been reserved by some other patron."; + } + push( + @message_log, + "item is on reserve and waiting, but has been reserved by some other patron" + ); + } } elsif ( $restype eq "Reserved" ) { # The item is on reserve for someone else. @@ -1211,6 +1292,14 @@ sub CanBookBeIssued { $needsconfirmation{'resbranchcode'} = $res->{branchcode}; $needsconfirmation{'resreservedate'} = $res->{reservedate}; $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + item is on reserve for someone else"; + } else { + $message = "item is on reserve for someone else"; + } + push( @message_log, "item is on reserve for someone else" ); + } } elsif ( $restype eq "Transferred" ) { # The item is determined hold being transferred for someone else. @@ -1222,6 +1311,14 @@ sub CanBookBeIssued { $needsconfirmation{'resbranchcode'} = $res->{branchcode}; $needsconfirmation{'resreservedate'} = $res->{reservedate}; $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + item is determined hold being transferred for someone else"; + } else { + $message = "item is determined hold being transferred for someone else"; + } + push( @message_log, "item is determined hold being transferred for someone else" ); + } } elsif ( $restype eq "Processing" ) { # The item is determined hold being processed for someone else. @@ -1233,6 +1330,14 @@ sub CanBookBeIssued { $needsconfirmation{'resbranchcode'} = $res->{branchcode}; $needsconfirmation{'resreservedate'} = $res->{reservedate}; $needsconfirmation{'reserve_id'} = $res->{reserve_id}; + if ($issueconfirmed) { + if ($message) { + $message = "$message + item is determined hold being processed for someone else"; + } else { + $message = "item is determined hold being processed for someone else"; + } + push( @message_log, "item is determined hold being processed for someone else" ); + } } } } @@ -1276,6 +1381,12 @@ sub CanBookBeIssued { if ( $restriction_age && $patron->dateofbirth && $restriction_age > $patron->get_age() ) { if ( C4::Context->preference('AgeRestrictionOverride') ) { $needsconfirmation{AGE_RESTRICTION} = "$agerestriction"; + if ($message) { + $message = "$message + age restriction"; + } else { + $message = "age restriction"; + } + push( @message_log, "age restriction" ); } else { $issuingimpossible{AGE_RESTRICTION} = "$agerestriction"; @@ -1332,7 +1443,37 @@ sub CanBookBeIssued { } } - return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages, ); + my $borrower = $patron; + my $user = C4::Context->userenv->{number}; + my $branchcode = C4::Context->userenv->{branch}; + my $item = Koha::Items->find( { barcode => $barcode } ); + my $itemnumber = $item->itemnumber; + + # action, cardnumber, barcode, date, heure, user, branche + if ($issueconfirmed) { + + my $infos = ( + { + message => \@message_log, + borrowernumber => $borrower->borrowernumber, + barcode => $barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "ISSUE", + $borrower->{'borrowernumber'}, + $json_infos, + ) if C4::Context->preference("IssueLog"); + } + + + return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages, \@message_log ); } =head2 CanBookBeReturned diff --git a/circ/circulation.pl b/circ/circulation.pl index 968470e6f1..e4f588f7dc 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -345,6 +345,7 @@ if ( @$barcodes && $op eq 'cud-checkout' ) { { onsite_checkout => $onsite_checkout, override_high_holds => $override_high_holds || $override_high_holds_tmp || 0, + issueconfirmed => $issueconfirmed, } ); } catch { -- 2.43.0