1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenILS::Application::Circ::Circulate;
6 use OpenILS::Application::Circ::Rules;
7 use OpenILS::Application::Circ::Survey;
8 use OpenILS::Application::Circ::StatCat;
9 use OpenILS::Application::Circ::Holds;
10 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::Circ::NonCat;
13 use OpenILS::Application::AppUtils;
14 my $apputils = "OpenILS::Application::AppUtils";
16 use OpenILS::Utils::ModsParser;
18 use OpenSRF::EX qw(:try);
19 use OpenSRF::Utils::Logger qw(:logger);
20 #my $logger = "OpenSRF::Utils::Logger";
23 # ------------------------------------------------------------------------
24 # Top level Circ package;
25 # ------------------------------------------------------------------------
29 OpenILS::Application::Circ::Rules->initialize();
30 OpenILS::Application::Circ::Circulate->initialize();
34 # ------------------------------------------------------------------------
35 # Returns an array of {circ, record} hashes checked out by the user.
36 # ------------------------------------------------------------------------
37 __PACKAGE__->register_method(
38 method => "checkouts_by_user",
39 api_name => "open-ils.circ.actor.user.checked_out",
41 Returns a list of open circulations as a pile of objects. each object
42 contains the relevant copy, circ, and record
45 sub checkouts_by_user {
46 my( $self, $client, $user_session, $user_id ) = @_;
48 my( $requestor, $target, $copy, $record, $evt );
50 ( $requestor, $target, $evt ) =
51 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
54 my $circs = $apputils->simplereq(
56 "open-ils.storage.direct.action.open_circulation.search.atomic",
57 # { usr => $target->id, xact_finish => undef } );
58 { usr => $target->id } );
61 for my $circ (@$circs) {
63 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
66 $logger->debug("Retrieving record for copy " . $circ->target_copy);
68 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
71 my $mods = $apputils->record_to_mvr($record);
73 push( @results, { copy => $copy, circ => $circ, record => $mods } );
82 __PACKAGE__->register_method(
83 method => "checkouts_by_user_slim",
84 api_name => "open-ils.circ.actor.user.checked_out.slim",
86 Returns a list of open circulation objects
89 sub checkouts_by_user_slim {
90 my( $self, $client, $user_session, $user_id ) = @_;
92 my( $requestor, $target, $copy, $record, $evt );
94 ( $requestor, $target, $evt ) =
95 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
98 $logger->debug( 'User ' . $requestor->id .
99 " retrieving checked out items for user " . $target->id );
101 return $apputils->simplereq(
103 "open-ils.storage.direct.action.open_circulation.search.atomic",
104 # { usr => $target->id, xact_finish => undef } );
105 { usr => $target->id } );
111 __PACKAGE__->register_method(
112 method => "title_from_transaction",
113 api_name => "open-ils.circ.circ_transaction.find_title",
114 NOTES => <<" NOTES");
115 Returns a mods object for the title that is linked to from the
116 copy from the hold that created the given transaction
119 sub title_from_transaction {
120 my( $self, $client, $login_session, $transactionid ) = @_;
122 my( $user, $circ, $title, $evt );
124 ( $user, $evt ) = $apputils->checkses( $login_session );
127 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
130 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
133 return $apputils->record_to_mvr($title);
137 __PACKAGE__->register_method(
138 method => "set_circ_lost",
139 api_name => "open-ils.circ.circulation.set_lost",
140 NOTES => <<" NOTES");
141 Params are login, circid
142 login must have SET_CIRC_LOST perms
143 Sets a circulation to lost
146 __PACKAGE__->register_method(
147 method => "set_circ_lost",
148 api_name => "open-ils.circ.circulation.set_claims_returned",
149 NOTES => <<" NOTES");
150 Params are login, circid
151 login must have SET_CIRC_MISSING perms
152 Sets a circulation to lost
156 my( $self, $client, $login, $circid ) = @_;
157 my( $user, $circ, $evt );
159 ( $user, $evt ) = $apputils->checkses($login);
162 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
165 if($self->api_name =~ /lost/) {
166 if($evt = $apputils->checkperms(
167 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
170 $circ->stop_fines("LOST");
173 # XXX Back date the checkin time so the patron has no fines
174 if($self->api_name =~ /claims_returned/) {
175 if($evt = $apputils->checkperms(
176 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
179 $circ->stop_fines("CLAIMSRETURNED");
182 my $s = $apputils->simplereq(
184 "open-ils.storage.direct.action.circulation.update", $circ );
186 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }