1 package OpenILS::Application::Circ::Circulate;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
5 use OpenSRF::EX qw(:try);
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Utils::ScriptRunner;
8 use OpenILS::Application::AppUtils;
9 my $apputils = "OpenILS::Application::AppUtils";
11 my %scripts; # - circulation script filenames
12 my $standings; # - cached patron standings
13 my $group_tree; # - cached permission group tree
15 # ------------------------------------------------------------------------------
16 # Load the circ script from the config
17 # ------------------------------------------------------------------------------
21 my $conf = OpenSRF::Utils::SettingsClient->new;
22 my @pfx = ( "apps", "open-ils.circ","app_settings", "scripts" );
24 my $p = $conf->config_value( @pfx, 'permission' );
25 my $d = $conf->config_value( @pfx, 'duration' );
26 my $f = $conf->config_value( @pfx, 'recurring_fines' );
27 my $m = $conf->config_value( @pfx, 'max_fines' );
28 my $pr = $conf->config_value( @pfx, 'permit_renew' );
29 my $ph = $conf->config_value( @pfx, 'permit_hold' );
31 $logger->error( "Missing circ script(s)" )
32 unless( $p and $d and $f and $m and $pr and $ph );
34 $scripts{circ_permit} = $p;
35 $scripts{circ_duration} = $d;
36 $scripts{circ_recurring_fines}= $f;
37 $scripts{circ_max_fines} = $m;
38 $scripts{circ_renew_permit} = $pr;
39 $scripts{hold_permit} = $ph;
41 $logger->debug("Loaded rules scripts for circ: " .
42 "circ permit : $p, circ duration :$d , circ recurring fines : $f, " .
43 "circ max fines : $m, circ renew permit : $pr, permit hold: $ph");
47 # ------------------------------------------------------------------------------
48 # Loads the necessary circ objects and pushes them into the script environment
49 # Returns ( $data, $evt ). if $evt is defined, then an
50 # unexpedted event occurred and should be dealt with / returned to the caller
51 # ------------------------------------------------------------------------------
55 my $barcode = $params{barcode};
56 my $patron = $params{patron};
57 my ( $copy, $title, $evt );
60 $standings = $apputils->fetch_patron_standings();
61 $group_tree = $apputils->fetch_permission_group_tree();
64 ( $copy, $evt ) = $apputils->fetch_copy_by_barcode( $barcode );
65 return ( undef, $evt ) if $evt;
67 ( $title, $evt ) = $apputils->fetch_record_by_copy( $copy->id );
68 return ( undef, $evt ) if $evt;
70 my $runner = OpenILS::Utils::ScriptRunner->new( type => 'js' );
71 $runner->insert( 'patron', $patron );
72 $runner->insert( 'title', $title );
73 $runner->insert( 'copy', $copy );
74 $runner->insert( 'standings', $standings );
75 $runner->insert( 'group_tree', $group_tree );
82 standings => $standings,
83 group_tree => $group_tree };
87 # ------------------------------------------------------------------------------
89 __PACKAGE__->register_method(
90 method => "permit_circ",
91 api_name => "open-ils.circ.permit_checkout_",
93 Determines if the given checkout can occur
94 PARAMS( authtoken, barcode => bc, patron => pid, renew => t/f )
99 my( $self, $client, $authtoken, %params ) = @_;
100 my $barcode = $params{barcode};
101 my $patronid = $params{patron};
102 my $isrenew = $params{renew};
103 my ( $requestor, $patron, $env, $evt );
105 ( $requestor, $patron, $evt) =
106 $apputils->checkses_requestor(
107 $authtoken, $patronid, 'VIEW_PERMIT_CHECKOUT' );
110 ( $env, $evt ) = create_circ_env( barcode => $barcode, patron => $patron );
113 my $runner = $env->{runner};
114 $runner->load($scripts{circ_permit});
116 if( ! $runner->run ) {
117 throw OpenSRF::EX::ERROR
118 ("Error running permit circ script: " . $scripts{circ_permit});
121 # Insepect the script results and return correct event
123 return OpenILS::Event->new( 'SUCCESS' );
127 # ------------------------------------------------------------------------------
129 __PACKAGE__->register_method(
130 method => "circulate",
131 api_name => "open-ils.circ.checkout.barcode_",
132 notes => <<" NOTES");
133 Checks out an item based on barcode
134 PARAMS( authtoken, barcode => bc, patron => pid )
138 my( $self, $client, $authtoken, %params ) = @_;
139 my $barcode = $params{barcode};
140 my $patronid = $params{patron};
144 # ------------------------------------------------------------------------------
146 __PACKAGE__->register_method(
148 api_name => "open-ils.circ.checkin.barcode_",
149 notes => <<" NOTES");
150 PARAMS( authtoken, barcode => bc )
151 Checks in based on barcode
152 Returns an event object whose payload contains the record, circ, and copy
153 If the item needs to be routed, the event is a ROUTE_COPY event
154 with an additional 'route_to' variable set on the event
158 my( $self, $client, $authtoken, %params ) = @_;
159 my $barcode = $params{barcode};
162 # ------------------------------------------------------------------------------
164 __PACKAGE__->register_method(
166 api_name => "open-ils.circ.renew_",
167 notes => <<" NOTES");
168 PARAMS( authtoken, circ => circ_id );
169 open-ils.circ.renew(login_session, circ_object);
170 Renews the provided circulation. login_session is the requestor of the
171 renewal and if the logged in user is not the same as circ->usr, then
172 the logged in user must have RENEW_CIRC permissions.
176 my( $self, $client, $authtoken, %params ) = @_;
177 my $circ = $params{circ};