1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenILS::Application::Circ::Rules;
6 use OpenILS::Application::Circ::Survey;
7 use OpenILS::Application::Circ::StatCat;
8 use OpenILS::Application::Circ::Holds;
9 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::AppUtils;
12 my $apputils = "OpenILS::Application::AppUtils";
14 use OpenILS::Utils::ModsParser;
17 # ------------------------------------------------------------------------
18 # Top level Circ package;
19 # ------------------------------------------------------------------------
23 OpenILS::Application::Circ::Rules->initialize();
28 # ------------------------------------------------------------------------
29 # Returns an array of {circ, record} hashes checked out by the user.
30 # ------------------------------------------------------------------------
31 __PACKAGE__->register_method(
32 method => "checkouts_by_user",
33 api_name => "open-ils.circ.actor.user.checked_out",
35 Returns a list of open circulations as a pile of objects. each object
36 contains the relevant copy, circ, and record
39 sub checkouts_by_user {
40 my( $self, $client, $user_session, $user_id ) = @_;
42 my $session = OpenSRF::AppSession->create("open-ils.storage");
43 my $user_obj = $apputils->check_user_session($user_session);
45 if(!$user_id) { $user_id = $user_obj->id(); }
47 my $circs = $session->request(
48 "open-ils.storage.direct.action.open_circulation.search.usr.atomic", $user_id );
49 $circs = $circs->gather(1);
52 for my $circ (@$circs) {
54 my $copy = $session->request(
55 "open-ils.storage.direct.asset.copy.retrieve",
58 warn "Retrieving record for copy " . $circ->target_copy . "\n";
60 my $record = $session->request(
61 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
64 $copy = $copy->gather(1);
65 $record = $record->gather(1);
69 my $u = OpenILS::Utils::ModsParser->new();
70 $u->start_mods_batch( $record->marc() );
71 my $mods = $u->finish_mods_batch();
72 $mods->doc_id($record->id());
74 push( @results, { copy => $copy, circ => $circ, record => $mods } );
82 __PACKAGE__->register_method(
83 method => "title_from_transaction",
84 api_name => "open-ils.circ.circ_transaction.find_title",
86 Returns a mods object for the title that is linked to from the
87 copy from the hold that created the given transaction
90 sub title_from_transaction {
92 my( $self, $client, $login_session, $transactionid ) = @_;
93 my $user = $apputils->check_user_session($login_session);
94 my $session = OpenSRF::AppSession->create('open-ils.storage');
96 my $circ = $session->request(
97 "open-ils.storage.direct.action.circulation.retrieve", $transactionid )->gather(1);
100 my $title = $session->request(
101 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
102 $circ->target_copy )->gather(1);
105 my $u = OpenILS::Utils::ModsParser->new();
106 $u->start_mods_batch( $title->marc );
107 return $u->finish_mods_batch();
115 __PACKAGE__->register_method(
116 method => "set_circ_lost",
117 api_name => "open-ils.circ.circulation.set_lost",
118 NOTES => <<" NOTES");
119 Params are login, circid
120 login must have SET_CIRC_LOST perms
121 Sets a circulation to lost
124 __PACKAGE__->register_method(
125 method => "set_circ_lost",
126 api_name => "open-ils.circ.circulation.set_claims_returned",
127 NOTES => <<" NOTES");
128 Params are login, circid
129 login must have SET_CIRC_MISSING perms
130 Sets a circulation to lost
134 my( $self, $client, $login, $circid ) = @_;
136 my $user = $apputils->check_user_session($login);
137 my $session = OpenSRF::AppSession->create('open-ils.storage');
138 my $circ = $session->request(
139 "open-ils.storage.direct.action.circulation.retrieve", $circid )->gather(1);
141 if(!$circ) { throw OpenSRF::EX::ERROR ("No circulation exists with id $circid"); }
143 if($self->api_name =~ /lost/) {
144 if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
145 return OpenILS::Perm->new("SET_CIRC_LOST");
147 $circ->stop_fines("LOST");
150 if($self->api_name =~ /claims_returned/) {
151 if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
152 return OpenILS::Perm->new("SET_CIRC_CLAIMS_RETURNED");
154 $circ->stop_fines("CLAIMSRETURNED");
158 my $s = $session->request(
159 "open-ils.storage.direct.action.circulation.update", $circ )->gather(1);
161 if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }