Lines 2270-2275
depending on how many rows are in serial table.
Link Here
|
2270 |
The issue number calculation is based on subscription frequency, first acquisition |
2270 |
The issue number calculation is based on subscription frequency, first acquisition |
2271 |
date, and $publisheddate. |
2271 |
date, and $publisheddate. |
2272 |
|
2272 |
|
|
|
2273 |
The routine is used to skip irregularities when calculating the next issue |
2274 |
date (in GetNextDate) or the next issue number (in GetNextSeq). |
2275 |
|
2273 |
=cut |
2276 |
=cut |
2274 |
|
2277 |
|
2275 |
sub GetFictiveIssueNumber { |
2278 |
sub GetFictiveIssueNumber { |
Lines 2295-2302
sub GetFictiveIssueNumber {
Link Here
|
2295 |
$delta = ($fa_year == $year) |
2298 |
$delta = ($fa_year == $year) |
2296 |
? ($month - $fa_month) |
2299 |
? ($month - $fa_month) |
2297 |
: ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) ); |
2300 |
: ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) ); |
2298 |
} elsif($unit eq 'year') { |
2301 |
} elsif( $unit eq 'year' ) { |
2299 |
$delta = $year - $fa_year; |
2302 |
$delta = _delta_units( [ $fa_year, $fa_month, $fa_day ], [ $year, $month, $day ], 'year' ); |
2300 |
} |
2303 |
} |
2301 |
if($frequency->{'unitsperissue'} == 1) { |
2304 |
if($frequency->{'unitsperissue'} == 1) { |
2302 |
$issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'}; |
2305 |
$issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'}; |
Lines 2308-2313
sub GetFictiveIssueNumber {
Link Here
|
2308 |
return $issueno; |
2311 |
return $issueno; |
2309 |
} |
2312 |
} |
2310 |
|
2313 |
|
|
|
2314 |
sub _delta_units { |
2315 |
# wrapper around N_Delta_YMD |
2316 |
# Note that N_Delta_YMD returns 29 days between e.g. 22-2-72 and 22-3-72 |
2317 |
# while we expect 1 month. |
2318 |
my ( $date1, $date2, $unit ) = @_; |
2319 |
my @delta = N_Delta_YMD( @$date1, @$date2 ); |
2320 |
if( $delta[2] > 27 ) { |
2321 |
# Check if we could add a month |
2322 |
my @jump = Add_Delta_YM( @$date1, $delta[0], 1 + $delta[1] ); |
2323 |
if( Delta_Days( @jump, @$date2 ) >= 0 ) { |
2324 |
$delta[1]++; |
2325 |
} |
2326 |
} |
2327 |
if( $delta[1] >= 12 ) { |
2328 |
$delta[0]++; |
2329 |
$delta[1] -= 12; |
2330 |
} |
2331 |
# if unit is year, we only return full years |
2332 |
return $unit eq 'month' ? $delta[0] * 12 + $delta[1] : $delta[0]; |
2333 |
} |
2334 |
|
2311 |
sub _get_next_date_day { |
2335 |
sub _get_next_date_day { |
2312 |
my ($subscription, $freqdata, $year, $month, $day) = @_; |
2336 |
my ($subscription, $freqdata, $year, $month, $day) = @_; |
2313 |
|
2337 |
|
Lines 2372-2394
sub _get_next_date_month {
Link Here
|
2372 |
sub _get_next_date_year { |
2396 |
sub _get_next_date_year { |
2373 |
my ($subscription, $freqdata, $year, $month, $day) = @_; |
2397 |
my ($subscription, $freqdata, $year, $month, $day) = @_; |
2374 |
|
2398 |
|
2375 |
my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{firstacquidate}; |
2399 |
my @newissue; # ( yy, mm, dd ) |
|
|
2400 |
my $delta_days = int( 365 / $freqdata->{issuesperunit} ); |
2376 |
|
2401 |
|
2377 |
if ($subscription->{countissuesperunit} + 1 > $freqdata->{issuesperunit}){ |
2402 |
if( $freqdata->{issuesperunit} == 1 ) { |
2378 |
$subscription->{countissuesperunit} = 1; |
2403 |
# Add full years |
2379 |
($year) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); |
2404 |
@newissue = Add_Delta_YM( $year, $month, $day, $freqdata->{"unitsperissue"}, 0 ); |
2380 |
$month = $fa_month; |
2405 |
} elsif ( $subscription->{countissuesperunit} < $freqdata->{issuesperunit} ) { |
2381 |
my $days_in_month = Days_in_Month($year, $month); |
2406 |
# Add rounded number of days based on frequency. |
2382 |
$day = $fa_day <= $days_in_month ? $fa_day : $days_in_month; |
2407 |
@newissue = Add_Delta_Days( $year, $month, $day, $delta_days ); |
2383 |
} else { |
|
|
2384 |
# Try to guess the next day in year |
2385 |
my $days_in_year = Days_in_Year($year,12); #Sum the days of all the months of this year |
2386 |
my $delta_days = int(($days_in_year - ($fa_day - 1)) / $freqdata->{issuesperunit}); |
2387 |
($year,$month,$day) = Add_Delta_Days($year, $month, $day, $delta_days); |
2388 |
$subscription->{countissuesperunit}++; |
2408 |
$subscription->{countissuesperunit}++; |
|
|
2409 |
} else { |
2410 |
# We finished a cycle of issues within a unit. |
2411 |
# Subtract delta * (issues - 1), add 1 year |
2412 |
@newissue = Add_Delta_Days( $year, $month, $day, -$delta_days * ($freqdata->{issuesperunit} - 1) ); |
2413 |
@newissue = Add_Delta_YM( @newissue, 1, 0 ); |
2414 |
$subscription->{countissuesperunit} = 1; |
2389 |
} |
2415 |
} |
2390 |
|
2416 |
return @newissue; |
2391 |
return ($year, $month, $day); |
|
|
2392 |
} |
2417 |
} |
2393 |
|
2418 |
|
2394 |
=head2 GetNextDate |
2419 |
=head2 GetNextDate |
2395 |
- |
|
|