diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 19961f01ea..c51f0f2452 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -23,6 +23,7 @@ use DateTime; use POSIX qw( floor ); use Encode; use Try::Tiny; +use JSON; use C4::Context; use C4::Stats qw( UpdateStats ); @@ -320,6 +321,21 @@ A recall for this item was found, and the item needs to be transferred to the re =cut +my $query = CGI->new; + +my $stickyduedate = $query->param('stickyduedate'); +my $duedatespec = $query->param('duedatespec'); +my $restoreduedatespec = $query->param('restoreduedatespec') || $duedatespec; +if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) { + undef $restoreduedatespec; +} +my $issueconfirmed = $query->param('issueconfirmed'); +my $cancelreserve = $query->param('cancelreserve'); +my $cancel_recall = $query->param('cancel_recall'); +my $recall_id = $query->param('recall_id'); +my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice +my $charges = $query->param('charges') || q{}; + sub transferbook { my $params = shift; my $tbr = $params->{to_branch}; @@ -823,9 +839,22 @@ sub CanBookBeIssued { my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); my $now = dt_from_string(); + my $message; + my @message; + $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, "sticky due date is invalid or due date in the past" ); + } + } my $fees = Koha::Charges::Fees->new( @@ -871,6 +900,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, "borrower is restricted" ); + } } if ( $patron->is_expired ) { @@ -943,10 +980,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, "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, "borrower had amend" ); + } } } @@ -1027,6 +1080,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, "item is checked out for someone else" ); + } } } } @@ -1054,6 +1115,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, "too many checkout" ); + } } else { $issuingimpossible{TOO_MANY} = $toomany->{reason}; $issuingimpossible{current_loan_count} = $toomany->{count}; @@ -1086,6 +1155,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, "item not for loan" ); + } } } else { @@ -1131,6 +1208,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, "item lost" ); + } } if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; @@ -1231,6 +1316,16 @@ 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, "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. @@ -1242,6 +1337,15 @@ 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, "item is on reserve for someone else" ); + } } elsif ( $restype eq "Transferred" ) { # The item is determined hold being transferred for someone else. @@ -1253,6 +1357,15 @@ 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, "item is determined hold being transferred for someone else" ); + } } elsif ( $restype eq "Processing" ) { # The item is determined hold being processed for someone else. @@ -1264,6 +1377,15 @@ 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, "item is determined hold being processed for someone else" ); + } } } } @@ -1307,6 +1429,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, "age restriction" ); } else { $issuingimpossible{AGE_RESTRICTION} = "$agerestriction"; } @@ -1365,6 +1493,35 @@ sub CanBookBeIssued { } } + 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, + 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, ); } diff --git a/circ/circulation.pl b/circ/circulation.pl index 0a9906028e..c92a41bdbe 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -39,6 +39,7 @@ use C4::Members; use C4::Biblio qw( TransformMarcToKoha ); use C4::Search qw( new_record_from_zebra ); use C4::Reserves qw( ModReserveAffect ); +use C4::Log qw( logaction ); use Koha::Holds; use C4::Context; use CGI::Session; @@ -239,7 +240,7 @@ if ( @$barcodes == 0 && $charges eq 'yes' ) { # STEP 2 : FIND BORROWER # if there is a list of find borrowers.... # -my $message; + if ($findborrower) { Koha::Plugins->call( 'patron_barcode_transform', \$findborrower ); my $patron = Koha::Patrons->find( { cardnumber => $findborrower } ); @@ -325,6 +326,9 @@ if ($patron) { # STEP 3 : ISSUING # # +my $message; +my @message; + if ( @$barcodes && $op eq 'cud-checkout' ) { my $checkout_infos; for my $barcode (@$barcodes) { @@ -370,6 +374,7 @@ if ( @$barcodes && $op eq 'cud-checkout' ) { } if ( $issuingimpossible->{'STATS'} ) { + my ( $stats_return, $stats_messages, $stats_iteminformation, $stats_borrower ) = AddReturn( $item->barcode, C4::Context->userenv->{'branch'}, undef, undef, 1 ); @@ -534,6 +539,7 @@ if ( @$barcodes && $op eq 'cud-checkout' ) { } ); $recall_id = ( $recall and $recall->id ) ? $recall->id : undef; + } # If booked (alerts or confirmation) update datedue to end of booking @@ -551,6 +557,34 @@ if ( @$barcodes && $op eq 'cud-checkout' ) { } ); $template_params->{issue} = $issue; + + my $borrower = $patron; + my $borrowernumber = $patron->borrowernumber; + my $user = C4::Context->userenv->{number}; + my $branchcode = C4::Context->userenv->{branch}; + $message = "Restriction overridden temporarily"; + @message = ("Restriction overridden temporarily"); + + if ($issueconfirmed) { + my $infos = ( + { + message => \@message, + borrowernumber => $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"); + } $session->clear('auto_renew'); $inprocess = 1; } diff --git a/circ/renew.pl b/circ/renew.pl index c27881a494..90833e5b3b 100755 --- a/circ/renew.pl +++ b/circ/renew.pl @@ -24,6 +24,7 @@ use C4::Context; use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Circulation qw( barcodedecode CanBookBeRenewed GetLatestAutoRenewDate AddRenewal ); +use C4::Log qw( logaction ); use Koha::DateUtils qw( dt_from_string ); use Koha::Database; use Koha::BiblioFrameworks; @@ -64,6 +65,11 @@ if ( $op eq 'cud-renew' && $barcode ) { if ($checkout) { $patron = $checkout->patron; + my $borrowernumber = $patron->borrowernumber; + my $user = C4::Context->userenv->{number}; + my $branchcode = C4::Context->userenv->{branch}; + my $message; + my @message; if ( ( $patron->is_debarred || q{} ) lt dt_from_string()->ymd() ) { my $can_renew; @@ -74,6 +80,28 @@ if ( $op eq 'cud-renew' && $barcode ) { if ($override_holds) { $can_renew = 1; $error = undef; + + $message = "Override Renew hold for another"; + @message = ("Override Renew hold for another"); + + my $infos = ( + { + message => \@message, + borrowernumber => $borrowernumber, + barcode => $barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "RENEWAL", + $patron->borrowernumber, + $json_infos, + ) if C4::Context->preference("RenewalLog"); } else { $can_renew = 0; } @@ -104,6 +132,28 @@ if ( $op eq 'cud-renew' && $barcode ) { } ); $template->param( date_due => $date_due ); + + $message = "Override limit Renew"; + @message = ("Override limit Renew"); + + my $infos = ( + { + message => \@message, + borrowernumber => $borrowernumber, + barcode => $barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "RENEWAL", + $patron->borrowernumber, + $json_infos, + ) if C4::Context->preference("RenewalLog"); } } else { $error = "patron_restricted"; diff --git a/circ/returns.pl b/circ/returns.pl index 901877ef1e..29b2d2f7bf 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -42,6 +42,7 @@ use C4::Members; use C4::Output qw( output_html_with_http_headers ); use C4::Reserves qw( ModReserve ModReserveAffect CheckReserves ); use C4::RotatingCollections; +use C4::Log qw( logaction ); use Koha::AuthorisedValues; use Koha::BiblioFrameworks; use Koha::Calendar; @@ -158,6 +159,32 @@ if ( $query->param('reserve_id') && $op eq 'cud-affect_reserve' ) { $transfer->transit; } } +} else { + my $message = "return an element that is reserved"; + my @message = ("return an element that is reserved"); + my $user = C4::Context->userenv->{number}; + my $branchcode = C4::Context->userenv->{branch}; + my $barcode = $query->param('barcode'); + + my $infos = ( + { + message => \@message, + + #'card number' => $cardnumber, + barcode => $barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "RETURN", + $session, + $json_infos, + ) if C4::Context->preference("ReturnLog"); } if ( $query->param('recall_id') && $op eq 'cud-affect_recall' ) { @@ -220,6 +247,7 @@ if ($return_date_override) { # If 'needstransfer' was set and the librarian has chosen to initiate the transfer if ( $op eq 'cud-dotransfer' ) { + my $transferitem = $query->param('transferitem'); my $item = Koha::Items->find($transferitem); my $tobranchcode = $query->param('tobranch'); diff --git a/reserve/request.pl b/reserve/request.pl index a553070e4b..dd2023c6b5 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -40,6 +40,7 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber ); use C4::Circulation qw( _GetCircControlBranch GetBranchItemRule ); use Koha::DateUtils qw( dt_from_string ); use C4::Search qw( enabled_staff_search_views ); +use C4::Log qw( logaction ); use Koha::Biblios; use Koha::Checkouts; @@ -569,6 +570,33 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) $num_alreadyheld++; } + my $borrower = $patron; + my $borrowernumber = $patron->borrowernumber; + my $user = C4::Context->userenv->{number}; + my $branchcode = C4::Context->userenv->{branch}; + my $message = "Override limitation of hold"; + my @message = ("Override limitation of hold"); + my $barcode = $item->{barcode}; + + my $infos = ( + { + message => \@message, + borrowernumber => $borrowernumber, + barcode => $barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "HOLD", "ISSUE", + $borrower->{'borrowernumber'}, + $json_infos, + ) if C4::Context->preference("IssueLog"); + push( @available_itemtypes, $item->{itype} ); } else { diff --git a/svc/renew b/svc/renew index b995a6ef34..9f0543268d 100755 --- a/svc/renew +++ b/svc/renew @@ -26,6 +26,7 @@ use Try::Tiny; use C4::Circulation qw( AddRenewal CanBookBeRenewed ); use C4::Context; use C4::Auth qw(check_cookie_auth); +use C4::Log qw( logaction ); use Koha::DateUtils qw(output_pref dt_from_string); @@ -53,6 +54,10 @@ my $date_due; if ( $input->param('date_due') ) { $date_due = dt_from_string( scalar $input->param('date_due') ); } +my $borrower = Koha::Patrons->find($borrowernumber); +my $user = C4::Context->userenv->{'number'}; +my $message; +my @message; my $data; $data->{itemnumber} = $itemnumber; @@ -69,6 +74,55 @@ my $item = Koha::Items->find($itemnumber); if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference('AllowRenewalOnHoldOverride') ) { $data->{renew_okay} = 1; $data->{error} = undef; + + $message = "Override Renew hold for another"; + @message = ("Override Renew hold for another"); + + my $infos = ( + { + message => \@message, + borrowernumber => $borrowernumber, + barcode => $item->barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "RENEWAL", + $borrower->{'borrowernumber'}, + $json_infos, + ) if C4::Context->preference("IssueLog"); +} + +if ( $data->{error} && $data->{error} eq 'too_many' && C4::Context->preference('AllowRenewalLimitOverride') ) { + $data->{renew_okay} = 1; + $data->{error} = undef; + + $message = "Override limit Renew"; + @message = ("Override limit Renew"); + + my $infos = ( + { + message => \@message, + borrowernumber => $borrowernumber, + barcode => $item->barcode, + manager_id => $user, + branchcode => $branchcode, + } + ); + + my $json_infos = JSON->new->utf8->pretty->encode($infos); + $json_infos =~ s/"/'/g; + + logaction( + "CIRCULATION", "RENEWAL", + $borrower->{'borrowernumber'}, + $json_infos, + ) if C4::Context->preference("IssueLog"); } if ( $data->{renew_okay} || ( $seen && $data->{error} eq 'too_unseen' ) ) {