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