Bugzilla – Attachment 70471 Details for
Bug 19191
Add ability to email receipts for account payments and write-offs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19191 - Add ability to email receipts for account payments and write-offs
Bug-19191---Add-ability-to-email-receipts-for-acco.patch (text/plain), 8.54 KB, created by
Kyle M Hall (khall)
on 2018-01-12 15:49:29 UTC
(
hide
)
Description:
Bug 19191 - Add ability to email receipts for account payments and write-offs
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2018-01-12 15:49:29 UTC
Size:
8.54 KB
patch
obsolete
>From 2cd0f9ac5ab1d1db3df0f3228f8f0827f9fbe5cb Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatetsolutions.com> >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 <josef.moravec@gmail.com> >--- > Koha/Account.pm | 28 ++++++++++++++++ > Koha/Account/Offset.pm | 28 ++++++++++++++++ > .../data/mysql/en/mandatory/sample_notices.sql | 5 +++ > t/db_dependent/Accounts.t | 38 +++++++++++++++++++++- > 4 files changed, 98 insertions(+), 1 deletion(-) > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index ed1fd3c..4fb2eb4 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -25,6 +25,7 @@ use Data::Dumper; > 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 ); >@@ -77,6 +78,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( > { >@@ -257,6 +260,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/Koha/Account/Offset.pm b/Koha/Account/Offset.pm >index b411653..aaf67a9 100644 >--- a/Koha/Account/Offset.pm >+++ b/Koha/Account/Offset.pm >@@ -35,6 +35,34 @@ Account offsets are used to track the changes in account lines > > =cut > >+=head3 debit >+ >+Returns the fine or fee associated with this offset. >+ >+=cut >+ >+sub debit { >+ my ( $self ) = @_; >+ >+ $self->{_debit} ||= Koha::Account::Lines->find( $self->debit_id ); >+ >+ return $self->{_debit}; >+} >+ >+=head3 credit >+ >+Returns the payment or writeoff associated with this offset. >+ >+=cut >+ >+sub credit { >+ my ( $self ) = @_; >+ >+ $self->{_credit} ||= Koha::Account::Lines->find( $self->credit_id ); >+ >+ return $self->{_credit}; >+} >+ > =head3 _type > > =cut >diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql >index 7a5c4da..4665580 100644 >--- a/installer/data/mysql/en/mandatory/sample_notices.sql >+++ b/installer/data/mysql/en/mandatory/sample_notices.sql >@@ -174,3 +174,8 @@ INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title` > ('circulation', 'AR_PENDING', '', 'Article request - open', 0, 'Article request received', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)\r\n\r\nWe have received your request for an article from <<biblio.title>> (<<items.barcode>>).\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\n\r\nThank you!', 'email'), > ('circulation', 'AR_SLIP', '', 'Article request - print slip', 0, 'Article request', 'Article request:\r\n\r\n<<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>),\r\n\r\nTitle: <<biblio.title>>\r\nBarcode: <<items.barcode>>\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n', 'print'), > ('circulation', 'AR_PROCESSING', '', 'Article request - processing', 0, 'Article request processing', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>),\r\n\r\nWe are now processing your request for an article from <<biblio.title>> (<<items.barcode>>).\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\nThank you!', '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'); >diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t >index 51c094a..107cc28 100644 >--- a/t/db_dependent/Accounts.t >+++ b/t/db_dependent/Accounts.t >@@ -18,7 +18,7 @@ > > use Modern::Perl; > >-use Test::More tests => 23; >+use Test::More tests => 24; > use Test::MockModule; > use Test::Warn; > >@@ -627,4 +627,40 @@ subtest "Koha::Account::chargelostitem tests" => sub { > is( $procfee->amount, "2.040000", "Processing fee if processing fee"); > }; > >+subtest "Koha::Account::Offset tests" => sub { >+ >+ plan tests => 2; >+ >+ Koha::Account::Lines->delete(); >+ Koha::Patrons->delete(); >+ >+ # Create a borrower >+ my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; >+ my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; >+ >+ my $borrower = Koha::Patron->new( { >+ cardnumber => 'chelseahall', >+ surname => 'Hall', >+ firstname => 'Chelsea', >+ } ); >+ $borrower->categorycode( $categorycode ); >+ $borrower->branchcode( $branchcode ); >+ $borrower->store; >+ >+ my $account = Koha::Account->new({ patron_id => $borrower->id }); >+ >+ my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store(); >+ >+ my $id = $account->pay( >+ { >+ amount => 13, >+ } >+ ); >+ >+ my $offset = Koha::Account::Offsets->find( { credit_id => $id } ); >+ >+ is( $offset->credit->id, $id, 'Got correct credit for account offset' ); >+ is( $offset->debit->id, $line->id, 'Got correct debit for account offset' ); >+}; >+ > 1; >-- >2.10.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19191
:
66554
|
68605
|
68812
|
70465
|
70466
|
70471
|
72366
|
72367
|
72370
|
73924
|
74092
|
74093
|
74094
|
74095
|
74104
|
74105
|
74423
|
74424
|
74504
|
74505
|
74506
|
74507
|
74508
|
74625
|
74626
|
74627
|
74628
|
74629
|
74630
|
74631
|
74686
|
75066
|
75067
|
75068
|
75069
|
75070
|
75071
|
75072
|
75093
|
75134