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 38-45
BEGIN {
Link Here
|
38 |
&GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber |
40 |
&GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber |
39 |
&GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory |
41 |
&GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory |
40 |
&HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire |
42 |
&HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire |
|
|
43 |
&GetSubscriptionHistoryFromSubscriptionId |
41 |
|
44 |
|
42 |
&GetNextSeq &NewIssue &ItemizeSerials &GetSerials |
45 |
&GetNextSeq &GetSeq &NewIssue &ItemizeSerials &GetSerials |
43 |
&GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 |
46 |
&GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 |
44 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
47 |
&ReNewSubscription &GetLateIssues &GetLateOrMissingIssues |
45 |
&GetSerialInformation &AddItem2Serial |
48 |
&GetSerialInformation &AddItem2Serial |
Lines 152-171
sub GetLateIssues {
Link Here
|
152 |
|
155 |
|
153 |
=head2 GetSubscriptionHistoryFromSubscriptionId |
156 |
=head2 GetSubscriptionHistoryFromSubscriptionId |
154 |
|
157 |
|
155 |
$sth = GetSubscriptionHistoryFromSubscriptionId() |
158 |
$history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid); |
156 |
this function prepares the SQL request and returns the statement handle |
159 |
|
157 |
After this function, don't forget to execute it by using $sth->execute($subscriptionid) |
160 |
This function returns the subscription history as a hashref |
158 |
|
161 |
|
159 |
=cut |
162 |
=cut |
160 |
|
163 |
|
161 |
sub GetSubscriptionHistoryFromSubscriptionId() { |
164 |
sub GetSubscriptionHistoryFromSubscriptionId { |
|
|
165 |
my ($subscriptionid) = @_; |
166 |
|
167 |
return unless $subscriptionid; |
168 |
|
162 |
my $dbh = C4::Context->dbh; |
169 |
my $dbh = C4::Context->dbh; |
163 |
my $query = qq| |
170 |
my $query = qq| |
164 |
SELECT * |
171 |
SELECT * |
165 |
FROM subscriptionhistory |
172 |
FROM subscriptionhistory |
166 |
WHERE subscriptionid = ? |
173 |
WHERE subscriptionid = ? |
167 |
|; |
174 |
|; |
168 |
return $dbh->prepare($query); |
175 |
my $sth = $dbh->prepare($query); |
|
|
176 |
$sth->execute($subscriptionid); |
177 |
my $results = $sth->fetchrow_hashref; |
178 |
$sth->finish; |
179 |
|
180 |
return $results; |
169 |
} |
181 |
} |
170 |
|
182 |
|
171 |
=head2 GetSerialStatusFromSerialId |
183 |
=head2 GetSerialStatusFromSerialId |
Lines 559-565
sub GetSubscriptions {
Link Here
|
559 |
my $dbh = C4::Context->dbh; |
571 |
my $dbh = C4::Context->dbh; |
560 |
my $sth; |
572 |
my $sth; |
561 |
my $sql = qq( |
573 |
my $sql = qq( |
562 |
SELECT subscription.*, subscriptionhistory.*, biblio.title,biblioitems.issn,biblio.biblionumber |
574 |
SELECT subscriptionhistory.*, subscription.*, biblio.title,biblioitems.issn,biblio.biblionumber |
563 |
FROM subscription |
575 |
FROM subscription |
564 |
LEFT JOIN subscriptionhistory USING(subscriptionid) |
576 |
LEFT JOIN subscriptionhistory USING(subscriptionid) |
565 |
LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
577 |
LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber |
Lines 796-880
a list containing all the input params updated.
Link Here
|
796 |
|
808 |
|
797 |
=cut |
809 |
=cut |
798 |
|
810 |
|
799 |
# sub GetNextSeq { |
|
|
800 |
# my ($val) =@_; |
801 |
# my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); |
802 |
# $calculated = $val->{numberingmethod}; |
803 |
# # calculate the (expected) value of the next issue recieved. |
804 |
# $newlastvalue1 = $val->{lastvalue1}; |
805 |
# # check if we have to increase the new value. |
806 |
# $newinnerloop1 = $val->{innerloop1}+1; |
807 |
# $newinnerloop1=0 if ($newinnerloop1 >= $val->{every1}); |
808 |
# $newlastvalue1 += $val->{add1} if ($newinnerloop1<1); # <1 to be true when 0 or empty. |
809 |
# $newlastvalue1=$val->{setto1} if ($newlastvalue1>$val->{whenmorethan1}); # reset counter if needed. |
810 |
# $calculated =~ s/\{X\}/$newlastvalue1/g; |
811 |
# |
812 |
# $newlastvalue2 = $val->{lastvalue2}; |
813 |
# # check if we have to increase the new value. |
814 |
# $newinnerloop2 = $val->{innerloop2}+1; |
815 |
# $newinnerloop2=0 if ($newinnerloop2 >= $val->{every2}); |
816 |
# $newlastvalue2 += $val->{add2} if ($newinnerloop2<1); # <1 to be true when 0 or empty. |
817 |
# $newlastvalue2=$val->{setto2} if ($newlastvalue2>$val->{whenmorethan2}); # reset counter if needed. |
818 |
# $calculated =~ s/\{Y\}/$newlastvalue2/g; |
819 |
# |
820 |
# $newlastvalue3 = $val->{lastvalue3}; |
821 |
# # check if we have to increase the new value. |
822 |
# $newinnerloop3 = $val->{innerloop3}+1; |
823 |
# $newinnerloop3=0 if ($newinnerloop3 >= $val->{every3}); |
824 |
# $newlastvalue3 += $val->{add3} if ($newinnerloop3<1); # <1 to be true when 0 or empty. |
825 |
# $newlastvalue3=$val->{setto3} if ($newlastvalue3>$val->{whenmorethan3}); # reset counter if needed. |
826 |
# $calculated =~ s/\{Z\}/$newlastvalue3/g; |
827 |
# return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); |
828 |
# } |
829 |
|
830 |
sub GetNextSeq { |
811 |
sub GetNextSeq { |
831 |
my ($val) = @_; |
812 |
my ($val, $planneddate) = @_; |
832 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
813 |
my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
833 |
my $pattern = $val->{numberpattern}; |
814 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
834 |
my @seasons = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' ); |
815 |
my $count = 1; |
835 |
my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' ); |
816 |
|
836 |
$calculated = $val->{numberingmethod}; |
817 |
if($val->{'skip_serialseq'}) { |
837 |
$newlastvalue1 = $val->{lastvalue1}; |
818 |
my @irreg = split /;/, $val->{'irregularity'}; |
838 |
$newlastvalue2 = $val->{lastvalue2}; |
819 |
if(@irreg > 0) { |
839 |
$newlastvalue3 = $val->{lastvalue3}; |
820 |
my $irregularities = {}; |
840 |
$newlastvalue1 = $val->{lastvalue1}; |
821 |
$irregularities->{$_} = 1 foreach(@irreg); |
841 |
|
822 |
my $issueno = GetFictiveIssueNumber($val, $planneddate) + 1; |
842 |
# check if we have to increase the new value. |
823 |
while($irregularities->{$issueno}) { |
843 |
$newinnerloop1 = $val->{innerloop1} + 1; |
824 |
$count++; |
844 |
$newinnerloop1 = 0 if ( $newinnerloop1 >= $val->{every1} ); |
825 |
$issueno++; |
845 |
$newlastvalue1 += $val->{add1} if ( $newinnerloop1 < 1 ); # <1 to be true when 0 or empty. |
826 |
} |
846 |
$newlastvalue1 = $val->{setto1} if ( $newlastvalue1 > $val->{whenmorethan1} ); # reset counter if needed. |
|
|
847 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
848 |
|
849 |
$newlastvalue2 = $val->{lastvalue2}; |
850 |
|
851 |
# check if we have to increase the new value. |
852 |
$newinnerloop2 = $val->{innerloop2} + 1; |
853 |
$newinnerloop2 = 0 if ( $newinnerloop2 >= $val->{every2} ); |
854 |
$newlastvalue2 += $val->{add2} if ( $newinnerloop2 < 1 ); # <1 to be true when 0 or empty. |
855 |
$newlastvalue2 = $val->{setto2} if ( $newlastvalue2 > $val->{whenmorethan2} ); # reset counter if needed. |
856 |
if ( $pattern == 6 ) { |
857 |
if ( $val->{hemisphere} == 2 ) { |
858 |
my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; |
859 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
860 |
} else { |
861 |
my $newlastvalue2seq = $seasons[$newlastvalue2]; |
862 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
863 |
} |
827 |
} |
864 |
} else { |
|
|
865 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
866 |
} |
828 |
} |
867 |
|
829 |
|
868 |
$newlastvalue3 = $val->{lastvalue3}; |
830 |
my $pattern = $val->{numberpattern}; |
|
|
831 |
$calculated = $val->{numberingmethod}; |
832 |
my $locale = $val->{locale}; |
833 |
$newlastvalue1 = $val->{lastvalue1} || 0; |
834 |
$newlastvalue2 = $val->{lastvalue2} || 0; |
835 |
$newlastvalue3 = $val->{lastvalue3} || 0; |
836 |
$newinnerloop1 = $val->{innerloop1} || 0; |
837 |
$newinnerloop2 = $val->{innerloop2} || 0; |
838 |
$newinnerloop3 = $val->{innerloop3} || 0; |
839 |
my %calc; |
840 |
foreach(qw/X Y Z/) { |
841 |
$calc{$_} = 1 if ($val->{'numberingmethod'} =~ /\{$_\}/); |
842 |
} |
869 |
|
843 |
|
870 |
# check if we have to increase the new value. |
844 |
for(my $i = 0; $i < $count; $i++) { |
871 |
$newinnerloop3 = $val->{innerloop3} + 1; |
845 |
if($calc{'X'}) { |
872 |
$newinnerloop3 = 0 if ( $newinnerloop3 >= $val->{every3} ); |
846 |
# check if we have to increase the new value. |
873 |
$newlastvalue3 += $val->{add3} if ( $newinnerloop3 < 1 ); # <1 to be true when 0 or empty. |
847 |
$newinnerloop1 += 1; |
874 |
$newlastvalue3 = $val->{setto3} if ( $newlastvalue3 > $val->{whenmorethan3} ); # reset counter if needed. |
848 |
if ($newinnerloop1 >= $val->{every1}) { |
875 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
849 |
$newinnerloop1 = 0; |
|
|
850 |
$newlastvalue1 += $val->{add1}; |
851 |
} |
852 |
# reset counter if needed. |
853 |
$newlastvalue1 = $val->{setto1} if ($newlastvalue1 > $val->{whenmorethan1}); |
854 |
} |
855 |
if($calc{'Y'}) { |
856 |
# check if we have to increase the new value. |
857 |
$newinnerloop2 += 1; |
858 |
if ($newinnerloop2 >= $val->{every2}) { |
859 |
$newinnerloop2 = 0; |
860 |
$newlastvalue2 += $val->{add2}; |
861 |
} |
862 |
# reset counter if needed. |
863 |
$newlastvalue2 = $val->{setto2} if ($newlastvalue2 > $val->{whenmorethan2}); |
864 |
} |
865 |
if($calc{'Z'}) { |
866 |
# check if we have to increase the new value. |
867 |
$newinnerloop3 += 1; |
868 |
if ($newinnerloop3 >= $val->{every3}) { |
869 |
$newinnerloop3 = 0; |
870 |
$newlastvalue3 += $val->{add3}; |
871 |
} |
872 |
# reset counter if needed. |
873 |
$newlastvalue3 = $val->{setto3} if ($newlastvalue3 > $val->{whenmorethan3}); |
874 |
} |
875 |
} |
876 |
if($calc{'X'}) { |
877 |
my $newlastvalue1string = _numeration( $newlastvalue1, $val->{numbering1}, $locale ); |
878 |
$calculated =~ s/\{X\}/$newlastvalue1string/g; |
879 |
} |
880 |
if($calc{'Y'}) { |
881 |
my $newlastvalue2string = _numeration( $newlastvalue2, $val->{numbering2}, $locale ); |
882 |
$calculated =~ s/\{Y\}/$newlastvalue2string/g; |
883 |
} |
884 |
if($calc{'Z'}) { |
885 |
my $newlastvalue3string = _numeration( $newlastvalue3, $val->{numbering3}, $locale ); |
886 |
$calculated =~ s/\{Z\}/$newlastvalue3string/g; |
887 |
} |
876 |
|
888 |
|
877 |
return ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); |
889 |
return ($calculated, |
|
|
890 |
$newlastvalue1, $newlastvalue2, $newlastvalue3, |
891 |
$newinnerloop1, $newinnerloop2, $newinnerloop3); |
878 |
} |
892 |
} |
879 |
|
893 |
|
880 |
=head2 GetSeq |
894 |
=head2 GetSeq |
Lines 889-915
the sequence in integer format
Link Here
|
889 |
|
903 |
|
890 |
sub GetSeq { |
904 |
sub GetSeq { |
891 |
my ($val) = @_; |
905 |
my ($val) = @_; |
|
|
906 |
my $locale = $val->{locale}; |
907 |
|
892 |
my $pattern = $val->{numberpattern}; |
908 |
my $pattern = $val->{numberpattern}; |
893 |
my @seasons = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' ); |
909 |
my $calculated = $val->{numberingmethod}; |
894 |
my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' ); |
910 |
|
895 |
my $calculated = $val->{numberingmethod}; |
911 |
my $newlastvalue1 = $val->{'lastvalue1'} || 0; |
896 |
my $x = $val->{'lastvalue1'}; |
912 |
$newlastvalue1 = _numeration($newlastvalue1, $val->{numbering1}, $locale) if ($val->{numbering1}); # reset counter if needed. |
897 |
$calculated =~ s/\{X\}/$x/g; |
913 |
$calculated =~ s/\{X\}/$newlastvalue1/g; |
898 |
my $newlastvalue2 = $val->{'lastvalue2'}; |
914 |
|
899 |
|
915 |
my $newlastvalue2 = $val->{'lastvalue2'} || 0; |
900 |
if ( $pattern == 6 ) { |
916 |
$newlastvalue2 = _numeration($newlastvalue2, $val->{numbering2}, $locale) if ($val->{numbering2}); # reset counter if needed. |
901 |
if ( $val->{hemisphere} == 2 ) { |
917 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
902 |
my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; |
918 |
|
903 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
919 |
my $newlastvalue3 = $val->{'lastvalue3'} || 0; |
904 |
} else { |
920 |
$newlastvalue3 = _numeration($newlastvalue3, $val->{numbering3}, $locale) if ($val->{numbering3}); # reset counter if needed. |
905 |
my $newlastvalue2seq = $seasons[$newlastvalue2]; |
921 |
$calculated =~ s/\{Z\}/$newlastvalue3/g; |
906 |
$calculated =~ s/\{Y\}/$newlastvalue2seq/g; |
|
|
907 |
} |
908 |
} else { |
909 |
$calculated =~ s/\{Y\}/$newlastvalue2/g; |
910 |
} |
911 |
my $z = $val->{'lastvalue3'}; |
912 |
$calculated =~ s/\{Z\}/$z/g; |
913 |
return $calculated; |
922 |
return $calculated; |
914 |
} |
923 |
} |
915 |
|
924 |
|
Lines 934-947
sub GetExpirationDate {
Link Here
|
934 |
$enddate = $startdate || $subscription->{startdate}; |
943 |
$enddate = $startdate || $subscription->{startdate}; |
935 |
my @date = split( /-/, $enddate ); |
944 |
my @date = split( /-/, $enddate ); |
936 |
return if ( scalar(@date) != 3 || not check_date(@date) ); |
945 |
return if ( scalar(@date) != 3 || not check_date(@date) ); |
937 |
if ( ( $subscription->{periodicity} % 16 ) > 0 ) { |
946 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); |
938 |
|
947 |
if ( $frequency and $frequency->{unit} ) { |
|
|
948 |
|
939 |
# If Not Irregular |
949 |
# If Not Irregular |
940 |
if ( my $length = $subscription->{numberlength} ) { |
950 |
if ( my $length = $subscription->{numberlength} ) { |
941 |
|
951 |
|
942 |
#calculate the date of the last issue. |
952 |
#calculate the date of the last issue. |
943 |
for ( my $i = 1 ; $i <= $length ; $i++ ) { |
953 |
for ( my $i = 1 ; $i <= $length ; $i++ ) { |
944 |
$enddate = GetNextDate( $enddate, $subscription ); |
954 |
$enddate = GetNextDate( $subscription, $enddate ); |
945 |
} |
955 |
} |
946 |
} elsif ( $subscription->{monthlength} ) { |
956 |
} elsif ( $subscription->{monthlength} ) { |
947 |
if ( $$subscription{startdate} ) { |
957 |
if ( $$subscription{startdate} ) { |
Lines 954-963
sub GetExpirationDate {
Link Here
|
954 |
my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 ); |
964 |
my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 ); |
955 |
$enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] ); |
965 |
$enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] ); |
956 |
} |
966 |
} |
|
|
967 |
} else { |
968 |
$enddate = $subscription->{enddate}; |
957 |
} |
969 |
} |
958 |
return $enddate; |
970 |
return $enddate; |
959 |
} else { |
971 |
} else { |
960 |
return; |
972 |
return $subscription->{enddate}; |
961 |
} |
973 |
} |
962 |
} |
974 |
} |
963 |
|
975 |
|
Lines 990-1009
returns the number of rows affected
Link Here
|
990 |
=cut |
1002 |
=cut |
991 |
|
1003 |
|
992 |
sub ModSubscriptionHistory { |
1004 |
sub ModSubscriptionHistory { |
993 |
my ( $subscriptionid, $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote ) = @_; |
1005 |
my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_; |
994 |
my $dbh = C4::Context->dbh; |
1006 |
my $dbh = C4::Context->dbh; |
995 |
my $query = "UPDATE subscriptionhistory |
1007 |
my $query = "UPDATE subscriptionhistory |
996 |
SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? |
1008 |
SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? |
997 |
WHERE subscriptionid=? |
1009 |
WHERE subscriptionid=? |
998 |
"; |
1010 |
"; |
999 |
my $sth = $dbh->prepare($query); |
1011 |
my $sth = $dbh->prepare($query); |
1000 |
$recievedlist =~ s/^; //; |
1012 |
$receivedlist =~ s/^; // if $receivedlist; |
1001 |
$missinglist =~ s/^; //; |
1013 |
$missinglist =~ s/^; // if $missinglist; |
1002 |
$opacnote =~ s/^; //; |
1014 |
$opacnote =~ s/^; // if $opacnote; |
1003 |
$sth->execute( $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote, $subscriptionid ); |
1015 |
$sth->execute( $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote, $subscriptionid ); |
1004 |
return $sth->rows; |
1016 |
return $sth->rows; |
1005 |
} |
1017 |
} |
1006 |
|
1018 |
|
|
|
1019 |
# Update missinglist field, used by ModSerialStatus |
1020 |
sub _update_missinglist { |
1021 |
my $subscriptionid = shift; |
1022 |
|
1023 |
my $dbh = C4::Context->dbh; |
1024 |
my @missingserials = GetSerials2($subscriptionid, "4,5"); |
1025 |
my $missinglist; |
1026 |
foreach (@missingserials) { |
1027 |
if($_->{'status'} == 4) { |
1028 |
$missinglist .= $_->{'serialseq'} . "; "; |
1029 |
} elsif($_->{'status'} == 5) { |
1030 |
$missinglist .= "not issued " . $_->{'serialseq'} . "; "; |
1031 |
} |
1032 |
} |
1033 |
$missinglist =~ s/; $//; |
1034 |
my $query = qq{ |
1035 |
UPDATE subscriptionhistory |
1036 |
SET missinglist = ? |
1037 |
WHERE subscriptionid = ? |
1038 |
}; |
1039 |
my $sth = $dbh->prepare($query); |
1040 |
$sth->execute($missinglist, $subscriptionid); |
1041 |
} |
1042 |
|
1043 |
# Update recievedlist field, used by ModSerialStatus |
1044 |
sub _update_receivedlist { |
1045 |
my $subscriptionid = shift; |
1046 |
|
1047 |
my $dbh = C4::Context->dbh; |
1048 |
my @receivedserials = GetSerials2($subscriptionid, "2"); |
1049 |
my $receivedlist; |
1050 |
foreach (@receivedserials) { |
1051 |
$receivedlist .= $_->{'serialseq'} . "; "; |
1052 |
} |
1053 |
$receivedlist =~ s/; $//; |
1054 |
my $query = qq{ |
1055 |
UPDATE subscriptionhistory |
1056 |
SET recievedlist = ? |
1057 |
WHERE subscriptionid = ? |
1058 |
}; |
1059 |
my $sth = $dbh->prepare($query); |
1060 |
$sth->execute($receivedlist, $subscriptionid); |
1061 |
} |
1062 |
|
1007 |
=head2 ModSerialStatus |
1063 |
=head2 ModSerialStatus |
1008 |
|
1064 |
|
1009 |
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes) |
1065 |
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes) |
Lines 1016-1037
Note : if we change from "waited" to something else,then we will have to create
Link Here
|
1016 |
sub ModSerialStatus { |
1072 |
sub ModSerialStatus { |
1017 |
my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_; |
1073 |
my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_; |
1018 |
|
1074 |
|
|
|
1075 |
|
1019 |
#It is a usual serial |
1076 |
#It is a usual serial |
1020 |
# 1st, get previous status : |
1077 |
# 1st, get previous status : |
1021 |
my $dbh = C4::Context->dbh; |
1078 |
my $dbh = C4::Context->dbh; |
1022 |
my $query = "SELECT subscriptionid,status FROM serial WHERE serialid=?"; |
1079 |
my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity |
|
|
1080 |
FROM serial, subscription |
1081 |
WHERE serial.subscriptionid=subscription.subscriptionid |
1082 |
AND serialid=?"; |
1023 |
my $sth = $dbh->prepare($query); |
1083 |
my $sth = $dbh->prepare($query); |
1024 |
$sth->execute($serialid); |
1084 |
$sth->execute($serialid); |
1025 |
my ( $subscriptionid, $oldstatus ) = $sth->fetchrow; |
1085 |
my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow; |
|
|
1086 |
my $frequency = GetSubscriptionFrequency($periodicity); |
1026 |
|
1087 |
|
1027 |
# change status & update subscriptionhistory |
1088 |
# change status & update subscriptionhistory |
1028 |
my $val; |
1089 |
my $val; |
1029 |
if ( $status == 6 ) { |
1090 |
if ( $status == 6 ) { |
1030 |
DelIssue( {'serialid'=>$serialid, 'subscriptionid'=>$subscriptionid,'serialseq'=>$serialseq} ); |
1091 |
DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); |
1031 |
} |
1092 |
} else { |
1032 |
else { |
1093 |
|
1033 |
my $query = |
1094 |
unless ($frequency->{'unit'}) { |
1034 |
'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?'; |
1095 |
if ( not $planneddate or $planneddate eq '0000-00-00' ) { $planneddate = C4::Dates->new()->output('iso') }; |
|
|
1096 |
if ( not $publisheddate or $publisheddate eq '0000-00-00' ) { $publisheddate = C4::Dates->new()->output('iso') }; |
1097 |
} |
1098 |
my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?'; |
1035 |
$sth = $dbh->prepare($query); |
1099 |
$sth = $dbh->prepare($query); |
1036 |
$sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid ); |
1100 |
$sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid ); |
1037 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
1101 |
$query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
Lines 1039-1096
sub ModSerialStatus {
Link Here
|
1039 |
$sth->execute($subscriptionid); |
1103 |
$sth->execute($subscriptionid); |
1040 |
my $val = $sth->fetchrow_hashref; |
1104 |
my $val = $sth->fetchrow_hashref; |
1041 |
unless ( $val->{manualhistory} ) { |
1105 |
unless ( $val->{manualhistory} ) { |
1042 |
$query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE subscriptionid=?"; |
1106 |
if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) { |
1043 |
$sth = $dbh->prepare($query); |
1107 |
_update_receivedlist($subscriptionid); |
1044 |
$sth->execute($subscriptionid); |
1108 |
} |
1045 |
my ( $missinglist, $recievedlist ) = $sth->fetchrow; |
1109 |
if($status == 4 || $status == 5 |
1046 |
if ( $status == 2 ) { |
1110 |
|| ($oldstatus == 4 && $status != 4) |
1047 |
|
1111 |
|| ($oldstatus == 5 && $status != 5)) { |
1048 |
$recievedlist .= "; $serialseq" |
1112 |
_update_missinglist($subscriptionid); |
1049 |
unless ( index( "$recievedlist", "$serialseq" ) >= 0 ); |
|
|
1050 |
} |
1113 |
} |
1051 |
|
|
|
1052 |
# warn "missinglist : $missinglist serialseq :$serialseq, ".index("$missinglist","$serialseq"); |
1053 |
$missinglist .= "; $serialseq" |
1054 |
if ( $status == 4 |
1055 |
and not index( "$missinglist", "$serialseq" ) >= 0 ); |
1056 |
$missinglist .= "; not issued $serialseq" |
1057 |
if ( $status == 5 |
1058 |
and index( "$missinglist", "$serialseq" ) >= 0 ); |
1059 |
$query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=?"; |
1060 |
$sth = $dbh->prepare($query); |
1061 |
$recievedlist =~ s/^; //; |
1062 |
$missinglist =~ s/^; //; |
1063 |
$sth->execute( $recievedlist, $missinglist, $subscriptionid ); |
1064 |
} |
1114 |
} |
1065 |
} |
1115 |
} |
1066 |
|
1116 |
|
1067 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1117 |
# create new waited entry if needed (ie : was a "waited" and has changed) |
1068 |
if ( $oldstatus == 1 && $status != 1 ) { |
1118 |
if ( $oldstatus == 1 && $status != 1 ) { |
1069 |
my $query = "SELECT * FROM subscription WHERE subscriptionid = ?"; |
1119 |
my $query = qq{ |
|
|
1120 |
SELECT subscription.*, subscription_numberpatterns.*, |
1121 |
subscription_frequencies.* |
1122 |
FROM subscription |
1123 |
LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id |
1124 |
LEFT JOIN subscription_frequencies ON subscription.periodicity = subscription_frequencies.id |
1125 |
WHERE subscriptionid = ? |
1126 |
}; |
1070 |
$sth = $dbh->prepare($query); |
1127 |
$sth = $dbh->prepare($query); |
1071 |
$sth->execute($subscriptionid); |
1128 |
$sth->execute($subscriptionid); |
1072 |
my $val = $sth->fetchrow_hashref; |
1129 |
my $val = $sth->fetchrow_hashref; |
1073 |
|
1130 |
|
1074 |
# next issue number |
1131 |
# next issue number |
1075 |
my ( |
1132 |
my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($val, $publisheddate); |
1076 |
$newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, |
|
|
1077 |
$newinnerloop1, $newinnerloop2, $newinnerloop3 |
1078 |
) = GetNextSeq($val); |
1079 |
|
1133 |
|
1080 |
# next date (calculated from actual date & frequency parameters) |
1134 |
# next date (calculated from actual date & frequency parameters) |
1081 |
my $nextpublisheddate = GetNextDate( $publisheddate, $val ); |
1135 |
my $nextpublisheddate = GetNextDate($val, $publisheddate, 1); |
1082 |
NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate, $nextpublisheddate ); |
1136 |
my $nextpubdate = $nextpublisheddate; |
|
|
1137 |
NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpubdate, $nextpubdate ); |
1083 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1138 |
$query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? |
1084 |
WHERE subscriptionid = ?"; |
1139 |
WHERE subscriptionid = ?"; |
1085 |
$sth = $dbh->prepare($query); |
1140 |
$sth = $dbh->prepare($query); |
1086 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1141 |
$sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid ); |
1087 |
|
1142 |
|
1088 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1143 |
# check if an alert must be sent... (= a letter is defined & status became "arrived" |
1089 |
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) { |
1144 |
if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) { |
1090 |
require C4::Letters; |
1145 |
require C4::Letters; |
1091 |
C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} ); |
1146 |
C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} ); |
1092 |
} |
1147 |
} |
1093 |
} |
1148 |
} |
|
|
1149 |
|
1094 |
return; |
1150 |
return; |
1095 |
} |
1151 |
} |
1096 |
|
1152 |
|
Lines 1104-1134
returns a hashref:
Link Here
|
1104 |
|
1160 |
|
1105 |
$nextexepected = { |
1161 |
$nextexepected = { |
1106 |
serialid => int |
1162 |
serialid => int |
1107 |
planneddate => C4::Dates object |
1163 |
planneddate => ISO date |
1108 |
} |
1164 |
} |
1109 |
|
1165 |
|
1110 |
=cut |
1166 |
=cut |
1111 |
|
1167 |
|
1112 |
sub GetNextExpected($) { |
1168 |
sub GetNextExpected($) { |
1113 |
my ($subscriptionid) = @_; |
1169 |
my ($subscriptionid) = @_; |
1114 |
my $dbh = C4::Context->dbh; |
1170 |
|
1115 |
my $sth = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?'); |
1171 |
my $dbh = C4::Context->dbh; |
|
|
1172 |
my $query = qq{ |
1173 |
SELECT * |
1174 |
FROM serial |
1175 |
WHERE subscriptionid = ? |
1176 |
AND status = ? |
1177 |
LIMIT 1 |
1178 |
}; |
1179 |
my $sth = $dbh->prepare($query); |
1116 |
|
1180 |
|
1117 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1181 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1118 |
$sth->execute( $subscriptionid, 1 ); |
1182 |
$sth->execute( $subscriptionid, 1 ); |
1119 |
my ( $nextissue ) = $sth->fetchrow_hashref; |
1183 |
my $nextissue = $sth->fetchrow_hashref; |
1120 |
if( !$nextissue){ |
1184 |
if ( !$nextissue ) { |
1121 |
$sth = $dbh->prepare('SELECT serialid,planneddate FROM serial WHERE subscriptionid = ? ORDER BY planneddate DESC LIMIT 1'); |
1185 |
$query = qq{ |
1122 |
$sth->execute( $subscriptionid ); |
1186 |
SELECT * |
1123 |
$nextissue = $sth->fetchrow_hashref; |
1187 |
FROM serial |
|
|
1188 |
WHERE subscriptionid = ? |
1189 |
ORDER BY planneddate DESC |
1190 |
LIMIT 1 |
1191 |
}; |
1192 |
$sth = $dbh->prepare($query); |
1193 |
$sth->execute($subscriptionid); |
1194 |
$nextissue = $sth->fetchrow_hashref; |
1124 |
} |
1195 |
} |
1125 |
if (!defined $nextissue->{planneddate}) { |
1196 |
foreach(qw/planneddate publisheddate/) { |
1126 |
# or should this default to 1st Jan ??? |
1197 |
if ( !defined $nextissue->{$_} ) { |
1127 |
$nextissue->{planneddate} = strftime('%Y-%m-%d',localtime); |
1198 |
# or should this default to 1st Jan ??? |
|
|
1199 |
$nextissue->{$_} = strftime( '%Y-%m-%d', localtime ); |
1200 |
} |
1201 |
$nextissue->{$_} = ($nextissue->{$_} ne '0000-00-00') |
1202 |
? $nextissue->{$_} |
1203 |
: undef; |
1128 |
} |
1204 |
} |
1129 |
$nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso'); |
|
|
1130 |
return $nextissue; |
1131 |
|
1205 |
|
|
|
1206 |
return $nextissue; |
1132 |
} |
1207 |
} |
1133 |
|
1208 |
|
1134 |
=head2 ModNextExpected |
1209 |
=head2 ModNextExpected |
Lines 1138-1144
ModNextExpected($subscriptionid,$date)
Link Here
|
1138 |
Update the planneddate for the current expected issue of the subscription. |
1213 |
Update the planneddate for the current expected issue of the subscription. |
1139 |
This will modify all future prediction results. |
1214 |
This will modify all future prediction results. |
1140 |
|
1215 |
|
1141 |
C<$date> is a C4::Dates object. |
1216 |
C<$date> is an ISO date. |
1142 |
|
1217 |
|
1143 |
returns 0 |
1218 |
returns 0 |
1144 |
|
1219 |
|
Lines 1152-1162
sub ModNextExpected($$) {
Link Here
|
1152 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1227 |
my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); |
1153 |
|
1228 |
|
1154 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1229 |
# Each subscription has only one 'expected' issue, with serial.status==1. |
1155 |
$sth->execute( $date->output('iso'), $date->output('iso'), $subscriptionid, 1 ); |
1230 |
$sth->execute( $date, $date, $subscriptionid, 1 ); |
1156 |
return 0; |
1231 |
return 0; |
1157 |
|
1232 |
|
1158 |
} |
1233 |
} |
1159 |
|
1234 |
|
|
|
1235 |
=head2 GetSubscriptionIrregularities |
1236 |
|
1237 |
=over4 |
1238 |
|
1239 |
=item @irreg = &GetSubscriptionIrregularities($subscriptionid); |
1240 |
get the list of irregularities for a subscription |
1241 |
|
1242 |
=back |
1243 |
|
1244 |
=cut |
1245 |
|
1246 |
sub GetSubscriptionIrregularities { |
1247 |
my $subscriptionid = shift; |
1248 |
|
1249 |
return undef unless $subscriptionid; |
1250 |
|
1251 |
my $dbh = C4::Context->dbh; |
1252 |
my $query = qq{ |
1253 |
SELECT irregularity |
1254 |
FROM subscription |
1255 |
WHERE subscriptionid = ? |
1256 |
}; |
1257 |
my $sth = $dbh->prepare($query); |
1258 |
$sth->execute($subscriptionid); |
1259 |
|
1260 |
my ($result) = $sth->fetchrow_array; |
1261 |
my @irreg = split /;/, $result; |
1262 |
|
1263 |
return @irreg; |
1264 |
} |
1265 |
|
1160 |
=head2 ModSubscription |
1266 |
=head2 ModSubscription |
1161 |
|
1267 |
|
1162 |
this function modifies a subscription. Put all new values on input args. |
1268 |
this function modifies a subscription. Put all new values on input args. |
Lines 1165-1207
returns the number of rows affected
Link Here
|
1165 |
=cut |
1271 |
=cut |
1166 |
|
1272 |
|
1167 |
sub ModSubscription { |
1273 |
sub ModSubscription { |
1168 |
my ($auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1274 |
my ( |
1169 |
$dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $add1, $every1, |
1275 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, |
1170 |
$whenmorethan1, $setto1, $lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, |
1276 |
$periodicity, $firstacquidate, $irregularity, $numberpattern, $locale, |
1171 |
$lastvalue2, $innerloop2, $add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, |
1277 |
$numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1, |
1172 |
$numberingmethod, $status, $biblionumber, $callnumber, $notes, $letter, $hemisphere, $manualhistory, |
1278 |
$lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, |
1173 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid |
1279 |
$biblionumber, $callnumber, $notes, $letter, $manualhistory, |
|
|
1280 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1281 |
$graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq |
1174 |
) = @_; |
1282 |
) = @_; |
1175 |
|
1283 |
|
1176 |
# warn $irregularity; |
|
|
1177 |
my $dbh = C4::Context->dbh; |
1284 |
my $dbh = C4::Context->dbh; |
1178 |
my $query = "UPDATE subscription |
1285 |
my $query = "UPDATE subscription |
1179 |
SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?, |
1286 |
SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, |
1180 |
periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?, |
1287 |
startdate=?, periodicity=?, firstacquidate=?, irregularity=?, |
1181 |
add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?, |
1288 |
numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?, |
1182 |
add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?, |
1289 |
lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?, |
1183 |
add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?, |
1290 |
lastvalue3=?, innerloop3=?, status=?, biblionumber=?, |
1184 |
numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, |
1291 |
callnumber=?, notes=?, letter=?, manualhistory=?, |
1185 |
letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?, |
1292 |
internalnotes=?, serialsadditems=?, staffdisplaycount=?, |
1186 |
staffdisplaycount = ?,opacdisplaycount = ?, graceperiod = ?, location = ? |
1293 |
opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, |
1187 |
,enddate=? |
1294 |
skip_serialseq=? |
1188 |
WHERE subscriptionid = ?"; |
1295 |
WHERE subscriptionid = ?"; |
1189 |
|
1296 |
|
1190 |
#warn "query :".$query; |
|
|
1191 |
my $sth = $dbh->prepare($query); |
1297 |
my $sth = $dbh->prepare($query); |
1192 |
$sth->execute( |
1298 |
$sth->execute( |
1193 |
$auser, $branchcode, $aqbooksellerid, $cost, |
1299 |
$auser, $branchcode, $aqbooksellerid, $cost, |
1194 |
$aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1300 |
$aqbudgetid, $startdate, $periodicity, $firstacquidate, |
1195 |
$dow, "$irregularity", $numberpattern, $numberlength, |
1301 |
$irregularity, $numberpattern, $locale, $numberlength, |
1196 |
$weeklength, $monthlength, $add1, $every1, |
1302 |
$weeklength, $monthlength, $lastvalue1, $innerloop1, |
1197 |
$whenmorethan1, $setto1, $lastvalue1, $innerloop1, |
1303 |
$lastvalue2, $innerloop2, $lastvalue3, $innerloop3, |
1198 |
$add2, $every2, $whenmorethan2, $setto2, |
1304 |
$status, $biblionumber, $callnumber, $notes, |
1199 |
$lastvalue2, $innerloop2, $add3, $every3, |
1305 |
$letter, ($manualhistory ? $manualhistory : 0), |
1200 |
$whenmorethan3, $setto3, $lastvalue3, $innerloop3, |
|
|
1201 |
$numberingmethod, $status, $biblionumber, $callnumber, |
1202 |
$notes, $letter, $hemisphere, ( $manualhistory ? $manualhistory : 0 ), |
1203 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1306 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, |
1204 |
$graceperiod, $location, $enddate, $subscriptionid |
1307 |
$graceperiod, $location, $enddate, $skip_serialseq, |
|
|
1308 |
$subscriptionid |
1205 |
); |
1309 |
); |
1206 |
my $rows = $sth->rows; |
1310 |
my $rows = $sth->rows; |
1207 |
|
1311 |
|
Lines 1213-1223
sub ModSubscription {
Link Here
|
1213 |
|
1317 |
|
1214 |
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, |
1318 |
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, |
1215 |
$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, |
1319 |
$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, |
1216 |
$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, |
1320 |
$lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3, |
1217 |
$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, |
1321 |
$status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, |
1218 |
$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, |
1322 |
$callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems, |
1219 |
$numberingmethod, $status, $notes, $serialsadditems, |
1323 |
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq); |
1220 |
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate); |
|
|
1221 |
|
1324 |
|
1222 |
Create a new subscription with value given on input args. |
1325 |
Create a new subscription with value given on input args. |
1223 |
|
1326 |
|
Lines 1227-1268
the id of this new subscription
Link Here
|
1227 |
=cut |
1330 |
=cut |
1228 |
|
1331 |
|
1229 |
sub NewSubscription { |
1332 |
sub NewSubscription { |
1230 |
my ($auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, |
1333 |
my ( |
1231 |
$dow, $numberlength, $weeklength, $monthlength, $add1, $every1, $whenmorethan1, $setto1, |
1334 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, |
1232 |
$lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, $lastvalue2, $innerloop2, |
1335 |
$startdate, $periodicity, $numberlength, $weeklength, $monthlength, |
1233 |
$add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, $numberingmethod, $status, |
1336 |
$lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, |
1234 |
$notes, $letter, $firstacquidate, $irregularity, $numberpattern, $callnumber, $hemisphere, $manualhistory, |
1337 |
$innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, |
1235 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate |
1338 |
$numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, |
|
|
1339 |
$serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, |
1340 |
$location, $enddate, $skip_serialseq |
1236 |
) = @_; |
1341 |
) = @_; |
1237 |
my $dbh = C4::Context->dbh; |
1342 |
my $dbh = C4::Context->dbh; |
1238 |
|
1343 |
|
1239 |
#save subscription (insert into database) |
1344 |
#save subscription (insert into database) |
1240 |
my $query = qq| |
1345 |
my $query = qq| |
1241 |
INSERT INTO subscription |
1346 |
INSERT INTO subscription |
1242 |
(librarian,branchcode,aqbooksellerid,cost,aqbudgetid,biblionumber, |
1347 |
(librarian, branchcode, aqbooksellerid, cost, aqbudgetid, |
1243 |
startdate,periodicity,dow,numberlength,weeklength,monthlength, |
1348 |
biblionumber, startdate, periodicity, numberlength, weeklength, |
1244 |
add1,every1,whenmorethan1,setto1,lastvalue1,innerloop1, |
1349 |
monthlength, lastvalue1, innerloop1, lastvalue2, innerloop2, |
1245 |
add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2, |
1350 |
lastvalue3, innerloop3, status, notes, letter, firstacquidate, |
1246 |
add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3, |
1351 |
irregularity, numberpattern, locale, callnumber, |
1247 |
numberingmethod, status, notes, letter,firstacquidate,irregularity, |
1352 |
manualhistory, internalnotes, serialsadditems, staffdisplaycount, |
1248 |
numberpattern, callnumber, hemisphere,manualhistory,internalnotes,serialsadditems, |
1353 |
opacdisplaycount, graceperiod, location, enddate, skip_serialseq) |
1249 |
staffdisplaycount,opacdisplaycount,graceperiod,location,enddate) |
1354 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
1250 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
|
|
1251 |
|; |
1355 |
|; |
1252 |
my $sth = $dbh->prepare($query); |
1356 |
my $sth = $dbh->prepare($query); |
1253 |
$sth->execute( |
1357 |
$sth->execute( |
1254 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, |
1358 |
$auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, |
1255 |
$dow, $numberlength, $weeklength, $monthlength, $add1, $every1, $whenmorethan1, $setto1, |
1359 |
$startdate, $periodicity, $numberlength, $weeklength, |
1256 |
$lastvalue1, $innerloop1, $add2, $every2, $whenmorethan2, $setto2, $lastvalue2, $innerloop2, |
1360 |
$monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, |
1257 |
$add3, $every3, $whenmorethan3, $setto3, $lastvalue3, $innerloop3, $numberingmethod, "$status", |
1361 |
$lastvalue3, $innerloop3, $status, $notes, $letter, |
1258 |
$notes, $letter, $firstacquidate, $irregularity, $numberpattern, $callnumber, $hemisphere, $manualhistory, |
1362 |
$firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, |
1259 |
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate |
1363 |
$manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, |
|
|
1364 |
$opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq |
1260 |
); |
1365 |
); |
1261 |
|
1366 |
|
1262 |
my $subscriptionid = $dbh->{'mysql_insertid'}; |
1367 |
my $subscriptionid = $dbh->{'mysql_insertid'}; |
1263 |
unless ($enddate){ |
1368 |
unless ($enddate) { |
1264 |
$enddate = GetExpirationDate($subscriptionid,$startdate); |
1369 |
$enddate = GetExpirationDate( $subscriptionid, $startdate ); |
1265 |
$query = q| |
1370 |
$query = qq| |
1266 |
UPDATE subscription |
1371 |
UPDATE subscription |
1267 |
SET enddate=? |
1372 |
SET enddate=? |
1268 |
WHERE subscriptionid=? |
1373 |
WHERE subscriptionid=? |
Lines 1270-1276
sub NewSubscription {
Link Here
|
1270 |
$sth = $dbh->prepare($query); |
1375 |
$sth = $dbh->prepare($query); |
1271 |
$sth->execute( $enddate, $subscriptionid ); |
1376 |
$sth->execute( $enddate, $subscriptionid ); |
1272 |
} |
1377 |
} |
1273 |
#then create the 1st waited number |
1378 |
|
|
|
1379 |
# then create the 1st expected number |
1274 |
$query = qq( |
1380 |
$query = qq( |
1275 |
INSERT INTO subscriptionhistory |
1381 |
INSERT INTO subscriptionhistory |
1276 |
(biblionumber, subscriptionid, histstartdate, opacnote, librariannote) |
1382 |
(biblionumber, subscriptionid, histstartdate, opacnote, librariannote) |
Lines 1283-1288
sub NewSubscription {
Link Here
|
1283 |
$query = qq( |
1389 |
$query = qq( |
1284 |
SELECT * |
1390 |
SELECT * |
1285 |
FROM subscription |
1391 |
FROM subscription |
|
|
1392 |
LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id |
1286 |
WHERE subscriptionid = ? |
1393 |
WHERE subscriptionid = ? |
1287 |
); |
1394 |
); |
1288 |
$sth = $dbh->prepare($query); |
1395 |
$sth = $dbh->prepare($query); |
Lines 1302-1309
sub NewSubscription {
Link Here
|
1302 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1409 |
logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); |
1303 |
|
1410 |
|
1304 |
#set serial flag on biblio if not already set. |
1411 |
#set serial flag on biblio if not already set. |
1305 |
my ( $null, ($bib) ) = GetBiblio($biblionumber); |
1412 |
my $bib = GetBiblioData($biblionumber); |
1306 |
if ( !$bib->{'serial'} ) { |
1413 |
if ( $bib and !$bib->{'serial'} ) { |
1307 |
my $record = GetMarcBiblio($biblionumber); |
1414 |
my $record = GetMarcBiblio($biblionumber); |
1308 |
my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} ); |
1415 |
my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} ); |
1309 |
if ($tag) { |
1416 |
if ($tag) { |
Lines 1621-1627
sub HasSubscriptionExpired {
Link Here
|
1621 |
my ($subscriptionid) = @_; |
1728 |
my ($subscriptionid) = @_; |
1622 |
my $dbh = C4::Context->dbh; |
1729 |
my $dbh = C4::Context->dbh; |
1623 |
my $subscription = GetSubscription($subscriptionid); |
1730 |
my $subscription = GetSubscription($subscriptionid); |
1624 |
if ( ( $subscription->{periodicity} % 16 ) > 0 ) { |
1731 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); |
|
|
1732 |
if ( $frequency and $frequency->{unit} ) { |
1625 |
my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); |
1733 |
my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); |
1626 |
if (!defined $expirationdate) { |
1734 |
if (!defined $expirationdate) { |
1627 |
$expirationdate = q{}; |
1735 |
$expirationdate = q{}; |
Lines 1645-1650
sub HasSubscriptionExpired {
Link Here
|
1645 |
|| ( !$res ) ); |
1753 |
|| ( !$res ) ); |
1646 |
return 0; |
1754 |
return 0; |
1647 |
} else { |
1755 |
} else { |
|
|
1756 |
# Irregular |
1648 |
if ( $subscription->{'numberlength'} ) { |
1757 |
if ( $subscription->{'numberlength'} ) { |
1649 |
my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} ); |
1758 |
my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} ); |
1650 |
return 1 if ( $countreceived > $subscription->{'numberlength'} ); |
1759 |
return 1 if ( $countreceived > $subscription->{'numberlength'} ); |
Lines 2136-2164
sub abouttoexpire {
Link Here
|
2136 |
my $dbh = C4::Context->dbh; |
2245 |
my $dbh = C4::Context->dbh; |
2137 |
my $subscription = GetSubscription($subscriptionid); |
2246 |
my $subscription = GetSubscription($subscriptionid); |
2138 |
my $per = $subscription->{'periodicity'}; |
2247 |
my $per = $subscription->{'periodicity'}; |
2139 |
if ($per && $per % 16 > 0){ |
2248 |
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($per); |
2140 |
my $expirationdate = GetExpirationDate($subscriptionid); |
2249 |
if ($frequency and $frequency->{unit}){ |
|
|
2250 |
my $expirationdate = GetExpirationDate($subscriptionid); |
2141 |
my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); |
2251 |
my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); |
2142 |
my @res; |
2252 |
my $nextdate = GetNextDate($subscription, $res); |
2143 |
if (defined $res) { |
2253 |
if(Date::Calc::Delta_Days( |
2144 |
@res=split (/-/,$res); |
2254 |
split( /-/, $nextdate ), |
2145 |
@res=Date::Calc::Today if ($res[0]*$res[1]==0); |
2255 |
split( /-/, $expirationdate ) |
2146 |
} else { # default an undefined value |
2256 |
) <= 0) { |
2147 |
@res=Date::Calc::Today; |
2257 |
return 1; |
2148 |
} |
2258 |
} |
2149 |
my @endofsubscriptiondate=split(/-/,$expirationdate); |
|
|
2150 |
my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 124, 0, 0); |
2151 |
my @datebeforeend; |
2152 |
@datebeforeend = Add_Delta_Days( $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2], |
2153 |
- (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]); |
2154 |
return 1 if ( @res && |
2155 |
(@datebeforeend && |
2156 |
Delta_Days($res[0],$res[1],$res[2], |
2157 |
$datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) <= 0) && |
2158 |
(@endofsubscriptiondate && |
2159 |
Delta_Days($res[0],$res[1],$res[2], |
2160 |
$endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) >= 0) ); |
2161 |
return 0; |
2162 |
} elsif ($subscription->{numberlength}>0) { |
2259 |
} elsif ($subscription->{numberlength}>0) { |
2163 |
return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1); |
2260 |
return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1); |
2164 |
} |
2261 |
} |
Lines 2175-2344
sub in_array { # used in next sub down
Link Here
|
2175 |
return 0; |
2272 |
return 0; |
2176 |
} |
2273 |
} |
2177 |
|
2274 |
|
|
|
2275 |
=head2 GetFictiveIssueNumber |
2276 |
|
2277 |
$issueno = GetFictiveIssueNumber($subscription, $publishedate); |
2278 |
|
2279 |
Get the position of the issue published at $publisheddate, considering the |
2280 |
first issue (at firstacquidate) is at position 1, the next is at position 2, etc... |
2281 |
This issuenumber doesn't take into account irregularities, so, for instance, if the 3rd |
2282 |
issue is declared as 'irregular' (will be skipped at receipt), the next issue number |
2283 |
will be 4, not 3. It's why it is called 'fictive'. It is NOT a serial seq, and is not |
2284 |
depending on how many rows are in serial table. |
2285 |
The issue number calculation is based on subscription frequency, first acquisition |
2286 |
date, and $publisheddate. |
2287 |
|
2288 |
=cut |
2289 |
|
2290 |
sub GetFictiveIssueNumber { |
2291 |
my ($subscription, $publisheddate) = @_; |
2292 |
|
2293 |
my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'}); |
2294 |
my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef; |
2295 |
my $issueno = 0; |
2296 |
|
2297 |
if($unit) { |
2298 |
my ($year, $month, $day) = split /-/, $publisheddate; |
2299 |
my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'}; |
2300 |
my $wkno; |
2301 |
my $delta; |
2302 |
|
2303 |
if($unit eq 'day') { |
2304 |
$delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day); |
2305 |
} elsif($unit eq 'week') { |
2306 |
($wkno, $year) = Week_of_Year($year, $month, $day); |
2307 |
my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day); |
2308 |
$delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) ); |
2309 |
} elsif($unit eq 'month') { |
2310 |
$delta = ($fa_year == $year) |
2311 |
? ($month - $fa_month) |
2312 |
: ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) ); |
2313 |
} elsif($unit eq 'year') { |
2314 |
$delta = $year - $fa_year; |
2315 |
} |
2316 |
if($frequency->{'unitsperissue'} == 1) { |
2317 |
$issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'}; |
2318 |
} else { |
2319 |
# Assuming issuesperunit == 1 |
2320 |
$issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} ); |
2321 |
} |
2322 |
} |
2323 |
return $issueno; |
2324 |
} |
2325 |
|
2178 |
=head2 GetNextDate |
2326 |
=head2 GetNextDate |
2179 |
|
2327 |
|
2180 |
$resultdate = GetNextDate($planneddate,$subscription) |
2328 |
$resultdate = GetNextDate($publisheddate,$subscription) |
2181 |
|
2329 |
|
2182 |
this function it takes the planneddate and will return the next issue's date and will skip dates if there |
2330 |
this function it takes the publisheddate and will return the next issue's date |
2183 |
exists an irregularity |
2331 |
and will skip dates if there exists an irregularity. |
2184 |
- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be |
2332 |
$publisheddate has to be an ISO date |
|
|
2333 |
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit' |
2334 |
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database |
2335 |
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be |
2185 |
skipped then the returned date will be 2007-05-10 |
2336 |
skipped then the returned date will be 2007-05-10 |
2186 |
|
2337 |
|
2187 |
return : |
2338 |
return : |
2188 |
$resultdate - then next date in the sequence |
2339 |
$resultdate - then next date in the sequence (ISO date) |
2189 |
|
2340 |
|
2190 |
Return 0 if periodicity==0 |
2341 |
Return $publisheddate if subscription is irregular |
2191 |
|
2342 |
|
2192 |
=cut |
2343 |
=cut |
2193 |
|
2344 |
|
2194 |
sub GetNextDate(@) { |
2345 |
sub GetNextDate { |
2195 |
my ( $planneddate, $subscription ) = @_; |
2346 |
my ( $subscription, $publisheddate, $updatecount ) = @_; |
2196 |
my @irreg = split( /\,/, $subscription->{irregularity} ); |
|
|
2197 |
|
2347 |
|
2198 |
#date supposed to be in ISO. |
2348 |
my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); |
2199 |
|
2349 |
|
2200 |
my ( $year, $month, $day ) = split( /-/, $planneddate ); |
2350 |
if ($freqdata->{'unit'}) { |
2201 |
$month = 1 unless ($month); |
2351 |
my ( $year, $month, $day ) = split /-/, $publisheddate; |
2202 |
$day = 1 unless ($day); |
|
|
2203 |
my @resultdate; |
2204 |
|
2352 |
|
2205 |
# warn "DOW $dayofweek"; |
2353 |
# Process an irregularity Hash |
2206 |
if ( $subscription->{periodicity} % 16 == 0 ) { # 'without regularity' || 'irregular' |
2354 |
# Suppose that irregularities are stored in a string with this structure |
2207 |
return 0; |
2355 |
# irreg1;irreg2;irreg3 |
2208 |
} |
2356 |
# where irregX is the number of issue which will not be received |
2209 |
|
2357 |
# (the first issue takes the number 1, the 2nd the number 2 and so on) |
2210 |
# daily : n / week |
2358 |
my @irreg = split /;/, $subscription->{'irregularity'} ; |
2211 |
# Since we're interpreting irregularity here as which days of the week to skip an issue, |
2359 |
my %irregularities; |
2212 |
# renaming this pattern from 1/day to " n / week ". |
2360 |
foreach my $irregularity (@irreg) { |
2213 |
if ( $subscription->{periodicity} == 1 ) { |
2361 |
$irregularities{$irregularity} = 1; |
2214 |
my $dayofweek = eval { Day_of_Week( $year, $month, $day ) }; |
|
|
2215 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2216 |
else { |
2217 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2218 |
$dayofweek = 0 if ( $dayofweek == 7 ); |
2219 |
if ( in_array( ( $dayofweek + 1 ), @irreg ) ) { |
2220 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 1 ); |
2221 |
$dayofweek++; |
2222 |
} |
2223 |
} |
2224 |
@resultdate = Add_Delta_Days( $year, $month, $day, 1 ); |
2225 |
} |
2362 |
} |
2226 |
} |
|
|
2227 |
|
2363 |
|
2228 |
# 1 week |
2364 |
# Get the 'fictive' next issue number |
2229 |
if ( $subscription->{periodicity} == 2 ) { |
2365 |
# It is used to check if next issue is an irregular issue. |
2230 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2366 |
my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1; |
2231 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2367 |
|
2232 |
else { |
2368 |
# Then get the next date |
2233 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2369 |
my $unit = lc $freqdata->{'unit'}; |
2234 |
|
2370 |
if ($unit eq 'day') { |
2235 |
#FIXME: if two consecutive irreg, do we only skip one? |
2371 |
while ($irregularities{$issueno}) { |
2236 |
if ( $irreg[$i] == ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ) ) { |
2372 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2237 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 7 ); |
2373 |
($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{'unitsperissue'} ); |
2238 |
$wkno = ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ); |
2374 |
$subscription->{'countissuesperunit'} = 1; |
|
|
2375 |
} else { |
2376 |
$subscription->{'countissuesperunit'}++; |
2239 |
} |
2377 |
} |
|
|
2378 |
$issueno++; |
2240 |
} |
2379 |
} |
2241 |
@resultdate = Add_Delta_Days( $year, $month, $day, 7 ); |
2380 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2242 |
} |
2381 |
($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{"unitsperissue"} ); |
2243 |
} |
2382 |
$subscription->{'countissuesperunit'} = 1; |
2244 |
|
2383 |
} else { |
2245 |
# 1 / 2 weeks |
2384 |
$subscription->{'countissuesperunit'}++; |
2246 |
if ( $subscription->{periodicity} == 3 ) { |
|
|
2247 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2248 |
if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; } |
2249 |
else { |
2250 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2251 |
if ( $irreg[$i] == ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ) ) { |
2252 |
### BUGFIX was previously +1 ^ |
2253 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 14 ); |
2254 |
$wkno = ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ); |
2255 |
} |
2256 |
} |
2385 |
} |
2257 |
@resultdate = Add_Delta_Days( $year, $month, $day, 14 ); |
|
|
2258 |
} |
2386 |
} |
2259 |
} |
2387 |
elsif ($unit eq 'week') { |
2260 |
|
2388 |
my ($wkno, $yr) = Week_of_Year($year, $month, $day); |
2261 |
# 1 / 3 weeks |
2389 |
while ($irregularities{$issueno}) { |
2262 |
if ( $subscription->{periodicity} == 4 ) { |
2390 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2263 |
my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) }; |
2391 |
$subscription->{'countissuesperunit'} = 1; |
2264 |
if ($@) { warn "année mois jour : $year $month $day $subscription->{subscriptionid} : $@"; } |
2392 |
$wkno += $freqdata->{"unitsperissue"}; |
2265 |
else { |
2393 |
if($wkno > 52){ |
2266 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2394 |
$wkno = $wkno % 52; |
2267 |
if ( $irreg[$i] == ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ) ) { |
2395 |
$yr++; |
2268 |
( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 21 ); |
2396 |
} |
2269 |
$wkno = ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ); |
2397 |
my $dow = Day_of_Week($year, $month, $day); |
|
|
2398 |
($year,$month,$day) = Monday_of_Week($wkno, $yr); |
2399 |
if($freqdata->{'issuesperunit'} == 1) { |
2400 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); |
2401 |
} |
2402 |
} else { |
2403 |
$subscription->{'countissuesperunit'}++; |
2270 |
} |
2404 |
} |
|
|
2405 |
$issueno++; |
2271 |
} |
2406 |
} |
2272 |
@resultdate = Add_Delta_Days( $year, $month, $day, 21 ); |
2407 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2273 |
} |
2408 |
$subscription->{'countissuesperunit'} = 1; |
2274 |
} |
2409 |
$wkno += $freqdata->{"unitsperissue"}; |
2275 |
my $tmpmonth = $month; |
2410 |
if($wkno > 52){ |
2276 |
if ( $year && $month && $day ) { |
2411 |
$wkno = $wkno % 52 ; |
2277 |
if ( $subscription->{periodicity} == 5 ) { |
2412 |
$yr++; |
2278 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
|
|
2279 |
if ( $irreg[$i] == ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ) ) { |
2280 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 ); |
2281 |
$tmpmonth = ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ); |
2282 |
} |
2413 |
} |
2283 |
} |
2414 |
my $dow = Day_of_Week($year, $month, $day); |
2284 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 ); |
2415 |
($year,$month,$day) = Monday_of_Week($wkno, $yr); |
2285 |
} |
2416 |
if($freqdata->{'issuesperunit'} == 1) { |
2286 |
if ( $subscription->{periodicity} == 6 ) { |
2417 |
($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); |
2287 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
|
|
2288 |
if ( $irreg[$i] == ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ) ) { |
2289 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 ); |
2290 |
$tmpmonth = ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ); |
2291 |
} |
2418 |
} |
|
|
2419 |
} else { |
2420 |
$subscription->{'countissuesperunit'}++; |
2292 |
} |
2421 |
} |
2293 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 ); |
|
|
2294 |
} |
2422 |
} |
2295 |
if ( $subscription->{periodicity} == 7 ) { |
2423 |
elsif ($unit eq 'month') { |
2296 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2424 |
while ($irregularities{$issueno}) { |
2297 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2425 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2298 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
2426 |
$subscription->{'countissuesperunit'} = 1; |
2299 |
$tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ); |
2427 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); |
|
|
2428 |
unless($freqdata->{'issuesperunit'} == 1) { |
2429 |
$day = 1; # Jumping to the first day of month, because we don't know what day is expected |
2430 |
} |
2431 |
} else { |
2432 |
$subscription->{'countissuesperunit'}++; |
2300 |
} |
2433 |
} |
|
|
2434 |
$issueno++; |
2301 |
} |
2435 |
} |
2302 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
2436 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2303 |
} |
2437 |
$subscription->{'countissuesperunit'} = 1; |
2304 |
if ( $subscription->{periodicity} == 8 ) { |
2438 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); |
2305 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2439 |
unless($freqdata->{'issuesperunit'} == 1) { |
2306 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2440 |
$day = 1; # Jumping to the first day of month, because we don't know what day is expected |
2307 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
|
|
2308 |
$tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ); |
2309 |
} |
2441 |
} |
|
|
2442 |
} else { |
2443 |
$subscription->{'countissuesperunit'}++; |
2310 |
} |
2444 |
} |
2311 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 ); |
|
|
2312 |
} |
2445 |
} |
2313 |
if ( $subscription->{periodicity} == 13 ) { |
2446 |
elsif ($unit eq 'year') { |
2314 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2447 |
while ($irregularities{$issueno}) { |
2315 |
if ( $irreg[$i] == ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ) ) { |
2448 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2316 |
( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 ); |
2449 |
$subscription->{'countissuesperunit'} = 1; |
2317 |
$tmpmonth = ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ); |
2450 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); |
|
|
2451 |
unless($freqdata->{'issuesperunit'} == 1) { |
2452 |
# Jumping to the first day of year, because we don't know what day is expected |
2453 |
$month = 1; |
2454 |
$day = 1; |
2455 |
} |
2456 |
} else { |
2457 |
$subscription->{'countissuesperunit'}++; |
2318 |
} |
2458 |
} |
|
|
2459 |
$issueno++; |
2319 |
} |
2460 |
} |
2320 |
@resultdate = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 ); |
2461 |
if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ |
2321 |
} |
2462 |
$subscription->{'countissuesperunit'} = 1; |
2322 |
if ( $subscription->{periodicity} == 9 ) { |
2463 |
($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); |
2323 |
for ( my $i = 0 ; $i < @irreg ; $i++ ) { |
2464 |
unless($freqdata->{'issuesperunit'} == 1) { |
2324 |
if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) { |
2465 |
# Jumping to the first day of year, because we don't know what day is expected |
2325 |
### BUFIX Seems to need more Than One ? |
2466 |
$month = 1; |
2326 |
( $year, $month, $day ) = Add_Delta_YM( $year, $month, $day, 0, 6 ); |
2467 |
$day = 1; |
2327 |
$tmpmonth = ( ( $tmpmonth != 6 ) ? ( $tmpmonth + 6 ) % 12 : 12 ); |
|
|
2328 |
} |
2468 |
} |
|
|
2469 |
} else { |
2470 |
$subscription->{'countissuesperunit'}++; |
2329 |
} |
2471 |
} |
2330 |
@resultdate = Add_Delta_YM( $year, $month, $day, 0, 6 ); |
|
|
2331 |
} |
2332 |
if ( $subscription->{periodicity} == 10 ) { |
2333 |
@resultdate = Add_Delta_YM( $year, $month, $day, 1, 0 ); |
2334 |
} |
2472 |
} |
2335 |
if ( $subscription->{periodicity} == 11 ) { |
2473 |
if ($updatecount){ |
2336 |
@resultdate = Add_Delta_YM( $year, $month, $day, 2, 0 ); |
2474 |
my $dbh = C4::Context->dbh; |
|
|
2475 |
my $query = qq{ |
2476 |
UPDATE subscription |
2477 |
SET countissuesperunit = ? |
2478 |
WHERE subscriptionid = ? |
2479 |
}; |
2480 |
my $sth = $dbh->prepare($query); |
2481 |
$sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'}); |
2337 |
} |
2482 |
} |
|
|
2483 |
return sprintf("%04d-%02d-%02d", $year, $month, $day); |
2484 |
} |
2485 |
else { |
2486 |
return $publisheddate; |
2338 |
} |
2487 |
} |
2339 |
my $resultdate = sprintf( "%04d-%02d-%02d", $resultdate[0], $resultdate[1], $resultdate[2] ); |
2488 |
} |
|
|
2489 |
|
2490 |
=head2 _numeration |
2340 |
|
2491 |
|
2341 |
return "$resultdate"; |
2492 |
$string = &_numeration($value,$num_type,$locale); |
|
|
2493 |
|
2494 |
_numeration returns the string corresponding to $value in the num_type |
2495 |
num_type can take : |
2496 |
-dayname |
2497 |
-monthname |
2498 |
-season |
2499 |
=cut |
2500 |
|
2501 |
#' |
2502 |
|
2503 |
sub _numeration { |
2504 |
my ($value, $num_type, $locale) = @_; |
2505 |
$value ||= 0; |
2506 |
my $initlocale = setlocale(LC_TIME); |
2507 |
if($locale and $locale ne $initlocale) { |
2508 |
$locale = setlocale(LC_TIME, $locale); |
2509 |
} |
2510 |
$locale ||= $initlocale; |
2511 |
my $string; |
2512 |
$num_type //= ''; |
2513 |
given ($num_type) { |
2514 |
when (/^dayname$/) { |
2515 |
$value = $value % 7; |
2516 |
$string = POSIX::strftime("%A",0,0,0,0,0,0,$value); |
2517 |
} |
2518 |
when (/^monthname$/) { |
2519 |
$value = $value % 12; |
2520 |
$string = POSIX::strftime("%B",0,0,0,1,$value,0,0,0,0); |
2521 |
} |
2522 |
when (/^season$/) { |
2523 |
my $seasonlocale = ($locale) |
2524 |
? (substr $locale,0,2) |
2525 |
: "en"; |
2526 |
my %seasons=( |
2527 |
"en" => |
2528 |
[qw(Spring Summer Fall Winter)], |
2529 |
"fr"=> |
2530 |
[qw(Printemps Été Automne Hiver)], |
2531 |
); |
2532 |
$value = $value % 4; |
2533 |
$string = ($seasons{$seasonlocale}) |
2534 |
? $seasons{$seasonlocale}->[$value] |
2535 |
: $seasons{'en'}->[$value]; |
2536 |
} |
2537 |
default { |
2538 |
$string = $value; |
2539 |
} |
2540 |
} |
2541 |
if($locale ne $initlocale) { |
2542 |
setlocale(LC_TIME, $initlocale); |
2543 |
} |
2544 |
return $string; |
2342 |
} |
2545 |
} |
2343 |
|
2546 |
|
2344 |
=head2 is_barcode_in_use |
2547 |
=head2 is_barcode_in_use |