my $new_patron;
- #try {
- # create/update the patron first so we can use his id
- if($patron->isnew()) {
- $new_patron = _add_patron(
- $session, _clone_patron($patron));
- if(UNIVERSAL::isa($new_patron, "OpenILS::EX")) {
- $client->respond_complete($new_patron->ex);
- return undef;
- }
-
- } else {
- $new_patron = $patron;
- }
+ # create/update the patron first so we can use his id
+ if($patron->isnew()) {
- $new_patron = _add_update_addresses($session, $patron, $new_patron);
- $new_patron = _add_update_cards($session, $patron, $new_patron);
+ $new_patron = _add_patron($session, _clone_patron($patron), $user_obj);
- if(UNIVERSAL::isa($new_patron,"OpenILS::EX")) {
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
$client->respond_complete($new_patron->ex);
return undef;
}
- $new_patron = _add_survey_responses($session, $patron, $new_patron);
- $new_patron = _create_stat_maps($session, $user_session, $patron, $new_patron);
+ } else { $new_patron = $patron; }
- # re-update the patron if anything has happened to him during this process
- if($new_patron->ischanged()) {
- $new_patron = _update_patron($session, $new_patron);
- }
- $apputils->commit_db_session($session);
+ $new_patron = _add_update_addresses($session, $patron, $new_patron, $user_obj);
-=head
- } catch Error with {
- my $e = shift;
- $err = "-*- Failure adding user: $e";
- $apputils->rollback_db_session($session);
- warn $err;
- };
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+ $client->respond_complete($new_patron->ex);
+ return undef;
+ }
- if($err) { throw OpenSRF::EX::ERROR ($err); }
-=cut
+ $new_patron = _add_update_cards($session, $patron, $new_patron, $user_obj);
+
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+ $client->respond_complete($new_patron->ex);
+ return undef;
+ }
+
+ $new_patron = _add_survey_responses($session, $patron, $new_patron, $user_obj);
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+ $client->respond_complete($new_patron->ex);
+ return undef;
+ }
+
+ $new_patron = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+ $client->respond_complete($new_patron->ex);
+ return undef;
+ }
+
+
+ # re-update the patron if anything has happened to him during this process
+ if($new_patron->ischanged()) {
+ $new_patron = _update_patron($session, $new_patron, $user_obj);
+
+ if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
+ UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+ $client->respond_complete($new_patron->ex);
+ return undef;
+ }
+ }
+ $apputils->commit_db_session($session);
warn "Patron Update/Create complete\n";
return flesh_user($new_patron->id());
sub _add_patron {
my $session = shift;
my $patron = shift;
+ my $user_obj = shift;
+
+
+ if($apputils->check_user_perms(
+ $user_obj->id, $user_obj->home_ou, "CREATE_USER")) {
+ return OpenILS::Perm->new("CREATE_USER");
+ }
warn "Creating new patron\n";
_d($patron);
sub _update_patron {
- my( $session, $patron) = @_;
+ my( $session, $patron, $user_obj) = @_;
+
+
+ if($apputils->check_user_perms(
+ $user_obj->id, $user_obj->home_ou, "UPDATE_USER")) {
+ return OpenILS::Perm->new("UPDATE_USER");
+ }
warn "updating patron " . Dumper($patron) . "\n";
my( $self, $orglist, $add_types ) = @_;
-
-
return $orglist unless (
ref($orglist) and @$orglist > 1 );
}
-
-sub start_long_request {
-
- my($self, $service, $method, @params) = @_;
-
- my $session = OpenSRF::AppSession->create( $service );
- my $request = $session->request( $method, @params );
- my $response = $request->recv(30);
-
- $request->wait_complete;
- if(!$request->complete) {
- throw $response ("Call to $service for method $method with params @params" .
- "\n did not complete successfully");
- }
- if(!$response) {
- warn "No response from $service for method $method with params @params";
- }
-
- if($response and UNIVERSAL::isa($response,"Error")) {
- throw $response ("Call to $service for method $method with params @params" .
- "\n failed with exception: " . $response->stringify );
- }
-
- $request->finish();
-
- my $value;
-
- if($response) { $value = $response->content; }
- else { $value = undef; }
-
- return [ $session, $value ];
-}
-sub long_request {
- my($self, $session, $service, $method, @params) = @_;
- my $request = $session->request( $method, @params );
- my $response = $request->recv(30);
-
- $request->wait_complete;
-
- if(!$request->complete) {
- throw $response ("Call to $service for method $method with params @params" .
- "\n did not complete successfully");
- }
-
- if(!$response) {
- warn "No response from $service for method $method with params @params";
- }
-
- if($response and UNIVERSAL::isa($response,"Error")) {
- throw $response ("Call to $service for method $method with params @params" .
- "\n failed with exception: " . $response->stringify );
- }
-
- $request->finish();
-
- my $value;
-
- if($response) { $value = $response->content; }
- else { $value = undef; }
-
- return $value;
-}
-
-sub finish_long_request {
- my($self, $session) = @_;
- if($session) {
- $session->finish();
- $session->disconnect();
- }
-}
1;
$holdid )->gather(1);
}
+__PACKAGE__->register_method(
+ method => "capture_copy",
+ api_name => "open-ils.circ.hold.capture_copy.barcode",
+ notes => <<" NOTE");
+ Captures a copy to fulfil a hold
+ Params is login session and copy barcode
+ login mus have COPY_CHECKIN permissions (since this is essentially
+ copy checkin)
+ NOTE
+
+sub capture_copy {
+ my( $self, $client, $login_session, $barcode ) = @_;
+
+ my $user = $apputils->check_user_session($login_session);
+
+ if($apputils->check_user_perms($user->id, $user->home_ou, "COPY_CHECKIN")) {
+ return OpenILS::Perm->new("COPY_CHECKIN");
+ }
+
+ my $session = $apputils->start_db_session();
+ my $copy = $session->request(
+ "open-ils.storage.direct.asset.copy.search.barcode",
+ $barcode )->gather(1);
+
+ warn "Capturing copy " . $copy->id . "\n";
+
+ # retrieve the hold copy maps for this copy
+ my $maps = $session->request(
+ "open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic",
+ $copy->id)->gather(1);
+
+ my @holdids = map { $_->hold } @$maps;
+
+ use Data::Dumper;
+ warn "Found possible holds\n" . Dumper(\@holdids) . "\n";
+
+ # retrieve sorted list of holds for the given maps and use the first
+ # if there is a hold for this lib, use that
+ my $holds = $session->request(
+ "open-ils.storage.direct.action.hold_request.search_where.atomic",
+ { id => \@holdids, current_copy => undef },
+ { order_by => "CASE WHEN ". $copy->circ_lib .
+ " = (SELECT a.home_ou FROM actor.usr a where a.id = usr ) THEN 0 ELSE 1 END, request_time" }
+ )->gather(1);
+
+ my $hold = $holds->[0];
+
+ warn "Found hold " . $hold->id . "\n";
+
+ $hold->current_copy($copy->id);
+ $hold->capture_time("now"); # ???
+
+ #update the hold
+ my $stat = $session->request(
+ "open-ils.storage.direct.action.hold_request.update", $hold)->gather(1);
+ if(!$stat) { throw OpenSRF::EX ("Error updating hold request " . $copy->id); }
+
+ $copy->status(8); #status on holds shelf
+
+ # if the staff member capturing this item is not at the pickup lib
+ if( $user->home_ou ne $hold->pickup_lib ) {
+ my $trans = Fieldmapper::action::hold_transit_copy->new;
+ $trans->hold($hold->id);
+ $trans->source($user->home_ou);
+ $trans->dest($hold->pickup_lib);
+ $trans->source_send_time("now");
+ my $meth = $self->method_lookup("open-ils.circ.hold_transit.create");
+ my ($stat) = $meth->run( $login_session, $trans, $session );
+ if(!$stat) { throw OpenSRF::EX ("Error creating new hold transit"); }
+ else { $copy->status(6); } #status in transit
+ }
+
+ $copy->editor($user->id);
+ $copy->edit_date("now");
+ $stat = $session->request(
+ "open-ils.storage.direct.asset.copy.update", $copy )->gather(1);
+ if(!$stat) { throw OpenSRF::EX ("Error updating copy " . $copy->id); }
+
+ $apputils->commit_db_session($session);
+
+ return { route_to => $hold->pickup_lib };
+
+}
+
+
+__PACKAGE__->register_method(
+ method => "create_hold_transit",
+ api_name => "open-ils.circ.hold_transit.create",
+ notes => <<" NOTE");
+ Creates a new transit object
+ NOTE
+
+sub create_hold_transit {
+ my( $self, $client, $login_session, $transit, $session ) = @_;
+
+ my $user = $apputils->check_user_session($login_session);
+ if($apputils->check_user_perms($user->id, $user->home_ou, "CREATE_TRANSIT")) {
+ return OpenILS::Perm->new("CREATE_TRANSIT");
+ }
+
+ my $ses;
+ if($session) { $ses = $session; }
+ else { $ses = OpenSRF::AppSession->create("open-ils.storage"); }
+
+ return $ses->request(
+ "open-ils.storage.direct.action.hold_transit_copy.create", $transit )->gather(1);
+}
+
sub permit_circ {
my( $self, $client, $user_session, $barcode, $user_id, $outstanding_count ) = @_;
+ my $copy_status_mangled;
+
my $renew = 0;
if(defined($outstanding_count) && $outstanding_count eq "renew") {
$renew = 1;
$outstanding_count = 0;
} else { $outstanding_count ||= 0; }
-
my $session = OpenSRF::AppSession->create("open-ils.storage");
# collect items necessary for circ calculation
text => "No copy available with barcode $barcode"
};
}
+ my $copy = $stash->get("circ_objects")->{copy};
+
+ if( $copy->status eq "8" ) {
+ $copy_status_mangled = 8;
+ $copy->status(0);
+ }
+
$stash->set("run_block", $permission_script);
# run the permissibility script
run_script();
-
my $arr = $stash->get("result");
+
+ if( $arr->[0] eq "0" and $copy_status_mangled == 8) {
+ my $hold = $session->request(
+ "open-ils.storage.direct.action.hold_request.search.current_copy",
+ $copy->id )->gather(1);
+ if($hold) {
+ if( $hold->usr eq $user_id ) {
+ return { status => 0, text => "OK" };
+ } else {
+ return { status => 6,
+ text => "Copy is needed by a different user to fulfill a hold" };
+ }
+ }
+ }
+
+
+
return { status => $arr->[0], text => $arr->[1] };
}
my $transaction;
my $user = $apputils->check_user_session($user_session);
+ if($apputils->check_user_perms($user->id, $user->home_ou, "COPY_CHECKIN")) {
+ return OpenILS::Perm->new("COPY_CHECKIN");
+ }
+
try {
my $session = $apputils->start_db_session();
-
-
-
# ------------------------------------------------------------------------------
# RENEWALS
# ------------------------------------------------------------------------------
"open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic",
$copy->id )->gather(1);
+ my @holdids = map { $_->hold } @$r;
+
if(@$r != 0) {
- if( $user->id ne $circ->usr ) {
+
+ my $holds = $session->request(
+ "open-ils.storage.direct.action.hold_request.search_where",
+ { id => \@holdids, current_copy => undef } )->gather(1);
+
+ if( $holds and $user->id ne $circ->usr ) {
if($apputils->check_user_perms($user->id, $user->home_ou, "RENEW_HOLD_OVERRIDE")) {
return OpenILS::Perm->new("RENEW_HOLD_OVERRIDE");
}
__PACKAGE__->register_method(
method => "proxy",
api_name => "open-ils.proxy.proxy",
+ stream => 1,
);