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

(-)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/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 (-2 / +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;
631
- 

Return to bug 19191