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 79-84 sub pay { Link Here
79
80
80
    my $userenv = C4::Context->userenv;
81
    my $userenv = C4::Context->userenv;
81
82
83
    my $patron = Koha::Patrons->find( $self->{patron_id} );
84
82
    # We should remove accountno, it is no longer needed
85
    # We should remove accountno, it is no longer needed
83
    my $last = Koha::Account::Lines->search(
86
    my $last = Koha::Account::Lines->search(
84
        {
87
        {
Lines 260-265 sub pay { Link Here
260
        );
263
        );
261
    }
264
    }
262
265
266
    require C4::Letters;
267
    if (
268
        my $letter = C4::Letters::GetPreparedLetter(
269
            module                 => 'circulation',
270
            letter_code            => uc("ACCOUNT_$type"),
271
            message_transport_type => 'email',
272
            lang    => Koha::Patrons->find( $self->{patron_id} )->lang,
273
            objects => {
274
                patron  => scalar Koha::Patrons->find( $self->{patron_id} ),
275
                library => scalar Koha::Libraries->find( $self->{library_id} ),
276
                offsets => \@account_offsets,
277
                credit  => $payment,
278
            },
279
          )
280
      )
281
    {
282
        C4::Letters::EnqueueLetter(
283
            {
284
                letter                 => $letter,
285
                borrowernumber         => $self->{patron_id},
286
                message_transport_type => 'email',
287
            }
288
        ) or warn "can't enqueue letter $letter";
289
    }
290
263
    return $payment->id;
291
    return $payment->id;
264
}
292
}
265
293
(-)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 => 26;
21
use Test::More tests => 27;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 904-907 subtest "Koha::Account::Line::void tests" => sub { Link Here
904
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
904
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
905
};
905
};
906
906
907
subtest "Koha::Account::Offset tests" => sub {
908
909
    plan tests => 2;
910
911
    Koha::Account::Lines->delete();
912
    Koha::Patrons->delete();
913
914
    # Create a borrower
915
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
916
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
917
918
    my $borrower = Koha::Patron->new( {
919
        cardnumber => 'chelseahall',
920
        surname => 'Hall',
921
        firstname => 'Chelsea',
922
    } );
923
    $borrower->categorycode( $categorycode );
924
    $borrower->branchcode( $branchcode );
925
    $borrower->store;
926
927
    my $account = Koha::Account->new({ patron_id => $borrower->id });
928
929
    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
930
931
    my $id = $account->pay(
932
        {
933
            amount => 13,
934
        }
935
    );
936
937
    my $offset = Koha::Account::Offsets->find( { credit_id => $id } );
938
939
    is( $offset->credit->id, $id, 'Got correct credit for account offset' );
940
    is( $offset->debit->id, $line->id, 'Got correct debit for account offset' );
941
};
942
907
1;
943
1;
908
- 

Return to bug 19191