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

(-)a/C4/Members.pm (-25 / +27 lines)
Lines 29-39 use C4::Reserves; Link Here
29
use C4::Accounts;
29
use C4::Accounts;
30
use C4::Letters qw( GetPreparedLetter );
30
use C4::Letters qw( GetPreparedLetter );
31
use DateTime;
31
use DateTime;
32
use Koha::Account::Lines;
33
use Koha::Checkouts;
34
use Koha::Old::Checkouts;
32
use Koha::Database;
35
use Koha::Database;
33
use Koha::DateUtils qw( dt_from_string output_pref );
36
use Koha::DateUtils qw( dt_from_string output_pref );
34
use Koha::Database;
37
use Koha::Database;
35
use Koha::Holds;
38
use Koha::Holds;
36
use Koha::AdditionalContents;
39
use Koha::AdditionalContents;
40
use Koha::Items;
37
use Koha::Patrons;
41
use Koha::Patrons;
38
use Koha::Patron::Categories;
42
use Koha::Patron::Categories;
39
43
Lines 684-722 WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; Link Here
684
    return $cnt eq '0E0'? 0: $cnt;
688
    return $cnt eq '0E0'? 0: $cnt;
685
}
689
}
686
690
687
sub GetBorrowerFines {
691
=head2 FineSlip
688
    my ($borrowernumber) = @_;
692
689
    my $dbh       = C4::Context->dbh;
693
    Returns letter hash and populates FINESLIP.
690
    my $query = qq{
694
691
        SELECT * FROM accountlines
695
=cut
692
        LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
693
        LEFT JOIN items ON accountlines.itemnumber = items.itemnumber
694
        WHERE accountlines.borrowernumber = ?
695
        ORDER BY accountlines.timestamp
696
    };
697
    my $sth = $dbh->prepare( $query );
698
    $sth->execute( $borrowernumber );
699
    my $data = $sth->fetchall_arrayref({});
700
    return $data;
701
}
702
696
703
sub FineSlip {
697
sub FineSlip {
704
    my ($borrowernumber, $branch) = @_;
698
    my ($borrowernumber, $branch) = @_;
705
699
706
    #my $now       = POSIX::strftime("%Y-%m-%d", localtime);
700
    my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber });
701
    my $total = $lines->total_outstanding;
702
    my @issueslist;
703
704
    while (my $line = $lines->next) {
705
        next if ($line->amountoutstanding =~ /^0.0+$/);
707
706
708
    my $issueslist = GetBorrowerFines($borrowernumber);
707
        my $item = Koha::Items->find({itemnumber => $line->itemnumber});
708
        $item = $item ? $item->unblessed : undef;
709
        my $issue = Koha::Checkouts->find({issue_id => $line->issue_id})
710
        || Koha::Old::Checkouts->find({issue_id => $line->issue_id});
711
        my $dt = dt_from_string( $issue->date_due );
709
712
710
    my $total = 0.0;
713
        $item->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
714
        $item->{'amount'} = sprintf('%.2f', $line->amount);
715
        $item->{'barcode'} = $item->{barcode} ? $item->{barcode} : '-';
716
        $item->{'timestamp'} = $line->timestamp;
717
        $item->{'description'} = $line->description;
711
718
712
    foreach my $it (@$issueslist){
719
        push @issueslist, $item;
713
        my $dt = dt_from_string( $it->{'date'} );
714
        $it->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
715
        $it->{'amount'} = sprintf('%.2f', $it->{'amount'});
716
        $total = $total + $it->{'amount'};
717
        $it->{'barcode'} = '-' if (!defined($it->{'barcode'}));
718
    }
720
    }
719
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
721
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @issueslist;
720
722
721
    my %repeat = (
723
    my %repeat = (
722
        'fines' => [ map {
724
        'fines' => [ map {
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+15 lines)
Lines 475-477 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
475
    [% END %]
475
    [% END %]
476
[% END %]
476
[% END %]
477
", 'email');
477
", 'email');
478
479
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
480
VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines', '<<borrowers.firstname>> <<borrowers.surname>><br>
481
<<borrowers.cardnumber>><br>
482
Fines: <<total.fines>>
483
<ul>
484
<fines>
485
<li><<fines.date_due>>, <<fines.amount>><br>
486
Bar code: <<items.barcode>><br>
487
<<fines.description>></li>
488
</fines>
489
</ul>
490
Total: <<total.amount>>
491
', 'print'
492
);
(-)a/t/db_dependent/Members/FineSlip.t (-1 / +135 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::MockModule;
22
use Test::MockTime qw( set_fixed_time );
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
25
26
use C4::Circulation qw( AddIssue AddReturn );
27
use C4::Members qw( FineSlip );
28
use C4::Overdues qw( UpdateFine );
29
30
use Koha::CirculationRules;
31
use Koha::DateUtils qw( dt_from_string output_pref );
32
33
my $schema = Koha::Database->schema;
34
$schema->storage->txn_begin;
35
my $dbh = C4::Context->dbh;
36
37
$dbh->do(q|DELETE FROM letter|);
38
$dbh->do(q|DELETE FROM circulation_rules|);
39
40
my $builder = t::lib::TestBuilder->new;
41
set_fixed_time(CORE::time());
42
43
my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
44
my $itemtype     = $builder->build({ source => 'Itemtype' })->{ itemtype };
45
46
my $item  = $builder->build_sample_item({
47
    homebranch => $branchcode,
48
    itype      => $itemtype
49
});
50
51
my $issuingrule = Koha::CirculationRules->set_rules(
52
    {
53
        categorycode => undef,
54
        itemtype     => undef,
55
        branchcode   => undef,
56
        rules        => {
57
            fine                   => 1,
58
            finedays               => 0,
59
            chargeperiod           => 7,
60
            chargeperiod_charge_at => 0,
61
            lengthunit             => 'days',
62
            issuelength            => 1,
63
        }
64
    }
65
);
66
67
my $module = Test::MockModule->new('C4::Context');
68
$module->mock( 'userenv', sub { { branch => $branchcode } } );
69
70
my $slip_content = <<EOS;
71
<<borrowers.firstname>> <<borrowers.surname>>
72
<<borrowers.cardnumber>>
73
Fines and fees: <<total.fines>>
74
<fines>
75
<<fines.date_due>>, <<fines.amount>>
76
Barcode: <<items.barcode>>
77
<<fines.description>>
78
</fines>
79
Total: <<total.amount>>
80
EOS
81
82
$dbh->do(q|
83
    INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type) VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines and fees slip', ?, 'print')
84
|, {}, $slip_content);
85
86
my $patron = $builder->build(
87
    {
88
        source => 'Borrower',
89
        value  => {
90
            surname    => 'Patron',
91
            firstname  => 'New',
92
            cardnumber => '0011223344',
93
            branchcode => $branchcode
94
        },
95
    }
96
);
97
98
my $today = dt_from_string();
99
my $date_due = dt_from_string->subtract_duration( DateTime::Duration->new( days => 13 ) );
100
my $issue_date = dt_from_string->subtract_duration( DateTime::Duration->new( days => 14 ) );
101
my $barcode = $item->barcode;
102
103
my $issue = AddIssue($patron, $barcode, $date_due, undef, $issue_date);
104
t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
105
AddReturn( $barcode, $branchcode);
106
107
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->{borrowernumber} });
108
my $total_fines = $lines->count;
109
my $fine_amount = 0;
110
my $description = '';
111
while (my $line = $lines->next){
112
    $fine_amount = sprintf('%.2f', $line->amount);
113
    $description = $line->description;
114
}
115
116
my $total = sprintf('%.2f', $lines->total_outstanding);
117
118
$date_due = output_pref({ dt => $date_due, dateonly => 1 });
119
120
my $fineslip = FineSlip( $patron->{borrowernumber}, $branchcode );
121
my $expected_slip = <<EOS;
122
New Patron
123
0011223344
124
Fines and fees: $total_fines
125
126
$date_due, $fine_amount
127
Barcode: $barcode
128
$description
129
130
Total: $total
131
EOS
132
133
is( $fineslip->{content}, $expected_slip, 'Fineslip returns slip with 1 item' );
134
135
$schema->storage->txn_rollback;

Return to bug 12285