From ce8a0fd84a7eb2b48422bc5640ae335cf7102616 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Mon, 23 Feb 2015 16:39:08 +0100
Subject: [PATCH] Bug 2806: Remove issuingbranch columns

This column is not in used in the Koha code and could be removed.

Test plan:
Verify the branch is correctly displayed on the circulation history
(members/readingrec.pl) and that both reports Most-cisulated items
(cat_issues_top.pl) and Avg checkout (issues_avg_stats.pl) work as
before.
---
 installer/data/mysql/kohastructure.sql                       |  4 ----
 installer/data/mysql/updatedatabase.pl                       | 12 ++++++++++++
 .../intranet-tmpl/prog/en/modules/members/readingrec.tt      |  3 ++-
 .../intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt  |  2 +-
 .../prog/en/modules/reports/issues_avg_stats.tt              |  8 --------
 members/readingrec.pl                                        |  3 ---
 6 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index cd83f99..bdc4252 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1144,7 +1144,6 @@ CREATE TABLE `issues` ( -- information related to check outs or issues
   `itemnumber` int(11), -- foreign key, linking this to the items table for the item that was checked out
   `date_due` datetime default NULL, -- datetime the item is due (yyyy-mm-dd hh:mm::ss)
   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
-  `issuingbranch` varchar(18) default NULL,
   `returndate` datetime default NULL, -- date the item was returned, will be NULL until moved to old_issues
   `lastreneweddate` datetime default NULL, -- date the item was last renewed
   `return` varchar(4) default NULL,
@@ -1156,7 +1155,6 @@ CREATE TABLE `issues` ( -- information related to check outs or issues
   KEY `issuesborridx` (`borrowernumber`),
   KEY `itemnumber_idx` (`itemnumber`),
   KEY `branchcode_idx` (`branchcode`),
-  KEY `issuingbranch_idx` (`issuingbranch`),
   KEY `bordate` (`borrowernumber`,`timestamp`),
   CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
   CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE
@@ -1618,7 +1616,6 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r
   `itemnumber` int(11) default NULL, -- foreign key, linking this to the items table for the item that was checked out
   `date_due` datetime default NULL, -- date the item is due (yyyy-mm-dd)
   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
-  `issuingbranch` varchar(18) default NULL,
   `returndate` datetime default NULL, -- date the item was returned
   `lastreneweddate` datetime default NULL, -- date the item was last renewed
   `return` varchar(4) default NULL,
@@ -1630,7 +1627,6 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r
   KEY `old_issuesborridx` (`borrowernumber`),
   KEY `old_issuesitemidx` (`itemnumber`),
   KEY `branchcode_idx` (`branchcode`),
-  KEY `issuingbranch_idx` (`issuingbranch`),
   KEY `old_bordate` (`borrowernumber`,`timestamp`),
   CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
     ON DELETE SET NULL ON UPDATE SET NULL,
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 47930ab..9355dc5 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -9779,6 +9779,18 @@ if ( CheckVersion($DBversion) ) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.19.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        ALTER TABLE issues DROP COLUMN issuingbranch
+    |);
+    $dbh->do(q|
+        ALTER TABLE oldissues DROP COLUMN issuingbranch
+    |);
+    print "Upgrade to $DBversion done (Bug 2806: Remove issuingbranch columns)\n";
+    SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt
index 773995a..df13a17 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt
@@ -1,5 +1,6 @@
 [% USE KohaDates %]
 [% USE Koha %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Circulation History for [% INCLUDE 'patron-title.inc' %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -108,7 +109,7 @@
           <td>
             <span title="[% issue.issuedate %]">[% issue.issuedate | $KohaDates %]</span></td>
           </td>
-          <td>[% issue.issuingbranch %]</td>
+          <td>[% Branches.GetName( issue.branchcode ) %]</td>
           <td>
             [% IF issue.date_due %]
                 <span title="[% issue.date_due %]">[% issue.date_due | $KohaDates %]</span>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt
index c7e45bd..c8b8f64 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt
@@ -152,7 +152,7 @@
 					</select></li>
 	<li><label for="criteria">By: </label><select name="Criteria" id="criteria">
 						<option value ="" selected="selected">None</option>
-						<option value ="issuingbranch">Library</option>
+						<option value ="branch">Library</option>
 						<option value ="categorycode">Categorycode</option>
 						<option value ="itemtype">Itemtype</option>
 						<option value ="Day">Day</option>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt
index ffbbdd1..ce4bf86 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt
@@ -172,14 +172,6 @@
                                     </select>
                                 </td>
 			</tr>
-<!-- Modified according to statistics table
-			<tr>
-                <td>Issuing library</td>
-				<td><input type="radio" name="Line" value="issuingbranch"></td>
-				<td><input type="radio" name="Column" value="issuingbranch"></td>
-				<td >[% CGIBranch %]</td>
-			</tr> -->
-<!--End Modified -->
 			[% IF ( hassort1 ) %]
 				<tr class="hilighted"> 
 					<td>Sort1</td>
diff --git a/members/readingrec.pl b/members/readingrec.pl
index de2baec..7f6d271 100755
--- a/members/readingrec.pl
+++ b/members/readingrec.pl
@@ -74,9 +74,6 @@ if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
 }
 
 my $branches = GetBranches();
-foreach my $issue ( @{$issues} ) {
-    $issue->{issuingbranch} = $branches->{ $issue->{branchcode} }->{branchname};
-}
 
 #   barcode export
 if ( $op eq 'export_barcodes' ) {
-- 
2.1.0