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

(-)a/C4/Serials.pm (-169 / +66 lines)
Lines 78-88 BEGIN { Link Here
78
      &GetSerialInformation                   &AddItem2Serial
78
      &GetSerialInformation                   &AddItem2Serial
79
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
79
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
80
      &GetPreviousSerialid
80
      &GetPreviousSerialid
81
      GetSerial GetSerialItemnumber
81
82
82
      &GetSuppliersWithLateIssues
83
      &GetSuppliersWithLateIssues
83
      &getroutinglist     &delroutingmember   &addroutingmember
84
      &updateClaim
84
      &reorder_members
85
      &check_routing &updateClaim
86
      &CountIssues
85
      &CountIssues
87
      HasItems
86
      HasItems
88
      &subscriptionCurrentlyOnOrder
87
      &subscriptionCurrentlyOnOrder
Lines 162-167 sub GetSubscriptionHistoryFromSubscriptionId { Link Here
162
    return $results;
161
    return $results;
163
}
162
}
164
163
164
=head2 GetSerial
165
166
    my $serial = &GetSerial($serialid);
167
168
This sub returns serial informations (ie. in serial table) for given $serialid
169
It returns a hashref where each key is a sql column.
170
171
=cut
172
173
sub GetSerial {
174
    my ($serialid) = @_;
175
176
    return unless $serialid;
177
178
    my $dbh = C4::Context->dbh;
179
    my $query = qq{
180
        SELECT *
181
        FROM serial
182
        WHERE serialid = ?
183
    };
184
    my $sth = $dbh->prepare($query);
185
    $sth->execute($serialid);
186
    return $sth->fetchrow_hashref;
187
}
188
189
=head2 GetSerialItemnumber
190
191
    my $itemnumber = GetSerialItemnumber($serialid);
192
193
Returns the itemnumber associated to $serialid or undef if there is no item.
194
195
=cut
196
197
sub GetSerialItemnumber {
198
    my ($serialid) = @_;
199
200
    return unless $serialid;
201
    my $itemnumber;
202
203
    my $dbh = C4::Context->dbh;
204
    my $query = qq{
205
        SELECT itemnumber
206
        FROM serialitems
207
        WHERE serialid = ?
208
    };
209
    my $sth = $dbh->prepare($query);
210
    my $rv = $sth->execute($serialid);
211
    if ($rv) {
212
        my $result = $sth->fetchrow_hashref;
213
        $itemnumber = $result->{itemnumber};
214
    }
215
    return $itemnumber;
216
}
217
165
=head2 GetSerialInformation
218
=head2 GetSerialInformation
166
219
167
$data = GetSerialInformation($serialid);
220
$data = GetSerialInformation($serialid);
Lines 657-663 sub GetSerials { Link Here
657
    my @serials;
710
    my @serials;
658
    my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) );
711
    my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) );
659
    my $query = "SELECT serialid,serialseq, status, publisheddate,
712
    my $query = "SELECT serialid,serialseq, status, publisheddate,
660
        publisheddatetext, planneddate,notes, routingnotes
713
        publisheddatetext, planneddate, notes
661
                        FROM   serial
714
                        FROM   serial
662
                        WHERE  subscriptionid = ? AND status NOT IN ( $statuses )
715
                        WHERE  subscriptionid = ? AND status NOT IN ( $statuses )
663
                        ORDER BY IF(publisheddate IS NULL,planneddate,publisheddate) DESC";
716
                        ORDER BY IF(publisheddate IS NULL,planneddate,publisheddate) DESC";
Lines 678-684 sub GetSerials { Link Here
678
731
679
    # OK, now add the last 5 issues arrives/missing
732
    # OK, now add the last 5 issues arrives/missing
680
    $query = "SELECT   serialid,serialseq, status, planneddate, publisheddate,
733
    $query = "SELECT   serialid,serialseq, status, planneddate, publisheddate,
681
        publisheddatetext, notes, routingnotes
734
        publisheddatetext, notes
682
       FROM     serial
735
       FROM     serial
683
       WHERE    subscriptionid = ?
736
       WHERE    subscriptionid = ?
684
       AND      status IN ( $statuses )
737
       AND      status IN ( $statuses )
Lines 726-732 sub GetSerials2 { Link Here
726
    my $dbh   = C4::Context->dbh;
779
    my $dbh   = C4::Context->dbh;
727
    my $query = q|
780
    my $query = q|
728
                 SELECT serialid,serialseq, status, planneddate, publisheddate,
781
                 SELECT serialid,serialseq, status, planneddate, publisheddate,
729
                    publisheddatetext, notes, routingnotes
782
                    publisheddatetext, notes
730
                 FROM     serial 
783
                 FROM     serial 
731
                 WHERE    subscriptionid=?
784
                 WHERE    subscriptionid=?
732
            |
785
            |
Lines 1084-1096 sub ModSerialStatus { Link Here
1084
    #It is a usual serial
1137
    #It is a usual serial
1085
    # 1st, get previous status :
1138
    # 1st, get previous status :
1086
    my $dbh   = C4::Context->dbh;
1139
    my $dbh   = C4::Context->dbh;
1087
    my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity,serial.routingnotes
1140
    my $query = "SELECT serial.subscriptionid,serial.status,subscription.periodicity
1088
        FROM serial, subscription
1141
        FROM serial, subscription
1089
        WHERE serial.subscriptionid=subscription.subscriptionid
1142
        WHERE serial.subscriptionid=subscription.subscriptionid
1090
            AND serialid=?";
1143
            AND serialid=?";
1091
    my $sth   = $dbh->prepare($query);
1144
    my $sth   = $dbh->prepare($query);
1092
    $sth->execute($serialid);
1145
    $sth->execute($serialid);
1093
    my ( $subscriptionid, $oldstatus, $periodicity, $routingnotes ) = $sth->fetchrow;
1146
    my ( $subscriptionid, $oldstatus, $periodicity ) = $sth->fetchrow;
1094
    my $frequency = GetSubscriptionFrequency($periodicity);
1147
    my $frequency = GetSubscriptionFrequency($periodicity);
1095
1148
1096
    # change status & update subscriptionhistory
1149
    # change status & update subscriptionhistory
Lines 1101-1112 sub ModSerialStatus { Link Here
1101
        my $query = '
1154
        my $query = '
1102
            UPDATE serial
1155
            UPDATE serial
1103
            SET serialseq = ?, publisheddate = ?, publisheddatetext = ?,
1156
            SET serialseq = ?, publisheddate = ?, publisheddatetext = ?,
1104
                planneddate = ?, status = ?, notes = ?, routingnotes = ?
1157
                planneddate = ?, status = ?, notes = ?
1105
            WHERE  serialid = ?
1158
            WHERE  serialid = ?
1106
        ';
1159
        ';
1107
        $sth = $dbh->prepare($query);
1160
        $sth = $dbh->prepare($query);
1108
        $sth->execute( $serialseq, $publisheddate, $publisheddatetext,
1161
        $sth->execute( $serialseq, $publisheddate, $publisheddatetext,
1109
            $planneddate, $status, $notes, $routingnotes, $serialid );
1162
            $planneddate, $status, $notes, $serialid );
1110
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1163
        $query = "SELECT * FROM   subscription WHERE  subscriptionid = ?";
1111
        $sth   = $dbh->prepare($query);
1164
        $sth   = $dbh->prepare($query);
1112
        $sth->execute($subscriptionid);
1165
        $sth->execute($subscriptionid);
Lines 1162-1168 sub ModSerialStatus { Link Here
1162
        $sth = $dbh->prepare($query);
1215
        $sth = $dbh->prepare($query);
1163
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1216
        $sth->execute( $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3, $subscriptionid );
1164
        my $newnote = C4::Context->preference('PreserveSerialNotes') ? $notes : "";
1217
        my $newnote = C4::Context->preference('PreserveSerialNotes') ? $notes : "";
1165
        NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate, undef, $newnote, $routingnotes );
1218
        NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, 1, $nextpubdate, $nextpubdate, undef, $newnote );
1166
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1219
        # check if an alert must be sent... (= a letter is defined & status became "arrived"
1167
        if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) {
1220
        if ( $subscription->{letter} && $status == ARRIVED && $oldstatus != ARRIVED ) {
1168
            require C4::Letters;
1221
            require C4::Letters;
Lines 1541-1547 sub ReNewSubscription { Link Here
1541
1594
1542
=head2 NewIssue
1595
=head2 NewIssue
1543
1596
1544
NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes, $routingnotes)
1597
NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes)
1545
1598
1546
Create a new issue stored on the database.
1599
Create a new issue stored on the database.
1547
Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription.
1600
Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription.
Lines 1551-1557 returns the serial id Link Here
1551
1604
1552
sub NewIssue {
1605
sub NewIssue {
1553
    my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate,
1606
    my ( $serialseq, $subscriptionid, $biblionumber, $status, $planneddate,
1554
        $publisheddate, $publisheddatetext, $notes, $routingnotes ) = @_;
1607
        $publisheddate, $publisheddatetext, $notes ) = @_;
1555
    ### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ?
1608
    ### FIXME biblionumber CAN be provided by subscriptionid. So Do we STILL NEED IT ?
1556
1609
1557
    return unless ($subscriptionid);
1610
    return unless ($subscriptionid);
Lines 1573-1579 sub NewIssue { Link Here
1573
            publisheddate     => $publisheddate,
1626
            publisheddate     => $publisheddate,
1574
            publisheddatetext => $publisheddatetext,
1627
            publisheddatetext => $publisheddatetext,
1575
            notes             => $notes,
1628
            notes             => $notes,
1576
            routingnotes      => $routingnotes
1577
        }
1629
        }
1578
    )->store();
1630
    )->store();
1579
1631
Lines 1886-2046 sub updateClaim { Link Here
1886
        {}, CLAIMED, @$serialids );
1938
        {}, CLAIMED, @$serialids );
1887
}
1939
}
1888
1940
1889
=head2 check_routing
1890
1891
$result = &check_routing($subscriptionid)
1892
1893
this function checks to see if a serial has a routing list and returns the count of routingid
1894
used to show either an 'add' or 'edit' link
1895
1896
=cut
1897
1898
sub check_routing {
1899
    my ($subscriptionid) = @_;
1900
1901
    return unless ($subscriptionid);
1902
1903
    my $dbh              = C4::Context->dbh;
1904
    my $sth              = $dbh->prepare(
1905
        "SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist 
1906
                              ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
1907
                              WHERE subscription.subscriptionid = ? GROUP BY routingid ORDER BY ranking ASC
1908
                              "
1909
    );
1910
    $sth->execute($subscriptionid);
1911
    my $line   = $sth->fetchrow_hashref;
1912
    my $result = $line->{'routingids'};
1913
    return $result;
1914
}
1915
1916
=head2 addroutingmember
1917
1918
addroutingmember($borrowernumber,$subscriptionid)
1919
1920
this function takes a borrowernumber and subscriptionid and adds the member to the
1921
routing list for that serial subscription and gives them a rank on the list
1922
of either 1 or highest current rank + 1
1923
1924
=cut
1925
1926
sub addroutingmember {
1927
    my ( $borrowernumber, $subscriptionid ) = @_;
1928
1929
    return unless ($borrowernumber and $subscriptionid);
1930
1931
    my $rank;
1932
    my $dbh = C4::Context->dbh;
1933
    my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" );
1934
    $sth->execute($subscriptionid);
1935
    while ( my $line = $sth->fetchrow_hashref ) {
1936
        if ( $line->{'rank'} > 0 ) {
1937
            $rank = $line->{'rank'} + 1;
1938
        } else {
1939
            $rank = 1;
1940
        }
1941
    }
1942
    $sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" );
1943
    $sth->execute( $subscriptionid, $borrowernumber, $rank );
1944
}
1945
1946
=head2 reorder_members
1947
1948
reorder_members($subscriptionid,$routingid,$rank)
1949
1950
this function is used to reorder the routing list
1951
1952
it takes the routingid of the member one wants to re-rank and the rank it is to move to
1953
- it gets all members on list puts their routingid's into an array
1954
- removes the one in the array that is $routingid
1955
- then reinjects $routingid at point indicated by $rank
1956
- then update the database with the routingids in the new order
1957
1958
=cut
1959
1960
sub reorder_members {
1961
    my ( $subscriptionid, $routingid, $rank ) = @_;
1962
    my $dbh = C4::Context->dbh;
1963
    my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" );
1964
    $sth->execute($subscriptionid);
1965
    my @result;
1966
    while ( my $line = $sth->fetchrow_hashref ) {
1967
        push( @result, $line->{'routingid'} );
1968
    }
1969
1970
    # To find the matching index
1971
    my $i;
1972
    my $key = -1;    # to allow for 0 being a valid response
1973
    for ( $i = 0 ; $i < @result ; $i++ ) {
1974
        if ( $routingid == $result[$i] ) {
1975
            $key = $i;    # save the index
1976
            last;
1977
        }
1978
    }
1979
1980
    # if index exists in array then move it to new position
1981
    if ( $key > -1 && $rank > 0 ) {
1982
        my $new_rank = $rank - 1;                       # $new_rank is what you want the new index to be in the array
1983
        my $moving_item = splice( @result, $key, 1 );
1984
        splice( @result, $new_rank, 0, $moving_item );
1985
    }
1986
    for ( my $j = 0 ; $j < @result ; $j++ ) {
1987
        my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" );
1988
        $sth->execute;
1989
    }
1990
    return;
1991
}
1992
1993
=head2 delroutingmember
1994
1995
delroutingmember($routingid,$subscriptionid)
1996
1997
this function either deletes one member from routing list if $routingid exists otherwise
1998
deletes all members from the routing list
1999
2000
=cut
2001
2002
sub delroutingmember {
2003
2004
    # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid
2005
    my ( $routingid, $subscriptionid ) = @_;
2006
    my $dbh = C4::Context->dbh;
2007
    if ($routingid) {
2008
        my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?");
2009
        $sth->execute($routingid);
2010
        reorder_members( $subscriptionid, $routingid );
2011
    } else {
2012
        my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?");
2013
        $sth->execute($subscriptionid);
2014
    }
2015
    return;
2016
}
2017
2018
=head2 getroutinglist
2019
2020
@routinglist = getroutinglist($subscriptionid)
2021
2022
this gets the info from the subscriptionroutinglist for $subscriptionid
2023
2024
return :
2025
the routinglist as an array. Each element of the array contains a hash_ref containing
2026
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription
2027
2028
=cut
2029
2030
sub getroutinglist {
2031
    my ($subscriptionid) = @_;
2032
    my $dbh              = C4::Context->dbh;
2033
    my $sth              = $dbh->prepare(
2034
        'SELECT routingid, borrowernumber, ranking, biblionumber
2035
            FROM subscription 
2036
            JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
2037
            WHERE subscription.subscriptionid = ? ORDER BY ranking ASC'
2038
    );
2039
    $sth->execute($subscriptionid);
2040
    my $routinglist = $sth->fetchall_arrayref({});
2041
    return @{$routinglist};
2042
}
2043
2044
=head2 countissuesfrom
1941
=head2 countissuesfrom
2045
1942
2046
$result = countissuesfrom($subscriptionid,$startdate)
1943
$result = countissuesfrom($subscriptionid,$startdate)
(-)a/C4/Serials/RoutingLists.pm (+309 lines)
Line 0 Link Here
1
package C4::Serials::RoutingLists;
2
3
# Copyright 2012 Biblibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
use Koha::Biblios;
25
use Koha::Patrons;
26
use Koha::I18N;
27
28
use vars qw($VERSION @ISA @EXPORT_OK);
29
30
BEGIN {
31
    $VERSION = 3.01;
32
    require Exporter;
33
    @ISA = qw(Exporter);
34
    @EXPORT_OK = qw(
35
        &AddRoutingList
36
        &ModRoutingList
37
        &DelRoutingList
38
        &GetRoutingList
39
        &GetRoutingLists
40
        &GetRoutingListsCount
41
        &GetRoutingListAsCSV
42
    );
43
}
44
45
=head1 NAME
46
47
C4::Serials::RoutingLists
48
49
=head1 SYNOPSYS
50
51
use C4::Serials::RoutingLists;
52
53
=head1 DESCRIPTION
54
55
This module provides subroutines to deal with subscriptions routing lists
56
57
=head1 FUNCTIONS
58
59
=head2 AddRoutingList
60
61
$routinglistid = &AddRoutingList($subscriptionid, $title);
62
63
this function create a new routing list for a subscription.
64
65
=cut
66
67
sub AddRoutingList {
68
    my ($subscriptionid, $title) = @_;
69
70
    return unless $subscriptionid and $title;
71
72
    my $dbh = C4::Context->dbh();
73
    my $query = qq{
74
        INSERT INTO subscriptionroutinglist (subscriptionid, title)
75
        VALUES (?, ?)
76
    };
77
    my $sth = $dbh->prepare($query);
78
    my $rv = $sth->execute($subscriptionid, $title);
79
80
    return unless $rv;
81
    return $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef);
82
}
83
84
=head2 ModRoutingList
85
86
&ModRoutingList($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers);
87
88
this function modifies a routing list.
89
90
=cut
91
92
sub ModRoutingList {
93
    my ($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers) = @_;
94
95
    return unless $routinglistid;
96
97
    my $dbh = C4::Context->dbh;
98
    my $query = 'UPDATE subscriptionroutinglist';
99
    my @setstrings = ();
100
    my @setargs = ();
101
    if($subscriptionid) {
102
        push @setstrings, 'subscriptionid = ?';
103
        push @setargs, $subscriptionid;
104
    }
105
    if($title) {
106
        push @setstrings, 'title = ?';
107
        push @setargs, $title;
108
    }
109
    if($notes) {
110
        push @setstrings, 'notes = ?';
111
        push @setargs, $notes;
112
    }
113
114
    if(@setstrings) {
115
        $query .= ' SET ' . join(',', @setstrings);
116
        $query .= ' WHERE routinglistid = ?';
117
        my $sth = $dbh->prepare($query);
118
        $sth->execute(@setargs, $routinglistid);
119
    }
120
121
    $query = qq{
122
        DELETE FROM subscriptionrouting
123
        WHERE routinglistid = ?
124
    };
125
    my $sth = $dbh->prepare($query);
126
    $sth->execute($routinglistid);
127
128
    if(@borrowernumbers > 0){
129
        $query = qq{
130
            INSERT INTO subscriptionrouting (routinglistid, borrowernumber, ranking)
131
            VALUES (?, ?, ?)
132
        };
133
        $sth = $dbh->prepare($query);
134
        my $i = 1;
135
        foreach (@borrowernumbers) {
136
            $sth->execute($routinglistid, $_, $i);
137
            $i++;
138
        }
139
    }
140
}
141
142
=head2 DelRoutingList
143
144
&DelRoutingList($routinglistid);
145
146
this function delete a routing list.
147
148
=cut
149
150
sub DelRoutingList {
151
    my ($routinglistid) = @_;
152
153
    return unless $routinglistid;
154
155
    my $dbh = C4::Context->dbh;
156
    my $query = qq{
157
        DELETE FROM subscriptionroutinglist
158
        WHERE routinglistid = ?
159
    };
160
    my $sth = $dbh->prepare($query);
161
    $sth->execute($routinglistid);
162
}
163
164
165
=head2 GetRoutingList
166
167
$routinglist = &GetRoutingList($routinglistid);
168
169
this function get infos from subscriptionroutinglist table.
170
The 'borrowers' keys contains the list of borrowernumbers attached
171
to this routing list.
172
173
=cut
174
175
sub GetRoutingList {
176
    my ($routinglistid) = @_;
177
178
    return unless $routinglistid;
179
180
    my $dbh = C4::Context->dbh;
181
    my $query = qq{
182
        SELECT *
183
        FROM subscriptionroutinglist
184
        WHERE routinglistid = ?
185
    };
186
    my $sth = $dbh->prepare($query);
187
    $sth->execute($routinglistid);
188
    my $result = $sth->fetchrow_hashref;
189
190
    $query = qq{
191
        SELECT borrowernumber
192
        FROM subscriptionrouting
193
        WHERE routinglistid = ?
194
        ORDER BY ranking ASC
195
    };
196
    $sth = $dbh->prepare($query);
197
    $sth->execute($routinglistid);
198
    while (my $row = $sth->fetchrow_hashref) {
199
        push @{$result->{borrowers}}, $row->{borrowernumber};
200
    }
201
202
    return $result;
203
}
204
205
=head2 GetRoutingLists
206
207
@routinglists = &GetRoutingLists($subscriptionid);
208
209
this function get all routing lists for a subscription.
210
211
=cut
212
213
sub GetRoutingLists {
214
    my ($subscriptionid) = @_;
215
216
    return () unless $subscriptionid;
217
218
    my $dbh = C4::Context->dbh;
219
    my $query = qq{
220
        SELECT routinglistid
221
        FROM subscriptionroutinglist
222
        WHERE subscriptionid = ?
223
    };
224
    my $sth = $dbh->prepare($query);
225
    $sth->execute($subscriptionid);
226
    my @results;
227
    while (my $row = $sth->fetchrow_hashref) {
228
        my $routinglistid = $row->{routinglistid};
229
        push @results, GetRoutingList($routinglistid);
230
    }
231
232
    return @results;
233
}
234
235
=head2 GetRoutingListsCount
236
237
$count = &GetRoutingListsCount($subscriptionid);
238
239
this function return the number of routing lists for a subscription.
240
241
=cut
242
243
sub GetRoutingListsCount {
244
    my ($subscriptionid) = @_;
245
246
    return unless $subscriptionid;
247
248
    my $dbh = C4::Context->dbh;
249
    my $query = qq{
250
        SELECT COUNT(*) AS count
251
        FROM subscriptionroutinglist
252
        WHERE subscriptionid = ?
253
    };
254
    my $sth = $dbh->prepare($query);
255
    $sth->execute($subscriptionid);
256
    my $result = $sth->fetchrow_hashref;
257
258
    return $result->{count};
259
}
260
261
=head2 GetRoutingListAsCSV
262
263
$csv_output = &GetRoutingListAsCSV($routinglistid);
264
265
this function return the routing list as a CSV file.
266
267
=cut
268
269
sub GetRoutingListAsCSV {
270
    my ($routinglistid) = @_;
271
272
    return unless $routinglistid;
273
274
    require C4::Serials;
275
    require C4::Templates;
276
    require Text::CSV::Encoded;
277
278
    my $csv = Text::CSV::Encoded->new( {encoding => "utf8" } );
279
    my $output;
280
281
    my $routinglist = GetRoutingList($routinglistid);
282
    my $subscription = C4::Serials::GetSubscription($routinglist->{'subscriptionid'});
283
    my $biblio = Koha::Biblios->find($subscription->{'biblionumber'});
284
285
    $csv->combine(
286
        __('Subscription title'),
287
        __('Routing list'),
288
        __('Surname'),
289
        __('First name'),
290
        __('Notes'),
291
    );
292
    $output .= $csv->string() . "\n";
293
294
    foreach (@{$routinglist->{borrowers}}) {
295
        my $patron = Koha::Patrons->find($_);
296
        $csv->combine(
297
            $biblio->title,
298
            $routinglist->{'title'},
299
            $patron->surname,
300
            $patron->firstname,
301
            $routinglist->{'notes'},
302
        );
303
        $output .= $csv->string() . "\n";
304
    }
305
306
    return $output;
307
}
308
309
1;
(-)a/acqui/newordersubscription.pl (-1 / +2 lines)
Lines 24-29 use C4::Auth; Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Output;
25
use C4::Output;
26
use C4::Serials;
26
use C4::Serials;
27
use C4::Serials::RoutingLists qw( GetRoutingListsCount );
27
28
28
use Koha::Acquisition::Booksellers;
29
use Koha::Acquisition::Booksellers;
29
30
Lines 71-77 foreach my $sub (@subscriptions) { Link Here
71
72
72
    # to toggle between create or edit routing list options
73
    # to toggle between create or edit routing list options
73
    if ($routing) {
74
    if ($routing) {
74
        $sub->{routingedit} = check_routing( $sub->{subscriptionid} );
75
        $sub->{routingedit} = GetRoutingListsCount( $sub->{subscriptionid} );
75
    }
76
    }
76
}
77
}
77
78
(-)a/installer/data/mysql/atomicupdate/bug_7957.perl (+67 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use C4::Context;
3
4
my $dbh = C4::Context->dbh;
5
$dbh->do("RENAME TABLE subscriptionroutinglist TO tmp_subscriptionroutinglist");
6
$dbh->do("
7
    CREATE TABLE subscriptionroutinglist (
8
        routinglistid int(11) NOT NULL AUTO_INCREMENT,
9
        subscriptionid int(11) NOT NULL,
10
        title varchar(256) NOT NULL,
11
        notes text default NULL,
12
        PRIMARY KEY (routinglistid),
13
        CONSTRAINT subscriptionroutinglist_ibfk_1 FOREIGN KEY (subscriptionid)
14
          REFERENCES subscription (subscriptionid) ON DELETE CASCADE
15
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
16
");
17
$dbh->do("
18
    CREATE TABLE subscriptionrouting (
19
        routinglistid int(11) NOT NULL,
20
        borrowernumber int(11) NOT NULL,
21
        ranking int(11) DEFAULT NULL,
22
        PRIMARY KEY (routinglistid, borrowernumber),
23
        CONSTRAINT subscriptionrouting_ibfk_1 FOREIGN KEY (routinglistid)
24
          REFERENCES subscriptionroutinglist (routinglistid) ON DELETE CASCADE,
25
        CONSTRAINT subscriptionrouting_ibfk_2 FOREIGN KEY (borrowernumber)
26
          REFERENCES borrowers (borrowernumber) ON DELETE CASCADE
27
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
28
");
29
30
# Migrate data from old subscriptionroutinglist table
31
my $query = qq{
32
    SELECT serial.subscriptionid, serial.routingnotes
33
    FROM tmp_subscriptionroutinglist
34
    LEFT JOIN serial ON (tmp_subscriptionroutinglist.subscriptionid = serial.subscriptionid)
35
    GROUP BY serial.subscriptionid
36
};
37
my $sth = $dbh->prepare($query);
38
$sth->execute();
39
my $results = $sth->fetchall_arrayref( {} );
40
$query = qq{
41
    INSERT INTO subscriptionroutinglist (subscriptionid, title, notes)
42
    VALUES (?, ?, ?)
43
};
44
$sth = $dbh->prepare($query);
45
$query = qq{
46
    SELECT borrowernumber, ranking
47
    FROM tmp_subscriptionroutinglist
48
    WHERE subscriptionid = ?
49
};
50
my $select_sth = $dbh->prepare($query);
51
$query = qq{
52
    INSERT INTO subscriptionrouting (routinglistid, borrowernumber, ranking)
53
    VALUES(?, ?, ?)
54
};
55
my $insert_sth = $dbh->prepare($query);
56
foreach ( @$results ) {
57
    $sth->execute($_->{subscriptionid}, 'import', $_->{routingnotes});
58
    my $routinglistid = $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef);
59
    $select_sth->execute($_->{subscriptionid});
60
    my $routings = $select_sth->fetchall_arrayref( {} );
61
    foreach (@$routings) {
62
        $insert_sth->execute($routinglistid, $_->{borrowernumber}, $_->{ranking});
63
    }
64
}
65
66
$dbh->do("DROP TABLE tmp_subscriptionroutinglist");
67
$dbh->do("ALTER TABLE serial DROP COLUMN routingnotes");
(-)a/installer/data/mysql/kohastructure.sql (-15 / +30 lines)
Lines 1473-1479 CREATE TABLE `serial` ( -- issues related to subscriptions Link Here
1473
  publisheddatetext varchar(100) default NULL, -- date published (descriptive)
1473
  publisheddatetext varchar(100) default NULL, -- date published (descriptive)
1474
  `claimdate` date default NULL, -- date claimed
1474
  `claimdate` date default NULL, -- date claimed
1475
  claims_count int(11) default 0, -- number of claims made related to this issue
1475
  claims_count int(11) default 0, -- number of claims made related to this issue
1476
  `routingnotes` MEDIUMTEXT, -- notes from the routing list
1477
  PRIMARY KEY (`serialid`)
1476
  PRIMARY KEY (`serialid`)
1478
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1477
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1479
1478
Lines 2056-2077 CREATE TABLE `subscriptionhistory` ( Link Here
2056
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2055
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2057
2056
2058
--
2057
--
2059
-- Table structure for table `subscriptionroutinglist`
2058
-- Table structure for table subscriptionroutinglist
2060
--
2059
--
2061
2060
2062
DROP TABLE IF EXISTS `subscriptionroutinglist`;
2061
DROP TABLE IF EXISTS subscriptionroutinglist;
2063
CREATE TABLE `subscriptionroutinglist` ( -- information related to the routing lists attached to subscriptions
2062
CREATE TABLE subscriptionroutinglist (
2064
  `routingid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2063
    routinglistid int(11) NOT NULL AUTO_INCREMENT, -- unique identifier assigned by Koha
2065
  `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines with patron is on the routing list
2064
    subscriptionid int(11) NOT NULL, -- foreign key from the subscription table,
2066
  `ranking` int(11) default NULL, -- where the patron stands in line to receive the serial
2065
                                     -- defines which subscription this routing list is for
2067
  `subscriptionid` int(11) NOT NULL, -- foreign key from the subscription table, defines which subscription this routing list is for
2066
    title varchar(256) NOT NULL, -- title of this routing list
2068
  PRIMARY KEY  (`routingid`),
2067
    notes text default NULL, -- notes for this routing list
2069
  UNIQUE (`subscriptionid`, `borrowernumber`),
2068
    PRIMARY KEY (routinglistid),
2070
  CONSTRAINT `subscriptionroutinglist_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
2069
    CONSTRAINT subscriptionroutinglist_ibfk_1 FOREIGN KEY (subscriptionid)
2071
    ON DELETE CASCADE ON UPDATE CASCADE,
2070
      REFERENCES subscription (subscriptionid) ON DELETE CASCADE
2072
  CONSTRAINT `subscriptionroutinglist_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`)
2071
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2073
    ON DELETE CASCADE ON UPDATE CASCADE
2072
2074
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2073
--
2074
-- Table structure for subscriptionrouting
2075
--
2076
2077
DROP TABLE IF EXISTS subscriptionrouting;
2078
CREATE TABLE subscriptionrouting (
2079
    routinglistid int(11) NOT NULL, -- foreign key from the subscriptionroutinglist
2080
                                    -- table, defines which routing list is affected
2081
    borrowernumber int(11) NOT NULL, -- foreign key from the borrowers table,
2082
                                     -- defines which patron is on the routing list
2083
    ranking int(11) DEFAULT NULL, -- where the patron stands in line to receive the serial
2084
    PRIMARY KEY (routinglistid, borrowernumber),
2085
    CONSTRAINT subscriptionrouting_ibfk_1 FOREIGN KEY (routinglistid)
2086
      REFERENCES subscriptionroutinglists (routinglistid) ON DELETE CASCADE,
2087
    CONSTRAINT subscriptionrouting_ibfk_2 FOREIGN KEY (borrowernumber)
2088
      REFERENCES borrowers (borrowernumber) ON DELETE CASCADE
2089
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2075
2090
2076
--
2091
--
2077
-- Table structure for table `systempreferences`
2092
-- Table structure for table `systempreferences`
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc (-2 / +2 lines)
Lines 6-14 Link Here
6
                [% UNLESS closed %]
6
                [% UNLESS closed %]
7
                    [% IF ( routing && CAN_user_serials_routing ) %]
7
                    [% IF ( routing && CAN_user_serials_routing ) %]
8
                        [% IF ( hasRouting ) %]
8
                        [% IF ( hasRouting ) %]
9
                            <li><a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]">Edit routing list</a></li>
9
                            <li><a href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscriptionid | uri %]">Edit routing list</a></li>
10
                        [% ELSE %]
10
                        [% ELSE %]
11
                            <li><a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]&amp;op=new">Create routing list</a></li>
11
                            <li><a href="/cgi-bin/koha/serials/routinglist.pl?subscriptionid=[% subscriptionid | uri %]&amp;op=new">Create routing list</a></li>
12
                        [% END %]
12
                        [% END %]
13
                    [% END %]
13
                    [% END %]
14
                [% END %]
14
                [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt (-38 / +33 lines)
Lines 30-83 Link Here
30
30
31
[% SET routinglists = patron.get_routing_lists %]
31
[% SET routinglists = patron.get_routing_lists %]
32
<h1>
32
<h1>
33
[% UNLESS ( routinglists ) %]
33
[% IF routinglists.size == 0 %]
34
0 subscription routing lists
34
0 subscription routing lists
35
[% ELSIF ( routinglists.count == 1 ) %]
35
[% ELSIF ( routinglists.size == 1 ) %]
36
[% routinglists.count | html %] subscription routing list
36
[% routinglists.size | html %] subscription routing list
37
[% ELSE %]
37
[% ELSE %]
38
[% routinglists.count | html %] subscription routing lists
38
[% routinglists.size | html %] subscription routing lists
39
[% END %]
39
[% END %]
40
</h1>
40
</h1>
41
41
42
<div id="subscriptions">
42
<div id="subscriptions">
43
43
  [% IF ( routinglists.size > 0 ) %]
44
[% IF ( routinglists ) %]
45
    <table id="subscriptiont">
44
    <table id="subscriptiont">
46
        <thead>
45
      <thead>
47
            <tr>
46
        <tr>
48
                <th>Subscription title</th>
47
          <th>Subscription title</th>
49
                <th>Position</th>
48
          <th>Routing list</th>
50
                <th>Routing list</th>
49
          <th>Actions</th>
51
            </tr>
50
        </tr>
52
        </thead>
51
      </thead>
53
        <tbody>
52
      <tbody>
54
        [% FOREACH routinglist IN routinglists %]
53
        [% FOREACH routinglist IN routinglists %]
55
            <tr>
54
          <tr>
56
                <td>
55
            <td>
57
                    <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% routinglist.subscription.subscriptionid | uri %]">
56
              <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% routinglist.subscriptionid | uri %]">
58
                        [% routinglist.subscription.biblio.title | html %]
57
                <strong>
59
                    </a>
58
                  [% routinglist.bibliotitle | html %]
60
                </td>
59
                </strong>
61
                <td>
60
              </a>
62
                    [% routinglist.ranking | html %]
61
            </td>
63
                </td>
62
            <td>[% routinglist.title | html %]</td>
64
                <td>
63
            <td>
65
                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% routinglist.subscription.subscriptionid | uri %]">
64
              <a href="/cgi-bin/koha/serials/routinglist.pl?routinglistid=[% routinglist.routinglistid | uri %]"><strong>
66
                        Edit routing list
65
              Edit routing list
67
                    </a>
66
                </strong>
68
                    <input type="hidden" name="biblionumber" value="[% routinglist.subscription.biblionumber | html %]" />
67
              </a>
69
                    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
68
            </td>
70
                </td>
69
          </tr>
71
            </tr>
70
        [% END %]
72
            [% END %]
71
      </tbody>
73
        </tbody>
74
    </table>
72
    </table>
75
[% ELSE %]
73
  [% ELSE %]
76
    <p>Patron does not belong to any subscription routing lists.</p>
74
    <p>Patron does not belong to any subscription routing lists.</p>
77
    <input type="hidden" name="biblionumber" value="[% routinglist.subscription.biblionumber | html %]" />
75
  [% END %]
78
    <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
79
[% END %]
80
81
</div>
76
</div>
82
77
83
            </main>
78
            </main>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt (-26 / +96 lines)
Lines 1-3 Link Here
1
[% USE Branches %]
1
[% USE Koha %]
2
[% USE Koha %]
2
[% USE raw %]
3
[% USE raw %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
Lines 12-47 Link Here
12
<body id="ser_routing-preview-slip" class="ser">
13
<body id="ser_routing-preview-slip" class="ser">
13
    <div class="container-fluid">
14
    <div class="container-fluid">
14
15
15
<table>
16
[% IF (missing_parameter_routinglistid or missing_parameter_serialid) %]
16
    <tr>
17
    <h1>Routing list preview for <em>[% title | html %]</em></h1>
17
        <td colspan="2"><h3>[% libraryname | html %]</h3></td>
18
18
    </tr>
19
    <form action="" method="get">
19
    <tr>
20
        [% IF (missing_parameter_routinglistid) %]
20
        <td colspan="2"><b>Title:</b> [% title | html %]<br />[% issue | html %]</td>
21
            <input type="hidden" name="serialid" value="[% serialid | html %]" />
21
    </tr>
22
            <label for="routinglist">Please select a routing list</label>
22
    <tr>
23
            <select id="routinglist" name="routinglistid">
23
        <td><b>Name</b></td>
24
                [% FOREACH routinglist IN routinglists %]
24
        <td><b>Date due</b></td>
25
                    <option value="[% routinglist.routinglistid | html %]">
25
    </tr>
26
                        [% routinglist.title | html %]
26
    [% FOREACH memberloo IN memberloop %]
27
                    </option>
27
    <tr>
28
                [% END %]
28
        <td>[% memberloo.name | html %]</td>
29
            </select>
29
        <td>&nbsp;</td>
30
        [% ELSE %]
30
    </tr>
31
            <input type="hidden" name="routinglistid" value="[% routinglistid | html %]" />
32
            <label for="serial">Please select a serial</label>
33
            <select id="serial" name="serialid">
34
                [% FOREACH serial IN serials %]
35
                    <option value="[% serial.serialid | html %]">
36
                        [% serial.serialseq | html %] ([% serial.planneddate | html %])
37
                    </option>
38
                [% END %]
39
            </select>
40
        [% END %]
41
        <input type="submit" value="Continue" />
42
    </form>
43
[% ELSE %]
44
    [% IF (error_no_item) %]
45
        <div class="error noprint">
46
            <p>Holds cannot be placed on this serial. There is no item attached to it.</p>
47
        </div>
31
    [% END %]
48
    [% END %]
32
</table>
49
    <table>
50
        [% IF branchcode %]
51
            <tr>
52
                <td colspan="2"><h3>[% Branches.GetName(branchcode) | html %]</h3></td>
53
            </tr>
54
        [% END %]
55
        <tr>
56
            <td colspan="2">
57
                <b>Title:</b> [% title | html %]<br />
58
                [% serial.serialseq | html %] ([% serial.planneddate | html %])
59
            </td>
60
        </tr>
61
        <tr>
62
            <td colspan="2">
63
                <b>Routing list:</b> [% routinglisttitle | html %]
64
            </td>
65
        </tr>
66
        <tr>
67
            <td><b>Name</b></td>
68
            <td><b>Date due</b></td>
69
        </tr>
70
        [% FOREACH member IN memberloop %]
71
        <tr>
72
            <td>[% member.surname | html %], [% member.firstname | html %]</td>
73
            <td>&nbsp;</td>
74
        </tr>
75
        [% END %]
76
    </table>
33
77
34
<div id="routingnotes">
78
    <div id="routingnotes">
35
    <p id="generalroutingnote">[% Koha.Preference('RoutingListNote') | $raw %]</p>
79
        <p id="generalroutingnote">[% Koha.Preference('RoutingListNote') | $raw %]</p>
36
    <p id="routingnote">[% routingnotes | html %]</p>
80
        <p id="routingnote">[% routingnotes | html %]</p>
37
</div>
81
    </div>
38
82
39
    <div id="closewindow" class="noprint"><a class="btn btn-default btn-default" id="print_slip" href="#"><i class="fa fa-print"></i> Print</a> <a class="btn btn-default btn-default close" href="#">Close</a></div>
83
    [% IF (need_confirm) %]
84
        [%# RoutingListAddReserves is ON %]
85
        <script type="text/javascript">
86
        //<![CDATA[
87
            function ask_confirm() {
88
                var msg = _("Holds will be placed for all borrowers in this list.");
89
                msg += "\n";
90
                msg += _("Do you want to continue?");
91
                return confirm(msg);
92
            }
93
        //]]>
94
        </script>
95
        <form action="" method="get" onsubmit="return ask_confirm()">
96
            <input type="hidden" name="routinglistid" value="[% routinglistid | html %]" />
97
            <input type="hidden" name="serialid" value="[% serialid | html %]" />
98
            <input type="hidden" name="confirm" value="1" />
99
            <input type="submit" value="Confirm and print" />
100
            <input type="button" value="Cancel" onclick="window.close()" />
101
        </form>
102
    [% ELSE %]
103
        <div id="closewindow" class="noprint">
104
            <a class="btn btn-default" id="print_slip" href="#"><i class="fa fa-print"></i> Print</a>
105
            <a class="btn btn-default close" href="#">Close</a>
106
        </div>
107
    [% END %]
108
[% END %]
109
110
    </div>
40
111
41
[% MACRO jsinclude BLOCK %]
112
[% MACRO jsinclude BLOCK %]
42
    <script type="text/javascript">
113
    <script>
43
        $(document).ready(function(){
114
        $(document).ready(function () {
44
            $("#print_slip").on("click",function(e){
115
            $('#print_slip').on('click', function (e) {
45
                e.preventDefault();
116
                e.preventDefault();
46
                window.print();
117
                window.print();
47
                self.close();
118
                self.close();
Lines 49-53 Link Here
49
        });
120
        });
50
    </script>
121
    </script>
51
[% END %]
122
[% END %]
52
53
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
123
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt (-68 lines)
Lines 1-68 Link Here
1
[% SET footerjs = 1 %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Serials &rsaquo; Preview routing list</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
</head>
6
7
<body id="ser_routing-preview" class="ser">
8
[% INCLUDE 'header.inc' %]
9
[% INCLUDE 'serials-search.inc' %]
10
11
<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; <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscriptionid | html %]"><i>[% title | html %]</i></a> &rsaquo; Preview routing list</div>
12
13
<div class="main container-fluid">
14
    <div class="row">
15
        <div class="col-sm-10 col-sm-push-2">
16
            <main>
17
18
<h2>Preview routing list for <i>[% title | html %]</i></h2>
19
20
<form method="post" action="routing-preview.pl">
21
<input type="hidden" id="subscriptionid" name="subscriptionid" value="[% subscriptionid | html %]" />
22
    <input type="hidden" id="issue_escaped" name="issue_escaped" value="[% issue_escaped | html %]" />
23
<fieldset class="rows">
24
	<ol>
25
		<li><span class="label">Issue:</span>[% issue | html %]</li>
26
		<li><span class="label">List member:</span><table style="clear:none;margin:0;">
27
        <tr><th>Name</th></tr>
28
[% FOREACH memberloo IN memberloop %]
29
        <tr><td>[% memberloo.surname | html %], [% memberloo.firstname | html %]</td></tr>
30
[% END %]
31
        </table></li>
32
		<li><span class="label">Notes:</span>[% routingnotes | html %]</li>
33
	</ol>
34
</fieldset>
35
36
<fieldset class="action">
37
    <input type="submit" name="ok" id="save_and_preview" class="button" value="Save and preview routing slip" />
38
<input type="submit" name="edit" class="button" value="Edit" />
39
<input type="submit" name="delete" class="button" value="Delete" /></fieldset>
40
</form>
41
42
            </main>
43
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
44
45
        <div class="col-sm-2 col-sm-pull-10">
46
            <aside>
47
                [% INCLUDE 'serials-menu.inc' %]
48
            </aside>
49
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
50
     </div> <!-- /.row -->
51
52
[% MACRO jsinclude BLOCK %]
53
    <script>
54
        $(document).ready(function(){
55
            $("#save_and_preview").on("click",function(e){
56
                e.preventDefault();
57
                print_slip( $("#subscriptionid").val(), $("#issue_escaped").val() );
58
            });
59
        });
60
        function print_slip(subscriptionid,issue){
61
            var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
62
            window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
63
            window.location.href='subscription-detail.pl?subscriptionid=' + subscriptionid;
64
        }
65
    </script>
66
[% END %]
67
68
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt (-135 lines)
Lines 1-135 Link Here
1
[% USE KohaDates %]
2
[% SET footerjs = 1 %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Serials &rsaquo; [% title | html %] &rsaquo; [% IF ( op ) %]Create routing list[% ELSE %]Edit routing list[% END %]</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
</head>
7
<body id="ser_routing" class="ser">
8
[% INCLUDE 'header.inc' %]
9
[% INCLUDE 'serials-search.inc' %]
10
11
<div id="breadcrumbs">
12
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
13
    &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a>
14
    [% UNLESS blocking_error %]
15
        &rsaquo; <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscriptionid | uri %]"><i>[% title | html %]</i></a>
16
        &rsaquo; [% IF ( op ) %]Create routing list[% ELSE %]Edit routing list[% END %]
17
    [% END %]
18
</div>
19
20
<div class="main container-fluid">
21
    <div class="row">
22
        <div class="col-sm-10 col-sm-push-2">
23
            <main>
24
[% INCLUDE 'blocking_errors.inc' %]
25
26
[% IF ( op ) %]
27
<h1>Create routing list for <i>[% title | html %]</i></h1>
28
[% ELSE %]
29
<h1>Edit routing list for <i>[% title | html %]</i></h1>
30
[% END %]
31
32
<form method="post" action="routing.pl">
33
<input type="hidden" name="op" value="save" />
34
<input type="hidden" name="subscriptionid" value="[% subscriptionid | html %]" />
35
<fieldset class="rows">
36
	<ol>
37
		<li><label for="date_selected">Issue: </label>
38
<select name="date_selected" id="date_selected">
39
    [% FOREACH date IN dates %]
40
        [% IF ( date.selected ) %]
41
            <option value="[% date.serialseq | html %] ([% date.publisheddate | html %])" selected="selected">[% date.serialseq | html %] ([% date.publisheddate | $KohaDates %])</option>
42
        [% ELSE %]
43
            <option value="[% date.serialseq | html %] ([% date.publisheddate | html %])">[% date.serialseq | html %] ([% date.publisheddate | $KohaDates %])</option>
44
        [% END %]
45
[% END %]
46
</select> [% issue | html %]</li>
47
48
<li>
49
    <span class="label">Recipients:</span>
50
    [% IF memberloop %]
51
        <table style="clear:none;margin:0;">
52
            <tr><th>Name</th>
53
                <th>Rank</th>
54
                <th>Delete</th>
55
            </tr>
56
            [% USE m_loop = iterator(memberloop) %]
57
            [% FOREACH member IN m_loop %]
58
            <tr><td>[% member.name | html %]</td>
59
                <td>
60
                    <select name="itemrank" class="itemrank" data-subscriptionid="[% subscriptionid | html %]" data-routingid="[% member.routingid | html %]">
61
                    [% rankings = [1 .. m_loop.size] %]
62
                    [% SET cur_rank = loop.count() %]
63
                    [% FOREACH r IN rankings %]
64
                        [% IF r == cur_rank %]
65
                          <option selected="selected" value="[% r | html %]">[% r | html %]</option>
66
                        [% ELSE %]
67
                          <option value="[% r | html %]">[% r | html %]</option>
68
                        [% END %]
69
                    [% END %]
70
                    </select>
71
                </td>
72
                <td><a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/routing.pl?routingid=[% member.routingid | html %]&amp;subscriptionid=[% subscriptionid | html %]&amp;op=delete"><i class="fa fa-trash"></i> Delete</a></td>
73
            </tr>
74
            [% END %]
75
        </table>
76
    [% END %]
77
78
    <p style="margin-left:10em;">
79
        <a href="#" id="add_recipients"><i class="fa fa-plus"></i> Add recipients</a>
80
        [% IF memberloop %]
81
            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]&amp;op=delete"><i class="fa fa-trash"></i> Delete all</a>
82
        [% END %]
83
    </p>
84
</li>
85
86
	<li><label for="notes">Notes:</label><textarea name="notes" id="notes" rows="3" cols="50">[% routingnotes | html %]</textarea></li>
87
	</ol>
88
89
</fieldset>
90
<fieldset class="action"><input type="submit" name="submit" value="Save" /></fieldset>
91
</form>
92
93
            </main>
94
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
95
96
        <div class="col-sm-2 col-sm-pull-10">
97
            <aside>
98
                [% INCLUDE 'serials-menu.inc' %]
99
            </aside>
100
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
101
     </div> <!-- /.row -->
102
[% MACRO jsinclude BLOCK %]
103
    <script>
104
        $(document).ready(function(){
105
            $("#add_recipients").on("click",function(e){
106
                e.preventDefault();
107
                userPopup();
108
            });
109
            $(".itemrank").on("change",function(){
110
                var subscriptionid = $(this).data("subscriptionid");
111
                var routingid = $(this).data("routingid");
112
                reorder_item( subscriptionid, routingid, $(this).val());
113
            });
114
        });
115
        function reorder_item(sid,rid,rank){
116
            var mylocation = 'reorder_members.pl?subscriptionid='+sid+'&routingid='+rid+'&rank='+rank;
117
            window.location.href=mylocation;
118
        }
119
120
        function userPopup() {
121
            window.open("/cgi-bin/koha/serials/add_user_search.pl",
122
                'PatronPopup',
123
                'width=740,height=450,location=yes,toolbar=no,'
124
                + 'scrollbars=yes,resize=yes'
125
            );
126
        }
127
128
        function add_user(borrowernumber) {
129
            var myurl = "routing.pl?subscriptionid="+[% subscriptionid | html %]+"&borrowernumber="+borrowernumber+"&op=add";
130
            window.location.href = myurl;
131
        }
132
    </script>
133
[% END %]
134
135
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt (+204 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Routing list</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
[% UNLESS ( new ) %]
7
var max_rank = [% max_rank %];
8
9
function IncMaxRank(){
10
    max_rank = max_rank + 1;
11
    var option = '<option value="' + max_rank + '">' + max_rank + '</option>';
12
    $('select[name="ranking"]').append(option);
13
}
14
15
function DecMaxRank(){
16
    max_rank = max_rank - 1;
17
    $('select[name="ranking"] option[value="'+(max_rank+1)+'"]').remove();
18
}
19
20
function updateTable(){
21
    var ids = $("#borrowersids").val().split(":");
22
    // split returns an array with one empty string if string is empty
23
    if(ids[0] == "")
24
        ids.splice(0,1);
25
26
    var new_trs = new Array();
27
    for(var i=0; i<ids.length; i++){
28
        var tr = $("#ranking"+ids[i]).parents("tr");
29
        new_trs.push("<tr>"+$(tr).html()+"</tr>");
30
    }
31
    $("#borrowers tbody").html(new_trs.join(" "));
32
    var i=0;
33
    $("select[name='ranking']").each(function(){
34
        $(this).val(i+1);
35
        i++;
36
        var borrowernumber = $(this).attr('id').replace("ranking","");
37
        $(this).change(function(){
38
            reorderBorrower(borrowernumber, $(this).val());
39
        });
40
    });
41
    if(i < max_rank)
42
        DecMaxRank();
43
44
    if(max_rank == 0){
45
        $("#borrowers").hide();
46
        $("#noborrowersp").show();
47
    }
48
}
49
50
// delete borrower if rank <= 0
51
function reorderBorrower(borrowernumber, rank){
52
    var ids = $("#borrowersids").val().split(":");
53
    for(var i=0; i<ids.length; i++){
54
        if(ids[i] == borrowernumber){
55
            ids.splice(i, 1);
56
            break;
57
        }
58
    }
59
    if(rank > 0){
60
      ids.splice(rank-1, 0, borrowernumber);
61
    }
62
    $("#borrowersids").val(ids.join(":"));
63
    updateTable();
64
}
65
66
function add_user(borrowernumber, borrowername){
67
    // Check if we have already this borrower
68
    var ids = $("#borrowersids").val();
69
    var re = new RegExp("(^"+borrowernumber+"$)|(^"+borrowernumber+":)|(:"+borrowernumber+"$)|(:"+borrowernumber+":)");
70
    if(ids.match(re))
71
        return -1;
72
73
    IncMaxRank();
74
    var tr = '<tr>';
75
    tr += '<td>' + borrowername + '</td>';
76
    tr += '<td><select name="ranking" id="ranking' + borrowernumber + '">';
77
    for(var i=0; i<(max_rank-1); i++){
78
        tr += '<option value="' + (i+1) + '">' + (i+1) + '</option>';
79
    }
80
    tr += '<option selected="selected" value="' + (max_rank) + '">' + (max_rank) + '</option>';
81
    tr += '</select></td>';
82
    tr += '<td><a style="cursor:pointer" onclick="delBorrower('+borrowernumber+');">Delete</a></td>';
83
    tr += '</tr>';
84
    $("#borrowers tbody").append(tr);
85
    $("#ranking"+borrowernumber).change(function(){
86
        reorderBorrower(borrowernumber, $(this).val());
87
    });
88
89
    if(ids.length != 0)
90
        ids += ':';
91
    ids += borrowernumber;
92
    $("#borrowersids").val(ids);
93
94
    $("#borrowers").show();
95
    $("#noborrowersp").hide();
96
97
    return 0;
98
}
99
100
function delBorrower(borrowernumber){
101
    reorderBorrower(borrowernumber, 0);
102
}
103
104
function SearchMember(){
105
    window.open("/cgi-bin/koha/serials/add_user_search.pl",
106
        'PatronPopup',
107
        'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes'
108
    );
109
}
110
111
$(document).ready(function() {
112
    updateTable();
113
});
114
[% END %]
115
116
//]]>
117
</script>
118
</head>
119
120
<body>
121
[% INCLUDE 'header.inc' %]
122
[% INCLUDE 'serials-search.inc' %]
123
124
<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; Routing list</div>
125
126
<div class="main container-fluid">
127
128
<div class="row">
129
  <div class="col-sm-10 col-sm-push-2">
130
    <main>
131
      [% INCLUDE 'serials-toolbar.inc' %]
132
      [% IF ( new ) %]
133
        <h1>Create routing list</h1>
134
135
        <form action="/cgi-bin/koha/serials/routinglist.pl" method="get">
136
          <input type="hidden" name="op" value="savenew" />
137
          <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
138
          <label for="title">Title: </label>
139
          <input type="text" id="title" name="title" />
140
          <input type="submit" value="Save" />
141
        </form>
142
      [% ELSE %]
143
        <h1>Routing list '[% title %]'</h1>
144
        <a style="cursor:pointer" onclick="SearchMember();">Add a borrower</a>
145
        [% IF ( borrowers_loop ) %]
146
          <table id="borrowers">
147
        [% ELSE %]
148
          <table id="borrowers" style="display:none">
149
        [% END %]
150
            <thead>
151
              <tr>
152
                <th>Name</th>
153
                <th>Rank</th>
154
                <th>&nbsp;</th>
155
              </tr>
156
            </thead>
157
            <tbody>
158
              [% FOREACH borrower IN borrowers_loop %]
159
                <tr>
160
                  <td>[% borrower.surname %], [% borrower.firstname %]</td>
161
                  <td>
162
                    <select name="ranking" id="ranking[% borrower.borrowernumber %]">
163
                      [% FOREACH ranking_loo IN borrower.ranking_loop %]
164
                        [% IF ( ranking_loo.selected ) %]
165
                          <option selected="selected" value="[% ranking_loo.rank %]">[% ranking_loo.rank %]</option>
166
                        [% ELSE %]
167
                          <option value="[% ranking_loo.rank %]">[% ranking_loo.rank %]</option>
168
                        [% END %]
169
                      [% END %]
170
                    </select>
171
                  </td>
172
                  <td><a style="cursor:pointer" onclick="delBorrower([% borrower.borrowernumber %]);">Delete</a></td>
173
                </tr>
174
              [% END %]
175
            </tbody>
176
          </table>
177
          [% UNLESS ( borrowers_loop ) %]
178
            <p id="noborrowersp">There are no borrowers in this routing list.</p>
179
          [% END %]
180
          <form action="/cgi-bin/koha/serials/routinglist.pl" method="post">
181
            <input type="hidden" id="borrowersids" name="borrowersids" value="[% borrowersids %]" />
182
            <input type="hidden" name="op" value="mod" />
183
            <input type="hidden" name="routinglistid" value="[% routinglistid %]" />
184
            <div>
185
              <label for="title">Title: </label>
186
              <input type="text" id="title" name="title" value="[% title %]"/>
187
            </div>
188
            <div>
189
              <label for="notes">Notes: </label><br />
190
              <textarea id="notes" name="notes">[% notes %]</textarea><br />
191
            </div>
192
            <input type="submit" value="Save" />
193
            <input type="button" value="Cancel" onclick="window.location.href='/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscriptionid %]';" />
194
          </form>
195
      [% END %]<!-- new -->
196
    </main>
197
  </div>
198
  <div class="col-sm-2 col-sm-pull-10">
199
    <aside>
200
        [% INCLUDE 'serials-menu.inc' %]
201
    </aside>
202
  </div>
203
</div>
204
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt (+71 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Routing lists</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
7
function previewSlip(routinglistid){
8
    window.open("/cgi-bin/koha/serials/routing-preview-slip.pl?routinglistid="+routinglistid, 'PreviewSlip', 'menubar=no,status=no,toolbar=no');
9
}
10
11
function confirmDelete(){
12
    return confirm(_("Are you sure you want to delete this routing list?"));
13
}
14
15
//]]>
16
</script>
17
</head>
18
19
<body>
20
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'serials-search.inc' %]
22
23
<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; Routing lists</div>
24
25
<div class="main container-fluid">
26
27
<div class="row">
28
  <div class="col-sm-10 col-sm-push-2">
29
    <main>
30
      [% INCLUDE 'serials-toolbar.inc' %]
31
      <h1>Routing lists for <em>[% title %]</em></h1>
32
33
      <a href="/cgi-bin/koha/serials/routinglist.pl?op=new&subscriptionid=[% subscriptionid %]">New routing list</a>
34
35
      [% IF ( routinglists_loop ) %]
36
      <table>
37
        <thead>
38
          <tr>
39
            <th>Title</th>
40
            <th>No. of borrowers</th>
41
            <th>Notes</th>
42
            <th>&nbsp;</th>
43
          </tr>
44
        </thead>
45
        <tbody>
46
          [% FOREACH routinglist IN routinglists_loop %]
47
            <tr>
48
              <td><a href="/cgi-bin/koha/serials/routinglist.pl?routinglistid=[% routinglist.routinglistid %]">[% routinglist.title %]</a></td>
49
              <td>[% routinglist.borrowers.size || 0 %]</td>
50
              <td>[% routinglist.notes %]</td>
51
              <td>
52
                <a style="cursor:pointer" onclick="previewSlip([% routinglist.routinglistid %]);">Preview</a> |
53
                <a style="text-decoration:none" href="/cgi-bin/koha/serials/routinglists.pl?op=export&routinglistid=[% routinglist.routinglistid %]">Export</a> |
54
                <a style="text-decoration:none" onclick="return confirmDelete();" href="/cgi-bin/koha/serials/routinglists.pl?op=del&routinglistid=[% routinglist.routinglistid %]">Delete</a></td>
55
            </tr>
56
          [% END %]
57
        </tbody>
58
      </table>
59
      [% ELSE %]
60
        <p>There are no routing lists for this subscription.</p>
61
      [% END %]
62
63
    </main>
64
  </div>
65
  <div class="col-sm-2 col-sm-pull-10">
66
    <aside>
67
      [% INCLUDE 'serials-menu.inc' %]
68
    </aside>
69
  </div>
70
</div>
71
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt (-6 / +6 lines)
Lines 65-74 Link Here
65
        [% IF ( subscription.abouttoexpire ) || ( subscription.subscriptionexpired ) %]<td class="problem actions">[% ELSE %]<td class="actions">[% END %]
65
        [% IF ( subscription.abouttoexpire ) || ( subscription.subscriptionexpired ) %]<td class="problem actions">[% ELSE %]<td class="actions">[% END %]
66
        [% UNLESS subscription.closed %]
66
        [% UNLESS subscription.closed %]
67
            [% IF ( routing && CAN_user_serials_routing ) %]
67
            [% IF ( routing && CAN_user_serials_routing ) %]
68
                [% IF ( subscription.hasRouting ) %]
68
                [% IF ( subscription.routinglistscount ) %]
69
                    <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid | html %]"><i class="fa fa-pencil"></i> Edit routing list</a>
69
                    <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscription.subscriptionid | html %]"><i class="fa fa-pencil"></i> Edit routing list</a>
70
                [% ELSE %]
70
                [% ELSE %]
71
                    <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid | html %]&amp;op=new"><i class="fa fa-plus"></i> Create routing list</a>
71
                    <a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/routinglist.pl?subscriptionid=[% subscription.subscriptionid | html %]&amp;op=new"><i class="fa fa-plus"></i> New routing list</a>
72
                [% END %]
72
                [% END %]
73
            [% END %]
73
            [% END %]
74
            [% IF ( subscription.abouttoexpire ) %]<a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-renew.pl?subscriptionid=[% subscription.subscriptionid | html %]" onclick="popup([% subscription.subscriptionid | html %]); return false;"><i class="fa fa-refresh"></i> Renew</a>
74
            [% IF ( subscription.abouttoexpire ) %]<a class="btn btn-default btn-xs" href="/cgi-bin/koha/serials/subscription-renew.pl?subscriptionid=[% subscription.subscriptionid | html %]" onclick="popup([% subscription.subscriptionid | html %]); return false;"><i class="fa fa-refresh"></i> Renew</a>
Lines 242-248 Link Here
242
                </td>
242
                </td>
243
                [% IF ( routing ) %]
243
                [% IF ( routing ) %]
244
                <td class="actions">
244
                <td class="actions">
245
                    <a href="" onclick="print_slip([% serial.subscriptionid | html %], '[% serial.serialseq.replace("'", "\\'") | html %] ([% serial.publisheddate | $KohaDates %])'); return false" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print list</a>
245
                    <a href="" onclick="print_slip([% serial.serialid | html %]); return false;" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print list</a>
246
                </td>
246
                </td>
247
                [% END %]
247
                [% END %]
248
            </tr>
248
            </tr>
Lines 280-287 Link Here
280
280
281
    <script>
281
    <script>
282
282
283
        function print_slip(subscriptionid,issue){
283
        function print_slip(serialid){
284
            var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
284
            var myurl = '/cgi-bin/koha/serials/routing-preview-slip.pl?serialid=' + serialid;
285
            window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
285
            window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
286
        }
286
        }
287
287
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt (-9 / +7 lines)
Lines 170-184 Link Here
170
                            [% IF ( routing && CAN_user_serials_routing ) %]
170
                            [% IF ( routing && CAN_user_serials_routing ) %]
171
                                [% IF ( subscription.cannotedit ) %]
171
                                [% IF ( subscription.cannotedit ) %]
172
                                [% ELSE %]
172
                                [% ELSE %]
173
                                    [% IF ( subscription.routingedit ) %]
173
                                    <li>
174
                                        <li>
174
                                        [% IF ( subscription.routinglistscount ) %]
175
                                            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid | uri %]"><i class="fa fa-pencil"></i> Edit routing list ([% subscription.routingedit | html %])</a>
175
                                            <a href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscription.subscriptionid | uri %]"><i class="fa fa-pencil"></i> Edit routing list ([% subscription.routinglistscount | html %])</a>
176
                                        </li>
176
                                        [% ELSE %]
177
                                    [% ELSE %]
177
                                            <a href="/cgi-bin/koha/serials/routinglist.pl?subscriptionid=[% subscription.subscriptionid | uri %]&amp;op=new"> <i class="fa fa-plus"></i> New routing list</a>
178
                                        <li>
178
                                        [% END %]
179
                                            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid | uri %]&amp;op=new"> <i class="fa fa-plus"></i> New routing list</a>
179
                                    </li>
180
                                        </li>
181
                                    [% END %]
182
                                [% END %]
180
                                [% END %]
183
                            [% END # IF ( routing && CAN_user_serials_routing ) %]
181
                            [% END # IF ( routing && CAN_user_serials_routing ) %]
184
182
(-)a/serials/reorder_members.pl (-37 lines)
Lines 1-37 Link Here
1
#!/usr/bin/perl
2
# This file is part of Koha.
3
#
4
# Koha is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# Koha is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
# Routing.pl script used to create a routing list for a serial subscription
18
# In this instance it is in fact a setting up of a list of reserves for the item
19
# where the hierarchical order can be changed on the fly and a routing list can be
20
# printed out
21
use Modern::Perl;
22
use CGI qw ( -utf8 );
23
use C4::Auth qw( checkauth );
24
use C4::Serials qw( reorder_members );
25
26
my $query          = CGI->new;
27
my $subscriptionid = $query->param('subscriptionid');
28
my $routingid      = $query->param('routingid');
29
my $rank           = $query->param('rank');
30
31
checkauth( $query, 0, { serials => 'routing' }, 'intranet' );
32
33
reorder_members( $subscriptionid, $routingid, $rank );
34
35
print $query->redirect(
36
    "/cgi-bin/koha/serials/routing.pl?subscriptionid=$subscriptionid");
37
(-)a/serials/routing-preview-slip.pl (+151 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
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
=head1 NAME
20
21
routing-preview-slip.pl
22
23
=head1 DESCRIPTION
24
25
Preview a routing list for printing.
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::Members;
37
use C4::Serials;
38
use C4::Serials::RoutingLists qw/GetRoutingList GetRoutingLists/;
39
40
use Koha::Biblios;
41
use Koha::Patrons;
42
43
my $input = new CGI;
44
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
45
    template_name   => 'serials/routing-preview-slip.tt',
46
    query           => $input,
47
    type            => 'intranet',
48
    authnotrequired => 0,
49
    flagsrequired   => { 'serials' => 'routing' },
50
    debug           => 1,
51
} );
52
53
my $routinglistid = $input->param('routinglistid');
54
my $serialid = $input->param('serialid');
55
56
if (!$routinglistid and !$serialid) {
57
    exit;
58
}
59
60
if (!$routinglistid) {
61
    my $serial = GetSerial($serialid);
62
    my $subscription = GetSubscription($serial->{subscriptionid});
63
    my $biblio = Koha::Biblios->find($subscription->{subscriptionid});
64
    my @routinglists = GetRoutingLists($subscription->{subscriptionid});
65
    $template->param(
66
        missing_parameter_routinglistid => 1,
67
        serialid => $serialid,
68
        title => $biblio->title,
69
        routinglists => \@routinglists
70
    );
71
    output_html_with_http_headers $input, $cookie, $template->output;
72
    exit;
73
} elsif (!$serialid) {
74
    my $routinglist = GetRoutingList($routinglistid);
75
    my $subscription = GetSubscription($routinglist->{subscriptionid});
76
    my $biblio = Koha::Biblios->find($subscription->{subscriptionid});
77
    my @serials = GetSerials2($subscription->{subscriptionid}, [1,2,3,4,5,6,7]);
78
    $template->param(
79
        missing_parameter_serialid => 1,
80
        routinglistid => $routinglistid,
81
        title => $biblio->title,
82
        serials => \@serials
83
    );
84
    output_html_with_http_headers $input, $cookie, $template->output;
85
    exit;
86
}
87
88
my $routinglist = GetRoutingList($routinglistid);
89
my $subscription = GetSubscription($routinglist->{subscriptionid});
90
my $serial = GetSerial($serialid);
91
my $biblio = Koha::Biblios->find($subscription->{biblionumber});
92
my @memberloop;
93
foreach (@{$routinglist->{borrowers}}) {
94
    my $patron = Koha::Patrons->find($_);
95
    push @memberloop, {
96
        surname => $patron->surname,
97
        firstname => $patron->firstname,
98
    };
99
}
100
101
my $no_holds = $input->param('no_holds');
102
if(C4::Context->preference('RoutingListAddReserves') and !$no_holds) {
103
    my $confirm = $input->param('confirm');
104
    if ($confirm) {
105
        require C4::Reserves;
106
        require C4::Items;
107
        my $itemnumber = GetSerialItemnumber($serialid);
108
        my $item = Koha::Items->find($itemnumber);
109
        if ($item) {
110
            my $rank = 1;
111
            foreach my $borrowernumber ( @{$routinglist->{borrowers}} ) {
112
                my @holds = Koha::Holds->search({
113
                    borrowernumber => $borrowernumber,
114
                    biblionumber => $item->biblionumber
115
                });
116
                if (@holds) {
117
                    C4::Reserves::ModReserve({
118
                        rank => $rank,
119
                        biblionumber => $item->biblionumber,
120
                        borrowernumber => $borrowernumber,
121
                        branchcode => $item->holdingbranch,
122
                        itemnumber => $itemnumber,
123
                    });
124
                } else {
125
                    C4::Reserves::AddReserve($item->holdingbranch, $borrowernumber,
126
                        $item->biblionumber, undef, $rank, undef,
127
                        undef, undef, $biblio->title, $itemnumber);
128
                }
129
                $rank++;
130
            }
131
        } else {
132
            $template->param(error_no_item => 1);
133
        }
134
    } else {
135
        $template->param(need_confirm => 1);
136
    }
137
}
138
139
$template->param(
140
    routinglistid   => $routinglistid,
141
    serialid        => $serialid,
142
    branchcode      => $subscription->{branchcode},
143
    title           => $biblio->{title},
144
    serial          => $serial,
145
    memberloop      => \@memberloop,
146
    routingnotes    => $routinglist->{notes},
147
    generalroutingnote  => C4::Context->preference('RoutingListNote'),
148
    routinglisttitle    => $routinglist->{title},
149
);
150
151
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/routing-preview.pl (-144 lines)
Lines 1-144 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
# Routing Preview.pl script used to view a routing list after creation
19
# lets one print out routing slip and create (in this instance) the hierarchy
20
# of reserves for the serial
21
use Modern::Perl;
22
use CGI qw ( -utf8 );
23
use C4::Koha;
24
use C4::Auth;
25
use C4::Output;
26
use C4::Acquisition;
27
use C4::Reserves;
28
use C4::Circulation;
29
use C4::Context;
30
use C4::Members;
31
use C4::Biblio;
32
use C4::Items;
33
use C4::Serials;
34
use URI::Escape;
35
36
use Koha::Biblios;
37
use Koha::Libraries;
38
use Koha::Patrons;
39
40
my $query = new CGI;
41
my $subscriptionid = $query->param('subscriptionid');
42
my $issue = $query->param('issue');
43
my $routingid;
44
my $ok = $query->param('ok');
45
my $edit = $query->param('edit');
46
my $delete = $query->param('delete');
47
my $dbh = C4::Context->dbh;
48
49
if($delete){
50
    delroutingmember($routingid,$subscriptionid);
51
    my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
52
    $sth->execute($subscriptionid);
53
    print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
54
}
55
56
if($edit){
57
    print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
58
}
59
60
my @routinglist = getroutinglist($subscriptionid);
61
my $subs = GetSubscription($subscriptionid);
62
my ($tmp ,@serials) = GetSerials($subscriptionid);
63
my ($template, $loggedinuser, $cookie);
64
65
my $library;
66
if($ok){
67
    # get biblio information....
68
    my $biblionumber = $subs->{'bibnum'};
69
    my @itemresults = GetItemsInfo( $biblionumber );
70
    my $branch = @itemresults ? $itemresults[0]->{'holdingbranch'} : $subs->{branchcode};
71
    $library = Koha::Libraries->find($branch);
72
73
	if (C4::Context->preference('RoutingListAddReserves')){
74
		# get existing reserves .....
75
76
        my $biblio = Koha::Biblios->find( $biblionumber );
77
        my $holds = $biblio->current_holds;
78
        my $count = $holds->count;
79
        while ( my $hold = $holds->next ) {
80
            $count-- if $hold->is_waiting;
81
        }
82
		my $notes;
83
		my $title = $subs->{'bibliotitle'};
84
        for my $routing ( @routinglist ) {
85
            my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
86
            $sth->execute($biblionumber,$routing->{borrowernumber});
87
            my $reserve = $sth->fetchrow_hashref;
88
89
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
90
                ModReserve({
91
                    rank           => $routing->{ranking},
92
                    biblionumber   => $biblionumber,
93
                    borrowernumber => $routing->{borrowernumber},
94
                    branchcode     => $branch
95
                });
96
            } else {
97
                AddReserve($branch,$routing->{borrowernumber},$biblionumber,undef,$routing->{ranking}, undef, undef, $notes,$title);
98
        }
99
    }
100
	}
101
102
    ($template, $loggedinuser, $cookie)
103
= get_template_and_user({template_name => "serials/routing-preview-slip.tt",
104
				query => $query,
105
				type => "intranet",
106
				authnotrequired => 0,
107
				flagsrequired => {serials => '*'},
108
				debug => 1,
109
				});
110
} else {
111
    ($template, $loggedinuser, $cookie)
112
= get_template_and_user({template_name => "serials/routing-preview.tt",
113
				query => $query,
114
				type => "intranet",
115
				authnotrequired => 0,
116
				flagsrequired => {serials => '*'},
117
				debug => 1,
118
				});
119
}
120
121
$template->param( libraryname => $library->branchname ) if $library;
122
123
my $memberloop = [];
124
for my $routing (@routinglist) {
125
    my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
126
    $member->{name}           = "$member->{firstname} $member->{surname}";
127
    push @{$memberloop}, $member;
128
}
129
130
my $routingnotes = $serials[0]->{'routingnotes'};
131
$routingnotes =~ s/\n/\<br \/\>/g;
132
133
$template->param(
134
    title => $subs->{'bibliotitle'},
135
    issue => $issue,
136
    issue_escaped => URI::Escape::uri_escape_utf8($issue),
137
    subscriptionid => $subscriptionid,
138
    memberloop => $memberloop,
139
    routingnotes => $routingnotes,
140
    hasRouting => check_routing($subscriptionid),
141
    (uc(C4::Context->preference("marcflavour"))) => 1
142
    );
143
144
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/serials/routing.pl (-133 lines)
Lines 1-133 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19
=head1 Routing.pl
20
21
script used to create a routing list for a serial subscription
22
In this instance it is in fact a setting up of a list of reserves for the item
23
where the hierarchical order can be changed on the fly and a routing list can be
24
printed out
25
26
=cut
27
28
use Modern::Perl;
29
use CGI qw ( -utf8 );
30
use C4::Koha;
31
use C4::Auth;
32
use C4::Output;
33
use C4::Acquisition;
34
use C4::Output;
35
use C4::Context;
36
37
use C4::Members;
38
use C4::Serials;
39
use Koha::Patrons;
40
41
use URI::Escape;
42
43
my $query = new CGI;
44
my $subscriptionid = $query->param('subscriptionid');
45
my $serialseq = $query->param('serialseq');
46
my $routingid = $query->param('routingid');
47
my $borrowernumber = $query->param('borrowernumber');
48
my $notes = $query->param('notes');
49
my $op = $query->param('op') || q{};
50
my $date_selected = $query->param('date_selected');
51
$date_selected ||= q{};
52
my $dbh = C4::Context->dbh;
53
54
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55
    {
56
        template_name   => 'serials/routing.tt',
57
        query           => $query,
58
        type            => 'intranet',
59
        authnotrequired => 0,
60
        flagsrequired   => { serials => 'routing' },
61
    }
62
);
63
64
my $subs = GetSubscription($subscriptionid);
65
66
output_and_exit( $query, $cookie, $template, 'unknown_subscription')
67
    unless $subs;
68
69
if($op eq 'delete'){
70
    delroutingmember($routingid,$subscriptionid);
71
}
72
73
if($op eq 'add'){
74
    addroutingmember($borrowernumber,$subscriptionid);
75
}
76
if($op eq 'save'){
77
    my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
78
    $sth->execute($notes,$subscriptionid);
79
    my $urldate = URI::Escape::uri_escape_utf8($date_selected);
80
    print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
81
}
82
83
my @routinglist = getroutinglist($subscriptionid);
84
85
my ($count,@serials) = GetSerials($subscriptionid);
86
my $serialdates = GetLatestSerials($subscriptionid,$count);
87
88
my $dates = [];
89
foreach my $dateseq (@{$serialdates}) {
90
    my $d = {};
91
    $d->{publisheddate} = $dateseq->{publisheddate};
92
    $d->{serialseq} = $dateseq->{serialseq};
93
    $d->{serialid} = $dateseq->{serialid};
94
    if($date_selected eq $dateseq->{serialid}){
95
        $d->{selected} = ' selected';
96
    } else {
97
        $d->{selected} = q{};
98
    }
99
    push @{$dates}, $d;
100
}
101
102
my $member_loop = [];
103
for my $routing ( @routinglist ) {
104
    my $member = Koha::Patrons->find( $routing->{borrowernumber} )->unblessed;
105
    $member->{location} = $member->{branchcode};
106
    if ($member->{firstname} ) {
107
        $member->{name} = $member->{firstname} . q| |;
108
    }
109
    else {
110
        $member->{name} = q{};
111
    }
112
    if ($member->{surname} ) {
113
        $member->{name} .= $member->{surname};
114
    }
115
    $member->{routingid}=$routing->{routingid} || q{};
116
    $member->{ranking} = $routing->{ranking} || q{};
117
118
    push(@{$member_loop}, $member);
119
}
120
121
$template->param(
122
    title => $subs->{bibliotitle},
123
    subscriptionid => $subscriptionid,
124
    memberloop => $member_loop,
125
    op => $op eq 'new',
126
    dates => $dates,
127
    routingnotes => $serials[0]->{'routingnotes'},
128
    hasRouting => check_routing($subscriptionid),
129
    (uc(C4::Context->preference("marcflavour"))) => 1
130
131
    );
132
133
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/serials/routinglist.pl (+120 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
=head1 NAME
20
21
routinglist.pl
22
23
=head1 DESCRIPTION
24
25
Create or modify a routing list
26
27
=cut
28
29
use Modern::Perl;
30
31
use CGI;
32
use C4::Auth;
33
use C4::Output;
34
35
use C4::Members;
36
use C4::Serials;
37
use C4::Serials::RoutingLists qw/AddRoutingList ModRoutingList GetRoutingList/;
38
39
use Koha::Patrons;
40
41
my $input = new CGI;
42
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
43
    template_name   => 'serials/routinglist.tt',
44
    query           => $input,
45
    type            => 'intranet',
46
    authnotrequired => 0,
47
    flagsrequired   => { serials => 'routing' },
48
    debug           => 1,
49
} );
50
51
my $op = $input->param('op');
52
my $routinglistid;
53
54
if($op && $op eq 'new') {
55
    my $subscriptionid = $input->param('subscriptionid');
56
    $template->param(
57
        new => 1,
58
        subscriptionid => $subscriptionid,
59
    );
60
    output_html_with_http_headers $input, $cookie, $template->output;
61
    exit;
62
}
63
64
if($op && $op eq 'savenew') {
65
    my $title = $input->param('title');
66
    my $subscriptionid = $input->param('subscriptionid');
67
68
    $routinglistid = AddRoutingList($subscriptionid, $title);
69
    print $input->redirect('/cgi-bin/koha/serials/routinglist.pl?routinglistid='
70
        . $routinglistid);
71
    exit;
72
} else {
73
    $routinglistid = $input->param('routinglistid');
74
}
75
76
if($op && $op eq 'mod') {
77
    my $borrowersids = $input->param('borrowersids');
78
    my $title = $input->param('title');
79
    my $notes = $input->param('notes');
80
    my @borrowernumbers = split /:/, $borrowersids;
81
    ModRoutingList($routinglistid, undef, $title, $notes, @borrowernumbers);
82
    my $routinglist = GetRoutingList($routinglistid);
83
    print $input->redirect("/cgi-bin/koha/serials/routinglists.pl?subscriptionid=".$routinglist->{'subscriptionid'});
84
    exit;
85
}
86
87
my $routinglist = GetRoutingList($routinglistid);
88
my @borrowers;
89
my $rank = 1;
90
foreach my $borrowernumber (@{$routinglist->{borrowers}}) {
91
    my @ranking_loop;
92
    for(my $i = 0 ; $i < scalar(@{$routinglist->{borrowers}}) ; $i++){
93
        my $selected = 0;
94
        $selected = 1 if ($rank == $i+1);
95
        push @ranking_loop, {
96
            rank => $i+1,
97
            selected => $selected,
98
        };
99
    }
100
    my $patron = Koha::Patrons->find($borrowernumber);
101
    push @borrowers, {
102
        borrowernumber => $borrowernumber,
103
        surname => $patron->surname,
104
        firstname => $patron->firstname,
105
        ranking_loop => \@ranking_loop
106
    };
107
    $rank ++;
108
}
109
110
$template->param(
111
    borrowers_loop => \@borrowers,
112
    borrowersids => join(':', map ($_->{borrowernumber}, @borrowers)),
113
    max_rank => scalar(@borrowers),
114
    title => $routinglist->{title},
115
    notes => $routinglist->{notes},
116
    subscriptionid => $routinglist->{subscriptionid},
117
    routinglistid => $routinglistid,
118
);
119
120
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/routinglists.pl (+81 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
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
=head1 NAME
20
21
routinglists.pl
22
23
=head1 DESCRIPTION
24
25
View all routing lists for a subscription
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::Serials;
37
use C4::Serials::RoutingLists qw/GetRoutingLists GetRoutingList DelRoutingList GetRoutingListAsCSV/;
38
39
use Koha::Biblios;
40
41
my $input = new CGI;
42
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
43
    template_name   => 'serials/routinglists.tt',
44
    query           => $input,
45
    type            => 'intranet',
46
    authnotrequired => 0,
47
    flagsrequired   => { serials => 'routing' },
48
    debug           => 1,
49
} );
50
51
my $subscriptionid = $input->param('subscriptionid');
52
my $op = $input->param('op');
53
54
if($op && $op eq "export") {
55
    my $routinglistid = $input->param('routinglistid');
56
    print $input->header(
57
        -type       => 'text/csv',
58
        -attachment => 'routinglist' . $routinglistid . '.csv',
59
    );
60
    print GetRoutingListAsCSV($routinglistid);
61
    exit;
62
} elsif($op && $op eq "del") {
63
    my $routinglistid = $input->param('routinglistid');
64
    if(!defined $subscriptionid){
65
        my $routinglist = GetRoutingList($routinglistid);
66
        $subscriptionid = $routinglist->{subscriptionid};
67
    }
68
    DelRoutingList($routinglistid);
69
}
70
71
my $subscription = GetSubscription($subscriptionid);
72
my $biblio = Koha::Biblios->find($subscription->{biblionumber});
73
my @routinglists = GetRoutingLists($subscriptionid);
74
75
$template->param(
76
    subscriptionid => $subscriptionid,
77
    routinglists_loop => \@routinglists,
78
    title => $biblio->title,
79
);
80
81
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/serials-collection.pl (-6 / +8 lines)
Lines 24-29 use CGI qw ( -utf8 ); Link Here
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Koha;
25
use C4::Koha;
26
use C4::Serials;
26
use C4::Serials;
27
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
27
use C4::Letters;
28
use C4::Letters;
28
use C4::Output;
29
use C4::Output;
29
use C4::Context;
30
use C4::Context;
Lines 59-65 if($op eq 'gennext' && @subscriptionid){ Link Here
59
    my $subscriptionid = $subscriptionid[0];
60
    my $subscriptionid = $subscriptionid[0];
60
    my $sth = $dbh->prepare("
61
    my $sth = $dbh->prepare("
61
        SELECT publisheddate, publisheddatetext, serialid, serialseq,
62
        SELECT publisheddate, publisheddatetext, serialid, serialseq,
62
            planneddate, notes, routingnotes
63
            planneddate, notes
63
        FROM serial
64
        FROM serial
64
        WHERE status = 1 AND subscriptionid = ?
65
        WHERE status = 1 AND subscriptionid = ?
65
    ");
66
    ");
Lines 91-97 if($op eq 'gennext' && @subscriptionid){ Link Here
91
             ## Creating the new issue
92
             ## Creating the new issue
92
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
93
             NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
93
                     1, $planneddate, $nextpublisheddate, undef,
94
                     1, $planneddate, $nextpublisheddate, undef,
94
                     $issue->{notes}, $issue->{routingnotes} );
95
                     $issue->{notes} );
95
96
96
             ## Updating the subscription seq status
97
             ## Updating the subscription seq status
97
             my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
98
             my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
Lines 130-136 if (@subscriptionid){ Link Here
130
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
131
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
131
    $subs->{frequency} = $frequency;
132
    $subs->{frequency} = $frequency;
132
    $subs->{numberpattern} = $numberpattern;
133
    $subs->{numberpattern} = $numberpattern;
133
    $subs->{'hasRouting'} = check_routing($subscriptionid);
134
    $subs->{'hasRouting'} = GetRoutingListsCount($subscriptionid);
134
    push @$subscriptiondescs,$subs;
135
    push @$subscriptiondescs,$subs;
135
    my $tmpsubscription= GetFullSubscription($subscriptionid);
136
    my $tmpsubscription= GetFullSubscription($subscriptionid);
136
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
137
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
Lines 158-166 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1) Link Here
158
my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
159
my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
159
my $subscriptionidlist="";
160
my $subscriptionidlist="";
160
foreach my $subscription (@$subscriptiondescs){
161
foreach my $subscription (@$subscriptiondescs){
161
  $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
162
    $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
162
  $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
163
    $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
163
  $subscription->{'hasRouting'} = check_routing($subscription->{'subscriptionid'});
164
    $subscription->{routinglistscount}
165
        = GetRoutingListsCount($subscription->{subscriptionid});
164
}
166
}
165
167
166
chop $subscriptionidlist;
168
chop $subscriptionidlist;
(-)a/serials/serials-edit.pl (-1 lines)
Lines 239-245 if ( $op and $op eq 'serialchangestatus' ) { Link Here
239
                    $pub_date,
239
                    $pub_date,
240
                    $publisheddatetexts[$i],
240
                    $publisheddatetexts[$i],
241
                    $notes[$i],
241
                    $notes[$i],
242
                    $serialdatalist[0]->{'routingnotes'}
243
                );
242
                );
244
            }
243
            }
245
        }
244
        }
(-)a/serials/serials-search.pl (-1 / +2 lines)
Lines 36-41 use C4::Koha qw( GetAuthorisedValues ); Link Here
36
use C4::Output;
36
use C4::Output;
37
use C4::Serials;
37
use C4::Serials;
38
use Koha::AdditionalFields;
38
use Koha::AdditionalFields;
39
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
39
40
40
use Koha::DateUtils;
41
use Koha::DateUtils;
41
use Koha::SharedContent;
42
use Koha::SharedContent;
Lines 151-157 else Link Here
151
    # to toggle between create or edit routing list options
152
    # to toggle between create or edit routing list options
152
    if ($routing) {
153
    if ($routing) {
153
        for my $subscription ( @subscriptions) {
154
        for my $subscription ( @subscriptions) {
154
            $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
155
            $subscription->{routinglistscount} = GetRoutingListsCount($subscription->{subscriptionid});
155
        }
156
        }
156
    }
157
    }
157
158
(-)a/serials/subscription-detail.pl (-1 / +2 lines)
Lines 22-27 use C4::Auth; Link Here
22
use C4::Budgets;
22
use C4::Budgets;
23
use C4::Koha;
23
use C4::Koha;
24
use C4::Serials;
24
use C4::Serials;
25
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
25
use C4::Output;
26
use C4::Output;
26
use C4::Context;
27
use C4::Context;
27
use C4::Search qw/enabled_staff_search_views/;
28
use C4::Search qw/enabled_staff_search_views/;
Lines 107-113 elsif ( $op and $op eq "share" ) { Link Here
107
    $subs->{mana_id} = $result->{id};
108
    $subs->{mana_id} = $result->{id};
108
}
109
}
109
110
110
my $hasRouting = check_routing($subscriptionid);
111
my $hasRouting = GetRoutingListsCount($subscriptionid);
111
112
112
(undef, $cookie, undef, undef)
113
(undef, $cookie, undef, undef)
113
    = checkauth($query, 0, {catalogue => 1}, "intranet");
114
    = checkauth($query, 0, {catalogue => 1}, "intranet");
(-)a/t/db_dependent/Serials.t (-9 / +40 lines)
Lines 18-24 use Koha::DateUtils; Link Here
18
use Koha::Acquisition::Booksellers;
18
use Koha::Acquisition::Booksellers;
19
use t::lib::Mocks;
19
use t::lib::Mocks;
20
use t::lib::TestBuilder;
20
use t::lib::TestBuilder;
21
use Test::More tests => 49;
21
use Test::More tests => 48;
22
22
23
BEGIN {
23
BEGIN {
24
    use_ok('C4::Serials');
24
    use_ok('C4::Serials');
Lines 163-169 subtest 'Values should not be erased on editing' => sub { Link Here
163
    );
163
    );
164
    my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
164
    my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
165
    my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber,
165
    my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber,
166
                                          1, undef, undef, "publisheddatetext", "notes", "routingnotes" );
166
                                          1, undef, undef, "publisheddatetext", "notes" );
167
    C4::Serials::AddItem2Serial( $serialid, $itemnumber );
167
    C4::Serials::AddItem2Serial( $serialid, $itemnumber );
168
    my $serial_info = C4::Serials::GetSerialInformation($serialid);
168
    my $serial_info = C4::Serials::GetSerialInformation($serialid);
169
    my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' }
169
    my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' }
Lines 282-294 subtest 'test_updateClaim' => sub { Link Here
282
    is($late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim');
282
    is($late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim');
283
};
283
};
284
284
285
is(C4::Serials::check_routing(), undef, 'test checking route');
286
is(C4::Serials::check_routing($subscriptionid), 0, 'There should not have any routing list for the subscription');
287
# TODO really test this check_routing subroutine
288
289
is(C4::Serials::addroutingmember(),undef, 'test adding route member');
290
291
292
# Unit tests for statuses management (Bug 11689)
285
# Unit tests for statuses management (Bug 11689)
293
$subscriptionid = NewSubscription(
286
$subscriptionid = NewSubscription(
294
    undef,      "",     undef, undef, $budget_id, $biblionumber,
287
    undef,      "",     undef, undef, $budget_id, $biblionumber,
Lines 400-402 subtest "NewSubscription" => sub { Link Here
400
    );
393
    );
401
    ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface");
394
    ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface");
402
};
395
};
396
397
subtest 'GetSerial' => sub {
398
    plan tests => 6;
399
400
    my $serial;
401
402
    $serial = GetSerial;
403
    ok(not (defined $serial), 'GetSerial() returns undef');
404
405
    $serial = GetSerial(-1);
406
    ok(not (defined $serial), 'GetSerial(-1) returns undef');
407
408
    my ($total_issues, @serials) = C4::Serials::GetSerials( $subscriptionid );
409
    $serial = GetSerial($serials[0]->{serialid});
410
    is($serial->{serialid}, $serials[0]->{serialid}, 'serialid is ok');
411
    is($serial->{serialseq}, $serials[0]->{serialseq}, 'serialseq is ok');
412
    is($serial->{status}, $serials[0]->{status}, 'status is ok');
413
    is($serial->{notes}, $serials[0]->{notes}, 'notes is ok');
414
};
415
416
subtest 'GetSerialItemnumber' => sub {
417
    plan tests => 3;
418
419
    my $itemnumber;
420
421
    $itemnumber = GetSerialItemnumber;
422
    ok(not (defined $itemnumber), 'GetSerialItemnumber() returns undef');
423
424
    $itemnumber = GetSerialItemnumber(-1);
425
    ok(not (defined $itemnumber), 'GetSerialItemnumber(-1) returns undef');
426
427
    my $item_itemnumber = C4::Items::AddItem({}, $biblionumber);
428
    my ($total_issues, @serials) = C4::Serials::GetSerials( $subscriptionid );
429
    AddItem2Serial($serials[0]->{serialid}, $item_itemnumber);
430
    $itemnumber = GetSerialItemnumber($serials[0]->{serialid});
431
    is($itemnumber, $item_itemnumber,
432
        'GetSerialItemnumber($serialid) returns itemnumber');
433
};
(-)a/t/db_dependent/Serials/RoutingLists.t (-1 / +240 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 7;
6
7
use C4::Serials;
8
use C4::Serials::RoutingLists;
9
10
use C4::Biblio;
11
use C4::Members;
12
13
use Koha::Database;
14
15
my $dbh = C4::Context->dbh;
16
$dbh->{AutoCommit} = 0;
17
18
my $record = MARC::Record->new;
19
my $field = C4::Context->preference('marcflavour') eq 'UNIMARC'
20
    ? MARC::Field->new(200, '', '', a => 'Title')
21
    : MARC::Field->new(245, '', '', a => 'Title');
22
$record->append_fields($field);
23
my ($biblionumber) = AddBiblio($record, '');
24
25
my $subscriptionid = C4::Serials::NewSubscription(undef, '', (undef)x3,
26
    $biblionumber, '2015-04-23', (undef)x10, '', '', (undef)x6, 0, '', 0,
27
    undef, undef, 0, undef, undef, 0);
28
29
my $schema = Koha::Database->new->schema;
30
my $categorycode = $schema->resultset('Category')->search->first->categorycode;
31
my $branchcode = $schema->resultset('Branch')->search->first->branchcode;
32
33
my $borrowernumber1 = C4::Members::AddMember(
34
    surname => 'Doe',
35
    firstname => 'John',
36
    categorycode => $categorycode,
37
    branchcode => $branchcode,
38
);
39
my $borrowernumber2 = C4::Members::AddMember(
40
    surname => 'Smith',
41
    firstname => 'Jane',
42
    categorycode => $categorycode,
43
    branchcode => $branchcode,
44
);
45
46
subtest 'AddRoutingList' => sub {
47
    plan tests => 9;
48
49
    my $routinglistid;
50
51
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList;
52
    ok(not (defined $routinglistid),
53
        'AddRoutingList with bad parameters should return undef');
54
55
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList(-1);
56
    ok(not (defined $routinglistid),
57
        'AddRoutingList with bad parameters should return undef');
58
59
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid);
60
    ok(not (defined $routinglistid),
61
        'AddRoutingList with bad parameters should return undef');
62
63
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, '');
64
    ok(not (defined $routinglistid),
65
        'AddRoutingList with bad parameters should return undef');
66
67
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
68
    ok((defined $routinglistid),
69
        'AddRoutingList with good parameters should return an id');
70
71
    my $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
72
    is($routinglist->{routinglistid}, $routinglistid,
73
        'new routing list id is ok');
74
    is($routinglist->{subscriptionid}, $subscriptionid,
75
        'new routing list subscriptionid is ok');
76
    is($routinglist->{title},
77
        'Title', 'new routing list title is ok');
78
    ok(not (defined $routinglist->{notes}),
79
        'new routing list has not notes');
80
};
81
82
subtest 'ModRoutingList' => sub {
83
    plan tests => 5;
84
85
    my ($routinglist, $expected);
86
87
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
88
89
    C4::Serials::RoutingLists::ModRoutingList($routinglistid);
90
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
91
    $expected = {
92
        routinglistid => $routinglistid,
93
        subscriptionid => $subscriptionid,
94
        title => 'Title',
95
        notes => undef,
96
    };
97
    is_deeply($routinglist, $expected, 'routing list is as expected');
98
99
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, 'Title 2');
100
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
101
    $expected = {
102
        routinglistid => $routinglistid,
103
        subscriptionid => $subscriptionid,
104
        title => 'Title 2',
105
        notes => undef,
106
    };
107
    is_deeply($routinglist, $expected, 'routing list is as expected');
108
109
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef, 'notes');
110
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
111
    $expected = {
112
        routinglistid => $routinglistid,
113
        subscriptionid => $subscriptionid,
114
        title => 'Title 2',
115
        notes => 'notes',
116
    };
117
    is_deeply($routinglist, $expected, 'routing list is as expected');
118
119
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
120
        undef, $borrowernumber1, $borrowernumber2);
121
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
122
    $expected = {
123
        routinglistid => $routinglistid,
124
        subscriptionid => $subscriptionid,
125
        title => 'Title 2',
126
        notes => 'notes',
127
        borrowers => [$borrowernumber1, $borrowernumber2],
128
    };
129
    is_deeply($routinglist, $expected, 'routing list is as expected');
130
131
    C4::Serials::RoutingLists::ModRoutingList($routinglistid);
132
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
133
    $expected = {
134
        routinglistid => $routinglistid,
135
        subscriptionid => $subscriptionid,
136
        title => 'Title 2',
137
        notes => 'notes',
138
    };
139
    is_deeply($routinglist, $expected, 'routing list is as expected');
140
};
141
142
subtest 'DelRoutingList' => sub {
143
    plan tests => 1;
144
145
    my $routinglist;
146
147
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
148
    C4::Serials::RoutingLists::DelRoutingList($routinglistid);
149
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
150
    ok(not (defined $routinglist), 'routing list is deleted');
151
};
152
153
subtest 'GetRoutingList' => sub {
154
    plan tests => 3;
155
156
    my $routinglist;
157
158
    $routinglist = C4::Serials::RoutingLists::GetRoutingList;
159
    ok (not (defined $routinglist), 'GetRoutingList() returns undef');
160
161
    $routinglist = C4::Serials::RoutingLists::GetRoutingList(-1);
162
    ok (not (defined $routinglist), 'GetRoutingList(-1) returns undef');
163
164
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'Title');
165
    $routinglist = C4::Serials::RoutingLists::GetRoutingList($routinglistid);
166
    ok ((defined $routinglist), 'GetRoutingList($routinglistid) returns undef');
167
};
168
169
subtest 'GetRoutingLists' => sub {
170
    plan tests => 4;
171
172
    my (@routinglists, $routinglistid);
173
174
    # Remove routing lists from previous tests
175
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
176
    foreach my $routinglist (@routinglists) {
177
        C4::Serials::RoutingLists::DelRoutingList($routinglist->{routinglistid});
178
    }
179
180
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists;
181
    is(scalar @routinglists, 0, 'GetRoutingLists() returns an empty list');
182
183
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
184
    is(scalar @routinglists, 0,
185
        'GetRoutingLists($subscriptionid) returns an empty list');
186
187
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 1');
188
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
189
        undef, $borrowernumber1);
190
    $routinglistid = C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 2');
191
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
192
        undef, $borrowernumber1);
193
    @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
194
    is(scalar @routinglists, 2,
195
        'GetRoutingLists($subscriptionid) returns all routing lists');
196
    is_deeply($routinglists[0]->{borrowers}, [$borrowernumber1],
197
        'GetRoutingLists returns borrower list for each routing list');
198
};
199
200
subtest 'GetRoutingListsCount' => sub {
201
    plan tests => 3;
202
203
    my $count;
204
205
    # Remove routing lists from previous tests
206
    my @routinglists = C4::Serials::RoutingLists::GetRoutingLists($subscriptionid);
207
    foreach my $routinglist (@routinglists) {
208
        C4::Serials::RoutingLists::DelRoutingList($routinglist->{routinglistid});
209
    }
210
211
    $count = C4::Serials::RoutingLists::GetRoutingListsCount;
212
    is($count, undef, 'GetRoutingListsCount() returns undef');
213
214
    $count = C4::Serials::RoutingLists::GetRoutingListsCount($subscriptionid);
215
    is($count, 0, 'GetRoutingListsCount($subscriptionid) returns 0');
216
217
    C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 1');
218
    C4::Serials::RoutingLists::AddRoutingList($subscriptionid, 'list 2');
219
    $count = C4::Serials::RoutingLists::GetRoutingListsCount($subscriptionid);
220
    is($count, 2, 'GetRoutingListsCount($subscriptionid) returns 2');
221
};
222
223
subtest 'GetRoutingListAsCSV' => sub {
224
    plan tests => 1;
225
226
    my $routinglistid = C4::Serials::RoutingLists::AddRoutingList(
227
        $subscriptionid, 'list 1');
228
229
    C4::Serials::RoutingLists::ModRoutingList($routinglistid, undef, undef,
230
        'notes', $borrowernumber1, $borrowernumber2);
231
232
    my $csv = C4::Serials::RoutingLists::GetRoutingListAsCSV($routinglistid);
233
    my $expected =
234
        q|"Subscription title","Routing list",Surname,Firstname,Notes| . "\n"
235
        . q|Title,"list 1",Doe,John,notes| . "\n"
236
        . q|Title,"list 1",Smith,Jane,notes| . "\n";
237
    is($csv, $expected, 'csv is as expected');
238
};
239
240
$dbh->rollback;

Return to bug 7957