From 0c963a2d9c01e28bb2968edb4274cf5cf130293e Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 12 Jul 2012 10:31:49 +0530 Subject: [PATCH 3/3] 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 --- C4/Serials.pm | 100 +++++++++++++++++- acqui/neworderempty.pl | 2 + acqui/newordersubscription.pl | 108 ++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++ .../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, 397 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 + +@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 0dd2396..a83ca4b 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 2e67daa..ae9ca76 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5536,6 +5536,7 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +<<<<<<< HEAD $DBversion = "3.09.00.027"; if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $dbh->do(" @@ -5596,6 +5597,13 @@ if (C4::Context->preference("Version") < TransformToNum($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 @@