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

(-)a/C4/Serials.pm (-1 / +45 lines)
Lines 24-29 use C4::Auth qw(haspermission); Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Dates qw(format_date format_date_in_iso);
25
use C4::Dates qw(format_date format_date_in_iso);
26
use DateTime;
26
use DateTime;
27
use DateTime::Format::MySQL;
27
use Date::Calc qw(:all);
28
use Date::Calc qw(:all);
28
use POSIX qw(strftime);
29
use POSIX qw(strftime);
29
use C4::Biblio;
30
use C4::Biblio;
Lines 268-274 sub GetSerialInformation { Link Here
268
        }
269
        }
269
    }
270
    }
270
    $data->{ "status" . $data->{'serstatus'} } = 1;
271
    $data->{ "status" . $data->{'serstatus'} } = 1;
271
    $data->{'subscriptionexpired'} = HasSubscriptionExpired( $data->{'subscriptionid'} ) && $data->{'status'} == 1;
272
    $data->{'subscriptionexpired'} = C4::Serials::HasSerialExpired( $data ) && $data->{'status'} == 1;
272
    $data->{'abouttoexpire'} = abouttoexpire( $data->{'subscriptionid'} );
273
    $data->{'abouttoexpire'} = abouttoexpire( $data->{'subscriptionid'} );
273
    $data->{cannotedit} = not can_edit_subscription( $data );
274
    $data->{cannotedit} = not can_edit_subscription( $data );
274
    return $data;
275
    return $data;
Lines 1878-1883 sub HasSubscriptionExpired { Link Here
1878
    return 0;    # Notice that you'll never get here.
1879
    return 0;    # Notice that you'll never get here.
1879
}
1880
}
1880
1881
1882
=head2 HasSerialExpired
1883
1884
$has_expired = HasSerialExpired($serial)
1885
1886
the serial has expired when the serials.publisheddate is beyond the subscription expiration date.
1887
1888
Used to check if individual serials can still be received even if the subscription
1889
has already expired.
1890
1891
@param {HASHRef} Serial
1892
1893
@returns : 0 if the serial has not expired
1894
           1 if the serial has expired
1895
           2 if has serial does not have a valid expiration date set
1896
           undef if something bad/strange hapened. This is VERY ODD default behaviour.
1897
1898
=cut
1899
1900
sub HasSerialExpired {
1901
    my ($serial) = @_;
1902
1903
    return unless ($serial);
1904
1905
    #Normalize dates for comparison
1906
    my ($expirationdate, $publisheddate);
1907
    eval {
1908
        $expirationdate = DateTime::Format::MySQL->parse_date($serial->{enddate} || GetExpirationDate($serial->{subscriptionid}));
1909
        $publisheddate =  Koha::DateUtils::dt_from_string($serial->{publisheddate});
1910
    };
1911
    if ($@) { #DateTime::Format can be finicky so let's not die on parsing errors.
1912
        warn $@;
1913
        return;
1914
    }
1915
1916
    if (!defined $expirationdate) {
1917
        return 2;
1918
    }
1919
    if (DateTime->compare($publisheddate, $expirationdate) == -1) { #publisheddate < expirationdate
1920
        return 0;
1921
    }
1922
    return 1;
1923
}
1924
1881
=head2 SetDistributedto
1925
=head2 SetDistributedto
1882
1926
1883
SetDistributedto($distributedto,$subscriptionid);
1927
SetDistributedto($distributedto,$subscriptionid);
(-)a/serials/serials-edit.pl (-2 / +1 lines)
Lines 147-153 foreach my $serialid (@serialids) { Link Here
147
147
148
        $serinfo->{'editdisable'} = (
148
        $serinfo->{'editdisable'} = (
149
            (
149
            (
150
                HasSubscriptionExpired( $serinfo->{subscriptionid} )
150
                C4::Serials::HasSerialExpired( $serinfo )
151
                && $serinfo->{'status1'}
151
                && $serinfo->{'status1'}
152
            )
152
            )
153
            || $serinfo->{'cannotedit'}
153
            || $serinfo->{'cannotedit'}
154
- 

Return to bug 11626