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

(-)a/C4/Letters.pm (-9 / +12 lines)
Lines 699-710 sub GetPreparedLetter { Link Here
699
               return;
699
               return;
700
    }
700
    }
701
701
702
    my $objects = $params{objects} || {};
702
    my $tables = $params{tables} || {};
703
    my $tables = $params{tables} || {};
703
    my $substitute = $params{substitute} || {};
704
    my $substitute = $params{substitute} || {};
704
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
705
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
705
    my $repeat = $params{repeat};
706
    my $repeat = $params{repeat};
706
    %$tables || %$substitute || $repeat || %$loops
707
    %$tables || %$substitute || $repeat || %$loops || %$objects
707
      or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ),
708
      or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ),
708
         return;
709
         return;
709
    my $want_librarian = $params{want_librarian};
710
    my $want_librarian = $params{want_librarian};
710
711
Lines 779-788 sub GetPreparedLetter { Link Here
779
780
780
    $letter->{content} = _process_tt(
781
    $letter->{content} = _process_tt(
781
        {
782
        {
782
            content => $letter->{content},
783
            content    => $letter->{content},
783
            tables  => $tables,
784
            tables     => $tables,
784
            loops  => $loops,
785
            loops      => $loops,
785
            substitute => $substitute,
786
            substitute => $substitute,
787
            objects    => $objects,
786
        }
788
        }
787
    );
789
    );
788
790
Lines 1453-1461 sub _set_message_status { Link Here
1453
sub _process_tt {
1455
sub _process_tt {
1454
    my ( $params ) = @_;
1456
    my ( $params ) = @_;
1455
1457
1456
    my $content = $params->{content};
1458
    my $content    = $params->{content};
1457
    my $tables = $params->{tables};
1459
    my $tables     = $params->{tables};
1458
    my $loops = $params->{loops};
1460
    my $loops      = $params->{loops};
1461
    my $objects    = $params->{objects};
1459
    my $substitute = $params->{substitute} || {};
1462
    my $substitute = $params->{substitute} || {};
1460
1463
1461
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1464
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
Lines 1471-1477 sub _process_tt { Link Here
1471
        }
1474
        }
1472
    ) or die Template->error();
1475
    ) or die Template->error();
1473
1476
1474
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1477
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
1475
1478
1476
    $content = qq|[% USE KohaDates %]$content|;
1479
    $content = qq|[% USE KohaDates %]$content|;
1477
1480
(-)a/Koha/Account.pm (+28 lines)
Lines 25-30 use Data::Dumper; Link Here
25
use C4::Log qw( logaction );
25
use C4::Log qw( logaction );
26
use C4::Stats qw( UpdateStats );
26
use C4::Stats qw( UpdateStats );
27
27
28
use Koha::Patrons;
28
use Koha::Account::Lines;
29
use Koha::Account::Lines;
29
use Koha::Account::Offsets;
30
use Koha::Account::Offsets;
30
use Koha::DateUtils qw( dt_from_string );
31
use Koha::DateUtils qw( dt_from_string );
Lines 77-82 sub pay { Link Here
77
78
78
    my $userenv = C4::Context->userenv;
79
    my $userenv = C4::Context->userenv;
79
80
81
    my $patron = Koha::Patrons->find( $self->{patron_id} );
82
80
    # We should remove accountno, it is no longer needed
83
    # We should remove accountno, it is no longer needed
81
    my $last = Koha::Account::Lines->search(
84
    my $last = Koha::Account::Lines->search(
82
        {
85
        {
Lines 257-262 sub pay { Link Here
257
        );
260
        );
258
    }
261
    }
259
262
263
    require C4::Letters;
264
    if (
265
        my $letter = C4::Letters::GetPreparedLetter(
266
            module                 => 'circulation',
267
            letter_code            => uc("ACCOUNT_$type"),
268
            message_transport_type => 'email',
269
            lang    => Koha::Patrons->find( $self->{patron_id} )->lang,
270
            objects => {
271
                patron  => scalar Koha::Patrons->find( $self->{patron_id} ),
272
                library => scalar Koha::Libraries->find( $self->{library_id} ),
273
                offsets => \@account_offsets,
274
                credit  => $payment,
275
            },
276
          )
277
      )
278
    {
279
        C4::Letters::EnqueueLetter(
280
            {
281
                letter                 => $letter,
282
                borrowernumber         => $self->{patron_id},
283
                message_transport_type => 'email',
284
            }
285
        ) or warn "can't enqueue letter $letter";
286
    }
287
260
    return $payment->id;
288
    return $payment->id;
261
}
289
}
262
290
(-)a/Koha/Account/Offset.pm (+28 lines)
Lines 35-40 Account offsets are used to track the changes in account lines Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 debit
39
40
Returns the fine or fee associated with this offset.
41
42
=cut
43
44
sub debit {
45
    my ( $self ) = @_;
46
47
    $self->{_debit} ||= Koha::Account::Lines->find( $self->debit_id );
48
49
    return $self->{_debit};
50
}
51
52
=head3 credit
53
54
Returns the payment or writeoff associated with this offset.
55
56
=cut
57
58
sub credit {
59
    my ( $self ) = @_;
60
61
    $self->{_credit} ||= Koha::Account::Lines->find( $self->credit_id );
62
63
    return $self->{_credit};
64
}
65
38
=head3 _type
66
=head3 _type
39
67
40
=cut
68
=cut
(-)a/installer/data/mysql/atomicupdate/bug_19191.sql (+3 lines)
Line 0 Link Here
1
INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
2
('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_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/installer/data/mysql/en/mandatory/sample_notices.sql (+5 lines)
Lines 174-176 INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title` Link Here
174
('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'),
174
('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'),
175
('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'),
175
('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'),
176
('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');
176
('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');
177
178
INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`)
179
    VALUES
180
        ('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'),
181
            ('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 (-1 / +37 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 23;
21
use Test::More tests => 24;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 627-630 subtest "Koha::Account::chargelostitem tests" => sub { Link Here
627
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
627
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
628
};
628
};
629
629
630
subtest "Koha::Account::Offset tests" => sub {
631
632
    plan tests => 2;
633
634
    Koha::Account::Lines->delete();
635
    Koha::Patrons->delete();
636
637
    # Create a borrower
638
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
639
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
640
641
    my $borrower = Koha::Patron->new( {
642
        cardnumber => 'chelseahall',
643
        surname => 'Hall',
644
        firstname => 'Chelsea',
645
    } );
646
    $borrower->categorycode( $categorycode );
647
    $borrower->branchcode( $branchcode );
648
    $borrower->store;
649
650
    my $account = Koha::Account->new({ patron_id => $borrower->id });
651
652
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
653
654
    my $id = $account->pay(
655
        {
656
            amount => 13,
657
        }
658
    );
659
660
    my $offset = Koha::Account::Offsets->find( { credit_id => $id } );
661
662
    is( $offset->credit->id, $id, 'Got correct credit for account offset' );
663
    is( $offset->debit->id, $line->id, 'Got correct debit for account offset' );
664
};
665
630
1;
666
1;
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +13 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 17;
22
use Test::More tests => 18;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use MARC::Record;
25
use MARC::Record;
Lines 42-47 use Koha::Serial; Link Here
42
use Koha::Subscription;
42
use Koha::Subscription;
43
use Koha::Suggestion;
43
use Koha::Suggestion;
44
use Koha::Checkout;
44
use Koha::Checkout;
45
use Koha::Patrons;
45
use Koha::Notice::Messages;
46
use Koha::Notice::Messages;
46
use Koha::Notice::Templates;
47
use Koha::Notice::Templates;
47
use Koha::Patron::Modification;
48
use Koha::Patron::Modification;
Lines 134-139 $prepared_letter = GetPreparedLetter( Link Here
134
);
135
);
135
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref' );
136
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref' );
136
137
138
$prepared_letter = GetPreparedLetter(
139
    (
140
        module      => 'test',
141
        letter_code => 'TEST_PATRON',
142
        objects      => {
143
            borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ),
144
        },
145
    )
146
);
147
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' );
148
137
$sth->execute( "TEST_BIBLIO", "[% biblio.id %]" );
149
$sth->execute( "TEST_BIBLIO", "[% biblio.id %]" );
138
$prepared_letter = GetPreparedLetter(
150
$prepared_letter = GetPreparedLetter(
139
    (
151
    (
140
- 

Return to bug 19191