Bug 11897: Stockrotation
[srvgit] / Koha / Checkout.pm
index 358f41c..b7a752c 100644 (file)
@@ -1,6 +1,7 @@
 package Koha::Checkout;
 
 # Copyright ByWater Solutions 2015
+# Copyright 2016 Koha Development Team
 #
 # This file is part of Koha.
 #
@@ -22,6 +23,9 @@ use Modern::Perl;
 use Carp;
 
 use Koha::Database;
+use DateTime;
+use Koha::DateUtils;
+use Koha::Items;
 
 use base qw(Koha::Object);
 
@@ -35,6 +39,55 @@ Koha::Checkout - Koha Checkout object class
 
 =cut
 
+=head3 is_overdue
+
+my  $is_overdue = $checkout->is_overdue( [ $reference_dt ] );
+
+Return 1 if the checkout is overdue.
+
+A reference date can be passed, in this case it will be used, otherwise today
+will be the reference date.
+
+=cut
+
+sub is_overdue {
+    my ( $self, $dt ) = @_;
+    $dt ||= DateTime->now( time_zone => C4::Context->tz );
+    my $is_overdue =
+      DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1
+      ? 1
+      : 0;
+    return $is_overdue;
+}
+
+=head3 item
+
+my $item = $checkout->item;
+
+Return the checked out item
+
+=cut
+
+sub item {
+    my ( $self ) = @_;
+    my $item_rs = $self->_result->item;
+    return Koha::Item->_new_from_dbic( $item_rs );
+}
+
+=head3 patron
+
+my $patron = $checkout->patron
+
+Return the patron for who the checkout has been done
+
+=cut
+
+sub patron {
+    my ( $self ) = @_;
+    my $patron_rs = $self->_result->borrower;
+    return Koha::Patron->_new_from_dbic( $patron_rs );
+}
+
 =head3 type
 
 =cut
@@ -47,6 +100,8 @@ sub _type {
 
 Kyle M Hall <kyle@bywatersolutions.com>
 
+Jonathan Druart <jonathan.druart@bugs.koha-community.org>
+
 =cut
 
 1;