View | Details | Raw Unified | Return to bug 19191
Collapse All | Expand All

(-)a/Koha/Account.pm (-24 / +26 lines)
Lines 263-293 sub pay { Link Here
263
        );
263
        );
264
    }
264
    }
265
265
266
    require C4::Letters;
266
    if ( C4::Context->preference('UseEmailReceipts') ) {
267
    if (
267
        require C4::Letters;
268
        my $letter = C4::Letters::GetPreparedLetter(
268
        if (
269
            module                 => 'circulation',
269
            my $letter = C4::Letters::GetPreparedLetter(
270
            letter_code            => uc("ACCOUNT_$type"),
270
                module                 => 'circulation',
271
            message_transport_type => 'email',
271
                letter_code            => uc("ACCOUNT_$type"),
272
            lang    => Koha::Patrons->find( $self->{patron_id} )->lang,
273
            tables => {
274
                borrowers       => $self->{patron_id},
275
                branches        => $self->{library_id},
276
            },
277
            substitute => {
278
                credit => $payment,
279
                offsets => scalar Koha::Account::Offsets->search( { id => { -in => [ map { $_->id } @account_offsets ] } } ),
280
            },
281
          )
282
      )
283
    {
284
        C4::Letters::EnqueueLetter(
285
            {
286
                letter                 => $letter,
287
                borrowernumber         => $self->{patron_id},
288
                message_transport_type => 'email',
272
                message_transport_type => 'email',
289
            }
273
                lang    => Koha::Patrons->find( $self->{patron_id} )->lang,
290
        ) or warn "can't enqueue letter $letter";
274
                tables => {
275
                    borrowers       => $self->{patron_id},
276
                    branches        => $self->{library_id},
277
                },
278
                substitute => {
279
                    credit => $payment,
280
                    offsets => scalar Koha::Account::Offsets->search( { id => { -in => [ map { $_->id } @account_offsets ] } } ),
281
                },
282
              )
283
          )
284
        {
285
            C4::Letters::EnqueueLetter(
286
                {
287
                    letter                 => $letter,
288
                    borrowernumber         => $self->{patron_id},
289
                    message_transport_type => 'email',
290
                }
291
            ) or warn "can't enqueue letter $letter";
292
        }
291
    }
293
    }
292
294
293
    return $payment->id;
295
    return $payment->id;
(-)a/installer/data/mysql/atomicupdate/bug_19191.sql (-1 / +6 lines)
Lines 1-4 Link Here
1
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`)
1
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`)
2
    VALUES
2
    VALUES
3
        ('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'),
3
        ('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'),
4
            ('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');
4
            ('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');
5
6
$dbh->do(q{
7
    INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
8
    VALUES ('UseEmailReceipts','0','','Send email receipts for payments and write-offs','YesNo')
9
});
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 593-598 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
593
('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'),
593
('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'),
594
('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'),
594
('useDefaultReplacementCost', '0', NULL, 'default replacement cost defined in item type', 'YesNo'),
595
('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'),
595
('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'),
596
('UseEmailReceipts','0','','Send email receipts for payments and write-offs','YesNo'),
596
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
597
('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
597
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
598
('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
598
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
599
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 6-11 Patrons: Link Here
6
               yes: Send
6
               yes: Send
7
               no: "Don't send"
7
               no: "Don't send"
8
         - an email to newly created patrons with their account details.
8
         - an email to newly created patrons with their account details.
9
     -
10
         - pref: UseEmailReceipts
11
           choices:
12
               yes: Send
13
               no: "Don't send"
14
         - email receipts to patrons for payments and writeoffs.
9
     -
15
     -
10
         - "Use"
16
         - "Use"
11
         - pref: AutoEmailPrimaryAddress
17
         - pref: AutoEmailPrimaryAddress
(-)a/t/db_dependent/Accounts.t (-8 / +17 lines)
Lines 908-914 subtest "Koha::Account::Line::void tests" => sub { Link Here
908
908
909
subtest "Payment notice tests" => sub {
909
subtest "Payment notice tests" => sub {
910
910
911
    plan tests => 6;
911
    plan tests => 8;
912
912
913
    Koha::Account::Lines->delete();
913
    Koha::Account::Lines->delete();
914
    Koha::Patrons->delete();
914
    Koha::Patrons->delete();
Lines 936-957 subtest "Payment notice tests" => sub { Link Here
936
    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
936
    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
937
    $letter->store();
937
    $letter->store();
938
938
939
    my $id = $account->pay( { amount => 13 } );
939
    t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
940
941
    my $id = $account->pay( { amount => 1 } );
942
    is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
943
944
    $id = $account->pay( { amount => 1, type => 'writeoff' } );
945
    is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
946
947
    t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
948
949
    $id = $account->pay( { amount => 12 } );
940
    my $notice = Koha::Notice::Messages->search()->next();
950
    my $notice = Koha::Notice::Messages->search()->next();
941
    is( $notice->subject, 'Account Payment', 'Notice subject is correct for payment' );
951
    is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' );
942
    is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
952
    is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
943
    is( $notice->content, 'A payment of 13.00 has been applied to your account.', 'Notice content is correct for payment' );
953
    is( $notice->content, 'A payment of 12.00 has been applied to your account.', 'Notice content is correct for payment' );
944
    $notice->delete();
954
    $notice->delete();
945
955
946
    $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } );
956
    $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } );
947
    $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.');
957
    $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.');
948
    $letter->store();
958
    $letter->store();
949
959
950
    $id = $account->pay( { amount => 14, type => 'writeoff' } );
960
    $id = $account->pay( { amount => 13, type => 'writeoff' } );
951
    $notice = Koha::Notice::Messages->search()->next();
961
    $notice = Koha::Notice::Messages->search()->next();
952
    is( $notice->subject, 'Account Writeoff', 'Notice subject is correct for payment' );
962
    is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
953
    is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
963
    is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
954
    is( $notice->content, 'A writeoff of 14.00 has been applied to your account.', 'Notice content is correct for writeoff' );
964
    is( $notice->content, 'A writeoff of 13.00 has been applied to your account.', 'Notice content is correct for writeoff' );
955
};
965
};
956
966
957
1;
967
1;
958
- 

Return to bug 19191