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