3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
26 use Koha::DateUtils qw( dt_from_string );
27 use Koha::CurbsidePickups;
28 use Koha::CurbsidePickupPolicies;
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35 template_name => "opac-curbside-pickups.tt",
41 unless( C4::Context->preference('CurbsidePickup') ) {
42 print $input->redirect("/cgi-bin/koha/errors/404.pl");
46 my $op = $input->param('op') || 'list';
48 my $logged_in_patron = Koha::Patrons->find($borrowernumber);
49 my $branchcode = $input->param('pickup_branch');
52 if ( $op eq 'create-pickup' ) {
53 my $scheduled_pickup_datetime = $input->param('pickup_time');
54 my $notes = $input->param('notes');
57 my $pickup = Koha::CurbsidePickup->new(
59 branchcode => $branchcode,
60 borrowernumber => $borrowernumber,
61 scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime),
65 $pickup->notify_new_pickup;
67 if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
70 code => 'too_many_pickups',
71 patron => Koha::Patrons->find($borrowernumber)
77 code => 'something_wrong_happened',
82 elsif ( $op eq 'cancel-pickup' ) {
83 my $id = $input->param('pickup_id');
84 my $curbside_pickup = Koha::CurbsidePickups->search(
85 { borrowernumber => $borrowernumber } )->find($id);
86 $curbside_pickup->delete
88 && !$curbside_pickup->delivered_datetime;
90 elsif ( $op eq 'arrival-alert' ) {
91 my $id = $input->param('pickup_id');
92 my $curbside_pickup = Koha::CurbsidePickups->search(
93 { borrowernumber => $borrowernumber } )->find($id);
94 $curbside_pickup->mark_patron_has_arrived if $curbside_pickup;
97 code => 'library_notified',
102 policies => Koha::CurbsidePickupPolicies->search(
105 patron_scheduled_pickup => 1,
108 patron_curbside_pickups => Koha::CurbsidePickups->search(
110 borrowernumber => $logged_in_patron->borrowernumber,
113 order_by => { -asc => 'scheduled_pickup_datetime' }
115 )->filter_by_scheduled_today,
116 curbside_pickups => Koha::CurbsidePickups->search(
119 order_by => { -asc => 'scheduled_pickup_datetime' }
121 )->filter_by_scheduled_today,
124 output_html_with_http_headers $input, $cookie, $template->output, undef,
125 { force_no_caching => 1 };