Bug 20912: (QA follow-up) Move Fees to Charges::
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 29 Jan 2019 11:28:28 +0000 (11:28 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 7 Mar 2019 17:27:36 +0000 (17:27 +0000)
In preparation for the introduction of Koha::Charges::Fines I have moved
this ::Fees class into the Koha::Charges:: namespace

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
C4/Circulation.pm
Koha/Charges/Fees.pm [new file with mode: 0644]
Koha/Fees.pm [deleted file]
t/db_dependent/Koha/Charges/Fees.t [new file with mode: 0644]
t/db_dependent/Koha/Fees.t [deleted file]

index 42eb690..23fafdd 100644 (file)
@@ -59,7 +59,7 @@ use Koha::RefundLostItemFeeRules;
 use Koha::Account::Lines;
 use Koha::Account::Offsets;
 use Koha::Config::SysPrefs;
-use Koha::Fees;
+use Koha::Charges::Fees;
 use Carp;
 use List::MoreUtils qw( uniq any );
 use Scalar::Util qw( looks_like_number );
@@ -716,7 +716,7 @@ sub CanBookBeIssued {
         #  So issuingimpossible should be ok.
     }
 
-    my $fees = Koha::Fees->new(
+    my $fees = Koha::Charges::Fees->new(
         {
             patron    => $patron,
             library   => $library,
@@ -1347,7 +1347,7 @@ sub AddIssue {
 
             my $patron = Koha::Patrons->find( $borrower );
             my $library = Koha::Libraries->find( $branch );
-            my $fees = Koha::Fees->new(
+            my $fees = Koha::Charges::Fees->new(
                 {
                     patron    => $patron,
                     library   => $library,
@@ -2893,7 +2893,7 @@ sub AddRenewal {
     }
 
 
-    my $fees = Koha::Fees->new(
+    my $fees = Koha::Charges::Fees->new(
         {
             patron    => $patron,
             library   => $library,
diff --git a/Koha/Charges/Fees.pm b/Koha/Charges/Fees.pm
new file mode 100644 (file)
index 0000000..62f5341
--- /dev/null
@@ -0,0 +1,186 @@
+package Koha::Charges::Fees;
+
+# Copyright 2018 ByWater Solutions
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Carp qw( confess );
+
+use Koha::Calendar;
+use Koha::DateUtils qw( dt_from_string );
+use Koha::Exceptions;
+
+=head1 NAME
+
+Koha::Charges::Fees - Module calculating fees in Koha
+
+=head3 new
+
+Koha::Charges::Fees->new(
+    {
+        patron    => $patron,
+        library   => $library,
+        item      => $item,
+        to_date   => $to_dt,
+        [ from_date => $from_dt, ]
+    }
+);
+
+=cut
+
+sub new {
+    my ( $class, $params ) = @_;
+
+    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: patron")
+        unless $params->{patron};
+    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: library")
+        unless $params->{library};
+    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: item")
+        unless $params->{item};
+    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
+        unless $params->{to_date};
+
+    Carp::confess("Key 'patron' is not a Koha::Patron object!")
+      unless $params->{patron}->isa('Koha::Patron');
+    Carp::confess("Key 'library' is not a Koha::Library object!")
+      unless $params->{library}->isa('Koha::Library');
+    Carp::confess("Key 'item' is not a Koha::Item object!")
+      unless $params->{item}->isa('Koha::Item');
+    Carp::confess("Key 'to_date' is not a DateTime object!")
+      unless $params->{to_date}->isa('DateTime');
+
+    if ( $params->{from_date} ) {
+        Carp::croak("Key 'from_date' is not a DateTime object!")
+          unless $params->{from_date}->isa('DateTime');
+    }
+    else {
+        $params->{from_date} = dt_from_string();
+    }
+
+    return bless( $params, $class );
+}
+
+=head3 rental_charge_daily
+
+    my $fee = $self->rental_charge_daily();
+
+    This method calculates the daily rental fee for a given itemtype for a given
+    period of time passed in as a pair of DateTime objects.
+
+=cut
+
+sub rental_charge_daily {
+    my ( $self, $params ) = @_;
+
+    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
+    my $rental_charge_daily = $itemtype->rental_charge_daily;
+
+    return undef unless $rental_charge_daily && $rental_charge_daily > 0;
+
+    my $duration;
+    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
+        my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
+        $duration = $calendar->days_between( $self->from_date, $self->to_date );
+    }
+    else {
+        $duration = $self->to_date->delta_days($self->from_date);
+    }
+    my $days = $duration->in_units('days');
+
+    my $charge = $rental_charge_daily * $days;
+
+    return $charge;
+}
+
+=head3 patron
+
+my $patron = $fees->patron( $patron );
+
+=cut
+
+sub patron {
+    my ( $self, $patron ) = @_;
+
+    $self->{patron} = $patron if $patron && $patron->isa('Koha::Patron');
+
+    return $self->{patron};
+}
+
+=head3 library
+
+my $library = $fees->library( $library );
+
+=cut
+
+sub library {
+    my ( $self, $library ) = @_;
+
+    $self->{library} = $library if $library && $library->isa('Koha::Library');
+
+    return $self->{library};
+}
+
+=head3 item
+
+my $item = $fees->item( $item );
+
+=cut
+
+sub item {
+    my ( $self, $item ) = @_;
+
+    $self->{item} = $item if $item && $item->isa('Koha::Item');
+
+    return $self->{item};
+}
+
+=head3 to_date
+
+my $to_date = $fees->to_date( $to_date );
+
+=cut
+
+sub to_date {
+    my ( $self, $to_date ) = @_;
+
+    $self->{to_date} = $to_date if $to_date && $to_date->isa('DateTime');
+
+    return $self->{to_date};
+}
+
+=head3 from_date
+
+my $from_date = $fees->from_date( $from_date );
+
+=cut
+
+sub from_date {
+    my ( $self, $from_date ) = @_;
+
+    $self->{from_date} = $from_date if $from_date && $from_date->isa('DateTime');
+
+    return $self->{from_date};
+}
+
+=head1 AUTHOR
+
+Kyle M Hall <kyle.m.hall@gmail.com>
+
+=cut
+
+1;
diff --git a/Koha/Fees.pm b/Koha/Fees.pm
deleted file mode 100644 (file)
index 33bf3aa..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-package Koha::Fees;
-
-# Copyright 2018 ByWater Solutions
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use Carp qw( confess );
-
-use Koha::Calendar;
-use Koha::DateUtils qw( dt_from_string );
-use Koha::Exceptions;
-
-=head1 NAME
-
-Koha::Feess - Module calculating fees in Koha
-
-=head3 new
-
-Koha::Fees->new(
-    {
-        patron    => $patron,
-        library   => $library,
-        item      => $item,
-        to_date   => $to_dt,
-        [ from_date => $from_dt, ]
-    }
-);
-
-=cut
-
-sub new {
-    my ( $class, $params ) = @_;
-
-    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: patron")
-        unless $params->{patron};
-    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: library")
-        unless $params->{library};
-    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: item")
-        unless $params->{item};
-    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
-        unless $params->{to_date};
-
-    Carp::confess("Key 'patron' is not a Koha::Patron object!")
-      unless $params->{patron}->isa('Koha::Patron');
-    Carp::confess("Key 'library' is not a Koha::Library object!")
-      unless $params->{library}->isa('Koha::Library');
-    Carp::confess("Key 'item' is not a Koha::Item object!")
-      unless $params->{item}->isa('Koha::Item');
-    Carp::confess("Key 'to_date' is not a DateTime object!")
-      unless $params->{to_date}->isa('DateTime');
-
-    if ( $params->{from_date} ) {
-        Carp::croak("Key 'from_date' is not a DateTime object!")
-          unless $params->{from_date}->isa('DateTime');
-    }
-    else {
-        $params->{from_date} = dt_from_string();
-    }
-
-    return bless( $params, $class );
-}
-
-=head3 rental_charge_daily
-
-    my $fee = $self->rental_charge_daily();
-
-    This method calculates the daily rental fee for a given itemtype for a given
-    period of time passed in as a pair of DateTime objects.
-
-=cut
-
-sub rental_charge_daily {
-    my ( $self, $params ) = @_;
-
-    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
-    my $rental_charge_daily = $itemtype->rental_charge_daily;
-
-    return undef unless $rental_charge_daily && $rental_charge_daily > 0;
-
-    my $duration;
-    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
-        my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
-        $duration = $calendar->days_between( $self->from_date, $self->to_date );
-    }
-    else {
-        $duration = $self->to_date->delta_days($self->from_date);
-    }
-    my $days = $duration->in_units('days');
-
-    my $charge = $rental_charge_daily * $days;
-
-    return $charge;
-}
-
-=head3 patron
-
-my $patron = $fees->patron( $patron );
-
-=cut
-
-sub patron {
-    my ( $self, $patron ) = @_;
-
-    $self->{patron} = $patron if $patron && $patron->isa('Koha::Patron');
-
-    return $self->{patron};
-}
-
-=head3 library
-
-my $library = $fees->library( $library );
-
-=cut
-
-sub library {
-    my ( $self, $library ) = @_;
-
-    $self->{library} = $library if $library && $library->isa('Koha::Library');
-
-    return $self->{library};
-}
-
-=head3 item
-
-my $item = $fees->item( $item );
-
-=cut
-
-sub item {
-    my ( $self, $item ) = @_;
-
-    $self->{item} = $item if $item && $item->isa('Koha::Item');
-
-    return $self->{item};
-}
-
-=head3 to_date
-
-my $to_date = $fees->to_date( $to_date );
-
-=cut
-
-sub to_date {
-    my ( $self, $to_date ) = @_;
-
-    $self->{to_date} = $to_date if $to_date && $to_date->isa('DateTime');
-
-    return $self->{to_date};
-}
-
-=head3 from_date
-
-my $from_date = $fees->from_date( $from_date );
-
-=cut
-
-sub from_date {
-    my ( $self, $from_date ) = @_;
-
-    $self->{from_date} = $from_date if $from_date && $from_date->isa('DateTime');
-
-    return $self->{from_date};
-}
-
-=head1 AUTHOR
-
-Kyle M Hall <kyle.m.hall@gmail.com>
-
-=cut
-
-1;
diff --git a/t/db_dependent/Koha/Charges/Fees.t b/t/db_dependent/Koha/Charges/Fees.t
new file mode 100644 (file)
index 0000000..55c3242
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/perl
+#
+# Copyright 2018 ByWater Solutions
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Test::More tests => 2;
+
+use t::lib::Mocks;
+use t::lib::TestBuilder;
+
+use Data::Dumper;
+
+use C4::Calendar;
+use Koha::DateUtils qw(dt_from_string);
+
+BEGIN {
+    use_ok('Koha::Charges::Fees');
+}
+
+my $builder = t::lib::TestBuilder->new();
+
+my $patron_category = $builder->build_object(
+    {
+        class => 'Koha::Patron::Categories',
+        value => {
+            category_type => 'P',
+            enrolmentfee  => 0,
+        }
+    }
+);
+my $library = $builder->build_object(
+    {
+        class => 'Koha::Libraries',
+    }
+);
+my $biblio = $builder->build_object(
+    {
+        class => 'Koha::Biblios',
+    }
+);
+my $itemtype = $builder->build_object(
+    {
+        class => 'Koha::ItemTypes',
+        value => {
+            rental_charge_daily => '0.00',
+            rentalcharge        => '0.00',
+            processfee          => '0.00',
+            defaultreplacecost  => '0.00',
+        },
+    }
+);
+my $item = $builder->build_object(
+    {
+        class => 'Koha::Items',
+        value => {
+            biblionumber  => $biblio->id,
+            homebranch    => $library->id,
+            holdingbranch => $library->id,
+            itype         => $itemtype->id,
+        }
+    }
+);
+my $patron = $builder->build_object(
+    {
+        class => 'Koha::Patrons',
+        value => {
+            dateexpiry   => '9999-12-31',
+            categorycode => $patron_category->id,
+        }
+    }
+);
+
+my $dt_from = dt_from_string();
+my $dt_to = dt_from_string()->add( days => 6 );
+
+my $fees = Koha::Charges::Fees->new(
+    {
+        patron    => $patron,
+        library   => $library,
+        item      => $item,
+        to_date   => $dt_to,
+        from_date => $dt_from,
+    }
+);
+
+subtest 'Koha::ItemType::rental_charge_daily tests' => sub {
+    plan tests => 4;
+
+    $itemtype->rental_charge_daily(1.00);
+    $itemtype->store();
+    is( $itemtype->rental_charge_daily,
+        1.00, 'Daily return charge stored correctly' );
+
+    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
+    my $charge = $fees->rental_charge_daily();
+    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' );
+
+    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
+    $charge = $fees->rental_charge_daily();
+    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' );
+
+    my $calendar = C4::Calendar->new( branchcode => $library->id );
+    $calendar->insert_week_day_holiday(
+        weekday     => 3,
+        title       => 'Test holiday',
+        description => 'Test holiday'
+    );
+    $charge = $fees->rental_charge_daily();
+    is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' );
+};
diff --git a/t/db_dependent/Koha/Fees.t b/t/db_dependent/Koha/Fees.t
deleted file mode 100644 (file)
index db16a82..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/perl
-#
-# Copyright 2018 ByWater Solutions
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Test::More tests => 2;
-
-use t::lib::Mocks;
-use t::lib::TestBuilder;
-
-use Data::Dumper;
-
-use C4::Calendar;
-use Koha::DateUtils qw(dt_from_string);
-
-BEGIN {
-    use_ok('Koha::Fees');
-}
-
-my $builder = t::lib::TestBuilder->new();
-
-my $patron_category = $builder->build_object(
-    {
-        class => 'Koha::Patron::Categories',
-        value => {
-            category_type => 'P',
-            enrolmentfee  => 0,
-        }
-    }
-);
-my $library = $builder->build_object(
-    {
-        class => 'Koha::Libraries',
-    }
-);
-my $biblio = $builder->build_object(
-    {
-        class => 'Koha::Biblios',
-    }
-);
-my $itemtype = $builder->build_object(
-    {
-        class => 'Koha::ItemTypes',
-        value => {
-            rental_charge_daily => '0.00',
-            rentalcharge        => '0.00',
-            processfee          => '0.00',
-            defaultreplacecost  => '0.00',
-        },
-    }
-);
-my $item = $builder->build_object(
-    {
-        class => 'Koha::Items',
-        value => {
-            biblionumber  => $biblio->id,
-            homebranch    => $library->id,
-            holdingbranch => $library->id,
-            itype         => $itemtype->id,
-        }
-    }
-);
-my $patron = $builder->build_object(
-    {
-        class => 'Koha::Patrons',
-        value => {
-            dateexpiry   => '9999-12-31',
-            categorycode => $patron_category->id,
-        }
-    }
-);
-
-my $dt_from = dt_from_string();
-my $dt_to = dt_from_string()->add( days => 6 );
-
-my $fees = Koha::Fees->new(
-    {
-        patron    => $patron,
-        library   => $library,
-        item      => $item,
-        to_date   => $dt_to,
-        from_date => $dt_from,
-    }
-);
-
-subtest 'Koha::ItemType::rental_charge_daily tests' => sub {
-    plan tests => 4;
-
-    $itemtype->rental_charge_daily(1.00);
-    $itemtype->store();
-    is( $itemtype->rental_charge_daily,
-        1.00, 'Daily return charge stored correctly' );
-
-    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
-    my $charge = $fees->rental_charge_daily();
-    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' );
-
-    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
-    $charge = $fees->rental_charge_daily();
-    is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' );
-
-    my $calendar = C4::Calendar->new( branchcode => $library->id );
-    $calendar->insert_week_day_holiday(
-        weekday     => 3,
-        title       => 'Test holiday',
-        description => 'Test holiday'
-    );
-    $charge = $fees->rental_charge_daily();
-    is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' );
-};