use Carp;
use C4::Context;
+use C4::Circulation;
use Koha::Checkout;
use Koha::Database;
use Koha::DateUtils;
my $userenv = C4::Context->userenv;
my $branchcode = $userenv->{branch} // q{};
- my $calendar = Koha::Calendar->new( branchcode => $branchcode );
- my $today = dt_from_string();
- my $dropbox_date = $calendar->addDate( $today, -1 );
+ my $daysmode = Koha::CirculationRules->get_effective_daysmode(
+ {
+ categorycode => undef,
+ itemtype => undef,
+ branchcode => $branchcode,
+ }
+ );
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
+ my $today = dt_from_string;
+ my $dropbox_date = $calendar->addDuration( $today, -1 );
return $dropbox_date;
}
+=head3 automatic_checkin
+
+my $automatic_checkins = Koha::Checkouts->automatic_checkin()
+
+Checks in every due issue which itemtype has automatic_checkin enabled
+
+=cut
+
+sub automatic_checkin {
+ my ($self, $params) = @_;
+
+ my $current_date = dt_from_string;
+
+ my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+ my $due_checkouts = $self->search(
+ { date_due => { '<=' => $dtf->format_datetime($current_date) } },
+ { prefetch => 'item'}
+ );
+
+ while ( my $checkout = $due_checkouts->next ) {
+ if ( $checkout->item->itemtype->automatic_checkin ) {
+ C4::Circulation::AddReturn( $checkout->item->barcode,
+ $checkout->branchcode, undef, dt_from_string($checkout->date_due) );
+ }
+ }
+}
+
=head3 type
=cut