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

(-)a/installer/data/mysql/atomicupdate/bug_19191.sql (+4 lines)
Line 0 Link Here
1
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`)
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'),
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');
(-)a/t/db_dependent/Accounts.t (-2 / +61 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 27;
21
use Test::More tests => 28;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 28-33 use t::lib::Mocks; Link Here
28
use Koha::Account;
28
use Koha::Account;
29
use Koha::Account::Lines;
29
use Koha::Account::Lines;
30
use Koha::Account::Offsets;
30
use Koha::Account::Offsets;
31
use Koha::Notice::Messages;
32
use Koha::Notice::Templates;
31
use Koha::DateUtils qw( dt_from_string );
33
use Koha::DateUtils qw( dt_from_string );
32
34
33
BEGIN {
35
BEGIN {
Lines 949-952 subtest "Koha::Account::Offset credit & debit tests" => sub { Link Here
949
    is( $account_offset->credit, undef, "Koha::Account::Offset->credit returns undef if no associated credit" );
951
    is( $account_offset->credit, undef, "Koha::Account::Offset->credit returns undef if no associated credit" );
950
};
952
};
951
953
954
subtest "Payment notice tests" => sub {
955
956
    plan tests => 8;
957
958
    Koha::Account::Lines->delete();
959
    Koha::Patrons->delete();
960
    Koha::Notice::Messages->delete();
961
    # Create a borrower
962
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
963
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
964
965
    my $borrower = Koha::Patron->new(
966
        {
967
            cardnumber   => 'chelseahall',
968
            surname      => 'Hall',
969
            firstname    => 'Chelsea',
970
            email        => 'chelsea@example.com',
971
            categorycode => $categorycode,
972
            branchcode   => $branchcode,
973
        }
974
    )->store();
975
976
    my $account = Koha::Account->new({ patron_id => $borrower->id });
977
978
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
979
980
    my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
981
    $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
982
    $letter->store();
983
984
    t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
985
986
    my $id = $account->pay( { amount => 1 } );
987
    is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );
988
989
    $id = $account->pay( { amount => 1, type => 'writeoff' } );
990
    is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' );
991
992
    t::lib::Mocks::mock_preference('UseEmailReceipts', '1');
993
994
    $id = $account->pay( { amount => 12 } );
995
    my $notice = Koha::Notice::Messages->search()->next();
996
    is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' );
997
    is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' );
998
    is( $notice->content, 'A payment of 12.00 has been applied to your account.', 'Notice content is correct for payment' );
999
    $notice->delete();
1000
1001
    $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } );
1002
    $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.');
1003
    $letter->store();
1004
1005
    $id = $account->pay( { amount => 13, type => 'writeoff' } );
1006
    $notice = Koha::Notice::Messages->search()->next();
1007
    is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' );
1008
    is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' );
1009
    is( $notice->content, 'A writeoff of 13.00 has been applied to your account.', 'Notice content is correct for writeoff' );
1010
};
1011
952
1;
1012
1;
953
- 

Return to bug 19191