From 286498066cffa6c17e8698daa9309744cfb0caac 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

6) Deletes doubled up SearchSubscriptions from Search.pm
---
 C4/Serials.pm                                      |   77 --------------------
 acqui/newordersubscription.pl                      |    1 +
 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      |    4 +-
 .../prog/en/modules/acqui/newordersubscription.tt  |    4 +-
 7 files changed, 10 insertions(+), 84 deletions(-)

diff --git a/C4/Serials.pm b/C4/Serials.pm
index 9483c3d..29bfda7 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -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..948fea3 100755
--- a/acqui/newordersubscription.pl
+++ b/acqui/newordersubscription.pl
@@ -104,5 +104,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..00bfb99 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
@@ -17,10 +17,12 @@
                 <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 %]" />
@@ -30,7 +32,7 @@
                 <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..c43eed7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
@@ -43,7 +43,7 @@
         <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">
@@ -57,7 +57,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>
-- 
1.7.9.5