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

(-)a/C4/Items.pm (-1 / +1 lines)
Lines 176-182 sub GetItem { Link Here
176
	#if we don't have an items.itype, use biblioitems.itemtype.
176
	#if we don't have an items.itype, use biblioitems.itemtype.
177
    # FIXME this should respect the itypes systempreference
177
    # FIXME this should respect the itypes systempreference
178
    # if (C4::Context->preference('item-level_itypes')) {
178
    # if (C4::Context->preference('item-level_itypes')) {
179
	if( ! $data->{'itype'} ) {
179
	if( $data and ! $data->{'itype'} ) {
180
		my $sth = $dbh->prepare("SELECT itemtype FROM biblioitems  WHERE biblionumber = ?");
180
		my $sth = $dbh->prepare("SELECT itemtype FROM biblioitems  WHERE biblionumber = ?");
181
		$sth->execute($data->{'biblionumber'});
181
		$sth->execute($data->{'biblionumber'});
182
		($data->{'itype'}) = $sth->fetchrow_array;
182
		($data->{'itype'}) = $sth->fetchrow_array;
(-)a/C4/Serials.pm (-172 / +66 lines)
Lines 73-85 BEGIN { Link Here
73
      &ReNewSubscription  &GetLateOrMissingIssues
73
      &ReNewSubscription  &GetLateOrMissingIssues
74
      &GetSerialInformation                   &AddItem2Serial
74
      &GetSerialInformation                   &AddItem2Serial
75
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
75
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
76
      &GetSerial &GetSerialItemnumber
76
77
77
      &UpdateClaimdateIssues
78
      &UpdateClaimdateIssues
78
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
79
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
79
      &GetDistributedTo   &SetDistributedTo
80
      &GetDistributedTo   &SetDistributedTo
80
      &getroutinglist     &delroutingmember   &addroutingmember
81
      &updateClaim
81
      &reorder_members
82
      &check_routing &updateClaim
83
      &CountIssues
82
      &CountIssues
84
      HasItems
83
      HasItems
85
      &GetSubscriptionsFromBorrower
84
      &GetSubscriptionsFromBorrower
Lines 160-165 sub GetSubscriptionHistoryFromSubscriptionId { Link Here
160
    return $results;
159
    return $results;
161
}
160
}
162
161
162
=head2 GetSerial
163
164
    my $serial = &GetSerial($serialid);
165
166
This sub returns serial informations (ie. in serial table) for given $serialid
167
It returns a hashref where each key is a sql column.
168
169
=cut
170
171
sub GetSerial {
172
    my ($serialid) = @_;
173
174
    return unless $serialid;
175
176
    my $dbh = C4::Context->dbh;
177
    my $query = qq{
178
        SELECT *
179
        FROM serial
180
        WHERE serialid = ?
181
    };
182
    my $sth = $dbh->prepare($query);
183
    $sth->execute($serialid);
184
    return $sth->fetchrow_hashref;
185
}
186
187
=head2 GetSerialItemnumber
188
189
    my $itemnumber = GetSerialItemnumber($serialid);
190
191
Returns the itemnumber associated to $serialid or undef if there is no item.
192
193
=cut
194
195
sub GetSerialItemnumber {
196
    my ($serialid) = @_;
197
198
    return unless $serialid;
199
    my $itemnumber;
200
201
    my $dbh = C4::Context->dbh;
202
    my $query = qq{
203
        SELECT itemnumber
204
        FROM serialitems
205
        WHERE serialid = ?
206
    };
207
    my $sth = $dbh->prepare($query);
208
    my $rv = $sth->execute($serialid);
209
    if ($rv) {
210
        my $result = $sth->fetchrow_hashref;
211
        $itemnumber = $result->{itemnumber};
212
    }
213
    return $itemnumber;
214
}
215
163
=head2 GetSerialStatusFromSerialId
216
=head2 GetSerialStatusFromSerialId
164
217
165
$sth = GetSerialStatusFromSerialId();
218
$sth = GetSerialStatusFromSerialId();
Lines 662-668 sub GetSerials { Link Here
662
    $count = 5 unless ($count);
715
    $count = 5 unless ($count);
663
    my @serials;
716
    my @serials;
664
    my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) );
717
    my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) );
665
    my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes, routingnotes
718
    my $query = "SELECT serialid,serialseq, status, publisheddate, planneddate,notes
666
                        FROM   serial
719
                        FROM   serial
667
                        WHERE  subscriptionid = ? AND status NOT IN ( $statuses )
720
                        WHERE  subscriptionid = ? AND status NOT IN ( $statuses )
668
                        ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC";
721
                        ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC";
Lines 682-688 sub GetSerials { Link Here
682
    }
735
    }
683
736
684
    # OK, now add the last 5 issues arrives/missing
737
    # OK, now add the last 5 issues arrives/missing
685
    $query = "SELECT   serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes
738
    $query = "SELECT   serialid,serialseq, status, planneddate, publisheddate,notes
686
       FROM     serial
739
       FROM     serial
687
       WHERE    subscriptionid = ?
740
       WHERE    subscriptionid = ?
688
       AND      status IN ( $statuses )
741
       AND      status IN ( $statuses )
Lines 731-737 sub GetSerials2 { Link Here
731
784
732
    my $dbh   = C4::Context->dbh;
785
    my $dbh   = C4::Context->dbh;
733
    my $query = qq|
786
    my $query = qq|
734
                 SELECT   serialid,serialseq, status, planneddate, publisheddate,notes, routingnotes
787
                 SELECT   serialid,serialseq, status, planneddate, publisheddate,notes
735
                 FROM     serial 
788
                 FROM     serial 
736
                 WHERE    subscriptionid=$subscription AND status IN ($statuses_string)
789
                 WHERE    subscriptionid=$subscription AND status IN ($statuses_string)
737
                 ORDER BY publisheddate,serialid DESC
790
                 ORDER BY publisheddate,serialid DESC
Lines 1990-2150 sub getsupplierbyserialid { Link Here
1990
    return $result;
2043
    return $result;
1991
}
2044
}
1992
2045
1993
=head2 check_routing
1994
1995
$result = &check_routing($subscriptionid)
1996
1997
this function checks to see if a serial has a routing list and returns the count of routingid
1998
used to show either an 'add' or 'edit' link
1999
2000
=cut
2001
2002
sub check_routing {
2003
    my ($subscriptionid) = @_;
2004
2005
    return unless ($subscriptionid);
2006
2007
    my $dbh              = C4::Context->dbh;
2008
    my $sth              = $dbh->prepare(
2009
        "SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist 
2010
                              ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
2011
                              WHERE subscription.subscriptionid = ? ORDER BY ranking ASC
2012
                              "
2013
    );
2014
    $sth->execute($subscriptionid);
2015
    my $line   = $sth->fetchrow_hashref;
2016
    my $result = $line->{'routingids'};
2017
    return $result;
2018
}
2019
2020
=head2 addroutingmember
2021
2022
addroutingmember($borrowernumber,$subscriptionid)
2023
2024
this function takes a borrowernumber and subscriptionid and adds the member to the
2025
routing list for that serial subscription and gives them a rank on the list
2026
of either 1 or highest current rank + 1
2027
2028
=cut
2029
2030
sub addroutingmember {
2031
    my ( $borrowernumber, $subscriptionid ) = @_;
2032
2033
    return unless ($borrowernumber and $subscriptionid);
2034
2035
    my $rank;
2036
    my $dbh = C4::Context->dbh;
2037
    my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" );
2038
    $sth->execute($subscriptionid);
2039
    while ( my $line = $sth->fetchrow_hashref ) {
2040
        if ( $line->{'rank'} > 0 ) {
2041
            $rank = $line->{'rank'} + 1;
2042
        } else {
2043
            $rank = 1;
2044
        }
2045
    }
2046
    $sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" );
2047
    $sth->execute( $subscriptionid, $borrowernumber, $rank );
2048
}
2049
2050
=head2 reorder_members
2051
2052
reorder_members($subscriptionid,$routingid,$rank)
2053
2054
this function is used to reorder the routing list
2055
2056
it takes the routingid of the member one wants to re-rank and the rank it is to move to
2057
- it gets all members on list puts their routingid's into an array
2058
- removes the one in the array that is $routingid
2059
- then reinjects $routingid at point indicated by $rank
2060
- then update the database with the routingids in the new order
2061
2062
=cut
2063
2064
sub reorder_members {
2065
    my ( $subscriptionid, $routingid, $rank ) = @_;
2066
    my $dbh = C4::Context->dbh;
2067
    my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" );
2068
    $sth->execute($subscriptionid);
2069
    my @result;
2070
    while ( my $line = $sth->fetchrow_hashref ) {
2071
        push( @result, $line->{'routingid'} );
2072
    }
2073
2074
    # To find the matching index
2075
    my $i;
2076
    my $key = -1;    # to allow for 0 being a valid response
2077
    for ( $i = 0 ; $i < @result ; $i++ ) {
2078
        if ( $routingid == $result[$i] ) {
2079
            $key = $i;    # save the index
2080
            last;
2081
        }
2082
    }
2083
2084
    # if index exists in array then move it to new position
2085
    if ( $key > -1 && $rank > 0 ) {
2086
        my $new_rank = $rank - 1;                       # $new_rank is what you want the new index to be in the array
2087
        my $moving_item = splice( @result, $key, 1 );
2088
        splice( @result, $new_rank, 0, $moving_item );
2089
    }
2090
    for ( my $j = 0 ; $j < @result ; $j++ ) {
2091
        my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" );
2092
        $sth->execute;
2093
    }
2094
    return;
2095
}
2096
2097
=head2 delroutingmember
2098
2099
delroutingmember($routingid,$subscriptionid)
2100
2101
this function either deletes one member from routing list if $routingid exists otherwise
2102
deletes all members from the routing list
2103
2104
=cut
2105
2106
sub delroutingmember {
2107
2108
    # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid
2109
    my ( $routingid, $subscriptionid ) = @_;
2110
    my $dbh = C4::Context->dbh;
2111
    if ($routingid) {
2112
        my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?");
2113
        $sth->execute($routingid);
2114
        reorder_members( $subscriptionid, $routingid );
2115
    } else {
2116
        my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?");
2117
        $sth->execute($subscriptionid);
2118
    }
2119
    return;
2120
}
2121
2122
=head2 getroutinglist
2123
2124
@routinglist = getroutinglist($subscriptionid)
2125
2126
this gets the info from the subscriptionroutinglist for $subscriptionid
2127
2128
return :
2129
the routinglist as an array. Each element of the array contains a hash_ref containing
2130
routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription
2131
2132
=cut
2133
2134
sub getroutinglist {
2135
    my ($subscriptionid) = @_;
2136
    my $dbh              = C4::Context->dbh;
2137
    my $sth              = $dbh->prepare(
2138
        'SELECT routingid, borrowernumber, ranking, biblionumber
2139
            FROM subscription 
2140
            JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
2141
            WHERE subscription.subscriptionid = ? ORDER BY ranking ASC'
2142
    );
2143
    $sth->execute($subscriptionid);
2144
    my $routinglist = $sth->fetchall_arrayref({});
2145
    return @{$routinglist};
2146
}
2147
2148
=head2 countissuesfrom
2046
=head2 countissuesfrom
2149
2047
2150
$result = countissuesfrom($subscriptionid,$startdate)
2048
$result = countissuesfrom($subscriptionid,$startdate)
Lines 2282-2302 sub GetSubscriptionsFromBorrower { Link Here
2282
    my ($borrowernumber) = @_;
2180
    my ($borrowernumber) = @_;
2283
    my $dbh              = C4::Context->dbh;
2181
    my $dbh              = C4::Context->dbh;
2284
    my $sth              = $dbh->prepare(
2182
    my $sth              = $dbh->prepare(
2285
        "SELECT subscription.subscriptionid, biblio.title
2183
        "SELECT subscriptionroutinglist.*, biblio.title AS bibliotitle
2286
            FROM subscription
2184
            FROM subscriptionroutinglist
2185
            JOIN subscriptionrouting ON (subscriptionroutinglist.routinglistid = subscriptionrouting.routinglistid)
2186
            JOIN subscription ON (subscriptionroutinglist.subscriptionid = subscription.subscriptionid)
2287
            JOIN biblio ON biblio.biblionumber = subscription.biblionumber
2187
            JOIN biblio ON biblio.biblionumber = subscription.biblionumber
2288
            JOIN subscriptionroutinglist USING (subscriptionid)
2188
            WHERE subscriptionrouting.borrowernumber = ? ORDER BY title ASC
2289
            WHERE subscriptionroutinglist.borrowernumber = ? ORDER BY title ASC
2290
                               "
2189
                               "
2291
    );
2190
    );
2292
    $sth->execute($borrowernumber);
2191
    $sth->execute($borrowernumber);
2293
    my @routinglist;
2192
    my $routinglists = $sth->fetchall_arrayref({});
2294
    my $count = 0;
2193
    return $routinglists ? @$routinglists : ();
2295
    while ( my $line = $sth->fetchrow_hashref ) {
2296
        $count++;
2297
        push( @routinglist, $line );
2298
    }
2299
    return ( $count, @routinglist );
2300
}
2194
}
2301
2195
2302
2196
(-)a/C4/Serials/RoutingLists.pm (+274 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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
use vars qw($VERSION @ISA @EXPORT_OK);
25
26
BEGIN {
27
    $VERSION = 3.01;
28
    require Exporter;
29
    @ISA = qw(Exporter);
30
    @EXPORT_OK = qw(
31
        &AddRoutingList
32
        &ModRoutingList
33
        &DelRoutingList
34
        &GetRoutingList
35
        &GetRoutingLists
36
        &GetRoutingListsCount
37
        &GetRoutingListAsCSV
38
    );
39
}
40
41
=head2 AddRoutingList
42
43
$routinglistid = &AddRoutingList($subscriptionid, $title);
44
45
this function create a new routing list for a subscription.
46
47
=cut
48
49
sub AddRoutingList {
50
    my ($subscriptionid, $title) = @_;
51
52
    my $dbh = C4::Context->dbh();
53
    my $query = qq{
54
        INSERT INTO subscriptionroutinglist (subscriptionid, title)
55
        VALUES (?, ?)
56
    };
57
    my $sth = $dbh->prepare($query);
58
    $sth->execute($subscriptionid, $title);
59
60
    return $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef);
61
}
62
63
=head2 ModRoutingList
64
65
&ModRoutingList($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers);
66
67
this function modifies a routing list.
68
69
=cut
70
71
sub ModRoutingList {
72
    my ($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers) = @_;
73
74
    my $dbh = C4::Context->dbh;
75
    my $query = 'UPDATE subscriptionroutinglist';
76
    my @setstrings = ();
77
    my @setargs = ();
78
    if($subscriptionid) {
79
        push @setstrings, 'subscriptionid = ?';
80
        push @setargs, $subscriptionid;
81
    }
82
    if($title) {
83
        push @setstrings, 'title = ?';
84
        push @setargs, $title;
85
    }
86
    if($notes) {
87
        push @setstrings, 'notes = ?';
88
        push @setargs, $notes;
89
    }
90
91
    if(@setstrings) {
92
        $query .= ' SET ' . join(',', @setstrings);
93
        $query .= ' WHERE routinglistid = ?';
94
        my $sth = $dbh->prepare($query);
95
        $sth->execute(@setargs, $routinglistid);
96
    }
97
98
    $query = qq{
99
        DELETE FROM subscriptionrouting
100
        WHERE routinglistid = ?
101
    };
102
    my $sth = $dbh->prepare($query);
103
    $sth->execute($routinglistid);
104
105
    if(@borrowernumbers > 0){
106
        $query = qq{
107
            INSERT INTO subscriptionrouting (routinglistid, borrowernumber, ranking)
108
            VALUES (?, ?, ?)
109
        };
110
        $sth = $dbh->prepare($query);
111
        my $i = 1;
112
        foreach (@borrowernumbers) {
113
            $sth->execute($routinglistid, $_, $i);
114
            $i++;
115
        }
116
    }
117
}
118
119
=head2 DelRoutingList
120
121
&DelRoutingList($routinglistid);
122
123
this function delete a routing list.
124
125
=cut
126
127
sub DelRoutingList {
128
    my ($routinglistid) = @_;
129
130
    my $dbh = C4::Context->dbh;
131
    my $query = qq{
132
        DELETE FROM subscriptionroutinglist
133
        WHERE routinglistid = ?
134
    };
135
    my $sth = $dbh->prepare($query);
136
    $sth->execute($routinglistid);
137
}
138
139
140
=head2 GetRoutingList
141
142
$routinglist = &GetRoutingList($routinglistid);
143
144
this function get infos from subscriptionroutinglist table.
145
The 'borrowers' keys contains the list of borrowernumbers attached
146
to this routing list.
147
148
=cut
149
150
sub GetRoutingList {
151
    my ($routinglistid) = @_;
152
153
    my $dbh = C4::Context->dbh;
154
    my $query = qq{
155
        SELECT *
156
        FROM subscriptionroutinglist
157
        WHERE routinglistid = ?
158
    };
159
    my $sth = $dbh->prepare($query);
160
    $sth->execute($routinglistid);
161
    my $result = $sth->fetchrow_hashref;
162
163
    $query = qq{
164
        SELECT borrowernumber
165
        FROM subscriptionrouting
166
        WHERE routinglistid = ?
167
        ORDER BY ranking ASC
168
    };
169
    $sth = $dbh->prepare($query);
170
    $sth->execute($routinglistid);
171
    while (my $row = $sth->fetchrow_hashref) {
172
        push @{$result->{borrowers}}, $row->{borrowernumber};
173
    }
174
175
    return $result;
176
}
177
178
=head2 GetRoutingLists
179
180
$routinglists = &GetRoutingLists($subscriptionid);
181
182
this function get all routing lists for a subscription.
183
184
=cut
185
186
sub GetRoutingLists {
187
    my ($subscriptionid) = @_;
188
189
    my $dbh = C4::Context->dbh;
190
    my $query = qq{
191
        SELECT routinglistid
192
        FROM subscriptionroutinglist
193
        WHERE subscriptionid = ?
194
    };
195
    my $sth = $dbh->prepare($query);
196
    $sth->execute($subscriptionid);
197
    my @results;
198
    while (my $row = $sth->fetchrow_hashref) {
199
        my $routinglistid = $row->{routinglistid};
200
        push @results, GetRoutingList($routinglistid);
201
    }
202
203
    return @results;
204
}
205
206
=head2 GetRoutingListsCount
207
208
$count = &GetRoutingListsCount($subscriptionid);
209
210
this function return the number of routing lists for a subscription.
211
212
=cut
213
214
sub GetRoutingListsCount {
215
    my ($subscriptionid) = @_;
216
217
    return unless $subscriptionid;
218
219
    my $dbh = C4::Context->dbh;
220
    my $query = qq{
221
        SELECT COUNT(*) AS count
222
        FROM subscriptionroutinglist
223
        WHERE subscriptionid = ?
224
    };
225
    my $sth = $dbh->prepare($query);
226
    $sth->execute($subscriptionid);
227
    my $result = $sth->fetchrow_hashref;
228
229
    return $result->{count};
230
}
231
232
=head2 GetRoutingListAsCSV
233
234
$csv_output = &GetRoutingListAsCSV($routinglistid);
235
236
this function return the routing list as a CSV file.
237
238
=cut
239
240
sub GetRoutingListAsCSV {
241
    my ($routinglistid) = @_;
242
243
    require C4::Biblio;
244
    require C4::Serials;
245
    require C4::Members;
246
    require Text::CSV::Encoded;
247
248
    my $csv = Text::CSV::Encoded->new( {encoding => "utf8" } );
249
    my $output;
250
251
    my $routinglist = GetRoutingList($routinglistid);
252
    my $subscription = C4::Serials::GetSubscription($routinglist->{'subscriptionid'});
253
    my $biblio = C4::Biblio::GetBiblio($subscription->{'biblionumber'});
254
255
    my @headers = ("Subscription title", "Routing list", qw(Surname Firstname Notes));
256
    $csv->combine(@headers);
257
    $output .= $csv->string() . "\n";
258
259
    foreach (@{$routinglist->{borrowers}}) {
260
        my $member = C4::Members::GetMemberDetails($_);
261
        $csv->combine(
262
            $biblio->{'title'},
263
            $routinglist->{'title'},
264
            $member->{'surname'},
265
            $member->{'firstname'},
266
            $routinglist->{'notes'},
267
        );
268
        $output .= $csv->string() . "\n";
269
    }
270
271
    return $output;
272
}
273
274
1;
(-)a/acqui/newordersubscription.pl (-1 / +2 lines)
Lines 25-30 use C4::Branch; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Output;
26
use C4::Output;
27
use C4::Serials;
27
use C4::Serials;
28
use C4::Serials::RoutingLists qw( GetRoutingListsCount );
28
29
29
use Koha::Acquisition::Bookseller;
30
use Koha::Acquisition::Bookseller;
30
31
Lines 72-78 foreach my $sub (@subscriptions) { Link Here
72
73
73
    # to toggle between create or edit routing list options
74
    # to toggle between create or edit routing list options
74
    if ($routing) {
75
    if ($routing) {
75
        $sub->{routingedit} = check_routing( $sub->{subscriptionid} );
76
        $sub->{routingedit} = GetRoutingListsCount( $sub->{subscriptionid} );
76
    }
77
    }
77
}
78
}
78
79
(-)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 / +31 lines)
Lines 2132-2152 CREATE TABLE `subscriptionhistory` ( Link Here
2132
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2132
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2133
2133
2134
--
2134
--
2135
-- Table structure for table `subscriptionroutinglist`
2135
-- Table structure for table subscriptionroutinglist
2136
--
2136
--
2137
2137
2138
DROP TABLE IF EXISTS `subscriptionroutinglist`;
2138
DROP TABLE IF EXISTS subscriptionroutinglist;
2139
CREATE TABLE `subscriptionroutinglist` ( -- information related to the routing lists attached to subscriptions
2139
CREATE TABLE subscriptionroutinglist (
2140
  `routingid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2140
    routinglistid int(11) NOT NULL AUTO_INCREMENT, -- unique identifier assigned by Koha
2141
  `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines with patron is on the routing list
2141
    subscriptionid int(11) NOT NULL, -- foreign key from the subscription table,
2142
  `ranking` int(11) default NULL, -- where the patron stands in line to receive the serial
2142
                                     -- defines which subscription this routing list is for
2143
  `subscriptionid` int(11) NOT NULL, -- foreign key from the subscription table, defines which subscription this routing list is for
2143
    title varchar(256) NOT NULL, -- title of this routing list
2144
  PRIMARY KEY  (`routingid`),
2144
    notes text default NULL, -- notes for this routing list
2145
  UNIQUE (`subscriptionid`, `borrowernumber`),
2145
    PRIMARY KEY (routinglistid),
2146
  CONSTRAINT `subscriptionroutinglist_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
2146
    CONSTRAINT subscriptionroutinglist_ibfk_1 FOREIGN KEY (subscriptionid)
2147
    ON DELETE CASCADE ON UPDATE CASCADE,
2147
      REFERENCES subscription (subscriptionid) ON DELETE CASCADE
2148
  CONSTRAINT `subscriptionroutinglist_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`)
2148
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2149
    ON DELETE CASCADE ON UPDATE CASCADE
2149
2150
--
2151
-- Table structure for subscriptionrouting
2152
--
2153
2154
DROP TABLE IF EXISTS subscriptionrouting;
2155
CREATE TABLE subscriptionrouting (
2156
    routinglistid int(11) NOT NULL, -- foreign key from the subscriptionroutinglist
2157
                                    -- table, defines which routing list is affected
2158
    borrowernumber int(11) NOT NULL, -- foreign key from the borrowers table,
2159
                                     -- defines which patron is on the routing list
2160
    ranking int(11) DEFAULT NULL, -- where the patron stands in line to receive the serial
2161
    PRIMARY KEY (routinglistid, borrowernumber),
2162
    CONSTRAINT subscriptionrouting_ibfk_1 FOREIGN KEY (routinglistid)
2163
      REFERENCES subscriptionroutinglists (routinglistid) ON DELETE CASCADE,
2164
    CONSTRAINT subscriptionrouting_ibfk_2 FOREIGN KEY (borrowernumber)
2165
      REFERENCES borrowers (borrowernumber) ON DELETE CASCADE
2150
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2166
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2151
2167
2152
--
2168
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc (-2 / +2 lines)
Lines 4-12 Link Here
4
  [% UNLESS closed %]
4
  [% UNLESS closed %]
5
    [% IF ( routing && CAN_user_serials_routing ) %]
5
    [% IF ( routing && CAN_user_serials_routing ) %]
6
        [% IF ( hasRouting ) %]
6
        [% IF ( hasRouting ) %]
7
             <li><a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid %]">Edit routing list</a></li>
7
             <li><a href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscriptionid %]">Edit routing list</a></li>
8
        [% ELSE %]
8
        [% ELSE %]
9
            <li><a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid %]&amp;op=new">Create routing list</a></li>
9
            <li><a href="/cgi-bin/koha/serials/routinglist.pl?subscriptionid=[% subscriptionid %]&amp;op=new">Create routing list</a></li>
10
        [% END %]
10
        [% END %]
11
    [% END %]
11
    [% END %]
12
  [% END %]
12
  [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc (+7 lines)
Lines 13-18 Link Here
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
14
        }
14
        }
15
    }
15
    }
16
    function confirm_deletion() {
17
        var is_confirmed = confirm(_("Are you sure you want to delete this subscription?"));
18
        if (is_confirmed) {
19
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=del";
20
        }
21
    }
22
16
23
17
	 $(document).ready(function() {
24
	 $(document).ready(function() {
18
        $("#deletesub").click(function(){
25
        $("#deletesub").click(function(){
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt (-39 / +36 lines)
Lines 22-71 Link Here
22
<!-- Search Bar End -->
22
<!-- Search Bar End -->
23
23
24
<h1>
24
<h1>
25
[% IF ( countSubscrip ) %]
25
[% IF ( routinglists.size > 0 ) %]
26
[% countSubscrip %] Subscription routing list(s)
26
  [% routinglists.size %] Subscription routing list(s)
27
[% ELSE %]
27
[% ELSE %]
28
0 Subscription routing lists
28
  0 Subscription routing lists
29
[% END %]
29
[% END %]
30
</h1>
30
</h1>
31
31
32
<div id="subscriptions">
32
<div id="subscriptions">
33
[% IF ( subscripLoop ) %]
33
  [% IF ( routinglists.size > 0 ) %]
34
<table id="subscriptiont">
34
    <table id="subscriptiont">
35
              <thead>
35
      <thead>
36
                <tr>
36
        <tr>
37
                  <th>Subscription title</th>
37
          <th>Subscription title</th>
38
                  <th>Routing list</th>
38
          <th>Routing list</th>
39
                </tr>
39
          <th>Actions</th>
40
              </thead>
40
        </tr>
41
              <tbody>
41
      </thead>
42
[% FOREACH subscripLoop IN subscripLoop %]
42
      <tbody>
43
<tr>
43
        [% FOREACH routinglist IN routinglists %]
44
    <td>
44
          <tr>
45
    <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscripLoop.subscriptionid %]"><strong>
45
            <td>
46
    [% subscripLoop.title %]
46
              <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% routinglist.subscriptionid %]">
47
    </strong>
47
                <strong>
48
                    </a>
48
                  [% routinglist.bibliotitle %]
49
                  </td>
49
                </strong>
50
                  <td>
50
              </a>
51
                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscripLoop.subscriptionid %]"><strong>
51
            </td>
52
                    Edit routing list
52
            <td>[% routinglist.title %]</td>
53
                      </strong>
53
            <td>
54
                    </a>
54
              <a href="/cgi-bin/koha/serials/routinglist.pl?routinglistid=[% routinglist.routinglistid %]"><strong>
55
                    <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
55
              Edit routing list
56
                    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
56
                </strong>
57
                  </td>
57
              </a>
58
                </tr>
58
            </td>
59
                [% END %]
59
          </tr>
60
                </tbody>
60
        [% END %]
61
            </table>
61
      </tbody>
62
            </form>
62
    </table>
63
          [% ELSE %]
63
  [% ELSE %]
64
          <p>Patron does not belong to any subscription routing lists.</p>
64
    <p>Patron does not belong to any subscription routing lists.</p>
65
          <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
65
  [% END %]
66
                    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
67
                    [% END %]
68
69
</div>
66
</div>
70
67
71
68
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt (-25 / +91 lines)
Lines 14-47 Link Here
14
<div id="custom-doc" class="yui-t7">
14
<div id="custom-doc" class="yui-t7">
15
   <div id="bd">
15
   <div id="bd">
16
16
17
<table>
17
[% IF (missing_parameter_routinglistid or missing_parameter_serialid) %]
18
    <tr>
18
    <h1>Routing list preview for <em>[% title %]</em></h1>
19
        <td colspan="2"><h3>[% libraryname %]</h3></td>
19
20
    </tr>
20
    <form action="" method="get">
21
    <tr>
21
        [% IF (missing_parameter_routinglistid) %]
22
        <td colspan="2"><b>Title:</b> [% title |html %]<br />[% issue %]</td>
22
            <input type="hidden" name="serialid" value="[% serialid %]" />
23
    </tr>
23
            <label for="routinglist">Please select a routing list</label>
24
    <tr>
24
            <select id="routinglist" name="routinglistid">
25
        <td><b>Name</b></td>
25
                [% FOREACH routinglist IN routinglists %]
26
        <td><b>Date due</b></td>
26
                    <option value="[% routinglist.routinglistid %]">
27
    </tr>
27
                        [% routinglist.title %]
28
    [% FOREACH memberloo IN memberloop %]
28
                    </option>
29
    <tr>
29
                [% END %]
30
        <td>[% memberloo.name %]</td>
30
            </select>
31
        <td>&nbsp;</td>
31
        [% ELSE %]
32
    </tr>
32
            <input type="hidden" name="routinglistid" value="[% routinglistid %]" />
33
            <label for="serial">Please select a serial</label>
34
            <select id="serial" name="serialid">
35
                [% FOREACH serial IN serials %]
36
                    <option value="[% serial.serialid %]">
37
                        [% serial.serialseq %] ([% serial.planneddate %])
38
                    </option>
39
                [% END %]
40
            </select>
41
        [% END %]
42
        <input type="submit" value="Continue" />
43
    </form>
44
[% ELSE %]
45
    [% IF (error_no_item) %]
46
        <div class="error noprint">
47
            <p>Holds cannot be placed on this serial. There is no item attached to it.</p>
48
        </div>
33
    [% END %]
49
    [% END %]
34
</table>
50
    <table>
51
        [% IF (libraryname) %]
52
            <tr>
53
                <td colspan="2"><h3>[% libraryname %]</h3></td>
54
            </tr>
55
        [% END %]
56
        <tr>
57
            <td colspan="2">
58
                <b>Title:</b> [% title |html %]<br />
59
                [% serial.serialseq %] ([% serial.planneddate %])
60
            </td>
61
        </tr>
62
        <tr>
63
            <td colspan="2">
64
                <b>Routing list:</b> [% routinglisttitle %]
65
            </td>
66
        </tr>
67
        <tr>
68
            <td><b>Name</b></td>
69
            <td><b>Date due</b></td>
70
        </tr>
71
        [% FOREACH member IN memberloop %]
72
        <tr>
73
            <td>[% member.surname %], [% member.firstname %]</td>
74
            <td>&nbsp;</td>
75
        </tr>
76
        [% END %]
77
    </table>
35
78
36
<div id="routingnotes">
79
    <div id="routingnotes">
37
    <p id="generalroutingnote">[% generalroutingnote %]</p>
80
        <p id="generalroutingnote">[% generalroutingnote %]</p>
38
    <p id="routingnote">[% routingnotes %]</p>
81
        <p id="routingnote">[% routingnotes %]</p>
39
</div>
82
    </div>
40
83
41
   <div id="slip-block-links" class="noprint">
84
    [% IF (need_confirm) %]
42
   <a class="button" href="javascript:window.print();self.close()">Print</a> &nbsp; <a class="button" href="javascript:self.close()">Close</a>
85
        [%# RoutingListAddReserves is ON %]
43
   </div>
86
        <script type="text/javascript">
87
        //<![CDATA[
88
            function ask_confirm() {
89
                var msg = _("Holds will be placed for all borrowers in this list.");
90
                msg += "\n";
91
                msg += _("Do you want to continue?");
92
                return confirm(msg);
93
            }
94
        //]]>
95
        </script>
96
        <form action="" method="get" onsubmit="return ask_confirm()">
97
            <input type="hidden" name="routinglistid" value="[% routinglistid %]" />
98
            <input type="hidden" name="serialid" value="[% serialid %]" />
99
            <input type="hidden" name="confirm" value="1" />
100
            <input type="submit" value="Confirm and print" />
101
            <input type="button" value="Cancel" onclick="window.close()" />
102
        </form>
103
    [% ELSE %]
104
        <div id="slip-block-links" class="noprint">
105
           <a class="button" href="javascript:window.print();self.close()">Print</a>
106
           &nbsp; <a class="button" href="javascript:self.close()">Close</a>
107
        </div>
108
    [% END %]
109
[% END %]
44
110
45
   </div>
111
    </div>
46
112
47
[% INCLUDE 'intranet-bottom.inc' %]
113
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt (-57 lines)
Lines 1-57 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Preview routing list</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
<!--
6
7
function print_slip(subscriptionid,issue){
8
    var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
9
    window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
10
    window.location.href='subscription-detail.pl?subscriptionid=' + subscriptionid;
11
}
12
//-->
13
</script>
14
</head>
15
<body id="ser_routing-preview" class="ser">
16
[% INCLUDE 'header.inc' %]
17
[% INCLUDE 'serials-search.inc' %]
18
19
<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 %]"><i>[% title |html %]</i></a> &rsaquo; Preview routing list</div>
20
21
<div id="doc3" class="yui-t2">
22
   
23
   <div id="bd">
24
	<div id="yui-main">
25
	<div class="yui-b">
26
27
<h2>Preview routing list for <i>[% title |html %]</i></h2>
28
29
<form method="post" action="routing-preview.pl">
30
<input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
31
<fieldset class="rows">
32
	<ol>
33
		<li><span class="label">Issue:</span>[% issue %]</li>
34
		<li><span class="label">List member:</span><table style="clear:none;margin:0;">
35
        <tr><th>Name</th></tr>
36
[% FOREACH memberloo IN memberloop %]
37
        <tr><td>[% memberloo.surname %], [% memberloo.firstname %]</td></tr>
38
[% END %]
39
        </table></li>
40
		<li><span class="label">Notes:</span>[% routingnotes %]</li>
41
	</ol>
42
</fieldset>
43
44
<fieldset class="action">
45
<input type="submit" name="ok" class="button" value="Save and preview routing slip" onclick="print_slip([% subscriptionid %],'[% issue_escaped %]'); return false" />
46
<input type="submit" name="edit" class="button" value="Edit" />
47
<input type="submit" name="delete" class="button" value="Delete" /></fieldset>
48
</form>
49
50
</div>
51
</div>
52
53
<div class="yui-b">
54
[% INCLUDE 'serials-menu.inc' %]
55
</div>
56
</div>
57
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt (-111 lines)
Lines 1-111 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; [% title |html %] &rsaquo; [% IF ( op ) %]Create Routing List[% ELSE %]Edit routing list[% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
<!--
6
7
function reorder_item(sid,rid,rank){
8
    var mylocation = 'reorder_members.pl?subscriptionid='+sid+'&routingid='+rid+'&rank='+rank;
9
    window.location.href=mylocation; 
10
}
11
12
    function userPopup() {
13
        window.open("/cgi-bin/koha/serials/add_user_search.pl",
14
            'PatronPopup',
15
            'width=740,height=450,location=yes,toolbar=no,'
16
            + 'scrollbars=yes,resize=yes'
17
        );
18
    }
19
20
    function add_user(borrowernumber) {
21
        var myurl = "routing.pl?subscriptionid="+[% subscriptionid %]+"&borrowernumber="+borrowernumber+"&op=add";
22
        window.location.href = myurl;
23
    }
24
25
//-->
26
</script>
27
</head>
28
<body id="ser_routing" class="ser">
29
[% INCLUDE 'header.inc' %]
30
[% INCLUDE 'serials-search.inc' %]
31
32
<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 %]"><i>[% title |html %]</i></a> &rsaquo; [% IF ( op ) %]Create Routing List[% ELSE %]Edit routing list[% END %]</div>
33
34
<div id="doc3" class="yui-t2">
35
   
36
   <div id="bd">
37
	<div id="yui-main">
38
	<div class="yui-b">
39
40
41
[% IF ( op ) %]
42
<h1>Create routing list for <i>[% title |html %]</i></h1>
43
[% ELSE %]
44
<h1>Edit routing list for <i>[% title |html %]</i></h1>
45
[% END %]
46
47
<form method="post" action="routing.pl">
48
<input type="hidden" name="op" value="save" />
49
<input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
50
<fieldset class="rows">
51
	<ol>
52
		<li><label for="date_selected">Issue: </label>
53
<select name="date_selected" id="date_selected">
54
[% FOREACH date IN dates %]
55
[% IF ( date.selected ) %]<option value="[% date.serialseq %] ([% date.publisheddate %])" selected="selected">[% date.serialseq %] ([% date.publisheddate %])</option>[% ELSE %]<option value="[% date.serialseq %] ([% date.publisheddate %])">[% date.serialseq %] ([% date.publisheddate %])</option>[% END %]
56
[% END %]
57
</select> [% issue %]</li>
58
59
<li>
60
    <span class="label">Recipients:</span>
61
    [% IF memberloop %]
62
        <table style="clear:none;margin:0;">
63
            <tr><th>Name</th>
64
                <th>Rank</th>
65
                <th>Delete</th>
66
            </tr>
67
            [% USE m_loop = iterator(memberloop) %]
68
            [% FOREACH member IN m_loop %]
69
            <tr><td>[% member.name %]</td>
70
                <td>
71
                    <select name="itemrank" onchange="reorder_item([%- subscriptionid -%], [%- member.routingid -%], this.value)">
72
                    [% rankings = [1 .. m_loop.size] %]
73
                    [% FOREACH r IN rankings %]
74
                        [% IF r == member.ranking %]
75
                          <option selected="selected" value="[% r %]">[% r %]</option>
76
                        [% ELSE %]
77
                          <option value="[% r %]">[% r %]</option>
78
                        [% END %]
79
                    [% END %]
80
                    </select>
81
                </td>
82
                <td><a href="/cgi-bin/koha/serials/routing.pl?routingid=[% member.routingid %]&amp;subscriptionid=[% subscriptionid %]&amp;op=delete">Delete</a></td>
83
            </tr>
84
            [% END %]
85
        </table>
86
    [% END %]
87
88
    <p style="margin-left:10em;">
89
        <input type="button" onclick="userPopup()" value="Add recipients" />
90
        [% IF memberloop %]
91
            <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid %]&amp;op=delete" class="button">Delete all</a>
92
        [% END %]
93
    </p>
94
</li>
95
96
	<li><label for="notes">Notes:</label><textarea name="notes" id="notes" rows="3" cols="50">[% routingnotes %]</textarea></li>
97
	</ol>
98
99
</fieldset>
100
<fieldset class="action"><input type="submit" name="submit" value="Save" /></fieldset>
101
</form>
102
103
104
</div>
105
</div>
106
107
<div class="yui-b">
108
[% INCLUDE 'serials-menu.inc' %]
109
</div>
110
</div>
111
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt (+196 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 id="doc3" class="yui-t2">
127
128
<div id="bd">
129
  <div id="yui-main">
130
    <div class="yui-b">
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 is 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
            <label for="notes">Notes: </label><br />
185
            <textarea id="notes" name="notes">[% notes %]</textarea><br />
186
            <input type="submit" value="Save" />
187
            <input type="button" value="Cancel" onclick="window.location.href='/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscriptionid %]';" />
188
          </form>
189
      [% END %]<!-- new -->
190
    </div>
191
  </div>
192
  <div class="yui-b">
193
    [% INCLUDE 'serials-menu.inc' %]
194
  </div>
195
</div>
196
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt (+69 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 id="doc3" class="yui-t2">
26
27
<div id="bd">
28
  <div id="yui-main">
29
    <div class="yui-b">
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 is no routing lists for this subscription.</p>
61
      [% END %]
62
63
    </div>
64
  </div>
65
  <div class="yui-b">
66
    [% INCLUDE 'serials-menu.inc' %]
67
  </div>
68
</div>
69
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt (-6 / +7 lines)
Lines 14-23 function generateReceive(subscriptionid) { Link Here
14
        document.location = 'serials-collection.pl?op=gennext&subscriptionid='+subscriptionid+'&nbissues='+nbissues;
14
        document.location = 'serials-collection.pl?op=gennext&subscriptionid='+subscriptionid+'&nbissues='+nbissues;
15
    }
15
    }
16
}
16
}
17
function print_slip(subscriptionid,issue){
17
function print_slip(serialid){
18
    var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
18
    var myurl = '/cgi-bin/koha/serials/routing-preview-slip.pl?serialid='+serialid;
19
    window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
19
    window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
20
}
20
}
21
21
function addsubscriptionid()
22
function addsubscriptionid()
22
{
23
{
23
	var tab=new Array();
24
	var tab=new Array();
Lines 134-143 $(document).ready(function() { Link Here
134
        [% IF ( routing && CAN_user_serials_routing ) %]
135
        [% IF ( routing && CAN_user_serials_routing ) %]
135
        <td>
136
        <td>
136
            [% UNLESS subscription.closed %]
137
            [% UNLESS subscription.closed %]
137
                [% IF ( subscription.hasRouting ) %]
138
                [% IF (subscription.routinglistscount) %]
138
                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]">Edit routing list</a>
139
                    <a href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscription.subscriptionid %]">Edit routing lists</a> ([% subscription.routinglistscount %])
139
                [% ELSE %]
140
                [% ELSE %]
140
                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]&amp;op=new">Create routing list</a>
141
                    <a href="/cgi-bin/koha/serials/routinglist.pl?op=new&subscriptionid=[% subscription.subscriptionid %]">New routing list</a>
141
                [% END %]
142
                [% END %]
142
            [% END %]
143
            [% END %]
143
        </td>
144
        </td>
Lines 294-300 $(document).ready(function() { Link Here
294
                </td>
295
                </td>
295
                [% IF ( routing ) %]
296
                [% IF ( routing ) %]
296
                <td>
297
                <td>
297
                    <a href="" onclick="print_slip([% serial.subscriptionid |html %], '[% serial.serialseq |html %] ([% serial.publisheddate | $KohaDates %])'); return false" >Print list</a>
298
                    <a style="cursor:pointer" onclick="print_slip([% serial.serialid %]);">Print list</a>
298
                </td>
299
                </td>
299
                [% END %]
300
                [% END %]
300
            </tr>
301
            </tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt (-9 / +7 lines)
Lines 199-213 Link Here
199
                                    [% IF ( routing && CAN_user_serials_routing ) %]
199
                                    [% IF ( routing && CAN_user_serials_routing ) %]
200
                                        [% IF ( subscription.cannotedit ) %]
200
                                        [% IF ( subscription.cannotedit ) %]
201
                                        [% ELSE %]
201
                                        [% ELSE %]
202
                                            [% IF ( subscription.routingedit ) %]
202
                                            <li>
203
                                                <li>
203
                                                [% IF ( subscription.routinglistscount ) %]
204
                                                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]"><i class="icon-pencil"></i> Edit routing list ([% subscription.routingedit %])</a>
204
                                                    <a href="/cgi-bin/koha/serials/routinglists.pl?subscriptionid=[% subscription.subscriptionid %]"><i class="icon-pencil"></i> Edit routing list ([% subscription.routinglistscount %])</a>
205
                                                </li>
205
                                                [% ELSE %]
206
                                            [% ELSE %]
206
                                                    <a href="/cgi-bin/koha/serials/routinglist.pl?subscriptionid=[% subscription.subscriptionid %]&amp;op=new"> <i class="icon-plus"></i> New routing list</a>
207
                                                <li>
207
                                                [% END %]
208
                                                    <a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscription.subscriptionid %]&amp;op=new"> <i class="icon-plus"></i> New routing list</a>
208
                                            </li>
209
                                                </li>
210
                                            [% END %]
211
                                        [% END %]
209
                                        [% END %]
212
                                    [% END # IF ( routing && CAN_user_serials_routing ) %]
210
                                    [% END # IF ( routing && CAN_user_serials_routing ) %]
213
211
(-)a/members/routing-lists.pl (-14 / +2 lines)
Lines 76-97 if ($borrowernumber) { Link Here
76
76
77
if ($borrowernumber) {
77
if ($borrowernumber) {
78
# new op dev
78
# new op dev
79
  my $count;
79
  my @routinglists = GetSubscriptionsFromBorrower($borrowernumber );
80
  my @borrowerSubscriptions;
81
  ($count, @borrowerSubscriptions) = GetSubscriptionsFromBorrower($borrowernumber );
82
  my @subscripLoop;
83
84
    foreach my $num_res (@borrowerSubscriptions) {
85
        my %getSubscrip;
86
        $getSubscrip{subscriptionid}	= $num_res->{'subscriptionid'};
87
        $getSubscrip{title}			= $num_res->{'title'};
88
        $getSubscrip{borrowernumber}		= $num_res->{'borrowernumber'};
89
        push( @subscripLoop, \%getSubscrip );
90
    }
91
80
92
    $template->param(
81
    $template->param(
93
        countSubscrip => scalar @subscripLoop,
82
        routinglists => \@routinglists,
94
        subscripLoop  => \@subscripLoop,
95
        routinglistview => 1
83
        routinglistview => 1
96
    );
84
    );
97
85
(-)a/serials/reorder_members.pl (-38 lines)
Lines 1-38 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 strict;
22
use warnings;
23
use CGI qw ( -utf8 );
24
use C4::Auth qw( checkauth );
25
use C4::Serials qw( reorder_members );
26
27
my $query          = CGI->new;
28
my $subscriptionid = $query->param('subscriptionid');
29
my $routingid      = $query->param('routingid');
30
my $rank           = $query->param('rank');
31
32
checkauth( $query, 0, { serials => 'routing' }, 'intranet' );
33
34
reorder_members( $subscriptionid, $routingid, $rank );
35
36
print $query->redirect(
37
    "/cgi-bin/koha/serials/routing.pl?subscriptionid=$subscriptionid");
38
(-)a/serials/routing-preview-slip.pl (+144 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
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::Branch;
37
use C4::Members;
38
use C4::Serials;
39
use C4::Serials::RoutingLists qw/GetRoutingList GetRoutingLists/;
40
41
my $input = new CGI;
42
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
43
    template_name   => 'serials/routing-preview-slip.tt',
44
    query           => $input,
45
    type            => 'intranet',
46
    authnotrequired => 0,
47
    flagsrequired   => { 'serials' => 'routing' },
48
    debug           => 1,
49
} );
50
51
my $routinglistid = $input->param('routinglistid');
52
my $serialid = $input->param('serialid');
53
54
if (!$routinglistid and !$serialid) {
55
    exit;
56
}
57
58
if (!$routinglistid) {
59
    my $serial = GetSerial($serialid);
60
    my $subscription = GetSubscription($serial->{subscriptionid});
61
    my $biblio = GetBiblio($subscription->{subscriptionid});
62
    my @routinglists = GetRoutingLists($subscription->{subscriptionid});
63
    $template->param(
64
        missing_parameter_routinglistid => 1,
65
        serialid => $serialid,
66
        title => $biblio->{title},
67
        routinglists => \@routinglists
68
    );
69
    output_html_with_http_headers $input, $cookie, $template->output;
70
    exit;
71
} elsif (!$serialid) {
72
    my $routinglist = GetRoutingList($routinglistid);
73
    my $subscription = GetSubscription($routinglist->{subscriptionid});
74
    my $biblio = GetBiblio($subscription->{subscriptionid});
75
    my @serials = GetSerials2($subscription->{subscriptionid}, [1,2,3,4,5,6,7]);
76
    $template->param(
77
        missing_parameter_serialid => 1,
78
        routinglistid => $routinglistid,
79
        title => $biblio->{title},
80
        serials => \@serials
81
    );
82
    output_html_with_http_headers $input, $cookie, $template->output;
83
    exit;
84
}
85
86
my $routinglist = GetRoutingList($routinglistid);
87
my $subscription = GetSubscription($routinglist->{subscriptionid});
88
my $serial = GetSerial($serialid);
89
my $biblio = GetBiblio($subscription->{biblionumber});
90
my $branch = GetBranchDetail($subscription->{branchcode});
91
my @memberloop;
92
foreach (@{$routinglist->{borrowers}}) {
93
    my $member = GetMemberDetails($_);
94
    push @memberloop, {
95
        surname => $member->{surname},
96
        firstname => $member->{firstname},
97
    };
98
}
99
100
my $no_holds = $input->param('no_holds');
101
if(C4::Context->preference('RoutingListAddReserves') and !$no_holds) {
102
    my $confirm = $input->param('confirm');
103
    if ($confirm) {
104
        require C4::Reserves;
105
        require C4::Items;
106
        my $itemnumber = GetSerialItemnumber($serialid);
107
        my $item = C4::Items::GetItem($itemnumber);
108
        if ($item) {
109
            my $rank = 1;
110
            foreach my $borrowernumber ( @{$routinglist->{borrowers}} ) {
111
                my $reserve = C4::Reserves::GetReserveInfo($borrowernumber,
112
                    $item->{biblionumber});
113
                if($reserve) {
114
                    C4::Reserves::ModReserve($rank, $item->{biblionumber},
115
                        $borrowernumber, $item->{holdingbranch}, $itemnumber);
116
                } else {
117
                    my @bibitems = GetBiblioItemByBiblioNumber($item->{biblionumber});
118
                    C4::Reserves::AddReserve($item->{holdingbranch}, $borrowernumber,
119
                        $item->{biblionumber}, \@bibitems, $rank, undef,
120
                        undef, undef, $biblio->{title}, $itemnumber);
121
                }
122
                $rank++;
123
            }
124
        } else {
125
            $template->param(error_no_item => 1);
126
        }
127
    } else {
128
        $template->param(need_confirm => 1);
129
    }
130
}
131
132
$template->param(
133
    routinglistid   => $routinglistid,
134
    serialid        => $serialid,
135
    libraryname     => $branch->{branchname},
136
    title           => $biblio->{title},
137
    serial          => $serial,
138
    memberloop      => \@memberloop,
139
    routingnotes    => $routinglist->{notes},
140
    generalroutingnote  => C4::Context->preference('RoutingListNote'),
141
    routinglisttitle    => $routinglist->{title},
142
);
143
144
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 heirarchy
20
# of reserves for the serial
21
use strict;
22
use warnings;
23
use CGI qw ( -utf8 );
24
use C4::Koha;
25
use C4::Auth;
26
use C4::Dates;
27
use C4::Output;
28
use C4::Acquisition;
29
use C4::Reserves;
30
use C4::Circulation;
31
use C4::Context;
32
use C4::Members;
33
use C4::Biblio;
34
use C4::Items;
35
use C4::Serials;
36
use URI::Escape;
37
use C4::Branch;
38
39
my $query = new CGI;
40
my $subscriptionid = $query->param('subscriptionid');
41
my $issue = $query->param('issue');
42
my $routingid;
43
my $ok = $query->param('ok');
44
my $edit = $query->param('edit');
45
my $delete = $query->param('delete');
46
my $dbh = C4::Context->dbh;
47
48
if($delete){
49
    delroutingmember($routingid,$subscriptionid);
50
    my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
51
    $sth->execute($subscriptionid);
52
    print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");
53
}
54
55
if($edit){
56
    print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
57
}
58
59
my @routinglist = getroutinglist($subscriptionid);
60
my $subs = GetSubscription($subscriptionid);
61
my ($tmp ,@serials) = GetSerials($subscriptionid);
62
my ($template, $loggedinuser, $cookie);
63
64
if($ok){
65
    # get biblio information....
66
    my $biblio = $subs->{'biblionumber'};
67
	my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio);
68
	my @itemresults = GetItemsInfo( $subs->{biblionumber} );
69
	my $branch = $itemresults[0]->{'holdingbranch'};
70
	my $branchname = GetBranchName($branch);
71
72
	if (C4::Context->preference('RoutingListAddReserves')){
73
		# get existing reserves .....
74
        my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblio });
75
        my $count = scalar( @$reserves );
76
        my $totalcount = $count;
77
		foreach my $res (@$reserves) {
78
			if ($res->{'found'} eq 'W') {
79
				$count--;
80
			}
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($biblio,$routing->{borrowernumber});
87
            my $reserve = $sth->fetchrow_hashref;
88
89
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
90
                ModReserve({
91
                    rank           => $routing->{ranking},
92
                    biblionumber   => $biblio,
93
                    borrowernumber => $routing->{borrowernumber},
94
                    branchcode     => $branch
95
                });
96
            } else {
97
                AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$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
    $template->param("libraryname"=>$branchname);
111
} else {
112
    ($template, $loggedinuser, $cookie)
113
= get_template_and_user({template_name => "serials/routing-preview.tt",
114
				query => $query,
115
				type => "intranet",
116
				authnotrequired => 0,
117
				flagsrequired => {serials => '*'},
118
				debug => 1,
119
				});
120
}
121
122
my $memberloop = [];
123
for my $routing (@routinglist) {
124
    my $member = GetMember( borrowernumber => $routing->{borrowernumber} );
125
    $member->{name}           = "$member->{firstname} $member->{surname}";
126
    push @{$memberloop}, $member;
127
}
128
129
my $routingnotes = $serials[0]->{'routingnotes'};
130
$routingnotes =~ s/\n/\<br \/\>/g;
131
132
$template->param(
133
    title => $subs->{'bibliotitle'},
134
    issue => $issue,
135
    issue_escaped => URI::Escape::uri_escape_utf8($issue),
136
    subscriptionid => $subscriptionid,
137
    memberloop => $memberloop,
138
    routingnotes => $routingnotes,
139
    generalroutingnote => C4::Context->preference('RoutingListNote'),
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 (-128 lines)
Lines 1-128 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 strict;
29
use warnings;
30
use CGI qw ( -utf8 );
31
use C4::Koha;
32
use C4::Auth;
33
use C4::Dates;
34
use C4::Output;
35
use C4::Acquisition;
36
use C4::Output;
37
use C4::Context;
38
39
use C4::Members;
40
use C4::Serials;
41
42
use URI::Escape;
43
44
my $query = new CGI;
45
my $subscriptionid = $query->param('subscriptionid');
46
my $serialseq = $query->param('serialseq');
47
my $routingid = $query->param('routingid');
48
my $borrowernumber = $query->param('borrowernumber');
49
my $notes = $query->param('notes');
50
my $op = $query->param('op') || q{};
51
my $date_selected = $query->param('date_selected');
52
$date_selected ||= q{};
53
my $dbh = C4::Context->dbh;
54
55
if($op eq 'delete'){
56
    delroutingmember($routingid,$subscriptionid);
57
}
58
59
if($op eq 'add'){
60
    addroutingmember($borrowernumber,$subscriptionid);
61
}
62
if($op eq 'save'){
63
    my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');
64
    $sth->execute($notes,$subscriptionid);
65
    my $urldate = URI::Escape::uri_escape_utf8($date_selected);
66
    print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
67
}
68
69
my @routinglist = getroutinglist($subscriptionid);
70
my $subs = GetSubscription($subscriptionid);
71
my ($count,@serials) = GetSerials($subscriptionid);
72
my $serialdates = GetLatestSerials($subscriptionid,$count);
73
74
my $dates = [];
75
foreach my $dateseq (@{$serialdates}) {
76
    my $d = {};
77
    $d->{publisheddate} = $dateseq->{publisheddate};
78
    $d->{serialseq} = $dateseq->{serialseq};
79
    $d->{serialid} = $dateseq->{serialid};
80
    if($date_selected eq $dateseq->{serialid}){
81
        $d->{selected} = ' selected';
82
    } else {
83
        $d->{selected} = q{};
84
    }
85
    push @{$dates}, $d;
86
}
87
88
my ($template, $loggedinuser, $cookie)
89
= get_template_and_user({template_name => 'serials/routing.tt',
90
				query => $query,
91
				type => 'intranet',
92
				authnotrequired => 0,
93
				flagsrequired => {serials => 'routing'},
94
				debug => 1,
95
				});
96
97
my $member_loop = [];
98
for my $routing ( @routinglist ) {
99
    my $member=GetMember('borrowernumber' => $routing->{borrowernumber});
100
    $member->{location} = $member->{branchcode};
101
    if ($member->{firstname} ) {
102
        $member->{name} = $member->{firstname} . q| |;
103
    }
104
    else {
105
        $member->{name} = q{};
106
    }
107
    if ($member->{surname} ) {
108
        $member->{name} .= $member->{surname};
109
    }
110
    $member->{routingid}=$routing->{routingid} || q{};
111
    $member->{ranking} = $routing->{ranking} || q{};
112
113
    push(@{$member_loop}, $member);
114
}
115
116
$template->param(
117
    title => $subs->{bibliotitle},
118
    subscriptionid => $subscriptionid,
119
    memberloop => $member_loop,
120
    op => $op eq 'new',
121
    dates => $dates,
122
    routingnotes => $serials[0]->{'routingnotes'},
123
    hasRouting => check_routing($subscriptionid),
124
    (uc(C4::Context->preference("marcflavour"))) => 1
125
126
    );
127
128
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/serials/routinglist.pl (+114 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
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
my $input = new CGI;
40
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
    template_name   => 'serials/routinglist.tt',
42
    query           => $input,
43
    type            => 'intranet',
44
    authnotrequired => 0,
45
    flagsrequired   => { serials => 'routing' },
46
    debug           => 1,
47
} );
48
49
my $op = $input->param('op');
50
my $routinglistid;
51
52
if($op && $op eq 'new') {
53
    my $subscriptionid = $input->param('subscriptionid');
54
    $template->param(
55
        new => 1,
56
        subscriptionid => $subscriptionid,
57
    );
58
    output_html_with_http_headers $input, $cookie, $template->output;
59
    exit;
60
}
61
62
if($op && $op eq 'savenew') {
63
    my $title = $input->param('title');
64
    my $subscriptionid = $input->param('subscriptionid');
65
66
    $routinglistid = AddRoutingList($subscriptionid, $title);
67
} else {
68
    $routinglistid = $input->param('routinglistid');
69
}
70
71
if($op && $op eq 'mod') {
72
    my $borrowersids = $input->param('borrowersids');
73
    my $notes = $input->param('notes');
74
    my @borrowernumbers = split /:/, $borrowersids;
75
    ModRoutingList($routinglistid, undef, undef, $notes, @borrowernumbers);
76
    my $routinglist = GetRoutingList($routinglistid);
77
    print $input->redirect("/cgi-bin/koha/serials/routinglists.pl?subscriptionid=".$routinglist->{'subscriptionid'});
78
    exit;
79
}
80
81
my $routinglist = GetRoutingList($routinglistid);
82
my @borrowers;
83
my $rank = 1;
84
foreach my $borrowernumber (@{$routinglist->{borrowers}}) {
85
    my @ranking_loop;
86
    for(my $i = 0 ; $i < scalar(@{$routinglist->{borrowers}}) ; $i++){
87
        my $selected = 0;
88
        $selected = 1 if ($rank == $i+1);
89
        push @ranking_loop, {
90
            rank => $i+1,
91
            selected => $selected,
92
        };
93
    }
94
    my $member = GetMemberDetails($borrowernumber);
95
    push @borrowers, {
96
        borrowernumber => $borrowernumber,
97
        surname => $member->{surname},
98
        firstname => $member->{firstname},
99
        ranking_loop => \@ranking_loop
100
    };
101
    $rank ++;
102
}
103
104
$template->param(
105
    borrowers_loop => \@borrowers,
106
    borrowersids => join(':', map ($_->{borrowernumber}, @borrowers)),
107
    max_rank => scalar(@borrowers),
108
    title => $routinglist->{title},
109
    notes => $routinglist->{notes},
110
    subscriptionid => $routinglist->{subscriptionid},
111
    routinglistid => $routinglistid,
112
);
113
114
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/routinglists.pl (+79 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
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
my $input = new CGI;
40
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
    template_name   => 'serials/routinglists.tt',
42
    query           => $input,
43
    type            => 'intranet',
44
    authnotrequired => 0,
45
    flagsrequired   => { serials => 'routing' },
46
    debug           => 1,
47
} );
48
49
my $subscriptionid = $input->param('subscriptionid');
50
my $op = $input->param('op');
51
52
if($op && $op eq "export") {
53
    my $routinglistid = $input->param('routinglistid');
54
    print $input->header(
55
        -type       => 'text/csv',
56
        -attachment => 'routinglist' . $routinglistid . '.csv',
57
    );
58
    print GetRoutingListAsCSV($routinglistid);
59
    exit;
60
} elsif($op && $op eq "del") {
61
    my $routinglistid = $input->param('routinglistid');
62
    if(!defined $subscriptionid){
63
        my $routinglist = GetRoutingList($routinglistid);
64
        $subscriptionid = $routinglist->{subscriptionid};
65
    }
66
    DelRoutingList($routinglistid);
67
}
68
69
my $subscription = GetSubscription($subscriptionid);
70
my $biblio = GetBiblio($subscription->{biblionumber});
71
my @routinglists = GetRoutingLists($subscriptionid);
72
73
$template->param(
74
    subscriptionid => $subscriptionid,
75
    routinglists_loop => \@routinglists,
76
    title => $biblio->{title},
77
);
78
79
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/serials/serials-collection.pl (-3 / +6 lines)
Lines 26-31 use C4::Auth; Link Here
26
use C4::Koha;
26
use C4::Koha;
27
use C4::Dates qw/format_date/;
27
use C4::Dates qw/format_date/;
28
use C4::Serials;
28
use C4::Serials;
29
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
29
use C4::Letters;
30
use C4::Letters;
30
use C4::Output;
31
use C4::Output;
31
use C4::Context;
32
use C4::Context;
Lines 128-134 if (@subscriptionid){ Link Here
128
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
129
    my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
129
    $subs->{frequency} = $frequency;
130
    $subs->{frequency} = $frequency;
130
    $subs->{numberpattern} = $numberpattern;
131
    $subs->{numberpattern} = $numberpattern;
131
    $subs->{'hasRouting'} = check_routing($subscriptionid);
132
    $subs->{'hasRouting'} = GetRoutingListsCount($subscriptionid);
132
    push @$subscriptiondescs,$subs;
133
    push @$subscriptiondescs,$subs;
133
    my $tmpsubscription= GetFullSubscription($subscriptionid);
134
    my $tmpsubscription= GetFullSubscription($subscriptionid);
134
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
135
    @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
Lines 147-154 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1) Link Here
147
my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
148
my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
148
my $subscriptionidlist="";
149
my $subscriptionidlist="";
149
foreach my $subscription (@$subscriptiondescs){
150
foreach my $subscription (@$subscriptiondescs){
150
  $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
151
    $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
151
  $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
152
    $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
153
    $subscription->{routinglistscount}
154
        = GetRoutingListsCount($subscription->{subscriptionid});
152
}
155
}
153
156
154
# warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
157
# warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
(-)a/serials/serials-search.pl (-1 / +4 lines)
Lines 35-40 use C4::Branch; Link Here
35
use C4::Context;
35
use C4::Context;
36
use C4::Output;
36
use C4::Output;
37
use C4::Serials;
37
use C4::Serials;
38
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
38
39
39
use Koha::DateUtils;
40
use Koha::DateUtils;
40
41
Lines 97-103 if ($searched){ Link Here
97
# to toggle between create or edit routing list options
98
# to toggle between create or edit routing list options
98
if ($routing) {
99
if ($routing) {
99
    for my $subscription ( @subscriptions) {
100
    for my $subscription ( @subscriptions) {
100
        $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
101
        $subscription->{routinglistscount}
102
            = GetRoutingListsCount($subscription->{subscriptionid});
103
        $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} );
101
    }
104
    }
102
}
105
}
103
106
(-)a/serials/subscription-detail.pl (-1 / +2 lines)
Lines 23-28 use C4::Budgets; Link Here
23
use C4::Koha;
23
use C4::Koha;
24
use C4::Dates qw/format_date/;
24
use C4::Dates qw/format_date/;
25
use C4::Serials;
25
use C4::Serials;
26
use C4::Serials::RoutingLists qw/GetRoutingListsCount/;
26
use C4::Output;
27
use C4::Output;
27
use C4::Context;
28
use C4::Context;
28
use C4::Search qw/enabled_staff_search_views/;
29
use C4::Search qw/enabled_staff_search_views/;
Lines 92-98 if ($op eq 'del') { Link Here
92
        exit;
93
        exit;
93
    }
94
    }
94
}
95
}
95
my $hasRouting = check_routing($subscriptionid);
96
my $hasRouting = GetRoutingListsCount($subscriptionid);
96
97
97
(undef, $cookie, undef, undef)
98
(undef, $cookie, undef, undef)
98
    = checkauth($query, 0, {catalogue => 1}, "intranet");
99
    = checkauth($query, 0, {catalogue => 1}, "intranet");
(-)a/t/db_dependent/Serials.t (-6 / +1 lines)
Lines 15-21 use C4::Bookseller; Link Here
15
use C4::Biblio;
15
use C4::Biblio;
16
use C4::Budgets;
16
use C4::Budgets;
17
use Koha::DateUtils;
17
use Koha::DateUtils;
18
use Test::More tests => 46;
18
use Test::More tests => 44;
19
19
20
BEGIN {
20
BEGIN {
21
    use_ok('C4::Serials');
21
    use_ok('C4::Serials');
Lines 186-195 is(C4::Serials::updateClaim(),undef, 'test updating claim'); Link Here
186
186
187
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
187
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
188
188
189
is(C4::Serials::check_routing(), undef, 'test checking route');
190
191
is(C4::Serials::addroutingmember(),undef, 'test adding route member');
192
193
189
194
# Unit tests for statuses management (Bug 11689)
190
# Unit tests for statuses management (Bug 11689)
195
$subscriptionid = NewSubscription(
191
$subscriptionid = NewSubscription(
196
- 

Return to bug 7957