diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c615c6..940f601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.5] - 2020-08-17 +## Changed +- Added support for CURBSIDE notice, which will be sent upon initial creation of a curbside pickup + +## [1.0.4] - 2020-08-12 +## Changed +- Remove dangling code, make fields required, prevent ISE when patron not found. + ## [1.0.3] - 2020-08-11 ## Added - This changelog! @@ -12,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Switched from `use` to `require` to allow installation to proceed without errors. Still requires plack to be restarted before using the plugin. ### Removed -- Installation debugging code +- Installation debugging code. ## [1.0.1] - 2020-08-11 ### Added diff --git a/Koha/Plugin/Com/ByWaterSolutions/CurbsidePickup.pm b/Koha/Plugin/Com/ByWaterSolutions/CurbsidePickup.pm index 0a11ff5..20f4b32 100644 --- a/Koha/Plugin/Com/ByWaterSolutions/CurbsidePickup.pm +++ b/Koha/Plugin/Com/ByWaterSolutions/CurbsidePickup.pm @@ -123,6 +123,7 @@ sub tool { notes => $notes, } )->store(); + $self->_notify_new_pickup($curbside_pickup); } } elsif ( $action eq 'cancel' ) { @@ -221,6 +222,67 @@ sub tool { $self->output_html( $template->output() ); } +sub _notify_new_pickup { + my ($self, $pickup_id) = @_; + + my $pickup = Koha::CurbsidePickups->find($pickup_id); + + my $patron = $pickup->patron; + + # Try to get the borrower's email address + my $to_address = $patron->notice_email_address; + + my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { + borrowernumber => $borrowernumber, + message_name => 'Hold_Filled' + } ); + + my $library = $pickup->library->unblessed; + + my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress'); + + my %letter_params = ( + module => 'reserves', + branchcode => $pickup->branchcode, + lang => $patron->lang, + tables => { + 'branches' => $library, + 'borrowers' => $patron->unblessed, + }, + substitute => { + curbside_pickup => $pickup, + } + ); + + my $send_notification = sub { + my ( $mtt, $letter_code ) = (@_); + return unless defined $letter_code; + $letter_params{letter_code} = $letter_code; + $letter_params{message_transport_type} = $mtt; + my $letter = C4::Letters::GetPreparedLetter ( %letter_params ); + unless ($letter) { + warn "Could not find a letter called '$letter_params{'letter_code'}' for $mtt in the 'reserves' module"; + return; + } + + C4::Letters::EnqueueLetter( { + letter => $letter, + borrowernumber => $borrowernumber, + from_address => $admin_email_address, + message_transport_type => $mtt, + } ); + }; + + while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) { + next if ( + ( $mtt eq 'email' and not $to_address ) # No email address + or ( $mtt eq 'sms' and not $patron->smsalertnumber ) # No SMS number + ); + + $send_notification($mtt, 'CURBSIDE'); + } +} + sub opac_js { my ($self) = @_;