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

(-)a/C4/Members.pm (-27 / +21 lines)
Lines 29-38 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;
39
use Koha::Items;
36
use Koha::News;
40
use Koha::News;
37
use Koha::Patrons;
41
use Koha::Patrons;
38
use Koha::Patron::Categories;
42
use Koha::Patron::Categories;
Lines 675-714 WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; Link Here
675
    return $cnt eq '0E0'? 0: $cnt;
679
    return $cnt eq '0E0'? 0: $cnt;
676
}
680
}
677
681
678
sub GetBorrowerFines {
679
    my ($borrowernumber) = @_;
680
    my $dbh       = C4::Context->dbh;
681
    my $query = qq{
682
        SELECT * FROM accountlines
683
        LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
684
        LEFT JOIN items ON accountlines.itemnumber = items.itemnumber
685
        WHERE accountlines.borrowernumber = ?
686
        ORDER BY accountlines.timestamp
687
    };
688
    my $sth = $dbh->prepare( $query );
689
    $sth->execute( $borrowernumber );
690
    my $data = $sth->fetchall_arrayref({});
691
    return $data;
692
}
693
694
sub FineSlip {
682
sub FineSlip {
695
    my ($borrowernumber, $branch) = @_;
683
    my ($borrowernumber, $branch) = @_;
696
684
697
    #my $now       = POSIX::strftime("%Y-%m-%d", localtime);
685
    my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber });
686
    my $total = $lines->total_outstanding;
687
    my @issueslist;
698
688
699
    my $issueslist = GetBorrowerFines($borrowernumber);
689
    while (my $line = $lines->next) {
690
        next if ($line->amountoutstanding =~ /^0.0+$/);
700
691
701
    my $total = 0.0;
692
        my $item = Koha::Items->find({itemnumber => $line->itemnumber})->unblessed; 
693
        my $issue = Koha::Checkouts->find({issue_id => $line->issue_id}) 
694
        || Koha::Old::Checkouts->find({issue_id => $line->issue_id});
695
        my $dt = dt_from_string( $issue->date_due );
702
696
703
    foreach my $it (@$issueslist){
697
        $item->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
704
        my $dt = dt_from_string( $it->{'date'} );
698
        $item->{'amount'} = sprintf('%.2f', $line->amount);   
705
        $it->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
699
        $item->{'barcode'} = $item ? $item->{barcode} : '-';
706
        $it->{'amount'} = sprintf('%.2f', $it->{'amount'});
700
        $item->{'timestamp'} = $line->timestamp;
707
        $total = $total + $it->{'amount'};
701
        
708
        $it->{'barcode'} = '-' if (!defined($it->{'barcode'}));
702
        push @issueslist, $item;
709
    }
703
    }
710
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
704
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @issueslist;
711
705
    
712
    my %repeat = (
706
    my %repeat = (
713
        'fines' => [ map {
707
        'fines' => [ map {
714
            'fines' => $_,
708
            'fines' => $_,
(-)a/installer/data/mysql/fr-CA/obligatoire/sample_notices.sql (+15 lines)
Lines 362-364 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
362
    [% END %]
362
    [% END %]
363
[% END %]
363
[% END %]
364
", 'email');
364
", 'email');
365
366
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
367
VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines and fees slip', '<<borrowers.firstname>> <<borrowers.surname>><br>
368
<<borrowers.cardnumber>><br>
369
Fines: <<total.fines>>
370
<ul>
371
<fines>
372
<li><<fines.date_due>>, <<fines.amount>><br>
373
Bar code: <<items.barcode>><br>
374
<<fines.description>></li>
375
</fines>
376
</ul>
377
Total: <<total.amount>>
378
', 'print'
379
);
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+15 lines)
Lines 474-476 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
474
    [% END %]
474
    [% END %]
475
[% END %]
475
[% END %]
476
", 'email');
476
", 'email');
477
478
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
479
VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines and fees slip', '<<borrowers.firstname>> <<borrowers.surname>><br>
480
<<borrowers.cardnumber>><br>
481
Fines: <<total.fines>>
482
<ul>
483
<fines>
484
<li><<fines.date_due>>, <<fines.amount>><br>
485
Bar code: <<items.barcode>><br>
486
<<fines.description>></li>
487
</fines>
488
</ul>
489
Total: <<total.amount>>
490
', 'print'
491
);
(-)a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql (+15 lines)
Lines 493-495 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
493
    [% END %]
493
    [% END %]
494
[% END %]
494
[% END %]
495
", 'email');
495
", 'email');
496
497
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
498
VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines and fees slip', '<<borrowers.firstname>> <<borrowers.surname>><br>
499
<<borrowers.cardnumber>><br>
500
Fines: <<total.fines>>
501
<ul>
502
<fines>
503
<li><<fines.date_due>>, <<fines.amount>><br>
504
Bar code: <<items.barcode>><br>
505
<<fines.description>></li>
506
</fines>
507
</ul>
508
Total: <<total.amount>>
509
', 'print'
510
);
(-)a/t/db_dependent/Members/FineSlip.t (-1 / +133 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: <<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
while (my $line = $lines->next){
111
    $fine_amount = sprintf('%.2f', $line->amount);    
112
}
113
114
my $total = sprintf('%.2f', $lines->total_outstanding);
115
116
$date_due = output_pref({ dt => $date_due, dateonly => 1 });
117
118
my $fineslip = FineSlip( $patron->{borrowernumber}, $branchcode );
119
my $expected_slip = <<EOS;
120
New Patron
121
0011223344
122
Fines: $total_fines
123
124
$date_due, $fine_amount
125
Barcode: $barcode
126
127
128
Total: $total
129
EOS
130
131
is( $fineslip->{content}, $expected_slip, 'Fineslip returns slip with 1 item' );
132
133
$schema->storage->txn_rollback;

Return to bug 12285