Lines 889-914
sub GetDistributedTo {
Link Here
|
889 |
|
889 |
|
890 |
=head2 GetNextSeq |
890 |
=head2 GetNextSeq |
891 |
|
891 |
|
892 |
GetNextSeq($val) |
892 |
my ( |
893 |
$val is a hashref containing all the attributes of the table 'subscription' |
893 |
$nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
|
|
894 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 |
895 |
) = GetNextSeq( $subscription, $pattern, $planneddate ); |
896 |
|
897 |
$subscription is a hashref containing all the attributes of the table |
898 |
'subscription'. |
899 |
$pattern is a hashref containing all the attributes of the table |
900 |
'subscription_numberpatterns'. |
901 |
$planneddate is a C4::Dates object. |
894 |
This function get the next issue for the subscription given on input arg |
902 |
This function get the next issue for the subscription given on input arg |
895 |
return: |
|
|
896 |
a list containing all the input params updated. |
897 |
|
903 |
|
898 |
=cut |
904 |
=cut |
899 |
|
905 |
|
900 |
sub GetNextSeq { |
906 |
sub GetNextSeq { |
901 |
my ($val, $planneddate) = @_; |
907 |
my ($subscription, $pattern, $planneddate) = @_; |
902 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
908 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
903 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
909 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
904 |
my $count = 1; |
910 |
my $count = 1; |
905 |
|
911 |
|
906 |
if($val->{'skip_serialseq'}) { |
912 |
if ($subscription->{'skip_serialseq'}) { |
907 |
my @irreg = split /;/, $val->{'irregularity'}; |
913 |
my @irreg = split /;/, $subscription->{'irregularity'}; |
908 |
if(@irreg > 0) { |
914 |
if(@irreg > 0) { |
909 |
my $irregularities = {}; |
915 |
my $irregularities = {}; |
910 |
$irregularities->{$_} = 1 foreach(@irreg); |
916 |
$irregularities->{$_} = 1 foreach(@irreg); |
911 |
my $issueno = GetFictiveIssueNumber($val, $planneddate) + 1; |
917 |
my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1; |
912 |
while($irregularities->{$issueno}) { |
918 |
while($irregularities->{$issueno}) { |
913 |
$count++; |
919 |
$count++; |
914 |
$issueno++; |
920 |
$issueno++; |
Lines 916-977
sub GetNextSeq {
Link Here
|
916 |
} |
922 |
} |
917 |
} |
923 |
} |
918 |
|
924 |
|
919 |
my $pattern = $val->{numberpattern}; |
925 |
my $numberingmethod = $pattern->{numberingmethod}; |
920 |
$calculated = $val->{numberingmethod}; |
926 |
$calculated = $numberingmethod; |
921 |
my $locale = $val->{locale}; |
927 |
my $locale = $subscription->{locale}; |
922 |
$newlastvalue1 = $val->{lastvalue1} || 0; |
928 |
$newlastvalue1 = $subscription->{lastvalue1} || 0; |
923 |
$newlastvalue2 = $val->{lastvalue2} || 0; |
929 |
$newlastvalue2 = $subscription->{lastvalue2} || 0; |
924 |
$newlastvalue3 = $val->{lastvalue3} || 0; |
930 |
$newlastvalue3 = $subscription->{lastvalue3} || 0; |
925 |
$newinnerloop1 = $val->{innerloop1} || 0; |
931 |
$newinnerloop1 = $subscription->{innerloop1} || 0; |
926 |
$newinnerloop2 = $val->{innerloop2} || 0; |
932 |
$newinnerloop2 = $subscription->{innerloop2} || 0; |
927 |
$newinnerloop3 = $val->{innerloop3} || 0; |
933 |
$newinnerloop3 = $subscription->{innerloop3} || 0; |
928 |
my %calc; |
934 |
my %calc; |
929 |
foreach(qw/X Y Z/) { |
935 |
foreach(qw/X Y Z/) { |
930 |
$calc{$_} = 1 if ($val->{'numberingmethod'} =~ /\{$_\}/); |
936 |
$calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/); |
931 |
} |
937 |
} |
932 |
|
938 |
|
933 |
for(my $i = 0; $i < $count; $i++) { |
939 |
for(my $i = 0; $i < $count; $i++) { |
934 |
if($calc{'X'}) { |
940 |
if($calc{'X'}) { |
935 |
# check if we have to increase the new value. |
941 |
# check if we have to increase the new value. |
936 |
$newinnerloop1 += 1; |
942 |
$newinnerloop1 += 1; |
937 |
if ($newinnerloop1 >= $val->{every1}) { |
943 |
if ($newinnerloop1 >= $pattern->{every1}) { |
938 |
$newinnerloop1 = 0; |
944 |
$newinnerloop1 = 0; |
939 |
$newlastvalue1 += $val->{add1}; |
945 |
$newlastvalue1 += $pattern->{add1}; |
940 |
} |
946 |
} |
941 |
# reset counter if needed. |
947 |
# reset counter if needed. |
942 |
$newlastvalue1 = $val->{setto1} if ($newlastvalue1 > $val->{whenmorethan1}); |
948 |
$newlastvalue1 = $pattern->{setto1} if ($newlastvalue1 > $pattern->{whenmorethan1}); |
943 |
} |
949 |
} |
944 |
if($calc{'Y'}) { |
950 |
if($calc{'Y'}) { |
945 |
# check if we have to increase the new value. |
951 |
# check if we have to increase the new value. |
946 |
$newinnerloop2 += 1; |
952 |
$newinnerloop2 += 1; |
947 |
if ($newinnerloop2 >= $val->{every2}) { |
953 |
if ($newinnerloop2 >= $pattern->{every2}) { |
948 |
$newinnerloop2 = 0; |
954 |
$newinnerloop2 = 0; |
949 |
$newlastvalue2 += $val->{add2}; |
955 |
$newlastvalue2 += $pattern->{add2}; |
950 |
} |
956 |
} |
951 |
# reset counter if needed. |
957 |
# reset counter if needed. |
952 |
$newlastvalue2 = $val->{setto2} if ($newlastvalue2 > $val->{whenmorethan2}); |
958 |
$newlastvalue2 = $pattern->{setto2} if ($newlastvalue2 > $pattern->{whenmorethan2}); |
953 |
} |
959 |
} |
954 |
if($calc{'Z'}) { |
960 |
if($calc{'Z'}) { |
955 |
# check if we have to increase the new value. |
961 |
# check if we have to increase the new value. |
956 |
$newinnerloop3 += 1; |
962 |
$newinnerloop3 += 1; |
957 |
if ($newinnerloop3 >= $val->{every3}) { |
963 |
if ($newinnerloop3 >= $pattern->{every3}) { |
958 |
$newinnerloop3 = 0; |
964 |
$newinnerloop3 = 0; |
959 |
$newlastvalue3 += $val->{add3}; |
965 |
$newlastvalue3 += $pattern->{add3}; |
960 |
} |
966 |
} |
961 |
# reset counter if needed. |
967 |
# reset counter if needed. |
962 |
$newlastvalue3 = $val->{setto3} if ($newlastvalue3 > $val->{whenmorethan3}); |
968 |
$newlastvalue3 = $pattern->{setto3} if ($newlastvalue3 > $pattern->{whenmorethan3}); |
963 |
} |
969 |
} |
964 |
} |
970 |
} |
965 |
if($calc{'X'}) { |
971 |
if($calc{'X'}) { |
966 |
my $newlastvalue1string = _numeration( $newlastvalue1, $val->{numbering1}, $locale ); |
972 |
my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale ); |
967 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
973 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
968 |
} |
974 |
} |
969 |
if($calc{'Y'}) { |
975 |
if($calc{'Y'}) { |
970 |
my $newlastvalue2string = _numeration( $newlastvalue2, $val->{numbering2}, $locale ); |
976 |
my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale ); |
971 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
977 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
972 |
} |
978 |
} |
973 |
if($calc{'Z'}) { |
979 |
if($calc{'Z'}) { |
974 |
my $newlastvalue3string = _numeration( $newlastvalue3, $val->{numbering3}, $locale ); |
980 |
my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale ); |
975 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
981 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
976 |
} |
982 |
} |
977 |
|
983 |
|
Lines 982-1012
sub GetNextSeq {
Link Here
|
982 |
|
988 |
|
983 |
=head2 GetSeq |
989 |
=head2 GetSeq |
984 |
|
990 |
|
985 |
$calculated = GetSeq($val) |
991 |
$calculated = GetSeq($subscription, $pattern) |
986 |
$val is a hashref containing all the attributes of the table 'subscription' |
992 |
$subscription is a hashref containing all the attributes of the table 'subscription' |
|
|
993 |
$pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns' |
987 |
this function transforms {X},{Y},{Z} to 150,0,0 for example. |
994 |
this function transforms {X},{Y},{Z} to 150,0,0 for example. |
988 |
return: |
995 |
return: |
989 |
the sequence in integer format |
996 |
the sequence in string format |
990 |
|
997 |
|
991 |
=cut |
998 |
=cut |
992 |
|
999 |
|
993 |
sub GetSeq { |
1000 |
sub GetSeq { |
994 |
my ($val) = @_; |
1001 |
my ($subscription, $pattern) = @_; |
995 |
my $locale = $val->{locale}; |
1002 |
my $locale = $subscription->{locale}; |
996 |
|
1003 |
|
997 |
my $pattern = $val->{numberpattern}; |
1004 |
my $calculated = $pattern->{numberingmethod}; |
998 |
my $calculated = $val->{numberingmethod}; |
|
|
999 |
|
1005 |
|
1000 |
my $newlastvalue1 = $val->{'lastvalue1'} || 0; |
1006 |
my $newlastvalue1 = $subscription->{'lastvalue1'} || 0; |
1001 |
$newlastvalue1 = _numeration($newlastvalue1, $val->{numbering1}, $locale) if ($val->{numbering1}); # reset counter if needed. |
1007 |
$newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed. |
1002 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
1008 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
1003 |
|
1009 |
|
1004 |
my $newlastvalue2 = $val->{'lastvalue2'} || 0; |
1010 |
my $newlastvalue2 = $subscription->{'lastvalue2'} || 0; |
1005 |
$newlastvalue2 = _numeration($newlastvalue2, $val->{numbering2}, $locale) if ($val->{numbering2}); # reset counter if needed. |
1011 |
$newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed. |
1006 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
1012 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
1007 |
|
1013 |
|
1008 |
my $newlastvalue3 = $val->{'lastvalue3'} || 0; |
1014 |
my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; |
1009 |
$newlastvalue3 = _numeration($newlastvalue3, $val->{numbering3}, $locale) if ($val->{numbering3}); # reset counter if needed. |
1015 |
$newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed. |
1010 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
1016 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
1011 |
return $calculated; |
1017 |
return $calculated; |
1012 |
} |
1018 |
} |
Lines 1205-1238
sub ModSerialStatus {
Link Here
|
1205 |
|
1211 |
|
1206 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1212 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1207 |
if ( $oldstatus == 1 && $status != 1 ) { |
1213 |
if ( $oldstatus == 1 && $status != 1 ) { |
1208 |
my $query = qq{ |
1214 |
my $subscription = GetSubscription($subscriptionid); |
1209 |
SELECT subscription.*, subscription_numberpatterns.*, |
1215 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1210 |
subscription_frequencies.* |
|
|
1211 |
FROM subscription |
1212 |
LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id |
1213 |
LEFT JOIN subscription_frequencies ON subscription.periodicity = subscription_frequencies.id |
1214 |
WHERE subscriptionid = ? |
1215 |
}; |
1216 |
$sth = $dbh->prepare($query); |
1217 |
$sth->execute($subscriptionid); |
1218 |
my $val = $sth->fetchrow_hashref; |
1219 |
|
1216 |
|
1220 |
# next issue number |
1217 |
# next issue number |
1221 |
my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($val, $publisheddate); |
1218 |
my ( |
|
|
1219 |
$newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
1220 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 |
1221 |
) |
1222 |
= GetNextSeq( $subscription, $pattern, $publisheddate ); |
1222 |
|
1223 |
|
1223 |
# next date (calculated from actual date & frequency parameters) |
1224 |
# next date (calculated from actual date & frequency parameters) |
1224 |
my $nextpublisheddate = GetNextDate($val, $publisheddate, 1); |
1225 |
my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); |
1225 |
my $nextpubdate = $nextpublisheddate; |
1226 |
my $nextpubdate = $nextpublisheddate; |
1226 |
NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpubdate, $nextpubdate ); |
1227 |
NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate ); |
1227 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1228 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1228 |
WHERE subscriptionid = ?"; |
1229 |
WHERE subscriptionid = ?"; |
1229 |
$sth = $dbh->prepare($query); |
1230 |
$sth = $dbh->prepare($query); |
1230 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1231 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1231 |
|
1232 |
|
1232 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1233 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1233 |
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) { |
1234 |
if ( $subscription->{letter} && $status == 2 && $oldstatus != 2 ) { |
1234 |
require C4::Letters; |
1235 |
require C4::Letters; |
1235 |
C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} ); |
1236 |
C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} ); |
1236 |
} |
1237 |
} |
1237 |
} |
1238 |
} |
1238 |
|
1239 |
|
Lines 1275-1281
sub GetNextExpected {
Link Here
|
1275 |
SELECT * |
1276 |
SELECT * |
1276 |
FROM serial |
1277 |
FROM serial |
1277 |
WHERE subscriptionid = ? |
1278 |
WHERE subscriptionid = ? |
1278 |
ORDER BY planneddate DESC |
1279 |
ORDER BY publisheddate DESC |
1279 |
LIMIT 1 |
1280 |
LIMIT 1 |
1280 |
}; |
1281 |
}; |
1281 |
$sth = $dbh->prepare($query); |
1282 |
$sth = $dbh->prepare($query); |
Lines 1475-1492
sub NewSubscription {
Link Here
|
1475 |
$sth->execute( $biblionumber, $subscriptionid, $startdate, $notes, $internalnotes ); |
1476 |
$sth->execute( $biblionumber, $subscriptionid, $startdate, $notes, $internalnotes ); |
1476 |
|
1477 |
|
1477 |
# reread subscription to get a hash (for calculation of the 1st issue number) |
1478 |
# reread subscription to get a hash (for calculation of the 1st issue number) |
1478 |
$query = qq( |
1479 |
my $subscription = GetSubscription($subscriptionid); |
1479 |
SELECT * |
1480 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); |
1480 |
FROM subscription |
|
|
1481 |
LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id |
1482 |
WHERE subscriptionid = ? |
1483 |
); |
1484 |
$sth = $dbh->prepare($query); |
1485 |
$sth->execute($subscriptionid); |
1486 |
my $val = $sth->fetchrow_hashref; |
1487 |
|
1481 |
|
1488 |
# calculate issue number |
1482 |
# calculate issue number |
1489 |
my $serialseq = GetSeq($val); |
1483 |
my $serialseq = GetSeq($subscription, $pattern); |
1490 |
$query = qq| |
1484 |
$query = qq| |
1491 |
INSERT INTO serial |
1485 |
INSERT INTO serial |
1492 |
(serialseq,subscriptionid,biblionumber,status, planneddate, publisheddate) |
1486 |
(serialseq,subscriptionid,biblionumber,status, planneddate, publisheddate) |