1 package OpenILS::Application::Circ::NonCat;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::Editor;
10 $Data::Dumper::Indent = 0;
12 my $U = "OpenILS::Application::AppUtils";
15 # returns ( $newid, $evt ). If $evt, then there was an error
16 sub create_non_cat_circ {
17 my( $staffid, $patronid, $circ_lib, $noncat_type, $circ_time, $editor ) = @_;
19 my( $id, $nct, $evt );
21 my $circ = Fieldmapper::action::non_cataloged_circulation->new;
23 $logger->activity("Creating non-cataloged circulation for ".
24 "staff $staffid, patron $patronid, location $circ_lib, and non-cat type $noncat_type");
26 $circ->patron($patronid);
27 $circ->staff($staffid);
28 $circ->circ_lib($circ_lib);
29 $circ->item_type($noncat_type);
30 $circ->circ_time($circ_time);
33 $evt = $editor->event unless
34 $circ = $editor->create_action_non_cataloged_circulation( $circ )
39 'open-ils.storage.direct.action.non_cataloged_circulation.create', $circ );
40 $evt = $U->DB_UPDATE_FAILED($circ) unless $id;
44 return( $circ, $evt );
48 __PACKAGE__->register_method(
49 method => "create_noncat_type",
50 api_name => "open-ils.circ.non_cat_type.create",
52 Creates a new non cataloged item type
53 @param authtoken The login session key
54 @param name The name of the new type
55 @param orgId The location where the type will live
56 @return The type object on success and the corresponding
60 sub create_noncat_type {
61 my( $self, $client, $authtoken, $name, $orgId, $interval, $inhouse ) = @_;
62 my( $staff, $evt ) = $U->checkses($authtoken);
65 # grab all of "my" non-cat types and see if one with
66 # the requested name already exists
67 my $types = $self->retrieve_noncat_types_all($client, $orgId);
70 return OpenILS::Event->new('NON_CAT_TYPE_EXISTS') if $_->name eq $name;
74 $evt = $U->check_perms( $staff->id, $orgId, 'CREATE_NON_CAT_TYPE' );
77 my $type = Fieldmapper::config::non_cataloged_type->new;
79 $type->owning_lib($orgId);
80 $type->circ_duration($interval);
81 $type->in_house( ($inhouse) ? 't' : 'f' );
83 my $id = $U->simplereq(
85 'open-ils.storage.direct.config.non_cataloged_type.create', $type );
87 return $U->DB_UPDATE_FAILED($type) unless $id;
92 __PACKAGE__->register_method(
93 method => "update_noncat_type",
94 api_name => "open-ils.circ.non_cat_type.update",
96 Updates a non-cataloged type object
97 @param authtoken The login session key
98 @param type The updated type object
99 @return The result of the DB update call unless a preceeding event occurs,
100 in which case the event will be returned
103 sub update_noncat_type {
104 my( $self, $client, $authtoken, $type ) = @_;
105 my( $staff, $evt ) = $U->checkses($authtoken);
109 ($otype, $evt) = $U->fetch_non_cat_type($type->id);
112 $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
114 $evt = $U->check_perms( $staff->id, $type->owning_lib, 'UPDATE_NON_CAT_TYPE' );
117 return $U->simplereq(
119 'open-ils.storage.direct.config.non_cataloged_type.update', $type );
122 __PACKAGE__->register_method(
123 method => "retrieve_noncat_types_all",
124 api_name => "open-ils.circ.non_cat_types.retrieve.all",
126 Retrieves the non-cat types at the requested location as well
127 as those above and below the requested location in the org tree
128 @param orgId The base location at which to retrieve the type objects
129 @param depth Optional parameter to limit the depth of the tree
130 @return An array of non cat type objects or an event if an error occurs
133 sub retrieve_noncat_types_all {
134 my( $self, $client, $orgId, $depth ) = @_;
135 my $meth = 'open-ils.storage.ranged.config.non_cataloged_type.retrieve.atomic';
136 my $svc = 'open-ils.storage';
137 return $U->simplereq($svc, $meth, $orgId, $depth) if defined($depth);
138 return $U->simplereq($svc, $meth, $orgId);
143 __PACKAGE__->register_method(
144 method => 'fetch_noncat',
145 api_name => 'open-ils.circ.non_cataloged_circulation.retrieve',
151 my( $self, $conn, $auth, $circid ) = @_;
152 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
153 return $e->event unless $e->checkauth;
154 my $c = $e->retrieve_action_non_cataloged_circulation($circid)
156 if( $c->patron ne $e->requestor->id ) {
157 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
164 __PACKAGE__->register_method(
165 method => 'fetch_open_noncats',
166 api_name => 'open-ils.circ.open_non_cataloged_circulation.user',
168 Returns an id-list of non-cataloged circulations that are considered
169 open as of now. a circ is open if circ time + circ duration
170 (based on type) is > than now.
172 @param userid user to retrieve non-cat circs for
173 defaults to the session user
177 sub fetch_open_noncats {
178 my( $self, $conn, $auth, $userid ) = @_;
179 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
180 return $e->event unless $e->checkauth;
181 $userid ||= $e->requestor->id;
182 if( $e->requestor->id ne $userid ) {
183 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
186 'open-ils.storage.action.open_non_cataloged_circulation.user', $userid );
190 __PACKAGE__->register_method(
191 method => 'delete_noncat',
192 api_name => 'open-ils.circ.non_cataloged_type.delete',
195 my( $self, $conn, $auth, $typeid ) = @_;
196 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
197 return $e->event unless $e->checkauth;
199 my $nc = $e->retrieve_config_non_cataloged_type($typeid)
202 $e->allowed('DELETE_NON_CAT_TYPE', $nc->owning_lib) # XXX rely on editor perm
205 $e->delete_config_non_cataloged_type($nc) or return $e->event;