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

(-)a/Koha/Account.pm (+28 lines)
Lines 26-31 use List::MoreUtils qw( uniq ); Link Here
26
use C4::Log qw( logaction );
26
use C4::Log qw( logaction );
27
use C4::Stats qw( UpdateStats );
27
use C4::Stats qw( UpdateStats );
28
28
29
use Koha::Patrons;
29
use Koha::Account::Lines;
30
use Koha::Account::Lines;
30
use Koha::Account::Offsets;
31
use Koha::Account::Offsets;
31
use Koha::DateUtils qw( dt_from_string );
32
use Koha::DateUtils qw( dt_from_string );
Lines 78-83 sub pay { Link Here
78
79
79
    my $userenv = C4::Context->userenv;
80
    my $userenv = C4::Context->userenv;
80
81
82
    my $patron = Koha::Patrons->find( $self->{patron_id} );
83
81
    # We should remove accountno, it is no longer needed
84
    # We should remove accountno, it is no longer needed
82
    my $last = Koha::Account::Lines->search(
85
    my $last = Koha::Account::Lines->search(
83
        {
86
        {
Lines 258-263 sub pay { Link Here
258
        );
261
        );
259
    }
262
    }
260
263
264
    require C4::Letters;
265
    if (
266
        my $letter = C4::Letters::GetPreparedLetter(
267
            module                 => 'circulation',
268
            letter_code            => uc("ACCOUNT_$type"),
269
            message_transport_type => 'email',
270
            lang    => Koha::Patrons->find( $self->{patron_id} )->lang,
271
            objects => {
272
                patron  => scalar Koha::Patrons->find( $self->{patron_id} ),
273
                library => scalar Koha::Libraries->find( $self->{library_id} ),
274
                offsets => \@account_offsets,
275
                credit  => $payment,
276
            },
277
          )
278
      )
279
    {
280
        C4::Letters::EnqueueLetter(
281
            {
282
                letter                 => $letter,
283
                borrowernumber         => $self->{patron_id},
284
                message_transport_type => 'email',
285
            }
286
        ) or warn "can't enqueue letter $letter";
287
    }
288
261
    return $payment->id;
289
    return $payment->id;
262
}
290
}
263
291
(-)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 175-177 INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title` Link Here
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
('circulation', 'CHECKOUT_NOTE', '', 'Checkout note on item set by patron', '0', 'Checkout note', '<<borrowers.firstname>> <<borrowers.surname>> has added a note to the item <<biblio.title>> - <<biblio.author>> (<<biblio.biblionumber>>).','email');
177
('circulation', 'CHECKOUT_NOTE', '', 'Checkout note on item set by patron', '0', 'Checkout note', '<<borrowers.firstname>> <<borrowers.surname>> has added a note to the item <<biblio.title>> - <<biblio.author>> (<<biblio.biblionumber>>).','email');
178
179
INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`)
180
    VALUES
181
        ('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'),
182
            ('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 => 25;
21
use Test::More tests => 26;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 844-847 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
844
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
844
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
845
};
845
};
846
846
847
subtest "Koha::Account::Offset tests" => sub {
848
849
    plan tests => 2;
850
851
    Koha::Account::Lines->delete();
852
    Koha::Patrons->delete();
853
854
    # Create a borrower
855
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
856
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
857
858
    my $borrower = Koha::Patron->new( {
859
        cardnumber => 'chelseahall',
860
        surname => 'Hall',
861
        firstname => 'Chelsea',
862
    } );
863
    $borrower->categorycode( $categorycode );
864
    $borrower->branchcode( $branchcode );
865
    $borrower->store;
866
867
    my $account = Koha::Account->new({ patron_id => $borrower->id });
868
869
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
870
871
    my $id = $account->pay(
872
        {
873
            amount => 13,
874
        }
875
    );
876
877
    my $offset = Koha::Account::Offsets->find( { credit_id => $id } );
878
879
    is( $offset->credit->id, $id, 'Got correct credit for account offset' );
880
    is( $offset->debit->id, $line->id, 'Got correct debit for account offset' );
881
};
882
847
1;
883
1;
848
- 

Return to bug 19191