[Koha-patches] [PATCH] Bug 8415 - Link Serial with Acquisition

Amit Gupta amit.gupta at osslabs.biz
Thu Jul 12 07:09:09 CEST 2012


To Test:
1) Create a basket.
2) Click on From a Subscription link under Add order to basket section.
3) A filter box appear on the left hand side (Search by ISSN, Title, Publisher, Supplier)
4) Search a subscription and click on order to add the order on the basket.
5) If already subscription add to the basket it shows "only one order per subscription is allowed".
---
 C4/Serials.pm                                      |  100 +++++++++++++++++-
 acqui/neworderempty.pl                             |    2 +
 acqui/newordersubscription.pl                      |  108 ++++++++++++++++++
 installer/data/mysql/kohastructure.sql             |    1 +
 installer/data/mysql/updatedatabase.pl             |    7 ++
 .../en/includes/acquisitions-add-to-basket.inc     |    1 +
 .../prog/en/includes/subscriptions-search.inc      |   61 +++++++++++
 .../intranet-tmpl/prog/en/modules/acqui/basket.tt  |    1 +
 .../prog/en/modules/acqui/neworderempty.tt         |    1 +
 .../prog/en/modules/acqui/newordersubscription.tt  |  115 ++++++++++++++++++++
 10 files changed, 396 insertions(+), 1 deletions(-)
 create mode 100755 acqui/newordersubscription.pl
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt

diff --git a/C4/Serials.pm b/C4/Serials.pm
index 58b6078..283afc0 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -51,7 +51,8 @@ BEGIN {
       &getroutinglist     &delroutingmember   &addroutingmember
       &reorder_members
       &check_routing &updateClaim &removeMissingIssue
-      &CountIssues
+      &CountIssues &SearchSubscriptions
+      &subscriptionCurrentlyOnOrder
       HasItems
 
     );
@@ -150,6 +151,103 @@ sub GetLateIssues {
     return @issuelist;
 }
 
+=head2 SearchSubscriptions
+
+ at 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
+    else 0
+=cut
+
+sub subscriptionCurrentlyOnOrder {
+    my ( $subscriptionid ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $query = qq|
+        SELECT COUNT(*) FROM aqorders
+        WHERE subscriptionid = ?
+            AND datereceived IS NULL
+    |;
+    my $sth = $dbh->prepare( $query );
+    $sth->execute($subscriptionid);
+    return $sth->fetchrow_array;
+}
+
+
 =head2 GetSubscriptionHistoryFromSubscriptionId
 
 $sth = GetSubscriptionHistoryFromSubscriptionId()
diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl
index a461a1b..85d9739 100755
--- a/acqui/neworderempty.pl
+++ b/acqui/neworderempty.pl
@@ -100,6 +100,7 @@ my $publicationyear = $input->param('publicationyear');
 my $bookseller      = GetBookSellerFromId($booksellerid);	# FIXME: else ERROR!
 my $ordernumber          = $input->param('ordernumber') || '';
 my $biblionumber    = $input->param('biblionumber');
+my $subscriptionid  = $input->param('subscriptionid');
 my $basketno        = $input->param('basketno');
 my $suggestionid    = $input->param('suggestionid');
 my $close           = $input->param('close');
@@ -355,6 +356,7 @@ $template->param(
     surnamesuggestedby   => $suggestion->{surnamesuggestedby},
     firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
     biblionumber     => $biblionumber,
+    subscriptionid   => $subscriptionid,
     uncertainprice   => $data->{'uncertainprice'},
     authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
     biblioitemnumber => $data->{'biblioitemnumber'},
diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl
new file mode 100755
index 0000000..425aa45
--- /dev/null
+++ b/acqui/newordersubscription.pl
@@ -0,0 +1,108 @@
+#!/usr/bin/perl
+
+# Copyright 2011 BibLibre
+# 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.
+
+use warnings;
+use strict;
+use CGI;
+use C4::Acquisition;
+use C4::Auth;
+use C4::Branch;
+use C4::Context;
+use C4::Bookseller;
+use C4::Output;
+use C4::Serials;
+
+my $query        = new CGI;
+my $title        = $query->param('title_filter');
+my $ISSN         = $query->param('ISSN_filter');
+my $EAN          = $query->param('EAN_filter');
+my $publisher    = $query->param('publisher_filter');
+my $supplier     = $query->param('supplier_filter');
+my $branch       = $query->param('branch_filter');
+my $routing      = $query->param('routing') || C4::Context->preference("RoutingSerials");
+my $searched     = $query->param('searched');
+my $biblionumber = $query->param('biblionumber');
+my $basketno     = $query->param('basketno');
+my $booksellerid = $query->param('booksellerid');
+
+my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
+    {   
+        template_name   => "acqui/newordersubscription.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { acquisition => 'order_manage' },
+    }
+);
+
+my $basket = GetBasket($basketno);
+$booksellerid = $basket->{booksellerid} unless $booksellerid;
+my ($bookseller) = C4::Bookseller::GetBookSellerFromId( $booksellerid);
+
+my @subscriptions;
+my $sub;
+if ($searched) {
+    @subscriptions = SearchSubscriptions($biblionumber, $title, $ISSN, $EAN, $publisher, $supplier, $branch);
+}
+
+
+foreach $sub (@subscriptions) {
+    my $enddate = C4::Dates->new($$sub{'enddate'}, "iso");
+    $$sub{'enddate'} = $enddate->output();
+    $$sub{alreadyOnOrder} = subscriptionCurrentlyOnOrder($$sub{subscriptionid});
+    
+    # to toggle between create or edit routing list options
+    if ($routing) {
+        $$sub{routingedit} = check_routing( $$sub{subscriptionid} );
+    }
+}
+
+my $branches = GetBranches();
+my @branches_loop;
+foreach (sort keys %$branches){
+    my $selected = 0;
+    $selected = 1 if defined $branch && $branch eq $_;
+    push @branches_loop, {
+        branchcode  => $_,
+        branchname  => $branches->{$_}->{'branchname'},
+        selected    => $selected,
+    };
+}
+
+$template->param(
+    subs_loop        => \@subscriptions,
+    booksellerid     => $booksellerid,
+    basketno         => $basketno,
+    title_filter     => $title,
+    ISSN_filter      => $ISSN,
+    EAN_filter       => $EAN,
+    publisher_filter => $publisher,
+    supplier_filter  => $supplier,
+    branch_filter    => $branch,
+    branches_loop    => \@branches_loop,
+    done_searched    => $searched,
+    routing          => $routing,
+    booksellerid     => $booksellerid,
+    basketno         => $basket->{'basketno'},
+    basketname       => $basket->{'basketname'},
+    booksellername   => $bookseller->{'name'},
+    unfolded_search  => 1,
+);
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 3b9827a..a311270 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -2770,6 +2770,7 @@ CREATE TABLE `aqorders` (
   `uncertainprice` tinyint(1),
   `claims_count` int(11) default 0,
   `claimed_date` date default NULL,
+  `subscriptionid` int(11) default NULL,
   PRIMARY KEY  (`ordernumber`),
   KEY `basketno` (`basketno`),
   KEY `biblionumber` (`biblionumber`),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index bb96644..eaffd80 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -5536,6 +5536,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($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";
+    SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
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 c36698d..0391df7 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,6 +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/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
new file mode 100644
index 0000000..c61fbc7
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
@@ -0,0 +1,61 @@
+
+<div id="advsearch">
+    <form action="[% searchform_action %]" method="get">
+        <fieldset class="brief">
+            [% IF ( unfolded_search ) %]
+            <div>
+            [% ELSE %]
+            <a id="unfold_advsearch" style="cursor:pointer" onclick="$('#advsearch_form').slideToggle(400);">Advanced search</a>
+            <div id="advsearch_form" style="display:none">
+            [% END %]
+            <ol>
+              <li>
+                <label for="issn">ISSN:</label>
+                <input type="text" id="issn" name="ISSN_filter" value="[% ISSN_filter %]" />
+              </li>
+              <li>
+                <label for="title">Title:</label>
+                <input type="text" id="title" name="title_filter" value="[% title_filter %]" />
+              </li>
+              <li>
+                <label for="ean">EAN:</label>
+                <input type="text" id="ean" name="EAN_filter" value="[% EAN_filter %]" />
+              </li>
+              <li>
+                <label for="publisher">Publisher:</label>
+                <input type="text" id="publisher" name="publisher_filter" value="[% publisher_filter %]" />
+              </li>
+              <li>
+                <label for="supplier">Supplier:</label>
+                <input type="text" id="supplier" name="supplier_filter" value="[% supplier_filter %]" />
+              </li>
+              <li>
+                <label for="branch">Branch:</label>
+                <select id="branch" name="branch_filter">
+                  <option value="">All</option>
+                  [% FOREACH branches_loo IN branches_loop %]
+                    [% IF ( branches_loo.selected ) %]
+                      <option selected="selected" value="[% branches_loo.branchcode %]">[% branches_loo.branchname %]</option>
+                    [% ELSE %]
+                      <option value="[% branches_loo.branchcode %]">[% branches_loo.branchname %]</option>
+                    [% END %]
+                  [% END %]
+                </select>
+              </li>
+            </ol>
+            <input type="hidden" name="searched" value="1" />
+            <input type="hidden" name="advsearched" value="1" />
+            [% IF ( booksellerid ) %]
+                <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
+            [% END %]
+            [% IF ( basketno ) %]
+                <input type="hidden" name="basketno" value="[% basketno %]" />
+            [% END %]
+            <fieldset class="action">
+              <input type="submit" value="Search" />
+            </fieldset>
+            </div>
+        </fieldset>
+    </form>
+</div>
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
index dcd6ccb..c8c9a20 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -311,6 +311,7 @@
                                 [% ELSE %]
                                     [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% books_loo.ordernumber %]">Add note</a>]
                                 [% END %]
+                                [% IF books_loo.subscriptionid %]<a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% books_loo.subscriptionid %]">Subscription Details</a>[% END %]
                             </p>
                         </td>
                         <td class="number [% IF books_loo.rrp.search('^0') %]error[% END %]">[% books_loo.rrp %]</td>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
index 566318f..fd1a93f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
@@ -221,6 +221,7 @@ $(document).ready(function()
         <input type="hidden" name="basketno" value="[% basketno %]" />
         <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
         <input type="hidden" name="biblionumber" value="[% biblionumber %]" />
+        <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
         <input type="hidden" name="biblioitemnumber" value="[% biblioitemnumber %]" />
         <input type="hidden" name="discount" value="[% discount %]" />
         <input type="hidden" name="listinc" value="[% listincgst %]" />
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
new file mode 100644
index 0000000..0046d43
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt
@@ -0,0 +1,115 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Serials [% biblionumber %]</title>
+[% INCLUDE 'doc-head-close.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript">
+//<![CDATA[
+    function updateRowsVisibility(show_only_renewed) {
+        if ( show_only_renewed ) {
+            $("#srlt [data-reneweddate='']").hide();
+        } else {
+            $("#srlt > tbody > tr").show();
+        }
+          $("#srlt").trigger("sorton", [$("#srlt")[0].config.sortList]);
+    }
+    $(document).ready(function() {
+        $("#srlt").tablesorter({
+            widgets : ['zebra'],
+            headers: {
+                2: { sorter: false },
+                6: { sorter: false },
+                7: { sorter: false }
+            }
+        });
+
+        $("#show_only_renewed").click(function(){
+            updateRowsVisibility($(this+":checked").val());
+        });
+        $("#show_only_renewed").attr('checked', false);
+        updateRowsVisibility(false);
+    });
+ //]]>
+</script>
+</head>
+<body> 
+[% 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="/cgi-bin/koha/acqui/supplier.pl?supplierid=[% supplierid %]">[% booksellername %]</a> &rsaquo; <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basketno %]">Shopping Basket [% basketno %]</a> &rsaquo; Add order from a subscription</div>
+
+<div id="doc3" class="yui-t2">
+    <div id="bd">
+    <div id="yui-main">
+        <div class="yui-b">
+            <h2>Serials subscriptions</h2>
+            [% IF ( routing ) %]
+                <h3>Search for Serial Routing List</h3>
+            [% END %]
+            [% IF ( done_searched ) %]
+                <label for="show_only_renewed">
+                    <input type="checkbox" style="vertical-align: middle;" id="show_only_renewed" />
+                    Show only renewed
+                </label>
+                [% IF ( subs_loop ) %]
+                    <table id="srlt">
+                        <thead>
+                            <tr>
+                                <th>Id</th> 
+                                <th>ISSN</th>
+                                <th>Title</th>
+                                <th> Notes </th>
+                                <th>Library</th>
+                                <th>Call number</th>
+                                <th>Expiration date</th>
+                                <th></th>
+                            </tr>
+                        </thead>
+                        <tbody> 
+                        [% FOREACH subs_loo IN subs_loop %]
+                            <tr data-reneweddate="[% subs_loo.reneweddate %]" >
+                                <td>[% subs_loo.subscriptionid %]</td>
+                                <td>[% subs_loo.issn %]</td>
+                                <td><a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subs_loo.subscriptionid %]" class="button" title="subscription detail">[% IF ( subs_loo.title ) %][% subs_loo.title |html %][% ELSE %]
+                                ---
+                            [% END %][% IF ( subs_loo.unititle ) %], [% subs_loo.unititle %][% END %]</a>
+                                </td>
+                                <td>[% subs_loo.notes %]
+                                    [% IF ( subs_loo.internalnotes ) %]([% subs_loo.internalnotes %])[% END %]
+                                </td>
+                                <td>
+                                    [% IF ( subs_loo.branchcode ) %][% subs_loo.branchcode %][% END %]
+                                </td>
+                                <td>
+                                    [% IF ( subs_loo.callnumber ) %][% subs_loo.callnumber %][% END %]
+                                </td>
+                                <td>
+                                    [% IF ( subs_loo.enddate ) %][% subs_loo.enddate %][% END %]
+                                </td>
+                                <td>
+                                    [% IF ( subs_loo.alreadyOnOrder ) %]
+                                        Outstanding order (only one order per subscription is allowed)
+                                    [% ELSE %]
+                                        <a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]&amp;biblionumber=[% subs_loo.biblionumber %]&amp;subscriptionid=[% subs_loo.subscriptionid %]" title="Order this one">
+                                            Order
+                                        </a>
+                                    [% END %]
+                                </td>
+                            </tr>
+                        [% END %]
+                        </tbody>
+                    </table>
+                [% ELSE %]
+                    <p>Sorry, there is no result for your search.</p>
+                [% END %]
+            [% ELSE %]
+                <p>Please fill in the form to the left to make a search.</p>
+            [% END %]
+        </div>
+    </div>
+
+    <div class="yui-b">
+        [% INCLUDE 'subscriptions-search.inc' %]
+        [% INCLUDE 'acquisitions-menu.inc' %]
+    </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
-- 
1.6.4.2



More information about the Koha-patches mailing list