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 685-723 WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; Link Here
685
    return $cnt eq '0E0'? 0: $cnt;
689
    return $cnt eq '0E0'? 0: $cnt;
686
}
690
}
687
691
688
sub GetBorrowerFines {
692
=head2 FineSlip
689
    my ($borrowernumber) = @_;
693
690
    my $dbh       = C4::Context->dbh;
694
    Returns letter hash and populates FINESLIP.
691
    my $query = qq{
695
692
        SELECT * FROM accountlines
696
=cut
693
        LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
694
        LEFT JOIN items ON accountlines.itemnumber = items.itemnumber
695
        WHERE accountlines.borrowernumber = ?
696
        ORDER BY accountlines.timestamp
697
    };
698
    my $sth = $dbh->prepare( $query );
699
    $sth->execute( $borrowernumber );
700
    my $data = $sth->fetchall_arrayref({});
701
    return $data;
702
}
703
697
704
sub FineSlip {
698
sub FineSlip {
705
    my ($borrowernumber, $branch) = @_;
699
    my ($borrowernumber, $branch) = @_;
706
700
707
    #my $now       = POSIX::strftime("%Y-%m-%d", localtime);
701
    my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber });
702
    my $total = $lines->total_outstanding;
703
    my @issueslist;
704
705
    while (my $line = $lines->next) {
706
        next if ($line->amountoutstanding =~ /^0.0+$/);
708
707
709
    my $issueslist = GetBorrowerFines($borrowernumber);
708
        my $item = Koha::Items->find({itemnumber => $line->itemnumber});
709
        $item = $item ? $item->unblessed : undef;
710
        my $issue = Koha::Checkouts->find({issue_id => $line->issue_id})
711
        || Koha::Old::Checkouts->find({issue_id => $line->issue_id});
712
        my $dt = dt_from_string( $issue->date_due );
710
713
711
    my $total = 0.0;
714
        $item->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
715
        $item->{'amount'} = sprintf('%.2f', $line->amount);
716
        $item->{'barcode'} = $item->{barcode} ? $item->{barcode} : '-';
717
        $item->{'timestamp'} = $line->timestamp;
718
        $item->{'description'} = $line->description;
712
719
713
    foreach my $it (@$issueslist){
720
        push @issueslist, $item;
714
        my $dt = dt_from_string( $it->{'date'} );
715
        $it->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 });
716
        $it->{'amount'} = sprintf('%.2f', $it->{'amount'});
717
        $total = $total + $it->{'amount'};
718
        $it->{'barcode'} = '-' if (!defined($it->{'barcode'}));
719
    }
721
    }
720
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
722
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @issueslist;
721
723
722
    my %repeat = (
724
    my %repeat = (
723
        'fines' => [ map {
725
        'fines' => [ map {
(-)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