From 49772c96129cc07b3c38287657448a2619fe2292 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 12 Jan 2018 10:46:24 -0500 Subject: [PATCH] Bug 19191: Add ability to email receipts for account payments and write-offs Some libraries are paperless and require all payment receipts to be emailed. Koha should give libraries the option to send email receipts if a patron has an email address. If a notice for the type of "credit" exists ( payment or writeoff ), then an email receipt will be sent. These notices only support Template Toolkit syntax. Test Plan: 1) Apply this patch and dependencies 2) Add the two new notices, you can find them in installer/data/mysql/en/mandatory/sample_notices.sql 3) Note two new notices exist in the notices editor, ACCOUNT_PAYMENT and ACCOUNT_WRITEOFF 4) Find or create a patron with an email address that owes some amount of money 5) Make a payment for one or more fees 6) Note a new email is queued for the patron 7) Make a writeoff for one or more fees 8) Note a new new email is queued for the patron Signed-off-by: Josef Moravec Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- Koha/Account.pm | 28 +++++++++++++++++++ .../mysql/en/mandatory/sample_notices.sql | 5 ++++ 2 files changed, 33 insertions(+) diff --git a/Koha/Account.pm b/Koha/Account.pm index 036b34e429..a19faf2d48 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -26,6 +26,7 @@ use List::MoreUtils qw( uniq ); use C4::Log qw( logaction ); use C4::Stats qw( UpdateStats ); +use Koha::Patrons; use Koha::Account::Lines; use Koha::Account::Offsets; use Koha::DateUtils qw( dt_from_string ); @@ -79,6 +80,8 @@ sub pay { my $userenv = C4::Context->userenv; + my $patron = Koha::Patrons->find( $self->{patron_id} ); + # We should remove accountno, it is no longer needed my $last = Koha::Account::Lines->search( { @@ -260,6 +263,31 @@ sub pay { ); } + require C4::Letters; + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => uc("ACCOUNT_$type"), + message_transport_type => 'email', + lang => Koha::Patrons->find( $self->{patron_id} )->lang, + objects => { + patron => scalar Koha::Patrons->find( $self->{patron_id} ), + library => scalar Koha::Libraries->find( $self->{library_id} ), + offsets => \@account_offsets, + credit => $payment, + }, + ) + ) + { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $self->{patron_id}, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } + return $payment->id; } diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index eaaa073f6c..f467f57eae 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -176,3 +176,8 @@ INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title` ('circulation', 'AR_SLIP', '', 'Article request - print slip', 0, 'Article request', 'Article request:\r\n\r\n<> <> (<>),\r\n\r\nTitle: <>\r\nBarcode: <>\r\n\r\nArticle requested:\r\nTitle: <>\r\nAuthor: <>\r\nVolume: <>\r\nIssue: <>\r\nDate: <>\r\nPages: <>\r\nChapters: <>\r\nNotes: <>\r\n', 'print'), ('circulation', 'AR_PROCESSING', '', 'Article request - processing', 0, 'Article request processing', 'Dear <> <> (<>),\r\n\r\nWe are now processing your request for an article from <> (<>).\r\n\r\nArticle requested:\r\nTitle: <>\r\nAuthor: <>\r\nVolume: <>\r\nIssue: <>\r\nDate: <>\r\nPages: <>\r\nChapters: <>\r\nNotes: <>\r\n\r\nThank you!', 'email'), ('circulation', 'CHECKOUT_NOTE', '', 'Checkout note on item set by patron', '0', 'Checkout note', '<> <> has added a note to the item <> - <> (<>).','email'); + +INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) + VALUES + ('circulation', 'ACCOUNT_PAYMENT', '', 'Account Payment', 0, 'Account Payment', '[%- USE Price -%]\r\nA payment of [% credit.amount * -1 | $Price %] has been applied to your account.\r\n\r\nThis payment affected the following fees:\r\n[%- FOREACH o IN offsets %]\r\nDescription: [% o.debit.description %]\r\nAmount paid: [% o.amount * -1 | $Price %]\r\nAmount remaining: [% o.debit.amountoutstanding | $Price %]\r\n[% END %]', 'email', 'default'), + ('circulation', 'ACCOUNT_WRITEOFF', '', 'Account Writeoff', 0, 'Account Writeoff', '[%- USE Price -%]\r\nAn account writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.\r\n\r\nThis writeoff affected the following fees:\r\n[%- FOREACH o IN offsets %]\r\nDescription: [% o.debit.description %]\r\nAmount paid: [% o.amount * -1 | $Price %]\r\nAmount remaining: [% o.debit.amountoutstanding | $Price %]\r\n[% END %]', 'email', 'default'); -- 2.39.5