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

(-)a/Koha/Checkouts.pm (-10 / +21 lines)
Lines 63-98 sub calculate_dropbox_date { Link Here
63
    return $dropbox_date;
63
    return $dropbox_date;
64
}
64
}
65
65
66
66
=head3 automatic_checkin
67
=head3 automatic_checkin
67
68
68
my $automatic_checkins = Koha::Checkouts->automatic_checkin()
69
my $automatic_checkins = Koha::Checkouts->automatic_checkin()
69
70
70
Checks in every due issue which itemtype has automatic_checkin enabled. Also if the AutoCheckinAutoFill sys. pref. is enabled, the item is trapped for the next patron.
71
Checks in every due issue which itemtype has automatic_checkin enabled. Also if the AutoCheckinAutoFill system preference is enabled, the item is trapped for the next patron.
71
72
72
=cut
73
=cut
73
74
74
sub automatic_checkin {
75
sub automatic_checkin {
75
    my ($self, $params) = @_;
76
    my ( $self, $params ) = @_;
76
77
77
    my $current_date = dt_from_string;
78
    my $current_date = dt_from_string;
78
79
79
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
80
    my $dtf           = Koha::Database->new->schema->storage->datetime_parser;
80
    my $due_checkouts = $self->search(
81
    my $due_checkouts = $self->search(
81
        { date_due => { '<=' => $dtf->format_datetime($current_date) } },
82
        { date_due => { '<=' => $dtf->format_datetime($current_date) } },
82
        { prefetch => 'item'}
83
        { prefetch => 'item' }
83
    );
84
    );
84
85
85
    my $autofill_next = C4::Context->preference('AutomaticCheckinAutoFill');
86
    my $autofill_next = C4::Context->preference('AutomaticCheckinAutoFill');
86
87
87
    while ( my $checkout = $due_checkouts->next ) {
88
    while ( my $checkout = $due_checkouts->next ) {
88
        if ( $checkout->item->itemtype->automatic_checkin ) {
89
        if ( $checkout->item->itemtype->automatic_checkin ) {
89
            my ( undef, $messages) = C4::Circulation::AddReturn($checkout->item->barcode, $checkout->branchcode, undef, dt_from_string($checkout->date_due) );
90
            my ( undef, $messages ) = C4::Circulation::AddReturn(
90
            if ( $autofill_next ){
91
                $checkout->item->barcode, $checkout->branchcode, undef,
91
                if ( $messages->{ResFound} ){
92
                dt_from_string( $checkout->date_due )
93
            );
94
            if ($autofill_next) {
95
                if ( $messages->{ResFound} ) {
92
                    my $is_transfer = $checkout->branchcode ne $messages->{ResFound}->{branchcode};
96
                    my $is_transfer = $checkout->branchcode ne $messages->{ResFound}->{branchcode};
93
                    C4::Reserves::ModReserveAffect($checkout->item->itemnumber, $checkout->borrowernumber, $is_transfer, $messages->{ResFound}->{reserve_id}, $checkout->{desk_id}, 0);
97
                    C4::Reserves::ModReserveAffect(
94
                    if( $is_transfer ){
98
                        $checkout->item->itemnumber, $checkout->borrowernumber,
95
                        C4::Items::ModItemTransfer($checkout->item->itemnumber,$checkout->branchcode, $messages->{ResFound}->{branchcode},"Reserve");
99
                        $is_transfer, $messages->{ResFound}->{reserve_id}, $checkout->{desk_id}, 0
100
                    );
101
                    if ($is_transfer) {
102
                        C4::Items::ModItemTransfer(
103
                            $checkout->item->itemnumber,         $checkout->branchcode,
104
                            $messages->{ResFound}->{branchcode}, "Reserve"
105
                        );
96
                    }
106
                    }
97
                }
107
                }
98
            }
108
            }
Lines 100-105 sub automatic_checkin { Link Here
100
    }
110
    }
101
}
111
}
102
112
113
103
=head3 type
114
=head3 type
104
115
105
=cut
116
=cut
(-)a/installer/data/mysql/atomicupdate/bug_33887.pl (-5 / +9 lines)
Lines 1-14 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "33887",
4
    bug_number  => "33887",
5
    description => "Automatically fill the next hold with a automatic check in.",
5
    description => "Automatically fill the next hold with a automatic check in.",
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
        # Do you stuffs here
10
        # Do you stuffs here
10
        $dbh->do(q{
11
        $dbh->do(
11
                INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('AutomaticCheckinAutoFill', '0', NULL,'Automatically fill the next hold with an automatic checkin cronjob.', 'YesNo') });
12
            q{
13
                INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('AutomaticCheckinAutoFill', '0', NULL,'Automatically fill the next hold with an automatic checkin cronjob.', 'YesNo') }
14
        );
15
12
        # Print useful stuff here
16
        # Print useful stuff here
13
        # sysprefs
17
        # sysprefs
14
        say $out "Added new system preference 'AutomaticCheckinAutoFill'";
18
        say $out "Added new system preference 'AutomaticCheckinAutoFill'";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +1 lines)
Lines 983-989 Circulation: Link Here
983
                  1: "Allow"
983
                  1: "Allow"
984
                  0: "Don't allow"
984
                  0: "Don't allow"
985
            - holds to be automatically filled after being automatically checked in.
985
            - holds to be automatically filled after being automatically checked in.
986
            - '<br><strong>NOTE:</strong> This system preference requires the <code>misc/cronjobs/automatic_checkin.pl</code> cronjob. Ask your system administrator to schedule it.<br>'
986
            - '<br><strong>NOTE:</strong> This system preference requires the <code>misc/cronjobs/automatic_checkin.pl</code> cronjob. Ask your system administrator to schedule it.'
987
    Patron restrictions:
987
    Patron restrictions:
988
        -
988
        -
989
            - pref: PatronRestrictionTypes
989
            - pref: PatronRestrictionTypes
(-)a/t/db_dependent/Koha/Checkouts.t (-10 / +13 lines)
Lines 421-427 subtest 'automatic_checkin' => sub { Link Here
421
            }
421
            }
422
        )->store;
422
        )->store;
423
423
424
        my $patron_2 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $patron->branchcode}  } );
424
        my $patron_2 =
425
            $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $patron->branchcode } } );
425
        my $reserveid = AddReserve(
426
        my $reserveid = AddReserve(
426
            {
427
            {
427
                branchcode     => $patron->branchcode,
428
                branchcode     => $patron->branchcode,
Lines 431-442 subtest 'automatic_checkin' => sub { Link Here
431
            }
432
            }
432
        );
433
        );
433
434
434
        t::lib::Mocks::mock_preference('AutomaticCheckinAutoFill', '0');
435
        t::lib::Mocks::mock_preference( 'AutomaticCheckinAutoFill', '0' );
435
436
436
        Koha::Checkouts->automatic_checkin;
437
        Koha::Checkouts->automatic_checkin;
437
        my $reserve = Koha::Holds->find( $reserveid );
438
        my $reserve = Koha::Holds->find($reserveid);
438
439
439
        is( $reserve->found, undef, "Hold was not filled when AutomaticCheckinAutoFill disabled");
440
        is( $reserve->found, undef, "Hold was not filled when AutomaticCheckinAutoFill disabled" );
440
441
441
        my $checkout_3_due_ac = Koha::Checkout->new(
442
        my $checkout_3_due_ac = Koha::Checkout->new(
442
            {
443
            {
Lines 446-457 subtest 'automatic_checkin' => sub { Link Here
446
                date_due       => $today
447
                date_due       => $today
447
            }
448
            }
448
        )->store;
449
        )->store;
449
        t::lib::Mocks::mock_preference('AutomaticCheckinAutoFill', '1');
450
        t::lib::Mocks::mock_preference( 'AutomaticCheckinAutoFill', '1' );
450
451
451
        Koha::Checkouts->automatic_checkin;
452
        Koha::Checkouts->automatic_checkin;
452
        $reserve->discard_changes;
453
        $reserve->discard_changes;
453
454
454
        is( $reserve->found, 'W', "Hold was filled when AutomaticCheckinAutoFill enabled");
455
        is( $reserve->found, 'W', "Hold was filled when AutomaticCheckinAutoFill enabled" );
455
456
456
        my $checkout_2_odue_ac = Koha::Checkout->new(
457
        my $checkout_2_odue_ac = Koha::Checkout->new(
457
            {
458
            {
Lines 461-467 subtest 'automatic_checkin' => sub { Link Here
461
                date_due       => $today
462
                date_due       => $today
462
            }
463
            }
463
        )->store;
464
        )->store;
464
        my $branch2 = $builder->build_object({ class=> "Koha::Libraries" });
465
        my $branch2    = $builder->build_object( { class => "Koha::Libraries" } );
465
        my $reserve2id = AddReserve(
466
        my $reserve2id = AddReserve(
466
            {
467
            {
467
                branchcode     => $branch2->branchcode,
468
                branchcode     => $branch2->branchcode,
Lines 472-479 subtest 'automatic_checkin' => sub { Link Here
472
        );
473
        );
473
        Koha::Checkouts->automatic_checkin;
474
        Koha::Checkouts->automatic_checkin;
474
475
475
        my $reserve2 = Koha::Holds->find( $reserve2id );
476
        my $reserve2 = Koha::Holds->find($reserve2id);
476
        is( $reserve2->found, 'T', "Hold was filled when AutomaticCheckinAutoFill enabled and transfer was initiated when branches didn't match");
477
        is(
478
            $reserve2->found, 'T',
479
            "Hold was filled when AutomaticCheckinAutoFill enabled and transfer was initiated when branches didn't match"
480
        );
477
    };
481
    };
478
482
479
    $schema->storage->txn_rollback;
483
    $schema->storage->txn_rollback;
480
- 

Return to bug 33887