3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 6;
22 use t::lib::TestBuilder;
25 use C4::Circulation qw( CanBookBeIssued );
27 use Koha::Account::Lines;
28 use Koha::Account::Offsets;
29 use Koha::Patron::Relationship;
31 my $schema = Koha::Database->new->schema;
32 $schema->storage->txn_begin;
34 my $builder = t::lib::TestBuilder->new();
36 my $item = $builder->build(
40 biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
47 my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
48 my $patron = $builder->build_object(
50 class => 'Koha::Patrons',
52 categorycode => $patron_category->{categorycode},
57 my $guarantee = $builder->build_object(
59 class => 'Koha::Patrons',
61 patron_category => $patron_category->{categorycode},
66 my $r = $builder->build_object(
68 class => 'Koha::Patron::Relationships',
70 guarantor_id => $patron->id,
71 guarantee_id => $guarantee->id,
72 relationship => 'parent',
77 t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', '5.00' );
78 t::lib::Mocks::mock_preference( 'AllowFineOverride', '' );
80 my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
81 is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
83 my $account = Koha::Account->new( { patron_id => $guarantee->id } );
84 $account->add_debit({ amount => 10.00, type => 'lost_item', interface => 'test' });
85 ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
86 is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
88 my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
89 is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
90 is( $accountline->accounttype, "LOST", "Account type is LOST" );
92 my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
93 is( $offset->type, 'Lost Item', 'Got correct offset type' );
94 is( $offset->amount, '10.000000', 'Got amount of $10.00' );
96 $schema->storage->txn_rollback;