]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
adding permit script. permit circ now basically functions
[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::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
12 use OpenILS::Application::AppUtils;
13 my $apputils = "OpenILS::Application::AppUtils";
14 use OpenSRF::Utils;
15 use OpenILS::Utils::ModsParser;
16 use OpenILS::Event;
17 use OpenSRF::EX qw(:try);
18 use OpenSRF::Utils::Logger qw(:logger);
19 #my $logger = "OpenSRF::Utils::Logger";
20
21
22 # ------------------------------------------------------------------------
23 # Top level Circ package;
24 # ------------------------------------------------------------------------
25
26 sub initialize {
27         my $self = shift;
28         OpenILS::Application::Circ::Rules->initialize();
29         OpenILS::Application::Circ::Circulate->initialize();
30 }
31
32
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",
39         NOTES           => <<"  NOTES");
40         Returns a list of open circulations as a pile of objects.  each object
41         contains the relevant copy, circ, and record
42         NOTES
43
44 sub checkouts_by_user {
45         my( $self, $client, $user_session, $user_id ) = @_;
46
47         my( $requestor, $target, $copy, $record, $evt );
48
49         ( $requestor, $target, $evt ) = 
50                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
51         return $evt if $evt;
52
53         my $circs = $apputils->simplereq(
54                 'open-ils.storage',
55                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
56 #               { usr => $target->id, xact_finish => undef } );
57                 { usr => $target->id } );
58
59         my @results;
60         for my $circ (@$circs) {
61
62                 ( $copy, $evt )  = $apputils->fetch_copy($circ->target_copy);
63                 return $evt if $evt;
64
65                 $logger->debug("Retrieving record for copy " . $circ->target_copy);
66
67                 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
68                 return $evt if $evt;
69
70                 my $mods = $apputils->record_to_mvr($record);
71
72                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
73         }
74
75         return \@results;
76
77 }
78
79
80
81 __PACKAGE__->register_method(
82         method  => "checkouts_by_user_slim",
83         api_name        => "open-ils.circ.actor.user.checked_out.slim",
84         NOTES           => <<"  NOTES");
85         Returns a list of open circulation objects
86         NOTES
87
88 sub checkouts_by_user_slim {
89         my( $self, $client, $user_session, $user_id ) = @_;
90
91         my( $requestor, $target, $copy, $record, $evt );
92
93         ( $requestor, $target, $evt ) = 
94                 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
95         return $evt if $evt;
96
97         $logger->debug( 'User ' . $requestor->id . 
98                 " retrieving checked out items for user " . $target->id );
99
100         return $apputils->simplereq(
101                 'open-ils.storage',
102                 "open-ils.storage.direct.action.open_circulation.search.atomic", 
103 #               { usr => $target->id, xact_finish => undef } );
104                 { usr => $target->id } );
105 }
106
107
108
109
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
116         NOTES
117
118 sub title_from_transaction {
119         my( $self, $client, $login_session, $transactionid ) = @_;
120
121         my( $user, $circ, $title, $evt );
122
123         ( $user, $evt ) = $apputils->checkses( $login_session );
124         return $evt if $evt;
125
126         ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
127         return $evt if $evt;
128         
129         ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
130         return $evt if $evt;
131
132         return $apputils->record_to_mvr($title);
133 }
134
135
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
143         NOTES
144
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
152         NOTES
153
154 sub set_circ_lost {
155         my( $self, $client, $login, $circid ) = @_;
156         my( $user, $circ, $evt );
157
158         ( $user, $evt ) = $apputils->checkses($login);
159         return $evt if $evt;
160
161         ( $circ, $evt ) = $apputils->fetch_circulation( $circid );
162         return $evt if $evt;
163
164         if($self->api_name =~ /lost/) {
165                 if($evt = $apputils->checkperms(
166                         $user->id, $circ->circ_lib, "SET_CIRC_LOST")) {
167                         return $evt;
168                 }
169                 $circ->stop_fines("LOST");              
170         }
171
172         # XXX Back date the checkin time so the patron has no fines
173         if($self->api_name =~ /claims_returned/) {
174                 if($evt = $apputils->checkperms(
175                         $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) {
176                         return $evt;
177                 }
178                 $circ->stop_fines("CLAIMSRETURNED");
179         }
180
181         my $s = $apputils->simplereq(
182                 'open-ils.storage',
183                 "open-ils.storage.direct.action.circulation.update", $circ );
184
185         if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); }
186 }
187
188
189
190
191
192
193 1;