]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
ec27ede4105791ded1268f86cfc4f85a9a23112a
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ.pm
1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
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;
10
11 use OpenILS::Application::AppUtils;
12 my $apputils = "OpenILS::Application::AppUtils";
13 use OpenSRF::Utils;
14 use OpenILS::Utils::ModsParser;
15 use OpenILS::Event;
16 use OpenSRF::EX qw(:try);
17 use OpenSRF::Utils::Logger qw(:logger);
18 #my $logger = "OpenSRF::Utils::Logger";
19
20
21 # ------------------------------------------------------------------------
22 # Top level Circ package;
23 # ------------------------------------------------------------------------
24
25 sub initialize {
26         my $self = shift;
27         OpenILS::Application::Circ::Rules->initialize();
28 }
29
30
31 # ------------------------------------------------------------------------
32 # Returns an array of {circ, record} hashes checked out by the user.
33 # ------------------------------------------------------------------------
34 __PACKAGE__->register_method(
35         method  => "checkouts_by_user",
36         api_name        => "open-ils.circ.actor.user.checked_out",
37         NOTES           => <<"  NOTES");
38         Returns a list of open circulations as a pile of objects.  each object
39         contains the relevant copy, circ, and record
40         NOTES
41
42 sub checkouts_by_user {
43         my( $self, $client, $user_session, $user_id ) = @_;
44
45         my( $requestor, $target, $copy, $record, $evt );
46
47         ( $requestor, $target, $evt ) = 
48                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
49         return $evt if $evt;
50
51         my $circs = $apputils->simplereq(
52                 'open-ils.storage',
53                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
54                 { usr => $target->id } );
55
56         my @results;
57         for my $circ (@$circs) {
58
59                 ( $copy, $evt )  = $apputils->fetch_copy($circ->target_copy);
60                 return $evt if $evt;
61
62                 $logger->debug("Retrieving record for copy " . $circ->target_copy);
63
64                 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
65                 return $evt if $evt;
66
67                 my $mods = $apputils->record_to_mvr($record);
68
69                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
70         }
71
72         return \@results;
73
74 }
75
76
77
78 __PACKAGE__->register_method(
79         method  => "checkouts_by_user_slim",
80         api_name        => "open-ils.circ.actor.user.checked_out.slim",
81         NOTES           => <<"  NOTES");
82         Returns a list of open circulation objects
83         NOTES
84
85 sub checkouts_by_user_slim {
86         my( $self, $client, $user_session, $user_id ) = @_;
87
88         my( $requestor, $target, $copy, $record, $evt );
89
90         ( $requestor, $target, $evt ) = 
91                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
92         return $evt if $evt;
93
94         $logger->debug( 'User ' . $requestor->id . 
95                 " retrieving checked out items for user " . $target->id );
96
97         return $apputils->simplereq(
98                 'open-ils.storage',
99                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
100                 { usr => $target->id } );
101 }
102
103
104
105
106 __PACKAGE__->register_method(
107         method  => "title_from_transaction",
108         api_name        => "open-ils.circ.circ_transaction.find_title",
109         NOTES           => <<"  NOTES");
110         Returns a mods object for the title that is linked to from the 
111         copy from the hold that created the given transaction
112         NOTES
113
114 sub title_from_transaction {
115         my( $self, $client, $login_session, $transactionid ) = @_;
116
117         my( $user, $circ, $title, $evt );
118
119         ( $user, $evt ) = $apputils->checkses( $login_session );
120         return $evt if $evt;
121
122         ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
123         return $evt if $evt;
124         
125         ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
126         return $evt if $evt;
127
128         return $apputils->record_to_mvr($title);
129 }
130
131
132 __PACKAGE__->register_method(
133         method  => "set_circ_lost",
134         api_name        => "open-ils.circ.circulation.set_lost",
135         NOTES           => <<"  NOTES");
136         Params are login, circid
137         login must have SET_CIRC_LOST perms
138         Sets a circulation to lost
139         NOTES
140
141 __PACKAGE__->register_method(
142         method  => "set_circ_lost",
143         api_name        => "open-ils.circ.circulation.set_claims_returned",
144         NOTES           => <<"  NOTES");
145         Params are login, circid
146         login must have SET_CIRC_MISSING perms
147         Sets a circulation to lost
148         NOTES
149
150 sub set_circ_lost {
151         my( $self, $client, $login, $circid ) = @_;
152         my( $user, $circ, $evt );
153
154         ( $user, $evt ) = $apputils->checkses($login);
155         return $evt if $evt;
156
157         ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
158         return $evt if $evt;
159
160         if($self->api_name =~ /lost/) {
161                 if($evt = $apputils->checkperms(
162                         $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
163                         return $evt;
164                 }
165                 $circ->stop_fines("LOST");              
166         }
167
168         if($self->api_name =~ /claims_returned/) {
169                 if($evt = $apputils->checkperms(
170                         $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
171                         return $evt;
172                 }
173                 $circ->stop_fines("CLAIMSRETURNED");
174         }
175
176         my $s = $apputils->simplereq(
177                 'open-ils.storage',
178                 "open-ils.storage.direct.action.circulation.update", $circ );
179
180         if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
181 }
182
183
184
185
186
187
188 1;