From 9b2ee5024f5aebb061e7105fd0a9d45dedad0156 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 8 Jun 2012 16:45:19 +0530 Subject: [PATCH] Bug 6813: Acquistions duplicate search across orders, suggestions and catalog Content-Type: text/plain; charset="utf-8" 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 c479502..45e01a7 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -97,6 +97,7 @@ BEGIN { &CountBiblioInOrders &GetSubscriptionsId &GetHolds + &FindBiblios ); # To modify something @@ -3705,6 +3706,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 0cb484a..8e83a0f 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..2495c06 --- /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@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 ) %]
  • Budgets
  • Funds
  • +
  • Duplicate Search
  • [% END %] [% IF ( CAN_user_parameters ) %]
  • Currencies
  • 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..632e9c6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicatesearch.tt @@ -0,0 +1,145 @@ +[% USE KohaDates %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Acquisitions › Duplicate Search +[% INCLUDE 'doc-head-close.inc' %] + + + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'acquisitions-search.inc' %] + + +
    +
    +
    +
    + +

    Duplicate Search

    +
    + [% IF ( result ) %] +
    + +
    + [% IF (numresults_order) %] + [% INCLUDE 'table-pager.inc' perpage='10' %] + + [% ELSE %] +
    + [% END %] + + + + + + + + + [% FOREACH orders_loo IN orders_loop %] + + + + + + + [% END %] +
    Basket NameOrder NumberSummaryVendor
    [% orders_loo.basketname %][% orders_loo.ordernumber %][% orders_loo.title |html %]
    [% orders_loo.author %]
    [% orders_loo.name %]
    +
    +
    +

    Suggestion Search Results

    + [% IF (numresults_sugg) %] + [% INCLUDE 'table-pager.inc' perpage='10' %] + + [% ELSE %] +
    + [% END %] + + + + + + + + + [% FOREACH sugg_loo IN sugg_loop %] + + + + + + + [% END %] +
    TitleAuthorISBNStatus
    [% sugg_loo.title %][% sugg_loo.author %][% sugg_loo.isbn %][% sugg_loo.STATUS %]
    +
    +
    +

    Catalog Search Results

    + [% IF (numresults_bib) %] + [% INCLUDE 'table-pager.inc' perpage='10' %] + + [% ELSE %] +
    + [% END %] + + + + + + + + [% FOREACH bib_loo IN bib_loop %] + + + + + + [% END %] +
    TitleAuthorISBN
    [% bib_loo.title %][% bib_loo.author %][% bib_loo.isbn %]
    +
    +
    +[% ELSE %] +

    No Result

    +[% END %] + +
    +
    +
    +
    +
    + +
    +

    Filter Results:

    +
      +
    1. +
    2. +
    3. +
    4. +
    5. +
    6. +
    7. +
    8. + +
    + Clear All +
    +
    +[% INCLUDE 'acquisitions-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] -- 1.7.2.5