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