From 0a72b270cfa739dd8a7493eb738ce04ec69facb6 Mon Sep 17 00:00:00 2001
From: Katrin Fischer <Katrin.Fischer.83@web.de>
Date: Sun, 26 Aug 2012 00:29:53 +0200
Subject: [PATCH] Bug 8415: Follow up - Fixing some smaller issues

1) Changes the updatedatabase to be a bit more precise and always add
   the new field after claimed_date, like it is in kohastructure.sql.

2) Fixes capitalization rules for the new link to create a serial order.

3) Hides EAN search field when marcflavour is not UNIMARC.

4) Adds documentation for the new column in kohastructure.sql

5) Fixes some terms
  * Branch to Library
  * Search for Serial Routing Lists to Search for serial subscriptions
  * Supplier to Vendor

6) Deletes doubled up SearchSubscriptions from Search.pm
  * Change call to sub to use new signature

7) Deletes "Show only renewed" checkbox and related code.
This feature requires a database field reneweddate in
subscription that is not available in master.
---
 C4/Serials.pm                                      |   79 +-------------------
 acqui/newordersubscription.pl                      |   16 +++-
 installer/data/mysql/kohastructure.sql             |    2 +-
 installer/data/mysql/updatedatabase.pl             |    4 +-
 .../en/includes/acquisitions-add-to-basket.inc     |    2 +-
 .../prog/en/includes/subscriptions-search.inc      |    6 +-
 .../prog/en/modules/acqui/newordersubscription.tt  |   25 +------
 7 files changed, 25 insertions(+), 109 deletions(-)

diff --git a/C4/Serials.pm b/C4/Serials.pm
index 9483c3d..dec5dd3 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -52,7 +52,7 @@ BEGIN {
       &getroutinglist     &delroutingmember   &addroutingmember
       &reorder_members
       &check_routing &updateClaim &removeMissingIssue
-      &CountIssues &SearchSubscriptions
+      &CountIssues
       &subscriptionCurrentlyOnOrder
       HasItems
       &GetSubscriptionsFromBorrower
@@ -153,83 +153,6 @@ sub GetLateIssues {
     return @issuelist;
 }
 
-=head2 SearchSubscriptions
-
-@results = SearchSubscriptions($biblionumber, $title, $issn, $ean, $publisher, $supplier, $branch, $minold, $maxold);
-
-this function gets all subscriptions which have biblionumber eq $biblionumber, title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, supplier like $supplier AND branchcode eq $branch.
-$minold and $maxold are values in days. It allows to get active and inactive subscription apart.
-
-return:
-a table of hashref. Each hash containt the subscription.
-
-=cut
-
-sub SearchSubscriptions {
-    my ($biblionumber, $title, $issn, $ean, $publisher, $supplier, $branch, $minold, $maxold) = @_;
-
-    my $query = qq{
-        SELECT subscription.*, subscriptionhistory.*, biblio.*, biblioitems.issn,
-            subscription.notes AS notes
-        FROM subscription
-            LEFT JOIN subscriptionhistory USING(subscriptionid)
-            LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
-            LEFT JOIN biblioitems ON biblioitems.biblionumber = subscription.biblionumber
-            LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
-    };
-    my @where_strs;
-    my @where_args;
-    if($biblionumber){
-        push @where_strs, "subscription.biblionumber = ?";
-        push @where_args, "$biblionumber";
-    }
-    if($title){
-        push @where_strs, "biblio.title LIKE ?";
-        push @where_args, "%$title%";
-    }
-    if($issn){
-        push @where_strs, "biblioitems.issn LIKE ?";
-        push @where_args, "%$issn%";
-    }
-    if($ean){
-        push @where_strs, "biblioitems.ean LIKE ?";
-        push @where_args, "%$ean%";
-    }
-    if($publisher){
-        push @where_strs, "biblioitems.publishercode LIKE ?";
-        push @where_args, "%$publisher%";
-    }
-    if($supplier){
-        push @where_strs, "aqbooksellers.name LIKE ?";
-        push @where_args, "%$supplier%";
-    }
-    if($branch){
-        push @where_strs, "subscription.branchcode = ?";
-        push @where_args, "$branch";
-    }
-    if ($minold) {
-        push @where_strs, "TO_DAYS(NOW()) - TO_DAYS(subscription.enddate) > ?" if ($minold);
-        push @where_args, "$minold" if ($minold);
-    }
-    if ($maxold) {
-        push @where_strs, "(TO_DAYS(NOW()) - TO_DAYS(subscription.enddate) <= ? OR subscription.enddate IS NULL OR subscription.enddate = '0000-00-00')";
-        push @where_args, "$maxold";
-    }
-
-    if(@where_strs){
-        $query .= " WHERE " . join(" AND ", @where_strs);
-    }
-    warn $query;
-    warn join(",", @where_args) if @where_args;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@where_args);
-    my $results = $sth->fetchall_arrayref( {} );
-    $sth->finish;
-
-    return @$results;
-}
-
 =head2
     $bool = subscriptionCurrentlyOnOrder( $subscriptionid );
     Return 1 if subscription is already on order
diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl
index 86db2e2..30b5538 100755
--- a/acqui/newordersubscription.pl
+++ b/acqui/newordersubscription.pl
@@ -18,8 +18,7 @@
 # with Koha; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-use warnings;
-use strict;
+use Modern::Perl;
 use CGI;
 use C4::Acquisition;
 use C4::Auth;
@@ -59,7 +58,17 @@ my ($bookseller) = C4::Bookseller::GetBookSellerFromId( $booksellerid);
 my @subscriptions;
 my $sub;
 if ($searched) {
-    @subscriptions = SearchSubscriptions($biblionumber, $title, $ISSN, $EAN, $publisher, $supplier, $branch);
+    @subscriptions = SearchSubscriptions(
+        {
+            biblionumber    => $biblionumber, 
+            title           => $title, 
+            issn            => $ISSN, 
+            ean             => $EAN, 
+            publisher       => $publisher, 
+            bookseller      => $supplier, 
+            branch          => $branch
+        }
+    );
 }
 
 
@@ -104,5 +113,6 @@ $template->param(
     basketname       => $basket->{'basketname'},
     booksellername   => $bookseller->{'name'},
     unfolded_search  => 1,
+    marcflavour      => uc(C4::Context->preference("marcflavour")),
 );
 output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index ec4ff30..4572b42 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -2780,7 +2780,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items
   `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
   `claims_count` int(11) default 0, -- count of claim letters generated
   `claimed_date` date default NULL, -- last date a claim was generated
-  `subscriptionid` int(11) default NULL,
+  `subscriptionid` int(11) default NULL, -- links this order to a subscription in the serials module
   parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
   PRIMARY KEY  (`ordernumber`),
   KEY `basketno` (`basketno`),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 3fa0541..a695fc5 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -5862,8 +5862,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.09.00.XXX";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("ALTER TABLE `aqorders` ADD `subscriptionid` int(11) default NULL");
-    print "Upgrade to $DBversion done (Alter table aqorders done)\n";
+    $dbh->do("ALTER TABLE `aqorders` ADD `subscriptionid` int(11) default NULL AFTER `claimed_date`");
+    print "Upgrade to $DBversion done (Add subscriptionid to table aqorders)\n";
     SetVersion ($DBversion);
 }
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc
index 0391df7..a7a64b1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc
@@ -6,7 +6,7 @@
         <input type="hidden" name="basketno" value="[% basketno %]" />
         <ul><li><label for="q">From an existing record: </label><input id="q" type="text"  size="25" name="q" />
         <input type="submit" class="submit" value="Search" /></li>
-        <li><a href="/cgi-bin/koha/acqui/newordersubscription.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a Subscription</a></li>
+        <li><a href="/cgi-bin/koha/acqui/newordersubscription.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a subscription</a></li>
         <li><a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a suggestion</a></li>
         <li><a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From a new (empty) record</a></li>
         <li><a href="/cgi-bin/koha/acqui/z3950_search.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">From an external source</a></li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
index 17fcd44..7763e88 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
@@ -17,20 +17,22 @@
                 <label for="title">Title:</label>
                 <input type="text" id="title" name="title_filter" value="[% title_filter %]" />
               </li>
+              [% IF ( marcflavour == "UNIMARC" ) %]
               <li>
                 <label for="ean">EAN:</label>
                 <input type="text" id="ean" name="EAN_filter" value="[% EAN_filter %]" />
               </li>
+              [% END %]
               <li>
                 <label for="publisher">Publisher:</label>
                 <input type="text" id="publisher" name="publisher_filter" value="[% publisher_filter %]" />
               </li>
               <li>
-                <label for="supplier">Supplier:</label>
+                <label for="supplier">Vendor:</label>
                 <input type="text" id="supplier" name="supplier_filter" value="[% supplier_filter %]" />
               </li>
               <li>
-                <label for="branch">Branch:</label>
+                <label for="branch">Library:</label>
                 <select id="branch" name="branch_filter">
                   <option value="">All</option>
                   [% FOREACH branches_loo IN branches_loop %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
index 127e57d..24fab65 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
@@ -4,29 +4,14 @@
 <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
 <script type="text/javascript">
 //<![CDATA[
-    function updateRowsVisibility(show_only_renewed) {
-        if ( show_only_renewed ) {
-            $("#srlt [data-reneweddate='']").hide();
-        } else {
-            $("#srlt > tbody > tr").show();
-        }
-          $("#srlt").trigger("sorton", [$("#srlt")[0].config.sortList]);
-    }
     $(document).ready(function() {
         $("#srlt").tablesorter({
             widgets : ['zebra'],
             headers: {
-                2: { sorter: false },
                 6: { sorter: false },
                 7: { sorter: false }
             }
         });
-
-        $("#show_only_renewed").click(function(){
-            updateRowsVisibility($(this+":checked").val());
-        });
-        $("#show_only_renewed").attr('checked', false);
-        updateRowsVisibility(false);
     });
  //]]>
 </script>
@@ -43,13 +28,9 @@
         <div class="yui-b">
             <h2>Serials subscriptions</h2>
             [% IF ( routing ) %]
-                <h3>Search for Serial Routing List</h3>
+                <h3>Search for serial subscriptions</h3>
             [% END %]
             [% IF ( done_searched ) %]
-                <label for="show_only_renewed">
-                    <input type="checkbox" style="vertical-align: middle;" id="show_only_renewed" />
-                    Show only renewed
-                </label>
                 [% IF ( subs_loop ) %]
                     <table id="srlt">
                         <thead>
@@ -57,7 +38,7 @@
                                 <th>Id</th>
                                 <th>ISSN</th>
                                 <th>Title</th>
-                                <th> Notes </th>
+                                <th>Notes</th>
                                 <th>Library</th>
                                 <th>Call number</th>
                                 <th>Expiration date</th>
@@ -66,7 +47,7 @@
                         </thead>
                         <tbody>
                         [% FOREACH subs_loo IN subs_loop %]
-                            <tr data-reneweddate="[% subs_loo.reneweddate %]" >
+                            <tr>
                                 <td>[% subs_loo.subscriptionid %]</td>
                                 <td>[% subs_loo.issn %]</td>
                                 <td><a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subs_loo.subscriptionid %]" class="button" title="subscription detail">[% IF ( subs_loo.title ) %][% subs_loo.title |html %][% ELSE %]
-- 
1.7.9.5