1 package OpenILS::Application::Curbside;
6 use POSIX qw/strftime/;
7 use OpenSRF::AppSession;
8 use OpenILS::Application;
9 use base qw/OpenILS::Application/;
11 use OpenILS::Utils::DateTime qw/:datetime/;
12 use OpenILS::Utils::CStoreEditor qw/:funcs/;
13 use OpenILS::Utils::Fieldmapper;
14 use OpenILS::Application::AppUtils;
15 my $U = "OpenILS::Application::AppUtils";
17 use Digest::MD5 qw(md5_hex);
20 use DateTime::Format::ISO8601;
22 my $date_parser = DateTime::Format::ISO8601->new;
24 use OpenSRF::Utils::Logger qw/$logger/;
26 sub fetch_mine { # returns appointments owned by $authtoken user, optional $org filter
27 my ($self, $conn, $authtoken, $org, $limit, $offset) = @_;
29 my $e = new_editor(xact => 1, authtoken => $authtoken);
30 return $e->die_event unless $e->checkauth;
32 # NOTE: not checking if curbside is enabled here
33 # because the pickup lib might be anything
35 my $slots = $e->search_action_curbside([{
36 patron => $e->requestor->id,
37 delivered => { '=' => undef },
38 ( $org ? (org => $org) : () )
40 ($limit ? (limit => $limit) : ()),
41 ($offset ? (offset => $offset) : ()),
42 flesh => 2, flesh_fields => {acsp => ['patron'], au => ['card']},
43 order_by => { acsp => {slot => {direction => 'asc'}} }
46 $conn->respond($_) for @$slots;
49 __PACKAGE__->register_method(
50 method => "fetch_mine",
51 api_name => "open-ils.curbside.fetch_mine",
55 {type => 'string', desc => 'Authentication token'},
56 {type => 'number', desc => 'Optional Library ID to filter further'},
57 {type => 'number', desc => 'Fetch limit'},
58 {type => 'number', desc => 'Fetch offset'},
60 return => { desc => 'A stream of appointments that the authenticated user owns'}
64 sub fetch_appointments { # returns appointment for user at location
65 my ($self, $conn, $authtoken, $usr, $org) = @_;
67 my $e = new_editor(xact => 1, authtoken => $authtoken);
68 return $e->die_event unless $e->checkauth;
70 $org ||= $e->requestor->ws_ou;
72 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
73 $U->ou_ancestor_setting_value($org, 'circ.curbside')
76 return new OpenILS::Event("BAD_PARAMS", "desc" => "No user ID supplied") unless $usr;
78 unless ($usr == $e->requestor->id) {
79 return $e->die_event unless $e->allowed("STAFF_LOGIN");
82 my $slots = $e->search_action_curbside([{
84 delivered => { '=' => undef },
87 order_by => { acsp => {slot => {direction => 'asc'}} }
90 $conn->respond($_) for @$slots;
93 __PACKAGE__->register_method(
94 method => "fetch_appointments",
95 api_name => "open-ils.curbside.open_user_appointments_at_lib",
99 {type => 'string', desc => 'Authentication token'},
100 {type => 'number', desc => 'Patron ID'},
101 {type => 'number', desc => 'Optional pickup library. If not supplied, taken from WS of session.'},
103 return => { desc => 'A stream of appointments that the authenticated user owns'}
107 sub fetch_holds_for_patron_at_pickup_lib {
108 my ($self, $conn, $authtoken, $usr, $org) = @_;
110 my $e = new_editor(xact => 1, authtoken => $authtoken);
111 return $e->die_event unless $e->checkauth;
113 $org ||= $e->requestor->ws_ou;
115 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
116 $U->ou_ancestor_setting_value($org, 'circ.curbside')
119 return new OpenILS::Event("BAD_PARAMS", "desc" => "No user ID supplied") unless $usr;
121 my $holds = $e->search_action_hold_request({
123 current_shelf_lib => $org,
125 shelf_time => {'!=' => undef},
126 cancel_time => undef,
127 fulfillment_time => undef
130 return scalar(@$holds);
133 __PACKAGE__->register_method(
134 method => "fetch_holds_for_patron_at_pickup_lib",
135 api_name => "open-ils.curbside.patron.ready_holds_at_lib.count",
138 {type => 'string', desc => 'Authentication token'},
139 {type => 'number', desc => 'Patron ID'},
140 {type => 'number', desc => 'Optional pickup library. If not supplied, taken from WS of session.'},
142 return => { desc => 'Number of holds on the shelf for the patron at the specified library'}
146 sub _flesh_and_emit_slots {
147 my ($conn, $e, $slots) = @_;
149 for my $s (@$slots) {
153 $start_time = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($s->delivered));
154 $end_time = $start_time->clone->add(seconds => 90); # 90 seconds is arbitrary
156 my $holds = $e->search_action_hold_request([{
157 usr => $s->patron->id,
158 current_shelf_lib => $s->org,
159 pickup_lib => $s->org,
160 shelf_time => {'!=' => undef},
161 cancel_time => undef,
164 '-and' => [ { fulfillment_time => {'>=' => $start_time->strftime('%FT%T%z') } },
165 { fulfillment_time => {'<=' => $end_time->strftime('%FT%T%z') } } ],
167 (fulfillment_time => undef),
169 flesh => 1, flesh_fields => {ahr => ['current_copy']},
172 my $rhrr_list = $e->search_reporter_hold_request_record(
173 {id => [ map { $_->id } @$holds ]}
177 ($_->id => $e->retrieve_metabib_wide_display_entry( $_->bib_record))
180 $conn->respond({slot_id => $s->id, slot => $s, holds => $holds, bib_data_by_hold => \%bib_data});
184 sub fetch_delivered { # returns appointments delivered TODAY
185 my ($self, $conn, $authtoken, $org, $limit, $offset) = @_;
187 my $e = new_editor(xact => 1, authtoken => $authtoken);
188 return $e->die_event unless $e->checkauth;
190 $org ||= $e->requestor->ws_ou;
192 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
193 $U->ou_ancestor_setting_value($org, 'circ.curbside')
196 my $slots = $e->search_action_curbside([{
198 arrival => { '!=' => undef},
199 delivered => { '>' => 'today'},
201 ($limit ? (limit => $limit) : ()),
202 ($offset ? (offset => $offset) : ()),
203 flesh => 2, flesh_fields => {acsp => ['patron'], au => ['card']},
204 order_by => { acsp => {delivered => {direction => 'desc'}} }
207 _flesh_and_emit_slots($conn, $e, $slots);
211 __PACKAGE__->register_method(
212 method => "fetch_delivered",
213 api_name => "open-ils.curbside.fetch_delivered",
217 {type => 'string', desc => 'Authentication token'},
218 {type => 'number', desc => 'Library ID'},
219 {type => 'number', desc => 'Fetch limit'},
220 {type => 'number', desc => 'Fetch offset'},
222 return => { desc => 'A stream of appointments that were delivered today'}
226 sub fetch_latest_delivered { # returns appointments delivered TODAY
227 my ($self, $conn, $authtoken, $org) = @_;
229 my $e = new_editor(xact => 1, authtoken => $authtoken);
230 return $e->die_event unless $e->checkauth;
232 $org ||= $e->requestor->ws_ou;
234 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
235 $U->ou_ancestor_setting_value($org, 'circ.curbside')
238 my $slots = $e->search_action_curbside([{
240 arrival => { '!=' => undef},
241 delivered => { '>' => 'today'},
243 order_by => { acsp => {delivered => {direction => 'desc'}} }
246 return md5_hex( join(',', @$slots) );
248 __PACKAGE__->register_method(
249 method => "fetch_latest_delivered",
250 api_name => "open-ils.curbside.fetch_delivered.latest",
253 {type => 'string', desc => 'Authentication token'},
254 {type => 'number', desc => 'Library ID'},
256 return => { desc => 'Hash of appointment IDs delivered today, or error event'}
261 my ($self, $conn, $authtoken, $org, $limit, $offset) = @_;
263 my $e = new_editor(xact => 1, authtoken => $authtoken);
264 return $e->die_event unless $e->checkauth;
266 $org ||= $e->requestor->ws_ou;
268 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
269 $U->ou_ancestor_setting_value($org, 'circ.curbside')
272 my $slots = $e->search_action_curbside([{
274 arrival => { '!=' => undef},
277 ($limit ? (limit => $limit) : ()),
278 ($offset ? (offset => $offset) : ()),
279 flesh => 3, flesh_fields => {acsp => ['patron'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
280 order_by => { acsp => 'arrival' }
284 _flesh_and_emit_slots($conn, $e, $slots);
288 __PACKAGE__->register_method(
289 method => "fetch_arrived",
290 api_name => "open-ils.curbside.fetch_arrived",
294 {type => 'string', desc => 'Authentication token'},
295 {type => 'number', desc => 'Library ID'},
296 {type => 'number', desc => 'Fetch limit'},
297 {type => 'number', desc => 'Fetch offset'},
299 return => { desc => 'A stream of appointments for patrons that have arrived but are not delivered'}
303 sub fetch_latest_arrived {
304 my ($self, $conn, $authtoken, $org) = @_;
306 my $e = new_editor(xact => 1, authtoken => $authtoken);
307 return $e->die_event unless $e->checkauth;
309 $org ||= $e->requestor->ws_ou;
311 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
312 $U->ou_ancestor_setting_value($org, 'circ.curbside')
315 my $slots = $e->search_action_curbside([{
317 arrival => { '!=' => undef},
320 order_by => { acsp => { arrival => { direction => 'desc' } } }
323 return md5_hex( join(',', @$slots) );
325 __PACKAGE__->register_method(
326 method => "fetch_latest_arrived",
327 api_name => "open-ils.curbside.fetch_arrived.latest",
330 {type => 'string', desc => 'Authentication token'},
331 {type => 'number', desc => 'Library ID'},
333 return => { desc => 'Hash of appointment IDs for undelivered appointments'}
338 my ($self, $conn, $authtoken, $org, $limit, $offset) = @_;
340 my $e = new_editor(xact => 1, authtoken => $authtoken);
341 return $e->die_event unless $e->checkauth;
343 $org ||= $e->requestor->ws_ou;
345 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
346 $U->ou_ancestor_setting_value($org, 'circ.curbside')
349 my $slots = $e->search_action_curbside([{
351 staged => { '!=' => undef},
354 ($limit ? (limit => $limit) : ()),
355 ($offset ? (offset => $offset) : ()),
356 flesh => 3, flesh_fields => {acsp => ['patron'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
357 order_by => { acsp => 'slot' }
360 _flesh_and_emit_slots($conn, $e, $slots);
364 __PACKAGE__->register_method(
365 method => "fetch_staged",
366 api_name => "open-ils.curbside.fetch_staged",
370 {type => 'string', desc => 'Authentication token'},
371 {type => 'number', desc => 'Library ID'},
372 {type => 'number', desc => 'Fetch limit'},
373 {type => 'number', desc => 'Fetch offset'},
375 return => { desc => 'A stream of appointments that are staged but patrons have not yet arrived'}
379 sub fetch_latest_staged {
380 my ($self, $conn, $authtoken, $org) = @_;
382 my $e = new_editor(xact => 1, authtoken => $authtoken);
383 return $e->die_event unless $e->checkauth;
385 $org ||= $e->requestor->ws_ou;
387 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
388 $U->ou_ancestor_setting_value($org, 'circ.curbside')
391 my $slots = $e->search_action_curbside([{
393 staged => { '!=' => undef},
397 { class => acsp => field => slot => direction => 'desc' },
398 { class => acsp => field => id => direction => 'desc' }
402 return md5_hex( join(',', @$slots) );
404 __PACKAGE__->register_method(
405 method => "fetch_latest_staged",
406 api_name => "open-ils.curbside.fetch_staged.latest",
409 {type => 'string', desc => 'Authentication token'},
410 {type => 'number', desc => 'Library ID'},
412 return => { desc => 'Hash of appointment IDs for staged appointment'}
416 sub fetch_to_be_staged {
417 my ($self, $conn, $authtoken, $org, $limit, $offset) = @_;
419 my $e = new_editor(xact => 1, authtoken => $authtoken);
420 return $e->die_event unless $e->checkauth;
422 $org ||= $e->requestor->ws_ou;
424 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
425 $U->ou_ancestor_setting_value($org, 'circ.curbside')
428 my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes';
429 my $gran_seconds = interval_to_seconds($gran);
430 my $horizon = DateTime->now; # NOTE: does not need timezone set because it gets UTC, not floating, so we can math with it
431 $horizon->add(seconds => $gran_seconds * 2);
433 my $slots = $e->search_action_curbside([{
436 slot => { '<=' => $horizon->strftime('%FT%T%z') },
438 ($limit ? (limit => $limit) : ()),
439 ($offset ? (offset => $offset) : ()),
440 flesh => 3, flesh_fields => {acsp => ['patron','stage_staff'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
441 order_by => { acsp => 'slot' }
444 _flesh_and_emit_slots($conn, $e, $slots);
448 __PACKAGE__->register_method(
449 method => "fetch_to_be_staged",
450 api_name => "open-ils.curbside.fetch_to_be_staged",
454 {type => 'string', desc => 'Authentication token'},
455 {type => 'number', desc => 'Library ID'},
456 {type => 'number', desc => 'Fetch limit'},
457 {type => 'number', desc => 'Fetch offset'},
459 return => { desc => 'A stream of appointments that need to be staged'}
463 sub fetch_latest_to_be_staged {
464 my ($self, $conn, $authtoken, $org) = @_;
466 my $e = new_editor(xact => 1, authtoken => $authtoken);
467 return $e->die_event unless $e->checkauth;
469 $org ||= $e->requestor->ws_ou;
471 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
472 $U->ou_ancestor_setting_value($org, 'circ.curbside')
475 my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes';
476 my $gran_seconds = interval_to_seconds($gran);
477 my $horizon = DateTime->now; # NOTE: does not need timezone set because it gets UTC, not floating, so we can math with it
478 $horizon->add(seconds => $gran_seconds * 2);
480 my $slots = $e->search_action_curbside([{
483 slot => { '<=' => $horizon->strftime('%FT%T%z') },
486 { class => acsp => field => slot => direction => 'desc' },
487 { class => acsp => field => id => direction => 'desc' }
491 return md5_hex( join(',', map { join('-', $_->id(), $_->stage_staff() // '', $_->arrival() // '') } @$slots) );
493 __PACKAGE__->register_method(
494 method => "fetch_latest_to_be_staged",
495 api_name => "open-ils.curbside.fetch_to_be_staged.latest",
498 {type => 'string', desc => 'Authentication token'},
499 {type => 'number', desc => 'Library ID'},
501 return => { desc => 'Hash of appointment IDs that needs to be staged'}
506 my ($self, $conn, $authtoken, $date, $org) = @_;
508 my $e = new_editor(xact => 1, authtoken => $authtoken);
509 return $e->die_event unless $e->checkauth;
511 $org ||= $e->requestor->ws_ou;
513 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
514 $U->ou_ancestor_setting_value($org, 'circ.curbside')
517 my $start_obj = $date_parser->parse_datetime($date);
518 return $conn->respond_complete unless ($start_obj);
520 my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes';
521 $gran .= ' minutes' if ($gran =~ /^\s*\d+\s*$/); # Assume minutes for bare numbers (maybe surrounded by spaces)
523 my $gran_seconds = interval_to_seconds($gran);
524 $gran_seconds = 600 if ($gran_seconds < 600); # No smaller than 10 minute intervals
526 my $max = $U->ou_ancestor_setting_value($org, 'circ.curbside.max_concurrent') || 10;
528 my $hoo = $e->retrieve_actor_org_unit_hours_of_operation($org);
529 return undef unless ($hoo);
531 my $dow = $start_obj->day_of_week_0;
533 my $open_method = "dow_${dow}_open";
534 my $close_method = "dow_${dow}_close";
536 my $open_time = $hoo->$open_method;
537 my $close_time = $hoo->$close_method;
538 return $conn->respond_complete if ($open_time eq $close_time); # location closed that day
540 my $tz = $U->ou_ancestor_setting_value($org, 'lib.timezone') || 'local';
541 $start_obj = $date_parser->parse_datetime($date.'T'.$open_time)->set_time_zone($tz); # reset this to opening time
542 my $end_obj = $date_parser->parse_datetime($date.'T'.$close_time)->set_time_zone($tz);
544 my $now_obj = DateTime->now; # NOTE: does not need timezone set because it gets UTC, not floating, so we can math with it
545 # Add two step intervals to avoid having an appointment be scheduled
546 # sooner than the library could stage the items. Setting the earliest
547 # available time to be no earlier than two intervals from now
548 # is arbitrary and could be made configurable in the future, though
549 # it does follow the hard-coding of the horizon in fetch_to_be_staged().
550 $now_obj->add(seconds => 2 * $gran_seconds);
552 my $step_obj = $start_obj->clone;
553 while (DateTime->compare($step_obj,$end_obj) < 0) { # inside HOO
554 if (DateTime->compare($step_obj,$now_obj) >= 0) { # only offer times in the future
555 my $step_ts = $step_obj->strftime('%FT%T%z');
556 my $other_slots = $e->search_action_curbside({org => $org, slot => $step_ts}, {idlist => 1});
557 my $available = $max - scalar(@$other_slots);
558 $available = $available < 0 ? 0 : $available; # so truthiness testing is always easy in the client
560 $conn->respond([$step_obj->strftime('%T'), $available]);
562 $step_obj->add(seconds => $gran_seconds);
568 __PACKAGE__->register_method(
569 method => "times_for_date",
570 api_name => "open-ils.curbside.times_for_date",
575 {type => "string", desc => "Authentication token"},
576 {type => "string", desc => "Date to find times for"},
577 {type => "number", desc => "Library ID (default ws_ou)"},
579 return => {desc => 'A stream of array refs, structure: ["hh:mm:ss",$available_count]; event on error.'}
581 notes => 'Restricted to logged in users to avoid spamming induced load'
584 sub create_update_appointment {
585 my ($self, $conn, $authtoken, $patron, $date, $time, $org, $notes) = @_;
587 $mode = 'update' if ($self->api_name =~ /update/);
589 my $e = new_editor(xact => 1, authtoken => $authtoken);
590 return $e->die_event unless $e->checkauth;
592 $org ||= $e->requestor->ws_ou;
594 return new OpenILS::Event("CURBSIDE_NOT_ALLOWED") unless ($U->is_true(
595 $U->ou_ancestor_setting_value($org, 'circ.curbside')
598 unless ($patron == $e->requestor->id) {
599 return $e->die_event unless $e->allowed("STAFF_LOGIN");
602 my $date_obj = $date_parser->parse_datetime($date); # no TZ necessary, just using it to test the input and get DOW
603 return undef unless ($date_obj);
605 if ($time =~ /^\d\d:\d\d$/) {
606 $time .= ":00"; # tack on seconds if needed to keep
607 # interval_to_seconds happy
612 # do they already have an open slot?
613 # NOTE: once arrival is set, it's past the point of editing.
614 my $old_slot = $e->search_action_curbside({
617 slot => { '!=' => undef },
621 if ($mode eq 'create') {
622 my $ev = new OpenILS::Event("CURBSIDE_EXISTS");
630 my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes';
631 my $max = $U->ou_ancestor_setting_value($org, 'circ.curbside.max_concurrent') || 10;
633 # some sanity checking
634 my $hoo = $e->retrieve_actor_org_unit_hours_of_operation($org);
635 return undef unless ($hoo);
637 my $dow = $date_obj->day_of_week_0;
639 my $open_method = "dow_${dow}_open";
640 my $close_method = "dow_${dow}_close";
642 my $open_time = $hoo->$open_method;
643 my $close_time = $hoo->$close_method;
644 return undef if ($open_time eq $close_time); # location closed that day
646 my $open_seconds = interval_to_seconds($open_time);
647 my $close_seconds = interval_to_seconds($close_time);
649 my $time_seconds = interval_to_seconds($time);
650 my $gran_seconds = interval_to_seconds($gran);
652 return undef if ($time_seconds < $open_seconds); # too early
653 return undef if ($time_seconds > $close_seconds + 1); # too late (/at/ closing allowed)
655 my $time_into_open_second = $time_seconds - $open_seconds;
656 if (my $extra_time = $time_into_open_second % $gran) { # a remainder means we got a time we shouldn't have
657 $time_into_open_second -= $extra_time; # just back it off to have staff gather earlier
660 my $tz = $U->ou_ancestor_setting_value($org, 'lib.timezone') || 'local';
661 $date_obj = $date_parser->parse_datetime($date.'T'.$open_time)->set_time_zone($tz);
663 my $slot_ts = $date_obj->add(seconds => $time_into_open_second)->strftime('%FT%T%z');
665 # finally, confirm that there aren't too many already
666 my $other_slots = $e->search_action_curbside(
669 ( $slot ? (id => { '<>' => $slot->id }) : () ) # exclude our own slot from the count
673 if (scalar(@$other_slots) >= $max) { # oops... return error
674 my $ev = new OpenILS::Event("CURBSIDE_MAX_FOR_TIME");
679 my $method = 'update_action_curbside';
680 if ($mode eq 'create' or !$slot) {
681 $slot = $e->search_action_curbside({
689 if (!$slot) { # just in case the hold-ready reactor isn't in place
690 $slot = Fieldmapper::action::curbside->new;
692 $slot->patron($patron);
694 $slot->notes($notes) if ($notes);
695 $method = 'create_action_curbside';
697 $slot->notes($notes) if ($notes);
699 $method = 'update_action_curbside';
702 $slot->slot($slot_ts);
703 $e->$method($slot) or return $e->die_event;
706 $conn->respond_complete($e->retrieve_action_curbside($slot->id));
709 ->create('open-ils.trigger')
711 'open-ils.trigger.event.autocreate',
712 'hold.confirm_curbside',
717 __PACKAGE__->register_method(
718 method => "create_update_appointment",
719 api_name => "open-ils.curbside.update_appointment",
722 {type => 'string', desc => 'Authentication token'},
723 {type => 'number', desc => 'Patron ID'},
724 {type => 'string', desc => 'New Date'},
725 {type => 'string', desc => 'New Time'},
726 {type => 'number', desc => 'Library ID (default ws_ou)'},
728 return => { desc => 'An action::curbside record on success, '.
729 'an ILS Event on config, permission, or '.
730 'recoverable errors, or nothing on bad '.
735 __PACKAGE__->register_method(
736 method => "create_update_appointment",
737 api_name => "open-ils.curbside.create_appointment",
740 {type => 'string', desc => 'Authentication token'},
741 {type => 'number', desc => 'Patron ID'},
742 {type => 'string', desc => 'Date'},
743 {type => 'string', desc => 'Time'},
744 {type => 'number', desc => 'Library ID (default ws_ou)'},
746 return => { desc => 'An action::curbside record on success, '.
747 'an ILS Event on config, permission, or '.
748 'recoverable errors, or nothing on bad '.
753 sub delete_appointment {
754 my ($self, $conn, $authtoken, $appointment) = @_;
755 my $e = new_editor(xact => 1, authtoken => $authtoken);
756 return $e->die_event unless $e->checkauth;
758 my $slot = $e->retrieve_action_curbside($appointment);
759 return undef unless ($slot);
761 unless ($slot->patron == $e->requestor->id) {
762 return $e->die_event unless $e->allowed("STAFF_LOGIN");
765 $e->delete_action_curbside($slot) or return $e->die_event;
770 __PACKAGE__->register_method(
771 method => "delete_appointment",
772 api_name => "open-ils.curbside.delete_appointment",
775 {type => 'string', desc => 'Authentication token'},
776 {type => 'number', desc => 'Appointment ID'},
778 return => { desc => '-1 on success, nothing when no appointment found, '.
779 'or an ILS Event on permission error'}
783 sub manage_staging_claim {
784 my ($self, $conn, $authtoken, $appointment) = @_;
785 my $e = new_editor(xact => 1, authtoken => $authtoken);
786 return $e->die_event unless $e->checkauth;
787 return $e->die_event unless $e->allowed("STAFF_LOGIN");
789 my $slot = $e->retrieve_action_curbside($appointment);
790 return undef unless ($slot);
792 if ($self->api_name =~ /unclaim/) {
793 $slot->clear_stage_staff();
795 $slot->stage_staff($e->requestor->id);
798 $e->update_action_curbside($slot) or return $e->die_event;
801 return $e->retrieve_action_curbside([
804 flesh_fields => {acsp => ['patron','stage_staff'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
808 __PACKAGE__->register_method(
809 method => "manage_staging_claim",
810 api_name => "open-ils.curbside.claim_staging",
813 {type => 'string', desc => 'Authentication token'},
814 {type => 'number', desc => 'Appointment ID'},
816 return => { desc => 'Appointment on success, nothing when no appointment found, '.
817 'an ILS Event on permission error'}
820 __PACKAGE__->register_method(
821 method => "manage_staging_claim",
822 api_name => "open-ils.curbside.unclaim_staging",
825 {type => 'string', desc => 'Authentication token'},
826 {type => 'number', desc => 'Appointment ID'},
828 return => { desc => 'Appointment on success, nothing when no appointment found, '.
829 'an ILS Event on permission error'}
834 my ($self, $conn, $authtoken, $appointment) = @_;
835 my $e = new_editor(xact => 1, authtoken => $authtoken);
836 return $e->die_event unless $e->checkauth;
837 return $e->die_event unless $e->allowed("STAFF_LOGIN");
839 my $slot = $e->retrieve_action_curbside($appointment);
840 return undef unless ($slot);
842 $slot->staged('now');
843 $slot->stage_staff($e->requestor->id);
844 $e->update_action_curbside($slot) or return $e->die_event;
847 return $e->retrieve_action_curbside($slot->id);
849 __PACKAGE__->register_method(
850 method => "mark_staged",
851 api_name => "open-ils.curbside.mark_staged",
854 {type => 'string', desc => 'Authentication token'},
855 {type => 'number', desc => 'Appointment ID'},
857 return => { desc => 'Appointment on success, nothing when no appointment found, '.
858 'an ILS Event on permission error'}
863 my ($self, $conn, $authtoken, $appointment) = @_;
864 my $e = new_editor(xact => 1, authtoken => $authtoken);
865 return $e->die_event unless $e->checkauth;
866 return $e->die_event unless $e->allowed("STAFF_LOGIN");
868 my $slot = $e->retrieve_action_curbside($appointment);
869 return undef unless ($slot);
871 $slot->clear_staged();
872 $slot->clear_stage_staff();
873 $e->update_action_curbside($slot) or return $e->die_event;
876 return $e->retrieve_action_curbside($slot->id);
878 __PACKAGE__->register_method(
879 method => "mark_unstaged",
880 api_name => "open-ils.curbside.mark_unstaged",
883 {type => 'string', desc => 'Authentication token'},
884 {type => 'number', desc => 'Appointment ID'},
886 return => { desc => 'Appointment on success, nothing when no appointment found, '.
887 'an ILS Event on permission error'}
892 my ($self, $conn, $authtoken, $appointment) = @_;
893 my $e = new_editor(xact => 1, authtoken => $authtoken);
894 return $e->die_event unless $e->checkauth;
896 my $slot = $e->retrieve_action_curbside($appointment);
897 return undef unless ($slot);
899 unless ($slot->patron == $e->requestor->id) {
900 return $e->die_event unless $e->allowed("STAFF_LOGIN");
903 $slot->arrival('now');
905 $e->update_action_curbside($slot) or return $e->die_event;
908 return $e->retrieve_action_curbside($slot->id);
910 __PACKAGE__->register_method(
911 method => "mark_arrived",
912 api_name => "open-ils.curbside.mark_arrived",
915 {type => 'string', desc => 'Authentication token'},
916 {type => 'number', desc => 'Appointment ID'},
918 return => { desc => 'Appointment on success, nothing when no appointment found, '.
919 'or an ILS Event on permission error'}
924 my ($self, $conn, $authtoken, $appointment) = @_;
925 my $e = new_editor(xact => 1, authtoken => $authtoken);
926 return $e->die_event unless $e->checkauth;
927 return $e->die_event unless $e->allowed("STAFF_LOGIN");
929 my $slot = $e->retrieve_action_curbside($appointment);
930 return undef unless ($slot);
932 if (!$slot->staged) {
933 $slot->staged('now');
934 $slot->stage_staff($e->requestor->id);
937 if (!$slot->arrival) {
938 $slot->arrival('now');
941 $slot->delivered('now');
942 $slot->delivery_staff($e->requestor->id);
944 $e->update_action_curbside($slot) or return $e->die_event;
947 my $holds = $e->search_action_hold_request({
948 usr => $slot->patron,
949 current_shelf_lib => $slot->org,
950 pickup_lib => $slot->org,
951 shelf_time => {'!=' => undef},
952 cancel_time => undef,
953 fulfillment_time => undef
956 my $circ_sess = OpenSRF::AppSession->connect('open-ils.circ');
958 $circ_sess->request( # Just try as hard as possible to check out everything
959 'open-ils.circ.checkout.full.override',
960 $authtoken, { patron => $slot->patron, copyid => $_->current_copy }
964 my @successful_checkouts;
965 my $successful_patron;
966 for my $r (@requests) {
967 my $co_res = $r->gather(1);
968 $conn->respond($co_res);
969 next if (ref($co_res) eq 'ARRAY'); # success is always singular
971 if ($co_res->{textcode} eq 'SUCCESS') { # that's great news...
972 push @successful_checkouts, $co_res->{payload}->{circ}->id;
973 $successful_patron = $co_res->{payload}->{circ}->usr;
977 $conn->respond_complete($e->retrieve_action_curbside($slot->id));
980 'open-ils.circ.checkout.batch_notify.session.atomic',
983 \@successful_checkouts
984 ) if (@successful_checkouts);
986 $circ_sess->disconnect;
989 __PACKAGE__->register_method(
990 method => "mark_delivered",
991 api_name => "open-ils.curbside.mark_delivered",
995 {type => 'string', desc => 'Authentication token'},
996 {type => 'number', desc => 'Appointment ID'},
998 return => { desc => 'Nothing for no appointment found, '.
999 'a stream of open-ils.circ.checkout.full.override '.
1000 'responses followed by the finalized slot, '.
1001 'or an ILS Event on permission error'}