|
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; |