From 1e9331104bade6a13a1c5ff0cb16a7b30eac54f4 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 12 Jul 2012 10:31:49 +0530 Subject: [PATCH] [SIGNED-OFF] Bug 8415 - Link Serial with Acquisition 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". Signed-off-by: Amit Gupta Signed-off-by: Katrin Fischer --- C4/Serials.pm | 100 ++++++++++++++++- acqui/neworderempty.pl | 2 + acqui/newordersubscription.pl | 108 ++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 10 +- .../en/includes/acquisitions-add-to-basket.inc | 1 + .../prog/en/includes/subscriptions-search.inc | 60 ++++++++++ .../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, 397 insertions(+), 2 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 eb620cc..9483c3d 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -52,7 +52,8 @@ BEGIN { &getroutinglist &delroutingmember &addroutingmember &reorder_members &check_routing &updateClaim &removeMissingIssue - &CountIssues + &CountIssues &SearchSubscriptions + &subscriptionCurrentlyOnOrder HasItems &GetSubscriptionsFromBorrower @@ -152,6 +153,103 @@ sub GetLateIssues { return @issuelist; } +=head2 SearchSubscriptions + +@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 4a3eb49..5a4216d 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'); @@ -351,6 +352,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..86db2e2 --- /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 8fd20a4..ec4ff30 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2780,6 +2780,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no) `claims_count` int(11) default 0, -- count of claim letters generated `claimed_date` date default NULL, -- last date a claim was generated + `subscriptionid` int(11) default NULL, parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent PRIMARY KEY (`ordernumber`), KEY `basketno` (`basketno`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 5d6f7db..3fa0541 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5610,7 +5610,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion($DBversion); } -$DBversion = "3.09.00.029"; # FIXME +$DBversion = "3.09.00.029"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $dbh->do("UPDATE systempreferences SET options=concat(options,'|EAN13') WHERE variable='itemBarcodeInputFilter' AND options NOT LIKE '%EAN13%'"); print "Upgrade to $DBversion done (Add itemBarcodeInputFilter choice EAN13)\n"; @@ -5859,6 +5859,14 @@ 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 @@
  • +
  • From a Subscription
  • From a suggestion
  • From a new (empty) record
  • From an external source
  • 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..17fcd44 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc @@ -0,0 +1,60 @@ + +
    +
    +
    + [% IF ( unfolded_search ) %] +
    + [% ELSE %] + Advanced search + +
    +
    +
    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 %] [Add note] [% END %] + [% IF books_loo.subscriptionid %]Subscription Details[% END %]

    [% books_loo.rrp %] 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 0195dd8..c4957ff 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() + 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..127e57d --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt @@ -0,0 +1,115 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Serials [% biblionumber %] +[% INCLUDE 'doc-head-close.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'acquisitions-search.inc' %] + + + +
    +
    +
    +
    +

    Serials subscriptions

    + [% IF ( routing ) %] +

    Search for Serial Routing List

    + [% END %] + [% IF ( done_searched ) %] + + [% IF ( subs_loop ) %] + + + + + + + + + + + + + + + [% FOREACH subs_loo IN subs_loop %] + + + + + + + + + + + [% END %] + +
    IdISSNTitle Notes LibraryCall numberExpiration date
    [% subs_loo.subscriptionid %][% subs_loo.issn %][% IF ( subs_loo.title ) %][% subs_loo.title |html %][% ELSE %] + --- + [% END %][% IF ( subs_loo.unititle ) %], [% subs_loo.unititle %][% END %] + [% subs_loo.notes %] + [% IF ( subs_loo.internalnotes ) %]([% subs_loo.internalnotes %])[% END %] + + [% IF ( subs_loo.branchcode ) %][% subs_loo.branchcode %][% END %] + + [% IF ( subs_loo.callnumber ) %][% subs_loo.callnumber %][% END %] + + [% IF ( subs_loo.enddate ) %][% subs_loo.enddate %][% END %] + + [% IF ( subs_loo.alreadyOnOrder ) %] + Outstanding order (only one order per subscription is allowed) + [% ELSE %] + + Order + + [% END %] +
    + [% ELSE %] +

    Sorry, there is no result for your search.

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

    Please fill in the form to the left to make a search.

    + [% END %] +
    +
    + +
    + [% INCLUDE 'subscriptions-search.inc' %] + [% INCLUDE 'acquisitions-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] -- 1.7.9.5