@@ -, +, @@ defaulting to disabled --- Koha/Account.pm | 50 +++++++++++----------- installer/data/mysql/atomicupdate/bug_19191.sql | 7 ++- installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/patrons.pref | 6 +++ t/db_dependent/Accounts.t | 24 ++++++++--- 5 files changed, 56 insertions(+), 32 deletions(-) --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -263,31 +263,33 @@ 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, - tables => { - borrowers => $self->{patron_id}, - branches => $self->{library_id}, - }, - substitute => { - credit => $payment, - offsets => scalar Koha::Account::Offsets->search( { id => { -in => [ map { $_->id } @account_offsets ] } } ), - }, - ) - ) - { - C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $self->{patron_id}, + if ( C4::Context->preference('UseEmailReceipts') ) { + require C4::Letters; + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => uc("ACCOUNT_$type"), message_transport_type => 'email', - } - ) or warn "can't enqueue letter $letter"; + lang => Koha::Patrons->find( $self->{patron_id} )->lang, + tables => { + borrowers => $self->{patron_id}, + branches => $self->{library_id}, + }, + substitute => { + credit => $payment, + offsets => scalar Koha::Account::Offsets->search( { id => { -in => [ map { $_->id } @account_offsets ] } } ), + }, + ) + ) + { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $self->{patron_id}, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } } return $payment->id; --- a/installer/data/mysql/atomicupdate/bug_19191.sql +++ a/installer/data/mysql/atomicupdate/bug_19191.sql @@ -1,4 +1,9 @@ INSERT IGNORE 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_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'); + +$dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) + VALUES ('UseEmailReceipts','0','','Send email receipts for payments and write-offs','YesNo') +}); --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -593,6 +593,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('useDaysMode','Calendar','Calendar|Days|Datedue','Choose the method for calculating due date: select Calendar to use the holidays module, and Days to ignore the holidays module','Choice'), ('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'), ('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'), +('UseEmailReceipts','0','','Send email receipts for payments and write-offs','YesNo'), ('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'), ('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'), ('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -7,6 +7,12 @@ Patrons: no: "Don't send" - an email to newly created patrons with their account details. - + - pref: UseEmailReceipts + choices: + yes: Send + no: "Don't send" + - email receipts to patrons for payments and writeoffs. + - - "Use" - pref: AutoEmailPrimaryAddress default: "OFF" --- a/t/db_dependent/Accounts.t +++ a/t/db_dependent/Accounts.t @@ -905,7 +905,7 @@ subtest "Koha::Account::Line::void tests" => sub { subtest "Payment notice tests" => sub { - plan tests => 6; + plan tests => 8; Koha::Account::Lines->delete(); Koha::Patrons->delete(); @@ -933,22 +933,32 @@ subtest "Payment notice tests" => sub { $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.'); $letter->store(); - my $id = $account->pay( { amount => 13 } ); + t::lib::Mocks::mock_preference('UseEmailReceipts', '0'); + + my $id = $account->pay( { amount => 1 } ); + is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' ); + + $id = $account->pay( { amount => 1, type => 'writeoff' } ); + is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' ); + + t::lib::Mocks::mock_preference('UseEmailReceipts', '1'); + + $id = $account->pay( { amount => 12 } ); my $notice = Koha::Notice::Messages->search()->next(); - is( $notice->subject, 'Account Payment', 'Notice subject is correct for payment' ); + is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' ); is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' ); - is( $notice->content, 'A payment of 13.00 has been applied to your account.', 'Notice content is correct for payment' ); + is( $notice->content, 'A payment of 12.00 has been applied to your account.', 'Notice content is correct for payment' ); $notice->delete(); $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } ); $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.'); $letter->store(); - $id = $account->pay( { amount => 14, type => 'writeoff' } ); + $id = $account->pay( { amount => 13, type => 'writeoff' } ); $notice = Koha::Notice::Messages->search()->next(); - is( $notice->subject, 'Account Writeoff', 'Notice subject is correct for payment' ); + is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' ); is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' ); - is( $notice->content, 'A writeoff of 14.00 has been applied to your account.', 'Notice content is correct for writeoff' ); + is( $notice->content, 'A writeoff of 13.00 has been applied to your account.', 'Notice content is correct for writeoff' ); }; 1; --