From: Mike Rylander Date: Fri, 29 May 2020 16:17:07 +0000 (-0400) Subject: Initial logic for My Account curbside X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e7ae5e13f78666c864b1e8833a0002ff9cb96c02;p=working%2FEvergreen.git Initial logic for My Account curbside Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 6579300132..7bf52f44e3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1169,11 +1169,27 @@ sub fetch_user_holds { # put the holds back into the original server sort order my @sorted; + my %pickup_libs; for my $id (@$hold_ids) { push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds; + + my $h = $sorted[-1]; + # if available, report the pickup lib in the list + $pickup_libs{$h->pickup_lib} = 1 if ( + $h->pickup_lib == $h->current_shelf_lib && + $h->shelf_time && !$h->cancel_time && !$h->fulfillment_time + ); } - return { holds => \@sorted, ids => $hold_ids, all_ids => $all_ids }; + my $curbsides = $U->simplereq( + 'open-ils.curbside', + 'open-ils.curbside.fetch_mine.atomic', + $e->authtoken + ); + + my @pickup_libs = keys %pickup_libs; + + return { holds => \@sorted, ids => $hold_ids, all_ids => $all_ids, pickup_libs => \@pickup_libs, curbsides => $curbsides }; } sub handle_hold_update { @@ -1181,6 +1197,7 @@ sub handle_hold_update { my $action = shift; my $hold_ids = shift; my $e = $self->editor; + my $ctx = $self->ctx; my $url; my @hold_ids = ($hold_ids) ? @$hold_ids : $self->cgi->param('hold_id'); # for non-_all actions @@ -1252,6 +1269,67 @@ sub handle_hold_update { $url .= ";$param=" . uri_escape_utf8($_) foreach @vals; } } + } elsif ($action eq 'curbside') { # we'll only work on one curbside slot per refresh + $circ->kill_me; + + $circ = OpenSRF::AppSession->create('open-ils.curbside'); + + # see what we're doing with curbside here... + my $cs_action = $self->cgi->param("cs_action"); + my $slot_id = $self->cgi->param("cs_slot_id"); + + # we have an id, let's grab it if we can + my $slot = $e->retrieve_action_curbside($slot_id); + $slot = undef if ($slot && $slot->patron != $e->requestor->id); # nice try! + + my $org = $self->cgi->param("cs_org"); + my $date = $self->cgi->param("cs_date"); + my $time = $self->cgi->param("cs_time"); + my $notes = $self->cgi->param("cs_notes"); + + if ($slot) { + $org ||= $slot->org; + $notes ||= $slot->notes; + if ($slot->slot) { + my $dt = DateTime::Format::ISO8601->parse_datetime($slot->slot); + $date ||= $dt->strftime('%F'); + $time ||= $dt->strftime('%T'); + } + } + $ctx->{cs_org} = $org; + $ctx->{cs_date} = $date; + $ctx->{cs_time} = $time; + $ctx->{cs_notes} = $notes; + $ctx->{cs_slot_id} = $slot->id; + $ctx->{cs_slot} = $slot; + + if ($cs_action eq 'save' && $org && $date && $time) { + my $mode = $slot ? 'update' : 'create'; + $slot = $circ->request( + "open-ils.curbside.${mode}_appointment", + $e->authtoken, $e->requestor->id, $date, $time, $org, $notes + )->gather(1); + + if (defined $U->event_code($slot)) { + $self->apache->log->warn( + "error attempting to $mode a curbside appointment for patron ". + $e->requestor->id . ", got event " . $slot->{textcode} + ); + $ctx->{curbside_action_event} = $slot; + $ctx->{cs_slot} = undef; + } else { + $ctx->{cs_slot} = $slot; + + # just redirect back to the holds page + } + } elsif ($cs_action eq 'next' && $org && $date) { # get a list of times + $ctx->{cs_times} = $circ->request( + 'open-ils.curbside.times_for_date.atomic', + $e->authtoken, $date, $org + )->gather(1); + } + + $url = $self->ctx->{proto} . '://' . $self->ctx->{hostname} . $self->ctx->{opac_root} . '/myopac/hold_curbside'; } $circ->kill_me; @@ -1282,6 +1360,11 @@ sub load_myopac_holds { if($holds_object->{holds}) { $ctx->{holds} = $holds_object->{holds}; + $ctx->{curbside_appointments} = $holds_object->{curbsides}; + $ctx->{curbside_pickup_libs} = []; + for my $pul (@{$holds_object->{pickup_libs}}) { + push(@{$ctx->{curbside_pickup_libs}}, $pul) if $ctx->{get_org_setting}->($pul, 'circ.curbside'); + } } $ctx->{holds_ids} = $holds_object->{all_ids}; $ctx->{holds_limit} = $limit;