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