| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              package Koha::Checkouts::Renewal;  | 
            
            
              | 2 | 
               | 
            
            
              | 3 | 
              # Copyright PTFS Europe 2022  | 
            
            
              | 4 | 
              #  | 
            
            
              | 5 | 
              # This file is part of Koha.  | 
            
            
              | 6 | 
              #  | 
            
            
              | 7 | 
              # Koha is free software; you can redistribute it and/or modify it  | 
            
            
              | 8 | 
              # under the terms of the GNU General Public License as published by  | 
            
            
              | 9 | 
              # the Free Software Foundation; either version 3 of the License, or  | 
            
            
              | 10 | 
              # (at your option) any later version.  | 
            
            
              | 11 | 
              #  | 
            
            
              | 12 | 
              # Koha is distributed in the hope that it will be useful, but  | 
            
            
              | 13 | 
              # WITHOUT ANY WARRANTY; without even the implied warranty of  | 
            
            
              | 14 | 
              # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
            
            
              | 15 | 
              # GNU General Public License for more details.  | 
            
            
              | 16 | 
              #  | 
            
            
              | 17 | 
              # You should have received a copy of the GNU General Public License  | 
            
            
              | 18 | 
              # along with Koha; if not, see <http://www.gnu.org/licenses>.  | 
            
            
              | 19 | 
               | 
            
            
              | 20 | 
              use Modern::Perl;  | 
            
            
              | 21 | 
               | 
            
            
              | 22 | 
              use base qw(Koha::Object);  | 
            
            
              | 23 | 
               | 
            
            
              | 24 | 
              use Koha::Checkout;  | 
            
            
              | 25 | 
              use Koha::Checkouts;  | 
            
            
              | 26 | 
              use Koha::Exceptions;  | 
            
            
              | 27 | 
              use Koha::Exceptions::Checkouts::Renewals;  | 
            
            
              | 28 | 
              use Koha::Old::Checkouts;  | 
            
            
              | 29 | 
              use Koha::Patron;  | 
            
            
              | 30 | 
               | 
            
            
              | 31 | 
              =head1 NAME  | 
            
            
              | 32 | 
               | 
            
            
              | 33 | 
              Koha::Checkouts::Renewal - Koha Renewal object class  | 
            
            
              | 34 | 
               | 
            
            
              | 35 | 
              =head1 API  | 
            
            
              | 36 | 
               | 
            
            
              | 37 | 
              =head2 Class methods  | 
            
            
              | 38 | 
               | 
            
            
              | 39 | 
              =cut  | 
            
            
              | 40 | 
               | 
            
            
              | 41 | 
              =head3 store  | 
            
            
              | 42 | 
               | 
            
            
              | 43 | 
                  my $return_claim = Koha::Checkout::Renewal->new($args)->store;  | 
            
            
              | 44 | 
               | 
            
            
              | 45 | 
              Overloaded I<store> method that validates the attributes and raises relevant  | 
            
            
              | 46 | 
              exceptions as needed.  | 
            
            
              | 47 | 
               | 
            
            
              | 48 | 
              =cut  | 
            
            
              | 49 | 
               | 
            
            
              | 50 | 
              sub store { | 
            
            
              | 51 | 
                  my ( $self ) = @_;  | 
            
            
              | 52 | 
               | 
            
            
              | 53 | 
                  unless ( $self->in_storage || $self->renewer_id ) { | 
            
            
              | 54 | 
                      Koha::Exceptions::Checkouts::Renewals::NoRenewedBy->throw();  | 
            
            
              | 55 | 
                  }  | 
            
            
              | 56 | 
               | 
            
            
              | 57 | 
                  unless ( !$self->issue_id  | 
            
            
              | 58 | 
                      || Koha::Checkouts->find( $self->issue_id )  | 
            
            
              | 59 | 
                      || Koha::Old::Checkouts->find( $self->issue_id ) )  | 
            
            
              | 60 | 
                  { | 
            
            
              | 61 | 
                      Koha::Exceptions::Object::FKConstraint->throw(  | 
            
            
              | 62 | 
                          error     => 'Broken FK constraint',  | 
            
            
              | 63 | 
                          broken_fk => 'issue_id'  | 
            
            
              | 64 | 
                      );  | 
            
            
              | 65 | 
                  }  | 
            
            
              | 66 | 
               | 
            
            
              | 67 | 
                  return $self->SUPER::store;  | 
            
            
              | 68 | 
              }  | 
            
            
              | 69 | 
               | 
            
            
              | 70 | 
              =head3 checkout  | 
            
            
              | 71 | 
               | 
            
            
              | 72 | 
              =cut  | 
            
            
              | 73 | 
               | 
            
            
              | 74 | 
              sub checkout { | 
            
            
              | 75 | 
                  my ($self) = @_;  | 
            
            
              | 76 | 
               | 
            
            
              | 77 | 
                  my $checkout_rs = $self->_result->checkout;  | 
            
            
              | 78 | 
                  return unless $checkout_rs;  | 
            
            
              | 79 | 
                  return Koha::Checkout->_new_from_dbic($checkout_rs);  | 
            
            
              | 80 | 
              }  | 
            
            
              | 81 | 
               | 
            
            
              | 82 | 
              =head3 old_checkout  | 
            
            
              | 83 | 
               | 
            
            
              | 84 | 
              =cut  | 
            
            
              | 85 | 
               | 
            
            
              | 86 | 
              sub old_checkout { | 
            
            
              | 87 | 
                  my ($self) = @_;  | 
            
            
              | 88 | 
               | 
            
            
              | 89 | 
                  my $old_checkout_rs = $self->_result->old_checkout;  | 
            
            
              | 90 | 
                  return unless $old_checkout_rs;  | 
            
            
              | 91 | 
                  return Koha::Old::Checkout->_new_from_dbic($old_checkout_rs);  | 
            
            
              | 92 | 
              }  | 
            
            
              | 93 | 
               | 
            
            
              | 94 | 
              =head3 renewer  | 
            
            
              | 95 | 
               | 
            
            
              | 96 | 
              =cut  | 
            
            
              | 97 | 
               | 
            
            
              | 98 | 
              sub renewer { | 
            
            
              | 99 | 
                  my ( $self ) = @_;  | 
            
            
              | 100 | 
               | 
            
            
              | 101 | 
                  my $renewer = $self->_result->renewer;  | 
            
            
              | 102 | 
                  return Koha::Patron->_new_from_dbic( $renewer ) if $renewer;  | 
            
            
              | 103 | 
              }  | 
            
            
              | 104 | 
               | 
            
            
              | 105 | 
              =head3 to_api_mapping  | 
            
            
              | 106 | 
               | 
            
            
              | 107 | 
              This method returns the mapping for representing a Koha::Checkouts::Renewal object  | 
            
            
              | 108 | 
              on the API.  | 
            
            
              | 109 | 
               | 
            
            
              | 110 | 
              =cut  | 
            
            
              | 111 | 
               | 
            
            
              | 112 | 
              sub to_api_mapping { | 
            
            
              | 113 | 
                  return { | 
            
            
              | 114 | 
                      id       => 'renewal_id',  | 
            
            
              | 115 | 
                      issue_id => 'checkout_id'  | 
            
            
              | 116 | 
                  };  | 
            
            
              | 117 | 
              }  | 
            
            
              | 118 | 
               | 
            
            
              | 119 | 
              =head2 Internal methods  | 
            
            
              | 120 | 
               | 
            
            
              | 121 | 
              =head3 _type  | 
            
            
              | 122 | 
               | 
            
            
              | 123 | 
              =cut  | 
            
            
              | 124 | 
               | 
            
            
              | 125 | 
              sub _type { | 
            
            
              | 126 | 
                  return 'CheckoutRenewal';  | 
            
            
              | 127 | 
              }  | 
            
            
              | 128 | 
               | 
            
            
              | 129 | 
              =head1 AUTHOR  | 
            
            
              | 130 | 
               | 
            
            
              | 131 | 
              Martin Renvoize <martin.renvoize@ptfs-europe.com>  | 
            
            
              | 132 | 
               | 
            
            
              | 133 | 
              =cut  | 
            
            
              | 134 | 
               | 
            
            
              | 135 | 
              1;  |