@@ -, +, @@
---
C4/Circulation.pm | 10 +++----
C4/HoldsQueue.pm | 8 ++---
C4/Overdues.pm | 5 ++--
C4/Reserves.pm | 4 +--
Koha/Hold.pm | 8 ++---
circ/returns.pl | 5 ++--
installer/data/mysql/updatedatabase.pl | 4 +--
.../prog/en/modules/tools/tools-home.tt | 5 ++++
misc/cronjobs/fines.pl | 4 +--
misc/cronjobs/holds/cancel_unfilled_holds.pl | 2 +-
misc/cronjobs/overdue_notices.pl | 18 +++++-------
misc/cronjobs/staticfines.pl | 4 +--
.../thirdparty/TalkingTech_itiva_outbound.pl | 4 +--
t/db_dependent/Circulation/CalcFine.t | 26 +++--------------
t/db_dependent/Fines.t | 11 +++----
t/db_dependent/HoldsQueue.t | 34 ++++++++++++++++------
16 files changed, 77 insertions(+), 75 deletions(-)
--- a/C4/Circulation.pm
+++ a/C4/Circulation.pm
@@ -44,7 +44,7 @@ use Koha::Account;
use Koha::AuthorisedValues;
use Koha::Biblioitems;
use Koha::DateUtils;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::Checkouts;
use Koha::IssuingRules;
use Koha::Items;
@@ -1195,7 +1195,7 @@ sub checkHighHolds {
my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
my $itype = $item_object->effective_itemtype;
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branch, $borrower );
@@ -2126,7 +2126,7 @@ sub MarkIssueReturned {
my $query = 'UPDATE issues SET returndate=';
my @bind;
if ($dropbox_branch) {
- my $calendar = Koha::Calendar->new( branchcode => $dropbox_branch );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $dropbox_branch );
my $dropboxdate = $calendar->addDate( DateTime->now( time_zone => C4::Context->tz), -1 );
$query .= ' ? ';
push @bind, $dropboxdate->strftime('%Y-%m-%d %H:%M');
@@ -3480,7 +3480,7 @@ sub CalcDateDue {
else { # days
$dur = DateTime::Duration->new( days => $loanlength->{$length_key});
}
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
$datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
if ($loanlength->{lengthunit} eq 'days') {
$datedue->set_hour(23);
@@ -3519,7 +3519,7 @@ sub CalcDateDue {
}
}
if ( C4::Context->preference('useDaysMode') ne 'Days' ) {
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
if ( $calendar->is_holiday($datedue) ) {
# Don't return on a closed day
$datedue = $calendar->prev_open_day( $datedue );
--- a/C4/HoldsQueue.pm
+++ a/C4/HoldsQueue.pm
@@ -30,7 +30,7 @@ use C4::Members;
use C4::Biblio;
use Koha::DateUtils;
use Koha::Patrons;
-
+use Koha::DiscreteCalendar;
use List::Util qw(shuffle);
use List::MoreUtils qw(any);
use Data::Dumper;
@@ -77,7 +77,7 @@ sub TransportCostMatrix {
};
if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
- $calendars->{$from} ||= Koha::Calendar->new( branchcode => $from );
+ $calendars->{$from} ||= Koha::DiscreteCalendar->new( branchcode => $from );
$transport_cost_matrix{$to}{$from}{disable_transfer} ||=
$calendars->{$from}->is_holiday( $today );
}
@@ -206,7 +206,7 @@ sub CreateQueue {
$total_requests += scalar(@$hold_requests);
$total_available_items += scalar(@$available_items);
- my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
+ my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
$item_map or next;
my $item_map_size = scalar(keys %$item_map)
or next;
@@ -742,7 +742,7 @@ sub load_branches_to_pull_from {
my $today = dt_from_string();
if ( C4::Context->preference('HoldsQueueSkipClosed') ) {
@branches_to_use = grep {
- !Koha::Calendar->new( branchcode => $_ )
+ !Koha::DiscreteCalendar->new( branchcode => $_ )
->is_holiday( $today )
} @branches_to_use;
}
--- a/C4/Overdues.pm
+++ a/C4/Overdues.pm
@@ -34,6 +34,7 @@ use C4::Accounts;
use C4::Log; # logaction
use C4::Debug;
use Koha::DateUtils;
+use Koha::DiscreteCalendar;
use Koha::Account::Lines;
use Koha::Account::Offsets;
use Koha::IssuingRules;
@@ -293,7 +294,7 @@ sub get_chargeable_units {
my $charge_duration;
if ($unit eq 'hours') {
if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
- my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
$charge_duration = $calendar->hours_between( $date_due, $date_returned );
} else {
$charge_duration = $date_returned->delta_ms( $date_due );
@@ -305,7 +306,7 @@ sub get_chargeable_units {
}
else { # days
if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
- my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
$charge_duration = $calendar->days_between( $date_due, $date_returned );
} else {
$charge_duration = $date_returned->delta_days( $date_due );
--- a/C4/Reserves.pm
+++ a/C4/Reserves.pm
@@ -38,7 +38,7 @@ use C4::Log;
use Koha::Biblios;
use Koha::DateUtils;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::Database;
use Koha::Hold;
use Koha::Old::Hold;
@@ -770,7 +770,7 @@ sub CancelExpiredReserves {
my $holds = Koha::Holds->search( $params );
while ( my $hold = $holds->next ) {
- my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $hold->branchcode );
next if !$cancel_on_holidays && $calendar->is_holiday( $today );
--- a/Koha/Hold.pm
+++ a/Koha/Hold.pm
@@ -25,14 +25,14 @@ use Data::Dumper qw(Dumper);
use C4::Context qw(preference);
use C4::Log;
-
+use Koha::DiscreteCalendar;
use Koha::DateUtils qw(dt_from_string output_pref);
use Koha::Patrons;
use Koha::Biblios;
use Koha::Items;
use Koha::Libraries;
use Koha::Old::Holds;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use base qw(Koha::Object);
@@ -62,7 +62,7 @@ sub age {
my $age;
if ( $use_calendar ) {
- my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $self->branchcode );
$age = $calendar->days_between( dt_from_string( $self->reservedate ), $today );
}
else {
@@ -164,7 +164,7 @@ sub set_waiting {
my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
- my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $self->branchcode );
my $expirationdate = $today->clone;
$expirationdate->add(days => $max_pickup_delay);
--- a/circ/returns.pl
+++ a/circ/returns.pl
@@ -47,7 +47,8 @@ use C4::Koha; # FIXME : is it still useful ?
use C4::RotatingCollections;
use Koha::AuthorisedValues;
use Koha::DateUtils;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
+use Koha::Checkouts;
use Koha::BiblioFrameworks;
use Koha::Holds;
use Koha::Items;
@@ -202,7 +203,7 @@ my $dropboxmode = $query->param('dropboxmode');
my $dotransfer = $query->param('dotransfer');
my $canceltransfer = $query->param('canceltransfer');
my $dest = $query->param('dest');
-my $calendar = Koha::Calendar->new( branchcode => $userenv_branch );
+my $calendar = Koha::DiscreteCalendar->new( branchcode => $userenv_branch );
#dropbox: get last open day (today - 1)
my $today = DateTime->now( time_zone => C4::Context->tz());
my $dropboxdate = $calendar->addDate($today, -1);
--- a/installer/data/mysql/updatedatabase.pl
+++ a/installer/data/mysql/updatedatabase.pl
@@ -14353,7 +14353,7 @@ if( CheckVersion( $DBversion ) ) {
$DBversion = '16.12.00.032';
if( CheckVersion( $DBversion ) ) {
- require Koha::Calendar;
+ require Koha::DiscreteCalendar;
require Koha::Holds;
$dbh->do(q{
@@ -14372,7 +14372,7 @@ if( CheckVersion( $DBversion ) ) {
my $expirationdate = dt_from_string($hold->waitingdate);
if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
- my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $hold->branchcode );
$expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay );
} else {
$expirationdate->add( days => $max_pickup_delay );
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt
@@ -79,6 +79,11 @@
Define days when the library is closed
[% END %]
+ [% IF ( CAN_user_tools_edit_calendar ) %]
+ Discrete Calendar
+ Define days when the library is closed
+ [% END %]
+
[% IF ( CAN_user_tools_manage_csv_profiles ) %]
CSV profiles
Manage CSV export profiles
--- a/misc/cronjobs/fines.pl
+++ a/misc/cronjobs/fines.pl
@@ -36,7 +36,7 @@ use Getopt::Long;
use Carp;
use File::Spec;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::DateUtils;
use C4::Log;
@@ -176,7 +176,7 @@ EOM
sub set_holiday {
my ( $branch, $dt ) = @_;
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
return $calendar->is_holiday($dt);
}
--- a/misc/cronjobs/holds/cancel_unfilled_holds.pl
+++ a/misc/cronjobs/holds/cancel_unfilled_holds.pl
@@ -31,7 +31,7 @@ use Pod::Usage;
use C4::Reserves;
use C4::Log;
use Koha::Holds;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::DateUtils;
use Koha::Libraries;
--- a/misc/cronjobs/overdue_notices.pl
+++ a/misc/cronjobs/overdue_notices.pl
@@ -40,7 +40,7 @@ use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_lette
use C4::Log;
use Koha::Patron::Debarments qw(AddUniqueDebarment);
use Koha::DateUtils;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::Libraries;
use Koha::Acquisition::Currencies;
use Koha::Patrons;
@@ -444,9 +444,8 @@ elsif ( defined $text_filename ) {
}
foreach my $branchcode (@branches) {
- my $calendar;
if ( C4::Context->preference('OverdueNoticeCalendar') ) {
- $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
if ( $calendar->is_holiday($date_to_run) ) {
next;
}
@@ -547,13 +546,11 @@ END_SQL
my $days_between;
if ( C4::Context->preference('OverdueNoticeCalendar') )
{
- $days_between =
- $calendar->days_between( dt_from_string($data->{date_due}),
- $date_to_run );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
+ $days_between = $calendar->days_between( dt_from_string($data->{date_due}), $date_to_run );
}
else {
- $days_between =
- $date_to_run->delta_days( dt_from_string($data->{date_due}) );
+ $days_between = $date_to_run->delta_days( dt_from_string($data->{date_due}) );
}
$days_between = $days_between->in_units('days');
if ($triggered) {
@@ -629,9 +626,8 @@ END_SQL
my $exceededPrintNoticesMaxLines = 0;
while ( my $item_info = $sth2->fetchrow_hashref() ) {
if ( C4::Context->preference('OverdueNoticeCalendar') ) {
- $days_between =
- $calendar->days_between(
- dt_from_string( $item_info->{date_due} ), $date_to_run );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
+ $days_between = $calendar->days_between( dt_from_string( $item_info->{date_due} ), $date_to_run );
}
else {
$days_between =
--- a/misc/cronjobs/staticfines.pl
+++ a/misc/cronjobs/staticfines.pl
@@ -40,7 +40,7 @@ use Date::Calc qw/Date_to_Days/;
use C4::Context;
use C4::Circulation;
use C4::Overdues;
-use C4::Calendar qw(); # don't need any exports from Calendar
+use Koha::DiscreteCalendar qw(); # don't need any exports from Calendar
use C4::Biblio;
use C4::Debug; # supplying $debug and $cgi_debug
use C4::Log;
@@ -176,7 +176,7 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
my $calendar;
unless ( defined( $calendars{$branchcode} ) ) {
- $calendars{$branchcode} = C4::Calendar->new( branchcode => $branchcode );
+ $calendars{$branchcode} = Koha::DiscreteCalendar->new( branchcode => $branchcode );
}
$calendar = $calendars{$branchcode};
my $isHoliday = $calendar->isHoliday( $tday, $tmonth, $tyear );
--- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl
+++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl
@@ -35,7 +35,7 @@ use C4::Context;
use C4::Items;
use C4::Letters;
use C4::Overdues;
-use Koha::Calendar;
+use Koha::DiscreteCalendar;
use Koha::DateUtils;
sub usage {
@@ -294,7 +294,7 @@ sub GetWaitingHolds {
$sth->execute();
my @results;
while ( my $issue = $sth->fetchrow_hashref() ) {
- my $calendar = Koha::Calendar->new( branchcode => $issue->{'site'} );
+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $issue->{'site'} );
my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
--- a/t/db_dependent/Circulation/CalcFine.t
+++ a/t/db_dependent/Circulation/CalcFine.t
@@ -90,17 +90,8 @@ subtest 'Test basic functionality' => sub {
}
);
- my $start_dt = DateTime->new(
- year => 2000,
- month => 1,
- day => 1,
- );
-
- my $end_dt = DateTime->new(
- year => 2000,
- month => 1,
- day => 30,
- );
+ my $start_dt = DateTime->today;
+ my $end_dt = DateTime->today->add(days => 29);
my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
@@ -129,17 +120,8 @@ subtest 'Test cap_fine_to_replacement_price' => sub {
}
);
- my $start_dt = DateTime->new(
- year => 2000,
- month => 1,
- day => 1,
- );
-
- my $end_dt = DateTime->new(
- year => 2000,
- month => 1,
- day => 30,
- );
+ my $start_dt = DateTime->today;
+ my $end_dt = DateTime->today->add(days => 29);
my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
--- a/t/db_dependent/Fines.t
+++ a/t/db_dependent/Fines.t
@@ -1,6 +1,7 @@
#!/usr/bin/perl
use Modern::Perl;
+use DateTime;
use C4::Context;
use C4::Overdues;
@@ -34,23 +35,23 @@ my $issuingrule = $schema->resultset('Issuingrule')->create(
ok( $issuingrule, 'Issuing rule created' );
-my $period_start = dt_from_string('2000-01-01');
-my $period_end = dt_from_string('2000-01-05');
+my $period_start = dt_from_string;
+my $period_end = dt_from_string->add(days => 4);
my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
-$period_end = dt_from_string('2000-01-10');
+$period_end = dt_from_string->add(days => 9);
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
# Test charging fine at the *beginning* of each charge period
$issuingrule->update( { chargeperiod_charge_at => 1 } );
-$period_end = dt_from_string('2000-01-05');
+$period_end = dt_from_string->add(days => 4);
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
-$period_end = dt_from_string('2000-01-10');
+$period_end = dt_from_string->add(days => 9);
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end );
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );
--- a/t/db_dependent/HoldsQueue.t
+++ a/t/db_dependent/HoldsQueue.t
@@ -11,9 +11,9 @@ use Modern::Perl;
use Test::More tests => 44;
use Data::Dumper;
-use C4::Calendar;
use C4::Context;
use C4::Members;
+use Koha::DiscreteCalendar;
use Koha::Database;
use Koha::DateUtils;
use Koha::Items;
@@ -189,6 +189,21 @@ $library2 = $builder->build({
$library3 = $builder->build({
source => 'Branch',
});
+
+$schema->resultset('DiscreteCalendar')->search({
+ branchcode =>''
+})->update_all({
+ is_opened => 1,
+ holiday_type => '',
+ note => '',
+ open_hour => '08:00:00',
+ close_hour => '16:00:00'
+});
+
+Koha::DiscreteCalendar->new( branchcode => '' )->add_new_branch('', $library1->{branchcode});
+Koha::DiscreteCalendar->new( branchcode => '' )->add_new_branch('', $library2->{branchcode});
+Koha::DiscreteCalendar->new( branchcode => '' )->add_new_branch('', $library3->{branchcode});
+
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
my $borrower1 = $builder->build({
@@ -302,16 +317,17 @@ is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue fill
# have 1 row in the holds queue
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1);
my $today = dt_from_string();
-C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday(
- day => $today->day(),
- month => $today->month(),
- year => $today->year(),
- title => "$today",
- description => "$today",
-);
+
# If the test below is removed, aother tests using the holiday will fail. For some reason if we call is_holiday now
# the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead.
-is( Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' );
+Koha::DiscreteCalendar->new( branchcode => $branchcodes[0] )->edit_holiday({
+ title => "Today",
+ holiday_type => "E",
+ start_date => $today,
+ end_date => $today
+});
+
+is( Koha::DiscreteCalendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' );
C4::HoldsQueue::CreateQueue();
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
--