From 15c4873dd0a16d93e43018f5ea8733e1e4ae519c Mon Sep 17 00:00:00 2001
From: David Cook <dcook@prosentient.com.au>
Date: Wed, 21 Aug 2013 15:18:31 +1000
Subject: [PATCH] Bug 10773 - Replace item-level codes with names/descriptions for Label Printing

This patch replaces item-level codes for certain fields so that names
and descriptions are printed out instead of codes when using the Label
Creator.

The fields in question are "ccode", "homebranch", "holdingbranch",
"location", and "permanent_location".

Test Plan:

1) Edit a layout in the Label Creator so that it includes any of these
fields. I suggest including "homebranch" and perhaps "ccode" if you
have them in your item data.
2) Add items to a batch in the Label Creator.
3) Export the batch using the layout, and view as PDF
4) Note how the codes for homebranch (and ccode if available) come
up instead of the name of the homebranch (and ccode).

5) Apply patch

6) Export the batch again
7) Note how the branch name and category name are now displaying
instead of the codes that showed before.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 C4/Labels/Label.pm |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm
index f62d50c..638b4bb 100644
--- a/C4/Labels/Label.pm
+++ b/C4/Labels/Label.pm
@@ -94,6 +94,19 @@ sub _get_label_item {
     my $data1 = $sth1->fetchrow_hashref;
     $data->{'itemtype'} = $data1->{'description'};
     $data->{'itype'} = $data1->{'description'};
+    #Replace item's branch codes with branch names
+    if ($data->{'homebranch'} || $data->{'holdingbranch'}){
+        require C4::Branch;
+        $data->{'homebranch'} = C4::Branch::GetBranchName($data->{'homebranch'}) if $data->{'homebranch'};
+        $data->{'holdingbranch'} = C4::Branch::GetBranchName($data->{'holdingbranch'}) if $data->{'holdingbranch'};
+    }
+    #Replace ccode, location, permanent_location with descriptions
+    my $ccode = C4::Biblio::GetAuthorisedValueDesc('','', $data->{'ccode'} ,'','','CCODE', 1);
+    $data->{'ccode'} = $ccode if $ccode;
+    my $location = C4::Biblio::GetAuthorisedValueDesc('','', $data->{'location'} ,'','','LOC', 1);
+    $data->{'location'} = $location if $location;
+    my $permanent_location = C4::Biblio::GetAuthorisedValueDesc('','', $data->{'permanent_location'} ,'','','LOC', 1);
+    $data->{'permanent_location'} = $permanent_location if $permanent_location;
     $barcode_only ? return $data->{'barcode'} : return $data;
 }
 
-- 
1.7.2.5