- my $per = $subscription->{'periodicity'};
- if ( $per % 16 > 0 ) {
- my $expirationdate = $subscription->{enddate};
- my $sth = $dbh->prepare("select max(planneddate) from serial where subscriptionid=?");
- $sth->execute($subscriptionid);
- my ($res) = $sth->fetchrow;
- my @res = split( /-/, $res );
- @res = Date::Calc::Today if ( $res[0] * $res[1] == 0 );
- my @endofsubscriptiondate = split( /-/, $expirationdate );
- my $x;
- if ( $per == 1 ) { $x = 7; }
- if ( $per == 2 ) { $x = 7; }
- if ( $per == 3 ) { $x = 14; }
- if ( $per == 4 ) { $x = 21; }
- if ( $per == 5 ) { $x = 31; }
- if ( $per == 6 ) { $x = 62; }
- if ( $per == 7 || $per == 8 ) { $x = 93; }
- if ( $per == 9 ) { $x = 190; }
- if ( $per == 10 ) { $x = 365; }
- if ( $per == 11 ) { $x = 730; }
- my @datebeforeend = Add_Delta_Days( $endofsubscriptiondate[0], $endofsubscriptiondate[1], $endofsubscriptiondate[2], -( 3 * $x ) )
- if ( @endofsubscriptiondate && $endofsubscriptiondate[0] * $endofsubscriptiondate[1] * $endofsubscriptiondate[2] );
-
- # warn "DATE BEFORE END: $datebeforeend";
- return 1
- if (
- @res
- && ( @datebeforeend
- && Delta_Days( $res[0], $res[1], $res[2], $datebeforeend[0], $datebeforeend[1], $datebeforeend[2] ) <= 0 )
- && ( @endofsubscriptiondate
- && Delta_Days( $res[0], $res[1], $res[2], $endofsubscriptiondate[0], $endofsubscriptiondate[1], $endofsubscriptiondate[2] ) >= 0 )
- );
- return 0;
- } elsif ( $subscription->{numberlength} > 0 ) {
- return ( countissuesfrom( $subscriptionid, $subscription->{'startdate'} ) >= $subscription->{numberlength} - 1 );
- } else {
+ my $per = $subscription->{'periodicity'};
+ if ($per && $per % 16 > 0){
+ my $expirationdate = GetExpirationDate($subscriptionid);
+ my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
+ my @res;
+ if (defined $res) {
+ @res=split (/-/,$res);
+ @res=Date::Calc::Today if ($res[0]*$res[1]==0);
+ } else { # default an undefined value
+ @res=Date::Calc::Today;
+ }
+ my @endofsubscriptiondate=split(/-/,$expirationdate);
+ my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 0, 0, 0);
+ my @datebeforeend;
+ @datebeforeend = Add_Delta_Days( $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2],
+ - (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]);
+ return 1 if ( @res &&
+ (@datebeforeend &&
+ Delta_Days($res[0],$res[1],$res[2],
+ $datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) <= 0) &&
+ (@endofsubscriptiondate &&
+ Delta_Days($res[0],$res[1],$res[2],
+ $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) >= 0) );