View | Details | Raw Unified | Return to bug 8800
Collapse All | Expand All

(-)a/C4/Circulation.pm (-11 / +27 lines)
Lines 971-980 AddIssue does the following things : Link Here
971
sub AddIssue {
971
sub AddIssue {
972
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_;
972
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_;
973
    my $dbh = C4::Context->dbh;
973
    my $dbh = C4::Context->dbh;
974
	my $barcodecheck=CheckValidBarcode($barcode);
974
975
    if ($datedue && ref $datedue ne 'DateTime') {
975
    my $barcodecheck=CheckValidBarcode($barcode);
976
        $datedue = dt_from_string($datedue);
976
977
    }
978
    # $issuedate defaults to today.
977
    # $issuedate defaults to today.
979
    if ( ! defined $issuedate ) {
978
    if ( ! defined $issuedate ) {
980
        $issuedate = DateTime->now(time_zone => C4::Context->tz());
979
        $issuedate = DateTime->now(time_zone => C4::Context->tz());
Lines 989-995 sub AddIssue { Link Here
989
		# find which item we issue
988
		# find which item we issue
990
		my $item = GetItem('', $barcode) or return undef;	# if we don't get an Item, abort.
989
		my $item = GetItem('', $barcode) or return undef;	# if we don't get an Item, abort.
991
		my $branch = _GetCircControlBranch($item,$borrower);
990
		my $branch = _GetCircControlBranch($item,$borrower);
992
		
991
992
                # $datedue was passed as a parameter, check validity
993
                # and adjust if mandated by sysprefs
994
                if ($datedue && ref $datedue ne 'DateTime') {
995
                    $datedue = dt_from_string($datedue);
996
                    my $calendar = Koha::Calendar->new( branchcode => $branch );
997
                    if ( C4::Context->preference('useDaysMode') eq 'Datedue' ) {
998
                        # use the calendar to push the due date to the next open day
999
                        $datedue = $calendar->next_open_day($datedue);
1000
                    }
1001
		}
1002
993
		# get actual issuing if there is one
1003
		# get actual issuing if there is one
994
		my $actualissue = GetItemIssue( $item->{itemnumber});
1004
		my $actualissue = GetItemIssue( $item->{itemnumber});
995
		
1005
		
Lines 2819-2840 sub CalcDateDue { Link Here
2819
            C4::Context->preference('dateformat')
2829
            C4::Context->preference('dateformat')
2820
        );
2830
        );
2821
    } else {
2831
    } else {
2822
2823
        # otherwise, calculate the datedue as normal
2832
        # otherwise, calculate the datedue as normal
2824
        if ( C4::Context->preference('useDaysMode') eq 'Days' )
2833
        my $calendar = Koha::Calendar->new( branchcode => $branch );
2825
        {    # ignoring calendar
2834
2835
        if ( C4::Context->preference('useDaysMode') ne 'Calendar' )
2836
        {   # ignoring calendar to calculate date due
2826
            my $dt =
2837
            my $dt =
2827
              DateTime->now( time_zone => C4::Context->tz() )
2838
              DateTime->now( time_zone => C4::Context->tz() )
2828
              ->truncate( to => 'minute' );
2839
              ->truncate( to => 'minute' );
2829
            if ( $loanlength->{lengthunit} eq 'hours' ) {
2840
            if ( $loanlength->{lengthunit} eq 'hours' ) {
2830
                $dt->add( hours => $loanlength->{issuelength} );
2841
                $dt->add( hours => $loanlength->{issuelength} );
2831
                return $dt;
2832
            } else {    # days
2842
            } else {    # days
2833
                $dt->add( days => $loanlength->{issuelength} );
2843
                $dt->add( days => $loanlength->{issuelength} );
2834
                $dt->set_hour(23);
2844
                $dt->set_hour(23);
2835
                $dt->set_minute(59);
2845
                $dt->set_minute(59);
2836
                return $dt;
2837
            }
2846
            }
2847
            
2848
            if ( C4::Context->preference('useDaysMode') eq 'Datedue' ) {
2849
                # use the calendar to push the due date to the next open day
2850
                $dt = $calendar->next_open_day($dt);
2851
            }
2852
2853
            return $dt;
2854
2838
        } else {
2855
        } else {
2839
            my $dur;
2856
            my $dur;
2840
            if ($loanlength->{lengthunit} eq 'hours') {
2857
            if ($loanlength->{lengthunit} eq 'hours') {
Lines 2846-2852 sub CalcDateDue { Link Here
2846
            if (ref $startdate ne 'DateTime' ) {
2863
            if (ref $startdate ne 'DateTime' ) {
2847
                $startdate = dt_from_string($startdate);
2864
                $startdate = dt_from_string($startdate);
2848
            }
2865
            }
2849
            my $calendar = Koha::Calendar->new( branchcode => $branch );
2850
            $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
2866
            $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
2851
            if ($loanlength->{lengthunit} eq 'days') {
2867
            if ($loanlength->{lengthunit} eq 'days') {
2852
                $datedue->set_hour(23);
2868
                $datedue->set_hour(23);
(-)a/Koha/Calendar.pm (-3 / +23 lines)
Lines 164-169 sub is_holiday { Link Here
164
    return 0;
164
    return 0;
165
}
165
}
166
166
167
sub next_open_day {
168
    my ( $self, $dt ) = @_;
169
170
    while ($self->is_holiday($dt)) {
171
        $dt->add(days => 1);
172
    }
173
174
    return $dt;
175
}
176
167
sub days_between {
177
sub days_between {
168
    my $self     = shift;
178
    my $self     = shift;
169
    my $start_dt = shift;
179
    my $start_dt = shift;
Lines 273-281 This documentation refers to Koha::Calendar version 0.0.1 Link Here
273
283
274
=head1 SYNOPSIS
284
=head1 SYNOPSIS
275
285
276
  use Koha::Calendat
286
  use Koha::Calendar
277
287
278
  my $c = Koha::Calender->new( branchcode => 'MAIN' );
288
  my $c = Koha::Calendar->new( branchcode => 'MAIN' );
279
  my $dt = DateTime->now();
289
  my $dt = DateTime->now();
280
290
281
  # are we open
291
  # are we open
Lines 315-321 parameter will be removed when issuingrules properly cope with that Link Here
315
325
316
$yesno = $calendar->is_holiday($dt);
326
$yesno = $calendar->is_holiday($dt);
317
327
318
passed at DateTime object returns 1 if it is a closed day
328
passed a DateTime object returns 1 if it is a closed day
319
0 if not according to the calendar
329
0 if not according to the calendar
320
330
321
=head2 days_between
331
=head2 days_between
Lines 326-331 Passed two dates returns a DateTime::Duration object measuring the length betwee Link Here
326
ignoring closed days. Always returns a positive number irrespective of the
336
ignoring closed days. Always returns a positive number irrespective of the
327
relative order of the parameters
337
relative order of the parameters
328
338
339
=head2 next_open_day
340
341
$datetime = $calendar->next_open_day($duedate_dt)
342
343
Passed a Datetime returns another Datetime representing the next open day. It is
344
intended for use to calculate the due date when useDaysMode syspref is set to either
345
'Datedue' or 'Calendar'.
346
347
Note: if is_holiday($duedate_dt) = 0 then it should return the same date.
348
329
=head2 set_daysmode
349
=head2 set_daysmode
330
350
331
For testing only allows the calling script to change days mode
351
For testing only allows the calling script to change days mode
(-)a/t/Calendar.t (-2 / +5 lines)
Lines 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
use DateTime;
5
use DateTime;
6
use Test::More tests => 21;
6
use Test::More tests => 23;
7
use Koha::DateUtils;
7
use Koha::DateUtils;
8
8
9
BEGIN {
9
BEGIN {
Lines 127-129 $cal->add_holiday( dt_from_string('2012-07-07','iso') ); Link Here
127
$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
127
$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
128
    dt_from_string("2012-07-15",'iso') )->in_units('days');
128
    dt_from_string("2012-07-15",'iso') )->in_units('days');
129
cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' );
129
cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' );
130
- 
130
$dt = dt_from_string('2012-07-07','iso');
131
cmp_ok( $dt->add(days => 1), '==', $cal->next_open_day(dt_from_string('2012-07-07','iso')), 'Next open day correctly calculated' );
132
$dt = dt_from_string('2012-07-08','iso');
133
cmp_ok( $dt, '==', $cal->next_open_day(dt_from_string('2012-07-08','iso')), 'Next open day correctly calculated (idempotent version)' );

Return to bug 8800