View | Details | Raw Unified | Return to bug 7688
Collapse All | Expand All

(-)a/C4/Serials.pm (-390 / +588 lines)
Lines 18-31 package C4::Serials; Link Here
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
21
use strict;
21
use Modern::Perl;
22
use warnings;
22
23
use C4::Dates qw(format_date format_date_in_iso);
23
use C4::Dates qw(format_date format_date_in_iso);
24
use Date::Calc qw(:all);
24
use Date::Calc qw(:all);
25
use POSIX qw(strftime);
25
use POSIX qw(strftime setlocale LC_TIME);
26
use C4::Biblio;
26
use C4::Biblio;
27
use C4::Log;    # logaction
27
use C4::Log;    # logaction
28
use C4::Debug;
28
use C4::Debug;
29
use C4::Serials::Frequency;
30
use C4::Serials::Numberpattern;
29
31
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
33
Lines 39-46 BEGIN { Link Here
39
      &SearchSubscriptions
41
      &SearchSubscriptions
40
      &GetFullSubscriptionsFromBiblionumber   &GetFullSubscription &ModSubscriptionHistory
42
      &GetFullSubscriptionsFromBiblionumber   &GetFullSubscription &ModSubscriptionHistory
41
      &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
43
      &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
44
      &GetSubscriptionHistoryFromSubscriptionId
42
45
43
      &GetNextSeq         &NewIssue           &ItemizeSerials    &GetSerials
46
      &GetNextSeq &GetSeq &NewIssue           &ItemizeSerials    &GetSerials
44
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
47
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
45
      &ReNewSubscription  &GetLateIssues      &GetLateOrMissingIssues
48
      &ReNewSubscription  &GetLateIssues      &GetLateOrMissingIssues
46
      &GetSerialInformation                   &AddItem2Serial
49
      &GetSerialInformation                   &AddItem2Serial
Lines 163-182 sub GetLateIssues { Link Here
163
166
164
=head2 GetSubscriptionHistoryFromSubscriptionId
167
=head2 GetSubscriptionHistoryFromSubscriptionId
165
168
166
$sth = GetSubscriptionHistoryFromSubscriptionId()
169
$history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
167
this function prepares the SQL request and returns the statement handle
170
168
After this function, don't forget to execute it by using $sth->execute($subscriptionid)
171
This function returns the subscription history as a hashref
169
172
170
=cut
173
=cut
171
174
172
sub GetSubscriptionHistoryFromSubscriptionId {
175
sub GetSubscriptionHistoryFromSubscriptionId {
176
    my ($subscriptionid) = @_;
177
178
    return unless $subscriptionid;
179
173
    my $dbh   = C4::Context->dbh;
180
    my $dbh   = C4::Context->dbh;
174
    my $query = qq|
181
    my $query = qq|
175
        SELECT *
182
        SELECT *
176
        FROM   subscriptionhistory
183
        FROM   subscriptionhistory
177
        WHERE  subscriptionid = ?
184
        WHERE  subscriptionid = ?
178
    |;
185
    |;
179
    return $dbh->prepare($query);
186
    my $sth = $dbh->prepare($query);
187
    $sth->execute($subscriptionid);
188
    my $results = $sth->fetchrow_hashref;
189
    $sth->finish;
190
191
    return $results;
180
}
192
}
181
193
182
=head2 GetSerialStatusFromSerialId
194
=head2 GetSerialStatusFromSerialId
Lines 570-576 sub GetSubscriptions { Link Here
570
    my $dbh = C4::Context->dbh;
582
    my $dbh = C4::Context->dbh;
571
    my $sth;
583
    my $sth;
572
    my $sql = qq(
584
    my $sql = qq(
573
            SELECT subscription.*, subscriptionhistory.*, biblio.title,biblioitems.issn,biblio.biblionumber
585
            SELECT subscriptionhistory.*, subscription.*, biblio.title,biblioitems.issn,biblio.biblionumber
574
            FROM   subscription
586
            FROM   subscription
575
            LEFT JOIN subscriptionhistory USING(subscriptionid)
587
            LEFT JOIN subscriptionhistory USING(subscriptionid)
576
            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
588
            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
Lines 878-1005 sub GetDistributedTo { Link Here
878
890
879
=head2 GetNextSeq
891
=head2 GetNextSeq
880
892
881
GetNextSeq($val)
893
    my (
882
$val is a hashref containing all the attributes of the table 'subscription'
894
        $nextseq,       $newlastvalue1, $newlastvalue2, $newlastvalue3,
895
        $newinnerloop1, $newinnerloop2, $newinnerloop3
896
    ) = GetNextSeq( $subscription, $pattern, $planneddate );
897
898
$subscription is a hashref containing all the attributes of the table
899
'subscription'.
900
$pattern is a hashref containing all the attributes of the table
901
'subscription_numberpatterns'.
902
$planneddate is a C4::Dates object.
883
This function get the next issue for the subscription given on input arg
903
This function get the next issue for the subscription given on input arg
884
return:
885
a list containing all the input params updated.
886
904
887
=cut
905
=cut
888
906
889
# sub GetNextSeq {
890
#     my ($val) =@_;
891
#     my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
892
#     $calculated = $val->{numberingmethod};
893
# # calculate the (expected) value of the next issue recieved.
894
#     $newlastvalue1 = $val->{lastvalue1};
895
# # check if we have to increase the new value.
896
#     $newinnerloop1 = $val->{innerloop1}+1;
897
#     $newinnerloop1=0 if ($newinnerloop1 >= $val->{every1});
898
#     $newlastvalue1 += $val->{add1} if ($newinnerloop1<1); # <1 to be true when 0 or empty.
899
#     $newlastvalue1=$val->{setto1} if ($newlastvalue1>$val->{whenmorethan1}); # reset counter if needed.
900
#     $calculated =~ s/\{X\}/$newlastvalue1/g;
901
#
902
#     $newlastvalue2 = $val->{lastvalue2};
903
# # check if we have to increase the new value.
904
#     $newinnerloop2 = $val->{innerloop2}+1;
905
#     $newinnerloop2=0 if ($newinnerloop2 >= $val->{every2});
906
#     $newlastvalue2 += $val->{add2} if ($newinnerloop2<1); # <1 to be true when 0 or empty.
907
#     $newlastvalue2=$val->{setto2} if ($newlastvalue2>$val->{whenmorethan2}); # reset counter if needed.
908
#     $calculated =~ s/\{Y\}/$newlastvalue2/g;
909
#
910
#     $newlastvalue3 = $val->{lastvalue3};
911
# # check if we have to increase the new value.
912
#     $newinnerloop3 = $val->{innerloop3}+1;
913
#     $newinnerloop3=0 if ($newinnerloop3 >= $val->{every3});
914
#     $newlastvalue3 += $val->{add3} if ($newinnerloop3<1); # <1 to be true when 0 or empty.
915
#     $newlastvalue3=$val->{setto3} if ($newlastvalue3>$val->{whenmorethan3}); # reset counter if needed.
916
#     $calculated =~ s/\{Z\}/$newlastvalue3/g;
917
#     return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
918
# }
919
920
sub GetNextSeq {
907
sub GetNextSeq {
921
    my ($val) = @_;
908
    my ($subscription, $pattern, $planneddate) = @_;
922
    my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 );
909
    my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3,
923
    my $pattern          = $val->{numberpattern};
910
    $newinnerloop1, $newinnerloop2, $newinnerloop3 );
924
    my @seasons          = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' );
911
    my $count = 1;
925
    my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' );
912
926
    $calculated    = $val->{numberingmethod};
913
    if ($subscription->{'skip_serialseq'}) {
927
    $newlastvalue1 = $val->{lastvalue1};
914
        my @irreg = split /;/, $subscription->{'irregularity'};
928
    $newlastvalue2 = $val->{lastvalue2};
915
        if(@irreg > 0) {
929
    $newlastvalue3 = $val->{lastvalue3};
916
            my $irregularities = {};
930
    $newlastvalue1 = $val->{lastvalue1};
917
            $irregularities->{$_} = 1 foreach(@irreg);
931
918
            my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1;
932
    # check if we have to increase the new value.
919
            while($irregularities->{$issueno}) {
933
    $newinnerloop1 = $val->{innerloop1} + 1;
920
                $count++;
934
    $newinnerloop1 = 0 if ( $newinnerloop1 >= $val->{every1} );
921
                $issueno++;
935
    $newlastvalue1 += $val->{add1} if ( $newinnerloop1 < 1 );    # <1 to be true when 0 or empty.
922
            }
936
    $newlastvalue1 = $val->{setto1} if ( $newlastvalue1 > $val->{whenmorethan1} );    # reset counter if needed.
937
    $calculated =~ s/\{X\}/$newlastvalue1/g;
938
939
    $newlastvalue2 = $val->{lastvalue2};
940
941
    # check if we have to increase the new value.
942
    $newinnerloop2 = $val->{innerloop2} + 1;
943
    $newinnerloop2 = 0 if ( $newinnerloop2 >= $val->{every2} );
944
    $newlastvalue2 += $val->{add2} if ( $newinnerloop2 < 1 );                         # <1 to be true when 0 or empty.
945
    $newlastvalue2 = $val->{setto2} if ( $newlastvalue2 > $val->{whenmorethan2} );    # reset counter if needed.
946
    if ( $pattern == 6 ) {
947
        if ( $val->{hemisphere} == 2 ) {
948
            my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
949
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
950
        } else {
951
            my $newlastvalue2seq = $seasons[$newlastvalue2];
952
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
953
        }
923
        }
954
    } else {
955
        $calculated =~ s/\{Y\}/$newlastvalue2/g;
956
    }
924
    }
957
925
958
    $newlastvalue3 = $val->{lastvalue3};
926
    my $numberingmethod = $pattern->{numberingmethod};
959
927
    $calculated    = $numberingmethod;
960
    # check if we have to increase the new value.
928
    my $locale = $subscription->{locale};
961
    $newinnerloop3 = $val->{innerloop3} + 1;
929
    $newlastvalue1 = $subscription->{lastvalue1} || 0;
962
    $newinnerloop3 = 0 if ( $newinnerloop3 >= $val->{every3} );
930
    $newlastvalue2 = $subscription->{lastvalue2} || 0;
963
    $newlastvalue3 += $val->{add3} if ( $newinnerloop3 < 1 );    # <1 to be true when 0 or empty.
931
    $newlastvalue3 = $subscription->{lastvalue3} || 0;
964
    $newlastvalue3 = $val->{setto3} if ( $newlastvalue3 > $val->{whenmorethan3} );    # reset counter if needed.
932
    $newinnerloop1 = $subscription->{innerloop1} || 0;
965
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
933
    $newinnerloop2 = $subscription->{innerloop2} || 0;
934
    $newinnerloop3 = $subscription->{innerloop3} || 0;
935
    my %calc;
936
    foreach(qw/X Y Z/) {
937
        $calc{$_} = 1 if ($numberingmethod =~ /\{$_\}/);
938
    }
939
940
    for(my $i = 0; $i < $count; $i++) {
941
        if($calc{'X'}) {
942
            # check if we have to increase the new value.
943
            $newinnerloop1 += 1;
944
            if ($newinnerloop1 >= $pattern->{every1}) {
945
                $newinnerloop1  = 0;
946
                $newlastvalue1 += $pattern->{add1};
947
            }
948
            # reset counter if needed.
949
            $newlastvalue1 = $pattern->{setto1} if ($newlastvalue1 > $pattern->{whenmorethan1});
950
        }
951
        if($calc{'Y'}) {
952
            # check if we have to increase the new value.
953
            $newinnerloop2 += 1;
954
            if ($newinnerloop2 >= $pattern->{every2}) {
955
                $newinnerloop2  = 0;
956
                $newlastvalue2 += $pattern->{add2};
957
            }
958
            # reset counter if needed.
959
            $newlastvalue2 = $pattern->{setto2} if ($newlastvalue2 > $pattern->{whenmorethan2});
960
        }
961
        if($calc{'Z'}) {
962
            # check if we have to increase the new value.
963
            $newinnerloop3 += 1;
964
            if ($newinnerloop3 >= $pattern->{every3}) {
965
                $newinnerloop3  = 0;
966
                $newlastvalue3 += $pattern->{add3};
967
            }
968
            # reset counter if needed.
969
            $newlastvalue3 = $pattern->{setto3} if ($newlastvalue3 > $pattern->{whenmorethan3});
970
        }
971
    }
972
    if($calc{'X'}) {
973
        my $newlastvalue1string = _numeration( $newlastvalue1, $pattern->{numbering1}, $locale );
974
        $calculated =~ s/\{X\}/$newlastvalue1string/g;
975
    }
976
    if($calc{'Y'}) {
977
        my $newlastvalue2string = _numeration( $newlastvalue2, $pattern->{numbering2}, $locale );
978
        $calculated =~ s/\{Y\}/$newlastvalue2string/g;
979
    }
980
    if($calc{'Z'}) {
981
        my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
982
        $calculated =~ s/\{Z\}/$newlastvalue3string/g;
983
    }
966
984
967
    return ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 );
985
    return ($calculated,
986
            $newlastvalue1, $newlastvalue2, $newlastvalue3,
987
            $newinnerloop1, $newinnerloop2, $newinnerloop3);
968
}
988
}
969
989
970
=head2 GetSeq
990
=head2 GetSeq
971
991
972
$calculated = GetSeq($val)
992
$calculated = GetSeq($subscription, $pattern)
973
$val is a hashref containing all the attributes of the table 'subscription'
993
$subscription is a hashref containing all the attributes of the table 'subscription'
994
$pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'
974
this function transforms {X},{Y},{Z} to 150,0,0 for example.
995
this function transforms {X},{Y},{Z} to 150,0,0 for example.
975
return:
996
return:
976
the sequence in integer format
997
the sequence in string format
977
998
978
=cut
999
=cut
979
1000
980
sub GetSeq {
1001
sub GetSeq {
981
    my ($val) = @_;
1002
    my ($subscription, $pattern) = @_;
982
    my $pattern = $val->{numberpattern};
1003
    my $locale = $subscription->{locale};
983
    my @seasons          = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' );
1004
984
    my @southern_seasons = ( '',        'Summer', 'Autumn', 'Winter', 'Spring' );
1005
    my $calculated = $pattern->{numberingmethod};
985
    my $calculated       = $val->{numberingmethod};
1006
986
    my $x                = $val->{'lastvalue1'};
1007
    my $newlastvalue1 = $subscription->{'lastvalue1'} || 0;
987
    $calculated =~ s/\{X\}/$x/g;
1008
    $newlastvalue1 = _numeration($newlastvalue1, $pattern->{numbering1}, $locale) if ($pattern->{numbering1}); # reset counter if needed.
988
    my $newlastvalue2 = $val->{'lastvalue2'};
1009
    $calculated =~ s/\{X\}/$newlastvalue1/g;
989
1010
990
    if ( $pattern == 6 ) {
1011
    my $newlastvalue2 = $subscription->{'lastvalue2'} || 0;
991
        if ( $val->{hemisphere} == 2 ) {
1012
    $newlastvalue2 = _numeration($newlastvalue2, $pattern->{numbering2}, $locale) if ($pattern->{numbering2}); # reset counter if needed.
992
            my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
1013
    $calculated =~ s/\{Y\}/$newlastvalue2/g;
993
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
1014
994
        } else {
1015
    my $newlastvalue3 = $subscription->{'lastvalue3'} || 0;
995
            my $newlastvalue2seq = $seasons[$newlastvalue2];
1016
    $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed.
996
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
1017
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
997
        }
998
    } else {
999
        $calculated =~ s/\{Y\}/$newlastvalue2/g;
1000
    }
1001
    my $z = $val->{'lastvalue3'};
1002
    $calculated =~ s/\{Z\}/$z/g;
1003
    return $calculated;
1018
    return $calculated;
1004
}
1019
}
1005
1020
Lines 1024-1037 sub GetExpirationDate { Link Here
1024
    $enddate = $startdate || $subscription->{startdate};
1039
    $enddate = $startdate || $subscription->{startdate};
1025
    my @date = split( /-/, $enddate );
1040
    my @date = split( /-/, $enddate );
1026
    return if ( scalar(@date) != 3 || not check_date(@date) );
1041
    return if ( scalar(@date) != 3 || not check_date(@date) );
1027
    if ( ( $subscription->{periodicity} % 16 ) > 0 ) {
1042
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
1043
    if ( $frequency and $frequency->{unit} ) {
1028
1044
1029
        # If Not Irregular
1045
        # If Not Irregular
1030
        if ( my $length = $subscription->{numberlength} ) {
1046
        if ( my $length = $subscription->{numberlength} ) {
1031
1047
1032
            #calculate the date of the last issue.
1048
            #calculate the date of the last issue.
1033
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1049
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
1034
                $enddate = GetNextDate( $enddate, $subscription );
1050
                $enddate = GetNextDate( $subscription, $enddate );
1035
            }
1051
            }
1036
        } elsif ( $subscription->{monthlength} ) {
1052
        } elsif ( $subscription->{monthlength} ) {
1037
            if ( $$subscription{startdate} ) {
1053
            if ( $$subscription{startdate} ) {
Lines 1044-1053 sub GetExpirationDate { Link Here
1044
                my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 );
1060
                my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 );
1045
                $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
1061
                $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
1046
            }
1062
            }
1063
        } else {
1064
            $enddate = $subscription->{enddate};
1047
        }
1065
        }
1048
        return $enddate;
1066
        return $enddate;
1049
    } else {
1067
    } else {
1050
        return;
1068
        return $subscription->{enddate};
1051
    }
1069
    }
1052
}
1070
}
1053
1071
Lines 1080-1099 returns the number of rows affected Link Here
1080
=cut
1098
=cut
1081
1099
1082
sub ModSubscriptionHistory {
1100
sub ModSubscriptionHistory {
1083
    my ( $subscriptionid, $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote ) = @_;
1101
    my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_;
1084
    my $dbh   = C4::Context->dbh;
1102
    my $dbh   = C4::Context->dbh;
1085
    my $query = "UPDATE subscriptionhistory 
1103
    my $query = "UPDATE subscriptionhistory 
1086
                    SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
1104
                    SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
1087
                    WHERE subscriptionid=?
1105
                    WHERE subscriptionid=?
1088
                ";
1106
                ";
1089
    my $sth = $dbh->prepare($query);
1107
    my $sth = $dbh->prepare($query);
1090
    $recievedlist =~ s/^; //;
1108
    $receivedlist =~ s/^; // if $receivedlist;
1091
    $missinglist  =~ s/^; //;
1109
    $missinglist  =~ s/^; // if $missinglist;
1092
    $opacnote     =~ s/^; //;
1110
    $opacnote     =~ s/^; // if $opacnote;
1093
    $sth->execute( $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote, $subscriptionid );
1111
    $sth->execute( $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote, $subscriptionid );
1094
    return $sth->rows;
1112
    return $sth->rows;
1095
}
1113
}
1096
1114
1115
# Update missinglist field, used by ModSerialStatus
1116
sub _update_missinglist {
1117
    my $subscriptionid = shift;
1118
1119
    my $dbh = C4::Context->dbh;
1120
    my @missingserials = GetSerials2($subscriptionid, "4,5");
1121
    my $missinglist;
1122
    foreach (@missingserials) {
1123
        if($_->{'status'} == 4) {
1124
            $missinglist .= $_->{'serialseq'} . "; ";
1125
        } elsif($_->{'status'} == 5) {
1126
            $missinglist .= "not issued " . $_->{'serialseq'} . "; ";
1127
        }
1128
    }
1129
    $missinglist =~ s/; $//;
1130
    my $query = qq{
1131
        UPDATE subscriptionhistory
1132
        SET missinglist = ?
1133
        WHERE subscriptionid = ?
1134
    };
1135
    my $sth = $dbh->prepare($query);
1136
    $sth->execute($missinglist, $subscriptionid);
1137
}
1138
1139
# Update recievedlist field, used by ModSerialStatus
1140
sub _update_receivedlist {
1141
    my $subscriptionid = shift;
1142
1143
    my $dbh = C4::Context->dbh;
1144
    my @receivedserials = GetSerials2($subscriptionid, "2");
1145
    my $receivedlist;
1146
    foreach (@receivedserials) {
1147
        $receivedlist .= $_->{'serialseq'} . "; ";
1148
    }
1149
    $receivedlist =~ s/; $//;
1150
    my $query = qq{
1151
        UPDATE subscriptionhistory
1152
        SET recievedlist = ?
1153
        WHERE subscriptionid = ?
1154
    };
1155
    my $sth = $dbh->prepare($query);
1156
    $sth->execute($receivedlist, $subscriptionid);
1157
}
1158
1097
=head2 ModSerialStatus
1159
=head2 ModSerialStatus
1098
1160
1099
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes)
1161
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes)
Lines 1106-1127 Note : if we change from "waited" to something else,then we will have to create Link Here
1106
sub ModSerialStatus {
1168
sub ModSerialStatus {
1107
    my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
1169
    my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
1108
1170
1171
1109
    #It is a usual serial
1172
    #It is a usual serial
1110
    # 1st, get previous status :
1173
    # 1st, get previous status :
1111
    my $dbh   = C4::Context->dbh;
1174
    my $dbh   = C4::Context->dbh;
1112
    my $query = "SELECT subscriptionid,status FROM serial WHERE  serialid=?";
1175
    my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity
1176
        FROM serial, subscription
1177
        WHERE serial.subscriptionid=subscription.subscriptionid
1178
            AND serialid=?";
1113
    my $sth   = $dbh->prepare($query);
1179
    my $sth   = $dbh->prepare($query);
1114
    $sth->execute($serialid);
1180
    $sth->execute($serialid);
1115
    my ( $subscriptionid, $oldstatus ) = $sth->fetchrow;
1181
    my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow;
1182
    my $frequency = GetSubscriptionFrequency($periodicity);
1116
1183
1117
    # change status & update subscriptionhistory
1184
    # change status & update subscriptionhistory
1118
    my $val;
1185
    my $val;
1119
    if ( $status == 6 ) {
1186
    if ( $status == 6 ) {
1120
        DelIssue( {'serialid'=>$serialid, 'subscriptionid'=>$subscriptionid,'serialseq'=>$serialseq} );
1187
        DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } );
1121
    }
1188
    } else {
1122
    else {
1189
1123
        my $query =
1190
        unless ($frequency->{'unit'}) {
1124
'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?';
1191
            if ( not $planneddate or $planneddate eq '0000-00-00' ) { $planneddate = C4::Dates->new()->output('iso') };
1192
            if ( not $publisheddate or $publisheddate eq '0000-00-00' ) { $publisheddate = C4::Dates->new()->output('iso') };
1193
        }
1194
        my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?';
1125
        $sth = $dbh->prepare($query);
1195
        $sth = $dbh->prepare($query);
1126
        $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid );
1196
        $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid );
1127
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1197
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
Lines 1129-1186 sub ModSerialStatus { Link Here
1129
        $sth->execute($subscriptionid);
1199
        $sth->execute($subscriptionid);
1130
        my $val = $sth->fetchrow_hashref;
1200
        my $val = $sth->fetchrow_hashref;
1131
        unless ( $val->{manualhistory} ) {
1201
        unless ( $val->{manualhistory} ) {
1132
            $query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE  subscriptionid=?";
1202
            if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) {
1133
            $sth   = $dbh->prepare($query);
1203
                  _update_receivedlist($subscriptionid);
1134
            $sth->execute($subscriptionid);
1135
            my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1136
            if ( $status == 2 ) {
1137
                $recievedlist .= "; $serialseq"
1138
                    if $recievedlist!~/(^|;)\s*$serialseq(?=;|$)/;
1139
            }
1204
            }
1140
            # in case serial has been previously marked as missing
1205
            if($status == 4 || $status == 5
1141
            if (grep /$status/, (1,2,3,7)) {
1206
              || ($oldstatus == 4 && $status != 4)
1142
                $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g;
1207
              || ($oldstatus == 5 && $status != 5)) {
1208
                _update_missinglist($subscriptionid);
1143
            }
1209
            }
1144
            $missinglist .= "; $serialseq"
1145
                if $status==4 && $missinglist!~/(^|;)\s*$serialseq(?=;|$)/;
1146
            $missinglist .= "; not issued $serialseq"
1147
                if $status==5 && $missinglist!~/(^|;)\s*$serialseq(?=;|$)/;
1148
1149
            $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
1150
            $sth   = $dbh->prepare($query);
1151
            $recievedlist =~ s/^; //;
1152
            $missinglist  =~ s/^; //;
1153
            $sth->execute( $recievedlist, $missinglist, $subscriptionid );
1154
        }
1210
        }
1155
    }
1211
    }
1156
1212
1157
    # create new waited entry if needed (ie : was a "waited" and has changed)
1213
    # create new waited entry if needed (ie : was a "waited" and has changed)
1158
    if ( $oldstatus == 1 && $status != 1 ) {
1214
    if ( $oldstatus == 1 && $status != 1 ) {
1159
        my $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1215
        my $subscription = GetSubscription($subscriptionid);
1160
        $sth = $dbh->prepare($query);
1216
        my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1161
        $sth->execute($subscriptionid);
1162
        my $val = $sth->fetchrow_hashref;
1163
1217
1164
        # next issue number
1218
        # next issue number
1165
        my (
1219
        my (
1166
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1220
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1167
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1221
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1168
        ) = GetNextSeq($val);
1222
          )
1223
          = GetNextSeq( $subscription, $pattern, $publisheddate );
1169
1224
1170
        # next date (calculated from actual date & frequency parameters)
1225
        # next date (calculated from actual date & frequency parameters)
1171
        my $nextpublisheddate = GetNextDate( $publisheddate, $val );
1226
        my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1);
1172
        NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate, $nextpublisheddate );
1227
        my $nextpubdate = $nextpublisheddate;
1228
        NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate );
1173
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1229
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1174
                    WHERE  subscriptionid = ?";
1230
                    WHERE  subscriptionid = ?";
1175
        $sth = $dbh->prepare($query);
1231
        $sth = $dbh->prepare($query);
1176
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1232
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1177
1233
1178
# check if an alert must be sent... (= a letter is defined & status became "arrived"
1234
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1179
        if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) {
1235
        if ( $subscription->{letter} && $status == 2 && $oldstatus != 2 ) {
1180
            require C4::Letters;
1236
            require C4::Letters;
1181
            C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} );
1237
            C4::Letters::SendAlerts( 'issue', $subscription->{subscriptionid}, $subscription->{letter} );
1182
        }
1238
        }
1183
    }
1239
    }
1240
1184
    return;
1241
    return;
1185
}
1242
}
1186
1243
Lines 1194-1224 returns a hashref: Link Here
1194
1251
1195
$nextexepected = {
1252
$nextexepected = {
1196
    serialid => int
1253
    serialid => int
1197
    planneddate => C4::Dates object
1254
    planneddate => ISO date
1198
    }
1255
    }
1199
1256
1200
=cut
1257
=cut
1201
1258
1202
sub GetNextExpected {
1259
sub GetNextExpected {
1203
    my ($subscriptionid) = @_;
1260
    my ($subscriptionid) = @_;
1204
    my $dbh              = C4::Context->dbh;
1261
1205
    my $sth              = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?');
1262
    my $dbh = C4::Context->dbh;
1263
    my $query = qq{
1264
        SELECT *
1265
        FROM serial
1266
        WHERE subscriptionid = ?
1267
          AND status = ?
1268
        LIMIT 1
1269
    };
1270
    my $sth = $dbh->prepare($query);
1206
1271
1207
    # Each subscription has only one 'expected' issue, with serial.status==1.
1272
    # Each subscription has only one 'expected' issue, with serial.status==1.
1208
    $sth->execute( $subscriptionid, 1 );
1273
    $sth->execute( $subscriptionid, 1 );
1209
    my ( $nextissue ) = $sth->fetchrow_hashref;
1274
    my $nextissue = $sth->fetchrow_hashref;
1210
    if( !$nextissue){
1275
    if ( !$nextissue ) {
1211
         $sth = $dbh->prepare('SELECT serialid,planneddate FROM serial WHERE subscriptionid  = ? ORDER BY planneddate DESC LIMIT 1');
1276
        $query = qq{
1212
         $sth->execute( $subscriptionid );  
1277
            SELECT *
1213
         $nextissue = $sth->fetchrow_hashref;       
1278
            FROM serial
1279
            WHERE subscriptionid = ?
1280
            ORDER BY publisheddate DESC
1281
            LIMIT 1
1282
        };
1283
        $sth = $dbh->prepare($query);
1284
        $sth->execute($subscriptionid);
1285
        $nextissue = $sth->fetchrow_hashref;
1214
    }
1286
    }
1215
    if (!defined $nextissue->{planneddate}) {
1287
    foreach(qw/planneddate publisheddate/) {
1216
        # or should this default to 1st Jan ???
1288
        if ( !defined $nextissue->{$_} ) {
1217
        $nextissue->{planneddate} = strftime('%Y-%m-%d',localtime);
1289
            # or should this default to 1st Jan ???
1290
            $nextissue->{$_} = strftime( '%Y-%m-%d', localtime );
1291
        }
1292
        $nextissue->{$_} = ($nextissue->{$_} ne '0000-00-00')
1293
                         ? $nextissue->{$_}
1294
                         : undef;
1218
    }
1295
    }
1219
    $nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso');
1220
    return $nextissue;
1221
1296
1297
    return $nextissue;
1222
}
1298
}
1223
1299
1224
=head2 ModNextExpected
1300
=head2 ModNextExpected
Lines 1228-1234 ModNextExpected($subscriptionid,$date) Link Here
1228
Update the planneddate for the current expected issue of the subscription.
1304
Update the planneddate for the current expected issue of the subscription.
1229
This will modify all future prediction results.  
1305
This will modify all future prediction results.  
1230
1306
1231
C<$date> is a C4::Dates object.
1307
C<$date> is an ISO date.
1232
1308
1233
returns 0
1309
returns 0
1234
1310
Lines 1242-1252 sub ModNextExpected { Link Here
1242
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1318
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1243
1319
1244
    # Each subscription has only one 'expected' issue, with serial.status==1.
1320
    # Each subscription has only one 'expected' issue, with serial.status==1.
1245
    $sth->execute( $date->output('iso'), $date->output('iso'), $subscriptionid, 1 );
1321
    $sth->execute( $date, $date, $subscriptionid, 1 );
1246
    return 0;
1322
    return 0;
1247
1323
1248
}
1324
}
1249
1325
1326
=head2 GetSubscriptionIrregularities
1327
1328
=over 4
1329
1330
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1331
get the list of irregularities for a subscription
1332
1333
=back
1334
1335
=cut
1336
1337
sub GetSubscriptionIrregularities {
1338
    my $subscriptionid = shift;
1339
1340
    return unless $subscriptionid;
1341
1342
    my $dbh = C4::Context->dbh;
1343
    my $query = qq{
1344
        SELECT irregularity
1345
        FROM subscription
1346
        WHERE subscriptionid = ?
1347
    };
1348
    my $sth = $dbh->prepare($query);
1349
    $sth->execute($subscriptionid);
1350
1351
    my ($result) = $sth->fetchrow_array;
1352
    my @irreg = split /;/, $result;
1353
1354
    return @irreg;
1355
}
1356
1250
=head2 ModSubscription
1357
=head2 ModSubscription
1251
1358
1252
this function modifies a subscription. Put all new values on input args.
1359
this function modifies a subscription. Put all new values on input args.
Lines 1255-1297 returns the number of rows affected Link Here
1255
=cut
1362
=cut
1256
1363
1257
sub ModSubscription {
1364
sub ModSubscription {
1258
    my ($auser,           $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $startdate,   $periodicity,   $firstacquidate,
1365
    my (
1259
        $dow,             $irregularity,    $numberpattern,     $numberlength,     $weeklength,    $monthlength, $add1,          $every1,
1366
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1260
        $whenmorethan1,   $setto1,          $lastvalue1,        $innerloop1,       $add2,          $every2,      $whenmorethan2, $setto2,
1367
    $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1261
        $lastvalue2,      $innerloop2,      $add3,              $every3,           $whenmorethan3, $setto3,      $lastvalue3,    $innerloop3,
1368
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1262
        $numberingmethod, $status,          $biblionumber,      $callnumber,       $notes,         $letter,      $hemisphere,    $manualhistory,
1369
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1263
        $internalnotes,   $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,    $enddate,       $subscriptionid
1370
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1371
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1372
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq
1264
    ) = @_;
1373
    ) = @_;
1265
1374
1266
    #     warn $irregularity;
1267
    my $dbh   = C4::Context->dbh;
1375
    my $dbh   = C4::Context->dbh;
1268
    my $query = "UPDATE subscription
1376
    my $query = "UPDATE subscription
1269
                    SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
1377
        SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?,
1270
                        periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?,
1378
            startdate=?, periodicity=?, firstacquidate=?, irregularity=?,
1271
                        add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
1379
            numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?,
1272
                        add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
1380
            lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?,
1273
                        add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
1381
            lastvalue3=?, innerloop3=?, status=?, biblionumber=?,
1274
                        numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, 
1382
            callnumber=?, notes=?, letter=?, manualhistory=?,
1275
						letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?,
1383
            internalnotes=?, serialsadditems=?, staffdisplaycount=?,
1276
						staffdisplaycount = ?,opacdisplaycount = ?, graceperiod = ?, location = ?
1384
            opacdisplaycount=?, graceperiod=?, location = ?, enddate=?,
1277
						,enddate=?
1385
            skip_serialseq=?
1278
                    WHERE subscriptionid = ?";
1386
        WHERE subscriptionid = ?";
1279
1387
1280
    #warn "query :".$query;
1281
    my $sth = $dbh->prepare($query);
1388
    my $sth = $dbh->prepare($query);
1282
    $sth->execute(
1389
    $sth->execute(
1283
        $auser,           $branchcode,     $aqbooksellerid, $cost,
1390
        $auser,           $branchcode,     $aqbooksellerid, $cost,
1284
        $aqbudgetid,      $startdate,      $periodicity,    $firstacquidate,
1391
        $aqbudgetid,      $startdate,      $periodicity,    $firstacquidate,
1285
        $dow,             "$irregularity", $numberpattern,  $numberlength,
1392
        $irregularity,    $numberpattern,  $locale,         $numberlength,
1286
        $weeklength,      $monthlength,    $add1,           $every1,
1393
        $weeklength,      $monthlength,    $lastvalue1,     $innerloop1,
1287
        $whenmorethan1,   $setto1,         $lastvalue1,     $innerloop1,
1394
        $lastvalue2,      $innerloop2,     $lastvalue3,     $innerloop3,
1288
        $add2,            $every2,         $whenmorethan2,  $setto2,
1395
        $status,          $biblionumber,   $callnumber,     $notes,
1289
        $lastvalue2,      $innerloop2,     $add3,           $every3,
1396
        $letter,          ($manualhistory ? $manualhistory : 0),
1290
        $whenmorethan3,   $setto3,         $lastvalue3,     $innerloop3,
1291
        $numberingmethod, $status,         $biblionumber,   $callnumber,
1292
        $notes, $letter, $hemisphere, ( $manualhistory ? $manualhistory : 0 ),
1293
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1397
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1294
        $graceperiod,   $location,        $enddate,           $subscriptionid
1398
        $graceperiod,     $location,       $enddate,        $skip_serialseq,
1399
        $subscriptionid
1295
    );
1400
    );
1296
    my $rows = $sth->rows;
1401
    my $rows = $sth->rows;
1297
1402
Lines 1303-1313 sub ModSubscription { Link Here
1303
1408
1304
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
1409
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
1305
    $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
1410
    $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
1306
    $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
1411
    $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3,
1307
    $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
1412
    $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern,
1308
    $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
1413
    $callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems,
1309
    $numberingmethod, $status, $notes, $serialsadditems,
1414
    $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq);
1310
    $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate);
1311
1415
1312
Create a new subscription with value given on input args.
1416
Create a new subscription with value given on input args.
1313
1417
Lines 1317-1358 the id of this new subscription Link Here
1317
=cut
1421
=cut
1318
1422
1319
sub NewSubscription {
1423
sub NewSubscription {
1320
    my ($auser,         $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $biblionumber, $startdate,       $periodicity,
1424
    my (
1321
        $dow,           $numberlength,    $weeklength,        $monthlength,      $add1,          $every1,       $whenmorethan1,   $setto1,
1425
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1322
        $lastvalue1,    $innerloop1,      $add2,              $every2,           $whenmorethan2, $setto2,       $lastvalue2,      $innerloop2,
1426
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1323
        $add3,          $every3,          $whenmorethan3,     $setto3,           $lastvalue3,    $innerloop3,   $numberingmethod, $status,
1427
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1324
        $notes,         $letter,          $firstacquidate,    $irregularity,     $numberpattern, $callnumber,   $hemisphere,      $manualhistory,
1428
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1325
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,     $enddate
1429
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1430
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1431
    $location, $enddate, $skip_serialseq
1326
    ) = @_;
1432
    ) = @_;
1327
    my $dbh = C4::Context->dbh;
1433
    my $dbh = C4::Context->dbh;
1328
1434
1329
    #save subscription (insert into database)
1435
    #save subscription (insert into database)
1330
    my $query = qq|
1436
    my $query = qq|
1331
        INSERT INTO subscription
1437
        INSERT INTO subscription
1332
            (librarian,branchcode,aqbooksellerid,cost,aqbudgetid,biblionumber,
1438
            (librarian, branchcode, aqbooksellerid, cost, aqbudgetid,
1333
            startdate,periodicity,dow,numberlength,weeklength,monthlength,
1439
            biblionumber, startdate, periodicity, numberlength, weeklength,
1334
            add1,every1,whenmorethan1,setto1,lastvalue1,innerloop1,
1440
            monthlength, lastvalue1, innerloop1, lastvalue2, innerloop2,
1335
            add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2,
1441
            lastvalue3, innerloop3, status, notes, letter, firstacquidate,
1336
            add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3,
1442
            irregularity, numberpattern, locale, callnumber,
1337
            numberingmethod, status, notes, letter,firstacquidate,irregularity,
1443
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1338
            numberpattern, callnumber, hemisphere,manualhistory,internalnotes,serialsadditems,
1444
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq)
1339
            staffdisplaycount,opacdisplaycount,graceperiod,location,enddate)
1445
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1340
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1341
        |;
1446
        |;
1342
    my $sth = $dbh->prepare($query);
1447
    my $sth = $dbh->prepare($query);
1343
    $sth->execute(
1448
    $sth->execute(
1344
        $auser,         $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $biblionumber, $startdate,       $periodicity,
1449
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1345
        $dow,           $numberlength,    $weeklength,        $monthlength,      $add1,          $every1,       $whenmorethan1,   $setto1,
1450
        $startdate, $periodicity, $numberlength, $weeklength,
1346
        $lastvalue1,    $innerloop1,      $add2,              $every2,           $whenmorethan2, $setto2,       $lastvalue2,      $innerloop2,
1451
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
1347
        $add3,          $every3,          $whenmorethan3,     $setto3,           $lastvalue3,    $innerloop3,   $numberingmethod, "$status",
1452
        $lastvalue3, $innerloop3, $status, $notes, $letter,
1348
        $notes,         $letter,          $firstacquidate,    $irregularity,     $numberpattern, $callnumber,   $hemisphere,      $manualhistory,
1453
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1349
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,     $enddate
1454
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1455
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq
1350
    );
1456
    );
1351
1457
1352
    my $subscriptionid = $dbh->{'mysql_insertid'};
1458
    my $subscriptionid = $dbh->{'mysql_insertid'};
1353
    unless ($enddate){
1459
    unless ($enddate) {
1354
       $enddate = GetExpirationDate($subscriptionid,$startdate);
1460
        $enddate = GetExpirationDate( $subscriptionid, $startdate );
1355
        $query = q|
1461
        $query = qq|
1356
            UPDATE subscription
1462
            UPDATE subscription
1357
            SET    enddate=?
1463
            SET    enddate=?
1358
            WHERE  subscriptionid=?
1464
            WHERE  subscriptionid=?
Lines 1360-1366 sub NewSubscription { Link Here
1360
        $sth = $dbh->prepare($query);
1466
        $sth = $dbh->prepare($query);
1361
        $sth->execute( $enddate, $subscriptionid );
1467
        $sth->execute( $enddate, $subscriptionid );
1362
    }
1468
    }
1363
    #then create the 1st waited number
1469
1470
    # then create the 1st expected number
1364
    $query = qq(
1471
    $query = qq(
1365
        INSERT INTO subscriptionhistory
1472
        INSERT INTO subscriptionhistory
1366
            (biblionumber, subscriptionid, histstartdate,  opacnote, librariannote)
1473
            (biblionumber, subscriptionid, histstartdate,  opacnote, librariannote)
Lines 1370-1386 sub NewSubscription { Link Here
1370
    $sth->execute( $biblionumber, $subscriptionid, $startdate, $notes, $internalnotes );
1477
    $sth->execute( $biblionumber, $subscriptionid, $startdate, $notes, $internalnotes );
1371
1478
1372
    # reread subscription to get a hash (for calculation of the 1st issue number)
1479
    # reread subscription to get a hash (for calculation of the 1st issue number)
1373
    $query = qq(
1480
    my $subscription = GetSubscription($subscriptionid);
1374
        SELECT *
1481
    my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1375
        FROM   subscription
1376
        WHERE  subscriptionid = ?
1377
    );
1378
    $sth = $dbh->prepare($query);
1379
    $sth->execute($subscriptionid);
1380
    my $val = $sth->fetchrow_hashref;
1381
1482
1382
    # calculate issue number
1483
    # calculate issue number
1383
    my $serialseq = GetSeq($val);
1484
    my $serialseq = GetSeq($subscription, $pattern);
1384
    $query = qq|
1485
    $query = qq|
1385
        INSERT INTO serial
1486
        INSERT INTO serial
1386
            (serialseq,subscriptionid,biblionumber,status, planneddate, publisheddate)
1487
            (serialseq,subscriptionid,biblionumber,status, planneddate, publisheddate)
Lines 1393-1399 sub NewSubscription { Link Here
1393
1494
1394
    #set serial flag on biblio if not already set.
1495
    #set serial flag on biblio if not already set.
1395
    my $bib = GetBiblio($biblionumber);
1496
    my $bib = GetBiblio($biblionumber);
1396
    if ( !$bib->{'serial'} ) {
1497
    if ( $bib and !$bib->{'serial'} ) {
1397
        my $record = GetMarcBiblio($biblionumber);
1498
        my $record = GetMarcBiblio($biblionumber);
1398
        my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
1499
        my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
1399
        if ($tag) {
1500
        if ($tag) {
Lines 1711-1717 sub HasSubscriptionExpired { Link Here
1711
    my ($subscriptionid) = @_;
1812
    my ($subscriptionid) = @_;
1712
    my $dbh              = C4::Context->dbh;
1813
    my $dbh              = C4::Context->dbh;
1713
    my $subscription     = GetSubscription($subscriptionid);
1814
    my $subscription     = GetSubscription($subscriptionid);
1714
    if ( ( $subscription->{periodicity} % 16 ) > 0 ) {
1815
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
1816
    if ( $frequency and $frequency->{unit} ) {
1715
        my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid);
1817
        my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid);
1716
        if (!defined $expirationdate) {
1818
        if (!defined $expirationdate) {
1717
            $expirationdate = q{};
1819
            $expirationdate = q{};
Lines 1735-1740 sub HasSubscriptionExpired { Link Here
1735
            || ( !$res ) );
1837
            || ( !$res ) );
1736
        return 0;
1838
        return 0;
1737
    } else {
1839
    } else {
1840
        # Irregular
1738
        if ( $subscription->{'numberlength'} ) {
1841
        if ( $subscription->{'numberlength'} ) {
1739
            my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} );
1842
            my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} );
1740
            return 1 if ( $countreceived > $subscription->{'numberlength'} );
1843
            return 1 if ( $countreceived > $subscription->{'numberlength'} );
Lines 2226-2254 sub abouttoexpire { Link Here
2226
    my $dbh              = C4::Context->dbh;
2329
    my $dbh              = C4::Context->dbh;
2227
    my $subscription     = GetSubscription($subscriptionid);
2330
    my $subscription     = GetSubscription($subscriptionid);
2228
    my $per = $subscription->{'periodicity'};
2331
    my $per = $subscription->{'periodicity'};
2229
    if ($per && $per % 16 > 0){
2332
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($per);
2230
        my $expirationdate   = GetExpirationDate($subscriptionid);
2333
    if ($frequency and $frequency->{unit}){
2334
        my $expirationdate = GetExpirationDate($subscriptionid);
2231
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2335
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2232
        my @res;
2336
        my $nextdate = GetNextDate($subscription, $res);
2233
        if (defined $res) {
2337
        if(Date::Calc::Delta_Days(
2234
            @res=split (/-/,$res);
2338
            split( /-/, $nextdate ),
2235
            @res=Date::Calc::Today if ($res[0]*$res[1]==0);
2339
            split( /-/, $expirationdate )
2236
        } else { # default an undefined value
2340
        ) <= 0) {
2237
            @res=Date::Calc::Today;
2341
            return 1;
2238
        }
2342
        }
2239
        my @endofsubscriptiondate=split(/-/,$expirationdate);
2240
        my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 124, 0, 0);
2241
        my @datebeforeend;
2242
        @datebeforeend = Add_Delta_Days(  $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2],
2243
            - (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]);
2244
        return 1 if ( @res &&
2245
            (@datebeforeend &&
2246
                Delta_Days($res[0],$res[1],$res[2],
2247
                    $datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) <= 0) &&
2248
            (@endofsubscriptiondate &&
2249
                Delta_Days($res[0],$res[1],$res[2],
2250
                    $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) >= 0) );
2251
        return 0;
2252
    } elsif ($subscription->{numberlength}>0) {
2343
    } elsif ($subscription->{numberlength}>0) {
2253
        return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1);
2344
        return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1);
2254
    }
2345
    }
Lines 2299-2468 sub GetSubscriptionsFromBorrower { Link Here
2299
    return ( $count, @routinglist );
2390
    return ( $count, @routinglist );
2300
}
2391
}
2301
2392
2302
=head2 GetNextDate
2303
2304
$resultdate = GetNextDate($planneddate,$subscription)
2305
2393
2306
this function it takes the planneddate and will return the next issue's date and will skip dates if there
2394
=head2 GetFictiveIssueNumber
2307
exists an irregularity
2308
- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be 
2309
skipped then the returned date will be 2007-05-10
2310
2395
2311
return :
2396
$issueno = GetFictiveIssueNumber($subscription, $publishedate);
2312
$resultdate - then next date in the sequence
2313
2397
2314
Return 0 if periodicity==0
2398
Get the position of the issue published at $publisheddate, considering the
2399
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
2400
This issuenumber doesn't take into account irregularities, so, for instance, if the 3rd
2401
issue is declared as 'irregular' (will be skipped at receipt), the next issue number
2402
will be 4, not 3. It's why it is called 'fictive'. It is NOT a serial seq, and is not
2403
depending on how many rows are in serial table.
2404
The issue number calculation is based on subscription frequency, first acquisition
2405
date, and $publisheddate.
2315
2406
2316
=cut
2407
=cut
2317
2408
2318
sub GetNextDate {
2409
sub GetFictiveIssueNumber {
2319
    my ( $planneddate, $subscription ) = @_;
2410
    my ($subscription, $publisheddate) = @_;
2320
    my @irreg = split( /\,/, $subscription->{irregularity} );
2411
2412
    my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
2413
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2414
    my $issueno = 0;
2415
2416
    if($unit) {
2417
        my ($year, $month, $day) = split /-/, $publisheddate;
2418
        my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'};
2419
        my $wkno;
2420
        my $delta;
2421
2422
        if($unit eq 'day') {
2423
            $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day);
2424
        } elsif($unit eq 'week') {
2425
            ($wkno, $year) = Week_of_Year($year, $month, $day);
2426
            my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day);
2427
            $delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2428
        } elsif($unit eq 'month') {
2429
            $delta = ($fa_year == $year)
2430
                   ? ($month - $fa_month)
2431
                   : ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) );
2432
        } elsif($unit eq 'year') {
2433
            $delta = $year - $fa_year;
2434
        }
2435
        if($frequency->{'unitsperissue'} == 1) {
2436
            $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
2437
        } else {
2438
            # Assuming issuesperunit == 1
2439
            $issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} );
2440
        }
2441
    }
2442
    return $issueno;
2443
}
2321
2444
2322
    #date supposed to be in ISO.
2445
=head2 GetNextDate
2323
2446
2324
    my ( $year, $month, $day ) = split( /-/, $planneddate );
2447
$resultdate = GetNextDate($publisheddate,$subscription)
2325
    $month = 1 unless ($month);
2326
    $day   = 1 unless ($day);
2327
    my @resultdate;
2328
2448
2329
    #       warn "DOW $dayofweek";
2449
this function it takes the publisheddate and will return the next issue's date
2330
    if ( $subscription->{periodicity} % 16 == 0 ) {    # 'without regularity' || 'irregular'
2450
and will skip dates if there exists an irregularity.
2331
        return 0;
2451
$publisheddate has to be an ISO date
2332
    }
2452
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit'
2453
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2454
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2455
skipped then the returned date will be 2007-05-10
2333
2456
2334
    #   daily : n / week
2457
return :
2335
    #   Since we're interpreting irregularity here as which days of the week to skip an issue,
2458
$resultdate - then next date in the sequence (ISO date)
2336
    #   renaming this pattern from 1/day to " n / week ".
2337
    if ( $subscription->{periodicity} == 1 ) {
2338
        my $dayofweek = eval { Day_of_Week( $year, $month, $day ) };
2339
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2340
        else {
2341
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2342
                $dayofweek = 0 if ( $dayofweek == 7 );
2343
                if ( in_array( ( $dayofweek + 1 ), @irreg ) ) {
2344
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 1 );
2345
                    $dayofweek++;
2346
                }
2347
            }
2348
            @resultdate = Add_Delta_Days( $year, $month, $day, 1 );
2349
        }
2350
    }
2351
2459
2352
    #   1  week
2460
Return $publisheddate if subscription is irregular
2353
    if ( $subscription->{periodicity} == 2 ) {
2354
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2355
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2356
        else {
2357
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2358
2461
2359
                #FIXME: if two consecutive irreg, do we only skip one?
2462
=cut
2360
                if ( $irreg[$i] == ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ) ) {
2361
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 7 );
2362
                    $wkno = ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 );
2363
                }
2364
            }
2365
            @resultdate = Add_Delta_Days( $year, $month, $day, 7 );
2366
        }
2367
    }
2368
2463
2369
    #   1 / 2 weeks
2464
sub GetNextDate {
2370
    if ( $subscription->{periodicity} == 3 ) {
2465
    my ( $subscription, $publisheddate, $updatecount ) = @_;
2371
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2466
2372
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2467
    my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'});
2373
        else {
2468
2374
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2469
    if ($freqdata->{'unit'}) {
2375
                if ( $irreg[$i] == ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ) ) {
2470
        my ( $year, $month, $day ) = split /-/, $publisheddate;
2376
                    ### BUGFIX was previously +1 ^
2471
2377
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 14 );
2472
        # Process an irregularity Hash
2378
                    $wkno = ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 );
2473
        # Suppose that irregularities are stored in a string with this structure
2379
                }
2474
        # irreg1;irreg2;irreg3
2380
            }
2475
        # where irregX is the number of issue which will not be received
2381
            @resultdate = Add_Delta_Days( $year, $month, $day, 14 );
2476
        # (the first issue takes the number 1, the 2nd the number 2 and so on)
2477
        my @irreg = split /;/, $subscription->{'irregularity'} ;
2478
        my %irregularities;
2479
        foreach my $irregularity (@irreg) {
2480
            $irregularities{$irregularity} = 1;
2382
        }
2481
        }
2383
    }
2384
2482
2385
    #   1 / 3 weeks
2483
        # Get the 'fictive' next issue number
2386
    if ( $subscription->{periodicity} == 4 ) {
2484
        # It is used to check if next issue is an irregular issue.
2387
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2485
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1;
2388
        if ($@) { warn "année mois jour : $year $month $day $subscription->{subscriptionid} : $@"; }
2486
2389
        else {
2487
        # Then get the next date
2390
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2488
        my $unit = lc $freqdata->{'unit'};
2391
                if ( $irreg[$i] == ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ) ) {
2489
        if ($unit eq 'day') {
2392
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 21 );
2490
            while ($irregularities{$issueno}) {
2393
                    $wkno = ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 );
2491
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2492
                    ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{'unitsperissue'} );
2493
                    $subscription->{'countissuesperunit'} = 1;
2494
                } else {
2495
                    $subscription->{'countissuesperunit'}++;
2394
                }
2496
                }
2497
                $issueno++;
2498
            }
2499
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2500
                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{"unitsperissue"} );
2501
                $subscription->{'countissuesperunit'} = 1;
2502
            } else {
2503
                $subscription->{'countissuesperunit'}++;
2395
            }
2504
            }
2396
            @resultdate = Add_Delta_Days( $year, $month, $day, 21 );
2397
        }
2505
        }
2398
    }
2506
        elsif ($unit eq 'week') {
2399
    my $tmpmonth = $month;
2507
            my ($wkno, $yr) = Week_of_Year($year, $month, $day);
2400
    if ( $year && $month && $day ) {
2508
            while ($irregularities{$issueno}) {
2401
        if ( $subscription->{periodicity} == 5 ) {
2509
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2402
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2510
                    $subscription->{'countissuesperunit'} = 1;
2403
                if ( $irreg[$i] == ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ) ) {
2511
                    $wkno += $freqdata->{"unitsperissue"};
2404
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 );
2512
                    if($wkno > 52){
2405
                    $tmpmonth = ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 );
2513
                        $wkno = $wkno % 52;
2514
                        $yr++;
2515
                    }
2516
                    my $dow = Day_of_Week($year, $month, $day);
2517
                    ($year,$month,$day) = Monday_of_Week($wkno, $yr);
2518
                    if($freqdata->{'issuesperunit'} == 1) {
2519
                        ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1);
2520
                    }
2521
                } else {
2522
                    $subscription->{'countissuesperunit'}++;
2406
                }
2523
                }
2524
                $issueno++;
2407
            }
2525
            }
2408
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 );
2526
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2409
        }
2527
                $subscription->{'countissuesperunit'} = 1;
2410
        if ( $subscription->{periodicity} == 6 ) {
2528
                $wkno += $freqdata->{"unitsperissue"};
2411
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2529
                if($wkno > 52){
2412
                if ( $irreg[$i] == ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ) ) {
2530
                    $wkno = $wkno % 52 ;
2413
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 );
2531
                    $yr++;
2414
                    $tmpmonth = ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 );
2532
                }
2533
                my $dow = Day_of_Week($year, $month, $day);
2534
                ($year,$month,$day) = Monday_of_Week($wkno, $yr);
2535
                if($freqdata->{'issuesperunit'} == 1) {
2536
                    ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1);
2415
                }
2537
                }
2538
            } else {
2539
                $subscription->{'countissuesperunit'}++;
2416
            }
2540
            }
2417
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 );
2418
        }
2541
        }
2419
        if ( $subscription->{periodicity} == 7 ) {
2542
        elsif ($unit eq 'month') {
2420
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2543
            while ($irregularities{$issueno}) {
2421
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2544
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2422
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2545
                    $subscription->{'countissuesperunit'} = 1;
2423
                    $tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 );
2546
                    ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2547
                    unless($freqdata->{'issuesperunit'} == 1) {
2548
                        $day = 1;   # Jumping to the first day of month, because we don't know what day is expected
2549
                    }
2550
                } else {
2551
                    $subscription->{'countissuesperunit'}++;
2424
                }
2552
                }
2553
                $issueno++;
2425
            }
2554
            }
2426
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2555
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2427
        }
2556
                $subscription->{'countissuesperunit'} = 1;
2428
        if ( $subscription->{periodicity} == 8 ) {
2557
                ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2429
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2558
                unless($freqdata->{'issuesperunit'} == 1) {
2430
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2559
                    $day = 1;   # Jumping to the first day of month, because we don't know what day is expected
2431
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2432
                    $tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 );
2433
                }
2560
                }
2561
            } else {
2562
                $subscription->{'countissuesperunit'}++;
2434
            }
2563
            }
2435
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2436
        }
2564
        }
2437
        if ( $subscription->{periodicity} == 13 ) {
2565
        elsif ($unit eq 'year') {
2438
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2566
            while ($irregularities{$issueno}) {
2439
                if ( $irreg[$i] == ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ) ) {
2567
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2440
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
2568
                    $subscription->{'countissuesperunit'} = 1;
2441
                    $tmpmonth = ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 );
2569
                    ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0);
2570
                    unless($freqdata->{'issuesperunit'} == 1) {
2571
                        # Jumping to the first day of year, because we don't know what day is expected
2572
                        $month = 1;
2573
                        $day = 1;
2574
                    }
2575
                } else {
2576
                    $subscription->{'countissuesperunit'}++;
2442
                }
2577
                }
2578
                $issueno++;
2443
            }
2579
            }
2444
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
2580
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2445
        }
2581
                $subscription->{'countissuesperunit'} = 1;
2446
        if ( $subscription->{periodicity} == 9 ) {
2582
                ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0);
2447
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2583
                unless($freqdata->{'issuesperunit'} == 1) {
2448
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2584
                    # Jumping to the first day of year, because we don't know what day is expected
2449
                    ### BUFIX Seems to need more Than One ?
2585
                    $month = 1;
2450
                    ( $year, $month, $day ) = Add_Delta_YM( $year, $month, $day, 0, 6 );
2586
                    $day = 1;
2451
                    $tmpmonth = ( ( $tmpmonth != 6 ) ? ( $tmpmonth + 6 ) % 12 : 12 );
2452
                }
2587
                }
2588
            } else {
2589
                $subscription->{'countissuesperunit'}++;
2453
            }
2590
            }
2454
            @resultdate = Add_Delta_YM( $year, $month, $day, 0, 6 );
2455
        }
2456
        if ( $subscription->{periodicity} == 10 ) {
2457
            @resultdate = Add_Delta_YM( $year, $month, $day, 1, 0 );
2458
        }
2591
        }
2459
        if ( $subscription->{periodicity} == 11 ) {
2592
        if ($updatecount){
2460
            @resultdate = Add_Delta_YM( $year, $month, $day, 2, 0 );
2593
            my $dbh = C4::Context->dbh;
2594
            my $query = qq{
2595
                UPDATE subscription
2596
                SET countissuesperunit = ?
2597
                WHERE subscriptionid = ?
2598
            };
2599
            my $sth = $dbh->prepare($query);
2600
            $sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'});
2461
        }
2601
        }
2602
        return sprintf("%04d-%02d-%02d", $year, $month, $day);
2603
    }
2604
    else {
2605
        return $publisheddate;
2462
    }
2606
    }
2463
    my $resultdate = sprintf( "%04d-%02d-%02d", $resultdate[0], $resultdate[1], $resultdate[2] );
2607
}
2608
2609
=head2 _numeration
2610
2611
  $string = &_numeration($value,$num_type,$locale);
2464
2612
2465
    return "$resultdate";
2613
_numeration returns the string corresponding to $value in the num_type
2614
num_type can take :
2615
    -dayname
2616
    -monthname
2617
    -season
2618
=cut
2619
2620
#'
2621
2622
sub _numeration {
2623
    my ($value, $num_type, $locale) = @_;
2624
    $value ||= 0;
2625
    my $initlocale = setlocale(LC_TIME);
2626
    if($locale and $locale ne $initlocale) {
2627
        $locale = setlocale(LC_TIME, $locale);
2628
    }
2629
    $locale ||= $initlocale;
2630
    my $string;
2631
    $num_type //= '';
2632
    given ($num_type) {
2633
        when (/^dayname$/) {
2634
              $value = $value % 7;
2635
              $string = POSIX::strftime("%A",0,0,0,0,0,0,$value);
2636
        }
2637
        when (/^monthname$/) {
2638
              $value = $value % 12;
2639
              $string = POSIX::strftime("%B",0,0,0,1,$value,0,0,0,0);
2640
        }
2641
        when (/^season$/) {
2642
              my $seasonlocale = ($locale)
2643
                               ? (substr $locale,0,2)
2644
                               : "en";
2645
              my %seasons=(
2646
                 "en" =>
2647
                    [qw(Spring Summer Fall Winter)],
2648
                 "fr"=>
2649
                    [qw(Printemps Été Automne Hiver)],
2650
              );
2651
              $value = $value % 4;
2652
              $string = ($seasons{$seasonlocale})
2653
                      ? $seasons{$seasonlocale}->[$value]
2654
                      : $seasons{'en'}->[$value];
2655
        }
2656
        default {
2657
            $string = $value;
2658
        }
2659
    }
2660
    if($locale ne $initlocale) {
2661
        setlocale(LC_TIME, $initlocale);
2662
    }
2663
    return $string;
2466
}
2664
}
2467
2665
2468
=head2 is_barcode_in_use
2666
=head2 is_barcode_in_use
(-)a/C4/Serials/Frequency.pm (+292 lines)
Line 0 Link Here
1
package C4::Serials::Frequency;
2
3
# Copyright 2000-2002 Biblibre SARL
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use C4::Context;
24
25
use vars qw($VERSION @ISA @EXPORT);
26
27
BEGIN {
28
    # set the version for version checking
29
    $VERSION = 3.01;
30
    require Exporter;
31
    @ISA    = qw(Exporter);
32
    @EXPORT = qw(
33
      &GetSubscriptionFrequencies
34
      &GetSubscriptionFrequency
35
      &AddSubscriptionFrequency
36
      &ModSubscriptionFrequency
37
      &DelSubscriptionFrequency
38
39
      &GetSubscriptionsWithFrequency
40
    );
41
}
42
43
44
=head1 NAME
45
46
C4::Serials::Frequency - Serials Frequency module
47
48
=head1 FUNCTIONS
49
50
=head2 GetSubscriptionFrequencies
51
52
=over 4
53
54
=item C<@frequencies> = &GetSubscriptionFrequencies();
55
56
gets frequencies restricted on filters
57
58
=back
59
60
=cut
61
62
sub GetSubscriptionFrequencies {
63
    my $dbh = C4::Context->dbh;
64
    my $query = qq{
65
        SELECT *
66
        FROM subscription_frequencies
67
        ORDER BY displayorder
68
    };
69
    my $sth = $dbh->prepare($query);
70
    $sth->execute();
71
72
    my $results = $sth->fetchall_arrayref( {} );
73
    return @$results;
74
}
75
76
=head2 GetSubscriptionFrequency
77
78
=over 4
79
80
=item $frequency = &GetSubscriptionFrequency($frequencyid);
81
82
gets frequency where $frequencyid is the identifier
83
84
=back
85
86
=cut
87
88
sub GetSubscriptionFrequency {
89
    my ($frequencyid) = @_;
90
91
    my $dbh = C4::Context->dbh;
92
    my $query = qq{
93
        SELECT *
94
        FROM subscription_frequencies
95
        WHERE id = ?
96
    };
97
    my $sth = $dbh->prepare($query);
98
    $sth->execute($frequencyid);
99
100
    return $sth->fetchrow_hashref;
101
}
102
103
=head2 AddSubscriptionFrequency
104
105
=over 4
106
107
=item C<$frequencyid> = &AddSubscriptionFrequency($frequency);
108
109
Add a new frequency
110
111
=item C<$frequency> is a hashref that can contains the following keys
112
113
=over 2
114
115
=item * description
116
117
=item * unit
118
119
=item * issuesperunit
120
121
=item * unitsperissue
122
123
=item * expectedissuesayear
124
125
=item * displayorder
126
127
=back
128
129
Only description is mandatory.
130
131
=back
132
133
=cut
134
135
sub AddSubscriptionFrequency {
136
    my $frequency = shift;
137
138
    unless(ref($frequency) eq 'HASH' && defined $frequency->{'description'} && $frequency->{'description'} ne '') {
139
        return;
140
    }
141
142
    my @keys;
143
    my @values;
144
    foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
145
        if(exists $frequency->{$_}) {
146
            push @keys, $_;
147
            push @values, $frequency->{$_};
148
        }
149
    }
150
151
    my $dbh = C4::Context->dbh;
152
    my $query = "INSERT INTO subscription_frequencies";
153
    $query .= '(' . join(',', @keys) . ')';
154
    $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
155
    my $sth = $dbh->prepare($query);
156
    my $rv = $sth->execute(@values);
157
158
    if(defined $rv) {
159
        return $dbh->last_insert_id(undef, undef, "subscription_frequencies", undef);
160
    }
161
162
    return $rv;
163
}
164
165
=head2 ModSubscriptionFrequency
166
167
=over 4
168
169
=item &ModSubscriptionFrequency($frequency);
170
171
Modifies a frequency
172
173
=item C<$frequency> is a hashref that can contains the following keys
174
175
=over 2
176
177
=item * id
178
179
=item * description
180
181
=item * unit
182
183
=item * issuesperunit
184
185
=item * unitsperissue
186
187
=item * expectedissuesayear
188
189
=item * displayorder
190
191
=back
192
193
Only id is mandatory.
194
195
=back
196
197
=cut
198
199
sub ModSubscriptionFrequency {
200
    my $frequency = shift;
201
202
    unless(
203
      ref($frequency) eq 'HASH'
204
      && defined $frequency->{'id'} && $frequency->{'id'} > 0
205
      && (
206
        (defined $frequency->{'description'}
207
        && $frequency->{'description'} ne '')
208
        || !defined $frequency->{'description'}
209
      )
210
    ) {
211
        return;
212
    }
213
214
    my @keys;
215
    my @values;
216
    foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
217
        if(exists $frequency->{$_}) {
218
            push @keys, $_;
219
            push @values, $frequency->{$_};
220
        }
221
    }
222
223
    my $dbh = C4::Context->dbh;
224
    my $query = "UPDATE subscription_frequencies";
225
    $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
226
    $query .= ' WHERE id = ?';
227
    my $sth = $dbh->prepare($query);
228
229
    return $sth->execute(@values, $frequency->{'id'});
230
}
231
232
=head2 DelSubscriptionFrequency
233
234
=over 4
235
236
=item &DelSubscriptionFrequency($frequencyid);
237
238
Delete a frequency
239
240
=back
241
242
=cut
243
244
sub DelSubscriptionFrequency {
245
    my $frequencyid = shift;
246
247
    my $dbh = C4::Context->dbh;
248
    my $query = qq{
249
        DELETE FROM subscription_frequencies
250
        WHERE id = ?
251
    };
252
    my $sth = $dbh->prepare($query);
253
    $sth->execute($frequencyid);
254
}
255
256
=head2 GetSubscriptionsWithFrequency
257
258
    my @subs = GetSubscriptionsWithFrequency($frequencyid);
259
260
Returns all subscriptions that are using a particular frequency
261
262
=cut
263
264
sub GetSubscriptionsWithFrequency {
265
    my ($frequencyid) = @_;
266
267
    return unless $frequencyid;
268
269
    my $dbh = C4::Context->dbh;
270
    my $query = qq{
271
        SELECT *
272
        FROM subscription
273
          LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber
274
        WHERE periodicity = ?
275
    };
276
    my $sth = $dbh->prepare($query);
277
    my @results;
278
    if ($sth->execute($frequencyid)) {
279
        @results = @{ $sth->fetchall_arrayref({}) };
280
    }
281
    return @results;
282
}
283
284
1;
285
286
__END__
287
288
=head1 AUTHOR
289
290
Koha Developement team <info@koha.org>
291
292
=cut
(-)a/C4/Serials/Numberpattern.pm (+289 lines)
Line 0 Link Here
1
package C4::Serials::Numberpattern;
2
3
# Copyright 2000-2002 Biblibre SARL
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use C4::Context;
24
25
use vars qw($VERSION @ISA @EXPORT);
26
27
BEGIN {
28
29
    # set the version for version checking
30
    $VERSION = 3.01;
31
    require Exporter;
32
    @ISA    = qw(Exporter);
33
    @EXPORT = qw(
34
        &GetSubscriptionNumberpatterns
35
        &GetSubscriptionNumberpattern
36
        &GetSubscriptionNumberpatternByName
37
        &AddSubscriptionNumberpattern
38
        &ModSubscriptionNumberpattern
39
        &DelSubscriptionNumberpattern
40
41
        &GetSubscriptionsWithNumberpattern
42
    );
43
}
44
45
46
=head1 NAME
47
48
C4::Serials::Numberpattern - Serials numbering pattern module
49
50
=head1 FUNCTIONS
51
52
=head2 GetSubscriptionNumberpatterns
53
54
@results = GetSubscriptionNumberpatterns;
55
this function get all subscription number patterns entered in table
56
57
=cut
58
59
sub GetSubscriptionNumberpatterns {
60
    my $dbh = C4::Context->dbh;
61
    my $query = qq{
62
        SELECT *
63
        FROM subscription_numberpatterns
64
        ORDER by displayorder
65
    };
66
    my $sth = $dbh->prepare($query);
67
    $sth->execute;
68
    my $results = $sth->fetchall_arrayref({});
69
70
    return @$results;
71
}
72
73
=head2 GetSubscriptionNumberpattern
74
75
$result = GetSubscriptionNumberpattern($numberpatternid);
76
this function get the data of the subscription numberpatterns which id is $numberpatternid
77
78
=cut
79
80
sub GetSubscriptionNumberpattern {
81
    my $numberpatternid = shift;
82
    my $dbh = C4::Context->dbh;
83
    my $query = qq(
84
        SELECT *
85
        FROM subscription_numberpatterns
86
        WHERE id = ?
87
    );
88
    my $sth = $dbh->prepare($query);
89
    $sth->execute($numberpatternid);
90
91
    return $sth->fetchrow_hashref;
92
}
93
94
=head2 GetSubscriptionNumberpatternByName
95
96
$result = GetSubscriptionNumberpatternByName($name);
97
this function get the data of the subscription numberpatterns which name is $name
98
99
=cut
100
101
sub GetSubscriptionNumberpatternByName {
102
    my $name = shift;
103
    my $dbh = C4::Context->dbh;
104
    my $query = qq(
105
        SELECT *
106
        FROM subscription_numberpatterns
107
        WHERE label = ?
108
    );
109
    my $sth = $dbh->prepare($query);
110
    my $rv = $sth->execute($name);
111
112
    return $sth->fetchrow_hashref;
113
}
114
115
=head2 AddSubscriptionNumberpattern
116
117
=over 4
118
119
=item C<$numberpatternid> = &AddSubscriptionNumberpattern($numberpattern)
120
121
Add a new numberpattern
122
123
=item C<$frequency> is a hashref that contains values of the number pattern
124
125
=item Only label and numberingmethod are mandatory
126
127
=back
128
129
=cut
130
131
sub AddSubscriptionNumberpattern {
132
    my $numberpattern = shift;
133
134
    unless(
135
      ref($numberpattern) eq 'HASH'
136
      && defined $numberpattern->{'label'}
137
      && $numberpattern->{'label'} ne ''
138
      && defined $numberpattern->{'numberingmethod'}
139
      && $numberpattern->{'numberingmethod'} ne ''
140
    ) {
141
        return;
142
    }
143
144
    my @keys;
145
    my @values;
146
    foreach (qw/ label description numberingmethod displayorder
147
      label1 label2 label3 add1 add2 add3 every1 every2 every3
148
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
149
      numbering1 numbering2 numbering3 /) {
150
        if(exists $numberpattern->{$_}) {
151
            push @keys, $_;
152
            push @values, $numberpattern->{$_};
153
        }
154
    }
155
156
    my $dbh = C4::Context->dbh;
157
    my $query = "INSERT INTO subscription_numberpatterns";
158
    $query .= '(' . join(',', @keys) . ')';
159
    $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
160
    my $sth = $dbh->prepare($query);
161
    my $rv = $sth->execute(@values);
162
163
    if(defined $rv) {
164
        return $dbh->last_insert_id(undef, undef, "subscription_numberpatterns", undef);
165
    }
166
167
    return $rv;
168
}
169
170
=head2 ModSubscriptionNumberpattern
171
172
=over 4
173
174
=item &ModSubscriptionNumberpattern($numberpattern)
175
176
Modifies a numberpattern
177
178
=item C<$frequency> is a hashref that contains values of the number pattern
179
180
=item Only id is mandatory
181
182
=back
183
184
=cut
185
186
sub ModSubscriptionNumberpattern {
187
    my $numberpattern = shift;
188
189
    unless(
190
      ref($numberpattern) eq 'HASH'
191
      && defined $numberpattern->{'id'}
192
      && $numberpattern->{'id'} > 0
193
      && (
194
        (defined $numberpattern->{'label'}
195
        && $numberpattern->{'label'} ne '')
196
        || !defined $numberpattern->{'label'}
197
      )
198
      && (
199
        (defined $numberpattern->{'numberingmethod'}
200
        && $numberpattern->{'numberingmethod'} ne '')
201
        || !defined $numberpattern->{'numberingmethod'}
202
      )
203
    ) {
204
        return;
205
    }
206
207
    my @keys;
208
    my @values;
209
    foreach (qw/ label description numberingmethod displayorder
210
      label1 label2 label3 add1 add2 add3 every1 every2 every3
211
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
212
      numbering1 numbering2 numbering3 /) {
213
        if(exists $numberpattern->{$_}) {
214
            push @keys, $_;
215
            push @values, $numberpattern->{$_};
216
        }
217
    }
218
219
    my $dbh = C4::Context->dbh;
220
    my $query = "UPDATE subscription_numberpatterns";
221
    $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
222
    $query .= ' WHERE id = ?';
223
    my $sth = $dbh->prepare($query);
224
225
    return $sth->execute(@values, $numberpattern->{'id'});
226
}
227
228
=head2 DelSubscriptionNumberpattern
229
230
=over 4
231
232
=item &DelSubscriptionNumberpattern($numberpatternid)
233
234
Delete a number pattern
235
236
=back
237
238
=cut
239
240
sub DelSubscriptionNumberpattern {
241
    my $numberpatternid = shift;
242
243
    my $dbh = C4::Context->dbh;
244
    my $query = qq{
245
        DELETE FROM subscription_numberpatterns
246
        WHERE id = ?
247
    };
248
    my $sth = $dbh->prepare($query);
249
    $sth->execute($numberpatternid);
250
}
251
252
=head2 GetSubscriptionsWithNumberpattern
253
254
    my @subs = GetSubscriptionsWithNumberpattern($numberpatternid);
255
256
Returns all subscriptions that are using a particular numbering pattern
257
258
=cut
259
260
sub GetSubscriptionsWithNumberpattern {
261
    my ($numberpatternid) = @_;
262
263
    return unless $numberpatternid;
264
265
    my $dbh = C4::Context->dbh;
266
    my $query = qq{
267
        SELECT *
268
        FROM subscription
269
          LEFT JOIN biblio ON subscription.biblionumber = biblio.biblionumber
270
        WHERE numberpattern = ?
271
    };
272
    my $sth = $dbh->prepare($query);
273
    my @results;
274
    if ($sth->execute($numberpatternid)) {
275
        @results = @{ $sth->fetchall_arrayref({}) };
276
    }
277
    return @results;
278
}
279
280
281
1;
282
283
__END__
284
285
=head1 AUTHOR
286
287
Koha Developement team <info@koha.org>
288
289
=cut
(-)a/installer/data/mysql/de-DE/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/de-DE/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/de-DE/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/de-DE/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/en/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/en/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/en/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/en/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/es-ES/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/es-ES/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/es-ES/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/es-ES/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/fr-FR/2-Optionel/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/jour', 'day', 1, 2, 1),
5
    ('1/jour', 'day', 1, 1, 2),
6
    ('3/semaine', 'week', 1, 3, 3),
7
    ('1/semaine', 'week', 1, 1, 4),
8
    ('1/2 semaines', 'week', 2, 1, 5),
9
    ('1/3 semaines', 'week', 3, 1, 6),
10
    ('1/mois', 'month', 1, 1, 7),
11
    ('1/2 mois', 'month', 2, 1, 8),
12
    ('1/3 mois', 'month', 3, 1, 9),
13
    ('2/an', 'month', 6, 1, 10),
14
    ('1/an', 'year', 1, 1, 11),
15
    ('1/2 ans', 'year', 2, 1, 12),
16
    ('Irrégulier', NULL, 1, 1, 13);
(-)a/installer/data/mysql/fr-FR/2-Optionel/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/fr-FR/2-Optionel/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/fr-FR/2-Optionel/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/it-IT/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/it-IT/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/it-IT/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/it-IT/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/kohastructure.sql (-19 / +55 lines)
Lines 1974-1979 DROP TABLE IF EXISTS `stopwords`; Link Here
1974
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1974
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1975
1975
1976
--
1976
--
1977
-- Table structure for table subscription_frequencies
1978
--
1979
1980
DROP TABLE IF EXISTS subscription_frequencies;
1981
CREATE TABLE subscription_frequencies (
1982
    id INTEGER NOT NULL AUTO_INCREMENT,
1983
    description TEXT NOT NULL,
1984
    displayorder INT DEFAULT NULL,
1985
    unit ENUM('day','week','month','year') DEFAULT NULL,
1986
    unitsperissue INTEGER NOT NULL DEFAULT '1',
1987
    issuesperunit INTEGER NOT NULL DEFAULT '1',
1988
    PRIMARY KEY (id)
1989
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1990
1991
--
1992
-- Table structure for table subscription_numberpatterns
1993
--
1994
1995
DROP TABLE IF EXISTS subscription_numberpatterns;
1996
CREATE TABLE subscription_numberpatterns (
1997
    id INTEGER NOT NULL AUTO_INCREMENT,
1998
    label VARCHAR(255) NOT NULL,
1999
    displayorder INTEGER DEFAULT NULL,
2000
    description TEXT NOT NULL,
2001
    numberingmethod VARCHAR(255) NOT NULL,
2002
    label1 VARCHAR(255) DEFAULT NULL,
2003
    add1 INTEGER DEFAULT NULL,
2004
    every1 INTEGER DEFAULT NULL,
2005
    whenmorethan1 INTEGER DEFAULT NULL,
2006
    setto1 INTEGER DEFAULT NULL,
2007
    numbering1 VARCHAR(255) DEFAULT NULL,
2008
    label2 VARCHAR(255) DEFAULT NULL,
2009
    add2 INTEGER DEFAULT NULL,
2010
    every2 INTEGER DEFAULT NULL,
2011
    whenmorethan2 INTEGER DEFAULT NULL,
2012
    setto2 INTEGER DEFAULT NULL,
2013
    numbering2 VARCHAR(255) DEFAULT NULL,
2014
    label3 VARCHAR(255) DEFAULT NULL,
2015
    add3 INTEGER DEFAULT NULL,
2016
    every3 INTEGER DEFAULT NULL,
2017
    whenmorethan3 INTEGER DEFAULT NULL,
2018
    setto3 INTEGER DEFAULT NULL,
2019
    numbering3 VARCHAR(255) DEFAULT NULL,
2020
    PRIMARY KEY (id)
2021
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2022
2023
--
1977
-- Table structure for table `subscription`
2024
-- Table structure for table `subscription`
1978
--
2025
--
1979
2026
Lines 1990-2029 CREATE TABLE `subscription` ( Link Here
1990
  `monthlength` int(11) default 0,
2037
  `monthlength` int(11) default 0,
1991
  `numberlength` int(11) default 0,
2038
  `numberlength` int(11) default 0,
1992
  `periodicity` tinyint(4) default 0,
2039
  `periodicity` tinyint(4) default 0,
1993
  `dow` varchar(100) default '',
2040
  countissuesperunit INTEGER NOT NULL DEFAULT 1,
1994
  `numberingmethod` varchar(100) default '',
1995
  `notes` mediumtext,
2041
  `notes` mediumtext,
1996
  `status` varchar(100) NOT NULL default '',
2042
  `status` varchar(100) NOT NULL default '',
1997
  `add1` int(11) default 0,
1998
  `every1` int(11) default 0,
1999
  `whenmorethan1` int(11) default 0,
2000
  `setto1` int(11) default NULL,
2001
  `lastvalue1` int(11) default NULL,
2043
  `lastvalue1` int(11) default NULL,
2002
  `add2` int(11) default 0,
2003
  `every2` int(11) default 0,
2004
  `whenmorethan2` int(11) default 0,
2005
  `setto2` int(11) default NULL,
2006
  `lastvalue2` int(11) default NULL,
2007
  `add3` int(11) default 0,
2008
  `every3` int(11) default 0,
2009
  `innerloop1` int(11) default 0,
2044
  `innerloop1` int(11) default 0,
2045
  `lastvalue2` int(11) default NULL,
2010
  `innerloop2` int(11) default 0,
2046
  `innerloop2` int(11) default 0,
2011
  `innerloop3` int(11) default 0,
2012
  `whenmorethan3` int(11) default 0,
2013
  `setto3` int(11) default NULL,
2014
  `lastvalue3` int(11) default NULL,
2047
  `lastvalue3` int(11) default NULL,
2015
  `issuesatonce` tinyint(3) NOT NULL default 1,
2048
  `innerloop3` int(11) default 0,
2016
  `firstacquidate` date default NULL,
2049
  `firstacquidate` date default NULL,
2017
  `manualhistory` tinyint(1) NOT NULL default 0,
2050
  `manualhistory` tinyint(1) NOT NULL default 0,
2018
  `irregularity` text,
2051
  `irregularity` text,
2052
  skip_serialseq BOOLEAN NOT NULL DEFAULT 0,
2019
  `letter` varchar(20) default NULL,
2053
  `letter` varchar(20) default NULL,
2020
  `numberpattern` tinyint(3) default 0,
2054
  `numberpattern` tinyint(3) default 0,
2055
  locale VARCHAR(80) DEFAULT NULL,
2021
  `distributedto` text,
2056
  `distributedto` text,
2022
  `internalnotes` longtext,
2057
  `internalnotes` longtext,
2023
  `callnumber` text,
2058
  `callnumber` text,
2024
  `location` varchar(80) NULL default '',
2059
  `location` varchar(80) NULL default '',
2025
  `branchcode` varchar(10) NOT NULL default '',
2060
  `branchcode` varchar(10) NOT NULL default '',
2026
  `hemisphere` tinyint(3) default 0,
2027
  `lastbranch` varchar(10),
2061
  `lastbranch` varchar(10),
2028
  `serialsadditems` tinyint(1) NOT NULL default '0',
2062
  `serialsadditems` tinyint(1) NOT NULL default '0',
2029
  `staffdisplaycount` VARCHAR(10) NULL,
2063
  `staffdisplaycount` VARCHAR(10) NULL,
Lines 2032-2038 CREATE TABLE `subscription` ( Link Here
2032
  `enddate` date default NULL,
2066
  `enddate` date default NULL,
2033
  `closed` INT(1) NOT NULL DEFAULT 0,
2067
  `closed` INT(1) NOT NULL DEFAULT 0,
2034
  `reneweddate` date default NULL,
2068
  `reneweddate` date default NULL,
2035
  PRIMARY KEY  (`subscriptionid`)
2069
  PRIMARY KEY  (`subscriptionid`),
2070
  CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
2071
  CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
2036
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2072
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2037
2073
2038
--
2074
--
(-)a/installer/data/mysql/nb-NO/2-Valgfritt/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/nb-NO/2-Valgfritt/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/nb-NO/2-Valgfritt/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/nb-NO/2-Valgfritt/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/pl-PL/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/pl-PL/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/pl-PL/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/pl-PL/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/ru-RU/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/ru-RU/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/ru-RU/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/ru-RU/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/uk-UA/optional/sample_frequencies.sql (+16 lines)
Line 0 Link Here
1
INSERT INTO subscription_frequencies
2
    (description, unit, unitsperissue, issuesperunit, displayorder)
3
VALUES
4
    ('2/day', 'day', 1, 2, 1),
5
    ('1/day', 'day', 1, 1, 2),
6
    ('3/week', 'week', 1, 3, 3),
7
    ('1/week', 'week', 1, 1, 4),
8
    ('1/2 weeks', 'week', 2, 1, 5),
9
    ('1/3 weeks', 'week', 3, 1, 6),
10
    ('1/month', 'month', 1, 1, 7),
11
    ('1/2 months', 'month', 2, 1, 8),
12
    ('1/3 months', 'month', 3, 1, 9),
13
    ('2/year', 'month', 6, 1, 10),
14
    ('1/year', 'year', 1, 1, 11),
15
    ('1/2 year', 'year', 2, 1, 12),
16
    ('Irregular', NULL, 1, 1, 13);
(-)a/installer/data/mysql/uk-UA/optional/sample_frequencies.txt (+1 lines)
Line 0 Link Here
1
Sample frequencies for subscriptions
(-)a/installer/data/mysql/uk-UA/optional/sample_numberpatterns.sql (+25 lines)
Line 0 Link Here
1
INSERT INTO subscription_numberpatterns
2
    (label, displayorder, description, numberingmethod,
3
    label1, add1, every1, whenmorethan1, setto1, numbering1,
4
    label2, add2, every2, whenmorethan2, setto2, numbering2,
5
    label3, add3, every3, whenmorethan3, setto3, numbering3)
6
VALUES
7
    ('Number', 1, 'Simple Numbering method', 'No.{X}',
8
    'Number', 1, 1, 99999, 1, NULL,
9
    NULL, NULL, NULL, NULL, NULL, NULL,
10
    NULL, NULL, NULL, NULL, NULL, NULL),
11
12
    ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
13
    'Volume', 1, 48, 99999, 1, NULL,
14
    'Number', 1, 4, 12, 1, NULL,
15
    'Issue', 1, 1, 4, 1, NULL),
16
17
    ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
18
    'Volume', 1, 12, 99999, 1, NULL,
19
    'Number', 1, 1, 12, 1, NULL,
20
    NULL, NULL, NULL, NULL, NULL, NULL),
21
22
    ('Seasonal', 4, 'Season Year', '{X} {Y}',
23
    'Season', 1, 1, 3, 0, 'season',
24
    'Year', 1, 4, 99999, 1, NULL,
25
    NULL, NULL, NULL, NULL, NULL, NULL);
(-)a/installer/data/mysql/uk-UA/optional/sample_numberpatterns.txt (+1 lines)
Line 0 Link Here
1
Sample numbering patterns for subscriptions
(-)a/installer/data/mysql/updatedatabase.pl (+221 lines)
Lines 6935-6940 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
6935
    SetVersion($DBversion);
6935
    SetVersion($DBversion);
6936
}
6936
}
6937
6937
6938
$DBversion = "XXX";
6939
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
6940
    $dbh->do(qq|
6941
        DROP TABLE IF EXISTS subscription_frequencies
6942
    |);
6943
    $dbh->do(qq|
6944
        CREATE TABLE subscription_frequencies (
6945
            id INTEGER NOT NULL AUTO_INCREMENT,
6946
            description TEXT NOT NULL,
6947
            displayorder INT DEFAULT NULL,
6948
            unit ENUM('day','week','month','year') DEFAULT NULL,
6949
            unitsperissue INTEGER NOT NULL DEFAULT '1',
6950
            issuesperunit INTEGER NOT NULL DEFAULT '1',
6951
            PRIMARY KEY (id)
6952
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
6953
    |);
6954
6955
    $dbh->do(qq|
6956
        DROP TABLE IF EXISTS subscription_numberpatterns
6957
    |);
6958
    $dbh->do(qq|
6959
        CREATE TABLE subscription_numberpatterns (
6960
            id INTEGER NOT NULL AUTO_INCREMENT,
6961
            label VARCHAR(255) NOT NULL,
6962
            displayorder INTEGER DEFAULT NULL,
6963
            description TEXT NOT NULL,
6964
            numberingmethod VARCHAR(255) NOT NULL,
6965
            label1 VARCHAR(255) DEFAULT NULL,
6966
            add1 INTEGER DEFAULT NULL,
6967
            every1 INTEGER DEFAULT NULL,
6968
            whenmorethan1 INTEGER DEFAULT NULL,
6969
            setto1 INTEGER DEFAULT NULL,
6970
            numbering1 VARCHAR(255) DEFAULT NULL,
6971
            label2 VARCHAR(255) DEFAULT NULL,
6972
            add2 INTEGER DEFAULT NULL,
6973
            every2 INTEGER DEFAULT NULL,
6974
            whenmorethan2 INTEGER DEFAULT NULL,
6975
            setto2 INTEGER DEFAULT NULL,
6976
            numbering2 VARCHAR(255) DEFAULT NULL,
6977
            label3 VARCHAR(255) DEFAULT NULL,
6978
            add3 INTEGER DEFAULT NULL,
6979
            every3 INTEGER DEFAULT NULL,
6980
            whenmorethan3 INTEGER DEFAULT NULL,
6981
            setto3 INTEGER DEFAULT NULL,
6982
            numbering3 VARCHAR(255) DEFAULT NULL,
6983
            PRIMARY KEY (id)
6984
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
6985
    |);
6986
6987
    $dbh->do(qq|
6988
        INSERT INTO subscription_frequencies (description, unit, unitsperissue, issuesperunit, displayorder)
6989
        VALUES
6990
            ('2/day', 'day', 1, 2, 1),
6991
            ('1/day', 'day', 1, 1, 2),
6992
            ('3/week', 'week', 1, 3, 3),
6993
            ('1/week', 'week', 1, 1, 4),
6994
            ('1/2 weeks', 'week', 2, 1, 5),
6995
            ('1/3 weeks', 'week', 3, 1, 6),
6996
            ('1/month', 'month', 1, 1, 7),
6997
            ('1/2 months', 'month', 2, 1, 8),
6998
            ('1/3 months', 'month', 3, 1, 9),
6999
            ('2/year', 'month', 6, 1, 10),
7000
            ('1/year', 'year', 1, 1, 11),
7001
            ('1/2 year', 'year', 2, 1, 12),
7002
            ('Irregular', NULL, 1, 1, 13)
7003
    |);
7004
7005
    # Used to link existing subscription to newly created frequencies
7006
    my $frequencies_mapping = {     # keys are old frequency numbers, values are the new ones
7007
        1 => 2,     # daily (n/week)
7008
        2 => 4,     # 1/week
7009
        3 => 5,     # 1/2 weeks
7010
        4 => 6,     # 1/3 weeks
7011
        5 => 7,     # 1/month
7012
        6 => 8,     # 1/2 months (6/year)
7013
        7 => 9,     # 1/3 months (1/quarter)
7014
        8 => 9,    # 1/quarter (seasonal)
7015
        9 => 10,    # 2/year
7016
        10 => 11,   # 1/year
7017
        11 => 12,   # 1/2 years
7018
        12 => 1,    # 2/day
7019
        16 => 13,   # Without periodicity
7020
        32 => 13,   # Irregular
7021
        48 => 13    # Unknown
7022
    };
7023
7024
    $dbh->do(qq|
7025
        INSERT INTO subscription_numberpatterns
7026
            (label, displayorder, description, numberingmethod,
7027
            label1, add1, every1, whenmorethan1, setto1, numbering1,
7028
            label2, add2, every2, whenmorethan2, setto2, numbering2,
7029
            label3, add3, every3, whenmorethan3, setto3, numbering3)
7030
        VALUES
7031
            ('Number', 1, 'Simple Numbering method', 'No.{X}',
7032
            'Number', 1, 1, 99999, 1, NULL,
7033
            NULL, NULL, NULL, NULL, NULL, NULL,
7034
            NULL, NULL, NULL, NULL, NULL, NULL),
7035
7036
            ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
7037
            'Volume', 1, 48, 99999, 1, NULL,
7038
            'Number', 1, 4, 12, 1, NULL,
7039
            'Issue', 1, 1, 4, 1, NULL),
7040
7041
            ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
7042
            'Volume', 1, 12, 99999, 1, NULL,
7043
            'Number', 1, 1, 12, 1, NULL,
7044
            NULL, NULL, NULL, NULL, NULL, NULL),
7045
7046
            ('Seasonal', 4, 'Season Year', '{X} {Y}',
7047
            'Season', 1, 1, 3, 0, 'season',
7048
            'Year', 1, 4, 99999, 1, NULL,
7049
            NULL, NULL, NULL, NULL, NULL, NULL)
7050
    |);
7051
7052
    $dbh->do(qq|
7053
        ALTER TABLE subscription
7054
        MODIFY COLUMN numberpattern INTEGER DEFAULT NULL,
7055
        MODIFY COLUMN periodicity INTEGER DEFAULT NULL
7056
    |);
7057
7058
    # Update existing subscriptions
7059
7060
    my $query = qq|
7061
        SELECT subscriptionid, periodicity, numberingmethod,
7062
            add1, every1, whenmorethan1, setto1,
7063
            add2, every2, whenmorethan2, setto2,
7064
            add3, every3, whenmorethan3, setto3
7065
        FROM subscription
7066
        ORDER BY subscriptionid
7067
    |;
7068
    my $sth = $dbh->prepare($query);
7069
    $sth->execute;
7070
    my $insert_numberpatterns_sth = $dbh->prepare(qq|
7071
        INSERT INTO subscription_numberpatterns
7072
             (label, displayorder, description, numberingmethod,
7073
            label1, add1, every1, whenmorethan1, setto1, numbering1,
7074
            label2, add2, every2, whenmorethan2, setto2, numbering2,
7075
            label3, add3, every3, whenmorethan3, setto3, numbering3)
7076
        VALUES
7077
            (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
7078
    |);
7079
    my $check_numberpatterns_sth = $dbh->prepare(qq|
7080
        SELECT * FROM subscription_numberpatterns
7081
        WHERE add1 = ? AND add2 = ? AND add3 = ?
7082
          AND every1 = ? AND every2 = ? AND every3 = ?
7083
          AND whenmorethan1 = ? AND whenmorethan2 = ? AND whenmorethan3 = ?
7084
          AND setto1 = ? AND setto2 = ? AND setto3 = ?
7085
          AND numberingmethod = ?
7086
        LIMIT 1
7087
    |);
7088
    my $update_subscription_sth = $dbh->prepare(qq|
7089
        UPDATE subscription
7090
        SET numberpattern = ?,
7091
            periodicity = ?
7092
        WHERE subscriptionid = ?
7093
    |);
7094
7095
    my $i = 1;
7096
    while(my $sub = $sth->fetchrow_hashref) {
7097
        $check_numberpatterns_sth->execute(
7098
            $sub->{add1}, $sub->{add2}, $sub->{add3},
7099
            $sub->{every1}, $sub->{every2}, $sub->{every3},
7100
            $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan3},
7101
            $sub->{setto1}, $sub->{setto2}, $sub->{setto3},
7102
            $sub->{numberingmethod}
7103
        );
7104
        my $p = $check_numberpatterns_sth->fetchrow_hashref;
7105
        if (defined $p) {
7106
            # Pattern already exists, link to it
7107
            $update_subscription_sth->execute($p->{id},
7108
                $frequencies_mapping->{$sub->{periodicity}},
7109
                $sub->{subscriptionid});
7110
        } else {
7111
            # Create a new numbering pattern for this subscription
7112
            my $ok = $insert_numberpatterns_sth->execute(
7113
                "Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod},
7114
                "X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef,
7115
                "Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef,
7116
                "Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef
7117
            );
7118
            if($ok) {
7119
                my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef);
7120
                # Link to subscription_numberpatterns and subscription_frequencies
7121
                $update_subscription_sth->execute($id,
7122
                    $frequencies_mapping->{$sub->{periodicity}},
7123
                    $sub->{subscriptionid});
7124
            }
7125
            $i++;
7126
        }
7127
    }
7128
7129
    # Remove now useless columns
7130
    $dbh->do(qq|
7131
        ALTER TABLE subscription
7132
        DROP COLUMN numberingmethod,
7133
        DROP COLUMN add1,
7134
        DROP COLUMN every1,
7135
        DROP COLUMN whenmorethan1,
7136
        DROP COLUMN setto1,
7137
        DROP COLUMN add2,
7138
        DROP COLUMN every2,
7139
        DROP COLUMN whenmorethan2,
7140
        DROP COLUMN setto2,
7141
        DROP COLUMN add3,
7142
        DROP COLUMN every3,
7143
        DROP COLUMN whenmorethan3,
7144
        DROP COLUMN setto3,
7145
        DROP COLUMN dow,
7146
        DROP COLUMN issuesatonce,
7147
        DROP COLUMN hemisphere,
7148
        ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 1 AFTER periodicity,
7149
        ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity,
7150
        ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern,
7151
        ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
7152
        ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
7153
    |);
7154
7155
    print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n";
7156
    SetVersion($DBversion);
7157
}
7158
6938
=head1 FUNCTIONS
7159
=head1 FUNCTIONS
6939
7160
6940
=head2 TableExists($table)
7161
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc (+10 lines)
Lines 20-23 Link Here
20
    [% IF ( CAN_user_serials_check_expiration ) %]
20
    [% IF ( CAN_user_serials_check_expiration ) %]
21
	<li><a href="/cgi-bin/koha/serials/checkexpiration.pl">Check expiration</a></li>
21
	<li><a href="/cgi-bin/koha/serials/checkexpiration.pl">Check expiration</a></li>
22
    [% END %]
22
    [% END %]
23
    <li>
24
        <a href="/cgi-bin/koha/serials/subscription-frequencies.pl">
25
            Manage frequencies
26
        </a>
27
    </li>
28
    <li>
29
        <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">
30
            Manage numbering patterns
31
        </a>
32
    </li>
23
</ul>
33
</ul>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt (-58 / +5 lines)
Lines 119-182 $(document).ready(function() { Link Here
119
</tr>
119
</tr>
120
[% FOREACH subscription IN subscriptions %]
120
[% FOREACH subscription IN subscriptions %]
121
    [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
121
    [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
122
      <td><a href="subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]"># [% subscription.subscriptionid %]</a> </td>
122
        <td><a href="subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]"># [% subscription.subscriptionid %]</a> </td>
123
      <td>         [% IF ( subscription.periodicity1 ) %]
123
        <td>[% subscription.frequency.description %]</td>
124
                        1/day
124
        <td>[% subscription.numberpattern.label %]</td>
125
                [% END %]
125
        <td> [% subscription.branchcode %]</td>
126
                [% IF ( subscription.periodicity2 ) %]
126
        <td> [% subscription.callnumber %]</td>
127
                        1/week
128
                [% END %]
129
                [% IF ( subscription.periodicity3 ) %]
130
                        1/2 weeks
131
                [% END %]
132
                [% IF ( subscription.periodicity4 ) %]
133
                        1/3 weeks
134
                [% END %]
135
                [% IF ( subscription.periodicity5 ) %]
136
                        1/Month
137
                [% END %]
138
                [% IF ( subscription.periodicity6 ) %]
139
                        1/2 Months (6/year)
140
                [% END %]
141
                [% IF ( subscription.periodicity7 ) %]
142
                        1/quarter
143
                [% END %]
144
                [% IF ( subscription.periodicity8 ) %]
145
                        1/quarter
146
                [% END %]
147
                [% IF ( subscription.periodicity9 ) %]
148
                        2/year
149
                [% END %]
150
                [% IF ( subscription.periodicity10 ) %]
151
                        1/year
152
                [% END %]
153
                [% IF ( subscription.periodicity11 ) %]
154
                        1/2 years
155
                [% END %]</td>
156
           <td>
157
                [% IF ( subscription.numberpattern1 ) %]
158
                    Number
159
                [% END %]
160
                [% IF ( subscription.numberpattern2 ) %]
161
                    Volume, number, issue
162
                [% END %]
163
                [% IF ( subscription.numberpattern3 ) %]
164
                    Volume, number
165
                [% END %]
166
                [% IF ( subscription.numberpattern4 ) %]
167
                    Volume, issue
168
                [% END %]
169
                [% IF ( subscription.numberpattern5 ) %]
170
                    Number, issue
171
                [% END %]
172
                [% IF ( subscription.numberpattern6 ) %]
173
                    Seasonal only
174
                [% END %]
175
                [% IF ( subscription.numberpattern7 ) %]
176
                    None of the above
177
                [% END %]</td>
178
            <td> [% subscription.branchcode %]</td>
179
            <td> [% subscription.callnumber %]</td>
180
        <td> [% subscription.notes %]
127
        <td> [% subscription.notes %]
181
            [% UNLESS subscription.closed %]
128
            [% UNLESS subscription.closed %]
182
                [% IF ( subscription.subscriptionexpired ) %]
129
                [% IF ( subscription.subscriptionexpired ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (+82 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
3
<h2>Prediction pattern</h1>
4
[% IF (not_consistent_end_date) %]
5
  <p><em>End date is not consistent with subscription length.</em></p>
6
[% END %]
7
[% IF (ask_for_irregularities) %]
8
    <p><em>Please check issues that are NOT published (irregularities)</em></p>
9
    [% IF (daily_options) %]
10
        <script type="text/javascript">
11
        //<![CDATA[
12
        function Check_boxes(dow) {
13
            if($(":checkbox[data-dow='"+dow+"']:first").attr("checked") == 'checked') {
14
                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
15
                    $(this).attr('checked', true);
16
                });
17
            } else {
18
                $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
19
                    $(this).attr('checked', false);
20
                });
21
            }
22
        }
23
        //]]>
24
        </script>
25
        <p><em>
26
            If there is a day (or more) in the week where issues are never
27
            published, you can check corresponding boxes below.
28
        </em></p>
29
        <input type="checkbox" id="monday" data-dow="1" onchange="Check_boxes(1);" />
30
        <label for="monday">Monday</label>
31
        <input type="checkbox" id="tuesday" data-dow="2" onchange="Check_boxes(2);" />
32
        <label for="tuesday">Tuesday</label>
33
        <input type="checkbox" id="wednesday" data-dow="3" onchange="Check_boxes(3);" />
34
        <label for="wednesday">Wednesday</label>
35
        <input type="checkbox" id="thursday" data-dow="4" onchange="Check_boxes(4);" />
36
        <label for="thursday">Thursday</label>
37
        <input type="checkbox" id="friday" data-dow="5" onchange="Check_boxes(5);" />
38
        <label for="friday">Friday</label>
39
        <input type="checkbox" id="saturday" data-dow="6" onchange="Check_boxes(6);" />
40
        <label for="saturday">Saturday</label>
41
        <input type="checkbox" id="sunday" data-dow="7" onchange="Check_boxes(7);" />
42
        <label for="sunday">Sunday</label>
43
    [% END %]
44
[% END %]
45
[% IF (predictions_loop) %]
46
<table id="predictionst">
47
  <thead>
48
    <tr>
49
      <th>Number</th>
50
      <th>Publication Date</th>
51
      [% IF (ask_for_irregularities) %]
52
      <th>Not published</th>
53
      [% END %]
54
    </tr>
55
  </thead>
56
  <tbody>
57
    [% FOREACH prediction IN predictions_loop %]
58
      <tr>
59
        <td>[% prediction.number %]</td>
60
        <td>
61
          [% IF (prediction.publicationdate) %]
62
            [% prediction.publicationdate | $KohaDates %]
63
          [% ELSE %]
64
            unknown
65
          [% END %]
66
        </td>
67
        [% IF (ask_for_irregularities) %]
68
         <td style="text-align:center">
69
         [% UNLESS (loop.first) %]
70
          [% IF (prediction.not_published) %]
71
            <input type="checkbox" name="irregularity" value="[% prediction.issuenumber %]" data-dow="[% prediction.dow %]" checked="checked" />
72
          [% ELSE %]
73
            <input type="checkbox" name="irregularity" value="[% prediction.issuenumber %]" data-dow="[% prediction.dow %]" />
74
          [% END %]
75
         </td>
76
         [% END %]
77
        [% END %]
78
      </tr>
79
    [% END %]
80
  </tbody>
81
</table>
82
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-1278 / +738 lines)
Lines 1-3 Link Here
1
[% USE KohaDates %]
2
1
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
4
<title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
Lines 11-963 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
11
<script type="text/javascript">
13
<script type="text/javascript">
12
//<![CDATA[
14
//<![CDATA[
13
15
14
// the english words used in display purposes
16
var globalnumpatterndata;
15
var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("Starting with:"),_("Rollover at:"),_("Choose Hemisphere:"),_("Northern"),_("Southern"),
17
var globalfreqdata;
16
_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
18
var advancedpatternlocked;
17
var weekno_label = _("Week # ");
19
var patternneedtobetested = 0;
18
var is_season = 0;
20
19
var is_hemisphere = 1;
21
function check_issues(){
20
var irregular_issues;   // will hold irregularity object.
22
    if (globalfreqdata.unit.length >0) {
21
23
        if (document.f.subtype.value == globalfreqdata.unit){
22
function formatDate(myDate) {
24
            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
23
    var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate());
25
        } else if (document.f.subtype.value != "issues"){
24
    if(d[1].toString().length == 1) { d[1] = '0'+d[1] };
26
            alert(_("Frequency and subscription length provided doesn't combine well. Please consider entering an issue count rather than a time period."));
25
    if(d[2].toString().length == 1) { d[2] = '0'+d[2] };
27
        }
26
    [% IF ( dateformat == "us" ) %]
27
        return(d[1] + '/' + d[2] + '/' + d[0]) ;
28
    [% ELSIF ( dateformat == "metric" ) %]
29
        return(d[2] + '/' + d[1] + '/' + d[0]) ;
30
    [% ELSE %]
31
        return(''+d[0] + '-' + d[1] + '-' + d[2]) ;
32
    [% END %]
33
}
34
35
Date.prototype.addDays = function(days) {
36
    this.setDate(this.getDate()+days);
37
}
38
39
function getWeeksArray(startDate,periodicity) {
40
// returns an array of syspref-formatted dates starting at the first day of startDate's year.
41
// This prediction method will not accurately predict irregularites beyond the first year.
42
// FIXME : Should replace with ajax query to get the first Monday of the year so that week numbers have correct dates.
43
    var incr=1;
44
    if(periodicity==3) {  // 1/2 wks
45
        incr=2;
46
    } else if(periodicity == 4) { // 1/3 wks
47
        incr=3;
48
    }
49
    var weeksArray = new Array;
50
    var jan01 = new Date();
51
    jan01.setDate(1);
52
    jan01.setMonth(0);
53
    jan01.setFullYear(startDate.getFullYear());
54
    for(var i=0;i<52;i++) {
55
        weeksArray[i] = formatDate(jan01) + ' ' + weekno_label + (i + 1);
56
        jan01.addDays( 7 ); 
57
    }
28
    }
58
    return weeksArray;
59
}
29
}
60
30
61
function YMDaToYWDa(S) {
31
function addbiblioPopup(biblionumber) {
62
    with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
32
    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
63
        var DoW = getUTCDay();
33
    if(biblionumber){
64
        setUTCDate(getUTCDate() - (DoW + 6) % 7 + 3);
34
        destination += "&biblionumber="+biblionumber;
65
        var ms = valueOf();
66
        setUTCMonth(0, 4);
67
        var WN = Math.round((ms - valueOf()) / 604800000) + 1;
68
        return [getUTCFullYear(), WN, DoW == 0 ? 7 : DoW];
69
    }
35
    }
36
    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
70
}
37
}
71
function dayofyear(d) { // d is a Date object
72
var yn = d.getFullYear();
73
var mn = d.getMonth();
74
var dn = d.getDate();
75
var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
76
var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
77
var ddiff = Math.round((d2-d1)/864e5);
78
return ddiff+1;
79
}
80
81
82
// create irregularity object.
83
function IrregularPattern() {
84
	this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
85
	this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
86
    this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday"));
87
    // create weeks irregularity selection array:
88
    this.firstissue = new Date();
89
    this.firstissue.setDate(1);
90
    this.firstissue.setMonth(0);
91
    [% IF ( firstacquiyear ) %] // it's a mod, we already have a start date.
92
        this.firstissue.setFullYear( [% firstacquiyear %] );
93
    [% END %]
94
   	this.weeks = getWeeksArray(this.firstissue); 
95
38
96
    this.numskipped = 0;
39
function Plugin(f)
97
    // init:
40
{
98
	var irregular = '[% irregularity %]';
41
    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
99
    this.skipped = irregular.split(',');
100
}
42
}
101
43
102
IrregularPattern.prototype.update = function() {
44
function FindAcqui(f)
103
		this.skipped= new Array;
45
{
104
		var cnt = 0;
46
    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
105
		// daily periodicity, we interpret irregular array as which days of week to skip.
106
		// else if weekly periodicity, week numbers (starting from 01 Jan) to skip.
107
        // else  irregular array is list of issues to skip
108
		var summary_str = '';
109
		this.numskipped = 0;
110
        if(document.f.irregularity_select) {
111
            //$("#irregularity_select option:selected").each(...); //jquery can combine both conditionals and the for loop
112
            for( var i in document.f.irregularity_select.options ) {
113
                if( document.f.irregularity_select.options[i].selected ) {
114
                    this.skipped[cnt] = document.f.irregularity_select.options[i].value ;
115
                    summary_str += document.f.irregularity_select.options[i].text + "\n" ;
116
				    cnt++;
117
				    this.numskipped++;
118
			    }
119
		    }
120
		    var summary = document.getElementById("irregularity_summary");
121
		    if(summary) {
122
			    summary.value = summary_str;
123
			    summary.rows= ( cnt > 6 ) ? cnt : 6 ; // textarea will bre resized, but not more than 6 lines will show.
124
		    }
125
        }
126
}
47
}
127
48
128
IrregularPattern.prototype.irregular = function(index) { 
49
function Find_ISSN(f)
129
	for( var i in this.skipped) {
50
{
130
			if( this.skipped[i] == index) {
51
    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
131
				return true;
132
			}
133
	}
134
	return false;
135
}
52
}
136
53
137
function init_pattern() {
54
function Clear(id) {
138
	irregular_issues = new IrregularPattern();
55
    $("#"+id).val('');
139
}
140
function reset_pattern() {
141
	document.getElementById("numberpattern").value = '';
142
    document.getElementById("irregularity").innerHTML = '';
143
	init_pattern();
144
	reset_num_pattern();
145
}
56
}
146
57
147
// common pre defined number patterns
58
function Check_page1() {
148
function reset_num_pattern() {
59
    if ( $("#aqbooksellerid").val().length == 0) {
149
var patternchoice = document.getElementById("numberpattern").value;
60
        input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
150
    switch(patternchoice){
61
        if (input_box==false) {
151
    case "2":
62
            return false;
152
        document.f.add1.value=1;
63
        }
153
        document.f.add2.value=1;
64
    }
154
        document.f.add3.value=1;
65
    if ($("#biblionumber").val().length == 0) {
155
        document.f.every1.value=12;
66
        alert(_("You must choose or create a biblio"));
156
        document.f.every2.value=1;
67
        return false;
157
        document.f.every3.value=1;
158
        document.f.whenmorethan1.value=9999999;
159
        document.f.whenmorethan2.value=12;
160
        document.f.whenmorethan3.value=4;
161
        document.f.setto1.value=0;
162
        document.f.setto2.value=1;
163
        document.f.setto3.value=1;
164
        document.f.lastvalue1.value=1;
165
        document.f.lastvalue2.value=1;
166
        document.f.lastvalue3.value=1;
167
        document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}");
168
        moreoptions(text[1],text[0],text[2]);
169
        display_table(0); // toggle info box on (1) or off (0)
170
        break;
171
    case "3":
172
        document.f.add1.value=1;
173
        document.f.add2.value=1;
174
        document.f.add3.value='';
175
        document.f.every1.value=12;
176
        document.f.every2.value=1;
177
        document.f.every3.value='';
178
        document.f.whenmorethan1.value=9999999;
179
        document.f.whenmorethan2.value=12;
180
        document.f.whenmorethan3.value='';
181
        document.f.setto1.value=0;
182
        document.f.setto2.value=1;
183
        document.f.setto3.value='';
184
        document.f.lastvalue1.value=1;
185
        document.f.lastvalue2.value=1;
186
        document.f.lastvalue3.value='';
187
        document.f.numberingmethod.value=_("Vol {X}, No {Y}");
188
        moreoptions(text[1],text[0]);
189
        display_table(0);
190
        break;
191
    case "4":
192
        document.f.add1.value=1;
193
        document.f.add2.value=1;
194
        document.f.add3.value='';
195
        document.f.every1.value=12;
196
        document.f.every2.value=1;
197
        document.f.every3.value='';
198
        document.f.whenmorethan1.value=9999999;
199
        document.f.whenmorethan2.value=12;
200
        document.f.whenmorethan3.value='';
201
        document.f.setto1.value=0;
202
        document.f.setto2.value=1;
203
        document.f.setto3.value='';
204
        document.f.lastvalue1.value=1;
205
        document.f.lastvalue2.value=1;
206
        document.f.lastvalue3.value='';
207
        document.f.numberingmethod.value=_("Vol {X}, Issue {Y}");
208
        moreoptions(text[1],text[2]);
209
        display_table(0);
210
        break;
211
    case "5":
212
//        var d = new Date(document.f.firstacquidate.value);
213
//        var smonth = d.getMonth();
214
        document.f.add1.value=1;
215
        document.f.add2.value=1;
216
        document.f.add3.value='';
217
        document.f.every1.value=12;
218
        document.f.every2.value=1;
219
        document.f.every3.value='';
220
        document.f.whenmorethan1.value=9999999;
221
        document.f.whenmorethan2.value=12;
222
        document.f.whenmorethan3.value='';
223
        document.f.setto1.value=0;
224
        document.f.setto2.value=1;
225
        document.f.setto3.value='';
226
        document.f.numberingmethod.value=_("No {X}, Issue {Y}");
227
        moreoptions(text[0],text[2]);
228
        display_table(0);
229
        break;
230
    case "6":
231
        var d = new Date(document.f.firstacquidate.value);
232
        var sYear = d.getFullYear();
233
        moreoptions_seasons(text[15],sYear);
234
        var d = new Date(document.f.firstacquidate.value);
235
        var sYear = d.getFullYear();
236
        document.f.add1.value=1;
237
        document.f.add2.value='1';
238
        document.f.add3.value='';
239
        document.f.every1.value=4;
240
        document.f.every2.value='1';
241
        document.f.every3.value='';
242
        document.f.whenmorethan1.value=9999999;
243
        document.f.whenmorethan2.value='4';
244
        document.f.whenmorethan3.value='';
245
        document.f.setto1.value=0;
246
        document.f.setto2.value='1';
247
        document.f.setto3.value='';
248
        document.f.periodicity.value='8';
249
        document.f.numberingmethod.value=_("{Y} {X}");
250
        moreoptions_seasons(text[15],sYear);
251
        document.f.lastvalue1temp.value=document.f.lastvalue1.value=sYear;
252
        display_table(0);
253
        is_season = 1;
254
        break;
255
    case "7":
256
        display_table(1);
257
        document.getElementById("more_options").innerHTML = '';
258
        document.f.irreg_check.value=1; 
259
        break;
260
    case "8":  // Year/Number
261
        var d = (document.f.firstacquidate.value) ? new Date( document.f.firstacquidate.value) : new Date() ;
262
        var sYear = d.getFullYear();
263
        document.f.add1.value=1;
264
        document.f.add2.value=1;
265
        document.f.add3.value='';
266
        document.f.every1.value=12;
267
        document.f.every2.value=1;
268
        document.f.every3.value='';
269
        document.f.whenmorethan1.value=9999999;
270
        document.f.whenmorethan2.value=12;
271
        document.f.whenmorethan3.value='';
272
        document.f.setto1.value=0;
273
        document.f.setto2.value=1;
274
        document.f.setto3.value='';
275
        document.f.lastvalue1.value=sYear;
276
          switch (document.f.periodicity.value){
277
            case 1:              
278
              var doy = dayofyear(d);
279
              document.f.lastvalue2.value=doy; 
280
              document.f.whenmorethan2.value=365; 
281
              break;      
282
            case 12:     
283
              var doy = dayofyear(d);
284
              document.f.lastvalue2.value=doy*2; 
285
              document.f.whenmorethan2.value=730; 
286
              break;      
287
            case 2:
288
            case 3:
289
            case 4:
290
              var YWDa = YMDaToYWDa(d);
291
              document.f.lastvalue2.value=YWDA[1]/(document.f.periodicity.value-1); 
292
              break;      
293
            case 5:
294
              var smonth = d.getMonth();
295
              document.f.lastvalue2.value=smonth;
296
              break;      
297
            case 6:
298
              var smonth = d.getMonth();
299
              document.f.lastvalue2.value=smonth/2;
300
              document.f.whenmorethan2.value=6;
301
              break;      
302
            case 7:
303
            case 8:      
304
              var smonth = d.getMonth();
305
              document.f.lastvalue2.value=smonth/3;
306
              document.f.whenmorethan2.value=4;
307
              break;      
308
            case 9:                        
309
              var smonth = d.getMonth();
310
              document.f.lastvalue2.value=smonth/6;
311
              document.f.whenmorethan2.value=2;
312
              break;      
313
            default:
314
          } 
315
        document.f.lastvalue3.value='';
316
        document.f.numberingmethod.value=_("{X} / {Y}");
317
        moreoptions(text[16],text[0]);
318
     //   document.f.lastvalue1temp.value=sYear;
319
     //   document.f.lastvalue2temp.value=document.f.lastvalue2.value;
320
        display_table(0);
321
        break;
322
    default:
323
        document.f.add1.value=1;
324
        document.f.add2.value='';
325
        document.f.add3.value='';
326
        document.f.every1.value=1;
327
        document.f.every2.value='';
328
        document.f.every3.value='';
329
        document.f.whenmorethan1.value=9999999;
330
        document.f.whenmorethan2.value='';
331
        document.f.whenmorethan3.value='';
332
        document.f.setto1.value=0;
333
        document.f.setto2.value='';
334
        document.f.setto3.value='';
335
        document.f.lastvalue1.value=1;
336
        document.f.lastvalue2.value='';
337
        document.f.lastvalue3.value='';
338
        document.f.numberingmethod.value='{X}';
339
//        moreoptions_daily_check(text[0]);
340
        moreoptions(text[0]);
341
        document.f.irreg_check.value=1;
342
        display_table(0);
343
        break;
344
    }
68
    }
345
}
346
69
347
function display_table(n) {
70
    return true;
348
    if(n==1){
349
        document.getElementById("basetable").style.display = 'block';
350
    } else if(n==0){
351
        document.getElementById("basetable").style.display = 'none';
352
    } else {
353
		var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ;
354
			document.getElementById("basetable").style.display = disp_val;
355
	}
356
}
71
}
357
72
358
function set_num_pattern_from_template_vars() {
73
function Check_page2(){
359
	if(!document.getElementById("numberpattern")){ return false; }
74
    [% UNLESS (more_than_one_serial) %]
360
    document.getElementById("numberpattern").value = '[% numberpattern %]';
75
      if($("#acqui_date").val().length == 0){
361
    reset_num_pattern();
76
          alert(_("You must choose a first publication date"));
362
    
77
          return false;
363
    document.f.add1.value='[% add1 %]';
78
      }
364
    document.f.add2.value='[% add2 %]';
365
    document.f.add3.value='[% add3 %]';
366
    document.f.every1.value='[% every1 %]';
367
    document.f.every2.value='[% every2 %]';
368
    document.f.every3.value='[% every3 %]';
369
    document.f.whenmorethan1.value='[% whenmorethan1 %]';
370
    document.f.whenmorethan2.value='[% whenmorethan2 %]';
371
    document.f.whenmorethan3.value='[% whenmorethan3 %]';
372
    document.f.setto1.value='[% setto1 %]';
373
    document.f.setto2.value='[% setto2 %]';
374
    document.f.setto3.value='[% setto3 %]';
375
    document.f.lastvalue1.value='[% lastvalue1 %]';
376
    document.f.lastvalue2.value='[% lastvalue2 %]';
377
    document.f.lastvalue3.value='[% lastvalue3 %]';
378
    document.f.numberingmethod.value='[% numberingmethod %]';
379
380
    var more_strY;
381
    var more_strZ;
382
    [% IF ( add2 ) %]
383
    if([% add2 %] > 0){
384
        more_strY="Y";
385
    }
386
    [% END %]
79
    [% END %]
387
    [% IF ( add3 ) %]
80
    if($("#frequency").val().length == 0){
388
    if([% add3 %] > 0){
81
        alert(_("You must choose a frequency"));
389
        more_strZ="Z";
82
        return false;
390
    }
83
    }
391
    [% END %]
84
    if($("input[name='startdate']").val().length == 0){
392
    document.f.lastvalue1temp.value='[% lastvalue1 %]';
85
        alert(_("You must choose a start date"));
393
    if(more_strY){
86
        return false;
394
        document.f.lastvalue2temp.value='[% lastvalue2 %]';
395
    document.f.whenmorethan2temp.value='[% whenmorethan2 %]';
396
    }
87
    }
397
    if(more_strZ){
88
    if($("#sublength").val().length == 0 && $("input[name='enddate']").val().length == 0){
398
        document.f.lastvalue3temp.value='[% lastvalue3 %]';
89
        alert(_("You must choose a subscription length or an end date."));
399
    document.f.whenmorethan3temp.value='[% whenmorethan3 %]';
90
        return false;
400
    }
91
    }
401
}
92
    if($("#numberpattern").val().length == 0){
402
93
        alert(_("You must choose a numbering pattern"));
403
// a pre check with more options to see if 'number' and '1/day' are chosen
94
        return false;
404
function moreoptions_daily_check(x) {
405
    var periodicity = document.f.periodicity.value;
406
    var errortext='';
407
    if(periodicity == 1){ // i.e. daily
408
        document.getElementById("irregularity").innerHTML = '';
409
        errortext =_("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
410
        for(var j=0;j<irregular_issues.daynames.length;j++){
411
            errortext +="<input type='checkbox' name='irregular' id='irregular"+(j+1)+"' value='"+(j+1)+"' />"+irregular_issues.daynames[j]+" &nbsp; ";
412
        }
413
        var error = errortext;
414
        moreoptions(x);
415
        document.getElementById("irregularity").innerHTML = error;
416
    } else {
417
        document.getElementById("irregularity").innerHTML = '';
418
        document.getElementById("more_options").innerHTML = '';
419
        moreoptions(x);
420
    }
95
    }
421
}
96
    if(advancedpatternlocked == 0){
422
97
        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
423
// to dispaly the more options section
98
        return false;
424
function moreoptions(x,y,z){
425
document.getElementById("irregularity").innerHTML = '';
426
document.getElementById("more_options").innerHTML = '';
427
var textbox = '';
428
    // alert("X: "+x+"Y: "+y+"Z: "+z);
429
    if(x){
430
        textbox +="<table id='irregularity_table'>\n<tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
431
        if(y){
432
            textbox +="<th>"+y+"<\/th>";
433
            if(z){
434
                textbox +="<th>"+z+"<\/th>";
435
            }
436
        }
437
        textbox +="<\/tr>\n";
438
        textbox +="<tr><th scope=\"row\">"+text[5]+"<\/td><td><input type='text' name='lastvalue1temp' id='lastvalue1temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue1.value +  "\" /><\/td>\n";
439
        if(y){
440
            textbox +="<td><input type=\"text\" name=\"lastvalue2temp\" id=\"lastvalue2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue2.value + "\" /><\/td>\n";
441
            if(z){
442
                textbox +="<td><input type=\"text\" name=\"lastvalue3temp\" id=\"lastvalue3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue3.value + "\" /><\/td>\n";
443
            }
444
        }
445
        textbox +="<\/tr>\n";
446
        if(y){
447
            textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
448
            textbox +="<td>&nbsp;<\/td>\n";
449
            textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
450
            if(z){
451
                textbox +="<td><input type=\"text\" name=\"whenmorethan3temp\" id=\"whenmorethan3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
452
            }
453
            textbox +="<\/tr>";
454
        } else {
455
          textbox +="<tr> <td>"+_("issues expected")+"<\/td><td><input type=\"text\" name=\"issuesexpected1temp\" id=\"issuesexpected1temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,0)\" value=\"" + document.f.issuesexpected1.value + "\" ><\/td><\/tr>";
456
        }
457
        textbox +="<\/table>\n";
458
    }
99
    }
459
    document.getElementById("more_options").innerHTML = textbox;
100
    if(patternneedtobetested){
460
}
101
        alert(_("Please click on 'Test prediction pattern' before saving subscription."));
461
102
        return false;
462
function hemispheres(chosen){
463
var selbox = document.getElementById("season1");
464
    if(selbox){
465
    var selboxselected = selbox.options[selbox.selectedIndex].value;
466
    selbox.options.length = 0;
467
468
    if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) {
469
        selbox.options[selbox.options.length] = new Option(text[11],'1');
470
        selbox.options[selbox.options.length] = new Option(text[12],'2');
471
        selbox.options[selbox.options.length] = new Option(text[13],'3');
472
        selbox.options[selbox.options.length] = new Option(text[14],'4');
473
        is_hemisphere = 1;
474
        selbox.options[selboxselected-1].selected = true;
475
    }
103
    }
476
104
477
    if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) {
105
    return true;
478
        selbox.options[selbox.options.length] = new Option(text[13],'1');
479
        selbox.options[selbox.options.length] = new Option(text[10],'2');
480
        selbox.options[selbox.options.length] = new Option(text[11],'3');
481
        selbox.options[selbox.options.length] = new Option(text[12],'4');
482
        is_hemisphere = 2;
483
        selbox.options[selboxselected-1].selected = true;
484
    }
485
    }
486
}
106
}
487
107
488
// to display the more options section for seasons
108
function frequencyload(){
489
function moreoptions_seasons(x,y){
109
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
490
// x = 'Season'.  y = 'Year'.
110
        function(freqdata){
491
document.getElementById("irregularity").innerHTML = '';
111
            globalfreqdata=freqdata;
492
document.getElementById("more_options").innerHTML = '';
112
            if ( globalfreqdata.unit.length == 0 ) {
493
var textbox = '';
113
                var option = $("#subtype option[value='issues']");
494
    //alert("X: "+x+"Year: "+y);
114
                $(option).attr('selected', 'selected');
495
    if(x){
115
                $("#subtype option[value!='issues']").attr('disabled', 'disabled')
496
        var hemi_select = parseInt('[% hemisphere %]');
116
            } else {
497
        textbox +="<li><label for=\"hemisphere\">"+ text[7]  +"<\/label><select name=\"hemisphere\" id=\"hemisphere\" onchange=\"hemispheres(this.options[this.selectedIndex].value)\">";
117
                $("#subtype option").attr('disabled', false)
498
        for(var i = 1; i <= 2; i++){
499
            textbox +="<option value='"+i+"'";
500
            if(i == hemi_select){
501
                textbox += " selected "
502
            }
118
            }
503
            textbox +=">"+text[i+7]+"<\/option>";
504
        }
119
        }
505
        textbox +="<\/li>\n";
120
    )
506
        textbox +="<table id=\"seasonal_irregularity\"><tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
507
        textbox +="<th>"+text[16]+"<\/th>";
508
        textbox +="<\/tr>\n";
509
        textbox +="<tr><th scope=\"row\">"+text[5]+"<\/th><td><select name=\"lastvalue2temp\" id=\"lastvalue2temp\" id=\"season1\" onchange=\"moreoptionsupdate(this)\">";
510
        for(var j = 1; j <= 4; j++){
511
            textbox +="<option value='"+j+"'>"+text[j+9]+"<\/option>";
512
        }
513
        textbox +="<\/select><\/td>";
514
        var isyr = irregular_issues.firstissue;
515
        textbox += "<td>" + irregular_issues.firstissue.getFullYear() + "<\/td><\/tr>\n";
516
        textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
517
        textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
518
        textbox +="<\/tr><\/table>\n";
519
    }
520
    document.getElementById("more_options").innerHTML = textbox;
521
}
121
}
522
122
523
function irregularity_check(){
123
function numberpatternload(){
524
    document.f.irreg_check.value = 1; // Irregularity button now pushed
124
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
525
    var periodicity = document.f.periodicity.value;
125
        function(numpatterndata){
526
	var rollover = document.f.issuesexpected1.value;
126
            globalnumpatterndata=numpatterndata;
527
    if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){
127
            if (globalnumpatterndata==undefined){
528
      rollover = document.f.whenmorethan2.value;
128
                return false;
529
    }
129
            }
530
    if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){
130
            displaymoreoptions();
531
        // FIXME: Irregularity check assumes that the full prediction pattern repeats each year.
131
            restoreAdvancedPattern();
532
		//  In cases where the outermost periodicity is > 1 year,  
533
		//  e.g. where a volume spans two years, the irregularity check will be incorrect, 
534
        // but you can safely ignore the check, submit the form, and the prediction pattern should be correct.
535
		//  a way to distinguish between these two cases is needed.
536
		rollover = document.f.whenmorethan3.value * document.f.whenmorethan2.value;
537
    }
538
    var error='';
539
    var toobig;
540
    var expected; 
541
    var errortext = "<b>"+_("Warning irregularity detected")+"</b><br \/>";
542
    switch(periodicity){
543
    case "12":
544
        if(rollover < 730) expected =730;
545
        if(rollover > 730) {
546
            expectedover=730;
547
            toobig=1;
548
        }
549
        break;
550
    case "1":
551
        if(rollover < 365) expected =365;
552
        if(rollover > 365) {
553
            expectedover=365;
554
            toobig=1;
555
        }
556
        break;
557
    case "2":
558
        if(rollover < 52) expected =52;
559
        if(rollover > 52){
560
            expectedover=52;
561
            toobig=1;
562
        }
563
        break;
564
    case "3":
565
        if(rollover < 26) expected =26;
566
        if(rollover > 26){
567
            expectedover=26;
568
            toobig=1;
569
        }
570
        break;
571
    case "4":
572
        if(rollover < 17) expected =17;
573
        if(rollover > 17){
574
            expectedover=17;
575
            toobig=1;
576
        }
577
        break;
578
    case "5":
579
        if(rollover < 12) expected =12;
580
        if(rollover > 12){
581
            expectedover=12;
582
            toobig=1;
583
        }
584
        break;
585
    case "6":
586
        if(rollover < 6) expected =6;
587
        if(rollover > 6){
588
            expectedover=6;
589
            toobig=1;
590
        }
591
        break;
592
    case "7":
593
        if(rollover < 4) expected =4;
594
        if(rollover > 4){
595
            expectedover=4;
596
            toobig=1;
597
        }
598
        break;
599
    case "8":
600
        if(rollover < 4) expected =4;
601
        if(rollover > 4){
602
            expectedover=4;
603
            toobig=1;
604
        }
605
        break;
606
    case "9":
607
        if(rollover < 2) expected =2;
608
        if(rollover > 2){
609
            expectedover=2;
610
            toobig=1;
611
        }
612
        break;
613
    case "10":
614
        if(rollover < 1) expected =1;
615
        if(rollover > 1){
616
            expectedover=1;
617
            toobig=1;
618
        }
132
        }
619
        break;
133
    );
620
    default:
621
        break;
622
    }
623
    if(expected){
624
        if(expected == 365 || expected==730){  // what about leap years ?
625
			// FIXME:  We interpret irregularity as which days per week for periodicity==1.
626
			//  We need two cases: one in which we're published n days/week, in which case irregularity should be per week,
627
			//  and a regular daily pub, where irregularity should be per year.
628
            errortext += _("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
629
        } else {
630
            errortext +=expected+_(" issues expected, ")+rollover+_(" were entered.")+"<br \/>"+_("Please indicate which date(s) an issue is not expected")+"<br \/>";
631
            irregular_issues.numskipped = expected - rollover;
632
		}
633
        errortext +="<select multiple id=\"irregularity_select\" name=\"irregularity_select\" onchange=\"irregular_issues.update();\">\n";
634
		errortext +=irregular_options(periodicity);
635
		errortext += "<\/select>\n <textarea rows=\"6\" width=\"18\" id=\"irregularity_summary\" name=\"irregularity_summary\" value=\"foo\"><\/textarea>";
636
        error=errortext;
637
    }
638
    if(toobig){
639
        errortext +=expectedover+_(" issues expected, ")+rollover+_(" were entered")+"<p class=\"warning\">"+_("You seem to have indicated more issues per year than expected.<\/p>");
640
        error=errortext;
641
    }
642
    if(error.length ==0){
643
        error=_("No irregularities noticed");
644
    }
645
	display_example(expected);
646
    document.getElementById("irregularity").innerHTML = error;
647
	irregular_issues.update();
648
}
134
}
649
135
650
function irregular_options(periodicity){
136
function displaymoreoptions() {
651
    var titles;
137
    if(globalnumpatterndata == undefined){
652
    var count;
138
        $("#moreoptionst").hide();
653
    var errortext='';
139
        return false;
654
    var numberpattern = document.getElementById('numberpattern').value;
140
    }
655
    if(periodicity == 1) {
141
656
        expected = 7;
142
    var X = 0, Y = 0, Z = 0;
657
        titles = irregular_issues.daynames;
143
    var numberingmethod = unescape(globalnumpatterndata.numberingmethod);
658
        count = 1;
144
    if(numberingmethod.match(/{X}/)) X = 1;
145
    if(numberingmethod.match(/{Y}/)) Y = 1;
146
    if(numberingmethod.match(/{Z}/)) Z = 1;
147
148
    if(X || Y || Z) {
149
        $("#moreoptionst").show();
150
    } else {
151
        $("#moreoptionst").hide();
659
    }
152
    }
660
    if(periodicity == 2 || periodicity == 3 || periodicity == 4) { 
153
661
        titles = irregular_issues.weeks;
154
    if(X) {
662
		count = 1;
155
        if(globalnumpatterndata.label1) {
663
        if(periodicity==3) {  // 1/2 wks
156
            $("#headerX").html(unescape(globalnumpatterndata.label1));
664
            expected = 26;
665
        } else if(periodicity == 4) { // 1/3 wks
666
            expected = 17;
667
        } else {
157
        } else {
668
            expected = 52;
158
            $("#headerX").html("X");
669
        }
159
        }
160
        $("#headerX").show();
161
        $("#beginsX").show();
162
        $("#innerX").show();
163
    } else {
164
        $("#headerX").hide();
165
        $("#beginsX").hide();
166
        $("#innerX").hide();
167
        $("#lastvaluetemp1").val('');
168
        $("#innerlooptemp1").val('');
670
    }
169
    }
671
    if(periodicity == 5 || periodicity == 6 || periodicity == 7 || periodicity == 8 || periodicity == 9) {
170
    if(Y) {
672
        if(periodicity == 8 && numberpattern==8) {
171
        if(globalnumpatterndata.label2) {
673
            is_season = 1; // setting up from edit page
172
            $("#headerY").html(unescape(globalnumpatterndata.label2));
674
        } 
675
        if(is_season){
676
            titles = irregular_issues.seasons;
677
            expected = 4;
678
            if(is_hemisphere == 2){
679
                count = 2;
680
            } else {
681
                count = 1;
682
            }
683
        } else {
173
        } else {
684
            titles = irregular_issues.months;
174
            $("#headerY").html("Y");
685
            expected = 12;
686
            count = 1;
687
        }
175
        }
176
        $("#headerY").show();
177
        $("#beginsY").show();
178
        $("#innerY").show();
179
    } else {
180
        $("#headerY").hide();
181
        $("#beginsY").hide();
182
        $("#innerY").hide();
183
        $("#lastvaluetemp2").val('');
184
        $("#innerlooptemp2").val('');
688
    }
185
    }
689
	if( !expected) {
186
    if(Z) {
690
		return '';   // don't know how to deal with irregularity.
187
        if(globalnumpatterndata.label3) {
691
	} 	
188
            $("#headerZ").html(unescape(globalnumpatterndata.label3));
692
    for(var j=0;j<expected;j++){   // rch - changed frrom (1..expected).
189
        } else {
693
        if(isArray(titles)){
190
            $("#headerZ").html("Z");
694
            if(count>expected){
695
                count = count-expected;
696
            }
697
            if(is_season && is_hemisphere == 1){
698
                errortext +="<option value='"+((count*3)-2)+"'>"+titles[j]+"<\/option>\n";
699
// alert("value: "+((count*3)-2)+" title: "+titles[j]);
700
            } else if(is_season && is_hemisphere == 2){
701
                errortext +="<option value='"+((count*3)-2)+"'>"+titles[j-1]+"<\/option>\n";
702
// alert("value: "+((count*3)-2)+" title: "+titles[j-1]);
703
            } else {  // all non-seasonal periodicities:
704
                var incr=1; // multiplier for ( 1/n weeks)  patterns; in this case the irreg calc relies on the week# , not the issue#.
705
                if(periodicity==3) {  // 1/2 wks
706
                    incr=2;
707
                } else if(periodicity == 4) { // 1/3 wks
708
                    incr=3;
709
                }
710
                errortext += "<option value='" + (1+j*incr) ;  
711
				if(irregular_issues.irregular(1+incr*j)) {
712
					errortext += "' selected='selected" ;
713
				}
714
				errortext += "'>"+titles[incr*j]+"<\/option>\n";
715
            }
716
            count++;
717
        } else { 
718
            errortext +="<option value='"+j+"'>"+titles+" "+j+"<\/option>\n";
719
        }
191
        }
192
        $("#headerZ").show();
193
        $("#beginsZ").show();
194
        $("#innerZ").show();
195
    } else {
196
        $("#headerZ").hide();
197
        $("#beginsZ").hide();
198
        $("#innerZ").hide();
199
        $("#lastvaluetemp3").val('');
200
        $("#innerlooptemp3").val('');
720
    }
201
    }
721
    return errortext;
722
}
202
}
723
203
204
function toggleAdvancedPattern() {
205
    $("#advancedpredictionpattern").toggle();
206
}
724
207
725
function display_example(expected){
208
function modifyAdvancedPattern() {
726
    var startfrom1 = parseInt(document.f.lastvalue1.value);
209
    $("#patternname").attr("readonly", false).val('');
727
    var startfrom2 = parseInt(document.f.lastvalue2.value);
210
    $("#numberingmethod").attr("readonly", false);
728
    var startfrom3 = parseInt(document.f.lastvalue3.value);
729
    var every1 = parseInt(document.f.every1.value);
730
    var every2 = parseInt(document.f.every2.value);
731
    var every3 = parseInt(document.f.every3.value);
732
    var numberpattern = document.f.numberingmethod.value;
733
    var whenmorethan2 = parseInt(document.f.whenmorethan2.value);
734
    var whenmorethan3 = parseInt(document.f.whenmorethan3.value);
735
    var setto2 = parseInt(document.f.setto2.value);
736
    var setto3 = parseInt(document.f.setto3.value);
737
    var displaytext = _("Based on the information entered, the Numbering Pattern will look like this: ") + "<br \/><ul class=\"numpattern_preview\">";
738
    if(startfrom3>0){
739
        var count=startfrom3-1;
740
        var count2=startfrom2;
741
        for(var i = 0 ; i < 12; i++){
742
            if(count>=whenmorethan3){
743
                count=setto3;
744
                if(count2>=whenmorethan2){
745
                    startfrom1++;
746
                    count2=setto2;
747
                } else {
748
                    count2++;
749
                }
750
            } else {
751
                count++;
752
            }
753
            displaytext += '<li>' + numberpattern.replace(/{Z}/,count) + '<\/li>\n';
754
            displaytext = displaytext.replace(/{Y}/,count2);
755
            displaytext = displaytext.replace(/{X}/,startfrom1);
756
211
757
        }
212
    $("#advancedpredictionpatternt input").each(function() {
758
    }
213
        $(this).attr("readonly", false);
759
    if(startfrom2>0 && !startfrom3){
214
    });
760
        var count=startfrom2-1;
215
    $("#advancedpredictionpatternt select").each(function() {
761
        for(var i=0;i<12;i++){
216
        $(this).attr("disabled", false);
762
            if(count>=whenmorethan2){
217
    });
763
                startfrom1++;
764
                count=setto2;
765
            } else {
766
                count++;
767
            }
768
218
769
            if(is_season){
219
    $("#restoreadvancedpatternbutton").show();
770
                if(is_hemisphere == 2){
220
    $("#saveadvancedpatternbutton").show();
771
                    if(count == 1) {
221
    $("#modifyadvancedpatternbutton").hide();
772
                        displaytext += numberpattern.replace(/{Y}/,text[count+12])+'\n';
222
773
                    } else {
223
    advancedpatternlocked = 0;
774
                        displaytext += numberpattern.replace(/{Y}/,text[count+8])+'\n';
224
}
775
                    }
225
776
                } else {
226
function restoreAdvancedPattern() {
777
                displaytext += numberpattern.replace(/{Y}/,text[count+10])+'\n';
227
    $("#patternname").attr("readonly", true).val(unescape(globalnumpatterndata.label));
778
                }
228
    $("#numberingmethod").attr("readonly", true).val(unescape(globalnumpatterndata.numberingmethod));
779
            } else {
229
780
                displaytext += numberpattern.replace(/{Y}/,count)+'\n';
230
    $("#advancedpredictionpatternt input").each(function() {
781
            }
231
        $(this).attr("readonly", true);
782
            displaytext = displaytext.replace(/{X}/,startfrom1)+'<br \/>\n';
232
        var id = $(this).attr('id');
233
        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
234
            var tempid = id.replace(/(\d)/, "temp$1");
235
            $(this).val($("#"+tempid).val());
236
        } else {
237
            $(this).val(unescape(globalnumpatterndata[id]));
783
        }
238
        }
239
    });
240
    $("#advancedpredictionpatternt select").each(function() {
241
        $(this).attr("disabled", true);
242
        var id = $(this).attr('id');
243
        $(this).val(unescape(globalnumpatterndata[id]));
244
    });
245
246
    $("#restoreadvancedpatternbutton").hide();
247
    $("#saveadvancedpatternbutton").hide();
248
    $("#modifyadvancedpatternbutton").show();
249
250
    advancedpatternlocked = 1;
251
}
252
253
function testPredictionPattern() {
254
    var frequencyid = $("#frequency").val();
255
    var acquidate;
256
    var error = 0;
257
    var error_msg = "";
258
    if(frequencyid == undefined || frequencyid == ""){
259
        error_msg += _("- Frequency is not defined\n");
260
        error ++;
784
    }
261
    }
785
    if(startfrom1>0 && !startfrom2 && !startfrom3){
262
    acquidate = $("#acqui_date").val();
786
        var offset=eval(document.f.issuesexpected1.value);
263
    if(acquidate == undefined || acquidate == ""){
787
        if (!offset){
264
        error_msg += _("- First publication date is not defined\n");
788
            offset = 12 
265
        error ++;
789
        }
790
        for(var i=startfrom1;i<(startfrom1+offset);i+=every1){
791
            displaytext += numberpattern.replace(/{X}/,i)+'<br \/>\n';
792
        }
793
    }
266
    }
794
   //  displaytext = "<div style='padding: 5px; background-color: #CCCCCC'>"+displaytext+"<\/div>";
267
    [% IF (more_than_one_serial) %]
795
    document.getElementById("displayexample").innerHTML = displaytext;
268
      var nextacquidate = $("#nextacquidate").val();
796
}
269
      if(nextacquidate == undefined || nextacquidate == ""){
270
        error_msg += _("- Next issue publication date is not defined\n");
271
        error ++;
272
      }
273
    [% END %]
797
274
798
function isArray(obj) {
275
    if(error){
799
if (obj.constructor.toString().indexOf("Array") == -1)
276
        alert(_("Cannot test prediction pattern for the following reason(s):\n\n")
800
    return false;
277
            + error_msg);
801
else
278
        return false;
802
    return true;
279
    }
803
}
804
280
805
function moreoptionsupdate(inputfield,rollover){
281
    var custompattern = 0;
806
    fieldname = inputfield.name;
282
    if(advancedpatternlocked == 0) {
807
    // find parent element in base table by stripping 'temp' from element name.
283
        custompattern = 1;
808
    basefield = document.getElementById(fieldname.slice(0,-4));
284
    }
809
    var fieldnumber = fieldname.slice(-5,-4);
810
285
811
    basefield.value = inputfield.value;
286
    var ajaxData = {
812
    var patternchoice = document.getElementById("numberpattern").value;
287
        'custompattern': custompattern,
813
    switch(patternchoice){
288
        [% IF (subscriptionid) %]
814
    case "2":
289
            'subscriptionid': [% subscriptionid %],
815
    case "4":
290
        [% END %]
816
    case "5":
291
        [% IF (more_than_one_serial) %]
817
    case "8": // Year, Number.  -- Why not just use Vol, Number withvol==year??
292
          'nextacquidate': nextacquidate,
818
                //  FIXME: this my conflict with innerloop calc below.
293
        [% END %]
819
       if (document.f.lastvalue2temp.value > 0){document.f.innerloop1.value = document.f.lastvalue2temp.value - 1;}
294
        'firstacquidate': acquidate
820
      break;   
295
    };
821
    }  
296
    var ajaxParams = [
822
    if(basefield.name.slice(0,-1) == 'lastvalue' || 'whenmorethan' ) {
297
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
823
        // The enumeration string is held in a positional numeral notation with three positions, X,Y,Z.
298
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
824
        // The last values lastvalue1, lastvalue2,lastvalue3 should match the last received serial's X,Y,Z enumeration.
299
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
825
        // make array indexes start with 1 for consistency with variable names.
300
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
826
        var innerloop = new Array( undefined, document.getElementById('innerloop1'), document.getElementById('innerloop2'), document.getElementById('innerloop3') );
301
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
827
        var lastvalue = new Array( undefined, document.getElementById('lastvalue1').value *1 , document.getElementById('lastvalue2').value *1 , document.getElementById('lastvalue3').value *1  );
302
    ];
828
        var every = new Array( undefined, document.getElementById('every1').value *1 , document.getElementById('every2').value *1 , document.getElementById('every3').value *1  );
303
    for(i in ajaxParams) {
829
        var add = new Array( undefined, document.getElementById('add1').value *1 , document.getElementById('add2').value *1 , document.getElementById('add3').value *1  );
304
        var param = ajaxParams[i];
830
        var whenmorethan = new Array( undefined, document.getElementById('whenmorethan1').value *1 , document.getElementById('whenmorethan2').value *1 , document.getElementById('whenmorethan3').value *1  );
305
        var value = $("#"+param).val();
831
        
306
        if(value.length > 0)
832
       if(rollover){
307
            ajaxData[param] = value;
833
       // calculate rollover  for higher level of periodicity.
834
       // if there are two levels of periodicity, (e.g. vol{X},num{Y},issue{Z}, then every1=every2*whenmorethan2 / add2 .
835
          for(var N=3;N>1;N--){
836
            if( add[N] > 0){
837
                var addN = (add[N]) ? add[N] : 1 ;
838
                var everyN = (document.getElementById('every'+N)) ? document.getElementById('every'+N).value : 1 ;
839
                document.getElementById('every'+(N-1)).value = whenmorethan[N] * everyN / addN ;
840
            }
841
          }
842
        }
843
        innerloop[3].value = ( every[3] > 1 ) ? lastvalue[3] % every[3] : 0 ;
844
        innerloop[2].value = ( every[2] > 1 ) ? lastvalue[3] - 1 : 0 ;
845
        innerloop[1].value = ( every[1] > 1 ) ? 
846
                                    ( whenmorethan[3] > 0 ) ?  (lastvalue[2] - 1) * every[2] + 1* innerloop[2].value 
847
                                                            : lastvalue[2] - 1
848
                                               : 0 ;
849
    }
308
    }
850
     //FIXME : add checks for innerloop || lastvalue .gt. rollover  
309
310
    $.ajax({
311
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
312
        data: ajaxData,
313
        success: function(data) {
314
            $("#displayexample").html(data);
315
            patternneedtobetested = 0;
316
        }
317
    });
851
}
318
}
852
319
320
function saveAdvancedPattern() {
321
    if ($("#patternname").val().length == 0) {
322
        alert(_("Please enter a name for this pattern"));
323
        return false;
324
    }
853
325
854
function check_input(e){
326
    // Check if patternname already exists, and modify pattern
855
    var unicode=e.charCode? e.charCode : e.keyCode
327
    // instead of creating it if so
856
    if (unicode!=8 && unicode !=46 && unicode!=9 && unicode !=13){ // if key isn't backspace or delete
328
    var found = 0;
857
        if (unicode<48||unicode>57) { // if not a number
329
    $("#numberpattern option").each(function(){
858
            alert(_("Needs to be entered in digit form -eg 10"));
330
        if($(this).text() == $("#patternname").val()){
859
            return false // disable key press
331
            found = 1;
332
            return false;
860
        }
333
        }
334
    });
335
    var cnfrm = 1;
336
    if(found){
337
        var msg = _("This pattern name already exists. Do you want to modify it?")
338
            + "\n" + _("Warning: it will modify the pattern for all subscriptions")
339
            + _("that are using it.");
340
        cnfrm = confirm(msg);
861
    }
341
    }
862
}
863
342
864
function addbiblioPopup(biblionumber) {
343
    if(cnfrm) {
865
	var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
344
        var ajaxData = {};
866
	if(biblionumber){ destination += "&biblionumber="+biblionumber; }
345
        var ajaxParams = [
867
 window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
346
            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
868
}
347
            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
348
            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
349
            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
350
        ];
351
        for(i in ajaxParams) {
352
            var param = ajaxParams[i];
353
            var value = $("#"+param).val();
354
            if(value.length > 0)
355
                ajaxData[param] = value;
356
        }
869
357
870
function Plugin(f)
358
        $.getJSON(
871
{
359
            "/cgi-bin/koha/serials/create-numberpattern.pl",
872
	 window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
360
            ajaxData,
361
            function(data){
362
                if (data.numberpatternid) {
363
                    if(found == 0){
364
                        $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
365
                    }
366
                    $("#numberpattern").val(data.numberpatternid);
367
                    numberpatternload();
368
                } else {
369
                    alert(_("Something went wrong. Unable to create a new numbering pattern."));
370
                }
371
            }
372
        );
373
    }
873
}
374
}
874
375
875
function FindAcqui(f)
376
function show_page_1() {
876
{
377
    $("#page_1").show();
877
	 window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
378
    $("#page_2").hide();
379
    $("#page_number").text("1/2");
878
}
380
}
879
381
880
function Find_ISSN(f)
382
function show_page_2() {
881
{
383
    $("#page_1").hide();
882
	 window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
384
    $("#page_2").show();
385
    $("#page_number").text("2/2");
386
    displaymoreoptions();
883
}
387
}
884
388
885
389
886
function Check(f) {
887
    if (f.aqbooksellerid.value.length==0) {
888
        input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
889
		if (input_box==true) {
890
		}
891
		else {
892
			return false;
893
		}
894
    }
895
	if (f.biblionumber.value.length==0) {
896
        alert(_("You must choose or create a biblio"));
897
    } else if(f.startdate.value.length != 0 && f.sublength.value > 0) {
898
        if (f.irreg_check.value == 1) {
899
            document.f.submit();
900
        } else {
901
            if(f.numbering_pattern.value == ''){
902
                alert(_("Please choose a numbering pattern"));
903
            } else {
904
                alert(_("Please check for irregularity by clicking 'Test Prediction Pattern'"));
905
            }
906
        }
907
    } else {
908
        alert(_("You must choose a start date and a subscription length"));
909
    }
910
	if(irregular_issues.numskipped < irregular_issues.skipped.length ) {
911
		alert(_("You have not accounted for all missing issues."));
912
	}
913
    return false;
914
}
915
916
$(document).ready(function() {
390
$(document).ready(function() {
917
    init_pattern();
391
    $("select#frequency").change(function(){
918
    // http://jqueryui.com/demos/datepicker/#date-range
392
        patternneedtobetested = 1;
919
    var dates = $( "#histstartdate, #histenddate" ).datepicker({
393
        $("input[name='enddate']").val('');
920
        changeMonth: true,
394
        frequencyload();
921
        numberOfMonths: 1,
395
    });
922
        onSelect: function( selectedDate ) {
396
    $("select#numberpattern").change(function(){
923
            var option = this.id == "histstartdate" ? "minDate" : "maxDate",
397
        patternneedtobetested = 1;
924
                instance = $( this ).data( "datepicker" );
398
        numberpatternload();
925
                date = $.datepicker.parseDate(
399
    });
926
                    instance.settings.dateFormat ||
400
    $("#subtype").change(function(){
927
                    $.datepicker._defaults.dateFormat,
401
        $("input[name='enddate']").val('');
928
                    selectedDate, instance.settings );
402
    });
929
            dates.not( this ).datepicker( "option", option, date );
403
    $("#sublength").change(function(){
930
        }
404
        $("input[name='enddate']").val('');
405
    });
406
    $("#lastvaluetemp1").keyup(function(){
407
        $("#lastvalue1").val($(this).val());
408
    });
409
    $("#lastvaluetemp2").keyup(function(){
410
        $("#lastvalue2").val($(this).val());
411
    });
412
    $("#lastvaluetemp3").keyup(function(){
413
        $("#lastvalue3").val($(this).val());
414
    });
415
    $("#lastvalue1").keyup(function(){
416
        $("#lastvaluetemp1").val($(this).val());
417
    });
418
    $("#lastvalue2").keyup(function(){
419
        $("#lastvaluetemp2").val($(this).val());
420
    });
421
    $("#lastvalue3").keyup(function(){
422
        $("#lastvaluetemp3").val($(this).val());
931
    });
423
    });
932
424
933
    [% IF ( manualhistory ) %] $("#subscription_form_history").show();[% END %]
425
    $("#innerlooptemp1").keyup(function(){
934
	$("#cancel_manual_history").click(function(){
426
        $("#innerloop1").val($(this).val());
935
		$("#subscription_form_history").hide();
427
    });
936
        $("#manuallist").removeAttr("checked");
428
    $("#innerlooptemp2").keyup(function(){
937
	});
429
        $("#innerloop2").val($(this).val());
938
   	$("#manuallist").click( function(){
430
    });
939
		if($(this).attr("checked")){
431
    $("#innerlooptemp3").keyup(function(){
940
			$("#subscription_form_history").show();
432
        $("#innerloop3").val($(this).val());
941
		} else {
433
    });
942
			$("#subscription_form_history").hide();
434
    $("#innerloop1").keyup(function(){
943
		}
435
        $("#innerlooptemp1").val($(this).val());
944
	}
436
    });
945
	);
437
    $("#innerloop2").keyup(function(){
946
   //  $(".widelabel").attr("width", "300px");  // labels stay skinny in IE7 anyway.
438
        $("#innerlooptemp2").val($(this).val());
947
[% IF ( modify ) %]
439
    });
948
    set_num_pattern_from_template_vars();
440
    $("#innerloop3").keyup(function(){
949
    [% IF ( hemisphere ) %]
441
        $("#innerlooptemp3").val($(this).val());
950
	is_hemisphere = [% hemisphere %] ;
951
    hemispheres();
952
    [% END %]
953
[% END %]
954
[% IF ( irregularity ) %]
955
    irregularity_check();
956
[% END %]
957
    $('#numberpattern').change( function() { 
958
        reset_num_pattern(); 
959
    });
442
    });
960
443
444
    if($("#frequency").val() != ""){
445
        frequencyload();
446
    }
447
    if($("#numberpattern").val() != ""){
448
        numberpatternload();
449
    }
450
961
    var node;
451
    var node;
962
    [% FOREACH field IN dont_export_field_loop %]
452
    [% FOREACH field IN dont_export_field_loop %]
963
        node = $("#[% field.fieldid %]");
453
        node = $("#[% field.fieldid %]");
Lines 967-972 $(document).ready(function() { Link Here
967
            $(node).find("option:first").attr('selected','selected');
457
            $(node).find("option:first").attr('selected','selected');
968
        }
458
        }
969
    [% END %]
459
    [% END %]
460
461
    show_page_1();
970
});
462
});
971
//]]>
463
//]]>
972
</script>
464
</script>
Lines 978-1392 $(document).ready(function() { Link Here
978
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; [% IF ( modify ) %]<a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscriptionid %]"><i>[% bibliotitle |html %]</i></a> &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</div>
470
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; [% IF ( modify ) %]<a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscriptionid %]"><i>[% bibliotitle |html %]</i></a> &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</div>
979
471
980
<div id="doc3" class="yui-t7">
472
<div id="doc3" class="yui-t7">
981
   
473
    <div id="bd">
982
   <div id="bd">
474
        <div class="yui-g">
983
<h1>[% IF ( modify ) %] Modify subscription for <i>[% bibliotitle |html %]</i>[% ELSE %]Add a new subscription[% END %]</h1>
475
            <h1>[% IF ( modify ) %] Modify subscription for <i>[% bibliotitle |html %]</i>[% ELSE %]Add a new subscription[% END %] (<span id="page_number">1/2</span>)</h1>
984
   <div class="yui-g">
476
            <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
985
    <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
477
                [% IF ( modify ) %]
986
[% IF ( modify ) %]
478
                    <input type="hidden" name="op" value="modsubscription" />
987
        <input type="hidden" name="op" value="modsubscription" />
479
                    <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
988
        <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
989
[% ELSE %]
990
        <input type="hidden" name="op" value="addsubscription" />
991
[% END %]
992
<input type="hidden" name="user" value="[% loggedinusername %]" />
993
<input type="hidden" name="irreg_check" value="0" />
994
<input type="hidden" name="issuesexpected1" id="issuesexpected1" value="0" />
995
996
	<div class="yui-u first">
997
    <fieldset id="subscription_add_information" class="rows">
998
	<legend>Subscription details</legend>
999
	<ol>
1000
	    [% IF ( subscriptionid ) %]
1001
        <li><span class="label">Subscription #</span> [% subscriptionid %]</li>
1002
        [% END %]
1003
        <li>
1004
            <label for="aqbooksellerid">Vendor: </label>
1005
            <input type="text" name="aqbooksellerid" id="aqbooksellerid" value="[% aqbooksellerid %]" size="8" /> (<input type="text" name="aqbooksellername" value="[% aqbooksellername %]" disabled="disabled" readonly="readonly" />) <a href="#" onclick="FindAcqui(f)">Search for a vendor</a>
1006
        </li>
1007
        <li>
1008
            <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
1009
            
1010
                <input type="text" name="biblionumber" id="biblionumber" value="[% bibnum %]" size="8" /> 
1011
                (<input type="text" name="title" value="[% bibliotitle %]" disabled="disabled" readonly="readonly" />) <span class="required" title="Subscriptions must be associated with a bibliographic record">Required</span>
1012
               <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a>
1013
		    [% IF ( CAN_user_editcatalogue ) %] 
1014
		       [% IF ( modify ) %]
1015
		       | <a href="#" onclick="addbiblioPopup([% bibnum %]); return false;">Edit biblio</a>
1016
		       [% ELSE %]
1017
		       | <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a>
1018
		       [% END %]
1019
		    [% END %]
1020
	       </div>
1021
            
1022
        </li>
1023
        <li class="radio">
1024
            [% IF ( serialsadditems ) %]
1025
                <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1026
                <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial </label></p>
1027
            [% ELSE %]
1028
                <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1029
                <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial</label></p>
1030
            [% END %]
1031
        </li>
1032
        <li>
1033
            <label for="branchcode">Library:</label>
1034
            
1035
                <select name="branchcode" id="branchcode" style="width: 20em;">
1036
                    [% UNLESS ( Independantbranches ) %]<option value="">None</option>[% END %]
1037
                    [% FOREACH branchloo IN branchloop %][% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
1038
				[% ELSE %]
1039
				<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
1040
				[% END %]
1041
                    [% END %]
1042
                </select> (select a library)
1043
            
1044
        </li>
1045
        <li>
1046
            <label for="location">Location:</label>
1047
            <select name="location" id="location">
1048
                <option value="">None</option>
1049
                [% FOREACH locations_loo IN locations_loop %][% IF ( locations_loo.selected ) %]<option value="[% locations_loo.authorised_value %]" selected="selected">[% locations_loo.lib %]</option>[% ELSE %]<option value="[% locations_loo.authorised_value %]">[% locations_loo.lib %]</option>[% END %][% END %]
1050
            </select>
1051
        </li>
1052
         <li>
1053
            <label for="callnumber">Call number:</label>
1054
            <input type="text" name="callnumber" id="callnumber" value="[% callnumber %]" size="20" />
1055
        </li>
1056
        <li>
1057
            <label for="graceperiod">Grace period:</label> <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s)
1058
        </li>
1059
        <li>
1060
            <label for="notes">OPAC note:</label>
1061
            <textarea name="notes" id="notes" cols="30" rows="2">[% notes %]</textarea>
1062
        </li>
1063
        <li>
1064
            <label for="internalnotes">Nonpublic note:</label>
1065
            <textarea name="internalnotes" id="internalnotes" cols="30" rows="2">[% internalnotes %]</textarea>
1066
        </li>
1067
        <li>
1068
            
1069
               [% IF ( letterloop ) %]
1070
            <label for="letter">Patron notification: </label>
1071
			   <select name="letter" id="letter">
1072
                    <option value="">None</option>
1073
                [% FOREACH letterloo IN letterloop %]
1074
				[% IF ( letterloo.selected ) %]
1075
                    <option value="[% letterloo.value %]" selected="selected">[% letterloo.lettername %]</option>
1076
[% ELSE %]
1077
                    <option value="[% letterloo.value %]">[% letterloo.lettername %]</option>
1078
[% END %]
1079
                [% END %]
1080
                </select> 
1081
                <div class="hint">Select a notice and subscribers will be notified when new issues are received.</div>
1082
            	[% ELSE %]
1083
            <span class="label">Patron notification: </span>
1084
				<div class="hint">To notify patrons of new serial issues, you must <a href="/cgi-bin/koha/tools/letter.pl">define a notice</a>.</div>
1085
				[% END %]
1086
        </li>
1087
		<li>
1088
			 <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label>
1089
			 <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/>
1090
		 </li>
1091
		 <li>
1092
            <label class="widelabel" for="opacdisplaycount">Number of issues to display in OPAC: </label>
1093
			<input type="text" name="opacdisplaycount" id="opacdisplaycount" value="[% opacdisplaycount %]" size="4"/>
1094
		</li>
1095
	</ol>
1096
	</fieldset>
1097
	</div>
1098
	
1099
<div class="yui-u">
1100
<div id="subscription_form_history" style="display:none"><h3 style="display:inline">Subscription history</h3> <a href="#" id="cancel_manual_history">[cancel manual history]</a>
1101
        <p>Hint: you can update the serial history manually. This can be useful for an old subscription or to clean the existing history. Modify these fields with care, as future serial receive will continue to update them automatically.</p>
1102
        <fieldset class="rows">
1103
            <ol>
1104
                <li>
1105
                <label for="histstartdate">Subscription start date: </label>
1106
                <input type="text" name="histstartdate" id="histstartdate" value="[% histstartdate %]" /><div class="hint"> (start date of the 1st subscription)</div>
1107
                </li>
1108
                <li>
1109
                <label for="histenddate">Subscription end date: </label>
1110
                <input type="text" name="histenddate" id="histenddate" value="[% histenddate %]" /> <div class="hint">(if empty, subscription is still active)</div>
1111
                </li>
1112
                <li>
1113
                <label for="recievedlist">Received issues: </label>
1114
                <textarea name="recievedlist" id="recievedlist" cols="60" rows="5">[% recievedlist %]</textarea>
1115
                </li>
1116
                <li>
1117
                <label for="missinglist">Missing issues: </label>
1118
                <textarea name="missinglist" id="missinglist" cols="60" rows="5">[% missinglist %]</textarea>
1119
                </li>
1120
                <li>
1121
                <label for="opacnote">Note for OPAC: </label>
1122
                <textarea name="opacnote" id="opacnote" cols="60" rows="5">[% opacnote %]</textarea>
1123
                </li>
1124
                <li>
1125
                <label for="librariannote">Note for staff: </label>
1126
                <textarea name="librariannote" id="librariannote" cols="60" rows="5">[% librariannote %]</textarea>
1127
                </li>
1128
            </ol>
1129
        </fieldset>
1130
    <fieldset class="action"><input type="submit" value="Save subscription history"  /></fieldset>
1131
</div>
1132
1133
<div id="subscription_form_planning">
1134
	<fieldset class="rows">
1135
	<legend>Serials planning</legend>
1136
    <ol>
1137
        <li>
1138
           <label for="acqui_date"> First issue publication date:</label>
1139
                [% IF ( modify ) %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" disabled="disabled" />
1140
                [% ELSE %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" class="datepicker" />[% END %]
1141
        </li>
1142
           [% IF ( modify ) %]<li><label for="next_acqui_date"> Next issue publication date:</label>
1143
                <input type="text" name="nextacquidate" value="[% nextacquidate %]" size="13" maxlength="10" id="next_acqui_date" class="datepicker" />
1144
                </li>[% END %]
1145
                
1146
        <li>
1147
            <label for="periodicity" class="required">Frequency:</label>
1148
                <select name="periodicity" size="1" id="periodicity" onchange="javascript:document.getElementsByName('manualhist')[0].checked=(this.value==1); reset_num_pattern();">
1149
                <option value="" selected="selected">-- please choose --</option>
1150
                [% IF ( periodicity16 ) %]
1151
                <option value="16" selected="selected">Without periodicity</option>
1152
                [% ELSE %]
1153
                    <option value="16">Without periodicity</option>
1154
                [% END %]
1155
                [% IF ( periodicity48 ) %]
1156
                <option value="48" selected="selected">Unknown</option>
1157
                [% ELSE %]
1158
                <option value="48">Unknown</option>
1159
                [% END %]
1160
                [% IF ( periodicity32 ) %]
1161
                <option value="32" selected="selected">Irregular</option>
1162
                [% ELSE %]
1163
                    <option value="32">Irregular</option>
1164
                [% END %]
1165
1166
                [% IF ( periodicity12 ) %]
1167
                    <option value="12" selected="selected">2/day</option>
1168
                [% ELSE %]
1169
                    <option value="12">2/day</option>
1170
                [% END %]
1171
                [% IF ( periodicity1 ) %]
1172
                    <option value="1" selected="selected">daily (n/week)</option>
1173
                [% ELSE %]
1174
                    <option value="1">daily (n/week)</option>
1175
                [% END %]
1176
                [% IF ( periodicity2 ) %]
1177
                    <option value="2" selected="selected">1/week</option>
1178
                [% ELSE %]
480
                [% ELSE %]
1179
                    <option value="2">1/week</option>
481
                        <input type="hidden" name="op" value="addsubscription" />
1180
                [% END %]
482
                [% END %]
1181
                [% IF ( periodicity3 ) %]
483
                <input type="hidden" name="user" value="[% loggedinusername %]" />
1182
                    <option value="3" selected="selected">1/2 weeks </option>
484
                <input type="hidden" name="irreg_check" value="0" />
1183
                [% ELSE %]
485
1184
                    <option value="3">1/2 weeks </option>
486
                <div id="page_1">
1185
                [% END %]
487
                    <div class="yui-u first">
1186
                [% IF ( periodicity4 ) %]
488
                        <fieldset id="subscription_add_information" class="rows">
1187
                    <option value="4" selected="selected">1/3 weeks</option>
489
                            <legend>Subscription details</legend>
1188
                [% ELSE %]
490
                            <ol>
1189
                    <option value="4">1/3 weeks</option>
491
                                [% IF ( subscriptionid ) %]
1190
                [% END %]
492
                                    <li><span class="label">Subscription #</span> [% subscriptionid %]</li>
1191
                [% IF ( periodicity5 ) %]
493
                                [% END %]
1192
                    <option value="5" selected="selected">1/month</option>
494
                                <li>
1193
                [% ELSE %]
495
                                    <label for="aqbooksellerid">Vendor: </label>
1194
                    <option value="5">1/month</option>
496
                                    <input type="text" name="aqbooksellerid" id="aqbooksellerid" value="[% aqbooksellerid %]" size="8" /> (<input type="text" name="aqbooksellername" value="[% aqbooksellername %]" disabled="disabled" readonly="readonly" />) <a href="#" onclick="FindAcqui(f)">Search for a vendor</a>
1195
                [% END %]
497
                                </li>
1196
                [% IF ( periodicity6 ) %]
498
                                <li>
1197
                    <option value="6" selected="selected">1/2 months (6/year)</option>
499
                                    <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
1198
                [% ELSE %]
500
                                    <input type="text" name="biblionumber" id="biblionumber" value="[% bibnum %]" size="8" />
1199
                    <option value="6">1/2 months (6/year)</option>
501
                                    (<input type="text" name="title" value="[% bibliotitle %]" disabled="disabled" readonly="readonly" />) <span class="required" title="Subscriptions must be associated with a bibliographic record">Required</span>
1200
                [% END %]
502
                                    <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a>
1201
                [% IF ( periodicity7 ) %]
503
                                        [% IF ( CAN_user_editcatalogue ) %]
1202
                    <option value="7" selected="selected">1/3 months (1/quarter)</option>
504
                                            [% IF ( modify ) %]
1203
                [% ELSE %]
505
                                            | <a href="#" onclick="addbiblioPopup([% bibnum %]); return false;">Edit biblio</a>
1204
                    <option value="7">1/3 months (1/quarter)</option>
506
                                            [% ELSE %]
1205
                [% END %]
507
                                            | <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a>
1206
                <!-- periodicity8 is 1/quarter, exactly like periodicity7 but will use it for seasonal option -->
508
                                            [% END %]
1207
                [% IF ( periodicity8 ) %]
509
                                        [% END %]
1208
                    <option value="8" selected="selected">1/quarter (seasonal)</option>
510
                                    </div>
1209
                [% ELSE %]
511
                                </li>
1210
                    <option value="8">1/quarter (seasonal)</option>
512
                                <li class="radio">
1211
                [% END %]
513
                                    [% IF ( serialsadditems ) %]
1212
                [% IF ( periodicity13 ) %]
514
                                        <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1213
                    <option value="13" selected="selected">1/4 months (3/year)</option>
515
                                        <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial </label></p>
1214
                [% ELSE %]
516
                                    [% ELSE %]
1215
                    <option value="13">1/4 months (3/year)</option>
517
                                        <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1216
                [% END %]
518
                                        <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial</label></p>
1217
519
                                    [% END %]
1218
                [% IF ( periodicity9 ) %]
520
                                </li>
1219
                    <option value="9" selected="selected">2/year</option>
521
                                <li class="radio">
1220
                [% ELSE %]
522
                                  <p>When there is an irregular issue:</p>
1221
                    <option value="9">2/year</option>
523
                                  [% IF (skip_serialseq) %]
1222
                [% END %]
524
                                    <p>
1223
                [% IF ( periodicity10 ) %]
525
                                      <input type="radio" id="skip_serialseq_yes" name="skip_serialseq" value="1" checked="checked" />
1224
                    <option value="10" selected="selected">1/year</option>
526
                                      <label for="skip_serialseq_yes">Skip issue number</label>
1225
                [% ELSE %]
527
                                    </p>
1226
                    <option value="10">1/year</option>
528
                                    <p>
1227
                [% END %]
529
                                      <input type="radio" id="skip_serialseq_no" name="skip_serialseq" value="0" />
1228
                [% IF ( periodicity11 ) %]
530
                                      <label for="skip_serialseq_no">Keep issue number</label>
1229
                    <option value="11" selected="selected">1/2 years</option>
531
                                    </p>
1230
                [% ELSE %]
532
                                  [% ELSE %]
1231
                    <option value="11">1/2 years</option>
533
                                    <p>
1232
                [% END %]
534
                                      <input type="radio" id="skip_serialseq_yes" name="skip_serialseq" value="1" />
1233
                </select> <span class="required">Required</span></li>
535
                                      <label for="skip_serialseq_yes">Skip issue number</label>
1234
                <li>
536
                                    </p>
1235
                    <label for="manuallist"> Manual history:</label>
537
                                    <p>
1236
                    [% IF ( manualhistory ) %]
538
                                      <input type="radio" id="skip_serialseq_no" name="skip_serialseq" value="0" checked="checked" />
1237
                        <input type="checkbox" name="manualhist" id="manuallist" value="1" checked="checked" />
539
                                      <label for="skip_serialseq_no">Keep issue number</label>
1238
                    [% ELSE %]
540
                                    </p>
1239
                        <input type="checkbox" name="manualhist" id="manuallist" value="1" />
541
                                  [% END %]
1240
                    [% END %]
542
                                </li>
1241
                </li>
543
                                <li>
1242
        <li>
544
                                    <label for="manualhistory">Manual history</label>
1243
           <label for="numberpattern"> Numbering pattern:</label>
545
                                    [% IF (manualhistory) %]
1244
            
546
                                        <input type="checkbox" id="manualhistory" name="manualhist" checked="checked" />
1245
                <select name="numbering_pattern" size="1" id="numberpattern" >
547
                                    [% ELSE %]
1246
                    <option value="" selected="selected">-- please choose --</option>
548
                                        <input type="checkbox" id="manualhistory" name="manualhist" />
1247
                    [% IF ( numberpattern1 ) %]
549
                                    [% END %]
1248
                        <option value="1" selected="selected">Number</option>
550
                                </li>
1249
                    [% ELSE %]
551
                                <li>
1250
                        <option value="1">Number</option>
552
                                    <label for="callnumber">Call number</label>
1251
                    [% END %]
553
                                    <input type="text" name="callnumber" id="callnumber" value="[% callnumber %]" size="20" />
1252
                    [% IF ( numberpattern2 ) %]
554
                                </li>
1253
                        <option value="2" selected="selected">Volume, number, issue</option>
555
                                <li>
1254
                    [% ELSE %]
556
                                    <label for="branchcode">Library:</label>
1255
                        <option value="2">Volume, number, issue</option>
557
                                    <select name="branchcode" id="branchcode" style="width: 20em;">
1256
                    [% END %]
558
                                        [% UNLESS ( Independantbranches ) %]
1257
                    [% IF ( numberpattern3 ) %]
559
                                            <option value="">None</option>
1258
                        <option value="3" selected="selected">Volume, number</option>
560
                                        [% END %]
1259
                    [% ELSE %]
561
                                        [% FOREACH branchloo IN branchloop %]
1260
                        <option value="3">Volume, number</option>
562
                                            [% IF ( branchloo.selected ) %]
1261
                    [% END %]
563
                                                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
1262
                    [% IF ( numberpattern4 ) %]
564
                                            [% ELSE %]
1263
                        <option value="4" selected="selected">Volume, issue</option>
565
                                                <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
1264
                    [% ELSE %]
566
                                            [% END %]
1265
                        <option value="4">Volume, issue</option>
567
                                        [% END %]
1266
                    [% END %]
568
                                    </select> (select a library)
1267
                    [% IF ( numberpattern5 ) %]
569
                                </li>
1268
                        <option value="5" selected="selected">Number, issue</option>
570
                                <li>
1269
                    [% ELSE %]
571
                                    <label for="notes">Public note:</label>
1270
                        <option value="5">Number, issue</option>
572
                                    <textarea name="notes" id="notes" cols="30" rows="2">[% notes %]</textarea>
1271
                    [% END %]
573
                                </li>
1272
                    [% IF ( numberpattern6 ) %]
574
                                <li>
1273
                        <option value="6" selected="selected">Seasonal only</option>
575
                                    <label for="internalnotes">Nonpublic note:</label>
1274
                    [% ELSE %]
576
                                    <textarea name="internalnotes" id="internalnotes" cols="30" rows="2">[% internalnotes %]</textarea>
1275
                        <option value="6">Seasonal only</option>
577
                                </li>
1276
                    [% END %]
578
                                <li>
1277
                    [% IF ( numberpattern8 ) %]
579
                                    [% IF ( letterloop ) %]
1278
                        <option value="8" selected="selected">Year/Number</option>
580
                                        <label for="letter">Patron notification: </label>
1279
                    [% ELSE %]
581
                                        <select name="letter" id="letter">
1280
                        <option value="8">Year/Number</option>
582
                                            <option value="">None</option>
1281
                    [% END %]          
583
                                            [% FOREACH letterloo IN letterloop %]
1282
                    [% IF ( numberpattern7 ) %]
584
                                                [% IF ( letterloo.selected ) %]
1283
                        <option value="7" selected="selected">None of the above</option>
585
                                                    <option value="[% letterloo.value %]" selected="selected">[% letterloo.lettername %]</option>
1284
                    [% ELSE %]
586
                                                [% ELSE %]
1285
                        <option value="7">None of the above</option>
587
                                                    <option value="[% letterloo.value %]">[% letterloo.lettername %]</option>
1286
                    [% END %]
588
                                                [% END %]
1287
                </select>
589
                                            [% END %]
1288
        </li>
590
                                        </select>
1289
                <li id="more_options"></li>
591
                                        <div class="hint">Select a notice and patrons on the routing list will be notified when new issues are received.</div>
1290
                <li id="irregularity"></li>
592
                                    [% ELSE %]
1291
   	           <li id="displayexample"></li>
593
                                        <span class="label">Patron notification: </span>
1292
        <li>
594
                                        <div class="hint">To notify patrons of new serial issues, you must <a href="/cgi-bin/koha/tools/letter.pl">define a notice</a>.</div>
1293
           <label for="from" class="required"> Subscription start date:</label>
595
                                    [% END %]
1294
                <input type="text" name="startdate" value="[% startdate %]" size="13" maxlength="10" id="from" class="datepickerfrom" />
596
                                </li>
1295
            <span class="required">Required</span>
597
                                <li>
1296
        </li>
598
                                    <label for="location">Location:</label>
1297
        <li>
599
                                    <select name="location" id="location">
1298
            <label for="subtype" class="required">Subscription length:</label>
600
                                        <option value="">None</option>
1299
            
601
                                        [% FOREACH locations_loo IN locations_loop %]
1300
                <select name="subtype" id="subtype">
602
                                            [% IF ( locations_loo.selected ) %]
1301
                    [% IF ( subtype_monthlength ) %]<option value="monthlength" selected="selected">[% ELSE %]<option value="monthlength">[% END %] Number of months</option>
603
                                                <option value="[% locations_loo.authorised_value %]" selected="selected">[% locations_loo.lib %]</option>
1302
                    [% IF ( subtype_numberlength ) %]<option value="numberlength" selected="selected">[% ELSE %]<option value="numberlength">[% END %] Number of issues</option>
604
                                            [% ELSE %]
1303
                    [% IF ( subtype_weeklength ) %]<option value="weeklength" selected="selected">[% ELSE %]<option value="weeklength">[% END %] Number of weeks</option>
605
                                                <option value="[% locations_loo.authorised_value %]">[% locations_loo.lib %]</option>
1304
                </select>
606
                                            [% END %]
1305
                <input type="text" id="numberlength" name="sublength" value="[% sublength %]" size="3" onkeypress="return check_input(event)" /> (enter amount in numerals)
607
                                        [% END %]
1306
            <span class="required">Required</span>
608
                                    </select>
1307
        </li>
609
                                </li>
1308
        <li>
610
                                <li>
1309
           <label for="to"> Subscription end date:</label>
611
                                    <label for="graceperiod">Grace period:</label>
1310
                <input type="text" name="enddate" value="[% enddate %]" size="13" maxlength="10" id="to" class="datepickerto" />
612
                                    <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s)
1311
        </li>
613
                                </li>
1312
    <li><label for="numberingmethod">Numbering formula:</label> <input type="text" name="numberingmethod" id="numberingmethod" value="[% numberingmethod %]" />
614
                                <li>
1313
    </li>
615
                                     <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label>
1314
    </ol>
616
                                     <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/>
1315
	</fieldset>
617
                                 </li>
1316
618
                                 <li>
1317
	<fieldset class="action">
619
                                    <label class="widelabel" for="opacdisplaycount">Number of issues to display to the public: </label>
1318
    <input type="button" class="action_test" value="Test prediction pattern" onclick="javascript:irregularity_check()" />
620
                                    <input type="text" name="opacdisplaycount" id="opacdisplaycount" value="[% opacdisplaycount %]" size="4"/>
1319
    <input type="button" class="action_reset" value="Reset pattern" onclick="javascript:reset_pattern()" />
621
                                </li>
1320
    <input type="button" class="action_save"  value="Save subscription" onclick="Check(this.form)" accesskey="w" />
622
                            </ol>
1321
	</fieldset>
623
                        </fieldset>
1322
    <fieldset class="action">
624
                        <fieldset class="action">
1323
    <input type="button" class="action_advanced" value="Show/Hide advanced pattern" onclick="javascript:display_table()" />
625
                            <input type="button" value="Next >>" onclick="if ( Check_page1() ) show_page_2();" style="float:right;" />
1324
    </fieldset>
626
                        </fieldset>
1325
           <div id="basetable"  style="display: none;">
627
                    </div>
1326
            <table class="small">
628
                </div>
1327
                <tr><th colspan="4">Advanced prediction pattern</th></tr>
629
1328
				<tr>
630
                <div id="page_2">
1329
                    <th>&nbsp;</th>
631
                    <div class="yui-u first">
1330
                    <th>X</th>
632
                        <div id="subscription_form_planning">
1331
                    <th>Y</th>
633
                            <fieldset class="rows">
1332
                    <th>Z</th>
634
                                <legend>Serials planning</legend>
1333
                </tr>
635
                                <ol>
1334
                <tr>
636
                                    <li>
1335
                    <td>Add</td>
637
                                        <label for="firstacquidate">First issue publication date: (*)</label>
1336
                    <td>
638
                                        [% UNLESS (more_than_one_serial) %]
1337
                        <input type="text" name="add1" id="add1" value="[% add1 %]" />
639
                                          <input type="text" size="10" id="acqui_date" name="firstacquidate" value="[% firstacquidate | $KohaDates %]" class="datepicker" readonly="readonly"/>
1338
                    </td>
640
                                        [% ELSE %]
1339
                    <td>
641
                                          [% firstacquidate | $KohaDates %]
1340
                        <input type="text" name="add2" id="add2" value="[% add2 %]" />
642
                                          <input type="hidden" size="10" id="acqui_date" name="firstacquidate" value="[% firstacquidate | $KohaDates %]"/>
1341
                    </td>
643
                                        [% END %]
1342
                    <td>
644
                                    </li>
1343
                        <input type="text" name="add3" id="add3" value="[% add3 %]" />
645
                                    [% IF (more_than_one_serial) %]
1344
                    </td>
646
                                      <li>
1345
                </tr>
647
                                        <label for="nextacquidate">Next issue publication date:</label>
1346
                <tr>
648
                                        <input type="text" size="10" id="nextacquidate" name="nextacquidate" value="[% nextacquidate | $KohaDates %]" class="datepicker" readonly="readonly"/>
1347
                    <td>once every</td>
649
                                      </li>
1348
                    <td><input type="text" name="every1" id="every1" value="[% every1 %]" /></td>
650
                                    [% END %]
1349
                    <td><input type="text" name="every2" id="every2" value="[% every2 %]" /></td>
651
                                    <li>
1350
                    <td><input type="text" name="every3" id="every3" value="[% every3 %]" /></td>
652
                                        <label for="frequency">Frequency: (*)</label>
1351
                </tr>
653
                                        <select name="frequency" size="1" id="frequency">
1352
                <tr>
654
                                            <option value="">-- please choose --</option>
1353
                    <td>When more than</td>
655
                                            [% FOREACH frequency IN frequencies %]
1354
                    <td><input type="text" name="whenmorethan1" id="whenmorethan1" value="[% whenmorethan1 %]" /></td>
656
                                                [% IF (frequency.selected) %]
1355
                    <td><input type="text" name="whenmorethan2" id="whenmorethan2" value="[% whenmorethan2 %]" /></td>
657
                                                    <option value="[% frequency.id %]" selected="selected">
1356
                    <td><input type="text" name="whenmorethan3" id="whenmorethan3" value="[% whenmorethan3 %]" /></td>
658
                                                [% ELSE %]
1357
                </tr>
659
                                                    <option value="[% frequency.id %]">
1358
                <tr>
660
                                                [% END %]
1359
                    <td>inner counter</td>
661
                                                    [% frequency.label %]
1360
                    <td><input type="text" name="innerloop1" id="innerloop1" value="[% innerloop1 %]" /></td>
662
                                                </option>
1361
                    <td><input type="text" name="innerloop2" id="innerloop2" value="[% innerloop2 %]" /></td>
663
                                            [% END %]
1362
                    <td><input type="text" name="innerloop3" id="innerloop3" value="[% innerloop3 %]" /></td>
664
                                        </select>
1363
                </tr>
665
                                    </li>
1364
                <tr>
666
                                    <li>
1365
                    <td>Set back to</td>
667
                                        <label for="subtype">Subscription length:</label>
1366
                    <td><input type="text" name="setto1" id="setto1" value="[% setto1 %]" /></td>
668
                                        <select name="subtype" id="subtype">
1367
                    <td><input type="text" name="setto2" id="setto2" value="[% setto2 %]" /></td>
669
                                            [% FOREACH subt IN subtype %]
1368
                    <td><input type="text" name="setto3" id="setto3" value="[% setto3 %]" /></td>
670
                                                [% IF (subt.selected) %]
1369
                </tr>
671
                                                    <option value="[% subt.name %]" selected="selected">
1370
                <tr>
672
                                                [% ELSE %]
1371
                    <td>
673
                                                    <option value="[% subt.name %]">
1372
                        [% IF ( modify ) %]
674
                                                [% END %]
1373
                            Last value
675
                                                    [% subt.name %]
1374
                        [% ELSE %]
676
                                                </option>
1375
                            Begins with
677
                                            [% END %]
1376
                        [% END %]
678
                                        </select>
1377
                    </td>
679
                                        <input type="text" name="sublength" id="sublength" value="[% sublength %]" size="3" /> (enter amount in numerals)
1378
                    <td><input type="text" name="lastvalue1" id="lastvalue1" value="[% lastvalue1 %]" /></td>
680
                                        <input type="hidden" name="issuelengthcount">
1379
                    <td><input type="text" name="lastvalue2" id="lastvalue2" value="[% lastvalue2 %]" /></td>
681
                                    </li>
1380
                    <td><input type="text" name="lastvalue3" id="lastvalue3" value="[% lastvalue3 %]" /></td>
682
                                    <li>
1381
                </tr>
683
                                        <label for="startdate"> Subscription start date: (*)</label>
1382
            </table>
684
                                        <input type="text" size="10" id="from" name="startdate" value="[% startdate | $KohaDates %]" class="datepickerfrom" readonly="readonly"/>
685
                                    </li>
686
                                    <li>
687
                                        <label for="enddate">Subscription end date:</label>
688
                                        <input type="text" size="10" id="to" name="enddate" value="[% enddate | $KohaDates %]" class="datepickerto" readonly="readonly"/>
689
                                    </li>
690
                                    <li>
691
                                        <label for="numberpattern">Numbering pattern:</label>
692
                                        <select name="numbering_pattern" size="1" id="numberpattern">
693
                                            <option value="">-- please choose --</option>
694
                                            [% FOREACH numberpattern IN numberpatterns %]
695
                                                [% IF (numberpattern.selected) %]
696
                                                    <option value="[% numberpattern.id %]">
697
                                                [% ELSE %]
698
                                                    <option value="[% numberpattern.id %]">
699
                                                [% END %]
700
                                                    [% numberpattern.label %]
701
                                                </option>
702
                                            [% END %]
703
                                        </select>
704
                                    </li>
705
                                    <li>
706
                                        <label for="locale">Locale</label>
707
                                        <select id="locale" name="locale">
708
                                            <option value=""></option>
709
                                            [% FOREACH locale IN locales %]
710
                                                <option value="[% locale %]">
711
                                                    [% locale %]
712
                                                </option>
713
                                            [% END %]
714
                                        </select>
715
                                        <span class="hint">If empty, system locale is used</span>
716
                                    </li>
717
                                    <li id="more_options">
718
                                        <table id="moreoptionst">
719
                                            <thead>
720
                                                <tr>
721
                                                    <th>&nbsp;</th>
722
                                                    <th id="headerX">&nbsp;</th>
723
                                                    <th id="headerY">&nbsp;</th>
724
                                                    <th id="headerZ">&nbsp;</th>
725
                                                </tr>
726
                                            </thead>
727
                                            <tbody>
728
                                                <tr>
729
                                                    <td>
730
                                                      [% IF (more_than_one_serial) %]
731
                                                        Last value
732
                                                      [% ELSE %]
733
                                                        Begins with
734
                                                      [% END %]
735
                                                    </td>
736
                                                    <td id="beginsX"><input type="text" id="lastvaluetemp1" name="lastvaluetemp1" value="[% lastvalue1 %]" /></td>
737
                                                    <td id="beginsY"><input type="text" id="lastvaluetemp2" name="lastvaluetemp2" value="[% lastvalue2 %]" /></td>
738
                                                    <td id="beginsZ"><input type="text" id="lastvaluetemp3" name="lastvaluetemp3" value="[% lastvalue3 %]" /></td>
739
                                                </tr>
740
                                                <tr>
741
                                                    <td>Inner counter</td>
742
                                                    <td id="innerX"><input type="text" id="innerlooptemp1" name="innerlooptemp1" value="[% innerloop1 %]" /></td>
743
                                                    <td id="innerY"><input type="text" id="innerlooptemp2" name="innerlooptemp2" value="[% innerloop2 %]" /></td>
744
                                                    <td id="innerZ"><input type="text" id="innerlooptemp3" name="innerlooptemp3" value="[% innerloop3 %]" /></td>
745
                                                </tr>
746
                                            </tbody>
747
                                        </table>
748
                                    </li>
749
                                    <li><a style="cursor:pointer" onclick="toggleAdvancedPattern();">Show/Hide advanced pattern</a></li>
750
                                    <div id="advancedpredictionpattern" style="display:none">
751
                                      <li>
752
                                        <label for="patternname">Pattern name: (*)</label>
753
                                        <input id="patternname" name="patternname" type="text" readonly="readonly" />
754
                                      </li>
755
                                      <li>
756
                                        <label for="numberingmethod">Numbering formula:</label>
757
                                        <input readonly="readonly" type="text" name="numberingmethod" id="numberingmethod" size="50" value="[% numberingmethod %]" />
758
                                      </li>
759
                                        <table id="advancedpredictionpatternt">
760
                                            <thead>
761
                                                <tr>
762
                                                    <th colspan="4">Advanced prediction pattern</td>
763
                                                </tr>
764
                                                <tr>
765
                                                    <th>&nbsp;</th>
766
                                                    <th>X</th>
767
                                                    <th>Y</th>
768
                                                    <th>Z</th>
769
                                                </tr>
770
                                            </thead>
771
                                            <tbody>
772
                                                <tr>
773
                                                    <td>Label</td>
774
                                                    <td><input type="text" readonly="readonly" id="label1" name="label1" /></td>
775
                                                    <td><input type="text" readonly="readonly" id="label2" name="label2" /></td>
776
                                                    <td><input type="text" readonly="readonly" id="label3" name="label3" /></td>
777
                                                </tr>
778
                                                <tr>
779
                                                    <td>Begins with</td>
780
                                                    <td><input type="text" readonly="readonly" id="lastvalue1" name="lastvalue1" /></td>
781
                                                    <td><input type="text" readonly="readonly" id="lastvalue2" name="lastvalue2" /></td>
782
                                                    <td><input type="text" readonly="readonly" id="lastvalue3" name="lastvalue3" /></td>
783
                                                </tr>
784
                                                <tr>
785
                                                    <td>Add</td>
786
                                                    <td><input type="text" readonly="readonly" id="add1" name="add1" /></td>
787
                                                    <td><input type="text" readonly="readonly" id="add2" name="add2" /></td>
788
                                                    <td><input type="text" readonly="readonly" id="add3" name="add3" /></td>
789
                                                </tr>
790
                                                <tr>
791
                                                    <td>Every</td>
792
                                                    <td><input type="text" readonly="readonly" id="every1" name="every1" /></td>
793
                                                    <td><input type="text" readonly="readonly" id="every2" name="every2" /></td>
794
                                                    <td><input type="text" readonly="readonly" id="every3" name="every3" /></td>
795
                                                </tr>
796
                                                <tr>
797
                                                    <td>Set back to</td>
798
                                                    <td><input type="text" readonly="readonly" id="setto1" name="setto1" /></td>
799
                                                    <td><input type="text" readonly="readonly" id="setto2" name="setto2" /></td>
800
                                                    <td><input type="text" readonly="readonly" id="setto3" name="setto3" /></td>
801
                                                </tr>
802
                                                <tr>
803
                                                    <td>When more than</td>
804
                                                    <td><input type="text" readonly="readonly" id="whenmorethan1" name="whenmorethan1" /></td>
805
                                                    <td><input type="text" readonly="readonly" id="whenmorethan2" name="whenmorethan2" /></td>
806
                                                    <td><input type="text" readonly="readonly" id="whenmorethan3" name="whenmorethan3" /></td>
807
                                                </tr>
808
                                                <tr>
809
                                                    <td>Inner counter</td>
810
                                                    <td><input type="text" readonly="readonly" id="innerloop1" name="innerloop1" /></td>
811
                                                    <td><input type="text" readonly="readonly" id="innerloop2" name="innerloop2" /></td>
812
                                                    <td><input type="text" readonly="readonly" id="innerloop3" name="innerloop3" /></td>
813
                                                </tr>
814
                                                <tr>
815
                                                    [% BLOCK numbering_select %]
816
                                                        <select disabled="disabled" id="[% name %]" name="[% name %]" />
817
                                                            <option value=""></option>
818
                                                            <option value="dayname">Name of day</option>
819
                                                            <option value="monthname">Name of month</option>
820
                                                            <option value="season">Name of season</option>
821
                                                        </select>
822
                                                    [% END %]
823
                                                    <td>Formatting</td>
824
                                                    <td>[% PROCESS numbering_select name="numbering1" %]</td>
825
                                                    <td>[% PROCESS numbering_select name="numbering2" %]</td>
826
                                                    <td>[% PROCESS numbering_select name="numbering3" %]</td>
827
                                                </tr>
828
                                            </tbody>
829
                                        </table>
830
                                        <input id="modifyadvancedpatternbutton" type="button" value="Modify pattern" onclick="modifyAdvancedPattern();" />
831
                                        <input id="restoreadvancedpatternbutton" type="button" value="Cancel modifications" onclick="restoreAdvancedPattern();" style="display:none" />
832
                                        <input id="saveadvancedpatternbutton" type="button" value="Save as new pattern" onclick="saveAdvancedPattern();" style="display:none" />
833
                                    </div>
834
                                </ol>
835
                            </fieldset>
836
                            <fieldset class="action">
837
                                <input type="button" value="<< Previous" onclick="show_page_1();" style="float:left;"/>
838
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" onclick="testPredictionPattern();" />
839
                                <input type="button" value="Save subscription" onclick="if (Check_page2()) submit();" style="float:right;" accesskey="w" />
840
                            </fieldset>
841
                        </div>
842
                    </div>
843
                    <div class="yui-u">
844
                        <li id="displayexample"></li>
845
                    </div>
846
                </div>
847
            </form>
1383
        </div>
848
        </div>
1384
849
    </div>
1385
</div>
1386
</div>
1387
</form>
1388
</div>
1389
1390
</div>
850
</div>
1391
851
1392
[% INCLUDE 'intranet-bottom.inc' %]
852
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-112 / +31 lines)
Lines 9-29 var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_(" Link Here
9
"Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
9
"Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
10
10
11
11
12
// to display the options section
13
function options(x,y,z){
14
var textbox = '';
15
    // alert("X: "+x+"Y: "+y+"Z: "+z);
16
    if(x){
17
        document.f.xfield.value = x;
18
        if(y){
19
            document.f.yfield.value = y;
20
            if(z){
21
                document.f.zfield.value = z;
22
            }
23
        }
24
    }
25
}
26
27
function confirm_deletion() {
12
function confirm_deletion() {
28
    var is_confirmed = confirm(_("Are you sure you want to delete this subscription?"));
13
    var is_confirmed = confirm(_("Are you sure you want to delete this subscription?"));
29
    if (is_confirmed) {
14
    if (is_confirmed) {
Lines 108-113 $(document).ready(function() { Link Here
108
        [% ELSE %]
93
        [% ELSE %]
109
            <li><span class="label">Items:</span> Serial receipt does not create an item record.</li>
94
            <li><span class="label">Items:</span> Serial receipt does not create an item record.</li>
110
        [% END %]
95
        [% END %]
96
        <li>
97
            <span class="label">Serial number:</span>
98
            [% IF skip_serialseq %]
99
                Serial number is skipped when an irregularity is found.
100
            [% ELSE %]
101
                Serial number is kept when an irregularity is found.
102
            [% END %]
103
        </li>
111
        <li><span class="label">Grace period:</span> [% graceperiod %]</li>
104
        <li><span class="label">Grace period:</span> [% graceperiod %]</li>
112
        </ol>
105
        </ol>
113
    </div>
106
    </div>
Lines 138-255 $(document).ready(function() { Link Here
138
        <ol>
131
        <ol>
139
            <li><span class="label">Beginning date:</span> [% startdate %]
132
            <li><span class="label">Beginning date:</span> [% startdate %]
140
            </li>
133
            </li>
141
            <li><span class="label">Frequency (*):</span>
134
            <li><span class="label">Frequency:</span>
142
                [% IF ( periodicity16 ) %]
135
                [% frequency.description %]
143
                        Without regularity
144
                [% END %]
145
                [% IF ( periodicity32 ) %]
146
                        Irregular
147
                [% END %]
148
                [% IF ( periodicity0 ) %]
149
                        Unknown
150
                [% END %]
151
                [% IF ( periodicity12 ) %]
152
                        2/day
153
                [% END %]
154
                [% IF ( periodicity1 ) %]
155
                        1/day
156
                [% END %]
157
                [% IF ( periodicity13 ) %]
158
                        1/4 months (3/year)
159
                [% END %]
160
                [% IF ( periodicity2 ) %]
161
                        1/week
162
                [% END %]
163
                [% IF ( periodicity3 ) %]
164
                        1/2 weeks
165
                [% END %]
166
                [% IF ( periodicity4 ) %]
167
                        1/3 weeks
168
                [% END %]
169
                [% IF ( periodicity5 ) %]
170
                        1/month
171
                [% END %]
172
                [% IF ( periodicity6 ) %]
173
                        1/2 months (6/year)
174
                [% END %]
175
                [% IF ( periodicity7 ) %]
176
                        1/quarter
177
                [% END %]
178
                [% IF ( periodicity8 ) %]
179
                        1/quarter
180
                [% END %]
181
                [% IF ( periodicity9 ) %]
182
                        2/year
183
                [% END %]
184
                [% IF ( periodicity10 ) %]
185
                        1/year
186
                [% END %]
187
                [% IF ( periodicity11 ) %]
188
                        1/2 years
189
                [% END %]
190
            </li>
136
            </li>
191
            <li>
137
            <li>
192
              <span class="label">Manual history: </span>
138
              <span class="label">Manual history: </span>
193
                [% IF ( manualhistory ) %]
139
                [% IF ( manualhistory ) %]
194
                    Enabled
140
                    Enabled <a href="/cgi-bin/koha/serials/subscription-history.pl?subscriptionid=[% subscriptionid %]">Edit history</a>
195
                [% ELSE %]
141
                [% ELSE %]
196
                    Disabled
142
                    Disabled
197
                [% END %]
143
                [% END %]
198
            </li>
144
            </li>
199
            <li><span class="label">Number pattern:</span>
145
            <li><span class="label">Number pattern:</span>
200
                [% IF ( numberpattern1 ) %]
146
                [% numberpattern.label %]
201
                    Number only
147
            </li>
202
                [% END %]
148
            <li><table>
203
                [% IF ( numberpattern2 ) %]
149
            <tr>
204
                    Volume, number, issue
150
                <td>Starting with:</td>
205
                [% END %]
151
                [% IF (has_X) %]
206
                [% IF ( numberpattern3 ) %]
152
                    <td align="center">[% lastvalue1 %]</td>
207
                    Volume, number
208
                [% END %]
153
                [% END %]
209
                [% IF ( numberpattern4 ) %]
154
                [% IF (has_Y) %]
210
                    Volume, issue
155
                    <td align="center">[% lastvalue2 %]</td>
211
                [% END %]
156
                [% END %]
212
                [% IF ( numberpattern5 ) %]
157
                [% IF (has_Z) %]
213
                    Number, issue
158
                    <td align="center">[% lastvalue3 %]</td>
214
                [% END %]
159
                [% END %]
215
                [% IF ( numberpattern8 ) %]
160
            </tr>
216
                    Year/Number
161
            <tr>
162
                <td>Rollover:</td>
163
                [% IF (has_X) %]
164
                    <td align="center">[% numberpattern.whenmorethan1 %]</td>
217
                [% END %]
165
                [% END %]
218
                [% IF ( numberpattern6 ) %]
166
                [% IF (has_Y) %]
219
                    Seasonal only
167
                    <td align="center">[% numberpattern.whenmorethan2 %]</td>
220
                [% END %]
168
                [% END %]
221
                [% IF ( numberpattern7 ) %]
169
                [% IF (has_Z) %]
222
                    None of the above
170
                    <td align="center">[% numberpattern.whenmorethan3 %]</td>
223
                [% END %]
171
                [% END %]
224
            </li>
225
            <li><table>
226
            <tr><td>Starting with:</td>
227
                <td align="center">[% lastvalue1 %]</td>
228
            [% IF ( lastvalue2 ) %]
229
                <td align="center">&nbsp; 
230
                    [% lastvalue2 %]
231
                </td>
232
            [% END %]
233
            [% IF ( lastvalue3 ) %]
234
                <td align="center">&nbsp; 
235
                    [% lastvalue3 %]
236
                </td>
237
            [% END %]
238
            </tr>
239
            <tr><td>Rollover:</td>
240
                <td align="center">
241
                    [% IF ( whenmorethan1 < 9999999 ) %][% whenmorethan1 %][% ELSE %]Never[% END %]
242
                </td>
243
            [% IF ( whenmorethan2 ) %]
244
                <td align="center">&nbsp;
245
                    [% IF ( whenmorethan2 < 9999999 ) %][% whenmorethan2 %][% ELSE %]Never[% END %]
246
                </td>
247
            [% END %]
248
            [% IF ( whenmorethan3 ) %]
249
                <td align="center">&nbsp;
250
                    [% IF ( whenmorethan3 < 9999999 ) %][% whenmorethan3 %][% ELSE %]Never[% END %]
251
                </td>
252
            [% END %]
253
            </tr>
172
            </tr>
254
            </table></li>
173
            </table></li>
255
            [% IF ( irregular_issues ) %]
174
            [% IF ( irregular_issues ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-frequencies.tt (+215 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Frequencies</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
function confirmDelete() {
7
  return confirm(_("Are you sure you want to delete this subscription frequency?"));
8
}
9
10
function check_form() {
11
    var description = $("#description").val();
12
    var unit = $("#unit").val();
13
    var issuesperunit = $("#issuesperunit").val();
14
    var unitsperissue = $("#unitsperissue").val();
15
    var alert_msg = _("Some fields are not valid:") + "\n";
16
    var errors = 0;
17
18
    if(description.length == 0) {
19
        alert_msg += "\t - " + _("Description is required");
20
        errors ++;
21
    }
22
    if(unit.length > 0) {
23
        if(isNaN(issuesperunit) || issuesperunit == 0) {
24
            alert_msg += "\n\t - " + _("Issues per unit is required")
25
                + " " + _("(must be a number greater than 0)");
26
            errors ++;
27
        }
28
        if(isNaN(unitsperissue) || unitsperissue == 0) {
29
            alert_msg += "\n\t - " + _("Units per issue is required")
30
                + " " + _("(must be a number greater than 0)");
31
            errors ++;
32
        }
33
        if(issuesperunit > 1 && unitsperissue > 1) {
34
            alert_msg += "\n\t - " + _("One of 'issues per unit' and 'units per issue' must be equal to 1");
35
            errors ++;
36
        }
37
    }
38
39
    if(errors == 0) {
40
        return true;
41
    }
42
43
    alert(alert_msg);
44
    return false;
45
}
46
47
function show_blocking_subs() {
48
    $("#blocking_subs").show();
49
}
50
51
$(document).ready(function() {
52
    $("#issuesperunit").change(function() {
53
        var value = $(this).val();
54
        if(!isNaN(value) && value > 1) {
55
            $("#unitsperissue").val(1);
56
        }
57
    });
58
    $("#unitsperissue").change(function() {
59
        var value = $(this).val();
60
        if(!isNaN(value) && value > 1) {
61
            $("#issuesperunit").val(1);
62
        }
63
    });
64
});
65
//]]>
66
</script>
67
</head>
68
69
<body>
70
[% INCLUDE 'header.inc' %]
71
[% INCLUDE 'serials-search.inc' %]
72
73
<div id="breadcrumbs">
74
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
75
    <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
76
    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl">Frequencies</a>
77
</div>
78
79
<div id="doc3" class="yui-t2">
80
81
<div id="bd">
82
  <div id="yui-main">
83
    <div class="yui-b">
84
      [% IF (new or modify) %]
85
        [% IF (new) %]
86
          <h1>New frequency</h1>
87
        [% ELSE %]
88
          <h1>Modify frequency: [% description %]</h1>
89
        [% END %]
90
        <form action="/cgi-bin/koha/serials/subscription-frequencies.pl" method="post" onsubmit="return check_form();">
91
          [% IF (modify) %]
92
            <input type="hidden" name="id" value="[% id %]" />
93
            <input type="hidden" name="op" value="savemod" />
94
          [% ELSE %]
95
            <input type="hidden" name="op" value="savenew" />
96
          [% END %]
97
          <fieldset class="rows">
98
            <ol>
99
              <li>
100
                <label for="description">Description:</label>
101
                <input type="text" id="description" name="description" value="[% description %]" />
102
              </li>
103
              <li>
104
                <label for="unit">Unit</label>
105
                <select id="unit" name="unit">
106
                  <option value="">None</option>
107
                  [% FOREACH unit IN units_loop %]
108
                    [% IF (unit.selected) %]
109
                      <option selected="selected" value="[% unit.val %]">
110
                    [% ELSE %]
111
                      <option value="[% unit.val %]">
112
                    [% END %]
113
                      [% unit.val %]
114
                    </option>
115
                  [% END %]
116
                </select>
117
              </li>
118
              <li><span class="hint">Note: one of the two following fields must be equal to 1</span></li>
119
              <li>
120
                <label for="issuesperunit">Issues per unit</label>
121
                [% IF (new) %]
122
                  <input type="text" id="issuesperunit" name="issuesperunit" value="1" size="3" />
123
                [% ELSE %]
124
                  <input type="text" id="issuesperunit" name="issuesperunit" value="[% issuesperunit %]" size="3" />
125
                [% END %]
126
              </li>
127
              <li>
128
                <label for="unitsperissue">Units per issue</label>
129
                [% IF (new) %]
130
                  <input type="text" id="unitsperissue" name="unitsperissue" value="1" size="3" />
131
                [% ELSE %]
132
                  <input type="text" id="unitsperissue" name="unitsperissue" value="[% unitsperissue %]" size="3" />
133
                [% END %]
134
              </li>
135
              <li>
136
                <label for="displayorder">Display order</label>
137
                <input type="text" id="displayorder" name="displayorder" value="[% displayorder %]" size="3" />
138
              </li>
139
            </ol>
140
          </fieldset>
141
          <fieldset class="action">
142
            <input type="submit" value="Save" />
143
            <input type="button" value="Cancel" onclick="window.location='/cgi-bin/koha/serials/subscription-frequencies.pl'" />
144
          </fieldset>
145
        </form>
146
      [% ELSE %]
147
        <h1>Frequencies</h1>
148
        [% IF still_used %]
149
            <div class="dialog">
150
                <p>
151
                    This frequency is still used by [% subscriptions.size %]
152
                    subscription(s). Do you still want to delete it?
153
                </p>
154
                <p><a href="#" onclick="show_blocking_subs(); return false;">Show subscriptions</a></p>
155
                <ul id="blocking_subs" style="display:none">
156
                    [% FOREACH sub IN subscriptions %]
157
                        <li style="list-style-type:none">
158
                            <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% sub.subscriptionid %]">[% sub.title %]</a>
159
                        </li>
160
                    [% END %]
161
                </ul>
162
163
                <form action="" method="get">
164
                    <input type="hidden" name="op" value="del" />
165
                    <input type="hidden" name="confirm" value="1" />
166
                    <input type="hidden" name="frequencyid" value="[% frequencyid %]" />
167
                    <input type="submit" class="approve" value="Yes, delete" />
168
                </form>
169
                <form action="" method="get">
170
                    <input type="submit" class="deny" value="No, don't delete" />
171
                </form>
172
            </div>
173
        [% END %]
174
        <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=new">New frenquency</a>
175
176
        [% IF (frequencies_loop.size) %]
177
          <table id="frequenciest">
178
            <thead>
179
              <tr>
180
                <th>Description</th>
181
                <th>Unit</th>
182
                <th>Issues per unit</th>
183
                <th>Units per issue</th>
184
                <th>Display order</th>
185
                <th>&nbsp;</th>
186
              </tr>
187
            </thead>
188
            <tbody>
189
              [% FOREACH frequency IN frequencies_loop %]
190
                <tr>
191
                  <td>[% frequency.description %]</td>
192
                  <td>[% frequency.unit %]</td>
193
                  <td>[% frequency.issuesperunit %]</td>
194
                  <td>[% frequency.unitsperissue %]</td>
195
                  <td>[% frequency.displayorder %]</td>
196
                  <td>
197
                    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=modify&frequencyid=[% frequency.id %]">Modify</a> |
198
                    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=del&frequencyid=[% frequency.id %]">Delete</a>
199
                  </td>
200
                </tr>
201
              [% END %]
202
            </tbody>
203
          </table>
204
        [% ELSE %]
205
          <p>There is no defined frequency.</p>
206
        [% END %]
207
      [% END %]
208
209
    </div>
210
  </div>
211
  <div class="yui-b">
212
    [% INCLUDE 'serials-menu.inc' %]
213
  </div>
214
</div>
215
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-history.tt (+60 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Serials &rsaquo; Subscription history</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
</head>
7
8
<body>
9
[% INCLUDE 'header.inc' %]
10
[% INCLUDE 'serials-search.inc' %]
11
12
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; Subscription history</div>
13
14
<div id="doc3" class="yui-t2">
15
16
<div id="bd">
17
  <div id="yui-main">
18
    <div class="yui-b">
19
      <h1>Subscription history for [% title %]</h1>
20
        <div id="subscription_form_history">
21
          <form method="post" action="/cgi-bin/koha/serials/subscription-history.pl">
22
            <input type="hidden" name="op" value="mod" />
23
            <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
24
            <p>Hint : you can update the serial history manually. This can be useful for an old subscription or to clean the existing history. Modify those fields with care, as future serial recieve will continue to update them automatically.</p>
25
            <table>
26
              <tr>
27
                <td>Subscription start date</td>
28
                <td><input type="text" name="histstartdate" value="[% histstartdate | $KohaDates %]" /> (start date of the 1st subscription)</td>
29
              </tr>
30
              <tr>
31
                <td>Subscription end date</td>
32
                <td><input type="text" name="histenddate" value="[% histenddate | $KohaDates %]" />(if empty, subscription is still active)</td>
33
              </tr>
34
              <tr>
35
                <td>Received issues</td>
36
                <td><textarea name="receivedlist" cols="60" rows="5">[% receivedlist %]</textarea></td>
37
              </tr>
38
              <tr>
39
                <td>Missing issues</td>
40
                <td><textarea name="missinglist" cols="60" rows="5">[% missinglist %]</textarea></td>
41
              </tr>
42
              <tr>
43
                <td>Note for OPAC</td>
44
                <td><textarea name="opacnote" cols="60" rows="5">[% opacnote %]</textarea></td>
45
              </tr>
46
              <tr>
47
                <td>Note for staff</td>
48
                <td><textarea name="librariannote" cols="60" rows="5">[% librariannote %]</textarea></td>
49
              </tr>
50
            </table>
51
            <input type="submit" value="Save subscription history"  />
52
          </form>
53
        </div>
54
    </div>
55
  </div>
56
  <div class="yui-b">
57
    [% INCLUDE 'serials-menu.inc' %]
58
  </div>
59
</div>
60
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-numberpatterns.tt (+333 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Number patterns</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'calendar.inc' %]
5
<script type="text/javascript">
6
//<![CDATA[
7
[% IF (new or modify) %]
8
  function testPattern() {
9
      var frequencyid = $("#frequency").val();
10
      var firstacquidate = $("#firstacquidate").val();
11
      var error = 0;
12
      var error_msg = "";
13
      if(frequencyid == undefined || frequencyid == "") {
14
          error_msg += _("- Frequency is not defined\n");
15
          error ++;
16
      }
17
      if(firstacquidate == undefined || firstacquidate == "") {
18
          error_msg += _("- First publication date is not defined\n");
19
          error ++;
20
      }
21
22
      if(error){
23
          alert(_("Cannot test prediction pattern for the following reason(s):\n\n")
24
              + error_msg);
25
          return false;
26
      }
27
28
      var ajaxData = {
29
          'custompattern': true,
30
      };
31
      var ajaxParams = [
32
          'firstacquidate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
33
          'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
34
          'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
35
          'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
36
          'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
37
      ];
38
      for(i in ajaxParams) {
39
          var param = ajaxParams[i];
40
          var value = $("#"+param).val();
41
          if(value.length > 0)
42
              ajaxData[param] = value;
43
      }
44
45
      $.ajax({
46
          url: "/cgi-bin/koha/serials/showpredictionpattern.pl",
47
          data: ajaxData,
48
          async: false,
49
          dataType: "text",
50
          success: function(data) {
51
              $("#predictionpattern").html(data);
52
          }
53
      });
54
  }
55
[% END %]
56
57
function show_blocking_subs() {
58
    $("#blocking_subs").show();
59
}
60
//]]>
61
</script>
62
</head>
63
64
<body>
65
[% INCLUDE 'header.inc' %]
66
[% INCLUDE 'serials-search.inc' %]
67
68
<div id="breadcrumbs">
69
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
70
    <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
71
    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">Numbering patterns</a>
72
</div>
73
74
<div id="doc3" class="yui-t2">
75
76
<div id="bd">
77
  <div id="yui-main">
78
    <div class="yui-b">
79
      [% IF (new or modify) %]
80
        <div class="yui-g">
81
          [% IF (new) %]
82
            <h1>New number pattern</h1>
83
            [% IF (error_existing_numberpattern) %]
84
              <div class="dialog">
85
                <p>A pattern with this name already exists.</p>
86
              </div>
87
            [% END %]
88
          [% ELSE %]
89
            <h1>Modify pattern: [% label %]</h1>
90
            [% IF (error_existing_numberpattern) %]
91
              <div class="dialog">
92
                <p>Another pattern with this name already exists.</p>
93
              </div>
94
            [% END %]
95
          [% END %]
96
        </div>
97
        <div class="yui-g">
98
          <form action="/cgi-bin/koha/serials/subscription-numberpatterns.pl" method="post">
99
            [% IF (new) %]
100
              <input type="hidden" name="op" value="savenew" />
101
            [% ELSE %]
102
              <input type="hidden" name="op" value="savemod" />
103
              <input type="hidden" name="id" value="[% id %]" />
104
            [% END %]
105
            <fieldset class="rows">
106
              <ol>
107
                <li>
108
                  <label for="label">Name:</label>
109
                  <input type="text" id="label" name="label" value="[% label %]" />
110
                </li>
111
                <li>
112
                  <label for="description">Description:</label>
113
                  <input type="text" id="description" name="description" value="[% description %]" />
114
                </li>
115
                <li>
116
                  <label for="numberingmethod">Numbering formula:</label>
117
                  <input type="text" id="numberingmethod" name="numberingmethod" value="[% numberingmethod %]" />
118
                </li>
119
                <li>
120
                  <label for="displayorder">Display order:</label>
121
                  <input type="text" id="displayorder" name="displayorder" value="[% displayorder %]" />
122
                </li>
123
              </ol>
124
              <table>
125
                <thead>
126
                  <tr>
127
                    <th>&nbsp;</th>
128
                    <th>X</th>
129
                    <th>Y</th>
130
                    <th>Z</th>
131
                  </tr>
132
                </thead>
133
                <tbody>
134
                  <tr>
135
                    <td>Label</td>
136
                    <td><input type="text" id="label1" name="label1" value="[% label1 %]" /></td>
137
                    <td><input type="text" id="label2" name="label2" value="[% label2 %]" /></td>
138
                    <td><input type="text" id="label3" name="label3" value="[% label3 %]" /></td>
139
                  </tr>
140
                  <tr>
141
                    <td>Add</td>
142
                    <td><input type="text" id="add1" name="add1" value="[% add1 %]" /></td>
143
                    <td><input type="text" id="add2" name="add2" value="[% add2 %]" /></td>
144
                    <td><input type="text" id="add3" name="add3" value="[% add3 %]" /></td>
145
                  </tr>
146
                  <tr>
147
                    <td>Every</td>
148
                    <td><input type="text" id="every1" name="every1" value="[% every1 %]" /></td>
149
                    <td><input type="text" id="every2" name="every2" value="[% every2 %]" /></td>
150
                    <td><input type="text" id="every3" name="every3" value="[% every3 %]" /></td>
151
                  </tr>
152
                  <tr>
153
                    <td>Set back to</td>
154
                    <td><input type="text" id="setto1" name="setto1" value="[% setto1 %]" /></td>
155
                    <td><input type="text" id="setto2" name="setto2" value="[% setto2 %]" /></td>
156
                    <td><input type="text" id="setto3" name="setto3" value="[% setto3 %]" /></td>
157
                  </tr>
158
                  <tr>
159
                    <td>When more than</td>
160
                    <td><input type="text" id="whenmorethan1" name="whenmorethan1" value="[% whenmorethan1 %]" /></td>
161
                    <td><input type="text" id="whenmorethan2" name="whenmorethan2" value="[% whenmorethan2 %]" /></td>
162
                    <td><input type="text" id="whenmorethan3" name="whenmorethan3" value="[% whenmorethan3 %]" /></td>
163
                  </tr>
164
                  <tr>
165
                    [% BLOCK numbering_select %]
166
                      <select id="[% name %]" name="[% name %]" />
167
                        <option value=""></option>
168
                        [% IF (value == "dayname") %]
169
                            <option selected="selected" value="dayname">Name of day</option>
170
                        [% ELSE %]
171
                            <option value="dayname">Name of day</option>
172
                        [% END %]
173
                        [% IF (value == "monthname") %]
174
                            <option selected="selected" value="monthname">Name of month</option>
175
                        [% ELSE %]
176
                            <option value="monthname">Name of month</option>
177
                        [% END %]
178
                        [% IF (value == "season") %]
179
                            <option selected="selected" value="season">Name of season</option>
180
                        [% ELSE %]
181
                            <option value="season">Name of season</option>
182
                        [% END %]
183
                      </select>
184
                    [% END %]
185
                    <td>Fromatting</td>
186
                    <td>[% PROCESS numbering_select name="numbering1" value=numbering1 %]</td>
187
                    <td>[% PROCESS numbering_select name="numbering2" value=numbering2 %]</td>
188
                    <td>[% PROCESS numbering_select name="numbering3" value=numbering3 %]</td>
189
                  </tr>
190
                </tbody>
191
              </table>
192
            </fieldset>
193
            <fieldset class="action">
194
              <input type="submit" value="Save" />
195
              <input type="reset" value="Reset" />
196
              <input type="button" value="Cancel" onclick="window.location = '/cgi-bin/koha/serials/subscription-numberpatterns.pl';" />
197
            </fieldset>
198
          </form>
199
        </div>
200
        <div class="yui-g">
201
          <form>
202
            <fieldset class="rows">
203
              <legend>Test prediction pattern</legend>
204
              <ol>
205
                <li>
206
                  <label for="frequency">Frequency:</label>
207
                  <select id="frequency">
208
                    [% FOREACH frequency IN frequencies_loop %]
209
                      <option value="[% frequency.id %]">[% frequency.description %]</option>
210
                    [% END %]
211
                  </select>
212
                </li>
213
                <li>
214
                  <label for="firstacquidate">First issue publication date</label>
215
                  <input type="text" id="firstacquidate" class="datepicker" size="10" />
216
                </li>
217
                <li>
218
                  <label for="sublength">Subscription length:</label>
219
                  <select id="subtype">
220
                    [% FOREACH subtype IN subtypes_loop %]
221
                      <option value="[% subtype.value %]">[% subtype.value %]</option>
222
                    [% END %]
223
                  </select>
224
                  <input type="text" id="sublength" size="3" />
225
                </li>
226
                <li>
227
                  <label for="locale">Locale:</label>
228
                  <select id="locale" name="locale">
229
                      <option value=""></option>
230
                      [% FOREACH locale IN locales %]
231
                        <option value="[% locale %]">[% locale %]</option>
232
                      [% END %]
233
                    </select>
234
                  <span class="hint">If empty, system locale is used</span>
235
                </li>
236
              </ol>
237
              <table>
238
                <thead>
239
                  <tr>
240
                    <th>&nbsp;</th>
241
                    <th>X</th>
242
                    <th>Y</th>
243
                    <th>Z</th>
244
                  </tr>
245
                </thead>
246
                <tbody>
247
                  <tr>
248
                    <td>Begins with</td>
249
                    <td><input type="text" id="lastvalue1" name="lastvalue1" value="[% lastvalue1 %]" /></td>
250
                    <td><input type="text" id="lastvalue2" name="lastvalue2" value="[% lastvalue2 %]" /></td>
251
                    <td><input type="text" id="lastvalue3" name="lastvalue3" value="[% lastvalue3 %]" /></td>
252
                  </tr>
253
                  <tr>
254
                    <td>Inner counter</td>
255
                    <td><input type="text" id="innerloop1" name="innerloop1" value="[% innerloop1 %]" /></td>
256
                    <td><input type="text" id="innerloop2" name="innerloop2" value="[% innerloop2 %]" /></td>
257
                    <td><input type="text" id="innerloop3" name="innerloop3" value="[% innerloop3 %]" /></td>
258
                  </tr>
259
                </tbody>
260
              </table>
261
              <fieldset class="action">
262
              <input type="button" value="Test pattern" onclick="testPattern();" />
263
              </fieldset>
264
              <div id="predictionpattern"></div>
265
            </fieldset>
266
          </form>
267
        </div>
268
      [% ELSE %]
269
        <h1>Number patterns</h1>
270
        [% IF still_used %]
271
            <div class="dialog">
272
                <p>
273
                    This pattern is still used by [% subscriptions.size %]
274
                    subscription(s). Do you still want to delete it?
275
                </p>
276
                <p><a href="#" onclick="show_blocking_subs(); return false;">Show subscriptions</a></p>
277
                <ul id="blocking_subs" style="display:none">
278
                    [% FOREACH sub IN subscriptions %]
279
                        <li style="list-style-type:none">
280
                            <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% sub.subscriptionid %]">[% sub.title %]</a>
281
                        </li>
282
                    [% END %]
283
                </ul>
284
285
                <form action="" method="get">
286
                    <input type="hidden" name="op" value="del" />
287
                    <input type="hidden" name="confirm" value="1" />
288
                    <input type="hidden" name="id" value="[% id %]" />
289
                    <input type="submit" class="approve" value="Yes, delete" />
290
                </form>
291
                <form action="" method="get">
292
                    <input type="submit" class="deny" value="No, don't delete" />
293
                </form>
294
            </div>
295
        [% END %]
296
        <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=new">New numbering pattern</a>
297
        [% IF (numberpatterns_loop.size) %]
298
          <table id="numberpatternst">
299
            <thead>
300
              <tr>
301
                <th>Name</th>
302
                <th>Description</th>
303
                <th>Numbering formula</th>
304
                <th>Display order</th>
305
                <th>&nbsp;</th>
306
              </tr>
307
            </thead>
308
            <tbody>
309
              [% FOREACH numberpattern IN numberpatterns_loop %]
310
                <tr>
311
                  <td>[% numberpattern.label %]</td>
312
                  <td>[% numberpattern.description %]</td>
313
                  <td>[% numberpattern.numberingmethod %]</td>
314
                  <td>[% numberpattern.displayorder %]</td>
315
                  <td>
316
                    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=modify&id=[% numberpattern.id %]">Edit</a> |
317
                    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=del&id=[% numberpattern.id %]">Delete</a>
318
                  </td>
319
                </tr>
320
              [% END %]
321
            </tbody>
322
          </table>
323
        [% ELSE %]
324
          <p>There is no existing patterns.</p>
325
        [% END %]
326
      [% END %]
327
    </div>
328
  </div>
329
  <div class="yui-b">
330
    [% INCLUDE 'serials-menu.inc' %]
331
  </div>
332
</div>
333
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/serials/create-numberpattern.pl (+42 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use CGI;
4
use C4::Context;
5
use C4::Serials::Numberpattern;
6
use URI::Escape;
7
use strict;
8
use warnings;
9
10
my $input = new CGI;
11
12
my $numberpattern;
13
foreach (qw/ numberingmethod label1 label2 label3 add1 add2 add3
14
  every1 every2 every3 setto1 setto2 setto3 whenmorethan1 whenmorethan2
15
  whenmorethan3 numbering1 numbering2 numbering3 locale /) {
16
    $numberpattern->{$_} = $input->param($_);
17
}
18
# patternname is label in database
19
$numberpattern->{'label'} = $input->param('patternname');
20
21
# Check if pattern already exist in database
22
my $dbh = C4::Context->dbh;
23
my $query = qq{
24
    SELECT id
25
    FROM subscription_numberpatterns
26
    WHERE STRCMP(label, ?) = 0
27
};
28
my $sth = $dbh->prepare($query);
29
my $rv = $sth->execute($numberpattern->{'label'});
30
my $numberpatternid;
31
if($rv == 0) {
32
    # Pattern does not exists
33
    $numberpatternid = AddSubscriptionNumberpattern($numberpattern);
34
} else {
35
    ($numberpatternid) = $sth->fetchrow_array;
36
    $numberpattern->{'id'} = $numberpatternid;
37
    ModSubscriptionNumberpattern($numberpattern);
38
}
39
40
binmode STDOUT, ":encoding(UTF-8)";
41
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
42
print "{\"numberpatternid\":\"$numberpatternid\"}";
(-)a/serials/serials-collection.pl (-33 / +37 lines)
Lines 61-98 if($op eq 'gennext' && @subscriptionid){ Link Here
61
    my $status = defined( $nbissues ) ? 2 : 3;
61
    my $status = defined( $nbissues ) ? 2 : 3;
62
    $nbissues ||= 1;
62
    $nbissues ||= 1;
63
    for ( my $i = 0; $i < $nbissues; $i++ ){
63
    for ( my $i = 0; $i < $nbissues; $i++ ){
64
	$sth->execute($subscriptionid);
64
        $sth->execute($subscriptionid);
65
	# modify actual expected issue, to generate the next
65
        # modify actual expected issue, to generate the next
66
	if ( my $issue = $sth->fetchrow_hashref ) {
66
        if ( my $issue = $sth->fetchrow_hashref ) {
67
		ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
67
            ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
68
                $issue->{planneddate}, $issue->{publisheddate},
68
                    $issue->{planneddate}, $issue->{publisheddate},
69
                $status, "" );
69
                    $status, "" );
70
	}else{
70
        } else {
71
            require C4::Serials::Numberpattern;
71
            my $subscription = GetSubscription($subscriptionid);
72
            my $subscription = GetSubscription($subscriptionid);
73
            my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
72
            my $expected = GetNextExpected($subscriptionid);
74
            my $expected = GetNextExpected($subscriptionid);
73
	    my (
75
            my (
74
	         $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
76
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
75
             $newinnerloop1, $newinnerloop2, $newinnerloop3
77
                 $newinnerloop1, $newinnerloop2, $newinnerloop3
76
            ) = GetNextSeq($subscription);
78
            ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate});
77
79
78
	     ## We generate the next publication date
80
             ## We generate the next publication date
79
	     my $nextpublisheddate = GetNextDate( $expected->{planneddate}->output('iso'), $subscription );
81
             my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
80
	     ## Creating the new issue
82
             ## Creating the new issue
81
	     NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
83
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
82
	             1, $nextpublisheddate, $nextpublisheddate );
84
                     1, $nextpublisheddate, $nextpublisheddate );
83
85
84
	     ## Updating the subscription seq status
86
             ## Updating the subscription seq status
85
	     my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
87
             my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
86
	                 WHERE  subscriptionid = ?";
88
                         WHERE  subscriptionid = ?";
87
	     my $seqsth = $dbh->prepare($squery);
89
             my $seqsth = $dbh->prepare($squery);
88
	     $seqsth->execute(
90
             $seqsth->execute(
89
	         $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
91
                 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
90
	         $newinnerloop2, $newinnerloop3, $subscriptionid
92
                 $newinnerloop2, $newinnerloop3, $subscriptionid
91
	         );
93
                 );
92
94
93
	}
95
        }
94
	last if $nbissues == 1;
96
        last if $nbissues == 1;
95
	last if HasSubscriptionExpired($subscriptionid) > 0;
97
        last if HasSubscriptionExpired($subscriptionid) > 0;
96
    }
98
    }
97
    print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
99
    print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
98
}
100
}
Lines 109-117 if (@subscriptionid){ Link Here
109
    $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
111
    $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
110
    $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
112
    $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
111
    ##these are display information
113
    ##these are display information
112
    $subs->{ "periodicity" . $subs->{periodicity} } = 1;
113
    $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
114
    $subs->{ "status" . $subs->{'status'} } = 1;
115
    $subs->{startdate}     = format_date( $subs->{startdate} );
114
    $subs->{startdate}     = format_date( $subs->{startdate} );
116
    $subs->{histstartdate} = format_date( $subs->{histstartdate} );
115
    $subs->{histstartdate} = format_date( $subs->{histstartdate} );
117
    if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
116
    if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
Lines 125-130 if (@subscriptionid){ Link Here
125
    $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
124
    $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
126
	$location = GetAuthorisedValues('LOC', $subs->{'location'});
125
	$location = GetAuthorisedValues('LOC', $subs->{'location'});
127
	$callnumber = $subs->{callnumber};
126
	$callnumber = $subs->{callnumber};
127
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity});
128
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
129
    $subs->{frequency} = $frequency;
130
    $subs->{numberpattern} = $numberpattern;
128
    push @$subscriptiondescs,$subs;
131
    push @$subscriptiondescs,$subs;
129
    my $tmpsubscription= GetFullSubscription($subscriptionid);
132
    my $tmpsubscription= GetFullSubscription($subscriptionid);
130
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
133
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
Lines 154-159 foreach (@$location) { Link Here
154
    $locationlib = $_->{'lib'} if $_->{'selected'};
157
    $locationlib = $_->{'lib'} if $_->{'selected'};
155
}
158
}
156
159
160
157
chop $subscriptionidlist;
161
chop $subscriptionidlist;
158
$template->param(
162
$template->param(
159
          subscriptionidlist => $subscriptionidlist,
163
          subscriptionidlist => $subscriptionidlist,
(-)a/serials/serials-recieve.pl (-7 / +2 lines)
Lines 192-201 for(my $i=0;$i<$count;$i++){ Link Here
192
    $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp);
192
    $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp);
193
}
193
}
194
194
195
my $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
195
my $solhistory = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
196
197
$sth->execute($subscriptionid);
198
my $solhistory = $sth->fetchrow_hashref;
199
196
200
$subs = &GetSubscription($subscriptionid);
197
$subs = &GetSubscription($subscriptionid);
201
($totalissues,@serialslist) = GetSerials($subscriptionid);
198
($totalissues,@serialslist) = GetSerials($subscriptionid);
Lines 253-261 if (C4::Context->preference("serialsadditems")){ Link Here
253
    $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ;
250
    $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ;
254
}
251
}
255
252
256
$sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
253
$solhistory = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
257
$sth->execute($subscriptionid);
258
$solhistory = $sth->fetchrow_hashref;
259
254
260
$template->param(
255
$template->param(
261
            user => $auser,
256
            user => $auser,
(-)a/serials/showpredictionpattern.pl (+194 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
showpredictionpattern.pl
22
23
=head1 DESCRIPTION
24
25
This script calculate numbering of serials based on numbering pattern, and
26
publication date, based on frequency and first publication date.
27
28
=cut
29
30
use Modern::Perl;
31
32
use CGI;
33
use Date::Calc qw(Today Day_of_Year Week_of_Year Day_of_Week Days_in_Year Delta_Days Add_Delta_Days Add_Delta_YM);
34
use C4::Auth;
35
use C4::Output;
36
use C4::Serials;
37
use C4::Serials::Frequency;
38
39
my $input = new CGI;
40
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
    template_name   => 'serials/showpredictionpattern.tt',
42
    query           => $input,
43
    type            => 'intranet',
44
    authnotrequired => 0,
45
    flagsrequired   => { 'serials' => '*' },
46
} );
47
48
my $subscriptionid = $input->param('subscriptionid');
49
my $frequencyid = $input->param('frequency');
50
my $firstacquidate = $input->param('firstacquidate');
51
my $nextacquidate = $input->param('nextacquidate');
52
my $enddate = $input->param('enddate');
53
my $subtype = $input->param('subtype');
54
my $sublength = $input->param('sublength');
55
my $custompattern = $input->param('custompattern');
56
57
58
my %pattern = (
59
    numberingmethod => $input->param('numberingmethod') // '',
60
    numbering1      => $input->param('numbering1') // '',
61
    numbering2      => $input->param('numbering2') // '',
62
    numbering3      => $input->param('numbering3') // '',
63
    add1            => $input->param('add1') // '',
64
    add2            => $input->param('add2') // '',
65
    add3            => $input->param('add3') // '',
66
    whenmorethan1   => $input->param('whenmorethan1') // '',
67
    whenmorethan2   => $input->param('whenmorethan2') // '',
68
    whenmorethan3   => $input->param('whenmorethan3') // '',
69
    setto1          => $input->param('setto1') // '',
70
    setto2          => $input->param('setto2') // '',
71
    setto3          => $input->param('setto3') // '',
72
    every1          => $input->param('every1') // '',
73
    every2          => $input->param('every2') // '',
74
    every3          => $input->param('every3') // '',
75
);
76
77
if(!defined $firstacquidate || $firstacquidate eq ''){
78
    my ($year, $month, $day) = Today();
79
    $firstacquidate = sprintf "%04d-%02d-%02d", $year, $month, $day;
80
} else {
81
    $firstacquidate = C4::Dates->new($firstacquidate)->output('iso');
82
}
83
84
if($enddate){
85
    $enddate = C4::Dates->new($enddate)->output('iso');
86
}
87
88
if($nextacquidate) {
89
    $nextacquidate = C4::Dates->new($nextacquidate)->output('iso');
90
} else {
91
    $nextacquidate = $firstacquidate;
92
}
93
my $date = $nextacquidate;
94
95
my %subscription = (
96
    locale      => $input->param('locale') // '',
97
    lastvalue1      => $input->param('lastvalue1') // '',
98
    lastvalue2      => $input->param('lastvalue2') // '',
99
    lastvalue3      => $input->param('lastvalue3') // '',
100
    innerloop1      => $input->param('innerloop1') // '',
101
    innerloop2      => $input->param('innerloop2') // '',
102
    innerloop3      => $input->param('innerloop3') // '',
103
    irregularity    => '',
104
    periodicity     => $frequencyid,
105
    countissuesperunit  => 1,
106
    firstacquidate  => $firstacquidate,
107
);
108
109
my $issuenumber;
110
if(defined $subscriptionid) {
111
    ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date);
112
} else {
113
    $issuenumber = 1;
114
}
115
116
my @predictions_loop;
117
my ($calculated) = GetSeq(\%subscription, \%pattern);
118
push @predictions_loop, {
119
    number => $calculated,
120
    publicationdate => $date,
121
    issuenumber => $issuenumber,
122
    dow => Day_of_Week(split /-/, $date),
123
};
124
my @irreg = ();
125
if(defined $subscriptionid) {
126
    @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
127
    while(@irreg && $issuenumber > $irreg[0]) {
128
        shift @irreg;
129
    }
130
    if(@irreg && $issuenumber == $irreg[0]){
131
        $predictions_loop[0]->{'not_published'} = 1;
132
        shift @irreg;
133
    }
134
}
135
136
my $i = 1;
137
while( $i < 1000 ) {
138
    my %line;
139
140
    if(defined $date){
141
        $date = GetNextDate(\%subscription, $date);
142
    }
143
    if(defined $date){
144
        $line{'publicationdate'} = $date;
145
        $line{'dow'} = Day_of_Week(split /-/, $date);
146
    }
147
148
    # Check if we don't have exceed end date
149
    if($sublength){
150
        if($subtype eq "issues" && $i >= $sublength){
151
            last;
152
        } elsif($subtype eq "weeks" && $date && Delta_Days( split(/-/, $date), Add_Delta_Days( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
153
            last;
154
        } elsif($subtype eq "months" && $date && (Delta_Days( split(/-/, $date), Add_Delta_YM( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
155
            last;
156
        }
157
    }
158
    if($enddate && $date && Delta_Days( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
159
        last;
160
    }
161
162
    ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern);
163
    $issuenumber++;
164
    $line{'number'} = $calculated;
165
    $line{'issuenumber'} = $issuenumber;
166
    if(@irreg && $issuenumber == $irreg[0]){
167
        $line{'not_published'} = 1;
168
        shift @irreg;
169
    }
170
    push @predictions_loop, \%line;
171
172
    $i++;
173
}
174
175
$template->param(
176
    predictions_loop => \@predictions_loop,
177
);
178
179
my $frequency = GetSubscriptionFrequency($frequencyid);
180
181
if ( $frequency->{unit} and not $custompattern ) {
182
    $template->param( ask_for_irregularities => 1 );
183
    if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {
184
        $template->param( daily_options => 1 );
185
    }
186
}
187
188
if (   ( $date && $enddate && $date ne $enddate )
189
    or ( $subtype eq 'issues' && $i < $sublength ) )
190
{
191
    $template->param( not_consistent_end_date => 1 );
192
}
193
194
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/subscription-add.pl (-100 / +154 lines)
Lines 19-25 use strict; Link Here
19
use warnings;
19
use warnings;
20
20
21
use CGI;
21
use CGI;
22
use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days);
22
use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM);
23
use C4::Koha;
23
use C4::Koha;
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Auth;
25
use C4::Auth;
Lines 29-34 use C4::Output; Link Here
29
use C4::Context;
29
use C4::Context;
30
use C4::Branch; # GetBranches
30
use C4::Branch; # GetBranches
31
use C4::Serials;
31
use C4::Serials;
32
use C4::Serials::Frequency;
33
use C4::Serials::Numberpattern;
32
use C4::Letters;
34
use C4::Letters;
33
use Carp;
35
use Carp;
34
36
Lines 46-52 my @budgets; Link Here
46
my $permission = ($op eq "modify") ? "edit_subscription" : "create_subscription";
48
my $permission = ($op eq "modify") ? "edit_subscription" : "create_subscription";
47
49
48
my ($template, $loggedinuser, $cookie)
50
my ($template, $loggedinuser, $cookie)
49
= get_template_and_user({template_name => "serials/subscription-add.tmpl",
51
= get_template_and_user({template_name => "serials/subscription-add.tt",
50
				query => $query,
52
				query => $query,
51
				type => "intranet",
53
				type => "intranet",
52
				authnotrequired => 0,
54
				authnotrequired => 0,
Lines 57-65 my ($template, $loggedinuser, $cookie) Link Here
57
59
58
60
59
my $sub_on;
61
my $sub_on;
60
my @subscription_types = (
62
my @subscription_types = (qw(issues weeks months));
61
            'issues', 'weeks', 'months'
62
        );
63
my @sub_type_data;
63
my @sub_type_data;
64
64
65
my $subs;
65
my $subs;
Lines 81-87 if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { Link Here
81
         if ($subs->{$_} eq '0000-00-00') {
81
         if ($subs->{$_} eq '0000-00-00') {
82
            $subs->{$_} = ''
82
            $subs->{$_} = ''
83
    	} else {
83
    	} else {
84
            $subs->{$_} = format_date($subs->{$_});
84
            $subs->{$_} = $subs->{$_};
85
        }
85
        }
86
	  }
86
	  }
87
      if (!defined $subs->{letter}) {
87
      if (!defined $subs->{letter}) {
Lines 89-116 if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { Link Here
89
      }
89
      }
90
    letter_loop($subs->{'letter'}, $template);
90
    letter_loop($subs->{'letter'}, $template);
91
    my $nextexpected = GetNextExpected($subscriptionid);
91
    my $nextexpected = GetNextExpected($subscriptionid);
92
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate}->output('iso') eq $firstissuedate ;
92
    $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate} eq $firstissuedate ;
93
    $subs->{nextacquidate} = $nextexpected->{planneddate}->output()  if($op eq 'modify');
93
    $subs->{nextacquidate} = $nextexpected->{planneddate}  if($op eq 'modify');
94
    unless($op eq 'modsubscription') {
94
    unless($op eq 'modsubscription') {
95
        foreach my $length_unit (qw(numberlength weeklength monthlength)) {
95
        foreach my $length_unit (qw(numberlength weeklength monthlength)) {
96
			if ($subs->{$length_unit}){
96
            if ($subs->{$length_unit}) {
97
				$sub_length=$subs->{$length_unit};
97
                $sub_length=$subs->{$length_unit};
98
				$sub_on=$length_unit;
98
                $sub_on=$length_unit;
99
				last;
99
                last;
100
			}
100
            }
101
		}
101
        }
102
102
103
        $template->param( %{$subs} );
103
        $template->param( %{$subs} );
104
        $template->param("dow".$subs->{'dow'} => 1) if defined $subs->{'dow'};
105
        $template->param(
104
        $template->param(
106
                    $op => 1,
105
                    $op => 1,
107
                    "subtype_$sub_on" => 1,
106
                    "subtype_$sub_on" => 1,
108
                    sublength =>$sub_length,
107
                    sublength =>$sub_length,
109
                    history => ($op eq 'modify'),
108
                    history => ($op eq 'modify'),
110
                    "periodicity".$subs->{'periodicity'} => 1,
111
                    "numberpattern".$subs->{'numberpattern'} => 1,
112
                    firstacquiyear => substr($firstissuedate,0,4),
109
                    firstacquiyear => substr($firstissuedate,0,4),
113
                    );
110
                    );
111
112
        if($op eq 'modify') {
113
            my ($serials_number) = GetSerials($subscriptionid);
114
            if($serials_number > 1) {
115
                $template->param(more_than_one_serial => 1);
116
            }
117
        }
114
    }
118
    }
115
119
116
    if ( $op eq 'dup' ) {
120
    if ( $op eq 'dup' ) {
Lines 173-180 if ($op eq 'addsubscription') { Link Here
173
            $template->param(bibliotitle => $bib->{title});
177
            $template->param(bibliotitle => $bib->{title});
174
        }
178
        }
175
    }
179
    }
176
        $template->param((uc(C4::Context->preference("marcflavour"))) => 1);
180
177
	output_html_with_http_headers $query, $cookie, $template->output;
181
    $template->param((uc(C4::Context->preference("marcflavour"))) => 1);
182
183
    my @frequencies = GetSubscriptionFrequencies;
184
    my @frqloop;
185
    foreach my $freq (@frequencies) {
186
        my $selected = 0;
187
        $selected = 1 if ($subs->{periodicity} and $freq->{id} eq $subs->{periodicity});
188
        my $row = {
189
            id => $freq->{'id'},
190
            selected => $selected,
191
            label => $freq->{'description'},
192
        };
193
        push @frqloop, $row;
194
    }
195
    $template->param(frequencies => \@frqloop);
196
197
    my @numpatterns = GetSubscriptionNumberpatterns;
198
    my @numberpatternloop;
199
    foreach my $numpattern (@numpatterns) {
200
        my $selected = 0;
201
        $selected = 1 if($subs->{numberpattern} and $numpattern->{id} eq $subs->{numberpattern});
202
        my $row = {
203
            id => $numpattern->{'id'},
204
            selected => $selected,
205
            label => $numpattern->{'label'},
206
        };
207
        push @numberpatternloop, $row;
208
    }
209
    $template->param(numberpatterns => \@numberpatternloop);
210
211
    # Get installed locales
212
    # FIXME this will not work with all environments.
213
    # If call to locale fails, @locales will be an empty array, which is fine.
214
    my @locales = map {
215
        chomp;
216
        # we don't want POSIX and C locales
217
        /^C|^POSIX$/ ? () : $_
218
    } `locale -a`;
219
    $template->param(locales => \@locales);
220
221
    output_html_with_http_headers $query, $cookie, $template->output;
178
}
222
}
179
223
180
sub letter_loop {
224
sub letter_loop {
Lines 196-271 sub _get_sub_length { Link Here
196
    my ($type, $length) = @_;
240
    my ($type, $length) = @_;
197
    return
241
    return
198
        (
242
        (
199
            $type eq 'numberlength' ? $length : 0,
243
            $type eq 'issues' ? $length : 0,
200
            $type eq 'weeklength'   ? $length : 0,
244
            $type eq 'weeks'   ? $length : 0,
201
            $type eq 'monthlength'  ? $length : 0,
245
            $type eq 'months'  ? $length : 0,
202
        );
246
        );
203
}
247
}
204
248
249
sub _guess_enddate {
250
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
251
    my ($year, $month, $day);
252
    my $enddate;
253
    if($numberlength != 0) {
254
        my $frequency = GetSubscriptionFrequency($frequencyid);
255
        if($frequency->{'unit'} eq 'day') {
256
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
257
        } elsif($frequency->{'unit'} eq 'week') {
258
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
259
        } elsif($frequency->{'unit'} eq 'month') {
260
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
261
        } elsif($frequency->{'unit'} eq 'year') {
262
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
263
        }
264
    } elsif($weeklength != 0) {
265
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
266
    } elsif($monthlength != 0) {
267
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
268
    }
269
    if(defined $year) {
270
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
271
    } else {
272
        undef $enddate;
273
    }
274
    return $enddate;
275
}
276
205
sub redirect_add_subscription {
277
sub redirect_add_subscription {
206
    my $auser          = $query->param('user');
278
    my $auser          = $query->param('user');
207
    my $branchcode     = $query->param('branchcode');
279
    my $branchcode     = $query->param('branchcode');
208
    my $aqbooksellerid = $query->param('aqbooksellerid');
280
    my $aqbooksellerid = $query->param('aqbooksellerid');
209
    my $cost           = $query->param('cost');
281
    my $cost           = $query->param('cost');
210
    my $aqbudgetid     = $query->param('aqbudgetid');
282
    my $aqbudgetid     = $query->param('aqbudgetid');
211
    my $periodicity    = $query->param('periodicity');
283
    my $periodicity    = $query->param('frequency');
212
    my $dow            = $query->param('dow');
284
    my @irregularity   = $query->param('irregularity');
213
    my @irregularity   = $query->param('irregularity_select');
214
    my $numberpattern  = $query->param('numbering_pattern');
285
    my $numberpattern  = $query->param('numbering_pattern');
286
    my $locale         = $query->param('locale');
215
    my $graceperiod    = $query->param('graceperiod') || 0;
287
    my $graceperiod    = $query->param('graceperiod') || 0;
216
288
289
    my $subtype = $query->param('subtype');
290
    my $sublength = $query->param('sublength');
217
    my ( $numberlength, $weeklength, $monthlength )
291
    my ( $numberlength, $weeklength, $monthlength )
218
        = _get_sub_length( $query->param('subtype'), $query->param('sublength') );
292
        = _get_sub_length( $subtype, $sublength );
219
    my $add1              = $query->param('add1');
293
    my $add1              = $query->param('add1');
220
    my $every1            = $query->param('every1');
221
    my $whenmorethan1     = $query->param('whenmorethan1');
222
    my $setto1            = $query->param('setto1');
223
    my $lastvalue1        = $query->param('lastvalue1');
294
    my $lastvalue1        = $query->param('lastvalue1');
224
    my $innerloop1        = $query->param('innerloop1');
295
    my $innerloop1        = $query->param('innerloop1');
225
    my $add2              = $query->param('add2');
226
    my $every2            = $query->param('every2');
227
    my $whenmorethan2     = $query->param('whenmorethan2');
228
    my $setto2            = $query->param('setto2');
229
    my $innerloop2        = $query->param('innerloop2');
296
    my $innerloop2        = $query->param('innerloop2');
230
    my $lastvalue2        = $query->param('lastvalue2');
297
    my $lastvalue2        = $query->param('lastvalue2');
231
    my $add3              = $query->param('add3');
232
    my $every3            = $query->param('every3');
233
    my $whenmorethan3     = $query->param('whenmorethan3');
234
    my $setto3            = $query->param('setto3');
235
    my $lastvalue3        = $query->param('lastvalue3');
298
    my $lastvalue3        = $query->param('lastvalue3');
236
    my $innerloop3        = $query->param('innerloop3');
299
    my $innerloop3        = $query->param('innerloop3');
237
    my $numberingmethod   = $query->param('numberingmethod');
238
    my $status            = 1;
300
    my $status            = 1;
239
    my $biblionumber      = $query->param('biblionumber');
301
    my $biblionumber      = $query->param('biblionumber');
240
    my $callnumber        = $query->param('callnumber');
302
    my $callnumber        = $query->param('callnumber');
241
    my $notes             = $query->param('notes');
303
    my $notes             = $query->param('notes');
242
    my $internalnotes     = $query->param('internalnotes');
304
    my $internalnotes     = $query->param('internalnotes');
243
    my $hemisphere        = $query->param('hemisphere') || 1;
244
    my $letter            = $query->param('letter');
305
    my $letter            = $query->param('letter');
245
    my $manualhistory     = $query->param('manualhist');
306
    my $manualhistory     = $query->param('manualhist') ? 1 : 0;
246
    my $serialsadditems   = $query->param('serialsadditems');
307
    my $serialsadditems   = $query->param('serialsadditems');
247
    my $staffdisplaycount = $query->param('staffdisplaycount');
308
    my $staffdisplaycount = $query->param('staffdisplaycount');
248
    my $opacdisplaycount  = $query->param('opacdisplaycount');
309
    my $opacdisplaycount  = $query->param('opacdisplaycount');
249
    my $location          = $query->param('location');
310
    my $location          = $query->param('location');
311
    my $skip_serialseq    = $query->param('skip_serialseq');
250
    my $startdate = format_date_in_iso( $query->param('startdate') );
312
    my $startdate = format_date_in_iso( $query->param('startdate') );
251
    my $enddate = format_date_in_iso( $query->param('enddate') );
313
    my $enddate = format_date_in_iso( $query->param('enddate') );
252
    my $firstacquidate  = format_date_in_iso($query->param('firstacquidate'));
314
    my $firstacquidate  = format_date_in_iso($query->param('firstacquidate'));
253
    my $histenddate = format_date_in_iso($query->param('histenddate'));
315
    if(!defined $enddate || $enddate eq '') {
254
    my $histstartdate = format_date_in_iso($query->param('histstartdate'));
316
        if($subtype eq "issues") {
255
    my $recievedlist = $query->param('recievedlist');
317
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
256
    my $missinglist = $query->param('missinglist');
318
        } else {
257
    my $opacnote = $query->param('opacnote');
319
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
258
    my $librariannote = $query->param('librariannote');
320
        }
259
	my $subscriptionid = NewSubscription($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
321
    }
260
					$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
322
261
					$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
323
    my $subscriptionid = NewSubscription(
262
					$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
324
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
263
					$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
325
        $startdate, $periodicity, $numberlength, $weeklength,
264
					$numberingmethod, $status, $notes,$letter,$firstacquidate,join(",",@irregularity),
326
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
265
                    $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes,
327
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
266
                    $serialsadditems,$staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate
328
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
267
				);
329
        $manualhistory, $internalnotes, $serialsadditems,
268
    ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
330
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
331
        $skip_serialseq
332
    );
269
333
270
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
334
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
271
    return;
335
    return;
Lines 273-279 sub redirect_add_subscription { Link Here
273
337
274
sub redirect_mod_subscription {
338
sub redirect_mod_subscription {
275
    my $subscriptionid = $query->param('subscriptionid');
339
    my $subscriptionid = $query->param('subscriptionid');
276
	  my @irregularity = $query->param('irregularity_select');
340
    my @irregularity = $query->param('irregularity');
277
    my $auser = $query->param('user');
341
    my $auser = $query->param('user');
278
    my $librarian => $query->param('librarian'),
342
    my $librarian => $query->param('librarian'),
279
    my $branchcode = $query->param('branchcode');
343
    my $branchcode = $query->param('branchcode');
Lines 282-357 sub redirect_mod_subscription { Link Here
282
    my $biblionumber = $query->param('biblionumber');
346
    my $biblionumber = $query->param('biblionumber');
283
    my $aqbudgetid = $query->param('aqbudgetid');
347
    my $aqbudgetid = $query->param('aqbudgetid');
284
    my $startdate = format_date_in_iso($query->param('startdate'));
348
    my $startdate = format_date_in_iso($query->param('startdate'));
349
    my $firstacquidate = format_date_in_iso( $query->param('firstacquidate') );
285
    my $nextacquidate = $query->param('nextacquidate') ?
350
    my $nextacquidate = $query->param('nextacquidate') ?
286
                            format_date_in_iso($query->param('nextacquidate')):
351
                            format_date_in_iso($query->param('nextacquidate')):
287
                            format_date_in_iso($query->param('startdate'));
352
                            $firstacquidate;
288
    my $enddate = format_date_in_iso($query->param('enddate'));
353
    my $enddate = format_date_in_iso($query->param('enddate'));
289
    my $periodicity = $query->param('periodicity');
354
    my $periodicity = $query->param('frequency');
290
    my $dow = $query->param('dow');
291
355
356
    my $subtype = $query->param('subtype');
357
    my $sublength = $query->param('sublength');
292
    my ($numberlength, $weeklength, $monthlength)
358
    my ($numberlength, $weeklength, $monthlength)
293
        = _get_sub_length( $query->param('subtype'), $query->param('sublength') );
359
        = _get_sub_length( $subtype, $sublength );
294
    my $numberpattern = $query->param('numbering_pattern');
360
    my $numberpattern = $query->param('numbering_pattern');
295
    my $add1 = $query->param('add1');
361
    my $locale = $query->param('locale');
296
    my $every1 = $query->param('every1');
297
    my $whenmorethan1 = $query->param('whenmorethan1');
298
    my $setto1 = $query->param('setto1');
299
    my $lastvalue1 = $query->param('lastvalue1');
362
    my $lastvalue1 = $query->param('lastvalue1');
300
    my $innerloop1 = $query->param('innerloop1');
363
    my $innerloop1 = $query->param('innerloop1');
301
    my $add2 = $query->param('add2');
302
    my $every2 = $query->param('every2');
303
    my $whenmorethan2 = $query->param('whenmorethan2');
304
    my $setto2 = $query->param('setto2');
305
    my $lastvalue2 = $query->param('lastvalue2');
364
    my $lastvalue2 = $query->param('lastvalue2');
306
    my $innerloop2 = $query->param('innerloop2');
365
    my $innerloop2 = $query->param('innerloop2');
307
    my $add3 = $query->param('add3');
308
    my $every3 = $query->param('every3');
309
    my $whenmorethan3 = $query->param('whenmorethan3');
310
    my $setto3 = $query->param('setto3');
311
    my $lastvalue3 = $query->param('lastvalue3');
366
    my $lastvalue3 = $query->param('lastvalue3');
312
    my $innerloop3 = $query->param('innerloop3');
367
    my $innerloop3 = $query->param('innerloop3');
313
    my $numberingmethod = $query->param('numberingmethod');
314
    my $status = 1;
368
    my $status = 1;
315
    my $callnumber = $query->param('callnumber');
369
    my $callnumber = $query->param('callnumber');
316
    my $notes = $query->param('notes');
370
    my $notes = $query->param('notes');
317
    my $internalnotes = $query->param('internalnotes');
371
    my $internalnotes = $query->param('internalnotes');
318
    my $hemisphere = $query->param('hemisphere');
319
    my $letter = $query->param('letter');
372
    my $letter = $query->param('letter');
320
    my $manualhistory = $query->param('manualhist');
373
    my $manualhistory = $query->param('manualhist') ? 1 : 0;
321
    my $serialsadditems = $query->param('serialsadditems');
374
    my $serialsadditems = $query->param('serialsadditems');
322
    # subscription history
323
    my $histenddate = format_date_in_iso($query->param('histenddate'));
324
    my $histstartdate = format_date_in_iso($query->param('histstartdate'));
325
    my $recievedlist = $query->param('recievedlist');
326
    my $missinglist = $query->param('missinglist');
327
    my $opacnote = $query->param('opacnote');
328
    my $librariannote = $query->param('librariannote');
329
	my $staffdisplaycount = $query->param('staffdisplaycount');
375
	my $staffdisplaycount = $query->param('staffdisplaycount');
330
	my $opacdisplaycount = $query->param('opacdisplaycount');
376
	my $opacdisplaycount = $query->param('opacdisplaycount');
331
    my $graceperiod     = $query->param('graceperiod') || 0;
377
    my $graceperiod     = $query->param('graceperiod') || 0;
332
    my $location = $query->param('location');
378
    my $location = $query->param('location');
379
    my $skip_serialseq    = $query->param('skip_serialseq');
380
381
    # Guess end date
382
    if(!defined $enddate || $enddate eq '') {
383
        if($subtype eq "issues") {
384
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
385
        } else {
386
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
387
        }
388
    }
389
333
    my $nextexpected = GetNextExpected($subscriptionid);
390
    my $nextexpected = GetNextExpected($subscriptionid);
334
	#  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
391
    #  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
335
    if ( $nextacquidate ne $nextexpected->{planneddate}->output('iso') ) {
392
    if ( $nextexpected->{planneddate} && $nextacquidate ne $nextexpected->{planneddate} ) {
336
        ModNextExpected($subscriptionid,C4::Dates->new($nextacquidate,'iso'));
393
        ModNextExpected($subscriptionid, $nextacquidate);
337
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
394
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
338
        $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
395
        $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
339
    }
396
    }
340
397
341
        ModSubscription(
398
    ModSubscription(
342
            $auser,           $branchcode,   $aqbooksellerid, $cost,
399
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
343
            $aqbudgetid,      $startdate,    $periodicity,    $firstissuedate,
400
        $periodicity, $firstacquidate, join(";",@irregularity),
344
            $dow,             join(q{,},@irregularity), $numberpattern,  $numberlength,
401
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
345
            $weeklength,      $monthlength,  $add1,           $every1,
402
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
346
            $whenmorethan1,   $setto1,       $lastvalue1,     $innerloop1,
403
        $status, $biblionumber, $callnumber, $notes, $letter,
347
            $add2,            $every2,       $whenmorethan2,  $setto2,
404
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
348
            $lastvalue2,      $innerloop2,   $add3,           $every3,
405
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
349
            $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3,
406
        $skip_serialseq
350
            $numberingmethod, $status,       $biblionumber,   $callnumber,
407
    );
351
            $notes,           $letter,       $hemisphere,     $manualhistory,$internalnotes,
408
352
            $serialsadditems, $staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate,$subscriptionid
353
        );
354
        ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
355
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
409
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
356
    return;
410
    return;
357
}
411
}
(-)a/serials/subscription-detail.pl (-12 / +8 lines)
Lines 118-132 $template->param(%{ $subs }); Link Here
118
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});
118
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});
119
my @irregular_issues = split /,/, $subs->{irregularity};
119
my @irregular_issues = split /,/, $subs->{irregularity};
120
120
121
if (! $subs->{numberpattern}) {
121
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity});
122
    $subs->{numberpattern} = q{};
122
my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
123
}
123
124
if (! $subs->{dow}) {
125
    $subs->{dow} = q{};
126
}
127
if (! $subs->{periodicity}) {
128
    $subs->{periodicity} = '0';
129
}
130
my $default_bib_view = get_default_view();
124
my $default_bib_view = get_default_view();
131
125
132
my ( $order, $bookseller, $tmpl_infos );
126
my ( $order, $bookseller, $tmpl_infos );
Lines 167-175 $template->param( Link Here
167
                C4::Context->userenv->{flags} % 2 !=1  &&
161
                C4::Context->userenv->{flags} % 2 !=1  &&
168
                C4::Context->userenv->{branch} && $subs->{branchcode} &&
162
                C4::Context->userenv->{branch} && $subs->{branchcode} &&
169
                (C4::Context->userenv->{branch} ne $subs->{branchcode})),
163
                (C4::Context->userenv->{branch} ne $subs->{branchcode})),
170
    'periodicity' . $subs->{periodicity} => 1,
164
    frequency => $frequency,
171
    'arrival' . $subs->{dow} => 1,
165
    numberpattern => $numberpattern,
172
    'numberpattern' . $subs->{numberpattern} => 1,
166
    has_X           => ($numberpattern->{'numberingmethod'} =~ /{X}/) ? 1 : 0,
167
    has_Y           => ($numberpattern->{'numberingmethod'} =~ /{Y}/) ? 1 : 0,
168
    has_Z           => ($numberpattern->{'numberingmethod'} =~ /{Z}/) ? 1 : 0,
173
    intranetstylesheet => C4::Context->preference('intranetstylesheet'),
169
    intranetstylesheet => C4::Context->preference('intranetstylesheet'),
174
    intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
170
    intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
175
    irregular_issues => scalar @irregular_issues,
171
    irregular_issues => scalar @irregular_issues,
(-)a/serials/subscription-frequencies.pl (+120 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
subscription-frequencies.pl
22
23
=head1 DESCRIPTION
24
25
Manage subscription frequencies
26
27
=cut
28
29
use Modern::Perl;
30
31
use CGI;
32
33
use C4::Auth;
34
use C4::Output;
35
use C4::Serials;
36
use C4::Serials::Frequency;
37
38
my $input = new CGI;
39
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40
    template_name   => 'serials/subscription-frequencies.tt',
41
    query           => $input,
42
    type            => 'intranet',
43
    authnotrequired => 0,
44
    flagsrequired   => { 'parameters' => 1 },
45
    debug           => 1,
46
} );
47
48
my $op = $input->param('op');
49
50
if($op && ($op eq 'new' || $op eq 'modify')) {
51
    my @units_loop;
52
    push @units_loop, {val => $_} for (qw/ day week month year /);
53
54
    if($op eq 'modify') {
55
        my $frequencyid = $input->param('frequencyid');
56
        my $frequency = GetSubscriptionFrequency($frequencyid);
57
        foreach (@units_loop) {
58
            if($frequency->{unit} and $_->{val} eq $frequency->{unit}) {
59
                $_->{selected} = 1;
60
                last;
61
            }
62
        }
63
        $template->param( %$frequency );
64
    }
65
66
    $template->param(
67
        units_loop => \@units_loop,
68
        $op        => 1,
69
    );
70
    output_html_with_http_headers $input, $cookie, $template->output;
71
    exit;
72
}
73
74
if($op && ($op eq 'savenew' || $op eq 'savemod')) {
75
    my $frequency;
76
    foreach (qw/ description unit issuesperunit unitsperissue displayorder /) {
77
        $frequency->{$_} = $input->param($_);
78
    }
79
    $frequency->{unit} = undef if $frequency->{unit} eq '';
80
    foreach (qw/issuesperunit unitsperissue/) {
81
        $frequency->{$_} = 1 if $frequency->{$_} !~ /\d+/;
82
    }
83
    $frequency->{issuesperunit} = 1 if $frequency->{issuesperunit} < 1;
84
    $frequency->{unitsperissue} = 1 if $frequency->{issuesperunit} != 1;
85
86
    if($op eq 'savemod') {
87
        $frequency->{id} = $input->param('id');
88
        ModSubscriptionFrequency($frequency);
89
    } else {
90
        AddSubscriptionFrequency($frequency);
91
    }
92
} elsif($op && $op eq 'del') {
93
    my $frequencyid = $input->param('frequencyid');
94
95
    if ($frequencyid) {
96
        my $confirm = $input->param('confirm');
97
        if ($confirm) {
98
            DelSubscriptionFrequency($frequencyid);
99
        } else {
100
            my @subs = GetSubscriptionsWithFrequency($frequencyid);
101
            if (@subs) {
102
                $template->param(
103
                    frequencyid => $frequencyid,
104
                    still_used => 1,
105
                    subscriptions => \@subs
106
                );
107
            } else {
108
                DelSubscriptionFrequency($frequencyid);
109
            }
110
        }
111
    }
112
}
113
114
115
my @frequencies = GetSubscriptionFrequencies();
116
117
$template->param(frequencies_loop => \@frequencies);
118
$template->param($op => 1) if $op;
119
120
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/subscription-frequency.pl (+19 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use CGI;
4
use C4::Context;
5
use C4::Serials::Frequency;
6
use C4::Auth qw/check_cookie_auth/;
7
use URI::Escape;
8
use strict;
9
10
my $input=new CGI;
11
my $frqid=$input->param("frequency_id");
12
my ($auth_status, $sessionID) = check_cookie_auth($input->cookie('CGISESSID'), { serials => '*' });
13
if ($auth_status ne "ok") {
14
    exit 0;
15
}
16
my $frequencyrecord=GetSubscriptionFrequency($frqid);
17
binmode STDOUT, ":encoding(UTF-8)";
18
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
19
print "{".join (",",map { "\"$_\":\"".uri_escape($frequencyrecord->{$_})."\"" }sort keys %$frequencyrecord)."}";
(-)a/serials/subscription-history.pl (+87 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
subscription-history.pl
22
23
=head1 DESCRIPTION
24
25
Modify subscription history
26
27
=cut
28
29
use Modern::Perl;
30
31
use CGI;
32
use C4::Auth;
33
use C4::Output;
34
35
use C4::Biblio;
36
use C4::Dates qw(format_date_in_iso);
37
use C4::Serials;
38
39
my $input = new CGI;
40
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
    template_name   => 'serials/subscription-history.tt',
42
    query           => $input,
43
    type            => 'intranet',
44
    authnotrequired => 0,
45
    flagsrequired   => { 'serials' => 'edit_subscription' },
46
    debug           => 1,
47
} );
48
49
my $subscriptionid  = $input->param('subscriptionid');
50
my $op              = $input->param('op');
51
52
if(!defined $subscriptionid || $subscriptionid eq '') {
53
    print $input->redirect('/cgi-bin/koha/serials/serials-home.pl');
54
    exit;
55
}
56
57
if($op && $op eq 'mod') {
58
    my $histstartdate   = $input->param('histstartdate');
59
    my $histenddate     = $input->param('histenddate');
60
    my $receivedlist    = $input->param('receivedlist');
61
    my $missinglist     = $input->param('missinglist');
62
    my $opacnote        = $input->param('opacnote');
63
    my $librariannote   = $input->param('librariannote');
64
65
    ModSubscriptionHistory( $subscriptionid, format_date_in_iso($histstartdate),
66
        format_date_in_iso($histenddate), $receivedlist, $missinglist, $opacnote,
67
        $librariannote );
68
69
    print $input->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
70
    exit;
71
} else {
72
    my $history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
73
    my (undef, $biblio) = GetBiblio($history->{'biblionumber'});
74
75
    $template->param(
76
        subscriptionid  => $subscriptionid,
77
        title           => $biblio->{'title'},
78
        histstartdate   => $history->{'histstartdate'},
79
        histenddate     => $history->{'histenddate'},
80
        receivedlist    => $history->{'recievedlist'},
81
        missinglist     => $history->{'missinglist'},
82
        opacnote        => $history->{'opacnote'},
83
        librariannote   => $history->{'librariannote'},
84
    );
85
86
    output_html_with_http_headers $input, $cookie, $template->output;
87
}
(-)a/serials/subscription-numberpattern.pl (+15 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use CGI;
4
use C4::Serials::Numberpattern;
5
use URI::Escape;
6
use strict;
7
use warnings;
8
9
my $input=new CGI;
10
my $numpatternid=$input->param("numberpattern_id");
11
12
my $numberpatternrecord=GetSubscriptionNumberpattern($numpatternid);
13
binmode STDOUT, ":encoding(UTF-8)";
14
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
15
print "{",join (",",map {"\"$_\":\"".(uri_escape($numberpatternrecord->{$_}) // '')."\"" }sort keys %$numberpatternrecord),"}";
(-)a/serials/subscription-numberpatterns.pl (-1 / +150 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
subscription-numberpatterns.pl
22
23
=head1 DESCRIPTION
24
25
Manage numbering patterns
26
27
=cut
28
29
use Modern::Perl;
30
use CGI;
31
32
use C4::Auth;
33
use C4::Output;
34
use C4::Serials::Numberpattern;
35
use C4::Serials::Frequency;
36
37
my $input = new CGI;
38
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
39
    template_name   => 'serials/subscription-numberpatterns.tt',
40
    query           => $input,
41
    type            => 'intranet',
42
    authnotrequired => 0,
43
    flagsrequired   => { 'parameters' => 1 }
44
} );
45
46
my $op = $input->param('op');
47
48
if($op && $op eq 'savenew') {
49
    my $label = $input->param('label');
50
    my $numberpattern;
51
    foreach(qw/ label description numberingmethod displayorder
52
      label1 label2 label3 add1 add2 add3 every1 every2 every3
53
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
54
      numbering1 numbering2 numbering3 /) {
55
        $numberpattern->{$_} = $input->param($_);
56
        if($numberpattern->{$_} and $numberpattern->{$_} eq '') {
57
            $numberpattern->{$_} = undef;
58
        }
59
    }
60
    my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
61
62
    if(!defined $numberpattern2) {
63
        AddSubscriptionNumberpattern($numberpattern);
64
    } else {
65
        $op = 'new';
66
        $template->param(error_existing_numberpattern => 1);
67
        $template->param(%$numberpattern);
68
    }
69
} elsif ($op && $op eq 'savemod') {
70
    my $id = $input->param('id');
71
    my $label = $input->param('label');
72
    my $numberpattern = GetSubscriptionNumberpattern($id);
73
    my $mod_ok = 1;
74
    if($numberpattern->{'label'} ne $label) {
75
        my $numberpattern2 = GetSubscriptionNumberpatternByName($label);
76
        if(defined $numberpattern2 && $id != $numberpattern2->{'id'}) {
77
            $mod_ok = 0;
78
        }
79
    }
80
    if($mod_ok) {
81
        foreach(qw/ id label description numberingmethod displayorder
82
          label1 label2 label3 add1 add2 add3 every1 every2 every3
83
          setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
84
          numbering1 numbering2 numbering3 /) {
85
            $numberpattern->{$_} = $input->param($_) || undef;
86
        }
87
        ModSubscriptionNumberpattern($numberpattern);
88
    } else {
89
        $op = 'modify';
90
        $template->param(error_existing_numberpattern => 1);
91
    }
92
}
93
94
if($op && ($op eq 'new' || $op eq 'modify')) {
95
    if($op eq 'modify') {
96
        my $id = $input->param('id');
97
        if(defined $id) {
98
            my $numberpattern = GetSubscriptionNumberpattern($id);
99
            $template->param(%$numberpattern);
100
        } else {
101
            $op = 'new';
102
        }
103
    }
104
    my @frequencies = GetSubscriptionFrequencies();
105
    my @subtypes;
106
    push @subtypes, { value => $_ } for (qw/ issues weeks months /);
107
    my @locales = map {
108
        chomp;
109
        /^C|^POSIX$/ ? () : $_
110
    } `locale -a`;
111
112
    $template->param(
113
        $op => 1,
114
        frequencies_loop => \@frequencies,
115
        subtypes_loop => \@subtypes,
116
        locales => \@locales,
117
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
118
    );
119
    output_html_with_http_headers $input, $cookie, $template->output;
120
    exit;
121
}
122
123
if($op && $op eq 'del') {
124
    my $id = $input->param('id');
125
    if ($id) {
126
        my $confirm = $input->param('confirm');
127
        if ($confirm) {
128
            DelSubscriptionNumberpattern($id);
129
        } else {
130
            my @subs = GetSubscriptionsWithNumberpattern($id);
131
            if (@subs) {
132
                $template->param(
133
                    id => $id,
134
                    still_used => 1,
135
                    subscriptions => \@subs
136
                );
137
            } else {
138
                DelSubscriptionNumberpattern($id);
139
            }
140
        }
141
    }
142
}
143
144
my @numberpatterns_loop = GetSubscriptionNumberpatterns();
145
146
$template->param(
147
    numberpatterns_loop => \@numberpatterns_loop,
148
);
149
150
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 7688