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::NotEnabled') ) {
70 code => 'not_enabled',
72 } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::LibraryIsClosed') ) {
75 code => 'library_is_closed',
76 patron => Koha::Patrons->find($borrowernumber)
78 } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoWaitingHolds') ) {
81 code => 'no_waiting_holds',
83 } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) {
86 code => 'too_many_pickups',
87 patron => Koha::Patrons->find($borrowernumber)
89 } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMatchingSlots') ) {
92 code => 'no_matching_slots',
94 } elsif ( $_->isa('Koha::Exceptions::CurbsidePickup::NoMorePickupsAvailable') ) {
97 code => 'no_more_pickups_available',
103 code => 'something_wrong_happened',
108 elsif ( $op eq 'cancel-pickup' ) {
109 my $id = $input->param('pickup_id');
110 my $curbside_pickup = Koha::CurbsidePickups->search(
111 { borrowernumber => $borrowernumber } )->find($id);
112 $curbside_pickup->delete
114 && !$curbside_pickup->delivered_datetime;
116 elsif ( $op eq 'arrival-alert' ) {
117 my $id = $input->param('pickup_id');
118 my $curbside_pickup = Koha::CurbsidePickups->search(
119 { borrowernumber => $borrowernumber } )->find($id);
120 $curbside_pickup->mark_patron_has_arrived if $curbside_pickup;
123 code => 'library_notified',
128 messages => \@messages,
129 policies => Koha::CurbsidePickupPolicies->search(
132 patron_scheduled_pickup => 1,
135 patron_curbside_pickups => Koha::CurbsidePickups->search(
137 borrowernumber => $logged_in_patron->borrowernumber,
140 order_by => { -asc => 'scheduled_pickup_datetime' }
142 )->filter_by_scheduled_today,
143 curbside_pickups => Koha::CurbsidePickups->search(
146 order_by => { -asc => 'scheduled_pickup_datetime' }
148 )->filter_by_scheduled_today,
151 output_html_with_http_headers $input, $cookie, $template->output, undef,
152 { force_no_caching => 1 };