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

(-)a/C4/Reserves.pm (-13 / +19 lines)
Lines 774-800 SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>? Link Here
774
    my ($fee) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
774
    my ($fee) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
775
    $fee += 0;
775
    $fee += 0;
776
    my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
776
    my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
777
    if ( $fee and $fee > 0 and $hold_fee_mode eq 'not_always' ) {
777
778
    if ( $fee and $fee > 0 and ( $hold_fee_mode eq 'not_always' or $hold_fee_mode eq 'issued_or_reserved' ) ) {
778
779
779
        # This is a reconstruction of the old code:
780
        # This is a reconstruction of the old code:
780
        # Compare number of items with items issued, and optionally check holds
781
        # Compare number of items with items issued, and optionally check holds
781
        # If not all items are issued and there are no holds: charge no fee
782
        # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
782
        # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
783
        my ( $notissued, $reserved );
783
        my $notissued = $dbh->selectrow_array(
784
        ($notissued) = $dbh->selectrow_array(
785
            $issue_qry, undef,
784
            $issue_qry, undef,
786
            ($biblionumber)
785
            ($biblionumber)
787
        );
786
        );
788
        if ( $notissued == 0 ) {
787
        my $reserved = $dbh->selectrow_array(
788
            $holds_qry, undef,
789
            ( $biblionumber, $borrowernumber )
790
        );
789
791
790
            # all items are issued
792
        if ( $hold_fee_mode eq 'issued_or_reserved' ) {
791
            ($reserved) = $dbh->selectrow_array(
793
            unless ( $notissued == 0 or $reserved > 0 ) {
792
                $holds_qry, undef,
794
793
                ( $biblionumber, $borrowernumber )
795
                # items still available to be checked out OR record has no reserves
794
            );
796
                $fee = 0;
795
            $fee = 0 if $reserved == 0;
797
            }
796
        } else {
798
        } elsif ( $hold_fee_mode eq 'not_always' ) {
797
            $fee = 0;
799
            unless ( $notissued == 0 and $reserved > 0 ) {
800
801
                # items still available to be checked out AND record has no reserves
802
                $fee = 0;
803
            }
798
        }
804
        }
799
    }
805
    }
800
    return $fee;
806
    return $fee;
(-)a/installer/data/mysql/atomicupdate/bug_32142_-_add_issued_or_reserved_option_to_HoldFeeMode_syspref.pl (-4 / +6 lines)
Lines 1-12 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "32142",
4
    bug_number  => "32142",
5
    description => "Add issued_or_reserved option to HoldFeeMode system preference",
5
    description => "Add issued_or_reserved option to HoldFeeMode system preference",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do(q{ UPDATE systempreferences SET options = 'any_time_is_placed|not_always|issued_or_reserved|any_time_is_collected' where variable = 'HoldFeeMode' });
10
        $dbh->do(
11
            q{ UPDATE systempreferences SET options = 'any_time_is_placed|not_always|issued_or_reserved|any_time_is_collected' where variable = 'HoldFeeMode' }
12
        );
11
    },
13
    },
12
};
14
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+1 lines)
Lines 1222-1227 Circulation: Link Here
1222
              choices:
1222
              choices:
1223
                  any_time_is_placed: "any time a hold is placed."
1223
                  any_time_is_placed: "any time a hold is placed."
1224
                  not_always: "only if all items are checked out and the record has at least one hold already."
1224
                  not_always: "only if all items are checked out and the record has at least one hold already."
1225
                  issued_or_reserved: "either if all items are checked out or the record has at least one hold already."
1225
                  any_time_is_collected: "any time a hold is collected."
1226
                  any_time_is_collected: "any time a hold is collected."
1226
        -
1227
        -
1227
            - pref: useDefaultReplacementCost
1228
            - pref: useDefaultReplacementCost
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-4 / +43 lines)
Lines 115-135 my $item2 = $builder->build_sample_item( Link Here
115
);
115
);
116
116
117
subtest 'GetReserveFee' => sub {
117
subtest 'GetReserveFee' => sub {
118
    plan tests => 6;
118
    plan tests => 8;
119
119
120
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} )
120
    C4::Circulation::AddIssue( $patron1, $item1->barcode, '2015-12-31', 0, undef, 0, {} )
121
        ;    # the date does not really matter
121
        ;    # the date does not really matter
122
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} )
122
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} )
123
        ;    # the date does not really matter
123
        ;    # the date does not really matter
124
    my $acc2 = acctlines( $patron2->borrowernumber );
124
    my $acc2 = acctlines( $patron2->borrowernumber );
125
    my $res1 = addreserve( $patron1->borrowernumber );
126
125
127
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
126
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
128
    my $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
127
    my $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
128
    is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
129
130
    my $res1 = addreserve( $patron1->borrowernumber );
131
132
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'issued_or_reserved' );
133
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
134
    is( int($fee), 2, 'HoldFeeMode=issued_or_reserved, Patron 2 should be charged' );
135
    C4::Circulation::AddIssue( $patron3, $item2->barcode, '2015-12-31', 0, undef, 0, {} )
136
        ;    # the date does not really matter
137
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
129
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
138
    is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
130
    C4::Reserves::ChargeReserveFee( $patron2->borrowernumber, $fee, $biblio->title );
139
    C4::Reserves::ChargeReserveFee( $patron2->borrowernumber, $fee, $biblio->title );
131
    is( acctlines( $patron2->borrowernumber ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
140
    is( acctlines( $patron2->borrowernumber ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
132
141
142
    t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
133
    # If we delete the reserve, there should be no charge
143
    # If we delete the reserve, there should be no charge
134
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->borrowernumber ) );
144
    $dbh->do( "DELETE FROM reserves WHERE borrowernumber = ?", undef, ( $patron1->borrowernumber ) );
135
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
145
    $fee = C4::Reserves::GetReserveFee( $patron2->borrowernumber, $biblio->biblionumber );
Lines 179-185 subtest 'Integration with AddReserve' => sub { Link Here
179
    };
189
    };
180
190
181
    subtest 'Items are issued' => sub {
191
    subtest 'Items are issued' => sub {
182
        plan tests => 4;
192
        plan tests => 7;
183
193
184
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item1->itemnumber );
194
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item1->itemnumber );
185
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item2->itemnumber );
195
        $dbh->do( "DELETE FROM issues       WHERE itemnumber=?", undef, $item2->itemnumber );
Lines 194-199 subtest 'Integration with AddReserve' => sub { Link Here
194
            'not_always - Patron should not be charged if items are not all checked out'
204
            'not_always - Patron should not be charged if items are not all checked out'
195
        );
205
        );
196
206
207
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'issued_or_reserved' );
208
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
209
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
210
        addreserve( $patron3->borrowernumber );
211
        addreserve( $patron1->borrowernumber );
212
        is(
213
            acctlines( $patron1->borrowernumber ), 1,
214
            'issued_or_reserved - Patron should be charged if all the items are not checked out because 1 hold is placed'
215
        );
216
217
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
197
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
218
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
198
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
219
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
199
        addreserve( $patron3->borrowernumber );
220
        addreserve( $patron3->borrowernumber );
Lines 212-217 subtest 'Integration with AddReserve' => sub { Link Here
212
            'not_always - Patron should not be charged if all items are checked out but no holds are placed'
233
            'not_always - Patron should not be charged if all items are checked out but no holds are placed'
213
        );
234
        );
214
235
236
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'issued_or_reserved' );
237
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
238
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
239
        addreserve( $patron1->borrowernumber );
240
        is(
241
            acctlines( $patron1->borrowernumber ), 1,
242
            'issued_or_reserved - Patron should be charged if all items are checked out but no holds are placed'
243
        );
244
245
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' );
215
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
246
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
216
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
247
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
217
        addreserve( $patron3->borrowernumber );
248
        addreserve( $patron3->borrowernumber );
Lines 219-224 subtest 'Integration with AddReserve' => sub { Link Here
219
        is(
250
        is(
220
            acctlines( $patron1->borrowernumber ), 1,
251
            acctlines( $patron1->borrowernumber ), 1,
221
            'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed'
252
            'not_always - Patron should only be charged if all items are checked out and at least 1 hold is already placed'
253
254
        t::lib::Mocks::mock_preference( 'HoldFeeMode', 'issued_or_reserved' );
255
        $dbh->do( "DELETE FROM reserves     WHERE biblionumber=?",   undef, $biblio->biblionumber );
256
        $dbh->do( "DELETE FROM accountlines WHERE borrowernumber=?", undef, $patron1->borrowernumber );
257
        addreserve( $patron3->borrowernumber );
258
        addreserve( $patron1->borrowernumber );
259
        is(
260
            acctlines( $patron1->borrowernumber ), 1,
261
            'issued_or_reserved - Patron should be charged if all items are checked out and at least 1 hold is already placed'
222
        );
262
        );
223
    };
263
    };
224
};
264
};
225
- 

Return to bug 32142