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

(-)a/Koha/DiscreteCalendar.pm (-3 / +79 lines)
Lines 875-880 sub open_hours_between { Link Here
875
875
876
    return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours'));
876
    return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours'));
877
}
877
}
878
879
sub open_minutes_between {
880
    my ($self, $start_date, $end_date) = @_;
881
    my $branchcode = $self->{branchcode};
882
    my $schema = Koha::Database->new->schema;
883
    my $dtf = $schema->storage->datetime_parser;
884
    $start_date = $dtf->format_datetime($start_date);
885
    $end_date = $dtf->format_datetime($end_date);
886
887
    my $working_minutes_between = $schema->resultset('DiscreteCalendar')->search(
888
        {
889
            branchcode  => $branchcode,
890
            isopened    => 1,
891
        },
892
        {
893
            select  => \['sum(time_to_sec(timediff(closehour, openhour)) / 60)'],
894
            as      => [qw /minutes_between/],
895
            where   => \['date BETWEEN DATE(?) AND DATE(?)', $start_date, $end_date]
896
        }
897
    );
898
899
    my $loan_day = $schema->resultset('DiscreteCalendar')->search(
900
        {
901
            branchcode  => $branchcode,
902
        },
903
        {
904
            where       => \['date = DATE(?)', $start_date],
905
        }
906
    );
907
908
    my $return_day = $schema->resultset('DiscreteCalendar')->search(
909
        {
910
            branchcode  => $branchcode,
911
        },
912
        {
913
            where       => \['date = DATE(?)', $end_date],
914
        }
915
    );
916
917
    #Capture the time portion of the date
918
    $start_date =~ /\s(.*)/;
919
    my $loan_date_time = $1;
920
    $end_date =~ /\s(.*)/;
921
    my $return_date_time = $1;
922
923
    my $not_used_minutes = $schema->resultset('DiscreteCalendar')->search(
924
        {
925
            branchcode  => $branchcode,
926
            isopened    => 1,
927
        },
928
        {
929
            select  => \[ '(time_to_sec(timediff(?, ?)) + time_to_sec(timediff(?, ?)) ) / 60', $return_day->next()->closehour(), $return_date_time, $loan_date_time, $loan_day->next()->openhour()],
930
            as      => [qw /not_used_minutes/],
931
        }
932
    );
933
934
    return DateTime::Duration->new( minutes => $working_minutes_between->next()->get_column('minutes_between') - $not_used_minutes->next()->get_column('not_used_minutes'));
935
}
936
878
sub addDate {
937
sub addDate {
879
    my ( $self, $startdate, $add_duration, $unit ) = @_;
938
    my ( $self, $startdate, $add_duration, $unit ) = @_;
880
939
Lines 889-897 sub addDate { Link Here
889
    if ( $unit eq 'hours' ) {
948
    if ( $unit eq 'hours' ) {
890
        # Fixed for legacy support. Should be set as a branch parameter
949
        # Fixed for legacy support. Should be set as a branch parameter
891
        my $return_by_hour = 10;
950
        my $return_by_hour = 10;
892
893
        $dt = $self->addHours($startdate, $add_duration, $return_by_hour);
951
        $dt = $self->addHours($startdate, $add_duration, $return_by_hour);
894
    } else {
952
    } elsif($unit eq 'minutes'){
953
        $dt = $self->addMinutes($startdate, $add_duration);
954
    }else {
895
        # days
955
        # days
896
        $dt = $self->addDays($startdate, $add_duration);
956
        $dt = $self->addDays($startdate, $add_duration);
897
    }
957
    }
Lines 899-904 sub addDate { Link Here
899
    return $dt;
959
    return $dt;
900
}
960
}
901
961
962
sub addMinutes {
963
    my ( $self, $startdate, $minutes_duration) = @_;
964
    my $base_date = $startdate->clone();
965
966
    $base_date->add_duration($minutes_duration);
967
968
    my $dateInfo = $self->get_date_info($base_date);
969
970
    my $close_datetime = dt_from_string($dateInfo->{date} ." ". $dateInfo->{closehour}, 'iso');
971
972
    if(DateTime->compare($base_date, $close_datetime) > 0) {
973
        return $close_datetime;
974
    }
975
976
    return $base_date;
977
}
978
902
sub addHours {
979
sub addHours {
903
    my ( $self, $startdate, $hours_duration, $return_by_hour ) = @_;
980
    my ( $self, $startdate, $hours_duration, $return_by_hour ) = @_;
904
    my $base_date = $startdate->clone();
981
    my $base_date = $startdate->clone();
905
- 

Return to bug 17983