From c67c0beba12a552c1551de0e8448c0ea006866be Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 17 Apr 2012 14:08:46 +0200 Subject: [PATCH] Bug 7957: Routing lists enhancements - Manage several routing list per subscription - Export a routing list as CSV Test plan: Run the updatedatabase.pl script Existing routing lists should have been imported in a routing list named 'import' From the serials-home.pl page: 1 Make a search, in the results list you have a column 'Actions' that should contain a "New/Edit routing list" link" (if not, consider setting RoutingSerials syspref). If the subscription doesn't have a routing list, you should have a 'New routing list' link. Otherwise you have an 'Edit routing lists (X)' link, where X is the number of routing lists. 2 Choose a subscription which have no routing lists and click on 'New routing list' 3 You are on the routing list creation page. Enter a title for the routing list and click on 'Save'. 4 The routing list has been created and now you are on the routing list modification page. The behaviour of this page is quite the same as before. A sensible change is that reordering borrowers doesn't reload the page each time you make a change. 5 Click on 'Save' to finish routing list modifications. 6 Now you are on the routing lists management page. You can edit a routing list by clicking on its title, preview it, export it, and delete it by clicking on the corresponding link. 7 Click on 'Preview'. 8 You will be asked to choose a serial. Pick the one you want to print the routing list for and click on 'Continue'. 9 If RoutingListAddReserves is OFF, the routing list is displayed and you just have to click on 'Print'. If the syspref is ON, you will have to click on 'Confirm and print', an alert will show telling you that holds will be placed on the serial you chose. Click 'OK' and you will be able to print the slip. Now check if the holds have been placed. (It works only if an item is attached to this serial). 10 Go back to the routing lists management page (routinglists.pl) and click on 'Export'. Download the CSV and check that it contains correct data. From serials-collection.pl page: 11 In the serials list, click on 'Print list'. 12 You will be asked to choose a routing list. Pick one and click on 'Continue'. 13 ... (same behaviour as above) Try to add and delete routing lists to show if links are correctly updated in serials-home.pl, serials-collection.pl and subscription-detail.pl Signed-off-by: Paola Rossi Signed-off-by: Aleisha --- C4/Items.pm | 2 +- C4/Serials.pm | 238 +++++------------- C4/Serials/RoutingLists.pm | 274 +++++++++++++++++++++ acqui/newordersubscription.pl | 3 +- installer/data/mysql/atomicupdate/bug_7957.perl | 67 +++++ installer/data/mysql/kohastructure.sql | 46 ++-- .../prog/en/includes/serials-menu.inc | 4 +- .../prog/en/includes/serials-toolbar.inc | 7 + .../prog/en/modules/members/routing-lists.tt | 75 +++--- .../en/modules/serials/routing-preview-slip.tt | 116 +++++++-- .../prog/en/modules/serials/routing-preview.tt | 57 ----- .../prog/en/modules/serials/routing.tt | 111 --------- .../prog/en/modules/serials/routinglist.tt | 196 +++++++++++++++ .../prog/en/modules/serials/routinglists.tt | 69 ++++++ .../prog/en/modules/serials/serials-collection.tt | 13 +- .../prog/en/modules/serials/serials-search.tt | 16 +- members/routing-lists.pl | 16 +- serials/reorder_members.pl | 38 --- serials/routing-preview-slip.pl | 143 +++++++++++ serials/routing-preview.pl | 143 ----------- serials/routing.pl | 127 ---------- serials/routinglist.pl | 114 +++++++++ serials/routinglists.pl | 79 ++++++ serials/serials-collection.pl | 9 +- serials/serials-search.pl | 5 +- serials/subscription-detail.pl | 3 +- t/db_dependent/Serials.t | 6 +- 27 files changed, 1207 insertions(+), 770 deletions(-) create mode 100644 C4/Serials/RoutingLists.pm create mode 100644 installer/data/mysql/atomicupdate/bug_7957.perl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt delete mode 100755 serials/reorder_members.pl create mode 100755 serials/routing-preview-slip.pl delete mode 100755 serials/routing-preview.pl delete mode 100755 serials/routing.pl create mode 100755 serials/routinglist.pl create mode 100755 serials/routinglists.pl diff --git a/C4/Items.pm b/C4/Items.pm index 7f9a3da..f183c6b 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -176,7 +176,7 @@ sub GetItem { #if we don't have an items.itype, use biblioitems.itemtype. # FIXME this should respect the itypes systempreference # if (C4::Context->preference('item-level_itypes')) { - if( ! $data->{'itype'} ) { + if( $data and ! $data->{'itype'} ) { my $sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); $sth->execute($data->{'biblionumber'}); ($data->{'itype'}) = $sth->fetchrow_array; diff --git a/C4/Serials.pm b/C4/Serials.pm index eca9b13..fd83da9 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -76,13 +76,12 @@ BEGIN { &ReNewSubscription &GetLateOrMissingIssues &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected + &GetSerial &GetSerialItemnumber &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid &GetDistributedTo &SetDistributedTo - &getroutinglist &delroutingmember &addroutingmember - &reorder_members - &check_routing &updateClaim + &updateClaim &CountIssues HasItems &GetSubscriptionsFromBorrower @@ -163,6 +162,60 @@ sub GetSubscriptionHistoryFromSubscriptionId { return $results; } +=head2 GetSerial + + my $serial = &GetSerial($serialid); + +This sub returns serial informations (ie. in serial table) for given $serialid +It returns a hashref where each key is a sql column. + +=cut + +sub GetSerial { + my ($serialid) = @_; + + return unless $serialid; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT * + FROM serial + WHERE serialid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($serialid); + return $sth->fetchrow_hashref; +} + +=head2 GetSerialItemnumber + + my $itemnumber = GetSerialItemnumber($serialid); + +Returns the itemnumber associated to $serialid or undef if there is no item. + +=cut + +sub GetSerialItemnumber { + my ($serialid) = @_; + + return unless $serialid; + my $itemnumber; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT itemnumber + FROM serialitems + WHERE serialid = ? + }; + my $sth = $dbh->prepare($query); + my $rv = $sth->execute($serialid); + if ($rv) { + my $result = $sth->fetchrow_hashref; + $itemnumber = $result->{itemnumber}; + } + return $itemnumber; +} + =head2 GetSerialStatusFromSerialId $sth = GetSerialStatusFromSerialId(); @@ -701,7 +754,7 @@ sub GetSerials { my @serials; my $statuses = join( ',', ( ARRIVED, MISSING_STATUSES, NOT_ISSUED ) ); my $query = "SELECT serialid,serialseq, status, publisheddate, - publisheddatetext, planneddate,notes, routingnotes + publisheddatetext, planneddate, notes FROM serial WHERE subscriptionid = ? AND status NOT IN ( $statuses ) ORDER BY IF(publisheddate<>'0000-00-00',publisheddate,planneddate) DESC"; @@ -722,7 +775,7 @@ sub GetSerials { # OK, now add the last 5 issues arrives/missing $query = "SELECT serialid,serialseq, status, planneddate, publisheddate, - publisheddatetext, notes, routingnotes + publisheddatetext, notes FROM serial WHERE subscriptionid = ? AND status IN ( $statuses ) @@ -772,7 +825,7 @@ sub GetSerials2 { my $dbh = C4::Context->dbh; my $query = qq| SELECT serialid,serialseq, status, planneddate, publisheddate, - publisheddatetext, notes, routingnotes + publisheddatetext, notes FROM serial WHERE subscriptionid=$subscription AND status IN ($statuses_string) ORDER BY publisheddate,serialid DESC @@ -1932,161 +1985,6 @@ sub getsupplierbyserialid { return $result; } -=head2 check_routing - -$result = &check_routing($subscriptionid) - -this function checks to see if a serial has a routing list and returns the count of routingid -used to show either an 'add' or 'edit' link - -=cut - -sub check_routing { - my ($subscriptionid) = @_; - - return unless ($subscriptionid); - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - "SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist - ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid - WHERE subscription.subscriptionid = ? ORDER BY ranking ASC - " - ); - $sth->execute($subscriptionid); - my $line = $sth->fetchrow_hashref; - my $result = $line->{'routingids'}; - return $result; -} - -=head2 addroutingmember - -addroutingmember($borrowernumber,$subscriptionid) - -this function takes a borrowernumber and subscriptionid and adds the member to the -routing list for that serial subscription and gives them a rank on the list -of either 1 or highest current rank + 1 - -=cut - -sub addroutingmember { - my ( $borrowernumber, $subscriptionid ) = @_; - - return unless ($borrowernumber and $subscriptionid); - - my $rank; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( "SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?" ); - $sth->execute($subscriptionid); - while ( my $line = $sth->fetchrow_hashref ) { - if ( $line->{'rank'} > 0 ) { - $rank = $line->{'rank'} + 1; - } else { - $rank = 1; - } - } - $sth = $dbh->prepare( "INSERT INTO subscriptionroutinglist (subscriptionid,borrowernumber,ranking) VALUES (?,?,?)" ); - $sth->execute( $subscriptionid, $borrowernumber, $rank ); -} - -=head2 reorder_members - -reorder_members($subscriptionid,$routingid,$rank) - -this function is used to reorder the routing list - -it takes the routingid of the member one wants to re-rank and the rank it is to move to -- it gets all members on list puts their routingid's into an array -- removes the one in the array that is $routingid -- then reinjects $routingid at point indicated by $rank -- then update the database with the routingids in the new order - -=cut - -sub reorder_members { - my ( $subscriptionid, $routingid, $rank ) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( "SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC" ); - $sth->execute($subscriptionid); - my @result; - while ( my $line = $sth->fetchrow_hashref ) { - push( @result, $line->{'routingid'} ); - } - - # To find the matching index - my $i; - my $key = -1; # to allow for 0 being a valid response - for ( $i = 0 ; $i < @result ; $i++ ) { - if ( $routingid == $result[$i] ) { - $key = $i; # save the index - last; - } - } - - # if index exists in array then move it to new position - if ( $key > -1 && $rank > 0 ) { - my $new_rank = $rank - 1; # $new_rank is what you want the new index to be in the array - my $moving_item = splice( @result, $key, 1 ); - splice( @result, $new_rank, 0, $moving_item ); - } - for ( my $j = 0 ; $j < @result ; $j++ ) { - my $sth = $dbh->prepare( "UPDATE subscriptionroutinglist SET ranking = '" . ( $j + 1 ) . "' WHERE routingid = '" . $result[$j] . "'" ); - $sth->execute; - } - return; -} - -=head2 delroutingmember - -delroutingmember($routingid,$subscriptionid) - -this function either deletes one member from routing list if $routingid exists otherwise -deletes all members from the routing list - -=cut - -sub delroutingmember { - - # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid - my ( $routingid, $subscriptionid ) = @_; - my $dbh = C4::Context->dbh; - if ($routingid) { - my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); - $sth->execute($routingid); - reorder_members( $subscriptionid, $routingid ); - } else { - my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); - $sth->execute($subscriptionid); - } - return; -} - -=head2 getroutinglist - -@routinglist = getroutinglist($subscriptionid) - -this gets the info from the subscriptionroutinglist for $subscriptionid - -return : -the routinglist as an array. Each element of the array contains a hash_ref containing -routingid - a unique id, borrowernumber, ranking, and biblionumber of subscription - -=cut - -sub getroutinglist { - my ($subscriptionid) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - 'SELECT routingid, borrowernumber, ranking, biblionumber - FROM subscription - JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid - WHERE subscription.subscriptionid = ? ORDER BY ranking ASC' - ); - $sth->execute($subscriptionid); - my $routinglist = $sth->fetchall_arrayref({}); - return @{$routinglist}; -} - =head2 countissuesfrom $result = countissuesfrom($subscriptionid,$startdate) @@ -2224,21 +2122,17 @@ sub GetSubscriptionsFromBorrower { my ($borrowernumber) = @_; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( - "SELECT subscription.subscriptionid, biblio.title - FROM subscription + "SELECT subscriptionroutinglist.*, biblio.title AS bibliotitle + FROM subscriptionroutinglist + JOIN subscriptionrouting ON (subscriptionroutinglist.routinglistid = subscriptionrouting.routinglistid) + JOIN subscription ON (subscriptionroutinglist.subscriptionid = subscription.subscriptionid) JOIN biblio ON biblio.biblionumber = subscription.biblionumber - JOIN subscriptionroutinglist USING (subscriptionid) - WHERE subscriptionroutinglist.borrowernumber = ? ORDER BY title ASC + WHERE subscriptionrouting.borrowernumber = ? ORDER BY title ASC " ); $sth->execute($borrowernumber); - my @routinglist; - my $count = 0; - while ( my $line = $sth->fetchrow_hashref ) { - $count++; - push( @routinglist, $line ); - } - return ( $count, @routinglist ); + my $routinglists = $sth->fetchall_arrayref({}); + return $routinglists ? @$routinglists : (); } diff --git a/C4/Serials/RoutingLists.pm b/C4/Serials/RoutingLists.pm new file mode 100644 index 0000000..0c38313 --- /dev/null +++ b/C4/Serials/RoutingLists.pm @@ -0,0 +1,274 @@ +package C4::Serials::RoutingLists; + +# Copyright 2012 Biblibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use C4::Context; + +use vars qw($VERSION @ISA @EXPORT_OK); + +BEGIN { + $VERSION = 3.01; + require Exporter; + @ISA = qw(Exporter); + @EXPORT_OK = qw( + &AddRoutingList + &ModRoutingList + &DelRoutingList + &GetRoutingList + &GetRoutingLists + &GetRoutingListsCount + &GetRoutingListAsCSV + ); +} + +=head2 AddRoutingList + +$routinglistid = &AddRoutingList($subscriptionid, $title); + +this function create a new routing list for a subscription. + +=cut + +sub AddRoutingList { + my ($subscriptionid, $title) = @_; + + my $dbh = C4::Context->dbh(); + my $query = qq{ + INSERT INTO subscriptionroutinglist (subscriptionid, title) + VALUES (?, ?) + }; + my $sth = $dbh->prepare($query); + $sth->execute($subscriptionid, $title); + + return $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef); +} + +=head2 ModRoutingList + +&ModRoutingList($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers); + +this function modifies a routing list. + +=cut + +sub ModRoutingList { + my ($routinglistid, $subscriptionid, $title, $notes, @borrowernumbers) = @_; + + my $dbh = C4::Context->dbh; + my $query = 'UPDATE subscriptionroutinglist'; + my @setstrings = (); + my @setargs = (); + if($subscriptionid) { + push @setstrings, 'subscriptionid = ?'; + push @setargs, $subscriptionid; + } + if($title) { + push @setstrings, 'title = ?'; + push @setargs, $title; + } + if($notes) { + push @setstrings, 'notes = ?'; + push @setargs, $notes; + } + + if(@setstrings) { + $query .= ' SET ' . join(',', @setstrings); + $query .= ' WHERE routinglistid = ?'; + my $sth = $dbh->prepare($query); + $sth->execute(@setargs, $routinglistid); + } + + $query = qq{ + DELETE FROM subscriptionrouting + WHERE routinglistid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($routinglistid); + + if(@borrowernumbers > 0){ + $query = qq{ + INSERT INTO subscriptionrouting (routinglistid, borrowernumber, ranking) + VALUES (?, ?, ?) + }; + $sth = $dbh->prepare($query); + my $i = 1; + foreach (@borrowernumbers) { + $sth->execute($routinglistid, $_, $i); + $i++; + } + } +} + +=head2 DelRoutingList + +&DelRoutingList($routinglistid); + +this function delete a routing list. + +=cut + +sub DelRoutingList { + my ($routinglistid) = @_; + + my $dbh = C4::Context->dbh; + my $query = qq{ + DELETE FROM subscriptionroutinglist + WHERE routinglistid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($routinglistid); +} + + +=head2 GetRoutingList + +$routinglist = &GetRoutingList($routinglistid); + +this function get infos from subscriptionroutinglist table. +The 'borrowers' keys contains the list of borrowernumbers attached +to this routing list. + +=cut + +sub GetRoutingList { + my ($routinglistid) = @_; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT * + FROM subscriptionroutinglist + WHERE routinglistid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($routinglistid); + my $result = $sth->fetchrow_hashref; + + $query = qq{ + SELECT borrowernumber + FROM subscriptionrouting + WHERE routinglistid = ? + ORDER BY ranking ASC + }; + $sth = $dbh->prepare($query); + $sth->execute($routinglistid); + while (my $row = $sth->fetchrow_hashref) { + push @{$result->{borrowers}}, $row->{borrowernumber}; + } + + return $result; +} + +=head2 GetRoutingLists + +$routinglists = &GetRoutingLists($subscriptionid); + +this function get all routing lists for a subscription. + +=cut + +sub GetRoutingLists { + my ($subscriptionid) = @_; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT routinglistid + FROM subscriptionroutinglist + WHERE subscriptionid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($subscriptionid); + my @results; + while (my $row = $sth->fetchrow_hashref) { + my $routinglistid = $row->{routinglistid}; + push @results, GetRoutingList($routinglistid); + } + + return @results; +} + +=head2 GetRoutingListsCount + +$count = &GetRoutingListsCount($subscriptionid); + +this function return the number of routing lists for a subscription. + +=cut + +sub GetRoutingListsCount { + my ($subscriptionid) = @_; + + return unless $subscriptionid; + + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT COUNT(*) AS count + FROM subscriptionroutinglist + WHERE subscriptionid = ? + }; + my $sth = $dbh->prepare($query); + $sth->execute($subscriptionid); + my $result = $sth->fetchrow_hashref; + + return $result->{count}; +} + +=head2 GetRoutingListAsCSV + +$csv_output = &GetRoutingListAsCSV($routinglistid); + +this function return the routing list as a CSV file. + +=cut + +sub GetRoutingListAsCSV { + my ($routinglistid) = @_; + + require C4::Biblio; + require C4::Serials; + require C4::Members; + require Text::CSV::Encoded; + + my $csv = Text::CSV::Encoded->new( {encoding => "utf8" } ); + my $output; + + my $routinglist = GetRoutingList($routinglistid); + my $subscription = C4::Serials::GetSubscription($routinglist->{'subscriptionid'}); + my $biblio = C4::Biblio::GetBiblio($subscription->{'biblionumber'}); + + my @headers = ("Subscription title", "Routing list", qw(Surname Firstname Notes)); + $csv->combine(@headers); + $output .= $csv->string() . "\n"; + + foreach (@{$routinglist->{borrowers}}) { + my $member = C4::Members::GetMemberDetails($_); + $csv->combine( + $biblio->{'title'}, + $routinglist->{'title'}, + $member->{'surname'}, + $member->{'firstname'}, + $routinglist->{'notes'}, + ); + $output .= $csv->string() . "\n"; + } + + return $output; +} + +1; diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl index 7353dc9..d05a7ff 100755 --- a/acqui/newordersubscription.pl +++ b/acqui/newordersubscription.pl @@ -25,6 +25,7 @@ use C4::Branch; use C4::Context; use C4::Output; use C4::Serials; +use C4::Serials::RoutingLists qw( GetRoutingListsCount ); use Koha::Acquisition::Bookseller; @@ -72,7 +73,7 @@ foreach my $sub (@subscriptions) { # to toggle between create or edit routing list options if ($routing) { - $sub->{routingedit} = check_routing( $sub->{subscriptionid} ); + $sub->{routingedit} = GetRoutingListsCount( $sub->{subscriptionid} ); } } diff --git a/installer/data/mysql/atomicupdate/bug_7957.perl b/installer/data/mysql/atomicupdate/bug_7957.perl new file mode 100644 index 0000000..2f8ca30 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_7957.perl @@ -0,0 +1,67 @@ +use Modern::Perl; +use C4::Context; + +my $dbh = C4::Context->dbh; +$dbh->do("RENAME TABLE subscriptionroutinglist TO tmp_subscriptionroutinglist"); +$dbh->do(" + CREATE TABLE subscriptionroutinglist ( + routinglistid int(11) NOT NULL AUTO_INCREMENT, + subscriptionid int(11) NOT NULL, + title varchar(256) NOT NULL, + notes text default NULL, + PRIMARY KEY (routinglistid), + CONSTRAINT subscriptionroutinglist_ibfk_1 FOREIGN KEY (subscriptionid) + REFERENCES subscription (subscriptionid) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 +"); +$dbh->do(" + CREATE TABLE subscriptionrouting ( + routinglistid int(11) NOT NULL, + borrowernumber int(11) NOT NULL, + ranking int(11) DEFAULT NULL, + PRIMARY KEY (routinglistid, borrowernumber), + CONSTRAINT subscriptionrouting_ibfk_1 FOREIGN KEY (routinglistid) + REFERENCES subscriptionroutinglist (routinglistid) ON DELETE CASCADE, + CONSTRAINT subscriptionrouting_ibfk_2 FOREIGN KEY (borrowernumber) + REFERENCES borrowers (borrowernumber) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 +"); + +# Migrate data from old subscriptionroutinglist table +my $query = qq{ + SELECT serial.subscriptionid, serial.routingnotes + FROM tmp_subscriptionroutinglist + LEFT JOIN serial ON (tmp_subscriptionroutinglist.subscriptionid = serial.subscriptionid) + GROUP BY serial.subscriptionid +}; +my $sth = $dbh->prepare($query); +$sth->execute(); +my $results = $sth->fetchall_arrayref( {} ); +$query = qq{ + INSERT INTO subscriptionroutinglist (subscriptionid, title, notes) + VALUES (?, ?, ?) +}; +$sth = $dbh->prepare($query); +$query = qq{ + SELECT borrowernumber, ranking + FROM tmp_subscriptionroutinglist + WHERE subscriptionid = ? +}; +my $select_sth = $dbh->prepare($query); +$query = qq{ + INSERT INTO subscriptionrouting (routinglistid, borrowernumber, ranking) + VALUES(?, ?, ?) +}; +my $insert_sth = $dbh->prepare($query); +foreach ( @$results ) { + $sth->execute($_->{subscriptionid}, 'import', $_->{routingnotes}); + my $routinglistid = $dbh->last_insert_id(undef, undef, 'subscriptionroutinglist', undef); + $select_sth->execute($_->{subscriptionid}); + my $routings = $select_sth->fetchall_arrayref( {} ); + foreach (@$routings) { + $insert_sth->execute($routinglistid, $_->{borrowernumber}, $_->{ranking}); + } +} + +$dbh->do("DROP TABLE tmp_subscriptionroutinglist"); +$dbh->do("ALTER TABLE serial DROP COLUMN routingnotes"); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e6e3142..8364e6c 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2181,21 +2181,37 @@ CREATE TABLE `subscriptionhistory` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- --- Table structure for table `subscriptionroutinglist` --- - -DROP TABLE IF EXISTS `subscriptionroutinglist`; -CREATE TABLE `subscriptionroutinglist` ( -- information related to the routing lists attached to subscriptions - `routingid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha - `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines with patron is on the routing list - `ranking` int(11) default NULL, -- where the patron stands in line to receive the serial - `subscriptionid` int(11) NOT NULL, -- foreign key from the subscription table, defines which subscription this routing list is for - PRIMARY KEY (`routingid`), - UNIQUE (`subscriptionid`, `borrowernumber`), - CONSTRAINT `subscriptionroutinglist_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) - ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `subscriptionroutinglist_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) - ON DELETE CASCADE ON UPDATE CASCADE +-- Table structure for table subscriptionroutinglist +-- + +DROP TABLE IF EXISTS subscriptionroutinglist; +CREATE TABLE subscriptionroutinglist ( + routinglistid int(11) NOT NULL AUTO_INCREMENT, -- unique identifier assigned by Koha + subscriptionid int(11) NOT NULL, -- foreign key from the subscription table, + -- defines which subscription this routing list is for + title varchar(256) NOT NULL, -- title of this routing list + notes text default NULL, -- notes for this routing list + PRIMARY KEY (routinglistid), + CONSTRAINT subscriptionroutinglist_ibfk_1 FOREIGN KEY (subscriptionid) + REFERENCES subscription (subscriptionid) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Table structure for subscriptionrouting +-- + +DROP TABLE IF EXISTS subscriptionrouting; +CREATE TABLE subscriptionrouting ( + routinglistid int(11) NOT NULL, -- foreign key from the subscriptionroutinglist + -- table, defines which routing list is affected + borrowernumber int(11) NOT NULL, -- foreign key from the borrowers table, + -- defines which patron is on the routing list + ranking int(11) DEFAULT NULL, -- where the patron stands in line to receive the serial + PRIMARY KEY (routinglistid, borrowernumber), + CONSTRAINT subscriptionrouting_ibfk_1 FOREIGN KEY (routinglistid) + REFERENCES subscriptionroutinglists (routinglistid) ON DELETE CASCADE, + CONSTRAINT subscriptionrouting_ibfk_2 FOREIGN KEY (borrowernumber) + REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc index 21dff3a..00e9751 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc @@ -4,9 +4,9 @@ [% UNLESS closed %] [% IF ( routing && CAN_user_serials_routing ) %] [% IF ( hasRouting ) %] -
  • Edit routing list
  • +
  • Edit routing list
  • [% ELSE %] -
  • Create routing list
  • +
  • Create routing list
  • [% END %] [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc index 2581be2..d88780f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc @@ -13,6 +13,13 @@ window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen"; } } + function confirm_deletion() { + var is_confirmed = confirm(_("Are you sure you want to delete this subscription?")); + if (is_confirmed) { + window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=del"; + } + } + $(document).ready(function() { $("#deletesub").click(function(){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt index d9d540e..7cccf5b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/routing-lists.tt @@ -23,50 +23,47 @@

    -[% IF ( countSubscrip ) %] -[% countSubscrip %] Subscription routing list(s) +[% IF ( routinglists.size > 0 ) %] + [% routinglists.size %] Subscription routing list(s) [% ELSE %] -0 Subscription routing lists + 0 Subscription routing lists [% END %]

    -[% IF ( subscripLoop ) %] - - - - - - - - -[% FOREACH subscripLoop IN subscripLoop %] - - - - - [% END %] - -
    Subscription titleRouting list
    - - [% subscripLoop.title %] - - - - - Edit routing list - - - - -
    - - [% ELSE %] -

    Patron does not belong to any subscription routing lists.

    - - - [% END %] - + [% IF ( routinglists.size > 0 ) %] + + + + + + + + + + [% FOREACH routinglist IN routinglists %] + + + + + + [% END %] + +
    Subscription titleRouting listActions
    + + + [% routinglist.bibliotitle %] + + + [% routinglist.title %] + + Edit routing list + + +
    + [% ELSE %] +

    Patron does not belong to any subscription routing lists.

    + [% END %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt index 5a23158..8ce74df 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview-slip.tt @@ -14,34 +14,100 @@
    - - - - - - - - - - - - [% FOREACH memberloo IN memberloop %] - - - - +[% IF (missing_parameter_routinglistid or missing_parameter_serialid) %] +

    Routing list preview for [% title %]

    + + + [% IF (missing_parameter_routinglistid) %] + + + + [% ELSE %] + + + + [% END %] + + +[% ELSE %] + [% IF (error_no_item) %] +
    +

    Holds cannot be placed on this serial. There is no item attached to it.

    +
    [% END %] -

    [% libraryname %]

    Title: [% title |html %]
    [% issue %]
    NameDate due
    [% memberloo.name %] 
    + + [% IF (libraryname) %] + + + + [% END %] + + + + + + + + + + + [% FOREACH member IN memberloop %] + + + + + [% END %] +

    [% libraryname %]

    + Title: [% title %]
    + [% serial.serialseq %] ([% serial.planneddate %]) +
    + Routing list: [% routinglisttitle %] +
    NameDate due
    [% member.surname %], [% member.firstname %] 
    -
    -

    [% generalroutingnote %]

    -

    [% routingnotes %]

    -
    +
    +

    [% generalroutingnote %]

    +

    [% routingnotes %]

    +
    - + [% IF (need_confirm) %] + [%# RoutingListAddReserves is ON %] + +
    + + + + + +
    + [% ELSE %] + + [% END %] +[% END %] -
    +
    [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt deleted file mode 100644 index 6892e1c..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing-preview.tt +++ /dev/null @@ -1,57 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Serials › Preview routing list -[% INCLUDE 'doc-head-close.inc' %] - - - -[% INCLUDE 'header.inc' %] -[% INCLUDE 'serials-search.inc' %] - - - -
    - -
    -
    -
    - -

    Preview routing list for [% title |html %]

    - -
    - -
    -
      -
    1. Issue:[% issue %]
    2. -
    3. List member: - -[% FOREACH memberloo IN memberloop %] - -[% END %] -
      Name
      [% memberloo.surname %], [% memberloo.firstname %]
    4. -
    5. Notes:[% routingnotes %]
    6. -
    -
    - -
    - - -
    -
    - -
    -
    - -
    -[% INCLUDE 'serials-menu.inc' %] -
    -
    -[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt deleted file mode 100644 index 6fccab8..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt +++ /dev/null @@ -1,111 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Serials › [% title |html %] › [% IF ( op ) %]Create Routing List[% ELSE %]Edit routing list[% END %] -[% INCLUDE 'doc-head-close.inc' %] - - - -[% INCLUDE 'header.inc' %] -[% INCLUDE 'serials-search.inc' %] - - - -
    - -
    -
    -
    - - -[% IF ( op ) %] -

    Create routing list for [% title |html %]

    -[% ELSE %] -

    Edit routing list for [% title |html %]

    -[% END %] - -
    - - -
    -
      -
    1. - [% issue %]
    2. - -
    3. - Recipients: - [% IF memberloop %] - - - - - - [% USE m_loop = iterator(memberloop) %] - [% FOREACH member IN m_loop %] - - - - - [% END %] -
      NameRankDelete
      [% member.name %] - - Delete
      - [% END %] - -

      - - [% IF memberloop %] - Delete all - [% END %] -

      -
    4. - -
    5. -
    - -
    -
    -
    - - -
    -
    - -
    -[% INCLUDE 'serials-menu.inc' %] -
    -
    -[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt new file mode 100644 index 0000000..fb1d377 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglist.tt @@ -0,0 +1,196 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Serials › Routing list +[% INCLUDE 'doc-head-close.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'serials-search.inc' %] + + + +
    + +
    +
    +
    + [% INCLUDE 'serials-toolbar.inc' %] + [% IF ( new ) %] +

    Create routing list

    + +
    + + + + + +
    + [% ELSE %] +

    Routing list '[% title %]'

    + Add a borrower + [% IF ( borrowers_loop ) %] + + [% ELSE %] +
    + [% END %] + + + + + + + + + [% FOREACH borrower IN borrowers_loop %] + + + + + + [% END %] + + + [% UNLESS ( borrowers_loop ) %] +

    There is no borrowers in this routing list.

    + [% END %] +
    + + + +
    +
    + + +
    + [% END %] +
    +
    +
    + [% INCLUDE 'serials-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt new file mode 100644 index 0000000..11ab8d8 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/routinglists.tt @@ -0,0 +1,69 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Serials › Routing lists +[% INCLUDE 'doc-head-close.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'serials-search.inc' %] + + + +
    + +
    +
    +
    + [% INCLUDE 'serials-toolbar.inc' %] +

    Routing lists for [% title %]

    + + New routing list + + [% IF ( routinglists_loop ) %] + + + + + + + + + + + [% FOREACH routinglist IN routinglists_loop %] + + + + + + + [% END %] + +
    TitleNo. of borrowersNotes 
    [% routinglist.title %][% routinglist.borrowers.size || 0 %][% routinglist.notes %] + Preview | + Export | + Delete
    + [% ELSE %] +

    There is no routing lists for this subscription.

    + [% END %] + +
    +
    +
    + [% INCLUDE 'serials-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt index ad60863..9ba61f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt @@ -15,10 +15,11 @@ function generateReceive(subscriptionid) { document.location = 'serials-collection.pl?op=gennext&subscriptionid='+subscriptionid+'&nbissues='+nbissues; } } -function print_slip(subscriptionid,issue){ - var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue; +function print_slip(serialid){ + var myurl = '/cgi-bin/koha/serials/routing-preview-slip.pl?serialid='+serialid; window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes'); } + function addsubscriptionid() { var tab=new Array(); @@ -135,10 +136,10 @@ $(document).ready(function() { [% IF ( routing && CAN_user_serials_routing ) %] [% UNLESS subscription.closed %] - [% IF ( subscription.hasRouting ) %] - Edit routing list + [% IF (subscription.routinglistscount) %] + Edit routing lists ([% subscription.routinglistscount %]) [% ELSE %] - Create routing list + New routing list [% END %] [% END %] @@ -304,7 +305,7 @@ $(document).ready(function() { [% IF ( routing ) %] - Print list + Print list [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index ed2ac49..e6c0c45 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -218,15 +218,13 @@ [% IF ( routing && CAN_user_serials_routing ) %] [% IF ( subscription.cannotedit ) %] [% ELSE %] - [% IF ( subscription.routingedit ) %] -
  • - Edit routing list ([% subscription.routingedit %]) -
  • - [% ELSE %] -
  • - New routing list -
  • - [% END %] +
  • + [% IF ( subscription.routinglistscount ) %] + Edit routing list ([% subscription.routinglistscount %]) + [% ELSE %] + New routing list + [% END %] +
  • [% END %] [% END # IF ( routing && CAN_user_serials_routing ) %] diff --git a/members/routing-lists.pl b/members/routing-lists.pl index 1925880..3da724f 100755 --- a/members/routing-lists.pl +++ b/members/routing-lists.pl @@ -77,22 +77,10 @@ if ($borrowernumber) { if ($borrowernumber) { # new op dev - my $count; - my @borrowerSubscriptions; - ($count, @borrowerSubscriptions) = GetSubscriptionsFromBorrower($borrowernumber ); - my @subscripLoop; - - foreach my $num_res (@borrowerSubscriptions) { - my %getSubscrip; - $getSubscrip{subscriptionid} = $num_res->{'subscriptionid'}; - $getSubscrip{title} = $num_res->{'title'}; - $getSubscrip{borrowernumber} = $num_res->{'borrowernumber'}; - push( @subscripLoop, \%getSubscrip ); - } + my @routinglists = GetSubscriptionsFromBorrower($borrowernumber ); $template->param( - countSubscrip => scalar @subscripLoop, - subscripLoop => \@subscripLoop, + routinglists => \@routinglists, routinglistview => 1 ); diff --git a/serials/reorder_members.pl b/serials/reorder_members.pl deleted file mode 100755 index 3e0b86a..0000000 --- a/serials/reorder_members.pl +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/perl -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -# Routing.pl script used to create a routing list for a serial subscription -# In this instance it is in fact a setting up of a list of reserves for the item -# where the hierarchical order can be changed on the fly and a routing list can be -# printed out -use strict; -use warnings; -use CGI qw ( -utf8 ); -use C4::Auth qw( checkauth ); -use C4::Serials qw( reorder_members ); - -my $query = CGI->new; -my $subscriptionid = $query->param('subscriptionid'); -my $routingid = $query->param('routingid'); -my $rank = $query->param('rank'); - -checkauth( $query, 0, { serials => 'routing' }, 'intranet' ); - -reorder_members( $subscriptionid, $routingid, $rank ); - -print $query->redirect( - "/cgi-bin/koha/serials/routing.pl?subscriptionid=$subscriptionid"); - diff --git a/serials/routing-preview-slip.pl b/serials/routing-preview-slip.pl new file mode 100755 index 0000000..44acf21 --- /dev/null +++ b/serials/routing-preview-slip.pl @@ -0,0 +1,143 @@ +#!/usr/bin/perl + +# Copyright 2011 BibLibre SARL +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +routing-preview-slip.pl + +=head1 DESCRIPTION + +Preview a routing list for printing. + +=cut + +use Modern::Perl; + +use CGI; +use C4::Auth; +use C4::Output; + +use C4::Biblio; +use C4::Branch; +use C4::Members; +use C4::Serials; +use C4::Serials::RoutingLists qw/GetRoutingList GetRoutingLists/; + +my $input = new CGI; +my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { + template_name => 'serials/routing-preview-slip.tt', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { 'serials' => 'routing' }, + debug => 1, +} ); + +my $routinglistid = $input->param('routinglistid'); +my $serialid = $input->param('serialid'); + +if (!$routinglistid and !$serialid) { + exit; +} + +if (!$routinglistid) { + my $serial = GetSerial($serialid); + my $subscription = GetSubscription($serial->{subscriptionid}); + my $biblio = GetBiblio($subscription->{subscriptionid}); + my @routinglists = GetRoutingLists($subscription->{subscriptionid}); + $template->param( + missing_parameter_routinglistid => 1, + serialid => $serialid, + title => $biblio->{title}, + routinglists => \@routinglists + ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} elsif (!$serialid) { + my $routinglist = GetRoutingList($routinglistid); + my $subscription = GetSubscription($routinglist->{subscriptionid}); + my $biblio = GetBiblio($subscription->{subscriptionid}); + my @serials = GetSerials2($subscription->{subscriptionid}, [1,2,3,4,5,6,7]); + $template->param( + missing_parameter_serialid => 1, + routinglistid => $routinglistid, + title => $biblio->{title}, + serials => \@serials + ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} + +my $routinglist = GetRoutingList($routinglistid); +my $subscription = GetSubscription($routinglist->{subscriptionid}); +my $serial = GetSerial($serialid); +my $biblio = GetBiblio($subscription->{biblionumber}); +my @memberloop; +foreach (@{$routinglist->{borrowers}}) { + my $member = GetMemberDetails($_); + push @memberloop, { + surname => $member->{surname}, + firstname => $member->{firstname}, + }; +} + +my $no_holds = $input->param('no_holds'); +if(C4::Context->preference('RoutingListAddReserves') and !$no_holds) { + my $confirm = $input->param('confirm'); + if ($confirm) { + require C4::Reserves; + require C4::Items; + my $itemnumber = GetSerialItemnumber($serialid); + my $item = C4::Items::GetItem($itemnumber); + if ($item) { + my $rank = 1; + foreach my $borrowernumber ( @{$routinglist->{borrowers}} ) { + my $reserve = C4::Reserves::GetReserveInfo($borrowernumber, + $item->{biblionumber}); + if($reserve) { + C4::Reserves::ModReserve($rank, $item->{biblionumber}, + $borrowernumber, $item->{holdingbranch}, $itemnumber); + } else { + my @bibitems = GetBiblioItemByBiblioNumber($item->{biblionumber}); + C4::Reserves::AddReserve($item->{holdingbranch}, $borrowernumber, + $item->{biblionumber}, \@bibitems, $rank, undef, + undef, undef, $biblio->{title}, $itemnumber); + } + $rank++; + } + } else { + $template->param(error_no_item => 1); + } + } else { + $template->param(need_confirm => 1); + } +} + +$template->param( + routinglistid => $routinglistid, + serialid => $serialid, + libraryname => C4::Branch::GetBranchName($subscription->{branchcode}), + title => $biblio->{title}, + serial => $serial, + memberloop => \@memberloop, + routingnotes => $routinglist->{notes}, + generalroutingnote => C4::Context->preference('RoutingListNote'), + routinglisttitle => $routinglist->{title}, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/serials/routing-preview.pl b/serials/routing-preview.pl deleted file mode 100755 index bed5091..0000000 --- a/serials/routing-preview.pl +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -# Routing Preview.pl script used to view a routing list after creation -# lets one print out routing slip and create (in this instance) the heirarchy -# of reserves for the serial -use strict; -use warnings; -use CGI qw ( -utf8 ); -use C4::Koha; -use C4::Auth; -use C4::Output; -use C4::Acquisition; -use C4::Reserves; -use C4::Circulation; -use C4::Context; -use C4::Members; -use C4::Biblio; -use C4::Items; -use C4::Serials; -use URI::Escape; -use C4::Branch; - -my $query = new CGI; -my $subscriptionid = $query->param('subscriptionid'); -my $issue = $query->param('issue'); -my $routingid; -my $ok = $query->param('ok'); -my $edit = $query->param('edit'); -my $delete = $query->param('delete'); -my $dbh = C4::Context->dbh; - -if($delete){ - delroutingmember($routingid,$subscriptionid); - my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?"); - $sth->execute($subscriptionid); - print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new"); -} - -if($edit){ - print $query->redirect("routing.pl?subscriptionid=$subscriptionid"); -} - -my @routinglist = getroutinglist($subscriptionid); -my $subs = GetSubscription($subscriptionid); -my ($tmp ,@serials) = GetSerials($subscriptionid); -my ($template, $loggedinuser, $cookie); - -if($ok){ - # get biblio information.... - my $biblio = $subs->{'biblionumber'}; - my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio); - my @itemresults = GetItemsInfo( $subs->{biblionumber} ); - my $branch = $itemresults[0]->{'holdingbranch'}; - my $branchname = GetBranchName($branch); - - if (C4::Context->preference('RoutingListAddReserves')){ - # get existing reserves ..... - my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblio }); - my $count = scalar( @$reserves ); - my $totalcount = $count; - foreach my $res (@$reserves) { - if ($res->{'found'} eq 'W') { - $count--; - } - } - my $notes; - my $title = $subs->{'bibliotitle'}; - for my $routing ( @routinglist ) { - my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1'); - $sth->execute($biblio,$routing->{borrowernumber}); - my $reserve = $sth->fetchrow_hashref; - - if($routing->{borrowernumber} == $reserve->{borrowernumber}){ - ModReserve({ - rank => $routing->{ranking}, - biblionumber => $biblio, - borrowernumber => $routing->{borrowernumber}, - branchcode => $branch - }); - } else { - AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title); - } - } - } - - ($template, $loggedinuser, $cookie) -= get_template_and_user({template_name => "serials/routing-preview-slip.tt", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => {serials => '*'}, - debug => 1, - }); - $template->param("libraryname"=>$branchname); -} else { - ($template, $loggedinuser, $cookie) -= get_template_and_user({template_name => "serials/routing-preview.tt", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => {serials => '*'}, - debug => 1, - }); -} - -my $memberloop = []; -for my $routing (@routinglist) { - my $member = GetMember( borrowernumber => $routing->{borrowernumber} ); - $member->{name} = "$member->{firstname} $member->{surname}"; - push @{$memberloop}, $member; -} - -my $routingnotes = $serials[0]->{'routingnotes'}; -$routingnotes =~ s/\n/\
    /g; - -$template->param( - title => $subs->{'bibliotitle'}, - issue => $issue, - issue_escaped => URI::Escape::uri_escape_utf8($issue), - subscriptionid => $subscriptionid, - memberloop => $memberloop, - routingnotes => $routingnotes, - generalroutingnote => C4::Context->preference('RoutingListNote'), - hasRouting => check_routing($subscriptionid), - (uc(C4::Context->preference("marcflavour"))) => 1 - ); - -output_html_with_http_headers $query, $cookie, $template->output; diff --git a/serials/routing.pl b/serials/routing.pl deleted file mode 100755 index 32f42e5..0000000 --- a/serials/routing.pl +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - - -=head1 Routing.pl - -script used to create a routing list for a serial subscription -In this instance it is in fact a setting up of a list of reserves for the item -where the hierarchical order can be changed on the fly and a routing list can be -printed out - -=cut - -use strict; -use warnings; -use CGI qw ( -utf8 ); -use C4::Koha; -use C4::Auth; -use C4::Output; -use C4::Acquisition; -use C4::Output; -use C4::Context; - -use C4::Members; -use C4::Serials; - -use URI::Escape; - -my $query = new CGI; -my $subscriptionid = $query->param('subscriptionid'); -my $serialseq = $query->param('serialseq'); -my $routingid = $query->param('routingid'); -my $borrowernumber = $query->param('borrowernumber'); -my $notes = $query->param('notes'); -my $op = $query->param('op') || q{}; -my $date_selected = $query->param('date_selected'); -$date_selected ||= q{}; -my $dbh = C4::Context->dbh; - -if($op eq 'delete'){ - delroutingmember($routingid,$subscriptionid); -} - -if($op eq 'add'){ - addroutingmember($borrowernumber,$subscriptionid); -} -if($op eq 'save'){ - my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?'); - $sth->execute($notes,$subscriptionid); - my $urldate = URI::Escape::uri_escape_utf8($date_selected); - print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate"); -} - -my @routinglist = getroutinglist($subscriptionid); -my $subs = GetSubscription($subscriptionid); -my ($count,@serials) = GetSerials($subscriptionid); -my $serialdates = GetLatestSerials($subscriptionid,$count); - -my $dates = []; -foreach my $dateseq (@{$serialdates}) { - my $d = {}; - $d->{publisheddate} = $dateseq->{publisheddate}; - $d->{serialseq} = $dateseq->{serialseq}; - $d->{serialid} = $dateseq->{serialid}; - if($date_selected eq $dateseq->{serialid}){ - $d->{selected} = ' selected'; - } else { - $d->{selected} = q{}; - } - push @{$dates}, $d; -} - -my ($template, $loggedinuser, $cookie) -= get_template_and_user({template_name => 'serials/routing.tt', - query => $query, - type => 'intranet', - authnotrequired => 0, - flagsrequired => {serials => 'routing'}, - debug => 1, - }); - -my $member_loop = []; -for my $routing ( @routinglist ) { - my $member=GetMember('borrowernumber' => $routing->{borrowernumber}); - $member->{location} = $member->{branchcode}; - if ($member->{firstname} ) { - $member->{name} = $member->{firstname} . q| |; - } - else { - $member->{name} = q{}; - } - if ($member->{surname} ) { - $member->{name} .= $member->{surname}; - } - $member->{routingid}=$routing->{routingid} || q{}; - $member->{ranking} = $routing->{ranking} || q{}; - - push(@{$member_loop}, $member); -} - -$template->param( - title => $subs->{bibliotitle}, - subscriptionid => $subscriptionid, - memberloop => $member_loop, - op => $op eq 'new', - dates => $dates, - routingnotes => $serials[0]->{'routingnotes'}, - hasRouting => check_routing($subscriptionid), - (uc(C4::Context->preference("marcflavour"))) => 1 - - ); - -output_html_with_http_headers $query, $cookie, $template->output; diff --git a/serials/routinglist.pl b/serials/routinglist.pl new file mode 100755 index 0000000..f8455d3 --- /dev/null +++ b/serials/routinglist.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +# Copyright 2011 BibLibre SARL +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +routinglist.pl + +=head1 DESCRIPTION + +Create or modify a routing list + +=cut + +use Modern::Perl; + +use CGI; +use C4::Auth; +use C4::Output; + +use C4::Members; +use C4::Serials; +use C4::Serials::RoutingLists qw/AddRoutingList ModRoutingList GetRoutingList/; + +my $input = new CGI; +my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { + template_name => 'serials/routinglist.tt', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { serials => 'routing' }, + debug => 1, +} ); + +my $op = $input->param('op'); +my $routinglistid; + +if($op && $op eq 'new') { + my $subscriptionid = $input->param('subscriptionid'); + $template->param( + new => 1, + subscriptionid => $subscriptionid, + ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} + +if($op && $op eq 'savenew') { + my $title = $input->param('title'); + my $subscriptionid = $input->param('subscriptionid'); + + $routinglistid = AddRoutingList($subscriptionid, $title); +} else { + $routinglistid = $input->param('routinglistid'); +} + +if($op && $op eq 'mod') { + my $borrowersids = $input->param('borrowersids'); + my $notes = $input->param('notes'); + my @borrowernumbers = split /:/, $borrowersids; + ModRoutingList($routinglistid, undef, undef, $notes, @borrowernumbers); + my $routinglist = GetRoutingList($routinglistid); + print $input->redirect("/cgi-bin/koha/serials/routinglists.pl?subscriptionid=".$routinglist->{'subscriptionid'}); + exit; +} + +my $routinglist = GetRoutingList($routinglistid); +my @borrowers; +my $rank = 1; +foreach my $borrowernumber (@{$routinglist->{borrowers}}) { + my @ranking_loop; + for(my $i = 0 ; $i < scalar(@{$routinglist->{borrowers}}) ; $i++){ + my $selected = 0; + $selected = 1 if ($rank == $i+1); + push @ranking_loop, { + rank => $i+1, + selected => $selected, + }; + } + my $member = GetMemberDetails($borrowernumber); + push @borrowers, { + borrowernumber => $borrowernumber, + surname => $member->{surname}, + firstname => $member->{firstname}, + ranking_loop => \@ranking_loop + }; + $rank ++; +} + +$template->param( + borrowers_loop => \@borrowers, + borrowersids => join(':', map ($_->{borrowernumber}, @borrowers)), + max_rank => scalar(@borrowers), + title => $routinglist->{title}, + notes => $routinglist->{notes}, + subscriptionid => $routinglist->{subscriptionid}, + routinglistid => $routinglistid, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/serials/routinglists.pl b/serials/routinglists.pl new file mode 100755 index 0000000..cb646c6 --- /dev/null +++ b/serials/routinglists.pl @@ -0,0 +1,79 @@ +#!/usr/bin/perl + +# Copyright 2011 BibLibre SARL +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +routinglists.pl + +=head1 DESCRIPTION + +View all routing lists for a subscription + +=cut + +use Modern::Perl; + +use CGI; +use C4::Auth; +use C4::Output; + +use C4::Biblio; +use C4::Serials; +use C4::Serials::RoutingLists qw/GetRoutingLists GetRoutingList DelRoutingList GetRoutingListAsCSV/; + +my $input = new CGI; +my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { + template_name => 'serials/routinglists.tt', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { serials => 'routing' }, + debug => 1, +} ); + +my $subscriptionid = $input->param('subscriptionid'); +my $op = $input->param('op'); + +if($op && $op eq "export") { + my $routinglistid = $input->param('routinglistid'); + print $input->header( + -type => 'text/csv', + -attachment => 'routinglist' . $routinglistid . '.csv', + ); + print GetRoutingListAsCSV($routinglistid); + exit; +} elsif($op && $op eq "del") { + my $routinglistid = $input->param('routinglistid'); + if(!defined $subscriptionid){ + my $routinglist = GetRoutingList($routinglistid); + $subscriptionid = $routinglist->{subscriptionid}; + } + DelRoutingList($routinglistid); +} + +my $subscription = GetSubscription($subscriptionid); +my $biblio = GetBiblio($subscription->{biblionumber}); +my @routinglists = GetRoutingLists($subscriptionid); + +$template->param( + subscriptionid => $subscriptionid, + routinglists_loop => \@routinglists, + title => $biblio->{title}, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index ad8317e..ca40289 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -25,6 +25,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Koha; use C4::Serials; +use C4::Serials::RoutingLists qw/GetRoutingListsCount/; use C4::Letters; use C4::Output; use C4::Context; @@ -125,7 +126,7 @@ if (@subscriptionid){ my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern}); $subs->{frequency} = $frequency; $subs->{numberpattern} = $numberpattern; - $subs->{'hasRouting'} = check_routing($subscriptionid); + $subs->{'hasRouting'} = GetRoutingListsCount($subscriptionid); push @$subscriptiondescs,$subs; my $tmpsubscription= GetFullSubscription($subscriptionid); @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation); @@ -144,8 +145,10 @@ my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1) my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year}; my $subscriptionidlist=""; foreach my $subscription (@$subscriptiondescs){ - $subscriptionidlist.=$subscription->{'subscriptionid'}."," ; - $biblionumber = $subscription->{'bibnum'} unless ($biblionumber); + $subscriptionidlist.=$subscription->{'subscriptionid'}."," ; + $biblionumber = $subscription->{'bibnum'} unless ($biblionumber); + $subscription->{routinglistscount} + = GetRoutingListsCount($subscription->{subscriptionid}); } chop $subscriptionidlist; diff --git a/serials/serials-search.pl b/serials/serials-search.pl index e5eb0dc..e32f226 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -37,6 +37,7 @@ use C4::Koha qw( GetAuthorisedValues ); use C4::Output; use C4::Serials; use Koha::AdditionalField; +use C4::Serials::RoutingLists qw/GetRoutingListsCount/; use Koha::DateUtils; @@ -116,7 +117,9 @@ if ($searched){ # to toggle between create or edit routing list options if ($routing) { for my $subscription ( @subscriptions) { - $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); + $subscription->{routinglistscount} + = GetRoutingListsCount($subscription->{subscriptionid}); + $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} ); } } diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 824ffc2..0e5d82c 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -22,6 +22,7 @@ use C4::Auth; use C4::Budgets; use C4::Koha; use C4::Serials; +use C4::Serials::RoutingLists qw/GetRoutingListsCount/; use C4::Output; use C4::Context; use C4::Search qw/enabled_staff_search_views/; @@ -92,7 +93,7 @@ if ($op eq 'del') { exit; } } -my $hasRouting = check_routing($subscriptionid); +my $hasRouting = GetRoutingListsCount($subscriptionid); (undef, $cookie, undef, undef) = checkauth($query, 0, {catalogue => 1}, "intranet"); diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 1f3ebb0..018a4d5 100644 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -15,7 +15,7 @@ use C4::Bookseller; use C4::Biblio; use C4::Budgets; use Koha::DateUtils; -use Test::More tests => 45; +use Test::More tests => 43; BEGIN { use_ok('C4::Serials'); @@ -184,10 +184,6 @@ is(C4::Serials::updateClaim(),undef, 'test updating claim'); is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea'); -is(C4::Serials::check_routing(), undef, 'test checking route'); - -is(C4::Serials::addroutingmember(),undef, 'test adding route member'); - # Unit tests for statuses management (Bug 11689) $subscriptionid = NewSubscription( -- 2.1.4