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;
12 use OpenILS::Application::AppUtils;
13 my $apputils = "OpenILS::Application::AppUtils";
15 use OpenILS::Utils::ModsParser;
17 use OpenSRF::EX qw(:try);
18 use OpenSRF::Utils::Logger qw(:logger);
19 #my $logger = "OpenSRF::Utils::Logger";
22 # ------------------------------------------------------------------------
23 # Top level Circ package;
24 # ------------------------------------------------------------------------
28 OpenILS::Application::Circ::Rules->initialize();
29 OpenILS::Application::Circ::Circulate->initialize();
33 # ------------------------------------------------------------------------
34 # Returns an array of {circ, record} hashes checked out by the user.
35 # ------------------------------------------------------------------------
36 __PACKAGE__->register_method(
37 method => "checkouts_by_user",
38 api_name => "open-ils.circ.actor.user.checked_out",
40 Returns a list of open circulations as a pile of objects. each object
41 contains the relevant copy, circ, and record
44 sub checkouts_by_user {
45 my( $self, $client, $user_session, $user_id ) = @_;
47 my( $requestor, $target, $copy, $record, $evt );
49 ( $requestor, $target, $evt ) =
50 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
53 my $circs = $apputils->simplereq(
55 "open-ils.storage.direct.action.open_circulation.search.atomic",
56 # { usr => $target->id, xact_finish => undef } );
57 { usr => $target->id } );
60 for my $circ (@$circs) {
62 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
65 $logger->debug("Retrieving record for copy " . $circ->target_copy);
67 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
70 my $mods = $apputils->record_to_mvr($record);
72 push( @results, { copy => $copy, circ => $circ, record => $mods } );
81 __PACKAGE__->register_method(
82 method => "checkouts_by_user_slim",
83 api_name => "open-ils.circ.actor.user.checked_out.slim",
85 Returns a list of open circulation objects
88 sub checkouts_by_user_slim {
89 my( $self, $client, $user_session, $user_id ) = @_;
91 my( $requestor, $target, $copy, $record, $evt );
93 ( $requestor, $target, $evt ) =
94 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
97 $logger->debug( 'User ' . $requestor->id .
98 " retrieving checked out items for user " . $target->id );
100 return $apputils->simplereq(
102 "open-ils.storage.direct.action.open_circulation.search.atomic",
103 # { usr => $target->id, xact_finish => undef } );
104 { usr => $target->id } );
110 __PACKAGE__->register_method(
111 method => "title_from_transaction",
112 api_name => "open-ils.circ.circ_transaction.find_title",
113 NOTES => <<" NOTES");
114 Returns a mods object for the title that is linked to from the
115 copy from the hold that created the given transaction
118 sub title_from_transaction {
119 my( $self, $client, $login_session, $transactionid ) = @_;
121 my( $user, $circ, $title, $evt );
123 ( $user, $evt ) = $apputils->checkses( $login_session );
126 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
129 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
132 return $apputils->record_to_mvr($title);
136 __PACKAGE__->register_method(
137 method => "set_circ_lost",
138 api_name => "open-ils.circ.circulation.set_lost",
139 NOTES => <<" NOTES");
140 Params are login, circid
141 login must have SET_CIRC_LOST perms
142 Sets a circulation to lost
145 __PACKAGE__->register_method(
146 method => "set_circ_lost",
147 api_name => "open-ils.circ.circulation.set_claims_returned",
148 NOTES => <<" NOTES");
149 Params are login, circid
150 login must have SET_CIRC_MISSING perms
151 Sets a circulation to lost
155 my( $self, $client, $login, $circid ) = @_;
156 my( $user, $circ, $evt );
158 ( $user, $evt ) = $apputils->checkses($login);
161 ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
164 if($self->api_name =~ /lost/) {
165 if($evt = $apputils->checkperms(
166 $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
169 $circ->stop_fines("LOST");
172 if($self->api_name =~ /claims_returned/) {
173 if($evt = $apputils->checkperms(
174 $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
177 $circ->stop_fines("CLAIMSRETURNED");
180 my $s = $apputils->simplereq(
182 "open-ils.storage.direct.action.circulation.update", $circ );
184 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }