Lines 18-31
package C4::Serials;
Link Here
|
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
20 |
|
21 |
use strict; |
21 |
use Modern::Perl; |
22 |
use warnings; |
22 |
|
23 |
use C4::Dates qw(format_date format_date_in_iso); |
23 |
use C4::Dates qw(format_date format_date_in_iso); |
24 |
use Date::Calc qw(:all); |
24 |
use Date::Calc qw(:all); |
25 |
use POSIX qw(strftime); |
25 |
use POSIX qw(strftime setlocale LC_TIME); |
26 |
use C4::Biblio; |
26 |
use C4::Biblio; |
27 |
use C4::Log; # logaction |
27 |
use C4::Log; # logaction |
28 |
use C4::Debug; |
28 |
use C4::Debug; |
|
|
29 |
use C4::Serials::Frequency; |
30 |
use C4::Serials::Numberpattern; |
29 |
|
31 |
|
30 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
32 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
31 |
|
33 |
|
Lines 39-46
BEGIN {
Link Here
|
39 |
&SearchSubscriptions |
41 |
&SearchSubscriptions |
40 |
&GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory |
42 |
&GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory |
41 |
&HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire |
43 |
&HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire |
|
|
44 |
&GetSubscriptionHistoryFromSubscriptionId |
42 |
|
45 |
|
43 |
&GetNextSeq &NewIssue &ItemizeSerials &GetSerials |
46 |
&GetNextSeq &GetSeq &NewIssue &ItemizeSerials &GetSerials |
44 |
&GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 |
47 |
&GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 |
45 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
48 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
46 |
&GetSerialInformation &AddItem2Serial |
49 |
&GetSerialInformation &AddItem2Serial |
Lines 162-181
sub GetLateIssues {
Link Here
|
162 |
|
165 |
|
163 |
=head2 GetSubscriptionHistoryFromSubscriptionId |
166 |
=head2 GetSubscriptionHistoryFromSubscriptionId |
164 |
|
167 |
|
165 |
$sth = GetSubscriptionHistoryFromSubscriptionId() |
168 |
$history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid); |
166 |
this function prepares the SQL request and returns the statement handle |
169 |
|
167 |
After this function, don't forget to execute it by using $sth->execute($subscriptionid) |
170 |
This function returns the subscription history as a hashref |
168 |
|
171 |
|
169 |
=cut |
172 |
=cut |
170 |
|
173 |
|
171 |
sub GetSubscriptionHistoryFromSubscriptionId { |
174 |
sub GetSubscriptionHistoryFromSubscriptionId { |
|
|
175 |
my ($subscriptionid) = @_; |
176 |
|
177 |
return unless $subscriptionid; |
178 |
|
172 |
my $dbh = C4::Context->dbh; |
179 |
my $dbh = C4::Context->dbh; |
173 |
my $query = qq| |
180 |
my $query = qq| |
174 |
SELECT * |
181 |
SELECT * |
175 |
FROM subscriptionhistory |
182 |
FROM subscriptionhistory |
176 |
WHERE subscriptionid = ? |
183 |
WHERE subscriptionid = ? |
177 |
|; |
184 |
|; |
178 |
return $dbh->prepare($query); |
185 |
my $sth = $dbh->prepare($query); |
|
|
186 |
$sth->execute($subscriptionid); |
187 |
my $results = $sth->fetchrow_hashref; |
188 |
$sth->finish; |
189 |
|
190 |
return $results; |
179 |
} |
191 |
} |
180 |
|
192 |
|
181 |
=head2 GetSerialStatusFromSerialId |
193 |
=head2 GetSerialStatusFromSerialId |
Lines 569-575
sub GetSubscriptions {
Link Here
|
569 |
my $dbh = C4::Context->dbh; |
581 |
my $dbh = C4::Context->dbh; |
570 |
my $sth; |
582 |
my $sth; |
571 |
my $sql = qq( |
583 |
my $sql = qq( |
572 |
SELECT subscription.*, subscriptionhistory.*, biblio.title,biblioitems.issn,biblio.biblionumber |
584 |
SELECT subscriptionhistory.*, subscription.*, biblio.title,biblioitems.issn,biblio.biblionumber |
573 |
FROM subscription |
585 |
FROM subscription |
574 |
LEFT JOIN subscriptionhistory USING(subscriptionid) |
586 |
LEFT JOIN subscriptionhistory USING(subscriptionid) |
575 |
LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
587 |
LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
Lines 885-969
a list containing all the input params updated.
Link Here
|
885 |
|
897 |
|
886 |
=cut |
898 |
=cut |
887 |
|
899 |
|
888 |
# sub GetNextSeq { |
|
|
889 |
# my ($val) =@_; |
890 |
# my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); |
891 |
# $calculated = $val->{numberingmethod}; |
892 |
# # calculate the (expected) value of the next issue recieved. |
893 |
# $newlastvalue1 = $val->{lastvalue1}; |
894 |
# # check if we have to increase the new value. |
895 |
# $newinnerloop1 = $val->{innerloop1}+1; |
896 |
# $newinnerloop1=0 if ($newinnerloop1 >= $val->{every1}); |
897 |
# $newlastvalue1 += $val->{add1} if ($newinnerloop1<1); # <1 to be true when 0 or empty. |
898 |
# $newlastvalue1=$val->{setto1} if ($newlastvalue1>$val->{whenmorethan1}); # reset counter if needed. |
899 |
# $calculated =~ s/\{X\}/$newlastvalue1/g; |
900 |
# |
901 |
# $newlastvalue2 = $val->{lastvalue2}; |
902 |
# # check if we have to increase the new value. |
903 |
# $newinnerloop2 = $val->{innerloop2}+1; |
904 |
# $newinnerloop2=0 if ($newinnerloop2 >= $val->{every2}); |
905 |
# $newlastvalue2 += $val->{add2} if ($newinnerloop2<1); # <1 to be true when 0 or empty. |
906 |
# $newlastvalue2=$val->{setto2} if ($newlastvalue2>$val->{whenmorethan2}); # reset counter if needed. |
907 |
# $calculated =~ s/\{Y\}/$newlastvalue2/g; |
908 |
# |
909 |
# $newlastvalue3 = $val->{lastvalue3}; |
910 |
# # check if we have to increase the new value. |
911 |
# $newinnerloop3 = $val->{innerloop3}+1; |
912 |
# $newinnerloop3=0 if ($newinnerloop3 >= $val->{every3}); |
913 |
# $newlastvalue3 += $val->{add3} if ($newinnerloop3<1); # <1 to be true when 0 or empty. |
914 |
# $newlastvalue3=$val->{setto3} if ($newlastvalue3>$val->{whenmorethan3}); # reset counter if needed. |
915 |
# $calculated =~ s/\{Z\}/$newlastvalue3/g; |
916 |
# return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); |
917 |
# } |
918 |
|
919 |
sub GetNextSeq { |
900 |
sub GetNextSeq { |
920 |
my ($val) = @_; |
901 |
my ($val, $planneddate) = @_; |
921 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
902 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
922 |
my $pattern = $val->{numberpattern}; |
903 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
923 |
my @seasons = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' ); |
904 |
my $count = 1; |
924 |
my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' ); |
905 |
|
925 |
$calculated = $val->{numberingmethod}; |
906 |
if($val->{'skip_serialseq'}) { |
926 |
$newlastvalue1 = $val->{lastvalue1}; |
907 |
my @irreg = split /;/, $val->{'irregularity'}; |
927 |
$newlastvalue2 = $val->{lastvalue2}; |
908 |
if(@irreg > 0) { |
928 |
$newlastvalue3 = $val->{lastvalue3}; |
909 |
my $irregularities = {}; |
929 |
$newlastvalue1 = $val->{lastvalue1}; |
910 |
$irregularities->{$_} = 1 foreach(@irreg); |
930 |
|
911 |
my $issueno = GetFictiveIssueNumber($val, $planneddate) + 1; |
931 |
# check if we have to increase the new value. |
912 |
while($irregularities->{$issueno}) { |
932 |
$newinnerloop1 = $val->{innerloop1} + 1; |
913 |
$count++; |
933 |
$newinnerloop1 = 0 if ( $newinnerloop1 >= $val->{every1} ); |
914 |
$issueno++; |
934 |
$newlastvalue1 += $val->{add1} if ( $newinnerloop1 < 1 ); # <1 to be true when 0 or empty. |
915 |
} |
935 |
$newlastvalue1 = $val->{setto1} if ( $newlastvalue1 > $val->{whenmorethan1} ); # reset counter if needed. |
|
|
936 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
937 |
|
938 |
$newlastvalue2 = $val->{lastvalue2}; |
939 |
|
940 |
# check if we have to increase the new value. |
941 |
$newinnerloop2 = $val->{innerloop2} + 1; |
942 |
$newinnerloop2 = 0 if ( $newinnerloop2 >= $val->{every2} ); |
943 |
$newlastvalue2 += $val->{add2} if ( $newinnerloop2 < 1 ); # <1 to be true when 0 or empty. |
944 |
$newlastvalue2 = $val->{setto2} if ( $newlastvalue2 > $val->{whenmorethan2} ); # reset counter if needed. |
945 |
if ( $pattern == 6 ) { |
946 |
if ( $val->{hemisphere} == 2 ) { |
947 |
my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; |
948 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
949 |
} else { |
950 |
my $newlastvalue2seq = $seasons[$newlastvalue2]; |
951 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
952 |
} |
916 |
} |
953 |
} else { |
|
|
954 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
955 |
} |
917 |
} |
956 |
|
918 |
|
957 |
$newlastvalue3 = $val->{lastvalue3}; |
919 |
my $pattern = $val->{numberpattern}; |
958 |
|
920 |
$calculated = $val->{numberingmethod}; |
959 |
# check if we have to increase the new value. |
921 |
my $locale = $val->{locale}; |
960 |
$newinnerloop3 = $val->{innerloop3} + 1; |
922 |
$newlastvalue1 = $val->{lastvalue1} || 0; |
961 |
$newinnerloop3 = 0 if ( $newinnerloop3 >= $val->{every3} ); |
923 |
$newlastvalue2 = $val->{lastvalue2} || 0; |
962 |
$newlastvalue3 += $val->{add3} if ( $newinnerloop3 < 1 ); # <1 to be true when 0 or empty. |
924 |
$newlastvalue3 = $val->{lastvalue3} || 0; |
963 |
$newlastvalue3 = $val->{setto3} if ( $newlastvalue3 > $val->{whenmorethan3} ); # reset counter if needed. |
925 |
$newinnerloop1 = $val->{innerloop1} || 0; |
964 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
926 |
$newinnerloop2 = $val->{innerloop2} || 0; |
|
|
927 |
$newinnerloop3 = $val->{innerloop3} || 0; |
928 |
my %calc; |
929 |
foreach(qw/X Y Z/) { |
930 |
$calc{$_} = 1 if ($val->{'numberingmethod'} =~ /\{$_\}/); |
931 |
} |
932 |
|
933 |
for(my $i = 0; $i < $count; $i++) { |
934 |
if($calc{'X'}) { |
935 |
# check if we have to increase the new value. |
936 |
$newinnerloop1 += 1; |
937 |
if ($newinnerloop1 >= $val->{every1}) { |
938 |
$newinnerloop1 = 0; |
939 |
$newlastvalue1 += $val->{add1}; |
940 |
} |
941 |
# reset counter if needed. |
942 |
$newlastvalue1 = $val->{setto1} if ($newlastvalue1 > $val->{whenmorethan1}); |
943 |
} |
944 |
if($calc{'Y'}) { |
945 |
# check if we have to increase the new value. |
946 |
$newinnerloop2 += 1; |
947 |
if ($newinnerloop2 >= $val->{every2}) { |
948 |
$newinnerloop2 = 0; |
949 |
$newlastvalue2 += $val->{add2}; |
950 |
} |
951 |
# reset counter if needed. |
952 |
$newlastvalue2 = $val->{setto2} if ($newlastvalue2 > $val->{whenmorethan2}); |
953 |
} |
954 |
if($calc{'Z'}) { |
955 |
# check if we have to increase the new value. |
956 |
$newinnerloop3 += 1; |
957 |
if ($newinnerloop3 >= $val->{every3}) { |
958 |
$newinnerloop3 = 0; |
959 |
$newlastvalue3 += $val->{add3}; |
960 |
} |
961 |
# reset counter if needed. |
962 |
$newlastvalue3 = $val->{setto3} if ($newlastvalue3 > $val->{whenmorethan3}); |
963 |
} |
964 |
} |
965 |
if($calc{'X'}) { |
966 |
my $newlastvalue1string = _numeration( $newlastvalue1, $val->{numbering1}, $locale ); |
967 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
968 |
} |
969 |
if($calc{'Y'}) { |
970 |
my $newlastvalue2string = _numeration( $newlastvalue2, $val->{numbering2}, $locale ); |
971 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
972 |
} |
973 |
if($calc{'Z'}) { |
974 |
my $newlastvalue3string = _numeration( $newlastvalue3, $val->{numbering3}, $locale ); |
975 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
976 |
} |
965 |
|
977 |
|
966 |
return ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
978 |
return ($calculated, |
|
|
979 |
$newlastvalue1, $newlastvalue2, $newlastvalue3, |
980 |
$newinnerloop1, $newinnerloop2, $newinnerloop3); |
967 |
} |
981 |
} |
968 |
|
982 |
|
969 |
=head2 GetSeq |
983 |
=head2 GetSeq |
Lines 978-1004
the sequence in integer format
Link Here
|
978 |
|
992 |
|
979 |
sub GetSeq { |
993 |
sub GetSeq { |
980 |
my ($val) = @_; |
994 |
my ($val) = @_; |
|
|
995 |
my $locale = $val->{locale}; |
996 |
|
981 |
my $pattern = $val->{numberpattern}; |
997 |
my $pattern = $val->{numberpattern}; |
982 |
my @seasons = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' ); |
998 |
my $calculated = $val->{numberingmethod}; |
983 |
my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' ); |
999 |
|
984 |
my $calculated = $val->{numberingmethod}; |
1000 |
my $newlastvalue1 = $val->{'lastvalue1'} || 0; |
985 |
my $x = $val->{'lastvalue1'}; |
1001 |
$newlastvalue1 = _numeration($newlastvalue1, $val->{numbering1}, $locale) if ($val->{numbering1}); # reset counter if needed. |
986 |
$calculated =~ s/\{X\}/$x/g; |
1002 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
987 |
my $newlastvalue2 = $val->{'lastvalue2'}; |
1003 |
|
988 |
|
1004 |
my $newlastvalue2 = $val->{'lastvalue2'} || 0; |
989 |
if ( $pattern == 6 ) { |
1005 |
$newlastvalue2 = _numeration($newlastvalue2, $val->{numbering2}, $locale) if ($val->{numbering2}); # reset counter if needed. |
990 |
if ( $val->{hemisphere} == 2 ) { |
1006 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
991 |
my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; |
1007 |
|
992 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
1008 |
my $newlastvalue3 = $val->{'lastvalue3'} || 0; |
993 |
} else { |
1009 |
$newlastvalue3 = _numeration($newlastvalue3, $val->{numbering3}, $locale) if ($val->{numbering3}); # reset counter if needed. |
994 |
my $newlastvalue2seq = $seasons[$newlastvalue2]; |
1010 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
995 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
|
|
996 |
} |
997 |
} else { |
998 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
999 |
} |
1000 |
my $z = $val->{'lastvalue3'}; |
1001 |
$calculated =~ s/\{Z\}/$z/g; |
1002 |
return $calculated; |
1011 |
return $calculated; |
1003 |
} |
1012 |
} |
1004 |
|
1013 |
|
Lines 1023-1036
sub GetExpirationDate {
Link Here
|
1023 |
$enddate = $startdate || $subscription->{startdate}; |
1032 |
$enddate = $startdate || $subscription->{startdate}; |
1024 |
my @date = split( /-/, $enddate ); |
1033 |
my @date = split( /-/, $enddate ); |
1025 |
return if ( scalar(@date) != 3 || not check_date(@date) ); |
1034 |
return if ( scalar(@date) != 3 || not check_date(@date) ); |
1026 |
if ( ( $subscription->{periodicity} % 16 ) > 0 ) { |
1035 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); |
1027 |
|
1036 |
if ( $frequency and $frequency->{unit} ) { |
|
|
1037 |
|
1028 |
# If Not Irregular |
1038 |
# If Not Irregular |
1029 |
if ( my $length = $subscription->{numberlength} ) { |
1039 |
if ( my $length = $subscription->{numberlength} ) { |
1030 |
|
1040 |
|
1031 |
#calculate the date of the last issue. |
1041 |
#calculate the date of the last issue. |
1032 |
for ( my $i = 1 ; $i <= $length ; $i++ ) { |
1042 |
for ( my $i = 1 ; $i <= $length ; $i++ ) { |
1033 |
$enddate = GetNextDate( $enddate, $subscription ); |
1043 |
$enddate = GetNextDate( $subscription, $enddate ); |
1034 |
} |
1044 |
} |
1035 |
} elsif ( $subscription->{monthlength} ) { |
1045 |
} elsif ( $subscription->{monthlength} ) { |
1036 |
if ( $$subscription{startdate} ) { |
1046 |
if ( $$subscription{startdate} ) { |
Lines 1043-1052
sub GetExpirationDate {
Link Here
|
1043 |
my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 ); |
1053 |
my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 ); |
1044 |
$enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] ); |
1054 |
$enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] ); |
1045 |
} |
1055 |
} |
|
|
1056 |
} else { |
1057 |
$enddate = $subscription->{enddate}; |
1046 |
} |
1058 |
} |
1047 |
return $enddate; |
1059 |
return $enddate; |
1048 |
} else { |
1060 |
} else { |
1049 |
return; |
1061 |
return $subscription->{enddate}; |
1050 |
} |
1062 |
} |
1051 |
} |
1063 |
} |
1052 |
|
1064 |
|
Lines 1079-1098
returns the number of rows affected
Link Here
|
1079 |
=cut |
1091 |
=cut |
1080 |
|
1092 |
|
1081 |
sub ModSubscriptionHistory { |
1093 |
sub ModSubscriptionHistory { |
1082 |
my ( $subscriptionid, $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote ) = @_; |
1094 |
my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_; |
1083 |
my $dbh = C4::Context->dbh; |
1095 |
my $dbh = C4::Context->dbh; |
1084 |
my $query = "UPDATE subscriptionhistory |
1096 |
my $query = "UPDATE subscriptionhistory |
1085 |
SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? |
1097 |
SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? |
1086 |
WHERE subscriptionid=? |
1098 |
WHERE subscriptionid=? |
1087 |
"; |
1099 |
"; |
1088 |
my $sth = $dbh->prepare($query); |
1100 |
my $sth = $dbh->prepare($query); |
1089 |
$recievedlist =~ s/^; //; |
1101 |
$receivedlist =~ s/^; // if $receivedlist; |
1090 |
$missinglist =~ s/^; //; |
1102 |
$missinglist =~ s/^; // if $missinglist; |
1091 |
$opacnote =~ s/^; //; |
1103 |
$opacnote =~ s/^; // if $opacnote; |
1092 |
$sth->execute( $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote, $subscriptionid ); |
1104 |
$sth->execute( $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote, $subscriptionid ); |
1093 |
return $sth->rows; |
1105 |
return $sth->rows; |
1094 |
} |
1106 |
} |
1095 |
|
1107 |
|
|
|
1108 |
# Update missinglist field, used by ModSerialStatus |
1109 |
sub _update_missinglist { |
1110 |
my $subscriptionid = shift; |
1111 |
|
1112 |
my $dbh = C4::Context->dbh; |
1113 |
my @missingserials = GetSerials2($subscriptionid, "4,5"); |
1114 |
my $missinglist; |
1115 |
foreach (@missingserials) { |
1116 |
if($_->{'status'} == 4) { |
1117 |
$missinglist .= $_->{'serialseq'} . "; "; |
1118 |
} elsif($_->{'status'} == 5) { |
1119 |
$missinglist .= "not issued " . $_->{'serialseq'} . "; "; |
1120 |
} |
1121 |
} |
1122 |
$missinglist =~ s/; $//; |
1123 |
my $query = qq{ |
1124 |
UPDATE subscriptionhistory |
1125 |
SET missinglist = ? |
1126 |
WHERE subscriptionid = ? |
1127 |
}; |
1128 |
my $sth = $dbh->prepare($query); |
1129 |
$sth->execute($missinglist, $subscriptionid); |
1130 |
} |
1131 |
|
1132 |
# Update recievedlist field, used by ModSerialStatus |
1133 |
sub _update_receivedlist { |
1134 |
my $subscriptionid = shift; |
1135 |
|
1136 |
my $dbh = C4::Context->dbh; |
1137 |
my @receivedserials = GetSerials2($subscriptionid, "2"); |
1138 |
my $receivedlist; |
1139 |
foreach (@receivedserials) { |
1140 |
$receivedlist .= $_->{'serialseq'} . "; "; |
1141 |
} |
1142 |
$receivedlist =~ s/; $//; |
1143 |
my $query = qq{ |
1144 |
UPDATE subscriptionhistory |
1145 |
SET recievedlist = ? |
1146 |
WHERE subscriptionid = ? |
1147 |
}; |
1148 |
my $sth = $dbh->prepare($query); |
1149 |
$sth->execute($receivedlist, $subscriptionid); |
1150 |
} |
1151 |
|
1096 |
=head2 ModSerialStatus |
1152 |
=head2 ModSerialStatus |
1097 |
|
1153 |
|
1098 |
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes) |
1154 |
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes) |
Lines 1105-1126
Note : if we change from "waited" to something else,then we will have to create
Link Here
|
1105 |
sub ModSerialStatus { |
1161 |
sub ModSerialStatus { |
1106 |
my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_; |
1162 |
my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_; |
1107 |
|
1163 |
|
|
|
1164 |
|
1108 |
#It is a usual serial |
1165 |
#It is a usual serial |
1109 |
# 1st, get previous status : |
1166 |
# 1st, get previous status : |
1110 |
my $dbh = C4::Context->dbh; |
1167 |
my $dbh = C4::Context->dbh; |
1111 |
my $query = "SELECT subscriptionid,status FROM serial WHERE serialid=?"; |
1168 |
my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity |
|
|
1169 |
FROM serial, subscription |
1170 |
WHERE serial.subscriptionid=subscription.subscriptionid |
1171 |
AND serialid=?"; |
1112 |
my $sth = $dbh->prepare($query); |
1172 |
my $sth = $dbh->prepare($query); |
1113 |
$sth->execute($serialid); |
1173 |
$sth->execute($serialid); |
1114 |
my ( $subscriptionid, $oldstatus ) = $sth->fetchrow; |
1174 |
my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow; |
|
|
1175 |
my $frequency = GetSubscriptionFrequency($periodicity); |
1115 |
|
1176 |
|
1116 |
# change status & update subscriptionhistory |
1177 |
# change status & update subscriptionhistory |
1117 |
my $val; |
1178 |
my $val; |
1118 |
if ( $status == 6 ) { |
1179 |
if ( $status == 6 ) { |
1119 |
DelIssue( {'serialid'=>$serialid, 'subscriptionid'=>$subscriptionid,'serialseq'=>$serialseq} ); |
1180 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1120 |
} |
1181 |
} else { |
1121 |
else { |
1182 |
|
1122 |
my $query = |
1183 |
unless ($frequency->{'unit'}) { |
1123 |
'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?'; |
1184 |
if ( not $planneddate or $planneddate eq '0000-00-00' ) { $planneddate = C4::Dates->new()->output('iso') }; |
|
|
1185 |
if ( not $publisheddate or $publisheddate eq '0000-00-00' ) { $publisheddate = C4::Dates->new()->output('iso') }; |
1186 |
} |
1187 |
my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?'; |
1124 |
$sth = $dbh->prepare($query); |
1188 |
$sth = $dbh->prepare($query); |
1125 |
$sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid ); |
1189 |
$sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid ); |
1126 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
1190 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
Lines 1128-1185
sub ModSerialStatus {
Link Here
|
1128 |
$sth->execute($subscriptionid); |
1192 |
$sth->execute($subscriptionid); |
1129 |
my $val = $sth->fetchrow_hashref; |
1193 |
my $val = $sth->fetchrow_hashref; |
1130 |
unless ( $val->{manualhistory} ) { |
1194 |
unless ( $val->{manualhistory} ) { |
1131 |
$query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE subscriptionid=?"; |
1195 |
if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) { |
1132 |
$sth = $dbh->prepare($query); |
1196 |
_update_receivedlist($subscriptionid); |
1133 |
$sth->execute($subscriptionid); |
1197 |
} |
1134 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1198 |
if($status == 4 || $status == 5 |
1135 |
if ( $status == 2 ) { |
1199 |
|| ($oldstatus == 4 && $status != 4) |
1136 |
|
1200 |
|| ($oldstatus == 5 && $status != 5)) { |
1137 |
$recievedlist .= "; $serialseq" |
1201 |
_update_missinglist($subscriptionid); |
1138 |
unless ( index( "$recievedlist", "$serialseq" ) >= 0 ); |
|
|
1139 |
} |
1202 |
} |
1140 |
|
|
|
1141 |
# warn "missinglist : $missinglist serialseq :$serialseq, ".index("$missinglist","$serialseq"); |
1142 |
$missinglist .= "; $serialseq" |
1143 |
if ( $status == 4 |
1144 |
and not index( "$missinglist", "$serialseq" ) >= 0 ); |
1145 |
$missinglist .= "; not issued $serialseq" |
1146 |
if ( $status == 5 |
1147 |
and index( "$missinglist", "$serialseq" ) >= 0 ); |
1148 |
$query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=?"; |
1149 |
$sth = $dbh->prepare($query); |
1150 |
$recievedlist =~ s/^; //; |
1151 |
$missinglist =~ s/^; //; |
1152 |
$sth->execute( $recievedlist, $missinglist, $subscriptionid ); |
1153 |
} |
1203 |
} |
1154 |
} |
1204 |
} |
1155 |
|
1205 |
|
1156 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1206 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1157 |
if ( $oldstatus == 1 && $status != 1 ) { |
1207 |
if ( $oldstatus == 1 && $status != 1 ) { |
1158 |
my $query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
1208 |
my $query = qq{ |
|
|
1209 |
SELECT subscription.*, subscription_numberpatterns.*, |
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 |
}; |
1159 |
$sth = $dbh->prepare($query); |
1216 |
$sth = $dbh->prepare($query); |
1160 |
$sth->execute($subscriptionid); |
1217 |
$sth->execute($subscriptionid); |
1161 |
my $val = $sth->fetchrow_hashref; |
1218 |
my $val = $sth->fetchrow_hashref; |
1162 |
|
1219 |
|
1163 |
# next issue number |
1220 |
# next issue number |
1164 |
my ( |
1221 |
my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($val, $publisheddate); |
1165 |
$newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
|
|
1166 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 |
1167 |
) = GetNextSeq($val); |
1168 |
|
1222 |
|
1169 |
# next date (calculated from actual date & frequency parameters) |
1223 |
# next date (calculated from actual date & frequency parameters) |
1170 |
my $nextpublisheddate = GetNextDate( $publisheddate, $val ); |
1224 |
my $nextpublisheddate = GetNextDate($val, $publisheddate, 1); |
1171 |
NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate, $nextpublisheddate ); |
1225 |
my $nextpubdate = $nextpublisheddate; |
|
|
1226 |
NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpubdate, $nextpubdate ); |
1172 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1227 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1173 |
WHERE subscriptionid = ?"; |
1228 |
WHERE subscriptionid = ?"; |
1174 |
$sth = $dbh->prepare($query); |
1229 |
$sth = $dbh->prepare($query); |
1175 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1230 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1176 |
|
1231 |
|
1177 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1232 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1178 |
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) { |
1233 |
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) { |
1179 |
require C4::Letters; |
1234 |
require C4::Letters; |
1180 |
C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} ); |
1235 |
C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} ); |
1181 |
} |
1236 |
} |
1182 |
} |
1237 |
} |
|
|
1238 |
|
1183 |
return; |
1239 |
return; |
1184 |
} |
1240 |
} |
1185 |
|
1241 |
|
Lines 1193-1223
returns a hashref:
Link Here
|
1193 |
|
1249 |
|
1194 |
$nextexepected = { |
1250 |
$nextexepected = { |
1195 |
serialid => int |
1251 |
serialid => int |
1196 |
planneddate => C4::Dates object |
1252 |
planneddate => ISO date |
1197 |
} |
1253 |
} |
1198 |
|
1254 |
|
1199 |
=cut |
1255 |
=cut |
1200 |
|
1256 |
|
1201 |
sub GetNextExpected { |
1257 |
sub GetNextExpected { |
1202 |
my ($subscriptionid) = @_; |
1258 |
my ($subscriptionid) = @_; |
1203 |
my $dbh = C4::Context->dbh; |
1259 |
|
1204 |
my $sth = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?'); |
1260 |
my $dbh = C4::Context->dbh; |
|
|
1261 |
my $query = qq{ |
1262 |
SELECT * |
1263 |
FROM serial |
1264 |
WHERE subscriptionid = ? |
1265 |
AND status = ? |
1266 |
LIMIT 1 |
1267 |
}; |
1268 |
my $sth = $dbh->prepare($query); |
1205 |
|
1269 |
|
1206 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1270 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1207 |
$sth->execute( $subscriptionid, 1 ); |
1271 |
$sth->execute( $subscriptionid, 1 ); |
1208 |
my ( $nextissue ) = $sth->fetchrow_hashref; |
1272 |
my $nextissue = $sth->fetchrow_hashref; |
1209 |
if( !$nextissue){ |
1273 |
if ( !$nextissue ) { |
1210 |
$sth = $dbh->prepare('SELECT serialid,planneddate FROM serial WHERE subscriptionid = ? ORDER BY planneddate DESC LIMIT 1'); |
1274 |
$query = qq{ |
1211 |
$sth->execute( $subscriptionid ); |
1275 |
SELECT * |
1212 |
$nextissue = $sth->fetchrow_hashref; |
1276 |
FROM serial |
|
|
1277 |
WHERE subscriptionid = ? |
1278 |
ORDER BY planneddate DESC |
1279 |
LIMIT 1 |
1280 |
}; |
1281 |
$sth = $dbh->prepare($query); |
1282 |
$sth->execute($subscriptionid); |
1283 |
$nextissue = $sth->fetchrow_hashref; |
1213 |
} |
1284 |
} |
1214 |
if (!defined $nextissue->{planneddate}) { |
1285 |
foreach(qw/planneddate publisheddate/) { |
1215 |
# or should this default to 1st Jan ??? |
1286 |
if ( !defined $nextissue->{$_} ) { |
1216 |
$nextissue->{planneddate} = strftime('%Y-%m-%d',localtime); |
1287 |
# or should this default to 1st Jan ??? |
|
|
1288 |
$nextissue->{$_} = strftime( '%Y-%m-%d', localtime ); |
1289 |
} |
1290 |
$nextissue->{$_} = ($nextissue->{$_} ne '0000-00-00') |
1291 |
? $nextissue->{$_} |
1292 |
: undef; |
1217 |
} |
1293 |
} |
1218 |
$nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso'); |
|
|
1219 |
return $nextissue; |
1220 |
|
1294 |
|
|
|
1295 |
return $nextissue; |
1221 |
} |
1296 |
} |
1222 |
|
1297 |
|
1223 |
=head2 ModNextExpected |
1298 |
=head2 ModNextExpected |
Lines 1227-1233
ModNextExpected($subscriptionid,$date)
Link Here
|
1227 |
Update the planneddate for the current expected issue of the subscription. |
1302 |
Update the planneddate for the current expected issue of the subscription. |
1228 |
This will modify all future prediction results. |
1303 |
This will modify all future prediction results. |
1229 |
|
1304 |
|
1230 |
C<$date> is a C4::Dates object. |
1305 |
C<$date> is an ISO date. |
1231 |
|
1306 |
|
1232 |
returns 0 |
1307 |
returns 0 |
1233 |
|
1308 |
|
Lines 1241-1251
sub ModNextExpected {
Link Here
|
1241 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1316 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1242 |
|
1317 |
|
1243 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1318 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1244 |
$sth->execute( $date->output('iso'), $date->output('iso'), $subscriptionid, 1 ); |
1319 |
$sth->execute( $date, $date, $subscriptionid, 1 ); |
1245 |
return 0; |
1320 |
return 0; |
1246 |
|
1321 |
|
1247 |
} |
1322 |
} |
1248 |
|
1323 |
|
|
|
1324 |
=head2 GetSubscriptionIrregularities |
1325 |
|
1326 |
=over4 |
1327 |
|
1328 |
=item @irreg = &GetSubscriptionIrregularities($subscriptionid); |
1329 |
get the list of irregularities for a subscription |
1330 |
|
1331 |
=back |
1332 |
|
1333 |
=cut |
1334 |
|
1335 |
sub GetSubscriptionIrregularities { |
1336 |
my $subscriptionid = shift; |
1337 |
|
1338 |
return undef unless $subscriptionid; |
1339 |
|
1340 |
my $dbh = C4::Context->dbh; |
1341 |
my $query = qq{ |
1342 |
SELECT irregularity |
1343 |
FROM subscription |
1344 |
WHERE subscriptionid = ? |
1345 |
}; |
1346 |
my $sth = $dbh->prepare($query); |
1347 |
$sth->execute($subscriptionid); |
1348 |
|
1349 |
my ($result) = $sth->fetchrow_array; |
1350 |
my @irreg = split /;/, $result; |
1351 |
|
1352 |
return @irreg; |
1353 |
} |
1354 |
|
1249 |
=head2 ModSubscription |
1355 |
=head2 ModSubscription |
1250 |
|
1356 |
|
1251 |
this function modifies a subscription. Put all new values on input args. |
1357 |
this function modifies a subscription. Put all new values on input args. |
Lines 1254-1296
returns the number of rows affected
Link Here
|
1254 |
=cut |
1360 |
=cut |
1255 |
|
1361 |
|
1256 |
sub ModSubscription { |
1362 |
sub ModSubscription { |
1257 |
my ($auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1363 |
my ( |
1258 |
$dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $add1, $every1, |
1364 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, |
1259 |
$whenmorethan1, $setto1, $lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, |
1365 |
$periodicity, $firstacquidate, $irregularity, $numberpattern, $locale, |
1260 |
$lastvalue2, $innerloop2, $add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, |
1366 |
$numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1, |
1261 |
$numberingmethod, $status, $biblionumber, $callnumber, $notes, $letter, $hemisphere, $manualhistory, |
1367 |
$lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, |
1262 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid |
1368 |
$biblionumber, $callnumber, $notes, $letter, $manualhistory, |
|
|
1369 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1370 |
$graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq |
1263 |
) = @_; |
1371 |
) = @_; |
1264 |
|
1372 |
|
1265 |
# warn $irregularity; |
|
|
1266 |
my $dbh = C4::Context->dbh; |
1373 |
my $dbh = C4::Context->dbh; |
1267 |
my $query = "UPDATE subscription |
1374 |
my $query = "UPDATE subscription |
1268 |
SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?, |
1375 |
SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, |
1269 |
periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?, |
1376 |
startdate=?, periodicity=?, firstacquidate=?, irregularity=?, |
1270 |
add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?, |
1377 |
numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?, |
1271 |
add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?, |
1378 |
lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?, |
1272 |
add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?, |
1379 |
lastvalue3=?, innerloop3=?, status=?, biblionumber=?, |
1273 |
numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, |
1380 |
callnumber=?, notes=?, letter=?, manualhistory=?, |
1274 |
letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?, |
1381 |
internalnotes=?, serialsadditems=?, staffdisplaycount=?, |
1275 |
staffdisplaycount = ?,opacdisplaycount = ?, graceperiod = ?, location = ? |
1382 |
opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, |
1276 |
,enddate=? |
1383 |
skip_serialseq=? |
1277 |
WHERE subscriptionid = ?"; |
1384 |
WHERE subscriptionid = ?"; |
1278 |
|
1385 |
|
1279 |
#warn "query :".$query; |
|
|
1280 |
my $sth = $dbh->prepare($query); |
1386 |
my $sth = $dbh->prepare($query); |
1281 |
$sth->execute( |
1387 |
$sth->execute( |
1282 |
$auser, $branchcode, $aqbooksellerid, $cost, |
1388 |
$auser, $branchcode, $aqbooksellerid, $cost, |
1283 |
$aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1389 |
$aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1284 |
$dow, "$irregularity", $numberpattern, $numberlength, |
1390 |
$irregularity, $numberpattern, $locale, $numberlength, |
1285 |
$weeklength, $monthlength, $add1, $every1, |
1391 |
$weeklength, $monthlength, $lastvalue1, $innerloop1, |
1286 |
$whenmorethan1, $setto1, $lastvalue1, $innerloop1, |
1392 |
$lastvalue2, $innerloop2, $lastvalue3, $innerloop3, |
1287 |
$add2, $every2, $whenmorethan2, $setto2, |
1393 |
$status, $biblionumber, $callnumber, $notes, |
1288 |
$lastvalue2, $innerloop2, $add3, $every3, |
1394 |
$letter, ($manualhistory ? $manualhistory : 0), |
1289 |
$whenmorethan3, $setto3, $lastvalue3, $innerloop3, |
|
|
1290 |
$numberingmethod, $status, $biblionumber, $callnumber, |
1291 |
$notes, $letter, $hemisphere, ( $manualhistory ? $manualhistory : 0 ), |
1292 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1395 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1293 |
$graceperiod, $location, $enddate, $subscriptionid |
1396 |
$graceperiod, $location, $enddate, $skip_serialseq, |
|
|
1397 |
$subscriptionid |
1294 |
); |
1398 |
); |
1295 |
my $rows = $sth->rows; |
1399 |
my $rows = $sth->rows; |
1296 |
|
1400 |
|
Lines 1302-1312
sub ModSubscription {
Link Here
|
1302 |
|
1406 |
|
1303 |
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, |
1407 |
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, |
1304 |
$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, |
1408 |
$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, |
1305 |
$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, |
1409 |
$lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3, |
1306 |
$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, |
1410 |
$status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, |
1307 |
$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, |
1411 |
$callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems, |
1308 |
$numberingmethod, $status, $notes, $serialsadditems, |
1412 |
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq); |
1309 |
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate); |
|
|
1310 |
|
1413 |
|
1311 |
Create a new subscription with value given on input args. |
1414 |
Create a new subscription with value given on input args. |
1312 |
|
1415 |
|
Lines 1316-1357
the id of this new subscription
Link Here
|
1316 |
=cut |
1419 |
=cut |
1317 |
|
1420 |
|
1318 |
sub NewSubscription { |
1421 |
sub NewSubscription { |
1319 |
my ($auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, |
1422 |
my ( |
1320 |
$dow, $numberlength, $weeklength, $monthlength, $add1, $every1, $whenmorethan1, $setto1, |
1423 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, |
1321 |
$lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, $lastvalue2, $innerloop2, |
1424 |
$startdate, $periodicity, $numberlength, $weeklength, $monthlength, |
1322 |
$add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, $numberingmethod, $status, |
1425 |
$lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, |
1323 |
$notes, $letter, $firstacquidate, $irregularity, $numberpattern, $callnumber, $hemisphere, $manualhistory, |
1426 |
$innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, |
1324 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate |
1427 |
$numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, |
|
|
1428 |
$serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, |
1429 |
$location, $enddate, $skip_serialseq |
1325 |
) = @_; |
1430 |
) = @_; |
1326 |
my $dbh = C4::Context->dbh; |
1431 |
my $dbh = C4::Context->dbh; |
1327 |
|
1432 |
|
1328 |
#save subscription (insert into database) |
1433 |
#save subscription (insert into database) |
1329 |
my $query = qq| |
1434 |
my $query = qq| |
1330 |
INSERT INTO subscription |
1435 |
INSERT INTO subscription |
1331 |
(librarian,branchcode,aqbooksellerid,cost,aqbudgetid,biblionumber, |
1436 |
(librarian, branchcode, aqbooksellerid, cost, aqbudgetid, |
1332 |
startdate,periodicity,dow,numberlength,weeklength,monthlength, |
1437 |
biblionumber, startdate, periodicity, numberlength, weeklength, |
1333 |
add1,every1,whenmorethan1,setto1,lastvalue1,innerloop1, |
1438 |
monthlength, lastvalue1, innerloop1, lastvalue2, innerloop2, |
1334 |
add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2, |
1439 |
lastvalue3, innerloop3, status, notes, letter, firstacquidate, |
1335 |
add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3, |
1440 |
irregularity, numberpattern, locale, callnumber, |
1336 |
numberingmethod, status, notes, letter,firstacquidate,irregularity, |
1441 |
manualhistory, internalnotes, serialsadditems, staffdisplaycount, |
1337 |
numberpattern, callnumber, hemisphere,manualhistory,internalnotes,serialsadditems, |
1442 |
opacdisplaycount, graceperiod, location, enddate, skip_serialseq) |
1338 |
staffdisplaycount,opacdisplaycount,graceperiod,location,enddate) |
1443 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
1339 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
|
|
1340 |
|; |
1444 |
|; |
1341 |
my $sth = $dbh->prepare($query); |
1445 |
my $sth = $dbh->prepare($query); |
1342 |
$sth->execute( |
1446 |
$sth->execute( |
1343 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, |
1447 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, |
1344 |
$dow, $numberlength, $weeklength, $monthlength, $add1, $every1, $whenmorethan1, $setto1, |
1448 |
$startdate, $periodicity, $numberlength, $weeklength, |
1345 |
$lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, $lastvalue2, $innerloop2, |
1449 |
$monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, |
1346 |
$add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, $numberingmethod, "$status", |
1450 |
$lastvalue3, $innerloop3, $status, $notes, $letter, |
1347 |
$notes, $letter, $firstacquidate, $irregularity, $numberpattern, $callnumber, $hemisphere, $manualhistory, |
1451 |
$firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, |
1348 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate |
1452 |
$manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, |
|
|
1453 |
$opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq |
1349 |
); |
1454 |
); |
1350 |
|
1455 |
|
1351 |
my $subscriptionid = $dbh->{'mysql_insertid'}; |
1456 |
my $subscriptionid = $dbh->{'mysql_insertid'}; |
1352 |
unless ($enddate){ |
1457 |
unless ($enddate) { |
1353 |
$enddate = GetExpirationDate($subscriptionid,$startdate); |
1458 |
$enddate = GetExpirationDate( $subscriptionid, $startdate ); |
1354 |
$query = q| |
1459 |
$query = qq| |
1355 |
UPDATE subscription |
1460 |
UPDATE subscription |
1356 |
SET enddate=? |
1461 |
SET enddate=? |
1357 |
WHERE subscriptionid=? |
1462 |
WHERE subscriptionid=? |
Lines 1359-1365
sub NewSubscription {
Link Here
|
1359 |
$sth = $dbh->prepare($query); |
1464 |
$sth = $dbh->prepare($query); |
1360 |
$sth->execute( $enddate, $subscriptionid ); |
1465 |
$sth->execute( $enddate, $subscriptionid ); |
1361 |
} |
1466 |
} |
1362 |
#then create the 1st waited number |
1467 |
|
|
|
1468 |
# then create the 1st expected number |
1363 |
$query = qq( |
1469 |
$query = qq( |
1364 |
INSERT INTO subscriptionhistory |
1470 |
INSERT INTO subscriptionhistory |
1365 |
(biblionumber, subscriptionid, histstartdate, opacnote, librariannote) |
1471 |
(biblionumber, subscriptionid, histstartdate, opacnote, librariannote) |
Lines 1372-1377
sub NewSubscription {
Link Here
|
1372 |
$query = qq( |
1478 |
$query = qq( |
1373 |
SELECT * |
1479 |
SELECT * |
1374 |
FROM subscription |
1480 |
FROM subscription |
|
|
1481 |
LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id |
1375 |
WHERE subscriptionid = ? |
1482 |
WHERE subscriptionid = ? |
1376 |
); |
1483 |
); |
1377 |
$sth = $dbh->prepare($query); |
1484 |
$sth = $dbh->prepare($query); |
Lines 1392-1398
sub NewSubscription {
Link Here
|
1392 |
|
1499 |
|
1393 |
#set serial flag on biblio if not already set. |
1500 |
#set serial flag on biblio if not already set. |
1394 |
my $bib = GetBiblio($biblionumber); |
1501 |
my $bib = GetBiblio($biblionumber); |
1395 |
if ( !$bib->{'serial'} ) { |
1502 |
if ( $bib and !$bib->{'serial'} ) { |
1396 |
my $record = GetMarcBiblio($biblionumber); |
1503 |
my $record = GetMarcBiblio($biblionumber); |
1397 |
my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} ); |
1504 |
my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} ); |
1398 |
if ($tag) { |
1505 |
if ($tag) { |
Lines 1710-1716
sub HasSubscriptionExpired {
Link Here
|
1710 |
my ($subscriptionid) = @_; |
1817 |
my ($subscriptionid) = @_; |
1711 |
my $dbh = C4::Context->dbh; |
1818 |
my $dbh = C4::Context->dbh; |
1712 |
my $subscription = GetSubscription($subscriptionid); |
1819 |
my $subscription = GetSubscription($subscriptionid); |
1713 |
if ( ( $subscription->{periodicity} % 16 ) > 0 ) { |
1820 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); |
|
|
1821 |
if ( $frequency and $frequency->{unit} ) { |
1714 |
my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); |
1822 |
my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); |
1715 |
if (!defined $expirationdate) { |
1823 |
if (!defined $expirationdate) { |
1716 |
$expirationdate = q{}; |
1824 |
$expirationdate = q{}; |
Lines 1734-1739
sub HasSubscriptionExpired {
Link Here
|
1734 |
|| ( !$res ) ); |
1842 |
|| ( !$res ) ); |
1735 |
return 0; |
1843 |
return 0; |
1736 |
} else { |
1844 |
} else { |
|
|
1845 |
# Irregular |
1737 |
if ( $subscription->{'numberlength'} ) { |
1846 |
if ( $subscription->{'numberlength'} ) { |
1738 |
my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} ); |
1847 |
my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} ); |
1739 |
return 1 if ( $countreceived > $subscription->{'numberlength'} ); |
1848 |
return 1 if ( $countreceived > $subscription->{'numberlength'} ); |
Lines 2225-2253
sub abouttoexpire {
Link Here
|
2225 |
my $dbh = C4::Context->dbh; |
2334 |
my $dbh = C4::Context->dbh; |
2226 |
my $subscription = GetSubscription($subscriptionid); |
2335 |
my $subscription = GetSubscription($subscriptionid); |
2227 |
my $per = $subscription->{'periodicity'}; |
2336 |
my $per = $subscription->{'periodicity'}; |
2228 |
if ($per && $per % 16 > 0){ |
2337 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($per); |
2229 |
my $expirationdate = GetExpirationDate($subscriptionid); |
2338 |
if ($frequency and $frequency->{unit}){ |
|
|
2339 |
my $expirationdate = GetExpirationDate($subscriptionid); |
2230 |
my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); |
2340 |
my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); |
2231 |
my @res; |
2341 |
my $nextdate = GetNextDate($subscription, $res); |
2232 |
if (defined $res) { |
2342 |
if(Date::Calc::Delta_Days( |
2233 |
@res=split (/-/,$res); |
2343 |
split( /-/, $nextdate ), |
2234 |
@res=Date::Calc::Today if ($res[0]*$res[1]==0); |
2344 |
split( /-/, $expirationdate ) |
2235 |
} else { # default an undefined value |
2345 |
) <= 0) { |
2236 |
@res=Date::Calc::Today; |
2346 |
return 1; |
2237 |
} |
2347 |
} |
2238 |
my @endofsubscriptiondate=split(/-/,$expirationdate); |
|
|
2239 |
my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 124, 0, 0); |
2240 |
my @datebeforeend; |
2241 |
@datebeforeend = Add_Delta_Days( $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2], |
2242 |
- (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]); |
2243 |
return 1 if ( @res && |
2244 |
(@datebeforeend && |
2245 |
Delta_Days($res[0],$res[1],$res[2], |
2246 |
$datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) <= 0) && |
2247 |
(@endofsubscriptiondate && |
2248 |
Delta_Days($res[0],$res[1],$res[2], |
2249 |
$endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) >= 0) ); |
2250 |
return 0; |
2251 |
} elsif ($subscription->{numberlength}>0) { |
2348 |
} elsif ($subscription->{numberlength}>0) { |
2252 |
return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1); |
2349 |
return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1); |
2253 |
} |
2350 |
} |
Lines 2298-2467
sub GetSubscriptionsFromBorrower {
Link Here
|
2298 |
return ( $count, @routinglist ); |
2395 |
return ( $count, @routinglist ); |
2299 |
} |
2396 |
} |
2300 |
|
2397 |
|
2301 |
=head2 GetNextDate |
|
|
2302 |
|
2398 |
|
2303 |
$resultdate = GetNextDate($planneddate,$subscription) |
2399 |
=head2 GetFictiveIssueNumber |
2304 |
|
2400 |
|
2305 |
this function it takes the planneddate and will return the next issue's date and will skip dates if there |
2401 |
$issueno = GetFictiveIssueNumber($subscription, $publishedate); |
2306 |
exists an irregularity |
|
|
2307 |
- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be |
2308 |
skipped then the returned date will be 2007-05-10 |
2309 |
|
2310 |
return : |
2311 |
$resultdate - then next date in the sequence |
2312 |
|
2402 |
|
2313 |
Return 0 if periodicity==0 |
2403 |
Get the position of the issue published at $publisheddate, considering the |
|
|
2404 |
first issue (at firstacquidate) is at position 1, the next is at position 2, etc... |
2405 |
This issuenumber doesn't take into account irregularities, so, for instance, if the 3rd |
2406 |
issue is declared as 'irregular' (will be skipped at receipt), the next issue number |
2407 |
will be 4, not 3. It's why it is called 'fictive'. It is NOT a serial seq, and is not |
2408 |
depending on how many rows are in serial table. |
2409 |
The issue number calculation is based on subscription frequency, first acquisition |
2410 |
date, and $publisheddate. |
2314 |
|
2411 |
|
2315 |
=cut |
2412 |
=cut |
2316 |
|
2413 |
|
2317 |
sub GetNextDate { |
2414 |
sub GetFictiveIssueNumber { |
2318 |
my ( $planneddate, $subscription ) = @_; |
2415 |
my ($subscription, $publisheddate) = @_; |
2319 |
my @irreg = split( /\,/, $subscription->{irregularity} ); |
2416 |
|
|
|
2417 |
my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'}); |
2418 |
my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef; |
2419 |
my $issueno = 0; |
2420 |
|
2421 |
if($unit) { |
2422 |
my ($year, $month, $day) = split /-/, $publisheddate; |
2423 |
my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'}; |
2424 |
my $wkno; |
2425 |
my $delta; |
2426 |
|
2427 |
if($unit eq 'day') { |
2428 |
$delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day); |
2429 |
} elsif($unit eq 'week') { |
2430 |
($wkno, $year) = Week_of_Year($year, $month, $day); |
2431 |
my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day); |
2432 |
$delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) ); |
2433 |
} elsif($unit eq 'month') { |
2434 |
$delta = ($fa_year == $year) |
2435 |
? ($month - $fa_month) |
2436 |
: ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) ); |
2437 |
} elsif($unit eq 'year') { |
2438 |
$delta = $year - $fa_year; |
2439 |
} |
2440 |
if($frequency->{'unitsperissue'} == 1) { |
2441 |
$issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'}; |
2442 |
} else { |
2443 |
# Assuming issuesperunit == 1 |
2444 |
$issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} ); |
2445 |
} |
2446 |
} |
2447 |
return $issueno; |
2448 |
} |
2320 |
|
2449 |
|
2321 |
#date supposed to be in ISO. |
2450 |
=head2 GetNextDate |
2322 |
|
2451 |
|
2323 |
my ( $year, $month, $day ) = split( /-/, $planneddate ); |
2452 |
$resultdate = GetNextDate($publisheddate,$subscription) |
2324 |
$month = 1 unless ($month); |
|
|
2325 |
$day = 1 unless ($day); |
2326 |
my @resultdate; |
2327 |
|
2453 |
|
2328 |
# warn "DOW $dayofweek"; |
2454 |
this function it takes the publisheddate and will return the next issue's date |
2329 |
if ( $subscription->{periodicity} % 16 == 0 ) { # 'without regularity' || 'irregular' |
2455 |
and will skip dates if there exists an irregularity. |
2330 |
return 0; |
2456 |
$publisheddate has to be an ISO date |
2331 |
} |
2457 |
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit' |
|
|
2458 |
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database |
2459 |
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be |
2460 |
skipped then the returned date will be 2007-05-10 |
2332 |
|
2461 |
|
2333 |
# daily : n / week |
2462 |
return : |
2334 |
# Since we're interpreting irregularity here as which days of the week to skip an issue, |
2463 |
$resultdate - then next date in the sequence (ISO date) |
2335 |
# renaming this pattern from 1/day to " n / week ". |
|
|
2336 |
if ( $subscription->{periodicity} == 1 ) { |
2337 |
my $dayofweek = eval { Day_of_Week( $year, $month, $day ) }; |
2338 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2339 |
else { |
2340 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2341 |
$dayofweek = 0 if ( $dayofweek == 7 ); |
2342 |
if ( in_array( ( $dayofweek + 1 ), @irreg ) ) { |
2343 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 1 ); |
2344 |
$dayofweek++; |
2345 |
} |
2346 |
} |
2347 |
@resultdate = Add_Delta_Days( $year, $month, $day, 1 ); |
2348 |
} |
2349 |
} |
2350 |
|
2464 |
|
2351 |
# 1 week |
2465 |
Return $publisheddate if subscription is irregular |
2352 |
if ( $subscription->{periodicity} == 2 ) { |
|
|
2353 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2354 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2355 |
else { |
2356 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2357 |
|
2466 |
|
2358 |
#FIXME: if two consecutive irreg, do we only skip one? |
2467 |
=cut |
2359 |
if ( $irreg[$i] == ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ) ) { |
|
|
2360 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 7 ); |
2361 |
$wkno = ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ); |
2362 |
} |
2363 |
} |
2364 |
@resultdate = Add_Delta_Days( $year, $month, $day, 7 ); |
2365 |
} |
2366 |
} |
2367 |
|
2468 |
|
2368 |
# 1 / 2 weeks |
2469 |
sub GetNextDate { |
2369 |
if ( $subscription->{periodicity} == 3 ) { |
2470 |
my ( $subscription, $publisheddate, $updatecount ) = @_; |
2370 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2471 |
|
2371 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2472 |
my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); |
2372 |
else { |
2473 |
|
2373 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2474 |
if ($freqdata->{'unit'}) { |
2374 |
if ( $irreg[$i] == ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ) ) { |
2475 |
my ( $year, $month, $day ) = split /-/, $publisheddate; |
2375 |
### BUGFIX was previously +1 ^ |
2476 |
|
2376 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 14 ); |
2477 |
# Process an irregularity Hash |
2377 |
$wkno = ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ); |
2478 |
# Suppose that irregularities are stored in a string with this structure |
2378 |
} |
2479 |
# irreg1;irreg2;irreg3 |
2379 |
} |
2480 |
# where irregX is the number of issue which will not be received |
2380 |
@resultdate = Add_Delta_Days( $year, $month, $day, 14 ); |
2481 |
# (the first issue takes the number 1, the 2nd the number 2 and so on) |
|
|
2482 |
my @irreg = split /;/, $subscription->{'irregularity'} ; |
2483 |
my %irregularities; |
2484 |
foreach my $irregularity (@irreg) { |
2485 |
$irregularities{$irregularity} = 1; |
2381 |
} |
2486 |
} |
2382 |
} |
|
|
2383 |
|
2487 |
|
2384 |
# 1 / 3 weeks |
2488 |
# Get the 'fictive' next issue number |
2385 |
if ( $subscription->{periodicity} == 4 ) { |
2489 |
# It is used to check if next issue is an irregular issue. |
2386 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2490 |
my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1; |
2387 |
if ($@) { warn "année mois jour : $year $month $day $subscription->{subscriptionid} : $@"; } |
2491 |
|
2388 |
else { |
2492 |
# Then get the next date |
2389 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2493 |
my $unit = lc $freqdata->{'unit'}; |
2390 |
if ( $irreg[$i] == ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ) ) { |
2494 |
if ($unit eq 'day') { |
2391 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 21 ); |
2495 |
while ($irregularities{$issueno}) { |
2392 |
$wkno = ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ); |
2496 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
|
|
2497 |
($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{'unitsperissue'} ); |
2498 |
$subscription->{'countissuesperunit'} = 1; |
2499 |
} else { |
2500 |
$subscription->{'countissuesperunit'}++; |
2393 |
} |
2501 |
} |
|
|
2502 |
$issueno++; |
2503 |
} |
2504 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2505 |
($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{"unitsperissue"} ); |
2506 |
$subscription->{'countissuesperunit'} = 1; |
2507 |
} else { |
2508 |
$subscription->{'countissuesperunit'}++; |
2394 |
} |
2509 |
} |
2395 |
@resultdate = Add_Delta_Days( $year, $month, $day, 21 ); |
|
|
2396 |
} |
2510 |
} |
2397 |
} |
2511 |
elsif ($unit eq 'week') { |
2398 |
my $tmpmonth = $month; |
2512 |
my ($wkno, $yr) = Week_of_Year($year, $month, $day); |
2399 |
if ( $year && $month && $day ) { |
2513 |
while ($irregularities{$issueno}) { |
2400 |
if ( $subscription->{periodicity} == 5 ) { |
2514 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2401 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2515 |
$subscription->{'countissuesperunit'} = 1; |
2402 |
if ( $irreg[$i] == ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ) ) { |
2516 |
$wkno += $freqdata->{"unitsperissue"}; |
2403 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 ); |
2517 |
if($wkno > 52){ |
2404 |
$tmpmonth = ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ); |
2518 |
$wkno = $wkno % 52; |
|
|
2519 |
$yr++; |
2520 |
} |
2521 |
my $dow = Day_of_Week($year, $month, $day); |
2522 |
($year,$month,$day) = Monday_of_Week($wkno, $yr); |
2523 |
if($freqdata->{'issuesperunit'} == 1) { |
2524 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); |
2525 |
} |
2526 |
} else { |
2527 |
$subscription->{'countissuesperunit'}++; |
2405 |
} |
2528 |
} |
|
|
2529 |
$issueno++; |
2406 |
} |
2530 |
} |
2407 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 ); |
2531 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2408 |
} |
2532 |
$subscription->{'countissuesperunit'} = 1; |
2409 |
if ( $subscription->{periodicity} == 6 ) { |
2533 |
$wkno += $freqdata->{"unitsperissue"}; |
2410 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2534 |
if($wkno > 52){ |
2411 |
if ( $irreg[$i] == ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ) ) { |
2535 |
$wkno = $wkno % 52 ; |
2412 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 ); |
2536 |
$yr++; |
2413 |
$tmpmonth = ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ); |
|
|
2414 |
} |
2537 |
} |
|
|
2538 |
my $dow = Day_of_Week($year, $month, $day); |
2539 |
($year,$month,$day) = Monday_of_Week($wkno, $yr); |
2540 |
if($freqdata->{'issuesperunit'} == 1) { |
2541 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); |
2542 |
} |
2543 |
} else { |
2544 |
$subscription->{'countissuesperunit'}++; |
2415 |
} |
2545 |
} |
2416 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 ); |
|
|
2417 |
} |
2546 |
} |
2418 |
if ( $subscription->{periodicity} == 7 ) { |
2547 |
elsif ($unit eq 'month') { |
2419 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2548 |
while ($irregularities{$issueno}) { |
2420 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2549 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2421 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
2550 |
$subscription->{'countissuesperunit'} = 1; |
2422 |
$tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ); |
2551 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); |
|
|
2552 |
unless($freqdata->{'issuesperunit'} == 1) { |
2553 |
$day = 1; # Jumping to the first day of month, because we don't know what day is expected |
2554 |
} |
2555 |
} else { |
2556 |
$subscription->{'countissuesperunit'}++; |
2423 |
} |
2557 |
} |
|
|
2558 |
$issueno++; |
2424 |
} |
2559 |
} |
2425 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
2560 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2426 |
} |
2561 |
$subscription->{'countissuesperunit'} = 1; |
2427 |
if ( $subscription->{periodicity} == 8 ) { |
2562 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); |
2428 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2563 |
unless($freqdata->{'issuesperunit'} == 1) { |
2429 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2564 |
$day = 1; # Jumping to the first day of month, because we don't know what day is expected |
2430 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
|
|
2431 |
$tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ); |
2432 |
} |
2565 |
} |
|
|
2566 |
} else { |
2567 |
$subscription->{'countissuesperunit'}++; |
2433 |
} |
2568 |
} |
2434 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
|
|
2435 |
} |
2569 |
} |
2436 |
if ( $subscription->{periodicity} == 13 ) { |
2570 |
elsif ($unit eq 'year') { |
2437 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2571 |
while ($irregularities{$issueno}) { |
2438 |
if ( $irreg[$i] == ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ) ) { |
2572 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2439 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 ); |
2573 |
$subscription->{'countissuesperunit'} = 1; |
2440 |
$tmpmonth = ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ); |
2574 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); |
|
|
2575 |
unless($freqdata->{'issuesperunit'} == 1) { |
2576 |
# Jumping to the first day of year, because we don't know what day is expected |
2577 |
$month = 1; |
2578 |
$day = 1; |
2579 |
} |
2580 |
} else { |
2581 |
$subscription->{'countissuesperunit'}++; |
2441 |
} |
2582 |
} |
|
|
2583 |
$issueno++; |
2442 |
} |
2584 |
} |
2443 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 ); |
2585 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2444 |
} |
2586 |
$subscription->{'countissuesperunit'} = 1; |
2445 |
if ( $subscription->{periodicity} == 9 ) { |
2587 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); |
2446 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2588 |
unless($freqdata->{'issuesperunit'} == 1) { |
2447 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2589 |
# Jumping to the first day of year, because we don't know what day is expected |
2448 |
### BUFIX Seems to need more Than One ? |
2590 |
$month = 1; |
2449 |
( $year, $month, $day ) = Add_Delta_YM( $year, $month, $day, 0, 6 ); |
2591 |
$day = 1; |
2450 |
$tmpmonth = ( ( $tmpmonth != 6 ) ? ( $tmpmonth + 6 ) % 12 : 12 ); |
|
|
2451 |
} |
2592 |
} |
|
|
2593 |
} else { |
2594 |
$subscription->{'countissuesperunit'}++; |
2452 |
} |
2595 |
} |
2453 |
@resultdate = Add_Delta_YM( $year, $month, $day, 0, 6 ); |
|
|
2454 |
} |
2596 |
} |
2455 |
if ( $subscription->{periodicity} == 10 ) { |
2597 |
if ($updatecount){ |
2456 |
@resultdate = Add_Delta_YM( $year, $month, $day, 1, 0 ); |
2598 |
my $dbh = C4::Context->dbh; |
2457 |
} |
2599 |
my $query = qq{ |
2458 |
if ( $subscription->{periodicity} == 11 ) { |
2600 |
UPDATE subscription |
2459 |
@resultdate = Add_Delta_YM( $year, $month, $day, 2, 0 ); |
2601 |
SET countissuesperunit = ? |
|
|
2602 |
WHERE subscriptionid = ? |
2603 |
}; |
2604 |
my $sth = $dbh->prepare($query); |
2605 |
$sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'}); |
2460 |
} |
2606 |
} |
|
|
2607 |
return sprintf("%04d-%02d-%02d", $year, $month, $day); |
2461 |
} |
2608 |
} |
2462 |
my $resultdate = sprintf( "%04d-%02d-%02d", $resultdate[0], $resultdate[1], $resultdate[2] ); |
2609 |
else { |
|
|
2610 |
return $publisheddate; |
2611 |
} |
2612 |
} |
2463 |
|
2613 |
|
2464 |
return "$resultdate"; |
2614 |
=head2 _numeration |
|
|
2615 |
|
2616 |
$string = &_numeration($value,$num_type,$locale); |
2617 |
|
2618 |
_numeration returns the string corresponding to $value in the num_type |
2619 |
num_type can take : |
2620 |
-dayname |
2621 |
-monthname |
2622 |
-season |
2623 |
=cut |
2624 |
|
2625 |
#' |
2626 |
|
2627 |
sub _numeration { |
2628 |
my ($value, $num_type, $locale) = @_; |
2629 |
$value ||= 0; |
2630 |
my $initlocale = setlocale(LC_TIME); |
2631 |
if($locale and $locale ne $initlocale) { |
2632 |
$locale = setlocale(LC_TIME, $locale); |
2633 |
} |
2634 |
$locale ||= $initlocale; |
2635 |
my $string; |
2636 |
$num_type //= ''; |
2637 |
given ($num_type) { |
2638 |
when (/^dayname$/) { |
2639 |
$value = $value % 7; |
2640 |
$string = POSIX::strftime("%A",0,0,0,0,0,0,$value); |
2641 |
} |
2642 |
when (/^monthname$/) { |
2643 |
$value = $value % 12; |
2644 |
$string = POSIX::strftime("%B",0,0,0,1,$value,0,0,0,0); |
2645 |
} |
2646 |
when (/^season$/) { |
2647 |
my $seasonlocale = ($locale) |
2648 |
? (substr $locale,0,2) |
2649 |
: "en"; |
2650 |
my %seasons=( |
2651 |
"en" => |
2652 |
[qw(Spring Summer Fall Winter)], |
2653 |
"fr"=> |
2654 |
[qw(Printemps Été Automne Hiver)], |
2655 |
); |
2656 |
$value = $value % 4; |
2657 |
$string = ($seasons{$seasonlocale}) |
2658 |
? $seasons{$seasonlocale}->[$value] |
2659 |
: $seasons{'en'}->[$value]; |
2660 |
} |
2661 |
default { |
2662 |
$string = $value; |
2663 |
} |
2664 |
} |
2665 |
if($locale ne $initlocale) { |
2666 |
setlocale(LC_TIME, $initlocale); |
2667 |
} |
2668 |
return $string; |
2465 |
} |
2669 |
} |
2466 |
|
2670 |
|
2467 |
=head2 is_barcode_in_use |
2671 |
=head2 is_barcode_in_use |