[Koha-patches] [PATCH 3/3] Bug 6813: Acquistions duplicate search across orders, suggestions and catalog

Amit Gupta amit.gupta at osslabs.biz
Fri Jun 8 13:21:18 CEST 2012


To Test:
Create a an suggestion, order and catalog record for a certain title. Use the duplicate search tool available in the acquisitions menu (left navigation bar) to search and find the suggestion, order and catalog record matching the search term.

Enter one or more of title, author and ISBN in the search criteria.
---
 C4/Biblio.pm                                       |   55 ++++++++
 C4/Suggestions.pm                                  |   54 +++++++
 acqui/duplicatesearch.pl                           |  105 ++++++++++++++
 .../prog/en/includes/acquisitions-menu.inc         |    1 +
 .../prog/en/modules/acqui/duplicatesearch.tt       |  145 ++++++++++++++++++++
 5 files changed, 360 insertions(+), 0 deletions(-)
 create mode 100755 acqui/duplicatesearch.pl
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicatesearch.tt

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 2aa17d5..637c1a3 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -97,6 +97,7 @@ BEGIN {
       &CountBiblioInOrders
       &GetSubscriptionsId
       &GetHolds
+      &FindBiblios
     );
 
     # To modify something
@@ -3700,6 +3701,60 @@ sub GetHolds {
     return ($holds);
 }
 
+=head2 FindBiblios
+
+Find biblios matching title, author, isbn and return a array containing details of matching biblios.
+
+=cut
+
+sub FindBiblios {
+    my $dbh    = C4::Context->dbh;
+    my %params = @_;
+    my $title = $params{title};
+    my $author = $params{author};
+    my $isbn   = $params{isbn};    
+    my $query = "SELECT title, author, isbn, biblio.biblionumber FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber";
+    $query .= " WHERE 1 ";                                                                                                                            
+    my @query_params  = ();
+        
+    if ( defined $title ) {
+        if ( $title eq ""){
+
+        } else {
+            $query .= " AND  biblio.title LIKE ? ";                                                                                           
+            $title =~ s/\s+/%/g;                                                                                                              
+            push @query_params, "%$title%";                                                                                                   
+        }                                                                                                                                     
+    }
+
+    if ( defined $author ) {
+        if( $author eq ""){
+
+        } else {              
+            $query .= " AND biblio.author LIKE ? ";
+            push @query_params, "%$author%";
+        }
+    }
+
+    if ( defined $isbn) {
+        if ( $isbn eq ""){
+
+        } else {
+            $query .= " AND biblioitems.isbn LIKE ? ";
+            push @query_params, "%$isbn%";
+        }
+    }
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute( @query_params );
+    my @bib_loop;
+    while (my $data=$sth->fetchrow_hashref){
+        push @bib_loop,$data;
+    }                    
+
+    return \@bib_loop;
+}
+
 =head2 prepare_host_field
 
 $marcfield = prepare_host_field( $hostbiblioitem, $marcflavour );
diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm
index 60d0e99..635b338 100644
--- a/C4/Suggestions.pm
+++ b/C4/Suggestions.pm
@@ -47,6 +47,7 @@ our @EXPORT  = qw<
     NewSuggestion
     SearchSuggestion
     DelSuggestionsOlderThan
+    FindSuggestions
 >;
 
 =head1 NAME
@@ -448,6 +449,59 @@ sub ModSuggestion {
     return $status_update_table;
 }
 
+=head2 FindSuggestions
+
+Find Suggestions matching title, author, isbn and return a array containing details of matching Suggestions.
+
+=cut
+
+sub FindSuggestions {
+    my $dbh    = C4::Context->dbh;
+    my %params = @_;
+    my $title = $params{title};
+    my $author = $params{author};
+    my $isbn   = $params{isbn};
+    my $querysug="SELECT title, author, isbn, STATUS, suggestionid FROM suggestions";
+    $querysug .=" WHERE 1";                                                          
+    my @query_sug  = ();
+
+    if ( defined $title ) {
+        if ( $title eq ""){
+
+        } else {  
+            $querysug .= " AND  suggestions.title LIKE ? "; 
+            $title =~ s/\s+/%/g;                 
+            push @query_sug, "%$title%";
+        }                                                                    
+    }                                                                        
+
+    if ( defined $author ) { 
+        if( $author eq ""){
+
+        } else {
+            $querysug .= " AND suggestions.author LIKE ? ";                  
+            push @query_sug, "%$author%";                                    
+        }                                                                    
+    }                                                                        
+
+    if ( defined $isbn) {
+        if ( $isbn eq ""){
+
+        } else {             
+            $querysug .= " AND suggestions.isbn LIKE ? ";
+            push @query_sug, "%$isbn%";                  
+        }                                                
+    }                                                    
+    my $sth = $dbh->prepare($querysug);                          
+    $sth->execute( @query_sug );                                 
+    my @sugg_loop;                                               
+    while (my $data=$sth->fetchrow_hashref){ 
+        push (@sugg_loop,$data);                                 
+    }                                                         
+   
+    return \@sugg_loop;
+}
+
 =head2 ConnectSuggestionAndBiblio
 
 &ConnectSuggestionAndBiblio($ordernumber,$biblionumber)
diff --git a/acqui/duplicatesearch.pl b/acqui/duplicatesearch.pl
new file mode 100755
index 0000000..532bd91
--- /dev/null
+++ b/acqui/duplicatesearch.pl
@@ -0,0 +1,105 @@
+#!/usr/bin/perl                                                  
+
+#script to duplicate search  (Orders, suggestions, bibliographic records)
+#written by amit.gupta at osslabs.biz 08/06/2012
+
+# Copyright 2012 Nucsoft Osslabs
+#
+# 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
+
+duplicatesearch.pl
+
+=head1 DESCRIPTION
+
+This script is used to search duplicate orders, suggestions and catalog records
+
+=cut
+
+use strict;
+use warnings;
+use CGI;                       
+use C4::Auth;    # get_template_and_user
+use C4::Output;                         
+use C4::Acquisition;
+use C4::Suggestions;
+use C4::Biblio;
+use C4::Debug;
+use C4::Search;
+
+my $input             = new CGI;
+my $title             = $input->param( 'title');
+my $author            = $input->param('author');
+my $isbn              = $input->param('isbn');
+my $op                = $input->param('op');
+
+# getting the template
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "acqui/duplicatesearch.tmpl",
+        query           => $input,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { acquisition => 'group_manage', acquisition => 'order_manage', acquisition => 'order_receive' },
+        debug           => 1,
+    }
+);
+
+
+if ($op eq "result"){
+    my ( $order_loop, $total_qty, $total_price, $total_qtyreceived ) = GetHistory(
+            title => $title,
+            author => $author,
+            isbn   => $isbn,
+            name => undef,
+            from_placed_on => undef,
+            to_placed_on => undef,
+            basket => undef,
+            booksellerinvoicenumber => undef,
+        );
+
+    my $sugg_loop = FindSuggestions(
+            title => $title,
+            author => $author,
+            isbn   => $isbn,
+        );
+
+    my $bib_loop = FindBiblios(
+            title => $title,
+            author => $author,
+            isbn   => $isbn
+       );
+
+
+    $template->param(
+            result => 1,
+            orders_loop => $order_loop,
+            sugg_loop => $sugg_loop,
+            bib_loop => $bib_loop,    
+            numresults_order  => scalar(@$order_loop),  
+            numresults_sugg  => scalar(@$sugg_loop),   
+            numresults_bib  => scalar(@$bib_loop),        
+    );
+}
+
+$template->param(
+    title => $title,
+    author => $author,    
+    isbn => $isbn,    
+);
+
+output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
index ac1a7a4..38cdf44 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
@@ -4,6 +4,7 @@
     [% IF ( CAN_user_acquisition_budget_manage ) %]
     <li><a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a></li>
     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a></li>
+    <li><a href="/cgi-bin/koha/acqui/duplicatesearch.pl">Duplicate Search</a></li>
     [% END %]
     [% IF ( CAN_user_parameters ) %]
      <li><a href="/cgi-bin/koha/admin/currency.pl">Currencies</a></li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicatesearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicatesearch.tt
new file mode 100644
index 0000000..711d780
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicatesearch.tt
@@ -0,0 +1,145 @@
+[% USE KohaDates %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Acquisitions &rsaquo; Duplicate Search</title>
+[% INCLUDE 'doc-head-close.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.pager.js"></script>
+<script type="text/javascript">//<![CDATA[
+    $(document).ready(function(){
+    $(".sorted").tablesorter({
+        sortList: [[0,0]],
+        headers: { 1: { sorter: false}}
+    }).tablesorterPager({container: $(".pager"),positionFixed: false,size: 10});
+});//]]>
+</script>
+<script type="text/javascript">//<![CDATA[
+$(function(){
+    $('#alerttabs > ul').tabs();     
+}); //]]>
+</script>
+</head>
+<body id="acq_duplicatesearch" class="acq">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'acquisitions-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <a href="duplicatesearch.pl">Duplicate Search</a></div>
+    <div id="doc3" class="yui-t2">   
+    <div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
+
+    <h1>Duplicate Search</h1>
+    <div id="acq_duplicatesearch">
+    [% IF ( result ) %]   
+        <div id="alerttabs" class="toptabs">
+        <ul>
+        <li><a href="#pagerordertable">Order ([% numresults_order %])</a></li>
+        <li><a href="#pagersuggestiontable">Suggestion ([% numresults_sugg %])</a></li>
+        <li><a href="#pagercatalogtable">Catalog ([% numresults_bib %])</a></li>
+        </ul>
+        <div id="pagerordertable">
+        [% IF (numresults_order) %]
+        [% INCLUDE 'table-pager.inc' perpage='10' %]        
+        <table id="ordertable" class="sorted">      
+        [% ELSE %]
+        <table> 
+        [% END %] 
+        <thead>               
+                <tr>                                                                                              
+                <th>Basket Name</th>
+                <th>Order Number</th>
+                <th>Summary</th>
+                <th>Vendor</th>
+                </tr>                                                                                             
+        </thead>
+        [% FOREACH orders_loo IN orders_loop %]
+                <tr>
+                <td><a href="basket.pl?basketno=[% orders_loo.basketno %]">[% orders_loo.basketname %]</a></td>                                                                                                                                                                                    
+                <td><a href="neworderempty.pl?ordernumber=[% orders_loo.ordernumber %]">[% orders_loo.ordernumber %]</a></td>
+                <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% orders_loo.biblionumber %]">[% orders_loo.title |html %]</a><br />[% orders_loo.author %]</td>
+                <td><a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=[% orders_loo.id %]">[% orders_loo.name %]</a></td>
+                </tr>
+        [% END %]
+        </table>
+        </div>
+        <div id="pagersuggestiontable">
+        <h1>Suggestion Search Results</h1>
+        [% IF (numresults_sugg) %]
+        [% INCLUDE 'table-pager.inc' perpage='10' %]         
+        <table id="suggestiontable" class="sorted"> 
+        [% ELSE %]
+         <table> 
+        [% END %]       
+        <thead>
+                <tr>
+                <th>Title</th>
+                <th>Author</th>
+                <th>ISBN</th>
+                <th>Status</th>
+                </tr>
+        </thead>
+        [% FOREACH sugg_loo IN sugg_loop %]
+                <tr>
+                <td><a href ="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% sugg_loo.suggestionid %]&op=edit"/>[% sugg_loo.title %]</td>
+                <td>[% sugg_loo.author %]</td>
+                <td>[% sugg_loo.isbn %]</td>
+                <td>[% sugg_loo.STATUS %]</td>
+                </tr>
+       [% END %]
+       </table>
+       </div>
+       <div id="pagercatalogtable">
+       <h1>Catalog Search Results</h1>
+       [% IF (numresults_bib) %]
+       [% INCLUDE 'table-pager.inc' perpage='10' %]
+       <table id="catalogtable" class="sorted">
+       [% ELSE %]
+       <table> 
+       [% END %]       
+       <thead>
+                <tr>
+                <th>Title</th>
+                <th>Author</th>
+                <th>ISBN</th>
+                </tr>
+       </thead>
+       [% FOREACH bib_loo IN bib_loop %]
+                <tr>
+                <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% bib_loo.biblionumber %]">[% bib_loo.title %]</td>
+                <td>[% bib_loo.author %]</td>
+                <td>[% bib_loo.isbn %]</td>
+                </tr>
+       [% END %]
+       </table>
+       </div>
+       </div>
+[% ELSE %]
+       <p>No Result</p>
+[% END %]
+
+</div>
+</div>
+</div>
+<div class="yui-b">
+<form  name="form" action="/cgi-bin/koha/acqui/duplicatesearch.pl" method="post">
+<input type="hidden" name="op" value="result" />
+<fieldset class="brief">
+<h4>Filter Results:</h4>
+    <ol>
+        <li><label for="title">Title: </label> <input type="text" name="title" id="title" value="[% title %]"  size="20" /></li>
+        <li><label for="author">Author: </label> <input type="text" name="author" id="author" value="[% author %]"  size="20" /></li>
+        <li><label for="isbn">ISBN: </label> <input type="text" name="isbn" id="isbn" value="[% isbn %]"  size="20" /></li>
+        <li><label for="title"></label><input type="hidden" name="idx" id="title" value="ti" /></li>
+        <li><input type="hidden" name="q" id="title1" value="[% title %]" /></li>
+        <li><label for="author"></label><input type="hidden" name="idx" id="author" value="au" /></li>
+        <li><input type="hidden" name="q" id="author1" value="[% author %]" /></li>
+        <li><label for="isbn"></label><input type="hidden" name="idx" id="isbn" value="nb" /></li>
+        <input type="hidden" name="q" id="isbn1" value="[% isbn %]" />
+    </ol> 
+        <input type="submit" value="Search" /> <a href="/cgi-bin/koha/acqui/duplicatesearch.pl">Clear All</a>
+    </fieldset>
+</form>
+[% INCLUDE 'acquisitions-menu.inc' %]
+</div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
-- 
1.6.4.2



More information about the Koha-patches mailing list