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

(-)a/C4/Serials.pm (-371 / +574 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 38-45 BEGIN { Link Here
38
      &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
40
      &GetSubscription    &CountSubscriptionFromBiblionumber      &GetSubscriptionsFromBiblionumber
39
      &GetFullSubscriptionsFromBiblionumber   &GetFullSubscription &ModSubscriptionHistory
41
      &GetFullSubscriptionsFromBiblionumber   &GetFullSubscription &ModSubscriptionHistory
40
      &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
42
      &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
43
      &GetSubscriptionHistoryFromSubscriptionId
41
44
42
      &GetNextSeq         &NewIssue           &ItemizeSerials    &GetSerials
45
      &GetNextSeq &GetSeq &NewIssue           &ItemizeSerials    &GetSerials
43
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
46
      &GetLatestSerials   &ModSerialStatus    &GetNextDate       &GetSerials2
44
      &ReNewSubscription  &GetLateIssues      &GetLateOrMissingIssues
47
      &ReNewSubscription  &GetLateIssues      &GetLateOrMissingIssues
45
      &GetSerialInformation                   &AddItem2Serial
48
      &GetSerialInformation                   &AddItem2Serial
Lines 152-171 sub GetLateIssues { Link Here
152
155
153
=head2 GetSubscriptionHistoryFromSubscriptionId
156
=head2 GetSubscriptionHistoryFromSubscriptionId
154
157
155
$sth = GetSubscriptionHistoryFromSubscriptionId()
158
$history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
156
this function prepares the SQL request and returns the statement handle
159
157
After this function, don't forget to execute it by using $sth->execute($subscriptionid)
160
This function returns the subscription history as a hashref
158
161
159
=cut
162
=cut
160
163
161
sub GetSubscriptionHistoryFromSubscriptionId() {
164
sub GetSubscriptionHistoryFromSubscriptionId {
165
    my ($subscriptionid) = @_;
166
167
    return unless $subscriptionid;
168
162
    my $dbh   = C4::Context->dbh;
169
    my $dbh   = C4::Context->dbh;
163
    my $query = qq|
170
    my $query = qq|
164
        SELECT *
171
        SELECT *
165
        FROM   subscriptionhistory
172
        FROM   subscriptionhistory
166
        WHERE  subscriptionid = ?
173
        WHERE  subscriptionid = ?
167
    |;
174
    |;
168
    return $dbh->prepare($query);
175
    my $sth = $dbh->prepare($query);
176
    $sth->execute($subscriptionid);
177
    my $results = $sth->fetchrow_hashref;
178
    $sth->finish;
179
180
    return $results;
169
}
181
}
170
182
171
=head2 GetSerialStatusFromSerialId
183
=head2 GetSerialStatusFromSerialId
Lines 559-565 sub GetSubscriptions { Link Here
559
    my $dbh = C4::Context->dbh;
571
    my $dbh = C4::Context->dbh;
560
    my $sth;
572
    my $sth;
561
    my $sql = qq(
573
    my $sql = qq(
562
            SELECT subscription.*, subscriptionhistory.*, biblio.title,biblioitems.issn,biblio.biblionumber
574
            SELECT subscriptionhistory.*, subscription.*, biblio.title,biblioitems.issn,biblio.biblionumber
563
            FROM   subscription
575
            FROM   subscription
564
            LEFT JOIN subscriptionhistory USING(subscriptionid)
576
            LEFT JOIN subscriptionhistory USING(subscriptionid)
565
            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
577
            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
Lines 782-866 a list containing all the input params updated. Link Here
782
794
783
=cut
795
=cut
784
796
785
# sub GetNextSeq {
786
#     my ($val) =@_;
787
#     my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
788
#     $calculated = $val->{numberingmethod};
789
# # calculate the (expected) value of the next issue recieved.
790
#     $newlastvalue1 = $val->{lastvalue1};
791
# # check if we have to increase the new value.
792
#     $newinnerloop1 = $val->{innerloop1}+1;
793
#     $newinnerloop1=0 if ($newinnerloop1 >= $val->{every1});
794
#     $newlastvalue1 += $val->{add1} if ($newinnerloop1<1); # <1 to be true when 0 or empty.
795
#     $newlastvalue1=$val->{setto1} if ($newlastvalue1>$val->{whenmorethan1}); # reset counter if needed.
796
#     $calculated =~ s/\{X\}/$newlastvalue1/g;
797
#
798
#     $newlastvalue2 = $val->{lastvalue2};
799
# # check if we have to increase the new value.
800
#     $newinnerloop2 = $val->{innerloop2}+1;
801
#     $newinnerloop2=0 if ($newinnerloop2 >= $val->{every2});
802
#     $newlastvalue2 += $val->{add2} if ($newinnerloop2<1); # <1 to be true when 0 or empty.
803
#     $newlastvalue2=$val->{setto2} if ($newlastvalue2>$val->{whenmorethan2}); # reset counter if needed.
804
#     $calculated =~ s/\{Y\}/$newlastvalue2/g;
805
#
806
#     $newlastvalue3 = $val->{lastvalue3};
807
# # check if we have to increase the new value.
808
#     $newinnerloop3 = $val->{innerloop3}+1;
809
#     $newinnerloop3=0 if ($newinnerloop3 >= $val->{every3});
810
#     $newlastvalue3 += $val->{add3} if ($newinnerloop3<1); # <1 to be true when 0 or empty.
811
#     $newlastvalue3=$val->{setto3} if ($newlastvalue3>$val->{whenmorethan3}); # reset counter if needed.
812
#     $calculated =~ s/\{Z\}/$newlastvalue3/g;
813
#     return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
814
# }
815
816
sub GetNextSeq {
797
sub GetNextSeq {
817
    my ($val) = @_;
798
    my ($val, $planneddate) = @_;
818
    my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 );
799
    my ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3,
819
    my $pattern          = $val->{numberpattern};
800
    $newinnerloop1, $newinnerloop2, $newinnerloop3 );
820
    my @seasons          = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' );
801
    my $count = 1;
821
    my @southern_seasons = ( '', 'Summer', 'Autumn', 'Winter', 'Spring' );
802
822
    $calculated    = $val->{numberingmethod};
803
    if($val->{'skip_serialseq'}) {
823
    $newlastvalue1 = $val->{lastvalue1};
804
        my @irreg = split /;/, $val->{'irregularity'};
824
    $newlastvalue2 = $val->{lastvalue2};
805
        if(@irreg > 0) {
825
    $newlastvalue3 = $val->{lastvalue3};
806
            my $irregularities = {};
826
    $newlastvalue1 = $val->{lastvalue1};
807
            $irregularities->{$_} = 1 foreach(@irreg);
827
808
            my $issueno = GetFictiveIssueNumber($val, $planneddate) + 1;
828
    # check if we have to increase the new value.
809
            while($irregularities->{$issueno}) {
829
    $newinnerloop1 = $val->{innerloop1} + 1;
810
                $count++;
830
    $newinnerloop1 = 0 if ( $newinnerloop1 >= $val->{every1} );
811
                $issueno++;
831
    $newlastvalue1 += $val->{add1} if ( $newinnerloop1 < 1 );    # <1 to be true when 0 or empty.
812
            }
832
    $newlastvalue1 = $val->{setto1} if ( $newlastvalue1 > $val->{whenmorethan1} );    # reset counter if needed.
833
    $calculated =~ s/\{X\}/$newlastvalue1/g;
834
835
    $newlastvalue2 = $val->{lastvalue2};
836
837
    # check if we have to increase the new value.
838
    $newinnerloop2 = $val->{innerloop2} + 1;
839
    $newinnerloop2 = 0 if ( $newinnerloop2 >= $val->{every2} );
840
    $newlastvalue2 += $val->{add2} if ( $newinnerloop2 < 1 );                         # <1 to be true when 0 or empty.
841
    $newlastvalue2 = $val->{setto2} if ( $newlastvalue2 > $val->{whenmorethan2} );    # reset counter if needed.
842
    if ( $pattern == 6 ) {
843
        if ( $val->{hemisphere} == 2 ) {
844
            my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
845
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
846
        } else {
847
            my $newlastvalue2seq = $seasons[$newlastvalue2];
848
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
849
        }
813
        }
850
    } else {
851
        $calculated =~ s/\{Y\}/$newlastvalue2/g;
852
    }
814
    }
853
815
854
    $newlastvalue3 = $val->{lastvalue3};
816
    my $pattern = $val->{numberpattern};
817
    $calculated    = $val->{numberingmethod};
818
    my $locale = $val->{locale};
819
    $newlastvalue1 = $val->{lastvalue1} || 0;
820
    $newlastvalue2 = $val->{lastvalue2} || 0;
821
    $newlastvalue3 = $val->{lastvalue3} || 0;
822
    $newinnerloop1 = $val->{innerloop1} || 0;
823
    $newinnerloop2 = $val->{innerloop2} || 0;
824
    $newinnerloop3 = $val->{innerloop3} || 0;
825
    my %calc;
826
    foreach(qw/X Y Z/) {
827
        $calc{$_} = 1 if ($val->{'numberingmethod'} =~ /\{$_\}/);
828
    }
855
829
856
    # check if we have to increase the new value.
830
    for(my $i = 0; $i < $count; $i++) {
857
    $newinnerloop3 = $val->{innerloop3} + 1;
831
        if($calc{'X'}) {
858
    $newinnerloop3 = 0 if ( $newinnerloop3 >= $val->{every3} );
832
            # check if we have to increase the new value.
859
    $newlastvalue3 += $val->{add3} if ( $newinnerloop3 < 1 );    # <1 to be true when 0 or empty.
833
            $newinnerloop1 += 1;
860
    $newlastvalue3 = $val->{setto3} if ( $newlastvalue3 > $val->{whenmorethan3} );    # reset counter if needed.
834
            if ($newinnerloop1 >= $val->{every1}) {
861
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
835
                $newinnerloop1  = 0;
836
                $newlastvalue1 += $val->{add1};
837
            }
838
            # reset counter if needed.
839
            $newlastvalue1 = $val->{setto1} if ($newlastvalue1 > $val->{whenmorethan1});
840
        }
841
        if($calc{'Y'}) {
842
            # check if we have to increase the new value.
843
            $newinnerloop2 += 1;
844
            if ($newinnerloop2 >= $val->{every2}) {
845
                $newinnerloop2  = 0;
846
                $newlastvalue2 += $val->{add2};
847
            }
848
            # reset counter if needed.
849
            $newlastvalue2 = $val->{setto2} if ($newlastvalue2 > $val->{whenmorethan2});
850
        }
851
        if($calc{'Z'}) {
852
            # check if we have to increase the new value.
853
            $newinnerloop3 += 1;
854
            if ($newinnerloop3 >= $val->{every3}) {
855
                $newinnerloop3  = 0;
856
                $newlastvalue3 += $val->{add3};
857
            }
858
            # reset counter if needed.
859
            $newlastvalue3 = $val->{setto3} if ($newlastvalue3 > $val->{whenmorethan3});
860
        }
861
    }
862
    if($calc{'X'}) {
863
        my $newlastvalue1string = _numeration( $newlastvalue1, $val->{numbering1}, $locale );
864
        $calculated =~ s/\{X\}/$newlastvalue1string/g;
865
    }
866
    if($calc{'Y'}) {
867
        my $newlastvalue2string = _numeration( $newlastvalue2, $val->{numbering2}, $locale );
868
        $calculated =~ s/\{Y\}/$newlastvalue2string/g;
869
    }
870
    if($calc{'Z'}) {
871
        my $newlastvalue3string = _numeration( $newlastvalue3, $val->{numbering3}, $locale );
872
        $calculated =~ s/\{Z\}/$newlastvalue3string/g;
873
    }
862
874
863
    return ( $calculated, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 );
875
    return ($calculated,
876
            $newlastvalue1, $newlastvalue2, $newlastvalue3,
877
            $newinnerloop1, $newinnerloop2, $newinnerloop3);
864
}
878
}
865
879
866
=head2 GetSeq
880
=head2 GetSeq
Lines 875-901 the sequence in integer format Link Here
875
889
876
sub GetSeq {
890
sub GetSeq {
877
    my ($val) = @_;
891
    my ($val) = @_;
892
    my $locale = $val->{locale};
893
878
    my $pattern = $val->{numberpattern};
894
    my $pattern = $val->{numberpattern};
879
    my @seasons          = ( 'nothing', 'Winter', 'Spring', 'Summer', 'Autumn' );
895
    my $calculated = $val->{numberingmethod};
880
    my @southern_seasons = ( '',        'Summer', 'Autumn', 'Winter', 'Spring' );
896
881
    my $calculated       = $val->{numberingmethod};
897
    my $newlastvalue1 = $val->{'lastvalue1'} || 0;
882
    my $x                = $val->{'lastvalue1'};
898
    $newlastvalue1 = _numeration($newlastvalue1, $val->{numbering1}, $locale) if ($val->{numbering1}); # reset counter if needed.
883
    $calculated =~ s/\{X\}/$x/g;
899
    $calculated =~ s/\{X\}/$newlastvalue1/g;
884
    my $newlastvalue2 = $val->{'lastvalue2'};
900
885
901
    my $newlastvalue2 = $val->{'lastvalue2'} || 0;
886
    if ( $pattern == 6 ) {
902
    $newlastvalue2 = _numeration($newlastvalue2, $val->{numbering2}, $locale) if ($val->{numbering2}); # reset counter if needed.
887
        if ( $val->{hemisphere} == 2 ) {
903
    $calculated =~ s/\{Y\}/$newlastvalue2/g;
888
            my $newlastvalue2seq = $southern_seasons[$newlastvalue2];
904
889
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
905
    my $newlastvalue3 = $val->{'lastvalue3'} || 0;
890
        } else {
906
    $newlastvalue3 = _numeration($newlastvalue3, $val->{numbering3}, $locale) if ($val->{numbering3}); # reset counter if needed.
891
            my $newlastvalue2seq = $seasons[$newlastvalue2];
907
    $calculated =~ s/\{Z\}/$newlastvalue3/g;
892
            $calculated =~ s/\{Y\}/$newlastvalue2seq/g;
893
        }
894
    } else {
895
        $calculated =~ s/\{Y\}/$newlastvalue2/g;
896
    }
897
    my $z = $val->{'lastvalue3'};
898
    $calculated =~ s/\{Z\}/$z/g;
899
    return $calculated;
908
    return $calculated;
900
}
909
}
901
910
Lines 920-933 sub GetExpirationDate { Link Here
920
    $enddate = $startdate || $subscription->{startdate};
929
    $enddate = $startdate || $subscription->{startdate};
921
    my @date = split( /-/, $enddate );
930
    my @date = split( /-/, $enddate );
922
    return if ( scalar(@date) != 3 || not check_date(@date) );
931
    return if ( scalar(@date) != 3 || not check_date(@date) );
923
    if ( ( $subscription->{periodicity} % 16 ) > 0 ) {
932
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
924
933
    if ( $frequency and $frequency->{unit} ) {
934
 
925
        # If Not Irregular
935
        # If Not Irregular
926
        if ( my $length = $subscription->{numberlength} ) {
936
        if ( my $length = $subscription->{numberlength} ) {
927
937
928
            #calculate the date of the last issue.
938
            #calculate the date of the last issue.
929
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
939
            for ( my $i = 1 ; $i <= $length ; $i++ ) {
930
                $enddate = GetNextDate( $enddate, $subscription );
940
                $enddate = GetNextDate( $subscription, $enddate );
931
            }
941
            }
932
        } elsif ( $subscription->{monthlength} ) {
942
        } elsif ( $subscription->{monthlength} ) {
933
            if ( $$subscription{startdate} ) {
943
            if ( $$subscription{startdate} ) {
Lines 940-949 sub GetExpirationDate { Link Here
940
                my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 );
950
                my @enddate = Add_Delta_Days( $date[0], $date[1], $date[2], $subscription->{weeklength} * 7 );
941
                $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
951
                $enddate = sprintf( "%04d-%02d-%02d", $enddate[0], $enddate[1], $enddate[2] );
942
            }
952
            }
953
        } else {
954
            $enddate = $subscription->{enddate};
943
        }
955
        }
944
        return $enddate;
956
        return $enddate;
945
    } else {
957
    } else {
946
        return;
958
        return $subscription->{enddate};
947
    }
959
    }
948
}
960
}
949
961
Lines 976-995 returns the number of rows affected Link Here
976
=cut
988
=cut
977
989
978
sub ModSubscriptionHistory {
990
sub ModSubscriptionHistory {
979
    my ( $subscriptionid, $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote ) = @_;
991
    my ( $subscriptionid, $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote ) = @_;
980
    my $dbh   = C4::Context->dbh;
992
    my $dbh   = C4::Context->dbh;
981
    my $query = "UPDATE subscriptionhistory 
993
    my $query = "UPDATE subscriptionhistory 
982
                    SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
994
                    SET histstartdate=?,histenddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=?
983
                    WHERE subscriptionid=?
995
                    WHERE subscriptionid=?
984
                ";
996
                ";
985
    my $sth = $dbh->prepare($query);
997
    my $sth = $dbh->prepare($query);
986
    $recievedlist =~ s/^; //;
998
    $receivedlist =~ s/^; // if $receivedlist;
987
    $missinglist  =~ s/^; //;
999
    $missinglist  =~ s/^; // if $missinglist;
988
    $opacnote     =~ s/^; //;
1000
    $opacnote     =~ s/^; // if $opacnote;
989
    $sth->execute( $histstartdate, $enddate, $recievedlist, $missinglist, $opacnote, $librariannote, $subscriptionid );
1001
    $sth->execute( $histstartdate, $enddate, $receivedlist, $missinglist, $opacnote, $librariannote, $subscriptionid );
990
    return $sth->rows;
1002
    return $sth->rows;
991
}
1003
}
992
1004
1005
# Update missinglist field, used by ModSerialStatus
1006
sub _update_missinglist {
1007
    my $subscriptionid = shift;
1008
1009
    my $dbh = C4::Context->dbh;
1010
    my @missingserials = GetSerials2($subscriptionid, "4,5");
1011
    my $missinglist;
1012
    foreach (@missingserials) {
1013
        if($_->{'status'} == 4) {
1014
            $missinglist .= $_->{'serialseq'} . "; ";
1015
        } elsif($_->{'status'} == 5) {
1016
            $missinglist .= "not issued " . $_->{'serialseq'} . "; ";
1017
        }
1018
    }
1019
    $missinglist =~ s/; $//;
1020
    my $query = qq{
1021
        UPDATE subscriptionhistory
1022
        SET missinglist = ?
1023
        WHERE subscriptionid = ?
1024
    };
1025
    my $sth = $dbh->prepare($query);
1026
    $sth->execute($missinglist, $subscriptionid);
1027
}
1028
1029
# Update recievedlist field, used by ModSerialStatus
1030
sub _update_receivedlist {
1031
    my $subscriptionid = shift;
1032
1033
    my $dbh = C4::Context->dbh;
1034
    my @receivedserials = GetSerials2($subscriptionid, "2");
1035
    my $receivedlist;
1036
    foreach (@receivedserials) {
1037
        $receivedlist .= $_->{'serialseq'} . "; ";
1038
    }
1039
    $receivedlist =~ s/; $//;
1040
    my $query = qq{
1041
        UPDATE subscriptionhistory
1042
        SET recievedlist = ?
1043
        WHERE subscriptionid = ?
1044
    };
1045
    my $sth = $dbh->prepare($query);
1046
    $sth->execute($receivedlist, $subscriptionid);
1047
}
1048
993
=head2 ModSerialStatus
1049
=head2 ModSerialStatus
994
1050
995
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes)
1051
ModSerialStatus($serialid,$serialseq, $planneddate,$publisheddate,$status,$notes)
Lines 1002-1023 Note : if we change from "waited" to something else,then we will have to create Link Here
1002
sub ModSerialStatus {
1058
sub ModSerialStatus {
1003
    my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
1059
    my ( $serialid, $serialseq, $planneddate, $publisheddate, $status, $notes ) = @_;
1004
1060
1061
1005
    #It is a usual serial
1062
    #It is a usual serial
1006
    # 1st, get previous status :
1063
    # 1st, get previous status :
1007
    my $dbh   = C4::Context->dbh;
1064
    my $dbh   = C4::Context->dbh;
1008
    my $query = "SELECT subscriptionid,status FROM serial WHERE  serialid=?";
1065
    my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity
1066
        FROM serial, subscription
1067
        WHERE serial.subscriptionid=subscription.subscriptionid
1068
            AND serialid=?";
1009
    my $sth   = $dbh->prepare($query);
1069
    my $sth   = $dbh->prepare($query);
1010
    $sth->execute($serialid);
1070
    $sth->execute($serialid);
1011
    my ( $subscriptionid, $oldstatus ) = $sth->fetchrow;
1071
    my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow;
1072
    my $frequency = GetSubscriptionFrequency($periodicity);
1012
1073
1013
    # change status & update subscriptionhistory
1074
    # change status & update subscriptionhistory
1014
    my $val;
1075
    my $val;
1015
    if ( $status == 6 ) {
1076
    if ( $status == 6 ) {
1016
        DelIssue( {'serialid'=>$serialid, 'subscriptionid'=>$subscriptionid,'serialseq'=>$serialseq} );
1077
        DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } );
1017
    }
1078
    } else {
1018
    else {
1079
1019
        my $query =
1080
        unless ($frequency->{'unit'}) {
1020
'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?';
1081
            if ( not $planneddate or $planneddate eq '0000-00-00' ) { $planneddate = C4::Dates->new()->output('iso') };
1082
            if ( not $publisheddate or $publisheddate eq '0000-00-00' ) { $publisheddate = C4::Dates->new()->output('iso') };
1083
        }
1084
        my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE  serialid = ?';
1021
        $sth = $dbh->prepare($query);
1085
        $sth = $dbh->prepare($query);
1022
        $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid );
1086
        $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid );
1023
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1087
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
Lines 1025-1082 sub ModSerialStatus { Link Here
1025
        $sth->execute($subscriptionid);
1089
        $sth->execute($subscriptionid);
1026
        my $val = $sth->fetchrow_hashref;
1090
        my $val = $sth->fetchrow_hashref;
1027
        unless ( $val->{manualhistory} ) {
1091
        unless ( $val->{manualhistory} ) {
1028
            $query = "SELECT missinglist,recievedlist FROM subscriptionhistory WHERE  subscriptionid=?";
1092
            if ( $status == 2 || ($oldstatus == 2 && $status != 2) ) {
1029
            $sth   = $dbh->prepare($query);
1093
                  _update_receivedlist($subscriptionid);
1030
            $sth->execute($subscriptionid);
1094
            }
1031
            my ( $missinglist, $recievedlist ) = $sth->fetchrow;
1095
            if($status == 4 || $status == 5
1032
            if ( $status == 2 ) {
1096
              || ($oldstatus == 4 && $status != 4)
1033
1097
              || ($oldstatus == 5 && $status != 5)) {
1034
                $recievedlist .= "; $serialseq"
1098
                _update_missinglist($subscriptionid);
1035
                  unless ( index( "$recievedlist", "$serialseq" ) >= 0 );
1036
            }
1099
            }
1037
1038
            #         warn "missinglist : $missinglist serialseq :$serialseq, ".index("$missinglist","$serialseq");
1039
            $missinglist .= "; $serialseq"
1040
              if ( $status == 4
1041
                and not index( "$missinglist", "$serialseq" ) >= 0 );
1042
            $missinglist .= "; not issued $serialseq"
1043
              if ( $status == 5
1044
                and index( "$missinglist", "$serialseq" ) >= 0 );
1045
            $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE  subscriptionid=?";
1046
            $sth   = $dbh->prepare($query);
1047
            $recievedlist =~ s/^; //;
1048
            $missinglist  =~ s/^; //;
1049
            $sth->execute( $recievedlist, $missinglist, $subscriptionid );
1050
        }
1100
        }
1051
    }
1101
    }
1052
1102
1053
    # create new waited entry if needed (ie : was a "waited" and has changed)
1103
    # create new waited entry if needed (ie : was a "waited" and has changed)
1054
    if ( $oldstatus == 1 && $status != 1 ) {
1104
    if ( $oldstatus == 1 && $status != 1 ) {
1055
        my $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1105
        my $query = qq{
1106
            SELECT subscription.*, subscription_numberpatterns.*,
1107
                   subscription_frequencies.*
1108
            FROM subscription
1109
            LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id
1110
            LEFT JOIN subscription_frequencies ON subscription.periodicity = subscription_frequencies.id
1111
            WHERE subscriptionid = ?
1112
        };
1056
        $sth = $dbh->prepare($query);
1113
        $sth = $dbh->prepare($query);
1057
        $sth->execute($subscriptionid);
1114
        $sth->execute($subscriptionid);
1058
        my $val = $sth->fetchrow_hashref;
1115
        my $val = $sth->fetchrow_hashref;
1059
1116
1060
        # next issue number
1117
        # next issue number
1061
        my (
1118
        my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($val, $publisheddate);
1062
            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
1063
            $newinnerloop1, $newinnerloop2, $newinnerloop3
1064
        ) = GetNextSeq($val);
1065
1119
1066
        # next date (calculated from actual date & frequency parameters)
1120
        # next date (calculated from actual date & frequency parameters)
1067
        my $nextpublisheddate = GetNextDate( $publisheddate, $val );
1121
        my $nextpublisheddate = GetNextDate($val, $publisheddate, 1);
1068
        NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate, $nextpublisheddate );
1122
        my $nextpubdate = $nextpublisheddate;
1123
        NewIssue( $newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpubdate, $nextpubdate );
1069
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1124
        $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
1070
                    WHERE  subscriptionid = ?";
1125
                    WHERE  subscriptionid = ?";
1071
        $sth = $dbh->prepare($query);
1126
        $sth = $dbh->prepare($query);
1072
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1127
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1073
1128
1074
# check if an alert must be sent... (= a letter is defined & status became "arrived"
1129
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1075
        if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) {
1130
        if ( $val->{letter} && $status == 2 && $oldstatus != 2 ) {
1076
            require C4::Letters;
1131
            require C4::Letters;
1077
            C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} );
1132
            C4::Letters::SendAlerts( 'issue', $val->{subscriptionid}, $val->{letter} );
1078
        }
1133
        }
1079
    }
1134
    }
1135
1080
    return;
1136
    return;
1081
}
1137
}
1082
1138
Lines 1090-1120 returns a hashref: Link Here
1090
1146
1091
$nextexepected = {
1147
$nextexepected = {
1092
    serialid => int
1148
    serialid => int
1093
    planneddate => C4::Dates object
1149
    planneddate => ISO date
1094
    }
1150
    }
1095
1151
1096
=cut
1152
=cut
1097
1153
1098
sub GetNextExpected($) {
1154
sub GetNextExpected($) {
1099
    my ($subscriptionid) = @_;
1155
    my ($subscriptionid) = @_;
1100
    my $dbh              = C4::Context->dbh;
1156
1101
    my $sth              = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?');
1157
    my $dbh = C4::Context->dbh;
1158
    my $query = qq{
1159
        SELECT *
1160
        FROM serial
1161
        WHERE subscriptionid = ?
1162
          AND status = ?
1163
        LIMIT 1
1164
    };
1165
    my $sth = $dbh->prepare($query);
1102
1166
1103
    # Each subscription has only one 'expected' issue, with serial.status==1.
1167
    # Each subscription has only one 'expected' issue, with serial.status==1.
1104
    $sth->execute( $subscriptionid, 1 );
1168
    $sth->execute( $subscriptionid, 1 );
1105
    my ( $nextissue ) = $sth->fetchrow_hashref;
1169
    my $nextissue = $sth->fetchrow_hashref;
1106
    if( !$nextissue){
1170
    if ( !$nextissue ) {
1107
         $sth = $dbh->prepare('SELECT serialid,planneddate FROM serial WHERE subscriptionid  = ? ORDER BY planneddate DESC LIMIT 1');
1171
        $query = qq{
1108
         $sth->execute( $subscriptionid );  
1172
            SELECT *
1109
         $nextissue = $sth->fetchrow_hashref;       
1173
            FROM serial
1174
            WHERE subscriptionid = ?
1175
            ORDER BY planneddate DESC
1176
            LIMIT 1
1177
        };
1178
        $sth = $dbh->prepare($query);
1179
        $sth->execute($subscriptionid);
1180
        $nextissue = $sth->fetchrow_hashref;
1110
    }
1181
    }
1111
    if (!defined $nextissue->{planneddate}) {
1182
    foreach(qw/planneddate publisheddate/) {
1112
        # or should this default to 1st Jan ???
1183
        if ( !defined $nextissue->{$_} ) {
1113
        $nextissue->{planneddate} = strftime('%Y-%m-%d',localtime);
1184
            # or should this default to 1st Jan ???
1185
            $nextissue->{$_} = strftime( '%Y-%m-%d', localtime );
1186
        }
1187
        $nextissue->{$_} = ($nextissue->{$_} ne '0000-00-00')
1188
                         ? $nextissue->{$_}
1189
                         : undef;
1114
    }
1190
    }
1115
    $nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso');
1116
    return $nextissue;
1117
1191
1192
    return $nextissue;
1118
}
1193
}
1119
1194
1120
=head2 ModNextExpected
1195
=head2 ModNextExpected
Lines 1124-1130 ModNextExpected($subscriptionid,$date) Link Here
1124
Update the planneddate for the current expected issue of the subscription.
1199
Update the planneddate for the current expected issue of the subscription.
1125
This will modify all future prediction results.  
1200
This will modify all future prediction results.  
1126
1201
1127
C<$date> is a C4::Dates object.
1202
C<$date> is an ISO date.
1128
1203
1129
returns 0
1204
returns 0
1130
1205
Lines 1138-1148 sub ModNextExpected($$) { Link Here
1138
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1213
    my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
1139
1214
1140
    # Each subscription has only one 'expected' issue, with serial.status==1.
1215
    # Each subscription has only one 'expected' issue, with serial.status==1.
1141
    $sth->execute( $date->output('iso'), $date->output('iso'), $subscriptionid, 1 );
1216
    $sth->execute( $date, $date, $subscriptionid, 1 );
1142
    return 0;
1217
    return 0;
1143
1218
1144
}
1219
}
1145
1220
1221
=head2 GetSubscriptionIrregularities
1222
1223
=over4
1224
1225
=item @irreg = &GetSubscriptionIrregularities($subscriptionid);
1226
get the list of irregularities for a subscription
1227
1228
=back
1229
1230
=cut
1231
1232
sub GetSubscriptionIrregularities {
1233
    my $subscriptionid = shift;
1234
1235
    return undef unless $subscriptionid;
1236
1237
    my $dbh = C4::Context->dbh;
1238
    my $query = qq{
1239
        SELECT irregularity
1240
        FROM subscription
1241
        WHERE subscriptionid = ?
1242
    };
1243
    my $sth = $dbh->prepare($query);
1244
    $sth->execute($subscriptionid);
1245
1246
    my ($result) = $sth->fetchrow_array;
1247
    my @irreg = split /;/, $result;
1248
1249
    return @irreg;
1250
}
1251
1146
=head2 ModSubscription
1252
=head2 ModSubscription
1147
1253
1148
this function modifies a subscription. Put all new values on input args.
1254
this function modifies a subscription. Put all new values on input args.
Lines 1151-1193 returns the number of rows affected Link Here
1151
=cut
1257
=cut
1152
1258
1153
sub ModSubscription {
1259
sub ModSubscription {
1154
    my ($auser,           $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $startdate,   $periodicity,   $firstacquidate,
1260
    my (
1155
        $dow,             $irregularity,    $numberpattern,     $numberlength,     $weeklength,    $monthlength, $add1,          $every1,
1261
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
1156
        $whenmorethan1,   $setto1,          $lastvalue1,        $innerloop1,       $add2,          $every2,      $whenmorethan2, $setto2,
1262
    $periodicity, $firstacquidate, $irregularity, $numberpattern, $locale,
1157
        $lastvalue2,      $innerloop2,      $add3,              $every3,           $whenmorethan3, $setto3,      $lastvalue3,    $innerloop3,
1263
    $numberlength, $weeklength, $monthlength, $lastvalue1, $innerloop1,
1158
        $numberingmethod, $status,          $biblionumber,      $callnumber,       $notes,         $letter,      $hemisphere,    $manualhistory,
1264
    $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status,
1159
        $internalnotes,   $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,    $enddate,       $subscriptionid
1265
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1266
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1267
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq
1160
    ) = @_;
1268
    ) = @_;
1161
1269
1162
    #     warn $irregularity;
1163
    my $dbh   = C4::Context->dbh;
1270
    my $dbh   = C4::Context->dbh;
1164
    my $query = "UPDATE subscription
1271
    my $query = "UPDATE subscription
1165
                    SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
1272
        SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?,
1166
                        periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?,
1273
            startdate=?, periodicity=?, firstacquidate=?, irregularity=?,
1167
                        add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
1274
            numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?,
1168
                        add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
1275
            lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?,
1169
                        add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
1276
            lastvalue3=?, innerloop3=?, status=?, biblionumber=?,
1170
                        numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, 
1277
            callnumber=?, notes=?, letter=?, manualhistory=?,
1171
						letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?,
1278
            internalnotes=?, serialsadditems=?, staffdisplaycount=?,
1172
						staffdisplaycount = ?,opacdisplaycount = ?, graceperiod = ?, location = ?
1279
            opacdisplaycount=?, graceperiod=?, location = ?, enddate=?,
1173
						,enddate=?
1280
            skip_serialseq=?
1174
                    WHERE subscriptionid = ?";
1281
        WHERE subscriptionid = ?";
1175
1282
1176
    #warn "query :".$query;
1177
    my $sth = $dbh->prepare($query);
1283
    my $sth = $dbh->prepare($query);
1178
    $sth->execute(
1284
    $sth->execute(
1179
        $auser,           $branchcode,     $aqbooksellerid, $cost,
1285
        $auser,           $branchcode,     $aqbooksellerid, $cost,
1180
        $aqbudgetid,      $startdate,      $periodicity,    $firstacquidate,
1286
        $aqbudgetid,      $startdate,      $periodicity,    $firstacquidate,
1181
        $dow,             "$irregularity", $numberpattern,  $numberlength,
1287
        $irregularity,    $numberpattern,  $locale,         $numberlength,
1182
        $weeklength,      $monthlength,    $add1,           $every1,
1288
        $weeklength,      $monthlength,    $lastvalue1,     $innerloop1,
1183
        $whenmorethan1,   $setto1,         $lastvalue1,     $innerloop1,
1289
        $lastvalue2,      $innerloop2,     $lastvalue3,     $innerloop3,
1184
        $add2,            $every2,         $whenmorethan2,  $setto2,
1290
        $status,          $biblionumber,   $callnumber,     $notes,
1185
        $lastvalue2,      $innerloop2,     $add3,           $every3,
1291
        $letter,          ($manualhistory ? $manualhistory : 0),
1186
        $whenmorethan3,   $setto3,         $lastvalue3,     $innerloop3,
1187
        $numberingmethod, $status,         $biblionumber,   $callnumber,
1188
        $notes, $letter, $hemisphere, ( $manualhistory ? $manualhistory : 0 ),
1189
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1292
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1190
        $graceperiod,   $location,        $enddate,           $subscriptionid
1293
        $graceperiod,     $location,       $enddate,        $skip_serialseq,
1294
        $subscriptionid
1191
    );
1295
    );
1192
    my $rows = $sth->rows;
1296
    my $rows = $sth->rows;
1193
1297
Lines 1199-1209 sub ModSubscription { Link Here
1199
1303
1200
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
1304
$subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
1201
    $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
1305
    $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
1202
    $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
1306
    $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3,
1203
    $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
1307
    $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern,
1204
    $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
1308
    $callnumber, $hemisphere, $manualhistory, $internalnotes, $serialsadditems,
1205
    $numberingmethod, $status, $notes, $serialsadditems,
1309
    $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq);
1206
    $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate);
1207
1310
1208
Create a new subscription with value given on input args.
1311
Create a new subscription with value given on input args.
1209
1312
Lines 1213-1254 the id of this new subscription Link Here
1213
=cut
1316
=cut
1214
1317
1215
sub NewSubscription {
1318
sub NewSubscription {
1216
    my ($auser,         $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $biblionumber, $startdate,       $periodicity,
1319
    my (
1217
        $dow,           $numberlength,    $weeklength,        $monthlength,      $add1,          $every1,       $whenmorethan1,   $setto1,
1320
    $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1218
        $lastvalue1,    $innerloop1,      $add2,              $every2,           $whenmorethan2, $setto2,       $lastvalue2,      $innerloop2,
1321
    $startdate, $periodicity, $numberlength, $weeklength, $monthlength,
1219
        $add3,          $every3,          $whenmorethan3,     $setto3,           $lastvalue3,    $innerloop3,   $numberingmethod, $status,
1322
    $lastvalue1, $innerloop1, $lastvalue2, $innerloop2, $lastvalue3,
1220
        $notes,         $letter,          $firstacquidate,    $irregularity,     $numberpattern, $callnumber,   $hemisphere,      $manualhistory,
1323
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1221
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,     $enddate
1324
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1325
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1326
    $location, $enddate, $skip_serialseq
1222
    ) = @_;
1327
    ) = @_;
1223
    my $dbh = C4::Context->dbh;
1328
    my $dbh = C4::Context->dbh;
1224
1329
1225
    #save subscription (insert into database)
1330
    #save subscription (insert into database)
1226
    my $query = qq|
1331
    my $query = qq|
1227
        INSERT INTO subscription
1332
        INSERT INTO subscription
1228
            (librarian,branchcode,aqbooksellerid,cost,aqbudgetid,biblionumber,
1333
            (librarian, branchcode, aqbooksellerid, cost, aqbudgetid,
1229
            startdate,periodicity,dow,numberlength,weeklength,monthlength,
1334
            biblionumber, startdate, periodicity, numberlength, weeklength,
1230
            add1,every1,whenmorethan1,setto1,lastvalue1,innerloop1,
1335
            monthlength, lastvalue1, innerloop1, lastvalue2, innerloop2,
1231
            add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2,
1336
            lastvalue3, innerloop3, status, notes, letter, firstacquidate,
1232
            add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3,
1337
            irregularity, numberpattern, locale, callnumber,
1233
            numberingmethod, status, notes, letter,firstacquidate,irregularity,
1338
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1234
            numberpattern, callnumber, hemisphere,manualhistory,internalnotes,serialsadditems,
1339
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq)
1235
            staffdisplaycount,opacdisplaycount,graceperiod,location,enddate)
1340
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1236
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
1237
        |;
1341
        |;
1238
    my $sth = $dbh->prepare($query);
1342
    my $sth = $dbh->prepare($query);
1239
    $sth->execute(
1343
    $sth->execute(
1240
        $auser,         $branchcode,      $aqbooksellerid,    $cost,             $aqbudgetid,    $biblionumber, $startdate,       $periodicity,
1344
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1241
        $dow,           $numberlength,    $weeklength,        $monthlength,      $add1,          $every1,       $whenmorethan1,   $setto1,
1345
        $startdate, $periodicity, $numberlength, $weeklength,
1242
        $lastvalue1,    $innerloop1,      $add2,              $every2,           $whenmorethan2, $setto2,       $lastvalue2,      $innerloop2,
1346
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
1243
        $add3,          $every3,          $whenmorethan3,     $setto3,           $lastvalue3,    $innerloop3,   $numberingmethod, "$status",
1347
        $lastvalue3, $innerloop3, $status, $notes, $letter,
1244
        $notes,         $letter,          $firstacquidate,    $irregularity,     $numberpattern, $callnumber,   $hemisphere,      $manualhistory,
1348
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1245
        $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,   $location,     $enddate
1349
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1350
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq
1246
    );
1351
    );
1247
1352
1248
    my $subscriptionid = $dbh->{'mysql_insertid'};
1353
    my $subscriptionid = $dbh->{'mysql_insertid'};
1249
    unless ($enddate){
1354
    unless ($enddate) {
1250
       $enddate = GetExpirationDate($subscriptionid,$startdate);
1355
        $enddate = GetExpirationDate( $subscriptionid, $startdate );
1251
        $query = q|
1356
        $query = qq|
1252
            UPDATE subscription
1357
            UPDATE subscription
1253
            SET    enddate=?
1358
            SET    enddate=?
1254
            WHERE  subscriptionid=?
1359
            WHERE  subscriptionid=?
Lines 1256-1262 sub NewSubscription { Link Here
1256
        $sth = $dbh->prepare($query);
1361
        $sth = $dbh->prepare($query);
1257
        $sth->execute( $enddate, $subscriptionid );
1362
        $sth->execute( $enddate, $subscriptionid );
1258
    }
1363
    }
1259
    #then create the 1st waited number
1364
1365
    # then create the 1st expected number
1260
    $query = qq(
1366
    $query = qq(
1261
        INSERT INTO subscriptionhistory
1367
        INSERT INTO subscriptionhistory
1262
            (biblionumber, subscriptionid, histstartdate,  opacnote, librariannote)
1368
            (biblionumber, subscriptionid, histstartdate,  opacnote, librariannote)
Lines 1269-1274 sub NewSubscription { Link Here
1269
    $query = qq(
1375
    $query = qq(
1270
        SELECT *
1376
        SELECT *
1271
        FROM   subscription
1377
        FROM   subscription
1378
        LEFT JOIN subscription_numberpatterns ON subscription.numberpattern = subscription_numberpatterns.id
1272
        WHERE  subscriptionid = ?
1379
        WHERE  subscriptionid = ?
1273
    );
1380
    );
1274
    $sth = $dbh->prepare($query);
1381
    $sth = $dbh->prepare($query);
Lines 1288-1295 sub NewSubscription { Link Here
1288
    logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1395
    logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1289
1396
1290
    #set serial flag on biblio if not already set.
1397
    #set serial flag on biblio if not already set.
1291
    my ( $null, ($bib) ) = GetBiblio($biblionumber);
1398
    my $bib = GetBiblioData($biblionumber);
1292
    if ( !$bib->{'serial'} ) {
1399
    if ( $bib and !$bib->{'serial'} ) {
1293
        my $record = GetMarcBiblio($biblionumber);
1400
        my $record = GetMarcBiblio($biblionumber);
1294
        my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
1401
        my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
1295
        if ($tag) {
1402
        if ($tag) {
Lines 1607-1613 sub HasSubscriptionExpired { Link Here
1607
    my ($subscriptionid) = @_;
1714
    my ($subscriptionid) = @_;
1608
    my $dbh              = C4::Context->dbh;
1715
    my $dbh              = C4::Context->dbh;
1609
    my $subscription     = GetSubscription($subscriptionid);
1716
    my $subscription     = GetSubscription($subscriptionid);
1610
    if ( ( $subscription->{periodicity} % 16 ) > 0 ) {
1717
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
1718
    if ( $frequency and $frequency->{unit} ) {
1611
        my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid);
1719
        my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid);
1612
        if (!defined $expirationdate) {
1720
        if (!defined $expirationdate) {
1613
            $expirationdate = q{};
1721
            $expirationdate = q{};
Lines 1631-1636 sub HasSubscriptionExpired { Link Here
1631
            || ( !$res ) );
1739
            || ( !$res ) );
1632
        return 0;
1740
        return 0;
1633
    } else {
1741
    } else {
1742
        # Irregular
1634
        if ( $subscription->{'numberlength'} ) {
1743
        if ( $subscription->{'numberlength'} ) {
1635
            my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} );
1744
            my $countreceived = countissuesfrom( $subscriptionid, $subscription->{'startdate'} );
1636
            return 1 if ( $countreceived > $subscription->{'numberlength'} );
1745
            return 1 if ( $countreceived > $subscription->{'numberlength'} );
Lines 2122-2150 sub abouttoexpire { Link Here
2122
    my $dbh              = C4::Context->dbh;
2231
    my $dbh              = C4::Context->dbh;
2123
    my $subscription     = GetSubscription($subscriptionid);
2232
    my $subscription     = GetSubscription($subscriptionid);
2124
    my $per = $subscription->{'periodicity'};
2233
    my $per = $subscription->{'periodicity'};
2125
    if ($per && $per % 16 > 0){
2234
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($per);
2126
        my $expirationdate   = GetExpirationDate($subscriptionid);
2235
    if ($frequency and $frequency->{unit}){
2236
        my $expirationdate = GetExpirationDate($subscriptionid);
2127
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2237
        my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid);
2128
        my @res;
2238
        my $nextdate = GetNextDate($subscription, $res);
2129
        if (defined $res) {
2239
        if(Date::Calc::Delta_Days(
2130
            @res=split (/-/,$res);
2240
            split( /-/, $nextdate ),
2131
            @res=Date::Calc::Today if ($res[0]*$res[1]==0);
2241
            split( /-/, $expirationdate )
2132
        } else { # default an undefined value
2242
        ) <= 0) {
2133
            @res=Date::Calc::Today;
2243
            return 1;
2134
        }
2244
        }
2135
        my @endofsubscriptiondate=split(/-/,$expirationdate);
2136
        my @per_list = (0, 7, 7, 14, 21, 31, 62, 93, 93, 190, 365, 730, 0, 124, 0, 0);
2137
        my @datebeforeend;
2138
        @datebeforeend = Add_Delta_Days(  $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2],
2139
            - (3 * $per_list[$per])) if (@endofsubscriptiondate && $endofsubscriptiondate[0]*$endofsubscriptiondate[1]*$endofsubscriptiondate[2]);
2140
        return 1 if ( @res &&
2141
            (@datebeforeend &&
2142
                Delta_Days($res[0],$res[1],$res[2],
2143
                    $datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) <= 0) &&
2144
            (@endofsubscriptiondate &&
2145
                Delta_Days($res[0],$res[1],$res[2],
2146
                    $endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) >= 0) );
2147
        return 0;
2148
    } elsif ($subscription->{numberlength}>0) {
2245
    } elsif ($subscription->{numberlength}>0) {
2149
        return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1);
2246
        return (countissuesfrom($subscriptionid,$subscription->{'startdate'}) >=$subscription->{numberlength}-1);
2150
    }
2247
    }
Lines 2161-2330 sub in_array { # used in next sub down Link Here
2161
    return 0;
2258
    return 0;
2162
}
2259
}
2163
2260
2261
=head2 GetFictiveIssueNumber
2262
2263
$issueno = GetFictiveIssueNumber($subscription, $publishedate);
2264
2265
Get the position of the issue published at $publisheddate, considering the
2266
first issue (at firstacquidate) is at position 1, the next is at position 2, etc...
2267
This issuenumber doesn't take into account irregularities, so, for instance, if the 3rd
2268
issue is declared as 'irregular' (will be skipped at receipt), the next issue number
2269
will be 4, not 3. It's why it is called 'fictive'. It is NOT a serial seq, and is not
2270
depending on how many rows are in serial table.
2271
The issue number calculation is based on subscription frequency, first acquisition
2272
date, and $publisheddate.
2273
2274
=cut
2275
2276
sub GetFictiveIssueNumber {
2277
    my ($subscription, $publisheddate) = @_;
2278
2279
    my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
2280
    my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
2281
    my $issueno = 0;
2282
2283
    if($unit) {
2284
        my ($year, $month, $day) = split /-/, $publisheddate;
2285
        my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'};
2286
        my $wkno;
2287
        my $delta;
2288
2289
        if($unit eq 'day') {
2290
            $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day);
2291
        } elsif($unit eq 'week') {
2292
            ($wkno, $year) = Week_of_Year($year, $month, $day);
2293
            my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day);
2294
            $delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2295
        } elsif($unit eq 'month') {
2296
            $delta = ($fa_year == $year)
2297
                   ? ($month - $fa_month)
2298
                   : ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) );
2299
        } elsif($unit eq 'year') {
2300
            $delta = $year - $fa_year;
2301
        }
2302
        if($frequency->{'unitsperissue'} == 1) {
2303
            $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
2304
        } else {
2305
            # Assuming issuesperunit == 1
2306
            $issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} );
2307
        }
2308
    }
2309
    return $issueno;
2310
}
2311
2164
=head2 GetNextDate
2312
=head2 GetNextDate
2165
2313
2166
$resultdate = GetNextDate($planneddate,$subscription)
2314
$resultdate = GetNextDate($publisheddate,$subscription)
2167
2315
2168
this function it takes the planneddate and will return the next issue's date and will skip dates if there
2316
this function it takes the publisheddate and will return the next issue's date
2169
exists an irregularity
2317
and will skip dates if there exists an irregularity.
2170
- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be 
2318
$publisheddate has to be an ISO date
2319
$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit'
2320
$updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database
2321
- eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be
2171
skipped then the returned date will be 2007-05-10
2322
skipped then the returned date will be 2007-05-10
2172
2323
2173
return :
2324
return :
2174
$resultdate - then next date in the sequence
2325
$resultdate - then next date in the sequence (ISO date)
2175
2326
2176
Return 0 if periodicity==0
2327
Return $publisheddate if subscription is irregular
2177
2328
2178
=cut
2329
=cut
2179
2330
2180
sub GetNextDate(@) {
2331
sub GetNextDate {
2181
    my ( $planneddate, $subscription ) = @_;
2332
    my ( $subscription, $publisheddate, $updatecount ) = @_;
2182
    my @irreg = split( /\,/, $subscription->{irregularity} );
2183
2333
2184
    #date supposed to be in ISO.
2334
    my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'});
2185
2335
2186
    my ( $year, $month, $day ) = split( /-/, $planneddate );
2336
    if ($freqdata->{'unit'}) {
2187
    $month = 1 unless ($month);
2337
        my ( $year, $month, $day ) = split /-/, $publisheddate;
2188
    $day   = 1 unless ($day);
2189
    my @resultdate;
2190
2338
2191
    #       warn "DOW $dayofweek";
2339
        # Process an irregularity Hash
2192
    if ( $subscription->{periodicity} % 16 == 0 ) {    # 'without regularity' || 'irregular'
2340
        # Suppose that irregularities are stored in a string with this structure
2193
        return 0;
2341
        # irreg1;irreg2;irreg3
2194
    }
2342
        # where irregX is the number of issue which will not be received
2195
2343
        # (the first issue takes the number 1, the 2nd the number 2 and so on)
2196
    #   daily : n / week
2344
        my @irreg = split /;/, $subscription->{'irregularity'} ;
2197
    #   Since we're interpreting irregularity here as which days of the week to skip an issue,
2345
        my %irregularities;
2198
    #   renaming this pattern from 1/day to " n / week ".
2346
        foreach my $irregularity (@irreg) {
2199
    if ( $subscription->{periodicity} == 1 ) {
2347
            $irregularities{$irregularity} = 1;
2200
        my $dayofweek = eval { Day_of_Week( $year, $month, $day ) };
2201
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2202
        else {
2203
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2204
                $dayofweek = 0 if ( $dayofweek == 7 );
2205
                if ( in_array( ( $dayofweek + 1 ), @irreg ) ) {
2206
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 1 );
2207
                    $dayofweek++;
2208
                }
2209
            }
2210
            @resultdate = Add_Delta_Days( $year, $month, $day, 1 );
2211
        }
2348
        }
2212
    }
2213
2349
2214
    #   1  week
2350
        # Get the 'fictive' next issue number
2215
    if ( $subscription->{periodicity} == 2 ) {
2351
        # It is used to check if next issue is an irregular issue.
2216
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2352
        my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1;
2217
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2353
2218
        else {
2354
        # Then get the next date
2219
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2355
        my $unit = lc $freqdata->{'unit'};
2220
2356
        if ($unit eq 'day') {
2221
                #FIXME: if two consecutive irreg, do we only skip one?
2357
            while ($irregularities{$issueno}) {
2222
                if ( $irreg[$i] == ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 ) ) {
2358
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2223
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 7 );
2359
                    ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{'unitsperissue'} );
2224
                    $wkno = ( ( $wkno != 51 ) ? ( $wkno + 1 ) % 52 : 52 );
2360
                    $subscription->{'countissuesperunit'} = 1;
2361
                } else {
2362
                    $subscription->{'countissuesperunit'}++;
2225
                }
2363
                }
2364
                $issueno++;
2226
            }
2365
            }
2227
            @resultdate = Add_Delta_Days( $year, $month, $day, 7 );
2366
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2228
        }
2367
                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{"unitsperissue"} );
2229
    }
2368
                $subscription->{'countissuesperunit'} = 1;
2230
2369
            } else {
2231
    #   1 / 2 weeks
2370
                $subscription->{'countissuesperunit'}++;
2232
    if ( $subscription->{periodicity} == 3 ) {
2233
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2234
        if ($@) { warn "year month day : $year $month $day $subscription->{subscriptionid} : $@"; }
2235
        else {
2236
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2237
                if ( $irreg[$i] == ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 ) ) {
2238
                    ### BUGFIX was previously +1 ^
2239
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 14 );
2240
                    $wkno = ( ( $wkno != 50 ) ? ( $wkno + 2 ) % 52 : 52 );
2241
                }
2242
            }
2371
            }
2243
            @resultdate = Add_Delta_Days( $year, $month, $day, 14 );
2244
        }
2372
        }
2245
    }
2373
        elsif ($unit eq 'week') {
2246
2374
            my ($wkno, $yr) = Week_of_Year($year, $month, $day);
2247
    #   1 / 3 weeks
2375
            while ($irregularities{$issueno}) {
2248
    if ( $subscription->{periodicity} == 4 ) {
2376
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2249
        my ( $wkno, $year ) = eval { Week_of_Year( $year, $month, $day ) };
2377
                    $subscription->{'countissuesperunit'} = 1;
2250
        if ($@) { warn "année mois jour : $year $month $day $subscription->{subscriptionid} : $@"; }
2378
                    $wkno += $freqdata->{"unitsperissue"};
2251
        else {
2379
                    if($wkno > 52){
2252
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2380
                        $wkno = $wkno % 52;
2253
                if ( $irreg[$i] == ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 ) ) {
2381
                        $yr++;
2254
                    ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, 21 );
2382
                    }
2255
                    $wkno = ( ( $wkno != 49 ) ? ( $wkno + 3 ) % 52 : 52 );
2383
                    my $dow = Day_of_Week($year, $month, $day);
2384
                    ($year,$month,$day) = Monday_of_Week($wkno, $yr);
2385
                    if($freqdata->{'issuesperunit'} == 1) {
2386
                        ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1);
2387
                    }
2388
                } else {
2389
                    $subscription->{'countissuesperunit'}++;
2256
                }
2390
                }
2391
                $issueno++;
2257
            }
2392
            }
2258
            @resultdate = Add_Delta_Days( $year, $month, $day, 21 );
2393
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2259
        }
2394
                $subscription->{'countissuesperunit'} = 1;
2260
    }
2395
                $wkno += $freqdata->{"unitsperissue"};
2261
    my $tmpmonth = $month;
2396
                if($wkno > 52){
2262
    if ( $year && $month && $day ) {
2397
                    $wkno = $wkno % 52 ;
2263
        if ( $subscription->{periodicity} == 5 ) {
2398
                    $yr++;
2264
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2265
                if ( $irreg[$i] == ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 ) ) {
2266
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 );
2267
                    $tmpmonth = ( ( $tmpmonth != 11 ) ? ( $tmpmonth + 1 ) % 12 : 12 );
2268
                }
2399
                }
2269
            }
2400
                my $dow = Day_of_Week($year, $month, $day);
2270
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 1, 0 );
2401
                ($year,$month,$day) = Monday_of_Week($wkno, $yr);
2271
        }
2402
                if($freqdata->{'issuesperunit'} == 1) {
2272
        if ( $subscription->{periodicity} == 6 ) {
2403
                    ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1);
2273
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2274
                if ( $irreg[$i] == ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 ) ) {
2275
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 );
2276
                    $tmpmonth = ( ( $tmpmonth != 10 ) ? ( $tmpmonth + 2 ) % 12 : 12 );
2277
                }
2404
                }
2405
            } else {
2406
                $subscription->{'countissuesperunit'}++;
2278
            }
2407
            }
2279
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 2, 0 );
2280
        }
2408
        }
2281
        if ( $subscription->{periodicity} == 7 ) {
2409
        elsif ($unit eq 'month') {
2282
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2410
            while ($irregularities{$issueno}) {
2283
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2411
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2284
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2412
                    $subscription->{'countissuesperunit'} = 1;
2285
                    $tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 );
2413
                    ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2414
                    unless($freqdata->{'issuesperunit'} == 1) {
2415
                        $day = 1;   # Jumping to the first day of month, because we don't know what day is expected
2416
                    }
2417
                } else {
2418
                    $subscription->{'countissuesperunit'}++;
2286
                }
2419
                }
2420
                $issueno++;
2287
            }
2421
            }
2288
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2422
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2289
        }
2423
                $subscription->{'countissuesperunit'} = 1;
2290
        if ( $subscription->{periodicity} == 8 ) {
2424
                ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"});
2291
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2425
                unless($freqdata->{'issuesperunit'} == 1) {
2292
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2426
                    $day = 1;   # Jumping to the first day of month, because we don't know what day is expected
2293
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2294
                    $tmpmonth = ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 );
2295
                }
2427
                }
2428
            } else {
2429
                $subscription->{'countissuesperunit'}++;
2296
            }
2430
            }
2297
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 3, 0 );
2298
        }
2431
        }
2299
        if ( $subscription->{periodicity} == 13 ) {
2432
        elsif ($unit eq 'year') {
2300
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2433
            while ($irregularities{$issueno}) {
2301
                if ( $irreg[$i] == ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 ) ) {
2434
                if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2302
                    ( $year, $month, $day ) = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
2435
                    $subscription->{'countissuesperunit'} = 1;
2303
                    $tmpmonth = ( ( $tmpmonth != 8 ) ? ( $tmpmonth + 4 ) % 12 : 12 );
2436
                    ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0);
2437
                    unless($freqdata->{'issuesperunit'} == 1) {
2438
                        # Jumping to the first day of year, because we don't know what day is expected
2439
                        $month = 1;
2440
                        $day = 1;
2441
                    }
2442
                } else {
2443
                    $subscription->{'countissuesperunit'}++;
2304
                }
2444
                }
2445
                $issueno++;
2305
            }
2446
            }
2306
            @resultdate = Add_Delta_YMD( $year, $month, $day, 0, 4, 0 );
2447
            if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){
2307
        }
2448
                $subscription->{'countissuesperunit'} = 1;
2308
        if ( $subscription->{periodicity} == 9 ) {
2449
                ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0);
2309
            for ( my $i = 0 ; $i < @irreg ; $i++ ) {
2450
                unless($freqdata->{'issuesperunit'} == 1) {
2310
                if ( $irreg[$i] == ( ( $tmpmonth != 9 ) ? ( $tmpmonth + 3 ) % 12 : 12 ) ) {
2451
                    # Jumping to the first day of year, because we don't know what day is expected
2311
                    ### BUFIX Seems to need more Than One ?
2452
                    $month = 1;
2312
                    ( $year, $month, $day ) = Add_Delta_YM( $year, $month, $day, 0, 6 );
2453
                    $day = 1;
2313
                    $tmpmonth = ( ( $tmpmonth != 6 ) ? ( $tmpmonth + 6 ) % 12 : 12 );
2314
                }
2454
                }
2455
            } else {
2456
                $subscription->{'countissuesperunit'}++;
2315
            }
2457
            }
2316
            @resultdate = Add_Delta_YM( $year, $month, $day, 0, 6 );
2317
        }
2318
        if ( $subscription->{periodicity} == 10 ) {
2319
            @resultdate = Add_Delta_YM( $year, $month, $day, 1, 0 );
2320
        }
2458
        }
2321
        if ( $subscription->{periodicity} == 11 ) {
2459
        if ($updatecount){
2322
            @resultdate = Add_Delta_YM( $year, $month, $day, 2, 0 );
2460
            my $dbh = C4::Context->dbh;
2461
            my $query = qq{
2462
                UPDATE subscription
2463
                SET countissuesperunit = ?
2464
                WHERE subscriptionid = ?
2465
            };
2466
            my $sth = $dbh->prepare($query);
2467
            $sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'});
2323
        }
2468
        }
2469
        return sprintf("%04d-%02d-%02d", $year, $month, $day);
2470
    }
2471
    else {
2472
        return $publisheddate;
2324
    }
2473
    }
2325
    my $resultdate = sprintf( "%04d-%02d-%02d", $resultdate[0], $resultdate[1], $resultdate[2] );
2474
}
2475
2476
=head2 _numeration
2326
2477
2327
    return "$resultdate";
2478
  $string = &_numeration($value,$num_type,$locale);
2479
2480
_numeration returns the string corresponding to $value in the num_type
2481
num_type can take :
2482
    -dayname
2483
    -monthname
2484
    -season
2485
=cut
2486
2487
#'
2488
2489
sub _numeration {
2490
    my ($value, $num_type, $locale) = @_;
2491
    $value ||= 0;
2492
    my $initlocale = setlocale(LC_TIME);
2493
    if($locale and $locale ne $initlocale) {
2494
        $locale = setlocale(LC_TIME, $locale);
2495
    }
2496
    $locale ||= $initlocale;
2497
    my $string;
2498
    $num_type //= '';
2499
    given ($num_type) {
2500
        when (/^dayname$/) {
2501
              $value = $value % 7;
2502
              $string = POSIX::strftime("%A",0,0,0,0,0,0,$value);
2503
        }
2504
        when (/^monthname$/) {
2505
              $value = $value % 12;
2506
              $string = POSIX::strftime("%B",0,0,0,1,$value,0,0,0,0);
2507
        }
2508
        when (/^season$/) {
2509
              my $seasonlocale = ($locale)
2510
                               ? (substr $locale,0,2)
2511
                               : "en";
2512
              my %seasons=(
2513
                 "en" =>
2514
                    [qw(Spring Summer Fall Winter)],
2515
                 "fr"=>
2516
                    [qw(Printemps Été Automne Hiver)],
2517
              );
2518
              $value = $value % 4;
2519
              $string = ($seasons{$seasonlocale})
2520
                      ? $seasons{$seasonlocale}->[$value]
2521
                      : $seasons{'en'}->[$value];
2522
        }
2523
        default {
2524
            $string = $value;
2525
        }
2526
    }
2527
    if($locale ne $initlocale) {
2528
        setlocale(LC_TIME, $initlocale);
2529
    }
2530
    return $string;
2328
}
2531
}
2329
2532
2330
=head2 is_barcode_in_use
2533
=head2 is_barcode_in_use
(-)a/C4/Serials/Frequency.pm (+255 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
}
40
41
=head3 GetSubscriptionFrequencies
42
43
=over 4
44
45
=item C<@frequencies> = &GetSubscriptionFrequencies();
46
47
gets frequencies restricted on filters
48
49
=back
50
51
=cut
52
53
sub GetSubscriptionFrequencies {
54
    my $dbh = C4::Context->dbh;
55
    my $query = qq{
56
        SELECT *
57
        FROM subscription_frequencies
58
        ORDER BY displayorder
59
    };
60
    my $sth = $dbh->prepare($query);
61
    $sth->execute();
62
63
    my $results = $sth->fetchall_arrayref( {} );
64
    return @$results;
65
}
66
67
=head3 GetSubscriptionFrequency
68
69
=over 4
70
71
=item $frequency = &GetSubscriptionFrequency($frequencyid);
72
73
gets frequency where $frequencyid is the identifier
74
75
=back
76
77
=cut
78
79
sub GetSubscriptionFrequency {
80
    my ($frequencyid) = @_;
81
82
    my $dbh = C4::Context->dbh;
83
    my $query = qq{
84
        SELECT *
85
        FROM subscription_frequencies
86
        WHERE id = ?
87
    };
88
    my $sth = $dbh->prepare($query);
89
    $sth->execute($frequencyid);
90
91
    return $sth->fetchrow_hashref;
92
}
93
94
=head3 AddSubscriptionFrequency
95
96
=over 4
97
98
=item C<$frequencyid> = &AddSubscriptionFrequency($frequency);
99
100
Add a new frequency
101
102
=item C<$frequency> is a hashref that can contains the following keys
103
104
=over 2
105
106
=item * description
107
108
=item * unit
109
110
=item * issuesperunit
111
112
=item * unitsperissue
113
114
=item * expectedissuesayear
115
116
=item * displayorder
117
118
=back
119
120
Only description is mandatory.
121
122
=back
123
124
=cut
125
126
sub AddSubscriptionFrequency {
127
    my $frequency = shift;
128
129
    unless(ref($frequency) eq 'HASH' && defined $frequency->{'description'} && $frequency->{'description'} ne '') {
130
        return undef;
131
    }
132
133
    my @keys;
134
    my @values;
135
    foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
136
        if(exists $frequency->{$_}) {
137
            push @keys, $_;
138
            push @values, $frequency->{$_};
139
        }
140
    }
141
142
    my $dbh = C4::Context->dbh;
143
    my $query = "INSERT INTO subscription_frequencies";
144
    $query .= '(' . join(',', @keys) . ')';
145
    $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
146
    my $sth = $dbh->prepare($query);
147
    my $rv = $sth->execute(@values);
148
149
    if(defined $rv) {
150
        return $dbh->last_insert_id(undef, undef, "subscription_frequencies", undef);
151
    }
152
153
    return $rv;
154
}
155
156
=head3 ModSubscriptionFrequency
157
158
=over 4
159
160
=item &ModSubscriptionFrequency($frequency);
161
162
Modifies a frequency
163
164
=item C<$frequency> is a hashref that can contains the following keys
165
166
=over 2
167
168
=item * id
169
170
=item * description
171
172
=item * unit
173
174
=item * issuesperunit
175
176
=item * unitsperissue
177
178
=item * expectedissuesayear
179
180
=item * displayorder
181
182
=back
183
184
Only id is mandatory.
185
186
=back
187
188
=cut
189
190
sub ModSubscriptionFrequency {
191
    my $frequency = shift;
192
193
    unless(
194
      ref($frequency) eq 'HASH'
195
      && defined $frequency->{'id'} && $frequency->{'id'} > 0
196
      && (
197
        (defined $frequency->{'description'}
198
        && $frequency->{'description'} ne '')
199
        || !defined $frequency->{'description'}
200
      )
201
    ) {
202
        return undef;
203
    }
204
205
    my @keys;
206
    my @values;
207
    foreach (qw/ description unit issuesperunit unitsperissue expectedissuesayear displayorder /) {
208
        if(exists $frequency->{$_}) {
209
            push @keys, $_;
210
            push @values, $frequency->{$_};
211
        }
212
    }
213
214
    my $dbh = C4::Context->dbh;
215
    my $query = "UPDATE subscription_frequencies";
216
    $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
217
    $query .= ' WHERE id = ?';
218
    my $sth = $dbh->prepare($query);
219
220
    return $sth->execute(@values, $frequency->{'id'});
221
}
222
223
=head3 DelSubscriptionFrequency
224
225
=over 4
226
227
=item &DelSubscriptionFrequency($frequencyid);
228
229
Delete a frequency
230
231
=back
232
233
=cut
234
235
sub DelSubscriptionFrequency {
236
    my $frequencyid = shift;
237
238
    my $dbh = C4::Context->dbh;
239
    my $query = qq{
240
        DELETE FROM subscription_frequencies
241
        WHERE id = ?
242
    };
243
    my $sth = $dbh->prepare($query);
244
    $sth->execute($frequencyid);
245
}
246
247
1;
248
249
__END__
250
251
=head1 AUTHOR
252
253
Koha Developement team <info@koha.org>
254
255
=cut
(-)a/C4/Serials/Numberpattern.pm (+266 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
    );
42
}
43
44
=head3 GetSubscriptionNumberpatterns
45
46
=over 4
47
48
@results = GetSubscriptionNumberpatterns;
49
this function get all subscription number patterns entered in table
50
51
=back
52
53
=cut
54
55
sub GetSubscriptionNumberpatterns {
56
    my $dbh = C4::Context->dbh;
57
    my $query = qq{
58
        SELECT *
59
        FROM subscription_numberpatterns
60
        ORDER by displayorder
61
    };
62
    my $sth = $dbh->prepare($query);
63
    $sth->execute;
64
    my $results = $sth->fetchall_arrayref({});
65
66
    return @$results;
67
}
68
69
=head3 GetSubscriptionNumberpattern
70
71
=over 4
72
73
$result = GetSubscriptionNumberpattern($numberpatternid);
74
this function get the data of the subscription numberpatterns which id is $numberpatternid
75
76
=back
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
=head3 GetSubscriptionNumberpatternByName
95
96
=over 4
97
98
$result = GetSubscriptionNumberpatternByName($name);
99
this function get the data of the subscription numberpatterns which name is $name
100
101
=back
102
103
=cut
104
105
sub GetSubscriptionNumberpatternByName {
106
    my $name = shift;
107
    my $dbh = C4::Context->dbh;
108
    my $query = qq(
109
        SELECT *
110
        FROM subscription_numberpatterns
111
        WHERE label = ?
112
    );
113
    my $sth = $dbh->prepare($query);
114
    my $rv = $sth->execute($name);
115
116
    return $sth->fetchrow_hashref;
117
}
118
119
=head3 AddSubscriptionNumberpattern
120
121
=over 4
122
123
=item C<$numberpatternid> = &AddSubscriptionNumberpattern($numberpattern)
124
125
Add a new numberpattern
126
127
=item C<$frequency> is a hashref that contains values of the number pattern
128
129
=item Only label and numberingmethod are mandatory
130
131
=back
132
133
=cut
134
135
sub AddSubscriptionNumberpattern {
136
    my $numberpattern = shift;
137
138
    unless(
139
      ref($numberpattern) eq 'HASH'
140
      && defined $numberpattern->{'label'}
141
      && $numberpattern->{'label'} ne ''
142
      && defined $numberpattern->{'numberingmethod'}
143
      && $numberpattern->{'numberingmethod'} ne ''
144
    ) {
145
        return undef;
146
    }
147
148
    my @keys;
149
    my @values;
150
    foreach (qw/ label description numberingmethod displayorder
151
      label1 label2 label3 add1 add2 add3 every1 every2 every3
152
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
153
      numbering1 numbering2 numbering3 /) {
154
        if(exists $numberpattern->{$_}) {
155
            push @keys, $_;
156
            push @values, $numberpattern->{$_};
157
        }
158
    }
159
160
    my $dbh = C4::Context->dbh;
161
    my $query = "INSERT INTO subscription_numberpatterns";
162
    $query .= '(' . join(',', @keys) . ')';
163
    $query .= ' VALUES (' . ('?,' x (scalar(@keys)-1)) . '?)';
164
    my $sth = $dbh->prepare($query);
165
    my $rv = $sth->execute(@values);
166
167
    if(defined $rv) {
168
        return $dbh->last_insert_id(undef, undef, "subscription_numberpatterns", undef);
169
    }
170
171
    return $rv;
172
}
173
174
=head3 ModSubscriptionNumberpattern
175
176
=over 4
177
178
=item &ModSubscriptionNumberpattern($numberpattern)
179
180
Modifies a numberpattern
181
182
=item C<$frequency> is a hashref that contains values of the number pattern
183
184
=item Only id is mandatory
185
186
=back
187
188
=cut
189
190
sub ModSubscriptionNumberpattern {
191
    my $numberpattern = shift;
192
193
    unless(
194
      ref($numberpattern) eq 'HASH'
195
      && defined $numberpattern->{'id'}
196
      && $numberpattern->{'id'} > 0
197
      && (
198
        (defined $numberpattern->{'label'}
199
        && $numberpattern->{'label'} ne '')
200
        || !defined $numberpattern->{'label'}
201
      )
202
      && (
203
        (defined $numberpattern->{'numberingmethod'}
204
        && $numberpattern->{'numberingmethod'} ne '')
205
        || !defined $numberpattern->{'numberingmethod'}
206
      )
207
    ) {
208
        return undef;
209
    }
210
211
    my @keys;
212
    my @values;
213
    foreach (qw/ label description numberingmethod displayorder
214
      label1 label2 label3 add1 add2 add3 every1 every2 every3
215
      setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3
216
      numbering1 numbering2 numbering3 /) {
217
        if(exists $numberpattern->{$_}) {
218
            push @keys, $_;
219
            push @values, $numberpattern->{$_};
220
        }
221
    }
222
223
    my $dbh = C4::Context->dbh;
224
    my $query = "UPDATE subscription_numberpatterns";
225
    $query .= ' SET ' . join(' = ?,', @keys) . ' = ?';
226
    $query .= ' WHERE id = ?';
227
    my $sth = $dbh->prepare($query);
228
229
    return $sth->execute(@values, $numberpattern->{'id'});
230
}
231
232
=head3 DelSubscriptionNumberpattern
233
234
=over 4
235
236
=item &DelSubscriptionNumberpattern($numberpatternid)
237
238
Delete a number pattern
239
240
=back
241
242
=cut
243
244
sub DelSubscriptionNumberpattern {
245
    my $numberpatternid = shift;
246
247
    my $dbh = C4::Context->dbh;
248
    my $query = qq{
249
        DELETE FROM subscription_numberpatterns
250
        WHERE id = ?
251
    };
252
    my $sth = $dbh->prepare($query);
253
    $sth->execute($numberpatternid);
254
}
255
256
257
258
1;
259
260
__END__
261
262
=head1 AUTHOR
263
264
Koha Developement team <info@koha.org>
265
266
=cut
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 1887-1893 CREATE TABLE `subscription` ( Link Here
1887
  `monthlength` int(11) default 0,
1887
  `monthlength` int(11) default 0,
1888
  `numberlength` int(11) default 0,
1888
  `numberlength` int(11) default 0,
1889
  `periodicity` tinyint(4) default 0,
1889
  `periodicity` tinyint(4) default 0,
1890
  countissuesperunit INTEGER NOT NULL DEFAULT 0,
1890
  countissuesperunit INTEGER NOT NULL DEFAULT 1,
1891
  `notes` mediumtext,
1891
  `notes` mediumtext,
1892
  `status` varchar(100) NOT NULL default '',
1892
  `status` varchar(100) NOT NULL default '',
1893
  `lastvalue1` int(11) default NULL,
1893
  `lastvalue1` int(11) default NULL,
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +1 lines)
Lines 5331-5337 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5331
        DROP COLUMN dow,
5331
        DROP COLUMN dow,
5332
        DROP COLUMN issuesatonce,
5332
        DROP COLUMN issuesatonce,
5333
        DROP COLUMN hemisphere,
5333
        DROP COLUMN hemisphere,
5334
        ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 0 AFTER periodicity,
5334
        ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 1 AFTER periodicity,
5335
        ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity,
5335
        ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity,
5336
        ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern,
5336
        ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern,
5337
        ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id),
5337
        ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc (+10 lines)
Lines 18-21 Link Here
18
    [% IF ( CAN_user_serials_check_expiration ) %]
18
    [% IF ( CAN_user_serials_check_expiration ) %]
19
	<li><a href="/cgi-bin/koha/serials/checkexpiration.pl">Check expiration</a></li>
19
	<li><a href="/cgi-bin/koha/serials/checkexpiration.pl">Check expiration</a></li>
20
    [% END %]
20
    [% END %]
21
    <li>
22
        <a href="/cgi-bin/koha/serials/subscription-frequencies.pl">
23
            Manage frequencies
24
        </a>
25
    </li>
26
    <li>
27
        <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">
28
            Manage numbering patterns
29
        </a>
30
    </li>
21
</ul>
31
</ul>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt (-58 / +5 lines)
Lines 88-151 $(document).ready(function() { Link Here
88
</tr>
88
</tr>
89
[% FOREACH subscription IN subscriptions %]
89
[% FOREACH subscription IN subscriptions %]
90
    [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
90
    [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
91
      <td><a href="subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]"># [% subscription.subscriptionid %]</a> </td>
91
        <td><a href="subscription-detail.pl?subscriptionid=[% subscription.subscriptionid %]"># [% subscription.subscriptionid %]</a> </td>
92
      <td>         [% IF ( subscription.periodicity1 ) %]
92
        <td>[% subscription.frequency.description %]</td>
93
                        1/day
93
        <td>[% subscription.numberpattern.label %]</td>
94
                [% END %]
94
        <td> [% subscription.branchcode %]</td>
95
                [% IF ( subscription.periodicity2 ) %]
95
        <td> [% subscription.callnumber %]</td>
96
                        1/week
97
                [% END %]
98
                [% IF ( subscription.periodicity3 ) %]
99
                        1/2 weeks
100
                [% END %]
101
                [% IF ( subscription.periodicity4 ) %]
102
                        1/3 weeks
103
                [% END %]
104
                [% IF ( subscription.periodicity5 ) %]
105
                        1/Month
106
                [% END %]
107
                [% IF ( subscription.periodicity6 ) %]
108
                        1/2 Months (6/year)
109
                [% END %]
110
                [% IF ( subscription.periodicity7 ) %]
111
                        1/quarter
112
                [% END %]
113
                [% IF ( subscription.periodicity8 ) %]
114
                        1/quarter
115
                [% END %]
116
                [% IF ( subscription.periodicity9 ) %]
117
                        2/year
118
                [% END %]
119
                [% IF ( subscription.periodicity10 ) %]
120
                        1/year
121
                [% END %]
122
                [% IF ( subscription.periodicity11 ) %]
123
                        1/2 years
124
                [% END %]</td>
125
           <td>
126
                [% IF ( subscription.numberpattern1 ) %]
127
                    Number
128
                [% END %]
129
                [% IF ( subscription.numberpattern2 ) %]
130
                    Volume, Number, Issue
131
                [% END %]
132
                [% IF ( subscription.numberpattern3 ) %]
133
                    Volume, Number
134
                [% END %]
135
                [% IF ( subscription.numberpattern4 ) %]
136
                    Volume, Issue
137
                [% END %]
138
                [% IF ( subscription.numberpattern5 ) %]
139
                    Number, Issue
140
                [% END %]
141
                [% IF ( subscription.numberpattern6 ) %]
142
                    Seasonal only
143
                [% END %]
144
                [% IF ( subscription.numberpattern7 ) %]
145
                    None of the above
146
                [% END %]</td>
147
            <td> [% subscription.branchcode %]</td>
148
            <td> [% subscription.callnumber %]</td>
149
        <td> [% subscription.notes %]        [% IF ( subscription.subscriptionexpired ) %]<br /><span class="problem"> Subscription expired</span>
96
        <td> [% subscription.notes %]        [% IF ( subscription.subscriptionexpired ) %]<br /><span class="problem"> Subscription expired</span>
150
        [% END %]
97
        [% END %]
151
        </td>
98
        </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt (+83 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") == true) {
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 %]
83
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-1337 / +763 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 12-949 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ Link Here
12
<script type="text/javascript">
14
<script type="text/javascript">
13
//<![CDATA[
15
//<![CDATA[
14
16
15
// the english words used in display purposes
17
var globalnumpatterndata;
16
var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("Starting with:"),_("Rollover at:"),_("Choose Hemisphere:"),_("Northern"),_("Southern"),
18
var globalfreqdata;
17
_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
19
var advancedpatternlocked;
18
var weekno_label = _("Week # ");
20
var patternneedtobetested = 0;
19
var is_season = 0;
21
20
var is_hemisphere = 1;
22
function check_issues(){
21
var irregular_issues;   // will hold irregularity object.
23
    if (globalfreqdata.unit.length >0) {
22
24
        if (document.f.subtype.value == globalfreqdata.unit){
23
function formatDate(myDate) {
25
            document.f.issuelengthcount.value=(document.f.sublength.value*globalfreqdata.issuesperunit)/globalfreqdata.unitsperissue;
24
    var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate());
26
        } else if (document.f.subtype.value != "issues"){
25
    if(d[1].toString().length == 1) { d[1] = '0'+d[1] };
27
            alert(_("Frequency and subscription length provided doesn't combine well. Please consider entering an issue count rather than a time period."));
26
    if(d[2].toString().length == 1) { d[2] = '0'+d[2] };
28
        }
27
    [% IF ( dateformat_us ) %]
28
        return(d[1] + '/' + d[2] + '/' + d[0]) ;
29
    [% ELSIF ( dateformat_metric ) %]
30
        return(d[2] + '/' + d[1] + '/' + d[0]) ;
31
    [% ELSE %]
32
        return(''+d[0] + '-' + d[1] + '-' + d[2]) ;
33
    [% END %]    
34
}
35
36
Date.prototype.addDays = function(days) {
37
    this.setDate(this.getDate()+days);
38
}
39
40
function getWeeksArray(startDate,periodicity) {
41
// returns an array of syspref-formatted dates starting at the first day of startDate's year.
42
// This prediction method will not accurately predict irregularites beyond the first year.
43
// FIXME : Should replace with ajax query to get the first Monday of the year so that week numbers have correct dates.
44
    var incr=1;
45
    if(periodicity==3) {  // 1/2 wks
46
        incr=2;
47
    } else if(periodicity == 4) { // 1/3 wks
48
        incr=3;
49
    }
50
    var weeksArray = new Array;
51
    var jan01 = new Date();
52
    jan01.setDate(1);
53
    jan01.setMonth(0);
54
    jan01.setFullYear(startDate.getFullYear());
55
    for(var i=0;i<52;i++) {
56
        weeksArray[i] = formatDate(jan01) + ' ' + weekno_label + (i + 1);
57
        jan01.addDays( 7 ); 
58
    }
29
    }
59
    return weeksArray;
60
}
30
}
61
31
62
function YMDaToYWDa(S) {
32
function addbiblioPopup(biblionumber) {
63
    with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
33
    var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
64
        var DoW = getUTCDay();
34
    if(biblionumber){
65
        setUTCDate(getUTCDate() - (DoW + 6) % 7 + 3);
35
        destination += "&biblionumber="+biblionumber;
66
        var ms = valueOf();
67
        setUTCMonth(0, 4);
68
        var WN = Math.round((ms - valueOf()) / 604800000) + 1;
69
        return [getUTCFullYear(), WN, DoW == 0 ? 7 : DoW];
70
    }
36
    }
37
    window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
71
}
38
}
72
function dayofyear(d) { // d is a Date object
73
var yn = d.getFullYear();
74
var mn = d.getMonth();
75
var dn = d.getDate();
76
var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
77
var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
78
var ddiff = Math.round((d2-d1)/864e5);
79
return ddiff+1;
80
}
81
82
39
83
// create irregularity object.
40
function Plugin(f)
84
function IrregularPattern() {
41
{
85
	this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
42
    window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
86
	this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
87
    this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday"));
88
    // create weeks irregularity selection array:
89
    this.firstissue = new Date();
90
    this.firstissue.setDate(1);
91
    this.firstissue.setMonth(0);
92
    [% IF ( firstacquiyear ) %] // it's a mod, we already have a start date.
93
        this.firstissue.setFullYear( [% firstacquiyear %] );
94
    [% END %]
95
   	this.weeks = getWeeksArray(this.firstissue); 
96
97
    this.numskipped = 0;
98
    // init:
99
	var irregular = '[% irregularity %]';
100
    this.skipped = irregular.split(',');
101
}
43
}
102
44
103
IrregularPattern.prototype.update = function() {
45
function FindAcqui(f)
104
		this.skipped= new Array;
46
{
105
		var cnt = 0;
47
    window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
106
		// daily periodicity, we interpret irregular array as which days of week to skip.
107
		// else if weekly periodicity, week numbers (starting from 01 Jan) to skip.
108
        // else  irregular array is list of issues to skip
109
		var summary_str = '';
110
		this.numskipped = 0;
111
        if(document.f.irregularity_select) {
112
            //$("#irregularity_select option:selected").each(...); //jquery can combine both conditionals and the for loop
113
            for( var i in document.f.irregularity_select.options ) {
114
                if( document.f.irregularity_select.options[i].selected ) {
115
                    this.skipped[cnt] = document.f.irregularity_select.options[i].value ;
116
                    summary_str += document.f.irregularity_select.options[i].text + "\n" ;
117
				    cnt++;
118
				    this.numskipped++;
119
			    }
120
		    }
121
		    var summary = document.getElementById("irregularity_summary");
122
		    if(summary) {
123
			    summary.value = summary_str;
124
			    summary.rows= ( cnt > 6 ) ? cnt : 6 ; // textarea will bre resized, but not more than 6 lines will show.
125
		    }
126
        }
127
}
48
}
128
49
129
IrregularPattern.prototype.irregular = function(index) { 
50
function Find_ISSN(f)
130
	for( var i in this.skipped) {
51
{
131
			if( this.skipped[i] == index) {
52
    window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
132
				return true;
133
			}
134
	}
135
	return false;
136
}
53
}
137
54
138
function init_pattern() {
55
function Clear(id) {
139
	irregular_issues = new IrregularPattern();
56
    $("#"+id).val('');
140
}
141
function reset_pattern() {
142
	document.getElementById("numberpattern").value = '';
143
    document.getElementById("irregularity").innerHTML = '';
144
	init_pattern();
145
	reset_num_pattern();
146
}
57
}
147
58
148
// common pre defined number patterns
59
function Check_page1() {
149
function reset_num_pattern() {
60
    if ( $("#aqbooksellerid").val().length == 0) {
150
var patternchoice = document.getElementById("numberpattern").value;
61
        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"));
151
    switch(patternchoice){
62
        if (input_box==false) {
152
    case "2":
63
            return false;
153
        document.f.add1.value=1;
64
        }
154
        document.f.add2.value=1;
65
    }
155
        document.f.add3.value=1;
66
    if ($("#biblionumber").val().length == 0) {
156
        document.f.every1.value=12;
67
        alert(_("You must choose or create a biblio"));
157
        document.f.every2.value=1;
68
        return false;
158
        document.f.every3.value=1;
159
        document.f.whenmorethan1.value=9999999;
160
        document.f.whenmorethan2.value=12;
161
        document.f.whenmorethan3.value=4;
162
        document.f.setto1.value=0;
163
        document.f.setto2.value=1;
164
        document.f.setto3.value=1;
165
        document.f.lastvalue1.value=1;
166
        document.f.lastvalue2.value=1;
167
        document.f.lastvalue3.value=1;
168
        document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}");
169
        moreoptions(text[1],text[0],text[2]);
170
        display_table(0); // toggle info box on (1) or off (0)
171
        break;
172
    case "3":
173
        document.f.add1.value=1;
174
        document.f.add2.value=1;
175
        document.f.add3.value='';
176
        document.f.every1.value=12;
177
        document.f.every2.value=1;
178
        document.f.every3.value='';
179
        document.f.whenmorethan1.value=9999999;
180
        document.f.whenmorethan2.value=12;
181
        document.f.whenmorethan3.value='';
182
        document.f.setto1.value=0;
183
        document.f.setto2.value=1;
184
        document.f.setto3.value='';
185
        document.f.lastvalue1.value=1;
186
        document.f.lastvalue2.value=1;
187
        document.f.lastvalue3.value='';
188
        document.f.numberingmethod.value=_("Vol {X}, No {Y}");
189
        moreoptions(text[1],text[0]);
190
        display_table(0);
191
        break;
192
    case "4":
193
        document.f.add1.value=1;
194
        document.f.add2.value=1;
195
        document.f.add3.value='';
196
        document.f.every1.value=12;
197
        document.f.every2.value=1;
198
        document.f.every3.value='';
199
        document.f.whenmorethan1.value=9999999;
200
        document.f.whenmorethan2.value=12;
201
        document.f.whenmorethan3.value='';
202
        document.f.setto1.value=0;
203
        document.f.setto2.value=1;
204
        document.f.setto3.value='';
205
        document.f.lastvalue1.value=1;
206
        document.f.lastvalue2.value=1;
207
        document.f.lastvalue3.value='';
208
        document.f.numberingmethod.value=_("Vol {X}, Issue {Y}");
209
        moreoptions(text[1],text[2]);
210
        display_table(0);
211
        break;
212
    case "5":
213
//        var d = new Date(document.f.firstacquidate.value);
214
//        var smonth = d.getMonth();
215
        document.f.add1.value=1;
216
        document.f.add2.value=1;
217
        document.f.add3.value='';
218
        document.f.every1.value=12;
219
        document.f.every2.value=1;
220
        document.f.every3.value='';
221
        document.f.whenmorethan1.value=9999999;
222
        document.f.whenmorethan2.value=12;
223
        document.f.whenmorethan3.value='';
224
        document.f.setto1.value=0;
225
        document.f.setto2.value=1;
226
        document.f.setto3.value='';
227
        document.f.numberingmethod.value=_("No {X}, Issue {Y}");
228
        moreoptions(text[0],text[2]);
229
        display_table(0);
230
        break;
231
    case "6":
232
        var d = new Date(document.f.firstacquidate.value);
233
        var sYear = d.getFullYear();
234
        moreoptions_seasons(text[15],sYear);
235
        var d = new Date(document.f.firstacquidate.value);
236
        var sYear = d.getFullYear();
237
        document.f.add1.value=1;
238
        document.f.add2.value='1';
239
        document.f.add3.value='';
240
        document.f.every1.value=4;
241
        document.f.every2.value='1';
242
        document.f.every3.value='';
243
        document.f.whenmorethan1.value=9999999;
244
        document.f.whenmorethan2.value='4';
245
        document.f.whenmorethan3.value='';
246
        document.f.setto1.value=0;
247
        document.f.setto2.value='1';
248
        document.f.setto3.value='';
249
        document.f.periodicity.value='8';
250
        document.f.numberingmethod.value=_("{Y} {X}");
251
        moreoptions_seasons(text[15],sYear);
252
        document.f.lastvalue1temp.value=document.f.lastvalue1.value=sYear;
253
        display_table(0);
254
        is_season = 1;
255
        break;
256
    case "7":
257
        display_table(1);
258
        document.getElementById("more_options").innerHTML = '';
259
        document.f.irreg_check.value=1; 
260
        break;
261
    case "8":  // Year/Number
262
        var d = (document.f.firstacquidate.value) ? new Date( document.f.firstacquidate.value) : new Date() ;
263
        var sYear = d.getFullYear();
264
        document.f.add1.value=1;
265
        document.f.add2.value=1;
266
        document.f.add3.value='';
267
        document.f.every1.value=12;
268
        document.f.every2.value=1;
269
        document.f.every3.value='';
270
        document.f.whenmorethan1.value=9999999;
271
        document.f.whenmorethan2.value=12;
272
        document.f.whenmorethan3.value='';
273
        document.f.setto1.value=0;
274
        document.f.setto2.value=1;
275
        document.f.setto3.value='';
276
        document.f.lastvalue1.value=sYear;
277
          switch (document.f.periodicity.value){
278
            case 1:              
279
              var doy = dayofyear(d);
280
              document.f.lastvalue2.value=doy; 
281
              document.f.whenmorethan2.value=365; 
282
              break;      
283
            case 12:     
284
              var doy = dayofyear(d);
285
              document.f.lastvalue2.value=doy*2; 
286
              document.f.whenmorethan2.value=730; 
287
              break;      
288
            case 2:
289
            case 3:
290
            case 4:
291
              var YWDa = YMDaToYWDa(d);
292
              document.f.lastvalue2.value=YWDA[1]/(document.f.periodicity.value-1); 
293
              break;      
294
            case 5:
295
              var smonth = d.getMonth();
296
              document.f.lastvalue2.value=smonth;
297
              break;      
298
            case 6:
299
              var smonth = d.getMonth();
300
              document.f.lastvalue2.value=smonth/2;
301
              document.f.whenmorethan2.value=6;
302
              break;      
303
            case 7:
304
            case 8:      
305
              var smonth = d.getMonth();
306
              document.f.lastvalue2.value=smonth/3;
307
              document.f.whenmorethan2.value=4;
308
              break;      
309
            case 9:                        
310
              var smonth = d.getMonth();
311
              document.f.lastvalue2.value=smonth/6;
312
              document.f.whenmorethan2.value=2;
313
              break;      
314
            default:
315
          } 
316
        document.f.lastvalue3.value='';
317
        document.f.numberingmethod.value=_("{X} / {Y}");
318
        moreoptions(text[16],text[0]);
319
     //   document.f.lastvalue1temp.value=sYear;
320
     //   document.f.lastvalue2temp.value=document.f.lastvalue2.value;
321
        display_table(0);
322
        break;
323
    default:
324
        document.f.add1.value=1;
325
        document.f.add2.value='';
326
        document.f.add3.value='';
327
        document.f.every1.value=1;
328
        document.f.every2.value='';
329
        document.f.every3.value='';
330
        document.f.whenmorethan1.value=9999999;
331
        document.f.whenmorethan2.value='';
332
        document.f.whenmorethan3.value='';
333
        document.f.setto1.value=0;
334
        document.f.setto2.value='';
335
        document.f.setto3.value='';
336
        document.f.lastvalue1.value=1;
337
        document.f.lastvalue2.value='';
338
        document.f.lastvalue3.value='';
339
        document.f.numberingmethod.value='{X}';
340
//        moreoptions_daily_check(text[0]);
341
        moreoptions(text[0]);
342
        document.f.irreg_check.value=1;
343
        display_table(0);
344
        break;
345
    }
69
    }
346
}
347
70
348
function display_table(n) {
71
    return true;
349
    if(n==1){
350
        document.getElementById("basetable").style.display = 'block';
351
    } else if(n==0){
352
        document.getElementById("basetable").style.display = 'none';
353
    } else {
354
		var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ;
355
			document.getElementById("basetable").style.display = disp_val;
356
	}
357
}
72
}
358
73
359
function set_num_pattern_from_template_vars() {
74
function Check_page2(){
360
	if(!document.getElementById("numberpattern")){ return false; }
75
    [% UNLESS (more_than_one_serial) %]
361
    document.getElementById("numberpattern").value = '[% numberpattern %]';
76
      if($("#acqui_date").val().length == 0){
362
    reset_num_pattern();
77
          alert(_("You must choose a first publication date"));
363
    
78
          return false;
364
    document.f.add1.value='[% add1 %]';
79
      }
365
    document.f.add2.value='[% add2 %]';
366
    document.f.add3.value='[% add3 %]';
367
    document.f.every1.value='[% every1 %]';
368
    document.f.every2.value='[% every2 %]';
369
    document.f.every3.value='[% every3 %]';
370
    document.f.whenmorethan1.value='[% whenmorethan1 %]';
371
    document.f.whenmorethan2.value='[% whenmorethan2 %]';
372
    document.f.whenmorethan3.value='[% whenmorethan3 %]';
373
    document.f.setto1.value='[% setto1 %]';
374
    document.f.setto2.value='[% setto2 %]';
375
    document.f.setto3.value='[% setto3 %]';
376
    document.f.lastvalue1.value='[% lastvalue1 %]';
377
    document.f.lastvalue2.value='[% lastvalue2 %]';
378
    document.f.lastvalue3.value='[% lastvalue3 %]';
379
    document.f.numberingmethod.value='[% numberingmethod %]';
380
381
    var more_strY;
382
    var more_strZ;
383
    [% IF ( add2 ) %]
384
    if([% add2 %] > 0){
385
        more_strY="Y";
386
    }
387
    [% END %]
80
    [% END %]
388
    [% IF ( add3 ) %]
81
    if($("#frequency").val().length == 0){
389
    if([% add3 %] > 0){
82
        alert(_("You must choose a frequency"));
390
        more_strZ="Z";
83
        return false;
391
    }
84
    }
392
    [% END %]
85
    if($("#startdate").val().length == 0){
393
    document.f.lastvalue1temp.value='[% lastvalue1 %]';
86
        alert(_("You must choose a start date"));
394
    if(more_strY){
87
        return false;
395
        document.f.lastvalue2temp.value='[% lastvalue2 %]';
396
    document.f.whenmorethan2temp.value='[% whenmorethan2 %]';
397
    }
88
    }
398
    if(more_strZ){
89
    if($("#sublength").val().length == 0 && $("#enddate").val().length == 0){
399
        document.f.lastvalue3temp.value='[% lastvalue3 %]';
90
        alert(_("You must choose a subscription length or an end date."));
400
    document.f.whenmorethan3temp.value='[% whenmorethan3 %]';
91
        return false;
401
    }
92
    }
402
}
93
    if($("#numberpattern").val().length == 0){
403
94
        alert(_("You must choose a numbering pattern"));
404
// a pre check with more options to see if 'number' and '1/day' are chosen
95
        return false;
405
function moreoptions_daily_check(x) {
406
    var periodicity = document.f.periodicity.value;
407
    var errortext='';
408
    if(periodicity == 1){ // i.e. daily
409
        document.getElementById("irregularity").innerHTML = '';
410
        errortext =_("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
411
        for(var j=0;j<irregular_issues.daynames.length;j++){
412
            errortext +="<input type='checkbox' name='irregular' id='irregular"+(j+1)+"' value='"+(j+1)+"' />"+irregular_issues.daynames[j]+" &nbsp; ";
413
        }
414
        var error = errortext;
415
        moreoptions(x);
416
        document.getElementById("irregularity").innerHTML = error;
417
    } else {
418
        document.getElementById("irregularity").innerHTML = '';
419
        document.getElementById("more_options").innerHTML = '';
420
        moreoptions(x);
421
    }
96
    }
422
}
97
    if(advancedpatternlocked == 0){
423
98
        alert(_("You have modified the advanced prediction pattern. Please save your work or cancel modifications."));
424
// to dispaly the more options section
99
        return false;
425
function moreoptions(x,y,z){
426
document.getElementById("irregularity").innerHTML = '';
427
document.getElementById("more_options").innerHTML = '';
428
var textbox = '';
429
    // alert("X: "+x+"Y: "+y+"Z: "+z);
430
    if(x){
431
        textbox +="<table id='irregularity_table'>\n<tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
432
        if(y){
433
            textbox +="<th>"+y+"<\/th>";
434
            if(z){
435
                textbox +="<th>"+z+"<\/th>";
436
            }
437
        }
438
        textbox +="<\/tr>\n";
439
        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";
440
        if(y){
441
            textbox +="<td><input type=\"text\" name=\"lastvalue2temp\" id=\"lastvalue2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue2.value + "\" /><\/td>\n";
442
            if(z){
443
                textbox +="<td><input type=\"text\" name=\"lastvalue3temp\" id=\"lastvalue3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue3.value + "\" /><\/td>\n";
444
            }
445
        }
446
        textbox +="<\/tr>\n";
447
        if(y){
448
            textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
449
            textbox +="<td>&nbsp;<\/td>\n";
450
            textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
451
            if(z){
452
                textbox +="<td><input type=\"text\" name=\"whenmorethan3temp\" id=\"whenmorethan3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
453
            }
454
            textbox +="<\/tr>";
455
        } else {
456
          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>";
457
        }
458
        textbox +="<\/table>\n";
459
    }
100
    }
460
    document.getElementById("more_options").innerHTML = textbox;
101
    if(patternneedtobetested){
461
}
102
        alert(_("Please click on 'Test prediction pattern' before saving subscription."));
462
103
        return false;
463
function hemispheres(chosen){
464
var selbox = document.getElementById("season1");
465
    if(selbox){
466
    var selboxselected = selbox.options[selbox.selectedIndex].value;
467
    selbox.options.length = 0;
468
469
    if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) {
470
        selbox.options[selbox.options.length] = new Option(text[11],'1');
471
        selbox.options[selbox.options.length] = new Option(text[12],'2');
472
        selbox.options[selbox.options.length] = new Option(text[13],'3');
473
        selbox.options[selbox.options.length] = new Option(text[14],'4');
474
        is_hemisphere = 1;
475
        selbox.options[selboxselected-1].selected = true;
476
    }
104
    }
477
105
478
    if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) {
106
    return true;
479
        selbox.options[selbox.options.length] = new Option(text[13],'1');
480
        selbox.options[selbox.options.length] = new Option(text[10],'2');
481
        selbox.options[selbox.options.length] = new Option(text[11],'3');
482
        selbox.options[selbox.options.length] = new Option(text[12],'4');
483
        is_hemisphere = 2;
484
        selbox.options[selboxselected-1].selected = true;
485
    }
486
    }
487
}
107
}
488
108
489
// to display the more options section for seasons
109
function frequencyload(){
490
function moreoptions_seasons(x,y){
110
    $.getJSON("subscription-frequency.pl",{"frequency_id":document.f.frequency.value,ajax:'true'},
491
// x = 'Season'.  y = 'Year'.
111
        function(freqdata){
492
document.getElementById("irregularity").innerHTML = '';
112
            globalfreqdata=freqdata;
493
document.getElementById("more_options").innerHTML = '';
113
            if ( globalfreqdata.unit.length == 0 ) {
494
var textbox = '';
114
                var option = $("#subtype option[value='issues']");
495
    //alert("X: "+x+"Year: "+y);
115
                $(option).attr('selected', 'selected');
496
    if(x){
116
                $("#subtype option[value!='issues']").attr('disabled', 'disabled')
497
        var hemi_select = parseInt('[% hemisphere %]');
117
            } else {
498
        textbox +="<li><label for=\"hemisphere\">"+ text[7]  +"<\/label><select name=\"hemisphere\" id=\"hemisphere\" onchange=\"hemispheres(this.options[this.selectedIndex].value)\">";
118
                $("#subtype option").attr('disabled', '')
499
        for(var i = 1; i <= 2; i++){
500
            textbox +="<option value='"+i+"'";
501
            if(i == hemi_select){
502
                textbox += " selected "
503
            }
119
            }
504
            textbox +=">"+text[i+7]+"<\/option>";
505
        }
506
        textbox +="<\/li>\n";
507
        textbox +="<table id=\"seasonal_irregularity\"><tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
508
        textbox +="<th>"+text[16]+"<\/th>";
509
        textbox +="<\/tr>\n";
510
        textbox +="<tr><th scope=\"row\">"+text[5]+"<\/th><td><select name=\"lastvalue2temp\" id=\"lastvalue2temp\" id=\"season1\" onchange=\"moreoptionsupdate(this)\">";
511
        for(var j = 1; j <= 4; j++){
512
            textbox +="<option value='"+j+"'>"+text[j+9]+"<\/option>";
513
        }
120
        }
514
        textbox +="<\/select><\/td>";
121
    )
515
        var isyr = irregular_issues.firstissue;
516
        textbox += "<td>" + irregular_issues.firstissue.getFullYear() + "<\/td><\/tr>\n";
517
        textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
518
        textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
519
        textbox +="<\/tr><\/table>\n";
520
    }
521
    document.getElementById("more_options").innerHTML = textbox;
522
}
122
}
523
123
524
function irregularity_check(){
124
function numberpatternload(){
525
    document.f.irreg_check.value = 1; // Irregularity button now pushed
125
    $.getJSON("subscription-numberpattern.pl",{"numberpattern_id":document.f.numbering_pattern.value,ajax:'true'},
526
    var periodicity = document.f.periodicity.value;
126
        function(numpatterndata){
527
	var rollover = document.f.issuesexpected1.value;
127
            globalnumpatterndata=numpatterndata;
528
    if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){
128
            if (globalnumpatterndata==undefined){
529
      rollover = document.f.whenmorethan2.value;
129
                return false;
530
    }
130
            }
531
    if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){
131
            displaymoreoptions();
532
        // FIXME: Irregularity check assumes that the full prediction pattern repeats each year.
132
            restoreAdvancedPattern();
533
		//  In cases where the outermost periodicity is > 1 year,  
534
		//  e.g. where a volume spans two years, the irregularity check will be incorrect, 
535
        // but you can safely ignore the check, submit the form, and the prediction pattern should be correct.
536
		//  a way to distinguish between these two cases is needed.
537
		rollover = document.f.whenmorethan3.value * document.f.whenmorethan2.value;
538
    }
539
    var error='';
540
    var toobig;
541
    var expected; 
542
    var errortext = "<b>"+_("Warning irregularity detected")+"</b><br \/>";
543
    switch(periodicity){
544
    case "12":
545
        if(rollover < 730) expected =730;
546
        if(rollover > 730) {
547
            expectedover=730;
548
            toobig=1;
549
        }
550
        break;
551
    case "1":
552
        if(rollover < 365) expected =365;
553
        if(rollover > 365) {
554
            expectedover=365;
555
            toobig=1;
556
        }
557
        break;
558
    case "2":
559
        if(rollover < 52) expected =52;
560
        if(rollover > 52){
561
            expectedover=52;
562
            toobig=1;
563
        }
564
        break;
565
    case "3":
566
        if(rollover < 26) expected =26;
567
        if(rollover > 26){
568
            expectedover=26;
569
            toobig=1;
570
        }
571
        break;
572
    case "4":
573
        if(rollover < 17) expected =17;
574
        if(rollover > 17){
575
            expectedover=17;
576
            toobig=1;
577
        }
578
        break;
579
    case "5":
580
        if(rollover < 12) expected =12;
581
        if(rollover > 12){
582
            expectedover=12;
583
            toobig=1;
584
        }
585
        break;
586
    case "6":
587
        if(rollover < 6) expected =6;
588
        if(rollover > 6){
589
            expectedover=6;
590
            toobig=1;
591
        }
592
        break;
593
    case "7":
594
        if(rollover < 4) expected =4;
595
        if(rollover > 4){
596
            expectedover=4;
597
            toobig=1;
598
        }
599
        break;
600
    case "8":
601
        if(rollover < 4) expected =4;
602
        if(rollover > 4){
603
            expectedover=4;
604
            toobig=1;
605
        }
606
        break;
607
    case "9":
608
        if(rollover < 2) expected =2;
609
        if(rollover > 2){
610
            expectedover=2;
611
            toobig=1;
612
        }
613
        break;
614
    case "10":
615
        if(rollover < 1) expected =1;
616
        if(rollover > 1){
617
            expectedover=1;
618
            toobig=1;
619
        }
133
        }
620
        break;
134
    );
621
    default:
622
        break;
623
    }
624
    if(expected){
625
        if(expected == 365 || expected==730){  // what about leap years ?
626
			// FIXME:  We interpret irregularity as which days per week for periodicity==1.
627
			//  We need two cases: one in which we're published n days/week, in which case irregularity should be per week,
628
			//  and a regular daily pub, where irregularity should be per year.
629
            errortext += _("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
630
        } else {
631
            errortext +=expected+_(" issues expected, ")+rollover+_(" were entered.")+"<br \/>"+_("Please indicate which date(s) an issue is not expected")+"<br \/>";
632
            irregular_issues.numskipped = expected - rollover;
633
		}
634
        errortext +="<select multiple id=\"irregularity_select\" name=\"irregularity_select\" onchange=\"irregular_issues.update();\">\n";
635
		errortext +=irregular_options(periodicity);
636
		errortext += "<\/select>\n <textarea rows=\"6\" width=\"18\" id=\"irregularity_summary\" name=\"irregularity_summary\" value=\"foo\"><\/textarea>";
637
        error=errortext;
638
    }
639
    if(toobig){
640
        errortext +=expectedover+_(" issues expected, ")+rollover+_(" were entered")+"<p class=\"warning\">"+_("You seem to have indicated more issues per year than expected.<\/p>");
641
        error=errortext;
642
    }
643
    if(error.length ==0){
644
        error=_("No irregularities noticed");
645
    }
646
	display_example(expected);
647
    document.getElementById("irregularity").innerHTML = error;
648
	irregular_issues.update();
649
}
135
}
650
136
651
function irregular_options(periodicity){
137
function displaymoreoptions() {
652
    var titles;
138
    if(globalnumpatterndata == undefined){
653
    var count;
139
        $("#moreoptionst").hide();
654
    var errortext='';
140
        return false;
655
    var numberpattern = document.getElementById('numberpattern').value;
656
    if(periodicity == 1) {
657
        expected = 7;
658
        titles = irregular_issues.daynames;
659
        count = 1;
660
    }
141
    }
661
    if(periodicity == 2 || periodicity == 3 || periodicity == 4) { 
142
662
        titles = irregular_issues.weeks;
143
    var X = 0, Y = 0, Z = 0;
663
		count = 1;
144
    var numberingmethod = unescape(globalnumpatterndata.numberingmethod);
664
        if(periodicity==3) {  // 1/2 wks
145
    if(numberingmethod.match(/{X}/)) X = 1;
665
            expected = 26;
146
    if(numberingmethod.match(/{Y}/)) Y = 1;
666
        } else if(periodicity == 4) { // 1/3 wks
147
    if(numberingmethod.match(/{Z}/)) Z = 1;
667
            expected = 17;
148
149
    if(X || Y || Z) {
150
        $("#moreoptionst").show();
151
    } else {
152
        $("#moreoptionst").hide();
153
    }
154
155
    if(X) {
156
        if(globalnumpatterndata.label1) {
157
            $("#headerX").html(unescape(globalnumpatterndata.label1));
668
        } else {
158
        } else {
669
            expected = 52;
159
            $("#headerX").html("X");
670
        }
160
        }
161
        $("#headerX").show();
162
        $("#beginsX").show();
163
        $("#innerX").show();
164
    } else {
165
        $("#headerX").hide();
166
        $("#beginsX").hide();
167
        $("#innerX").hide();
168
        $("#lastvaluetemp1").val('');
169
        $("#innerlooptemp1").val('');
671
    }
170
    }
672
    if(periodicity == 5 || periodicity == 6 || periodicity == 7 || periodicity == 8 || periodicity == 9) {
171
    if(Y) {
673
        if(periodicity == 8 && numberpattern==8) {
172
        if(globalnumpatterndata.label2) {
674
            is_season = 1; // setting up from edit page
173
            $("#headerY").html(unescape(globalnumpatterndata.label2));
675
        } 
676
        if(is_season){
677
            titles = irregular_issues.seasons;
678
            expected = 4;
679
            if(is_hemisphere == 2){
680
                count = 2;
681
            } else {
682
                count = 1;
683
            }
684
        } else {
174
        } else {
685
            titles = irregular_issues.months;
175
            $("#headerY").html("Y");
686
            expected = 12;
687
            count = 1;
688
        }
176
        }
177
        $("#headerY").show();
178
        $("#beginsY").show();
179
        $("#innerY").show();
180
    } else {
181
        $("#headerY").hide();
182
        $("#beginsY").hide();
183
        $("#innerY").hide();
184
        $("#lastvaluetemp2").val('');
185
        $("#innerlooptemp2").val('');
689
    }
186
    }
690
	if( !expected) {
187
    if(Z) {
691
		return '';   // don't know how to deal with irregularity.
188
        if(globalnumpatterndata.label3) {
692
	} 	
189
            $("#headerZ").html(unescape(globalnumpatterndata.label3));
693
    for(var j=0;j<expected;j++){   // rch - changed frrom (1..expected).
190
        } else {
694
        if(isArray(titles)){
191
            $("#headerZ").html("Z");
695
            if(count>expected){
696
                count = count-expected;
697
            }
698
            if(is_season && is_hemisphere == 1){
699
                errortext +="<option value='"+((count*3)-2)+"'>"+titles[j]+"<\/option>\n";
700
// alert("value: "+((count*3)-2)+" title: "+titles[j]);
701
            } else if(is_season && is_hemisphere == 2){
702
                errortext +="<option value='"+((count*3)-2)+"'>"+titles[j-1]+"<\/option>\n";
703
// alert("value: "+((count*3)-2)+" title: "+titles[j-1]);
704
            } else {  // all non-seasonal periodicities:
705
                var incr=1; // multiplier for ( 1/n weeks)  patterns; in this case the irreg calc relies on the week# , not the issue#.
706
                if(periodicity==3) {  // 1/2 wks
707
                    incr=2;
708
                } else if(periodicity == 4) { // 1/3 wks
709
                    incr=3;
710
                }
711
                errortext += "<option value='" + (1+j*incr) ;  
712
				if(irregular_issues.irregular(1+incr*j)) {
713
					errortext += "' selected='selected" ;
714
				}
715
				errortext += "'>"+titles[incr*j]+"<\/option>\n";
716
            }
717
            count++;
718
        } else { 
719
            errortext +="<option value='"+j+"'>"+titles+" "+j+"<\/option>\n";
720
        }
192
        }
193
        $("#headerZ").show();
194
        $("#beginsZ").show();
195
        $("#innerZ").show();
196
    } else {
197
        $("#headerZ").hide();
198
        $("#beginsZ").hide();
199
        $("#innerZ").hide();
200
        $("#lastvaluetemp3").val('');
201
        $("#innerlooptemp3").val('');
721
    }
202
    }
722
    return errortext;
723
}
203
}
724
204
205
function toggleAdvancedPattern() {
206
    $("#advancedpredictionpattern").toggle();
207
}
725
208
726
function display_example(expected){
209
function modifyAdvancedPattern() {
727
    var startfrom1 = parseInt(document.f.lastvalue1.value);
210
    $("#patternname").attr("readonly", false).val('');
728
    var startfrom2 = parseInt(document.f.lastvalue2.value);
211
    $("#numberingmethod").attr("readonly", false);
729
    var startfrom3 = parseInt(document.f.lastvalue3.value);
730
    var every1 = parseInt(document.f.every1.value);
731
    var every2 = parseInt(document.f.every2.value);
732
    var every3 = parseInt(document.f.every3.value);
733
    var numberpattern = document.f.numberingmethod.value;
734
    var whenmorethan2 = parseInt(document.f.whenmorethan2.value);
735
    var whenmorethan3 = parseInt(document.f.whenmorethan3.value);
736
    var setto2 = parseInt(document.f.setto2.value);
737
    var setto3 = parseInt(document.f.setto3.value);
738
    var displaytext = _("Based on the information entered, the Numbering Pattern will look like this: ") + "<br \/><ul class=\"numpattern_preview\">";
739
    if(startfrom3>0){
740
        var count=startfrom3-1;
741
        var count2=startfrom2;
742
        for(var i = 0 ; i < 12; i++){
743
            if(count>=whenmorethan3){
744
                count=setto3;
745
                if(count2>=whenmorethan2){
746
                    startfrom1++;
747
                    count2=setto2;
748
                } else {
749
                    count2++;
750
                }
751
            } else {
752
                count++;
753
            }
754
            displaytext += '<li>' + numberpattern.replace(/{Z}/,count) + '<\/li>\n';
755
            displaytext = displaytext.replace(/{Y}/,count2);
756
            displaytext = displaytext.replace(/{X}/,startfrom1);
757
212
758
        }
213
    $("#advancedpredictionpatternt input").each(function() {
759
    }
214
        $(this).attr("readonly", false);
760
    if(startfrom2>0 && !startfrom3){
215
    });
761
        var count=startfrom2-1;
762
        for(var i=0;i<12;i++){
763
            if(count>=whenmorethan2){
764
                startfrom1++;
765
                count=setto2;
766
            } else {
767
                count++;
768
            }
769
216
770
            if(is_season){
217
    $("#restoreadvancedpatternbutton").show();
771
                if(is_hemisphere == 2){
218
    $("#saveadvancedpatternbutton").show();
772
                    if(count == 1) {
219
    $("#modifyadvancedpatternbutton").hide();
773
                        displaytext += numberpattern.replace(/{Y}/,text[count+12])+'\n';
220
774
                    } else {
221
    advancedpatternlocked = 0;
775
                        displaytext += numberpattern.replace(/{Y}/,text[count+8])+'\n';
222
}
776
                    }
223
777
                } else {
224
function restoreAdvancedPattern() {
778
                displaytext += numberpattern.replace(/{Y}/,text[count+10])+'\n';
225
    $("#patternname").attr("readonly", true).val(unescape(globalnumpatterndata.label));
779
                }
226
    $("#numberingmethod").attr("readonly", true).val(unescape(globalnumpatterndata.numberingmethod));
780
            } else {
227
781
                displaytext += numberpattern.replace(/{Y}/,count)+'\n';
228
    $("#advancedpredictionpatternt input").each(function() {
782
            }
229
        $(this).attr("readonly", true);
783
            displaytext = displaytext.replace(/{X}/,startfrom1)+'<br \/>\n';
230
        var id = $(this).attr('id');
231
        if(id.match(/lastvalue/) || id.match(/innerloop/)) {
232
            var tempid = id.replace(/(\d)/, "temp$1");
233
            $(this).val($("#"+tempid).val());
234
        } else {
235
            $(this).val(unescape(globalnumpatterndata[id]));
784
        }
236
        }
237
    });
238
239
    $("#restoreadvancedpatternbutton").hide();
240
    $("#saveadvancedpatternbutton").hide();
241
    $("#modifyadvancedpatternbutton").show();
242
243
    advancedpatternlocked = 1;
244
}
245
246
function testPredictionPattern() {
247
    var frequencyid = $("#frequency").val();
248
    var acquidate;
249
    var error = 0;
250
    var error_msg = "";
251
    if(frequencyid == undefined || frequencyid == ""){
252
        error_msg += _("- Frequency is not defined\n");
253
        error ++;
785
    }
254
    }
786
    if(startfrom1>0 && !startfrom2 && !startfrom3){
255
    acquidate = $("#acqui_date").val();
787
        var offset=eval(document.f.issuesexpected1.value);
256
    if(acquidate == undefined || acquidate == ""){
788
        if (!offset){
257
        error_msg += _("- First publication date is not defined\n");
789
            offset = 12 
258
        error ++;
790
        }
791
        for(var i=startfrom1;i<(startfrom1+offset);i+=every1){
792
            displaytext += numberpattern.replace(/{X}/,i)+'<br \/>\n';
793
        }
794
    }
259
    }
795
   //  displaytext = "<div style='padding: 5px; background-color: #CCCCCC'>"+displaytext+"<\/div>";
260
    [% IF (more_than_one_serial) %]
796
    document.getElementById("displayexample").innerHTML = displaytext;
261
      var nextacquidate = $("#nextacquidate").val();
797
}
262
      if(nextacquidate == undefined || nextacquidate == ""){
263
        error_msg += _("- Next issue publication date is not defined\n");
264
        error ++;
265
      }
266
    [% END %]
798
267
799
function isArray(obj) {
268
    if(error){
800
if (obj.constructor.toString().indexOf("Array") == -1)
269
        alert(_("Cannot test prediction pattern for the following reason(s):\n\n")
801
    return false;
270
            + error_msg);
802
else
271
        return false;
803
    return true;
272
    }
804
}
805
273
806
function moreoptionsupdate(inputfield,rollover){
274
    var custompattern = 0;
807
    fieldname = inputfield.name;
275
    if(advancedpatternlocked == 0) {
808
    // find parent element in base table by stripping 'temp' from element name.
276
        custompattern = 1;
809
    basefield = document.getElementById(fieldname.slice(0,-4));
277
    }
810
    var fieldnumber = fieldname.slice(-5,-4);
811
278
812
    basefield.value = inputfield.value;
279
    var ajaxData = {
813
    var patternchoice = document.getElementById("numberpattern").value;
280
        'custompattern': custompattern,
814
    switch(patternchoice){
281
        [% IF (subscriptionid) %]
815
    case "2":
282
            'subscriptionid': [% subscriptionid %],
816
    case "4":
283
        [% END %]
817
    case "5":
284
        [% IF (more_than_one_serial) %]
818
    case "8": // Year, Number.  -- Why not just use Vol, Number withvol==year??
285
          'nextacquidate': nextacquidate,
819
                //  FIXME: this my conflict with innerloop calc below.
286
        [% END %]
820
       if (document.f.lastvalue2temp.value > 0){document.f.innerloop1.value = document.f.lastvalue2temp.value - 1;}
287
        'firstacquidate': acquidate
821
      break;   
288
    };
822
    }  
289
    var ajaxParams = [
823
    if(basefield.name.slice(0,-1) == 'lastvalue' || 'whenmorethan' ) {
290
        'enddate', 'subtype', 'sublength', 'frequency', 'numberingmethod',
824
        // The enumeration string is held in a positional numeral notation with three positions, X,Y,Z.
291
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
825
        // The last values lastvalue1, lastvalue2,lastvalue3 should match the last received serial's X,Y,Z enumeration.
292
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
826
        // make array indexes start with 1 for consistency with variable names.
293
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
827
        var innerloop = new Array( undefined, document.getElementById('innerloop1'), document.getElementById('innerloop2'), document.getElementById('innerloop3') );
294
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
828
        var lastvalue = new Array( undefined, document.getElementById('lastvalue1').value *1 , document.getElementById('lastvalue2').value *1 , document.getElementById('lastvalue3').value *1  );
295
    ];
829
        var every = new Array( undefined, document.getElementById('every1').value *1 , document.getElementById('every2').value *1 , document.getElementById('every3').value *1  );
296
    for(i in ajaxParams) {
830
        var add = new Array( undefined, document.getElementById('add1').value *1 , document.getElementById('add2').value *1 , document.getElementById('add3').value *1  );
297
        var param = ajaxParams[i];
831
        var whenmorethan = new Array( undefined, document.getElementById('whenmorethan1').value *1 , document.getElementById('whenmorethan2').value *1 , document.getElementById('whenmorethan3').value *1  );
298
        var value = $("#"+param).val();
832
        
299
        if(value.length > 0)
833
       if(rollover){
300
            ajaxData[param] = value;
834
       // calculate rollover  for higher level of periodicity.
835
       // if there are two levels of periodicity, (e.g. vol{X},num{Y},issue{Z}, then every1=every2*whenmorethan2 / add2 .
836
          for(var N=3;N>1;N--){
837
            if( add[N] > 0){
838
                var addN = (add[N]) ? add[N] : 1 ;
839
                var everyN = (document.getElementById('every'+N)) ? document.getElementById('every'+N).value : 1 ;
840
                document.getElementById('every'+(N-1)).value = whenmorethan[N] * everyN / addN ;
841
            }
842
          }
843
        }
844
        innerloop[3].value = ( every[3] > 1 ) ? lastvalue[3] % every[3] : 0 ;
845
        innerloop[2].value = ( every[2] > 1 ) ? lastvalue[3] - 1 : 0 ;
846
        innerloop[1].value = ( every[1] > 1 ) ? 
847
                                    ( whenmorethan[3] > 0 ) ?  (lastvalue[2] - 1) * every[2] + 1* innerloop[2].value 
848
                                                            : lastvalue[2] - 1
849
                                               : 0 ;
850
    }
301
    }
851
     //FIXME : add checks for innerloop || lastvalue .gt. rollover  
302
303
    $.ajax({
304
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
305
        data: ajaxData,
306
        success: function(data) {
307
            $("#displayexample").html(data);
308
            patternneedtobetested = 0;
309
        }
310
    });
852
}
311
}
853
312
313
function saveAdvancedPattern() {
314
    // Check if patternname already exists, and modify pattern
315
    // instead of creating it if so
316
    var found = 0;
317
    $("#numberpattern option").each(function(){
318
        if($(this).text() == $("#patternname").val()){
319
            found = 1;
320
            return false;
321
        }
322
    });
323
    var cnfrm = 1;
324
    if(found){
325
        cnfrm = confirm(_("This pattern already exists. Do you want to modify it"));
326
    }
854
327
855
function check_input(e){
328
    if(cnfrm) {
856
    var unicode=e.charCode? e.charCode : e.keyCode
329
        var ajaxData = {};
857
    if (unicode!=8 && unicode !=46 && unicode!=9 && unicode !=13){ // if key isn't backspace or delete
330
        var ajaxParams = [
858
        if (unicode<48||unicode>57) { // if not a number
331
            'patternname', 'numberingmethod', 'label1', 'label2', 'label3',
859
            alert(_("Needs to be entered in digit form -eg 10"));
332
            'add1', 'add2', 'add3', 'every1', 'every2', 'every3',
860
            return false // disable key press
333
            'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
334
            'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale'
335
        ];
336
        for(i in ajaxParams) {
337
            var param = ajaxParams[i];
338
            var value = $("#"+param).val();
339
            if(value.length > 0)
340
                ajaxData[param] = value;
861
        }
341
        }
342
343
        $.getJSON(
344
            "/cgi-bin/koha/serials/create-numberpattern.pl",
345
            ajaxData,
346
            function(data){
347
                if(found == 0){
348
                    $("#numberpattern").append("<option value=\""+data.numberpatternid+"\">"+$("#patternname").val()+"</option>");
349
                }
350
                $("#numberpattern").val(data.numberpatternid);
351
                numberpatternload();
352
            }
353
        );
862
    }
354
    }
863
}
355
}
864
356
865
function addbiblioPopup(biblionumber) {
357
function show_page_1() {
866
	var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
358
    $("#page_1").show();
867
	if(biblionumber){ destination += "&biblionumber="+biblionumber; }
359
    $("#page_2").hide();
868
 window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
360
    $("#page_number").text("1/2");
869
}
361
}
870
362
871
function Plugin(f)
363
function show_page_2() {
872
{
364
    $("#page_1").hide();
873
	 window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
365
    $("#page_2").show();
366
    $("#page_number").text("2/2");
367
    displaymoreoptions();
874
}
368
}
875
369
876
function FindAcqui(f)
877
{
878
	 window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
879
}
880
370
881
function Find_ISSN(f)
371
$(document).ready(function() {
882
{
372
    $("select#frequency").change(function(){
883
	 window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
373
        patternneedtobetested = 1;
884
}
374
        $("#enddate").val('');
375
        frequencyload();
376
    });
377
    $("select#numberpattern").change(function(){
378
        patternneedtobetested = 1;
379
        numberpatternload();
380
    });
381
    $("#subtype").change(function(){
382
        $("#enddate").val('');
383
    });
384
    $("#sublength").change(function(){
385
        $("#enddate").val('');
386
    });
387
    $("#lastvaluetemp1").keyup(function(){
388
        $("#lastvalue1").val($(this).val());
389
    });
390
    $("#lastvaluetemp2").keyup(function(){
391
        $("#lastvalue2").val($(this).val());
392
    });
393
    $("#lastvaluetemp3").keyup(function(){
394
        $("#lastvalue3").val($(this).val());
395
    });
396
    $("#lastvalue1").keyup(function(){
397
        $("#lastvaluetemp1").val($(this).val());
398
    });
399
    $("#lastvalue2").keyup(function(){
400
        $("#lastvaluetemp2").val($(this).val());
401
    });
402
    $("#lastvalue3").keyup(function(){
403
        $("#lastvaluetemp3").val($(this).val());
404
    });
885
405
406
    $("#innerlooptemp1").keyup(function(){
407
        $("#innerloop1").val($(this).val());
408
    });
409
    $("#innerlooptemp2").keyup(function(){
410
        $("#innerloop2").val($(this).val());
411
    });
412
    $("#innerlooptemp3").keyup(function(){
413
        $("#innerloop3").val($(this).val());
414
    });
415
    $("#innerloop1").keyup(function(){
416
        $("#innerlooptemp1").val($(this).val());
417
    });
418
    $("#innerloop2").keyup(function(){
419
        $("#innerlooptemp2").val($(this).val());
420
    });
421
    $("#innerloop3").keyup(function(){
422
        $("#innerlooptemp3").val($(this).val());
423
    });
886
424
887
function Check(f) {
425
    if($("#frequency").val() != ""){
888
    if (f.aqbooksellerid.value.length==0) {
426
        frequencyload();
889
        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"));
890
		if (input_box==true) {
891
		}
892
		else {
893
			return false;
894
		}
895
    }
427
    }
896
	if (f.biblionumber.value.length==0) {
428
    if($("#numberpattern").val() != ""){
897
        alert(_("You must choose or create a biblio"));
429
        numberpatternload();
898
    } else if(f.startdate.value.length != 0 && f.sublength.value > 0) {
899
        if (f.irreg_check.value == 1) {
900
            document.f.submit();
901
        } else {
902
            if(f.numbering_pattern.value == ''){
903
                alert(_("Please choose a numbering pattern"));
904
            } else {
905
                alert(_("Please check for irregularity by clicking 'Test Prediction Pattern'"));
906
            }
907
        }
908
    } else {
909
        alert(_("You must choose a start date and a subscription length"));
910
    }
430
    }
911
	if(irregular_issues.numskipped < irregular_issues.skipped.length ) {
912
		alert(_("You have not accounted for all missing issues."));
913
	}
914
    return false;
915
}
916
917
$(document).ready(function() {
918
    init_pattern();
919
	
920
	[% IF ( history ) %] $("#subscription_form_history").show();[% END %]
921
	$("#cancel_manual_history").click(function(){
922
		$("#subscription_form_history").hide();
923
		$("#manuallist").attr("checked","");
924
	});
925
   	$("#manuallist").click( function(){
926
		if($(this).attr("checked")){
927
			$("#subscription_form_history").show();
928
		} else {
929
			$("#subscription_form_history").hide();
930
		}
931
	}
932
	);
933
   //  $(".widelabel").attr("width", "300px");  // labels stay skinny in IE7 anyway.
934
[% IF ( modify ) %]
935
    set_num_pattern_from_template_vars();
936
    [% IF ( hemisphere ) %]
937
	is_hemisphere = [% hemisphere %] ;
938
    hemispheres();
939
    [% END %]
940
[% END %]
941
[% IF ( irregularity ) %]
942
    irregularity_check();
943
[% END %]
944
    $('#numberpattern').change( function() { 
945
        reset_num_pattern(); 
946
    });
947
431
948
    var node;
432
    var node;
949
    [% FOREACH field IN dont_export_field_loop %]
433
    [% FOREACH field IN dont_export_field_loop %]
Lines 954-959 $(document).ready(function() { Link Here
954
            $(node).find("option:first").attr('selected','selected');
438
            $(node).find("option:first").attr('selected','selected');
955
        }
439
        }
956
    [% END %]
440
    [% END %]
441
442
    show_page_1();
957
});
443
});
958
//]]>
444
//]]>
959
</script>
445
</script>
Lines 965-1450 $(document).ready(function() { Link Here
965
<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>
451
<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>
966
452
967
<div id="doc3" class="yui-t7">
453
<div id="doc3" class="yui-t7">
968
   
454
    <div id="bd">
969
   <div id="bd">
455
        <div class="yui-g">
970
<h1>[% IF ( modify ) %] Modify subscription for <i>[% bibliotitle |html %]</i>[% ELSE %]Add a new subscription[% END %]</h1>
456
            <h1>[% IF ( modify ) %] Modify subscription for <i>[% bibliotitle |html %]</i>[% ELSE %]Add a new subscription[% END %] (<span id="page_number">1/2</span>)</h1>
971
   <div class="yui-g">
457
            <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
972
    <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
458
                [% IF ( modify ) %]
973
[% IF ( modify ) %]
459
                    <input type="hidden" name="op" value="modsubscription" />
974
        <input type="hidden" name="op" value="modsubscription" />
460
                    <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
975
        <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
976
[% ELSE %]
977
        <input type="hidden" name="op" value="addsubscription" />
978
[% END %]
979
<input type="hidden" name="user" value="[% loggedinusername %]" />
980
<input type="hidden" name="irreg_check" value="0" />
981
<input type="hidden" name="issuesexpected1" id="issuesexpected1" value="0" />
982
983
	<div class="yui-u first">
984
    <fieldset id="subscription_add_information" class="rows">
985
	<legend>Subscription details</legend>
986
	<ol>
987
	    [% IF ( subscriptionid ) %]
988
        <li><span class="label">Subscription #</span> [% subscriptionid %]</li>
989
        [% END %]
990
        <li>
991
            <label for="aqbooksellerid">Vendor: </label>
992
            <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>
993
        </li>
994
        <li>
995
            <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
996
            
997
                <input type="text" name="biblionumber" id="biblionumber" value="[% bibnum %]" size="8" /> 
998
                (<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>
999
               <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a>
1000
		    [% IF ( CAN_user_editcatalogue ) %] 
1001
		       [% IF ( modify ) %]
1002
		       | <a href="#" onclick="addbiblioPopup([% bibnum %]); return false;">Edit biblio</a>
1003
		       [% ELSE %]
1004
		       | <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a>
1005
		       [% END %]
1006
		    [% END %]
1007
	       </div>
1008
            
1009
        </li>
1010
        <li class="radio">
1011
            [% IF ( serialsadditems ) %]
1012
                <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>
1013
                <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>
1014
            [% ELSE %]
1015
                <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>
1016
                <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>
1017
            [% END %]
1018
        </li>
1019
        <li>
1020
            <label for="branchcode">Library:</label>
1021
            
1022
                <select name="branchcode" id="branchcode" style="width: 20em;">
1023
                    [% UNLESS ( Independantbranches ) %]<option value="">None</option>[% END %]
1024
                    [% FOREACH branchloo IN branchloop %][% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
1025
				[% ELSE %]
1026
				<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
1027
				[% END %]
1028
                    [% END %]
1029
                </select> (select a library)
1030
            
1031
        </li>
1032
        <li>
1033
            <label for="location">Location:</label>
1034
            <select name="location" id="location">
1035
                <option value="">None</option>
1036
                [% 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 %]
1037
            </select>
1038
        </li>
1039
         <li>
1040
            <label for="callnumber">Call Number:</label>
1041
            <input type="text" name="callnumber" id="callnumber" value="[% callnumber %]" size="20" />
1042
        </li>
1043
        <li>
1044
            <label for="graceperiod">Grace period:</label> <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s)
1045
        </li>
1046
        <li>
1047
            <label for="notes">Public note:</label>
1048
            <textarea name="notes" id="notes" cols="30" rows="2">[% notes %]</textarea>
1049
        </li>
1050
        <li>
1051
            <label for="internalnotes">Nonpublic note:</label>
1052
            <textarea name="internalnotes" id="internalnotes" cols="30" rows="2">[% internalnotes %]</textarea>
1053
        </li>
1054
        <li>
1055
            
1056
               [% IF ( letterloop ) %]
1057
            <label for="letter">Patron notification: </label>
1058
			   <select name="letter" id="letter">
1059
                    <option value="">None</option>
1060
                [% FOREACH letterloo IN letterloop %]
1061
				[% IF ( letterloo.selected ) %]
1062
                    <option value="[% letterloo.value %]" selected="selected">[% letterloo.lettername %]</option>
1063
[% ELSE %]
1064
                    <option value="[% letterloo.value %]">[% letterloo.lettername %]</option>
1065
[% END %]
1066
                [% END %]
1067
                </select> 
1068
				<div class="hint">Select a notice and patrons on the routing list will be notified when new issues are received.</div>
1069
            	[% ELSE %]
1070
            <span class="label">Patron notification: </span>
1071
				<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>
1072
				[% END %]
1073
        </li>
1074
		<li>
1075
			 <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label>
1076
			 <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/>
1077
		 </li>
1078
		 <li>
1079
			<label class="widelabel" for="opacdisplaycount">Number of issues to display to the public: </label>
1080
			<input type="text" name="opacdisplaycount" id="opacdisplaycount" value="[% opacdisplaycount %]" size="4"/>
1081
		</li>
1082
	</ol>
1083
	</fieldset>
1084
	</div>
1085
	
1086
<div id="subscription_form_history" class="yui-u" style="display:none">
1087
<div><h3 style="display:inline">Subscription history</h3> <a href="#" id="cancel_manual_history">[cancel manual history]</a></div>
1088
        <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>
1089
        <fieldset class="rows">
1090
            <ol>
1091
                <li>
1092
                <label for="histstartdate">Subscription start date</label>
1093
                <input type="text" name="histstartdate" id="histstartdate" value="[% histstartdate %]" /><div class="hint"> (start date of the 1st subscription)</div>
1094
                </li>
1095
                <li>
1096
                <label for="histenddate">Subscription end date</label>
1097
                <input type="text" name="histenddate" id="histenddate" value="[% histenddate %]" /> <div class="hint">(if empty, subscription is still active)</div>
1098
                </li>
1099
                <li>
1100
                <label for="recievedlist">Received issues</label>
1101
                <textarea name="recievedlist" id="recievedlist" cols="60" rows="5">[% recievedlist %]</textarea>
1102
                </li>
1103
                <li>
1104
                <label for="missinglist">Missing issues</label>
1105
                <textarea name="missinglist" id="missinglist" cols="60" rows="5">[% missinglist %]</textarea>
1106
                </li>
1107
                <li>
1108
                <label for="opacnote">Note for OPAC</label>
1109
                <textarea name="opacnote" id="opacnote" cols="60" rows="5">[% opacnote %]</textarea>
1110
                </li>
1111
                <li>
1112
                <label for="librariannote">Note for staff</label>
1113
                <textarea name="librariannote" id="librariannote" cols="60" rows="5">[% librariannote %]</textarea>
1114
                </li>
1115
            </ol>
1116
        </fieldset>
1117
    <fieldset class="action"><input type="submit" value="Save subscription history"  /></fieldset>
1118
</div>
1119
1120
<div class="yui-g">
1121
<div id="subscription_form_planning">
1122
	<fieldset class="rows">
1123
	<legend>Serials planning</legend>
1124
    <ol>
1125
        <li>
1126
           <label for="acqui_date"> First issue publication date:</label>
1127
                [% UNLESS ( modify ) %]<img src="[% themelang %]/lib/calendar/cal.gif" id="acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />[% END %]
1128
                [% IF ( modify ) %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" disabled="disabled" />
1129
                [% ELSE %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" />[% END %]
1130
        </li>
1131
           [% IF ( modify ) %]<li><label for="next_acqui_date"> Next issue publication date:</label>
1132
                <img src="[% themelang %]/lib/calendar/cal.gif" id="next_acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1133
                <input type="text" name="nextacquidate" value="[% nextacquidate %]" size="13" maxlength="10" id="next_acqui_date" />
1134
                </li>[% END %]
1135
                
1136
        <li><!-- both scripts for calendar must follow the input field --> 
1137
                <script type="text/javascript">
1138
                    Calendar.setup({
1139
                        inputField      :   "[% IF ( modify ) %]next_[% END %]acqui_date",
1140
                        ifFormat       :   "[% DHTMLcalendar_dateformat %]",
1141
                        button         :   "[% IF ( modify ) %]next_[% END %]acqui_button",
1142
                        align          :   "Tl",
1143
                        onUpdate        :    function(cal) { 
1144
                                                             irregular_issues.weeks = getWeeksArray(cal.date);
1145
                                                            irregular_issues.firstissue = cal.date;
1146
                                                            if(document.irregularity_summary) {
1147
                                                                irregular_issues.update();
1148
                                                            }
1149
                                                            if(document.getElementById("seasonal_irregularity")) {
1150
                                                                moreoptions_seasons(text[15]);
1151
                                                            }
1152
                                                        } 
1153
                        });
1154
                    Calendar.setup({
1155
                        inputField      :   "[% IF ( modify ) %]next_[% END %]acqui_date",
1156
                        ifFormat       :   "[% DHTMLcalendar_dateformat %]",
1157
                        button         :   "[% IF ( modify ) %]next_[% END %]acqui_date",
1158
                        align          :   "Tl",
1159
                        onUpdate        :    function(cal) { irregular_issues.weeks = getWeeksArray(cal.date);
1160
                                                            irregular_issues.firstissue = cal.date;
1161
                                                            if(document.irregularity_summary) {
1162
                                                                irregular_issues.update();
1163
                                                            }
1164
                                                            if(document.getElementById("seasonal_irregularity")) {
1165
                                                                moreoptions_seasons(text[15]);
1166
                                                            }
1167
                                                        } 
1168
                        });
1169
                </script>
1170
            <label for="periodicity" class="required">Frequency:</label>
1171
            
1172
                <select name="periodicity" size="1" id="periodicity" onchange="javascript:document.getElementsByName('manualhist')[0].checked=(this.value==1); reset_num_pattern();">
1173
                <option value="" selected="selected">-- please choose --</option>
1174
                [% IF ( periodicity16 ) %]
1175
                <option value="16" selected="selected">Without periodicity</option>
1176
                [% ELSE %]
1177
                    <option value="16">Without periodicity</option>
1178
                [% END %]
1179
                [% IF ( periodicity48 ) %]
1180
                <option value="48" selected="selected">Unknown</option>
1181
                [% ELSE %]
1182
                <option value="48">Unknown</option>
1183
                [% END %]
1184
                [% IF ( periodicity32 ) %]
1185
                <option value="32" selected="selected">Irregular</option>
1186
                [% ELSE %]
1187
                    <option value="32">Irregular</option>
1188
                [% END %]
1189
1190
                [% IF ( periodicity12 ) %]
1191
                    <option value="12" selected="selected">2/day</option>
1192
                [% ELSE %]
1193
                    <option value="12">2/day</option>
1194
                [% END %]
1195
                [% IF ( periodicity1 ) %]
1196
                    <option value="1" selected="selected">daily (n/week)</option>
1197
                [% ELSE %]
1198
                    <option value="1">daily (n/week)</option>
1199
                [% END %]
1200
                [% IF ( periodicity2 ) %]
1201
                    <option value="2" selected="selected">1/week</option>
1202
                [% ELSE %]
1203
                    <option value="2">1/week</option>
1204
                [% END %]
1205
                [% IF ( periodicity3 ) %]
1206
                    <option value="3" selected="selected">1/2 weeks </option>
1207
                [% ELSE %]
1208
                    <option value="3">1/2 weeks </option>
1209
                [% END %]
1210
                [% IF ( periodicity4 ) %]
1211
                    <option value="4" selected="selected">1/3 weeks</option>
1212
                [% ELSE %]
1213
                    <option value="4">1/3 weeks</option>
1214
                [% END %]
1215
                [% IF ( periodicity5 ) %]
1216
                    <option value="5" selected="selected">1/month</option>
1217
                [% ELSE %]
1218
                    <option value="5">1/month</option>
1219
                [% END %]
1220
                [% IF ( periodicity6 ) %]
1221
                    <option value="6" selected="selected">1/2 months (6/year)</option>
1222
                [% ELSE %]
1223
                    <option value="6">1/2 months (6/year)</option>
1224
                [% END %]
1225
                [% IF ( periodicity7 ) %]
1226
                    <option value="7" selected="selected">1/3 months (1/quarter)</option>
1227
                [% ELSE %]
1228
                    <option value="7">1/3 months (1/quarter)</option>
1229
                [% END %]
1230
                <!-- periodicity8 is 1/quarter, exactly like periodicity7 but will use it for seasonal option -->
1231
                [% IF ( periodicity8 ) %]
1232
                    <option value="8" selected="selected">1/quarter (seasonal)</option>
1233
                [% ELSE %]
1234
                    <option value="8">1/quarter (seasonal)</option>
1235
                [% END %]
1236
                [% IF ( periodicity13 ) %]
1237
                    <option value="13" selected="selected">1/4 months (3/year)</option>
1238
                [% ELSE %]
461
                [% ELSE %]
1239
                    <option value="13">1/4 months (3/year)</option>
462
                        <input type="hidden" name="op" value="addsubscription" />
1240
                [% END %]
463
                [% END %]
1241
464
                <input type="hidden" name="user" value="[% loggedinusername %]" />
1242
                [% IF ( periodicity9 ) %]
465
                <input type="hidden" name="irreg_check" value="0" />
1243
                    <option value="9" selected="selected">2/years</option>
466
1244
                [% ELSE %]
467
                <div id="page_1">
1245
                    <option value="9">2/year</option>
468
                    <div class="yui-u first">
1246
                [% END %]
469
                        <fieldset id="subscription_add_information" class="rows">
1247
                [% IF ( periodicity10 ) %]
470
                            <legend>Subscription details</legend>
1248
                    <option value="10" selected="selected">1/year</option>
471
                            <ol>
1249
                [% ELSE %]
472
                                [% IF ( subscriptionid ) %]
1250
                    <option value="10">1/year</option>
473
                                    <li><span class="label">Subscription #</span> [% subscriptionid %]</li>
1251
                [% END %]
474
                                [% END %]
1252
                [% IF ( periodicity11 ) %]
475
                                <li>
1253
                    <option value="11" selected="selected">1/2 years</option>
476
                                    <label for="aqbooksellerid">Vendor: </label>
1254
                [% ELSE %]
477
                                    <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>
1255
                    <option value="11">1/2 years</option>
478
                                </li>
1256
                [% END %]
479
                                <li>
1257
                </select> <span class="required">Required</span></li>
480
                                    <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
1258
                <li>
481
                                    <input type="text" name="biblionumber" id="biblionumber" value="[% bibnum %]" size="8" /> 
1259
                    <label for="manuallist"> Manual history:</label>
482
                                    (<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>
1260
                    [% IF ( manualhistory ) %]
483
                                    <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a>
1261
                        <input type="checkbox" name="manualhist" id="manuallist" value="1" checked="checked" />
484
                                        [% IF ( CAN_user_editcatalogue ) %] 
1262
                    [% ELSE %]
485
                                            [% IF ( modify ) %]
1263
                        <input type="checkbox" name="manualhist" id="manuallist" value="1" />
486
                                            | <a href="#" onclick="addbiblioPopup([% bibnum %]); return false;">Edit biblio</a>
1264
                    [% END %]
487
                                            [% ELSE %]
1265
                </li>
488
                                            | <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a>
1266
        <li>
489
                                            [% END %]
1267
           <label for="numberpattern"> Numbering pattern:</label>
490
                                        [% END %]
1268
            
491
                                    </div>
1269
                <select name="numbering_pattern" size="1" id="numberpattern" >
492
                                </li>
1270
                    <option value="" selected="selected">-- please choose --</option>
493
                                <li class="radio">
1271
                    [% IF ( numberpattern1 ) %]
494
                                    [% IF ( serialsadditems ) %]
1272
                        <option value="1" selected="selected">Number</option>
495
                                        <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>
1273
                    [% ELSE %]
496
                                        <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>
1274
                        <option value="1">Number</option>
497
                                    [% ELSE %]
1275
                    [% END %]
498
                                        <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>
1276
                    [% IF ( numberpattern2 ) %]
499
                                        <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>
1277
                        <option value="2" selected="selected">Volume, Number, Issue</option>
500
                                    [% END %]
1278
                    [% ELSE %]
501
                                </li>
1279
                        <option value="2">Volume, Number, Issue</option>
502
                                <li class="radio">
1280
                    [% END %]
503
                                  <p>When there is an irregular issue:</p>
1281
                    [% IF ( numberpattern3 ) %]
504
                                  [% IF (skip_serialseq) %]
1282
                        <option value="3" selected="selected">Volume, Number</option>
505
                                    <p>
1283
                    [% ELSE %]
506
                                      <input type="radio" id="skip_serialseq_yes" name="skip_serialseq" value="1" checked="checked" />
1284
                        <option value="3">Volume, Number</option>
507
                                      <label for="skip_serialseq_yes">Skip issue number</label>
1285
                    [% END %]
508
                                    </p>
1286
                    [% IF ( numberpattern4 ) %]
509
                                    <p>
1287
                        <option value="4" selected="selected">Volume, Issue</option>
510
                                      <input type="radio" id="skip_serialseq_no" name="skip_serialseq" value="0" />
1288
                    [% ELSE %]
511
                                      <label for="skip_serialseq_no">Keep issue number</label>
1289
                        <option value="4">Volume, Issue</option>
512
                                    </p>
1290
                    [% END %]
513
                                  [% ELSE %]
1291
                    [% IF ( numberpattern5 ) %]
514
                                    <p>
1292
                        <option value="5" selected="selected">Number, Issue</option>
515
                                      <input type="radio" id="skip_serialseq_yes" name="skip_serialseq" value="1" />
1293
                    [% ELSE %]
516
                                      <label for="skip_serialseq_yes">Skip issue number</label>
1294
                        <option value="5">Number, Issue</option>
517
                                    </p>
1295
                    [% END %]
518
                                    <p>
1296
                    [% IF ( numberpattern6 ) %]
519
                                      <input type="radio" id="skip_serialseq_no" name="skip_serialseq" value="0" checked="checked" />
1297
                        <option value="6" selected="selected">Seasonal only</option>
520
                                      <label for="skip_serialseq_no">Keep issue number</label>
1298
                    [% ELSE %]
521
                                    </p>
1299
                        <option value="6">Seasonal only</option>
522
                                  [% END %]
1300
                    [% END %]
523
                                </li>
1301
                    [% IF ( numberpattern8 ) %]
524
                                <li>
1302
                        <option value="8" selected="selected">Year/Number</option>
525
                                    <label for="manualhistory">Manual history</label>
1303
                    [% ELSE %]
526
                                    [% IF (manualhistory) %]
1304
                        <option value="8">Year/Number</option>
527
                                        <input type="checkbox" id="manualhistory" name="manualhist" checked="checked" />
1305
                    [% END %]          
528
                                    [% ELSE %]
1306
                    [% IF ( numberpattern7 ) %]
529
                                        <input type="checkbox" id="manualhistory" name="manualhist" />
1307
                        <option value="7" selected="selected">None of the above</option>
530
                                    [% END %]
1308
                    [% ELSE %]
531
                                </li>
1309
                        <option value="7">None of the above</option>
532
                                <li>
1310
                    [% END %]
533
                                    <label for="callnumber">Call number</label>
1311
                </select>
534
                                    <input type="text" name="callnumber" id="callnumber" value="[% callnumber %]" size="20" />
1312
        </li>
535
                                </li>
1313
                <li id="more_options"></li>
536
                                <li>
1314
                <li id="irregularity"></li>
537
                                    <label for="branchcode">Library:</label>
1315
   	           <li id="displayexample"></li>
538
                                    <select name="branchcode" id="branchcode" style="width: 20em;">
1316
        <li>
539
                                        [% UNLESS ( Independantbranches ) %]
1317
           <label for="beginning_date" class="required"> Subscription start date:</label>
540
                                            <option value="">None</option>
1318
            
541
                                        [% END %]
1319
                <img src="[% themelang %]/lib/calendar/cal.gif" id="button1" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
542
                                        [% FOREACH branchloo IN branchloop %]
1320
                <input type="text" name="startdate" value="[% startdate %]" size="13" maxlength="10" id="beginning_date" />
543
                                            [% IF ( branchloo.selected ) %]
1321
                <!-- both scripts for calendar must follow the input field --> 
544
                                                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
1322
                <script type="text/javascript">
545
                                            [% ELSE %]
1323
                    Calendar.setup({
546
                                                <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
1324
                        inputField   : "beginning_date",
547
                                            [% END %]
1325
                        ifFormat     : "[% DHTMLcalendar_dateformat %]",
548
                                        [% END %]
1326
                        button       : "button1",
549
                                    </select> (select a library)
1327
                        align        : "Tl"
550
                                </li>
1328
                    });
551
                                <li>
1329
                    Calendar.setup({
552
                                    <label for="notes">Public note:</label>
1330
                        inputField   : "beginning_date",
553
                                    <textarea name="notes" id="notes" cols="30" rows="2">[% notes %]</textarea>
1331
                        ifFormat     : "[% DHTMLcalendar_dateformat %]",
554
                                </li>
1332
                        button       : "beginning_date",
555
                                <li>
1333
                        align        : "Tl"
556
                                    <label for="internalnotes">Nonpublic note:</label>
1334
                    });
557
                                    <textarea name="internalnotes" id="internalnotes" cols="30" rows="2">[% internalnotes %]</textarea>
1335
                </script>
558
                                </li>
1336
            <span class="required">Required</span>
559
                                <li>
1337
        </li>
560
                                    [% IF ( letterloop ) %]
1338
        <li>
561
                                        <label for="letter">Patron notification: </label>
1339
            <label for="subtype" class="required">Subscription length:</label>
562
                                        <select name="letter" id="letter">
1340
            
563
                                            <option value="">None</option>
1341
                <select name="subtype" id="subtype">
564
                                            [% FOREACH letterloo IN letterloop %]
1342
					[% IF ( subtype_monthlength ) %]<option value="monthlength" selected="selected">[% ELSE %]<option value="monthlength">[% END %] Number of months</option>					
565
                                                [% IF ( letterloo.selected ) %]
1343
					[% IF ( subtype_numberlength ) %]<option value="numberlength" selected="selected">[% ELSE %]<option value="numberlength">[% END %] Number of issues</option>					
566
                                                    <option value="[% letterloo.value %]" selected="selected">[% letterloo.lettername %]</option>
1344
					[% IF ( subtype_weeklength ) %]<option value="weeklength" selected="selected">[% ELSE %]<option value="weeklength">[% END %] Number of weeks</option>					
567
                                                [% ELSE %]
1345
                </select>
568
                                                    <option value="[% letterloo.value %]">[% letterloo.lettername %]</option>
1346
                <input type="text" id="numberlength" name="sublength" value="[% sublength %]" size="3" onkeypress="return check_input(event)" /> (enter amount in numerals)
569
                                                [% END %]
1347
            <span class="required">Required</span>
570
                                            [% END %]
1348
        </li>
571
                                        </select>
1349
        <li>
572
                                        <div class="hint">Select a notice and patrons on the routing list will be notified when new issues are received.</div>
1350
           <label for="ending_date"> Subscription end date:</label>
573
                                    [% ELSE %]
1351
            
574
                                        <span class="label">Patron notification: </span>
1352
                <img src="[% themelang %]/lib/calendar/cal.gif" id="buttonend1" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
575
                                        <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>
1353
                <input type="text" name="enddate" value="[% enddate %]" size="13" maxlength="10" id="ending_date" />
576
                                    [% END %]
1354
                <!-- both scripts for calendar must follow the input field --> 
577
                                </li>
1355
                <script type="text/javascript">
578
                                <li>
1356
                    Calendar.setup({
579
                                    <label for="location">Location:</label>
1357
                        inputField   : "ending_date",
580
                                    <select name="location" id="location">
1358
                        ifFormat     : "[% DHTMLcalendar_dateformat %]",
581
                                        <option value="">None</option>
1359
                        button       : "buttonend1",
582
                                        [% FOREACH locations_loo IN locations_loop %]
1360
                        align        : "Tl"
583
                                            [% IF ( locations_loo.selected ) %]
1361
                    });
584
                                                <option value="[% locations_loo.authorised_value %]" selected="selected">[% locations_loo.lib %]</option>
1362
                    Calendar.setup({
585
                                            [% ELSE %]
1363
                        inputField   : "ending_date",
586
                                                <option value="[% locations_loo.authorised_value %]">[% locations_loo.lib %]</option>
1364
                        ifFormat     : "[% DHTMLcalendar_dateformat %]",
587
                                            [% END %]
1365
                        button       : "ending_date",
588
                                        [% END %]
1366
                        align        : "Tl"
589
                                    </select>
1367
                    });
590
                                </li>
1368
                </script>
591
                                <li>
1369
        </li>
592
                                    <label for="graceperiod">Grace period:</label>
1370
    <li><label for="numberingmethod">Numbering formula:</label> <input type="text" name="numberingmethod" id="numberingmethod" value="[% numberingmethod %]" />
593
                                    <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s)
1371
    </li>
594
                                </li>
1372
    </ol>
595
                                <li>
1373
	</fieldset>
596
                                     <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label>
1374
</div>
597
                                     <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/>
1375
	<fieldset class="action">
598
                                 </li>
1376
	<input type="button" class="action_test" value="Test Prediction Pattern" onclick="javascript:irregularity_check()" />
599
                                 <li>
1377
	<input type="button" class="action_reset" value="Reset Pattern" onclick="javascript:reset_pattern()" />
600
                                    <label class="widelabel" for="opacdisplaycount">Number of issues to display to the public: </label>
1378
    <input type="button" class="action_save"  value="Save subscription" onclick="Check(this.form)" accesskey="w" />
601
                                    <input type="text" name="opacdisplaycount" id="opacdisplaycount" value="[% opacdisplaycount %]" size="4"/>
1379
	</fieldset>
602
                                </li>
1380
    <fieldset class="action">
603
                            </ol>
1381
    <input type="button" class="action_advanced" value="Show/Hide Advanced Pattern" onclick="javascript:display_table()" />
604
                        </fieldset>
1382
    </fieldset>
605
                        <fieldset class="action">
1383
           <div id="basetable"  style="display: none;">
606
                            <input type="button" value="Next >>" onclick="if ( Check_page1() ) show_page_2();" style="float:right;" />
1384
            <table class="small">
607
                        </fieldset>
1385
                <tr><th colspan="4">Advanced Prediction Pattern</th></tr>
608
                    </div>
1386
				<tr>
609
                </div>
1387
                    <th>&nbsp;</th>
610
1388
                    <th>X</th>
611
                <div id="page_2">
1389
                    <th>Y</th>
612
                    <div class="yui-u first">
1390
                    <th>Z</th>
613
                        <div id="subscription_form_planning">
1391
                </tr>
614
                            <fieldset class="rows">
1392
                <tr>
615
                                <legend>Serials planning</legend>
1393
                    <td>Add</td>
616
                                <ol>
1394
                    <td>
617
                                    <li>
1395
                        <input type="text" name="add1" id="add1" value="[% add1 %]" />
618
                                        <label for="firstacquidate">First issue publication date: (*)</label>
1396
                    </td>
619
                                        [% UNLESS (more_than_one_serial) %]
1397
                    <td>
620
                                          <input type="text" name="firstacquidate" value="[% firstacquidate %]" size="13" maxlength="10" id="acqui_date" readonly="readonly" />
1398
                        <input type="text" name="add2" id="add2" value="[% add2 %]" />
621
                                          <img src="[% themelang %]/lib/calendar/cal.gif" id="button2" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1399
                    </td>
622
                                          <!-- both scripts for calendar must follow the input field --> 
1400
                    <td>
623
                                          <script type="text/javascript">
1401
                        <input type="text" name="add3" id="add3" value="[% add3 %]" />
624
                                              Calendar.setup({
1402
                    </td>
625
                                                  inputField:"acqui_date",
1403
                </tr>
626
                                                  ifFormat       :   "[% DHTMLcalendar_dateformat %]",
1404
                <tr>
627
                                                  button         :   "button2",
1405
                    <td>once every</td>
628
                                                  align          :   "Tl"
1406
                    <td><input type="text" name="every1" id="every1" value="[% every1 %]" /></td>
629
                                              });
1407
                    <td><input type="text" name="every2" id="every2" value="[% every2 %]" /></td>
630
                                          </script>
1408
                    <td><input type="text" name="every3" id="every3" value="[% every3 %]" /></td>
631
                                          <script type="text/javascript">
1409
                </tr>
632
                                              Calendar.setup({
1410
                <tr>
633
                                                  inputField     :   "acqui_date",
1411
                    <td>When more than</td>
634
                                                  ifFormat       :   "[% DHTMLcalendar_dateformat %]",
1412
                    <td><input type="text" name="whenmorethan1" id="whenmorethan1" value="[% whenmorethan1 %]" /></td>
635
                                                  button         :   "acqui_date",
1413
                    <td><input type="text" name="whenmorethan2" id="whenmorethan2" value="[% whenmorethan2 %]" /></td>
636
                                                  align          :   "Tl"
1414
                    <td><input type="text" name="whenmorethan3" id="whenmorethan3" value="[% whenmorethan3 %]" /></td>
637
                                              });
1415
                </tr>
638
                                          </script>
1416
                <tr>
639
                                        [% ELSE %]
1417
                    <td>inner counter</td>
640
                                          [% firstacquidate %]
1418
                    <td><input type="text" name="innerloop1" id="innerloop1" value="[% innerloop1 %]" /></td>
641
                                          <input type="hidden" id="acqui_date" name="firstacquidate" value="[% firstacquidate %]" />
1419
                    <td><input type="text" name="innerloop2" id="innerloop2" value="[% innerloop2 %]" /></td>
642
                                        [% END %]
1420
                    <td><input type="text" name="innerloop3" id="innerloop3" value="[% innerloop3 %]" /></td>
643
                                    </li>
1421
                </tr>
644
                                    [% IF (more_than_one_serial) %]
1422
                <tr>
645
                                      <li>
1423
                    <td>Set back to</td>
646
                                        <label for="nextacquidate">Next issue publication date:</label>
1424
                    <td><input type="text" name="setto1" id="setto1" value="[% setto1 %]" /></td>
647
                                        <input type="text" id="nextacquidate" name="nextacquidate" size="13" readonly="readonly" value="[% nextacquidate | $KohaDates %]" />
1425
                    <td><input type="text" name="setto2" id="setto2" value="[% setto2 %]" /></td>
648
                                        <img src="[% themelang %]/lib/calendar/cal.gif" id="nextacquidatebutton" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1426
                    <td><input type="text" name="setto3" id="setto3" value="[% setto3 %]" /></td>
649
                                        <script type="text/javascript">
1427
                </tr>
650
                                          Calendar.setup({
1428
                <tr>
651
                                            inputField: "nextacquidate",
1429
                    <td>
652
                                            ifFormat: "[% DHTMLcalendar_dateformat %]",
1430
                        [% IF ( modify ) %]
653
                                            button: "nextacquidatebutton",
1431
                            Last value
654
                                            align: "Tl"
1432
                        [% ELSE %]
655
                                          });
1433
                            Begins with
656
                                        </script>
1434
                        [% END %]
657
                                        <script type="text/javascript">
1435
                    </td>
658
                                          Calendar.setup({
1436
                    <td><input type="text" name="lastvalue1" id="lastvalue1" value="[% lastvalue1 %]" /></td>
659
                                            inputField: "nextacquidate",
1437
                    <td><input type="text" name="lastvalue2" id="lastvalue2" value="[% lastvalue2 %]" /></td>
660
                                            ifFormat: "[% DHTMLcalendar_dateformat %]",
1438
                    <td><input type="text" name="lastvalue3" id="lastvalue3" value="[% lastvalue3 %]" /></td>
661
                                            button: "nextacquidate",
1439
                </tr>
662
                                            align: "Tl"
1440
            </table>
663
                                          });
664
                                        </script>
665
                                      </li>
666
                                    [% END %]
667
                                    <li>
668
                                        <label for="frequency">Frequency: (*)</label>
669
                                        <select name="frequency" size="1" id="frequency">
670
                                            <option value="">-- please choose --</option>
671
                                            [% FOREACH frequency IN frequencies %]
672
                                                <option value="[% frequency.id %]" [% IF (frequency.selected) %] selected="selected" [% END %]>
673
                                                    [% frequency.label %]
674
                                                </option>
675
                                            [% END %]
676
                                        </select>
677
                                    </li>
678
                                    <li>
679
                                        <label for="subtype">Subscription length:</label>
680
                                        <select name="subtype" id="subtype">
681
                                            [% FOREACH subt IN subtype %]
682
                                                <option value="[% subt.name %]" [% IF (subt.selected) %] selected="selected" [% END %] >
683
                                                    [% subt.name %]
684
                                                </option>
685
                                            [% END %]
686
                                        </select>
687
                                        <input type="text" name="sublength" id="sublength" value="[% sublength %]" size="3" /> (enter amount in numerals)
688
                                        <input type="hidden" name="issuelengthcount">
689
                                    </li>
690
                                    <li>
691
                                        <label for="startdate"> Subscription start date: (*)</label>
692
                                        <input type="text" name="startdate" value="[% startdate %]" size="13" maxlength="10" id="startdate" readonly="readonly" />
693
                                        <img src="[% themelang %]/lib/calendar/cal.gif" id="button1" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
694
                                        <!-- both scripts for calendar must follow the input field --> 
695
                                        <script type="text/javascript">
696
                                            Calendar.setup({
697
                                                inputField   : "startdate",
698
                                                ifFormat     : "[% DHTMLcalendar_dateformat %]",
699
                                                button       : "button1",
700
                                                align        : "Tl"
701
                                            });
702
                                        </script>
703
                                        <script type="text/javascript">
704
                                            Calendar.setup({
705
                                                inputField   : "startdate",
706
                                                ifFormat     : "[% DHTMLcalendar_dateformat %]",
707
                                                button       : "startdate",
708
                                                align        : "Tl"
709
                                            });
710
                                        </script>
711
                                    </li>
712
                                    <li>
713
                                        <label for="enddate">Subscription end date:</label>
714
                                        <input type="text" name="enddate" value="[% enddate %]" size="13" maxlength="10" id="enddate" readonly="readonly" />
715
                                        <a title="Clear" style="cursor:pointer" onclick="Clear('enddate');">&Chi;</a>
716
                                        <img src="[% themelang %]/lib/calendar/cal.gif" id="button3" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
717
                                        <!-- both scripts for calendar must follow the input field --> 
718
                                        <script type="text/javascript">
719
                                            Calendar.setup({
720
                                                inputField   : "enddate",
721
                                                ifFormat     : "[% DHTMLcalendar_dateformat %]",
722
                                                button       : "button3",
723
                                                align        : "Tl"
724
                                            });
725
                                        </script>
726
                                        <script type="text/javascript">
727
                                            Calendar.setup({
728
                                                inputField   : "enddate",
729
                                                ifFormat     : "[% DHTMLcalendar_dateformat %]",
730
                                                button       : "enddate",
731
                                                align        : "Tl"
732
                                            });
733
                                        </script>
734
                                    </li>
735
                                    <li>
736
                                        <label for="numberpattern"> Numbering pattern:</label>
737
                                        <select name="numbering_pattern" size="1" id="numberpattern">
738
                                            <option value="">-- please choose --</option>
739
                                            [% FOREACH numberpattern IN numberpatterns %]
740
                                                <option value="[% numberpattern.id %]" [% IF (numberpattern.selected) %] selected="selected" [% END %]>[% numberpattern.label %]</option>
741
                                            [% END %]
742
                                        </select>
743
                                    </li>
744
                                    <li>
745
                                        <label for="locale">Locale</label>
746
                                        <input type="text" id="locale" name="locale" value="[% locale %]" />
747
                                        <span class="hint">If empty, system locale is used</span>
748
                                    </li>
749
                                    <li id="more_options">
750
                                        <table id="moreoptionst">
751
                                            <thead>
752
                                                <tr>
753
                                                    <th>&nbsp;</th>
754
                                                    <th id="headerX">&nbsp;</th>
755
                                                    <th id="headerY">&nbsp;</th>
756
                                                    <th id="headerZ">&nbsp;</th>
757
                                                </tr>
758
                                            </thead>
759
                                            <tbody>
760
                                                <tr>
761
                                                    <td>
762
                                                      [% IF (more_than_one_serial) %]
763
                                                        Last value
764
                                                      [% ELSE %]
765
                                                        Begins with
766
                                                      [% END %]
767
                                                    </td>
768
                                                    <td id="beginsX"><input type="text" id="lastvaluetemp1" name="lastvaluetemp1" value="[% lastvalue1 %]" /></td>
769
                                                    <td id="beginsY"><input type="text" id="lastvaluetemp2" name="lastvaluetemp2" value="[% lastvalue2 %]" /></td>
770
                                                    <td id="beginsZ"><input type="text" id="lastvaluetemp3" name="lastvaluetemp3" value="[% lastvalue3 %]" /></td>
771
                                                </tr>
772
                                                <tr>
773
                                                    <td>Inner counter</td>
774
                                                    <td id="innerX"><input type="text" id="innerlooptemp1" name="innerlooptemp1" value="[% innerloop1 %]" /></td>
775
                                                    <td id="innerY"><input type="text" id="innerlooptemp2" name="innerlooptemp2" value="[% innerloop2 %]" /></td>
776
                                                    <td id="innerZ"><input type="text" id="innerlooptemp3" name="innerlooptemp3" value="[% innerloop3 %]" /></td>
777
                                                </tr>
778
                                            </tbody>
779
                                        </table>
780
                                    </li>
781
                                    <li><a style="cursor:pointer" onclick="toggleAdvancedPattern();">Show/Hide advanced pattern</a></li>
782
                                    <div id="advancedpredictionpattern" style="display:none">
783
                                      <li>
784
                                        <label for="patternname">Pattern name: (*)</label>
785
                                        <input id="patternname" name="patternname" type="text" readonly="readonly" />
786
                                      </li>
787
                                      <li>
788
                                        <label for="numberingmethod">Numbering formula:</label>
789
                                        <input readonly="readonly" type="text" name="numberingmethod" id="numberingmethod" size="50" value="[% numberingmethod %]" />
790
                                      </li>
791
                                        <table id="advancedpredictionpatternt">
792
                                            <thead>
793
                                                <tr>
794
                                                    <th colspan="4">Advanced prediction pattern</td>
795
                                                </tr>
796
                                                <tr>
797
                                                    <th>&nbsp;</th>
798
                                                    <th>X</th>
799
                                                    <th>Y</th>
800
                                                    <th>Z</th>
801
                                                </tr>
802
                                            </thead>
803
                                            <tbody>
804
                                                <tr>
805
                                                    <td>Label</td>
806
                                                    <td><input type="text" readonly="readonly" id="label1" name="label1" /></td>
807
                                                    <td><input type="text" readonly="readonly" id="label2" name="label2" /></td>
808
                                                    <td><input type="text" readonly="readonly" id="label3" name="label3" /></td>
809
                                                </tr>
810
                                                <tr>
811
                                                    <td>Begins with</td>
812
                                                    <td><input type="text" readonly="readonly" id="lastvalue1" name="lastvalue1" /></td>
813
                                                    <td><input type="text" readonly="readonly" id="lastvalue2" name="lastvalue2" /></td>
814
                                                    <td><input type="text" readonly="readonly" id="lastvalue3" name="lastvalue3" /></td>
815
                                                </tr>
816
                                                <tr>
817
                                                    <td>Add</td>
818
                                                    <td><input type="text" readonly="readonly" id="add1" name="add1" /></td>
819
                                                    <td><input type="text" readonly="readonly" id="add2" name="add2" /></td>
820
                                                    <td><input type="text" readonly="readonly" id="add3" name="add3" /></td>
821
                                                </tr>
822
                                                <tr>
823
                                                    <td>Every</td>
824
                                                    <td><input type="text" readonly="readonly" id="every1" name="every1" /></td>
825
                                                    <td><input type="text" readonly="readonly" id="every2" name="every2" /></td>
826
                                                    <td><input type="text" readonly="readonly" id="every3" name="every3" /></td>
827
                                                </tr>
828
                                                <tr>
829
                                                    <td>Set back to</td>
830
                                                    <td><input type="text" readonly="readonly" id="setto1" name="setto1" /></td>
831
                                                    <td><input type="text" readonly="readonly" id="setto2" name="setto2" /></td>
832
                                                    <td><input type="text" readonly="readonly" id="setto3" name="setto3" /></td>
833
                                                </tr>
834
                                                <tr>
835
                                                    <td>When more than</td>
836
                                                    <td><input type="text" readonly="readonly" id="whenmorethan1" name="whenmorethan1" /></td>
837
                                                    <td><input type="text" readonly="readonly" id="whenmorethan2" name="whenmorethan2" /></td>
838
                                                    <td><input type="text" readonly="readonly" id="whenmorethan3" name="whenmorethan3" /></td>
839
                                                </tr>
840
                                                <tr>
841
                                                    <td>Inner counter</td>
842
                                                    <td><input type="text" readonly="readonly" id="innerloop1" name="innerloop1" /></td>
843
                                                    <td><input type="text" readonly="readonly" id="innerloop2" name="innerloop2" /></td>
844
                                                    <td><input type="text" readonly="readonly" id="innerloop3" name="innerloop3" /></td>
845
                                                </tr>
846
                                                <tr>
847
                                                    <td>Numbering</td>
848
                                                    <td><input type="text" readonly="readonly" id="numbering1" name="numbering1" /></td>
849
                                                    <td><input type="text" readonly="readonly" id="numbering2" name="numbering2" /></td>
850
                                                    <td><input type="text" readonly="readonly" id="numbering3" name="numbering3" /></td>
851
                                                </tr>
852
                                            </tbody>
853
                                        </table>
854
                                        <input id="modifyadvancedpatternbutton" type="button" value="Modify pattern" onclick="modifyAdvancedPattern();" />
855
                                        <input id="restoreadvancedpatternbutton" type="button" value="Cancel modifications" onclick="restoreAdvancedPattern();" style="display:none" />
856
                                        <input id="saveadvancedpatternbutton" type="button" value="Save as new pattern" onclick="saveAdvancedPattern();" style="display:none" />
857
                                    </div>
858
                                </ol>
859
                            </fieldset>
860
                            <fieldset class="action">
861
                                <input type="button" value="<< Previous" onclick="show_page_1();" style="float:left;"/>
862
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" onclick="testPredictionPattern();" />
863
                                <input type="button" value="Save subscription" onclick="if (Check_page2()) submit();" style="float:right;" accesskey="w" />
864
                            </fieldset>
865
                        </div>
866
                    </div>
867
                    <div class="yui-u">
868
                        <li id="displayexample"></li>
869
                    </div>
870
                </div>
871
            </form>
1441
        </div>
872
        </div>
1442
873
    </div>
1443
</div>
1444
1445
</form>
1446
</div>
1447
1448
</div>
874
</div>
1449
875
1450
[% INCLUDE 'intranet-bottom.inc' %]
876
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-113 / +32 lines)
Lines 8-28 var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_(" Link Here
8
"Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
8
"Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
9
9
10
10
11
// to display the options section
12
function options(x,y,z){
13
var textbox = '';
14
    // alert("X: "+x+"Y: "+y+"Z: "+z);
15
    if(x){
16
        document.f.xfield.value = x;
17
        if(y){
18
            document.f.yfield.value = y;
19
            if(z){
20
                document.f.zfield.value = z;
21
            }
22
        }
23
    }
24
}
25
26
function confirm_deletion() {
11
function confirm_deletion() {
27
    var is_confirmed = confirm(_("Are you sure you want to delete this subscription?"));
12
    var is_confirmed = confirm(_("Are you sure you want to delete this subscription?"));
28
    if (is_confirmed) {
13
    if (is_confirmed) {
Lines 99-104 $(document).ready(function() { Link Here
99
        [% ELSE %]
84
        [% ELSE %]
100
            <li><span class="label">Items:</span> Serial receipt does not create an item record.</li>
85
            <li><span class="label">Items:</span> Serial receipt does not create an item record.</li>
101
        [% END %]
86
        [% END %]
87
        <li>
88
            <span class="label">Serial number:</span>
89
            [% IF skip_serialseq %]
90
                Serial number is skipped when an irregularity is found.
91
            [% ELSE %]
92
                Serial number is kept when an irregularity is found.
93
            [% END %]
94
        </li>
102
        <li><span class="label">Grace period:</span> [% graceperiod %]</li>
95
        <li><span class="label">Grace period:</span> [% graceperiod %]</li>
103
        </ol>
96
        </ol>
104
    </div>
97
    </div>
Lines 128-245 $(document).ready(function() { Link Here
128
        <ol>
121
        <ol>
129
            <li><span class="label">Beginning date:</span> [% startdate %]
122
            <li><span class="label">Beginning date:</span> [% startdate %]
130
            </li>
123
            </li>
131
            <li><span class="label">Frequency (*):</span>
124
            <li><span class="label">Frequency:</span>
132
                [% IF ( periodicity16 ) %]
125
                [% frequency.description %]
133
                        Without regularity
134
                [% END %]
135
                [% IF ( periodicity32 ) %]
136
                        Irregular
137
                [% END %]
138
                [% IF ( periodicity0 ) %]
139
                        Unknown
140
                [% END %]
141
                [% IF ( periodicity12 ) %]
142
                        2/day
143
                [% END %]
144
                [% IF ( periodicity1 ) %]
145
                        1/day
146
                [% END %]
147
                [% IF ( periodicity13 ) %]
148
                        1/4 months (3/year)
149
                [% END %]
150
                [% IF ( periodicity2 ) %]
151
                        1/week
152
                [% END %]
153
                [% IF ( periodicity3 ) %]
154
                        1/2 weeks
155
                [% END %]
156
                [% IF ( periodicity4 ) %]
157
                        1/3 weeks
158
                [% END %]
159
                [% IF ( periodicity5 ) %]
160
                        1/Month
161
                [% END %]
162
                [% IF ( periodicity6 ) %]
163
                        1/2 Months (6/year)
164
                [% END %]
165
                [% IF ( periodicity7 ) %]
166
                        1/quarter
167
                [% END %]
168
                [% IF ( periodicity8 ) %]
169
                        1/quarter
170
                [% END %]
171
                [% IF ( periodicity9 ) %]
172
                        2/year
173
                [% END %]
174
                [% IF ( periodicity10 ) %]
175
                        1/year
176
                [% END %]
177
                [% IF ( periodicity11 ) %]
178
                        1/2 years
179
                [% END %]
180
            </li>
126
            </li>
181
            <li>
127
            <li>
182
              <span class="label">Manual history: </span>
128
              <span class="label">Manual history: </span>
183
                [% IF ( manualhistory ) %]
129
                [% IF ( manualhistory ) %]
184
                    Disabled
130
                    Enabled <a href="/cgi-bin/koha/serials/subscription-history.pl?subscriptionid=[% subscriptionid %]">Edit history</a>
185
                [% ELSE %]
131
                [% ELSE %]
186
                    Enabled
132
                    Disabled
187
                [% END %]
133
                [% END %]
188
            </li>
134
            </li>
189
            <li><span class="label">Number pattern:</span>
135
            <li><span class="label">Number pattern:</span>
190
                [% IF ( numberpattern1 ) %]
136
                [% numberpattern.label %]
191
                    Number only
137
            </li>
192
                [% END %]
138
            <li><table>
193
                [% IF ( numberpattern2 ) %]
139
            <tr>
194
                    Volume, Number, Issue
140
                <td>Starting with:</td>
195
                [% END %]
141
                [% IF (has_X) %]
196
                [% IF ( numberpattern3 ) %]
142
                    <td align="center">[% lastvalue1 %]</td>
197
                    Volume, Number
198
                [% END %]
143
                [% END %]
199
                [% IF ( numberpattern4 ) %]
144
                [% IF (has_Y) %]
200
                    Volume, Issue
145
                    <td align="center">[% lastvalue2 %]</td>
201
                [% END %]
146
                [% END %]
202
                [% IF ( numberpattern5 ) %]
147
                [% IF (has_Z) %]
203
                    Number, Issue
148
                    <td align="center">[% lastvalue3 %]</td>
204
                [% END %]
149
                [% END %]
205
                [% IF ( numberpattern8 ) %]
150
            </tr>
206
                    Year/Number
151
            <tr>
152
                <td>Rollover:</td>
153
                [% IF (has_X) %]
154
                    <td align="center">[% numberpattern.whenmorethan1 %]</td>
207
                [% END %]
155
                [% END %]
208
                [% IF ( numberpattern6 ) %]
156
                [% IF (has_Y) %]
209
                    Seasonal only
157
                    <td align="center">[% numberpattern.whenmorethan2 %]</td>
210
                [% END %]
158
                [% END %]
211
                [% IF ( numberpattern7 ) %]
159
                [% IF (has_Z) %]
212
                    None of the above
160
                    <td align="center">[% numberpattern.whenmorethan3 %]</td>
213
                [% END %]
161
                [% END %]
214
            </li>
215
            <li><table>
216
            <tr><td>Starting with:</td>
217
                <td align="center">[% lastvalue1 %]</td>
218
            [% IF ( lastvalue2 ) %]
219
                <td align="center">&nbsp; 
220
                    [% lastvalue2 %]
221
                </td>
222
            [% END %]
223
            [% IF ( lastvalue3 ) %]
224
                <td align="center">&nbsp; 
225
                    [% lastvalue3 %]
226
                </td>
227
            [% END %]
228
            </tr>
229
            <tr><td>Rollover:</td>
230
                <td align="center">
231
                    [% IF ( whenmorethan1 < 9999999 ) %][% whenmorethan1 %][% ELSE %]Never[% END %]
232
                </td>
233
            [% IF ( whenmorethan2 ) %]
234
                <td align="center">&nbsp;
235
                    [% IF ( whenmorethan2 < 9999999 ) %][% whenmorethan2 %][% ELSE %]Never[% END %]
236
                </td>
237
            [% END %]
238
            [% IF ( whenmorethan3 ) %]
239
                <td align="center">&nbsp;
240
                    [% IF ( whenmorethan3 < 9999999 ) %][% whenmorethan3 %][% ELSE %]Never[% END %]
241
                </td>
242
            [% END %]
243
            </tr>
162
            </tr>
244
            </table></li>
163
            </table></li>
245
            [% IF ( irregular_issues ) %]
164
            [% IF ( irregular_issues ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-frequencies.tt (+185 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
$(document).ready(function() {
48
    $("#issuesperunit").change(function() {
49
        var value = $(this).val();
50
        if(!isNaN(value) && value > 1) {
51
            $("#unitsperissue").val(1);
52
        }
53
    });
54
    $("#unitsperissue").change(function() {
55
        var value = $(this).val();
56
        if(!isNaN(value) && value > 1) {
57
            $("#issuesperunit").val(1);
58
        }
59
    });
60
});
61
//]]>
62
</script>
63
</head>
64
65
<body>
66
[% INCLUDE 'header.inc' %]
67
[% INCLUDE 'serials-search.inc' %]
68
69
<div id="breadcrumbs">
70
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
71
    <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
72
    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl">Frequencies</a>
73
</div>
74
75
<div id="doc3" class="yui-t2">
76
77
<div id="bd">
78
  <div id="yui-main">
79
    <div class="yui-b">
80
      [% IF (new or modify) %]
81
        [% IF (new) %]
82
          <h1>New frequency</h1>
83
        [% ELSE %]
84
          <h1>Modify frequency: [% description %]</h1>
85
        [% END %]
86
        <form action="/cgi-bin/koha/serials/subscription-frequencies.pl" method="post" onsubmit="return check_form();">
87
          [% IF (modify) %]
88
            <input type="hidden" name="id" value="[% id %]" />
89
            <input type="hidden" name="op" value="savemod" />
90
          [% ELSE %]
91
            <input type="hidden" name="op" value="savenew" />
92
          [% END %]
93
          <fieldset class="rows">
94
            <ol>
95
              <li>
96
                <label for="description">Description:</label>
97
                <input type="text" id="description" name="description" value="[% description %]" />
98
              </li>
99
              <li>
100
                <label for="unit">Unit</label>
101
                <select id="unit" name="unit">
102
                  <option value="">None</option>
103
                  [% FOREACH unit IN units_loop %]
104
                    [% IF (unit.selected) %]
105
                      <option selected="selected" value="[% unit.val %]">
106
                    [% ELSE %]
107
                      <option value="[% unit.val %]">
108
                    [% END %]
109
                      [% unit.val %]
110
                    </option>
111
                  [% END %]
112
                </select>
113
              </li>
114
              <li><span class="hint">Note: one of the two following fields must be equal to 1</span></li>
115
              <li>
116
                <label for="issuesperunit">Issues per unit</label>
117
                [% IF (new) %]
118
                  <input type="text" id="issuesperunit" name="issuesperunit" value="1" size="3" />
119
                [% ELSE %]
120
                  <input type="text" id="issuesperunit" name="issuesperunit" value="[% issuesperunit %]" size="3" />
121
                [% END %]
122
              </li>
123
              <li>
124
                <label for="unitsperissue">Units per issue</label>
125
                [% IF (new) %]
126
                  <input type="text" id="unitsperissue" name="unitsperissue" value="1" size="3" />
127
                [% ELSE %]
128
                  <input type="text" id="unitsperissue" name="unitsperissue" value="[% unitsperissue %]" size="3" />
129
                [% END %]
130
              </li>
131
              <li>
132
                <label for="displayorder">Display order</label>
133
                <input type="text" id="displayorder" name="displayorder" value="[% displayorder %]" size="3" />
134
              </li>
135
            </ol>
136
          </fieldset>
137
          <fieldset class="action">
138
            <input type="submit" value="Save" />
139
            <input type="button" value="Cancel" onclick="window.location='/cgi-bin/koha/serials/subscription-frequencies.pl'" />
140
          </fieldset>
141
        </form>
142
      [% ELSE %]
143
        <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=new">New frenquency</a>
144
145
        [% IF (frequencies_loop.size) %]
146
          <h1>Frenquencies</h1>
147
          <table id="frequenciest">
148
            <thead>
149
              <tr>
150
                <th>Description</th>
151
                <th>Unit</th>
152
                <th>Issues per unit</th>
153
                <th>Units per issue</th>
154
                <th>Display order</th>
155
                <th>&nbsp;</th>
156
              </tr>
157
            </thead>
158
            <tbody>
159
              [% FOREACH frequency IN frequencies_loop %]
160
                <tr>
161
                  <td>[% frequency.description %]</td>
162
                  <td>[% frequency.unit %]</td>
163
                  <td>[% frequency.issuesperunit %]</td>
164
                  <td>[% frequency.unitsperissue %]</td>
165
                  <td>[% frequency.displayorder %]</td>
166
                  <td>
167
                    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=modify&frequencyid=[% frequency.id %]">Modify</a> |
168
                    <a href="/cgi-bin/koha/serials/subscription-frequencies.pl?op=del&frequencyid=[% frequency.id %]" onclick="return confirmDelete();">Delete</a>
169
                  </td>
170
                </tr>
171
              [% END %]
172
            </tbody>
173
          </table>
174
        [% ELSE %]
175
          <p>There is no defined frequency.</p>
176
        [% END %]
177
      [% END %]
178
179
    </div>
180
  </div>
181
  <div class="yui-b">
182
    [% INCLUDE 'serials-menu.inc' %]
183
  </div>
184
</div>
185
[% 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 (+289 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
</script>
58
</head>
59
60
<body>
61
[% INCLUDE 'header.inc' %]
62
[% INCLUDE 'serials-search.inc' %]
63
64
<div id="breadcrumbs">
65
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
66
    <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo;
67
    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl">Numbering patterns</a>
68
</div>
69
70
<div id="doc3" class="yui-t2">
71
72
<div id="bd">
73
  <div id="yui-main">
74
    <div class="yui-b">
75
      [% IF (new or modify) %]
76
        <div class="yui-g">
77
          [% IF (new) %]
78
            <h1>New number pattern</h1>
79
            [% IF (error_existing_numberpattern) %]
80
              <div class="dialog">
81
                <p>A pattern with this name already exists.</p>
82
              </div>
83
            [% END %]
84
          [% ELSE %]
85
            <h1>Modify pattern: [% label %]</h1>
86
            [% IF (error_existing_numberpattern) %]
87
              <div class="dialog">
88
                <p>Another pattern with this name already exists.</p>
89
              </div>
90
            [% END %]
91
          [% END %]
92
        </div>
93
        <div class="yui-g">
94
          <form action="/cgi-bin/koha/serials/subscription-numberpatterns.pl" method="post">
95
            [% IF (new) %]
96
              <input type="hidden" name="op" value="savenew" />
97
            [% ELSE %]
98
              <input type="hidden" name="op" value="savemod" />
99
              <input type="hidden" name="id" value="[% id %]" />
100
            [% END %]
101
            <fieldset class="rows">
102
              <ol>
103
                <li>
104
                  <label for="label">Name:</label>
105
                  <input type="text" id="label" name="label" value="[% label %]" />
106
                </li>
107
                <li>
108
                  <label for="description">Description:</label>
109
                  <input type="text" id="description" name="description" value="[% description %]" />
110
                </li>
111
                <li>
112
                  <label for="numberingmethod">Numbering formula:</label>
113
                  <input type="text" id="numberingmethod" name="numberingmethod" value="[% numberingmethod %]" />
114
                </li>
115
                <li>
116
                  <label for="displayorder">Display order:</label>
117
                  <input type="text" id="displayorder" name="displayorder" value="[% displayorder %]" />
118
                </li>
119
              </ol>
120
              <table>
121
                <thead>
122
                  <tr>
123
                    <th>&nbsp;</th>
124
                    <th>X</th>
125
                    <th>Y</th>
126
                    <th>Z</th>
127
                  </tr>
128
                </thead>
129
                <tbody>
130
                  <tr>
131
                    <td>Label</td>
132
                    <td><input type="text" id="label1" name="label1" value="[% label1 %]" /></td>
133
                    <td><input type="text" id="label2" name="label2" value="[% label2 %]" /></td>
134
                    <td><input type="text" id="label3" name="label3" value="[% label3 %]" /></td>
135
                  </tr>
136
                  <tr>
137
                    <td>Add</td>
138
                    <td><input type="text" id="add1" name="add1" value="[% add1 %]" /></td>
139
                    <td><input type="text" id="add2" name="add2" value="[% add2 %]" /></td>
140
                    <td><input type="text" id="add3" name="add3" value="[% add3 %]" /></td>
141
                  </tr>
142
                  <tr>
143
                    <td>Every</td>
144
                    <td><input type="text" id="every1" name="every1" value="[% every1 %]" /></td>
145
                    <td><input type="text" id="every2" name="every2" value="[% every2 %]" /></td>
146
                    <td><input type="text" id="every3" name="every3" value="[% every3 %]" /></td>
147
                  </tr>
148
                  <tr>
149
                    <td>Set back to</td>
150
                    <td><input type="text" id="setto1" name="setto1" value="[% setto1 %]" /></td>
151
                    <td><input type="text" id="setto2" name="setto2" value="[% setto2 %]" /></td>
152
                    <td><input type="text" id="setto3" name="setto3" value="[% setto3 %]" /></td>
153
                  </tr>
154
                  <tr>
155
                    <td>When more than</td>
156
                    <td><input type="text" id="whenmorethan1" name="whenmorethan1" value="[% whenmorethan1 %]" /></td>
157
                    <td><input type="text" id="whenmorethan2" name="whenmorethan2" value="[% whenmorethan2 %]" /></td>
158
                    <td><input type="text" id="whenmorethan3" name="whenmorethan3" value="[% whenmorethan3 %]" /></td>
159
                  </tr>
160
                  <tr>
161
                    <td>Numbering</td>
162
                    <td><input type="text" id="numbering1" name="numbering1" value="[% numbering1 %]" /></td>
163
                    <td><input type="text" id="numbering2" name="numbering2" value="[% numbering2 %]" /></td>
164
                    <td><input type="text" id="numbering3" name="numbering3" value="[% numbering3 %]" /></td>
165
                  </tr>
166
                </tbody>
167
              </table>
168
            </fieldset>
169
            <fieldset class="action">
170
              <input type="submit" value="Save" />
171
              <input type="reset" value="Reset" />
172
              <input type="button" value="Cancel" onclick="window.location = '/cgi-bin/koha/serials/subscription-numberpatterns.pl';" />
173
            </fieldset>
174
          </form>
175
        </div>
176
        <div class="yui-g">
177
          <form>
178
            <fieldset class="rows">
179
              <legend>Test prediction pattern</legend>
180
              <ol>
181
                <li>
182
                  <label for="frequency">Frequency:</label>
183
                  <select id="frequency">
184
                    [% FOREACH frequency IN frequencies_loop %]
185
                      <option value="[% frequency.id %]">[% frequency.description %]</option>
186
                    [% END %]
187
                  </select>
188
                </li>
189
                <li>
190
                  <label for="firstacquidate">First issue publication date</label>
191
                  <input type="text" id="firstacquidate" size="10" />
192
                  <img src="[% themelang %]/lib/calendar/cal.gif" id="firstacquidatebutton" style="cursor:pointer" alt="Show Calendar" title="Show Calendar" />
193
                  <script type="text/javascript">
194
                    //<![CDATA[
195
                    Calendar.setup({
196
                      inputField: "firstacquidate",
197
                      ifFormat: "[% DHTMLcalendar_dateformat %]",
198
                      button: "firstacquidatebutton",
199
                      align: "Tl"
200
                    });
201
                    //]]>
202
                  </script>
203
                </li>
204
                <li>
205
                  <label for="sublength">Subscription length:</label>
206
                  <select id="subtype">
207
                    [% FOREACH subtype IN subtypes_loop %]
208
                      <option value="[% subtype.value %]">[% subtype.value %]</option>
209
                    [% END %]
210
                  </select>
211
                  <input type="text" id="sublength" size="3" />
212
                </li>
213
                <li>
214
                  <label for="locale">Locale:</label>
215
                  <input type="text" id="locale" name="locale" />
216
                  <span class="hint">If empty, system locale is used</span>
217
                </li>
218
              </ol>
219
              <table>
220
                <thead>
221
                  <tr>
222
                    <th>&nbsp;</th>
223
                    <th>X</th>
224
                    <th>Y</th>
225
                    <th>Z</th>
226
                  </tr>
227
                </thead>
228
                <tbody>
229
                  <tr>
230
                    <td>Begins with</td>
231
                    <td><input type="text" id="lastvalue1" name="lastvalue1" value="[% lastvalue1 %]" /></td>
232
                    <td><input type="text" id="lastvalue2" name="lastvalue2" value="[% lastvalue2 %]" /></td>
233
                    <td><input type="text" id="lastvalue3" name="lastvalue3" value="[% lastvalue3 %]" /></td>
234
                  </tr>
235
                  <tr>
236
                    <td>Inner counter</td>
237
                    <td><input type="text" id="innerloop1" name="innerloop1" value="[% innerloop1 %]" /></td>
238
                    <td><input type="text" id="innerloop2" name="innerloop2" value="[% innerloop2 %]" /></td>
239
                    <td><input type="text" id="innerloop3" name="innerloop3" value="[% innerloop3 %]" /></td>
240
                  </tr>
241
                </tbody>
242
              </table>
243
              <fieldset class="action">
244
              <input type="button" value="Test pattern" onclick="testPattern();" />
245
              </fieldset>
246
              <div id="predictionpattern"></div>
247
            </fieldset>
248
          </form>
249
        </div>
250
      [% ELSE %]
251
        <h1>Number patterns</h1>
252
        <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=new">New numbering pattern</a>
253
        [% IF (numberpatterns_loop.size) %]
254
          <table id="numberpatternst">
255
            <thead>
256
              <tr>
257
                <th>Name</th>
258
                <th>Description</th>
259
                <th>Numbering formula</th>
260
                <th>Display order</th>
261
                <th>&nbsp;</th>
262
              </tr>
263
            </thead>
264
            <tbody>
265
              [% FOREACH numberpattern IN numberpatterns_loop %]
266
                <tr>
267
                  <td>[% numberpattern.label %]</td>
268
                  <td>[% numberpattern.description %]</td>
269
                  <td>[% numberpattern.numberingmethod %]</td>
270
                  <td>[% numberpattern.displayorder %]</td>
271
                  <td>
272
                    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=modify&id=[% numberpattern.id %]">Edit</a> |
273
                    <a href="/cgi-bin/koha/serials/subscription-numberpatterns.pl?op=del&id=[% numberpattern.id %]">Delete</a>
274
                  </td>
275
                </tr>
276
              [% END %]
277
            </tbody>
278
          </table>
279
        [% ELSE %]
280
          <p>There is no existing patterns.</p>
281
        [% END %]
282
      [% END %]
283
    </div>
284
  </div>
285
  <div class="yui-b">
286
    [% INCLUDE 'serials-menu.inc' %]
287
  </div>
288
</div>
289
[% 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, ":utf8";
41
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
42
print "{\"numberpatternid\":\"$numberpatternid\"}";
(-)a/serials/serials-collection.pl (-4 / +6 lines)
Lines 103-111 if (@subscriptionid){ Link Here
103
    $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
103
    $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
104
    $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
104
    $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
105
    ##these are display information
105
    ##these are display information
106
    $subs->{ "periodicity" . $subs->{periodicity} } = 1;
107
    $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
108
    $subs->{ "status" . $subs->{'status'} } = 1;
109
    $subs->{startdate}     = format_date( $subs->{startdate} );
106
    $subs->{startdate}     = format_date( $subs->{startdate} );
110
    $subs->{histstartdate} = format_date( $subs->{histstartdate} );
107
    $subs->{histstartdate} = format_date( $subs->{histstartdate} );
111
    if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
108
    if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
Lines 119-124 if (@subscriptionid){ Link Here
119
    $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
116
    $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
120
	$location = GetAuthorisedValues('LOC', $subs->{'location'});
117
	$location = GetAuthorisedValues('LOC', $subs->{'location'});
121
	$callnumber = $subs->{callnumber};
118
	$callnumber = $subs->{callnumber};
119
    my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity});
120
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
121
    $subs->{frequency} = $frequency;
122
    $subs->{numberpattern} = $numberpattern;
122
    push @$subscriptiondescs,$subs;
123
    push @$subscriptiondescs,$subs;
123
    my $tmpsubscription= GetFullSubscription($subscriptionid);
124
    my $tmpsubscription= GetFullSubscription($subscriptionid);
124
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
125
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
Lines 147-152 foreach (@$location) { Link Here
147
    $locationlib = $_->{'lib'} if $_->{'selected'};
148
    $locationlib = $_->{'lib'} if $_->{'selected'};
148
}
149
}
149
150
151
150
chop $subscriptionidlist;
152
chop $subscriptionidlist;
151
$template->param(
153
$template->param(
152
          subscriptionidlist => $subscriptionidlist,
154
          subscriptionidlist => $subscriptionidlist,
Lines 163-168 $template->param( Link Here
163
          subscriptioncount => $subscriptioncount,
165
          subscriptioncount => $subscriptioncount,
164
    location	       => $locationlib,
166
    location	       => $locationlib,
165
    callnumber	       => $callnumber,
167
    callnumber	       => $callnumber,
166
          );
168
);
167
169
168
output_html_with_http_headers $query, $cookie, $template->output;
170
output_html_with_http_headers $query, $cookie, $template->output;
(-)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 %val = (
59
    locale          => $input->param('locale') // '',
60
    numberingmethod => $input->param('numberingmethod') // '',
61
    numbering1      => $input->param('numbering1') // '',
62
    numbering2      => $input->param('numbering2') // '',
63
    numbering3      => $input->param('numbering3') // '',
64
    lastvalue1      => $input->param('lastvalue1') // '',
65
    lastvalue2      => $input->param('lastvalue2') // '',
66
    lastvalue3      => $input->param('lastvalue3') // '',
67
    add1            => $input->param('add1') // '',
68
    add2            => $input->param('add2') // '',
69
    add3            => $input->param('add3') // '',
70
    whenmorethan1   => $input->param('whenmorethan1') // '',
71
    whenmorethan2   => $input->param('whenmorethan2') // '',
72
    whenmorethan3   => $input->param('whenmorethan3') // '',
73
    setto1          => $input->param('setto1') // '',
74
    setto2          => $input->param('setto2') // '',
75
    setto3          => $input->param('setto3') // '',
76
    every1          => $input->param('every1') // '',
77
    every2          => $input->param('every2') // '',
78
    every3          => $input->param('every3') // '',
79
    innerloop1      => $input->param('innerloop1') // '',
80
    innerloop2      => $input->param('innerloop2') // '',
81
    innerloop3      => $input->param('innerloop3') // '',
82
);
83
84
if(!defined $firstacquidate || $firstacquidate eq ''){
85
    my ($year, $month, $day) = Today();
86
    $firstacquidate = sprintf "%04d-%02d-%02d", $year, $month, $day;
87
} else {
88
    $firstacquidate = C4::Dates->new($firstacquidate)->output('iso');
89
}
90
91
if($enddate){
92
    $enddate = C4::Dates->new($enddate)->output('iso');
93
}
94
95
if($nextacquidate) {
96
    $nextacquidate = C4::Dates->new($nextacquidate)->output('iso');
97
} else {
98
    $nextacquidate = $firstacquidate;
99
}
100
my $date = $nextacquidate;
101
102
my %subscription = (
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(\%val);
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, $val{'lastvalue1'}, $val{'lastvalue2'}, $val{'lastvalue3'}, $val{'innerloop1'}, $val{'innerloop2'}, $val{'innerloop3'}) = GetNextSeq(\%val);
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 (-93 / +135 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 89-98 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;
Lines 101-116 if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { Link Here
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 175-181 if ($op eq 'addsubscription') { Link Here
175
            $template->param(bibliotitle => $bib->{title});
179
            $template->param(bibliotitle => $bib->{title});
176
        }
180
        }
177
    }
181
    }
178
	output_html_with_http_headers $query, $cookie, $template->output;
182
    my @frequencies = GetSubscriptionFrequencies;
183
    my @frqloop;
184
    foreach my $freq (@frequencies) {
185
        my $selected = 0;
186
        $selected = 1 if ($subs->{periodicity} and $freq->{id} eq $subs->{periodicity});
187
        my $row = {
188
            id => $freq->{'id'},
189
            selected => $selected,
190
            label => $freq->{'description'},
191
        };
192
        push @frqloop, $row;
193
    }
194
    $template->param(frequencies => \@frqloop);
195
196
    my @numpatterns = GetSubscriptionNumberpatterns;
197
    my @numberpatternloop;
198
    foreach my $numpattern (@numpatterns) {
199
        my $selected = 0;
200
        $selected = 1 if($subs->{numberpattern} and $numpattern->{id} eq $subs->{numberpattern});
201
        my $row = {
202
            id => $numpattern->{'id'},
203
            selected => $selected,
204
            label => $numpattern->{'label'},
205
        };
206
        push @numberpatternloop, $row;
207
    }
208
    $template->param(numberpatterns => \@numberpatternloop);
209
210
    output_html_with_http_headers $query, $cookie, $template->output;
179
}
211
}
180
212
181
sub letter_loop {
213
sub letter_loop {
Lines 197-272 sub _get_sub_length { Link Here
197
    my ($type, $length) = @_;
229
    my ($type, $length) = @_;
198
    return
230
    return
199
        (
231
        (
200
            $type eq 'numberlength' ? $length : 0,
232
            $type eq 'issues' ? $length : 0,
201
            $type eq 'weeklength'   ? $length : 0,
233
            $type eq 'weeks'   ? $length : 0,
202
            $type eq 'monthlength'  ? $length : 0,
234
            $type eq 'months'  ? $length : 0,
203
        );
235
        );
204
}
236
}
205
237
238
sub _guess_enddate {
239
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
240
    my ($year, $month, $day);
241
    my $enddate;
242
    if($numberlength != 0) {
243
        my $frequency = GetSubscriptionFrequency($frequencyid);
244
        if($frequency->{'unit'} eq 'day') {
245
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
246
        } elsif($frequency->{'unit'} eq 'week') {
247
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
248
        } elsif($frequency->{'unit'} eq 'month') {
249
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
250
        } elsif($frequency->{'unit'} eq 'year') {
251
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
252
        }
253
    } elsif($weeklength != 0) {
254
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
255
    } elsif($monthlength != 0) {
256
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
257
    }
258
    if(defined $year) {
259
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
260
    } else {
261
        undef $enddate;
262
    }
263
    return $enddate;
264
}
265
206
sub redirect_add_subscription {
266
sub redirect_add_subscription {
207
    my $auser          = $query->param('user');
267
    my $auser          = $query->param('user');
208
    my $branchcode     = $query->param('branchcode');
268
    my $branchcode     = $query->param('branchcode');
209
    my $aqbooksellerid = $query->param('aqbooksellerid');
269
    my $aqbooksellerid = $query->param('aqbooksellerid');
210
    my $cost           = $query->param('cost');
270
    my $cost           = $query->param('cost');
211
    my $aqbudgetid     = $query->param('aqbudgetid');
271
    my $aqbudgetid     = $query->param('aqbudgetid');
212
    my $periodicity    = $query->param('periodicity');
272
    my $periodicity    = $query->param('frequency');
213
    my $dow            = $query->param('dow');
273
    my @irregularity   = $query->param('irregularity');
214
    my @irregularity   = $query->param('irregularity_select');
215
    my $numberpattern  = $query->param('numbering_pattern');
274
    my $numberpattern  = $query->param('numbering_pattern');
275
    my $locale         = $query->param('locale');
216
    my $graceperiod    = $query->param('graceperiod') || 0;
276
    my $graceperiod    = $query->param('graceperiod') || 0;
217
277
278
    my $subtype = $query->param('subtype');
279
    my $sublength = $query->param('sublength');
218
    my ( $numberlength, $weeklength, $monthlength )
280
    my ( $numberlength, $weeklength, $monthlength )
219
        = _get_sub_length( $query->param('subtype'), $query->param('sublength') );
281
        = _get_sub_length( $subtype, $sublength );
220
    my $add1              = $query->param('add1');
282
    my $add1              = $query->param('add1');
221
    my $every1            = $query->param('every1');
222
    my $whenmorethan1     = $query->param('whenmorethan1');
223
    my $setto1            = $query->param('setto1');
224
    my $lastvalue1        = $query->param('lastvalue1');
283
    my $lastvalue1        = $query->param('lastvalue1');
225
    my $innerloop1        = $query->param('innerloop1');
284
    my $innerloop1        = $query->param('innerloop1');
226
    my $add2              = $query->param('add2');
227
    my $every2            = $query->param('every2');
228
    my $whenmorethan2     = $query->param('whenmorethan2');
229
    my $setto2            = $query->param('setto2');
230
    my $innerloop2        = $query->param('innerloop2');
285
    my $innerloop2        = $query->param('innerloop2');
231
    my $lastvalue2        = $query->param('lastvalue2');
286
    my $lastvalue2        = $query->param('lastvalue2');
232
    my $add3              = $query->param('add3');
233
    my $every3            = $query->param('every3');
234
    my $whenmorethan3     = $query->param('whenmorethan3');
235
    my $setto3            = $query->param('setto3');
236
    my $lastvalue3        = $query->param('lastvalue3');
287
    my $lastvalue3        = $query->param('lastvalue3');
237
    my $innerloop3        = $query->param('innerloop3');
288
    my $innerloop3        = $query->param('innerloop3');
238
    my $numberingmethod   = $query->param('numberingmethod');
239
    my $status            = 1;
289
    my $status            = 1;
240
    my $biblionumber      = $query->param('biblionumber');
290
    my $biblionumber      = $query->param('biblionumber');
241
    my $callnumber        = $query->param('callnumber');
291
    my $callnumber        = $query->param('callnumber');
242
    my $notes             = $query->param('notes');
292
    my $notes             = $query->param('notes');
243
    my $internalnotes     = $query->param('internalnotes');
293
    my $internalnotes     = $query->param('internalnotes');
244
    my $hemisphere        = $query->param('hemisphere') || 1;
245
    my $letter            = $query->param('letter');
294
    my $letter            = $query->param('letter');
246
    my $manualhistory     = $query->param('manualhist');
295
    my $manualhistory     = $query->param('manualhist') ? 1 : 0;
247
    my $serialsadditems   = $query->param('serialsadditems');
296
    my $serialsadditems   = $query->param('serialsadditems');
248
    my $staffdisplaycount = $query->param('staffdisplaycount');
297
    my $staffdisplaycount = $query->param('staffdisplaycount');
249
    my $opacdisplaycount  = $query->param('opacdisplaycount');
298
    my $opacdisplaycount  = $query->param('opacdisplaycount');
250
    my $location          = $query->param('location');
299
    my $location          = $query->param('location');
300
    my $skip_serialseq    = $query->param('skip_serialseq');
251
    my $startdate = format_date_in_iso( $query->param('startdate') );
301
    my $startdate = format_date_in_iso( $query->param('startdate') );
252
    my $enddate = format_date_in_iso( $query->param('enddate') );
302
    my $enddate = format_date_in_iso( $query->param('enddate') );
253
    my $firstacquidate  = format_date_in_iso($query->param('firstacquidate'));
303
    my $firstacquidate  = format_date_in_iso($query->param('firstacquidate'));
254
    my $histenddate = format_date_in_iso($query->param('histenddate'));
304
    if(!defined $enddate || $enddate eq '') {
255
    my $histstartdate = format_date_in_iso($query->param('histstartdate'));
305
        if($subtype eq "issues") {
256
    my $recievedlist = $query->param('recievedlist');
306
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
257
    my $missinglist = $query->param('missinglist');
307
        } else {
258
    my $opacnote = $query->param('opacnote');
308
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
259
    my $librariannote = $query->param('librariannote');
309
        }
260
	my $subscriptionid = NewSubscription($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
310
    }
261
					$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
311
262
					$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
312
    my $subscriptionid = NewSubscription(
263
					$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
313
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
264
					$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
314
        $startdate, $periodicity, $numberlength, $weeklength,
265
					$numberingmethod, $status, $notes,$letter,$firstacquidate,join(",",@irregularity),
315
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
266
                    $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes,
316
        $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate,
267
                    $serialsadditems,$staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate
317
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
268
				);
318
        $manualhistory, $internalnotes, $serialsadditems,
269
    ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
319
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
320
        $skip_serialseq
321
    );
270
322
271
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
323
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
272
    return;
324
    return;
Lines 274-280 sub redirect_add_subscription { Link Here
274
326
275
sub redirect_mod_subscription {
327
sub redirect_mod_subscription {
276
    my $subscriptionid = $query->param('subscriptionid');
328
    my $subscriptionid = $query->param('subscriptionid');
277
	  my @irregularity = $query->param('irregularity_select');
329
    my @irregularity = $query->param('irregularity');
278
    my $auser = $query->param('user');
330
    my $auser = $query->param('user');
279
    my $librarian => $query->param('librarian'),
331
    my $librarian => $query->param('librarian'),
280
    my $branchcode = $query->param('branchcode');
332
    my $branchcode = $query->param('branchcode');
Lines 283-358 sub redirect_mod_subscription { Link Here
283
    my $biblionumber = $query->param('biblionumber');
335
    my $biblionumber = $query->param('biblionumber');
284
    my $aqbudgetid = $query->param('aqbudgetid');
336
    my $aqbudgetid = $query->param('aqbudgetid');
285
    my $startdate = format_date_in_iso($query->param('startdate'));
337
    my $startdate = format_date_in_iso($query->param('startdate'));
338
    my $firstacquidate = format_date_in_iso( $query->param('firstacquidate') );
286
    my $nextacquidate = $query->param('nextacquidate') ?
339
    my $nextacquidate = $query->param('nextacquidate') ?
287
                            format_date_in_iso($query->param('nextacquidate')):
340
                            format_date_in_iso($query->param('nextacquidate')):
288
                            format_date_in_iso($query->param('startdate'));
341
                            $firstacquidate;
289
    my $enddate = format_date_in_iso($query->param('enddate'));
342
    my $enddate = format_date_in_iso($query->param('enddate'));
290
    my $periodicity = $query->param('periodicity');
343
    my $periodicity = $query->param('frequency');
291
    my $dow = $query->param('dow');
292
344
345
    my $subtype = $query->param('subtype');
346
    my $sublength = $query->param('sublength');
293
    my ($numberlength, $weeklength, $monthlength)
347
    my ($numberlength, $weeklength, $monthlength)
294
        = _get_sub_length( $query->param('subtype'), $query->param('sublength') );
348
        = _get_sub_length( $subtype, $sublength );
295
    my $numberpattern = $query->param('numbering_pattern');
349
    my $numberpattern = $query->param('numbering_pattern');
296
    my $add1 = $query->param('add1');
350
    my $locale = $query->param('locale');
297
    my $every1 = $query->param('every1');
298
    my $whenmorethan1 = $query->param('whenmorethan1');
299
    my $setto1 = $query->param('setto1');
300
    my $lastvalue1 = $query->param('lastvalue1');
351
    my $lastvalue1 = $query->param('lastvalue1');
301
    my $innerloop1 = $query->param('innerloop1');
352
    my $innerloop1 = $query->param('innerloop1');
302
    my $add2 = $query->param('add2');
303
    my $every2 = $query->param('every2');
304
    my $whenmorethan2 = $query->param('whenmorethan2');
305
    my $setto2 = $query->param('setto2');
306
    my $lastvalue2 = $query->param('lastvalue2');
353
    my $lastvalue2 = $query->param('lastvalue2');
307
    my $innerloop2 = $query->param('innerloop2');
354
    my $innerloop2 = $query->param('innerloop2');
308
    my $add3 = $query->param('add3');
309
    my $every3 = $query->param('every3');
310
    my $whenmorethan3 = $query->param('whenmorethan3');
311
    my $setto3 = $query->param('setto3');
312
    my $lastvalue3 = $query->param('lastvalue3');
355
    my $lastvalue3 = $query->param('lastvalue3');
313
    my $innerloop3 = $query->param('innerloop3');
356
    my $innerloop3 = $query->param('innerloop3');
314
    my $numberingmethod = $query->param('numberingmethod');
315
    my $status = 1;
357
    my $status = 1;
316
    my $callnumber = $query->param('callnumber');
358
    my $callnumber = $query->param('callnumber');
317
    my $notes = $query->param('notes');
359
    my $notes = $query->param('notes');
318
    my $internalnotes = $query->param('internalnotes');
360
    my $internalnotes = $query->param('internalnotes');
319
    my $hemisphere = $query->param('hemisphere');
320
    my $letter = $query->param('letter');
361
    my $letter = $query->param('letter');
321
    my $manualhistory = $query->param('manualhist');
362
    my $manualhistory = $query->param('manualhist') ? 1 : 0;
322
    my $serialsadditems = $query->param('serialsadditems');
363
    my $serialsadditems = $query->param('serialsadditems');
323
    # subscription history
324
    my $histenddate = format_date_in_iso($query->param('histenddate'));
325
    my $histstartdate = format_date_in_iso($query->param('histstartdate'));
326
    my $recievedlist = $query->param('recievedlist');
327
    my $missinglist = $query->param('missinglist');
328
    my $opacnote = $query->param('opacnote');
329
    my $librariannote = $query->param('librariannote');
330
	my $staffdisplaycount = $query->param('staffdisplaycount');
364
	my $staffdisplaycount = $query->param('staffdisplaycount');
331
	my $opacdisplaycount = $query->param('opacdisplaycount');
365
	my $opacdisplaycount = $query->param('opacdisplaycount');
332
    my $graceperiod     = $query->param('graceperiod') || 0;
366
    my $graceperiod     = $query->param('graceperiod') || 0;
333
    my $location = $query->param('location');
367
    my $location = $query->param('location');
368
    my $skip_serialseq    = $query->param('skip_serialseq');
369
370
    # Guess end date
371
    if(!defined $enddate || $enddate eq '') {
372
        if($subtype eq "issues") {
373
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
374
        } else {
375
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
376
        }
377
    }
378
334
    my $nextexpected = GetNextExpected($subscriptionid);
379
    my $nextexpected = GetNextExpected($subscriptionid);
335
	#  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
380
    #  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary.
336
    if ( $nextacquidate ne $nextexpected->{planneddate}->output('iso') ) {
381
    if ( $nextexpected->{planneddate} && $nextacquidate ne $nextexpected->{planneddate} ) {
337
        ModNextExpected($subscriptionid,C4::Dates->new($nextacquidate,'iso'));
382
        ModNextExpected($subscriptionid, $nextacquidate);
338
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
383
        # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
339
        $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
384
        $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
340
    }
385
    }
341
386
342
        ModSubscription(
387
    ModSubscription(
343
            $auser,           $branchcode,   $aqbooksellerid, $cost,
388
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate,
344
            $aqbudgetid,      $startdate,    $periodicity,    $firstissuedate,
389
        $periodicity, $firstacquidate, join(";",@irregularity),
345
            $dow,             join(q{,},@irregularity), $numberpattern,  $numberlength,
390
        $numberpattern, $locale, $numberlength, $weeklength, $monthlength, $lastvalue1,
346
            $weeklength,      $monthlength,  $add1,           $every1,
391
        $innerloop1, $lastvalue2, $innerloop2, $lastvalue3, $innerloop3,
347
            $whenmorethan1,   $setto1,       $lastvalue1,     $innerloop1,
392
        $status, $biblionumber, $callnumber, $notes, $letter,
348
            $add2,            $every2,       $whenmorethan2,  $setto2,
393
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
349
            $lastvalue2,      $innerloop2,   $add3,           $every3,
394
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
350
            $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3,
395
        $skip_serialseq
351
            $numberingmethod, $status,       $biblionumber,   $callnumber,
396
    );
352
            $notes,           $letter,       $hemisphere,     $manualhistory,$internalnotes,
397
353
            $serialsadditems, $staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate,$subscriptionid
354
        );
355
        ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
356
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
398
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
357
    return;
399
    return;
358
}
400
}
(-)a/serials/subscription-detail.pl (-13 / +9 lines)
Lines 100-106 my $hasRouting = check_routing($subscriptionid); Link Here
100
100
101
# COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
101
# COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
102
102
103
for my $date qw(startdate enddate firstacquidate histstartdate histenddate){
103
for my $date (qw(startdate enddate firstacquidate histstartdate histenddate)) {
104
    $$subs{$date}      = format_date($$subs{$date}) if $date && $$subs{$date};
104
    $$subs{$date}      = format_date($$subs{$date}) if $date && $$subs{$date};
105
}
105
}
106
$subs->{location} = GetKohaAuthorisedValueLib("LOC",$subs->{location});
106
$subs->{location} = GetKohaAuthorisedValueLib("LOC",$subs->{location});
Lines 109-123 $template->param(%{ $subs }); Link Here
109
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});
109
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});
110
my @irregular_issues = split /,/, $subs->{irregularity};
110
my @irregular_issues = split /,/, $subs->{irregularity};
111
111
112
if (! $subs->{numberpattern}) {
112
my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity});
113
    $subs->{numberpattern} = q{};
113
my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
114
}
114
115
if (! $subs->{dow}) {
116
    $subs->{dow} = q{};
117
}
118
if (! $subs->{periodicity}) {
119
    $subs->{periodicity} = '0';
120
}
121
my $default_bib_view = get_default_view();
115
my $default_bib_view = get_default_view();
122
$template->param(
116
$template->param(
123
	subscriptionid => $subscriptionid,
117
	subscriptionid => $subscriptionid,
Lines 131-139 $template->param( Link Here
131
                C4::Context->userenv->{flags} % 2 !=1  &&
125
                C4::Context->userenv->{flags} % 2 !=1  &&
132
                C4::Context->userenv->{branch} && $subs->{branchcode} &&
126
                C4::Context->userenv->{branch} && $subs->{branchcode} &&
133
                (C4::Context->userenv->{branch} ne $subs->{branchcode})),
127
                (C4::Context->userenv->{branch} ne $subs->{branchcode})),
134
    'periodicity' . $subs->{periodicity} => 1,
128
    frequency => $frequency,
135
    'arrival' . $subs->{dow} => 1,
129
    numberpattern => $numberpattern,
136
    'numberpattern' . $subs->{numberpattern} => 1,
130
    has_X           => ($numberpattern->{'numberingmethod'} =~ /{X}/) ? 1 : 0,
131
    has_Y           => ($numberpattern->{'numberingmethod'} =~ /{Y}/) ? 1 : 0,
132
    has_Z           => ($numberpattern->{'numberingmethod'} =~ /{Z}/) ? 1 : 0,
137
    intranetstylesheet => C4::Context->preference('intranetstylesheet'),
133
    intranetstylesheet => C4::Context->preference('intranetstylesheet'),
138
    intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
134
    intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
139
    irregular_issues => scalar @irregular_issues,
135
    irregular_issues => scalar @irregular_issues,
(-)a/serials/subscription-frequencies.pl (+104 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
    DelSubscriptionFrequency($frequencyid);
96
}
97
98
99
my @frequencies = GetSubscriptionFrequencies();
100
101
$template->param(frequencies_loop => \@frequencies);
102
$template->param($op => 1) if $op;
103
104
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, ":utf8";
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 (+88 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
}
88
(-)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, ":utf8";
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 / +130 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
    $template->param(
108
        $op => 1,
109
        frequencies_loop => \@frequencies,
110
        subtypes_loop => \@subtypes,
111
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
112
    );
113
    output_html_with_http_headers $input, $cookie, $template->output;
114
    exit;
115
}
116
117
if($op && $op eq 'del') {
118
    my $id = $input->param('id');
119
    if(defined $id) {
120
        DelSubscriptionNumberpattern($id);
121
    }
122
}
123
124
my @numberpatterns_loop = GetSubscriptionNumberpatterns();
125
126
$template->param(
127
    numberpatterns_loop => \@numberpatterns_loop,
128
);
129
130
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 7688