@@ -, +, @@ - Adds 2 fields: subscription.reneweddate and aqorders.subscriptionid. - Removes 2 unused fields: aqorders.serialid and aqorders.subscription. --- C4/Acquisition.pm | 63 +++++++++- C4/Budgets.pm | 23 ++++ C4/Serials.pm | 24 +++- acqui/addorder.pl | 1 + acqui/finishreceive.pl | 1 - acqui/neworderempty.pl | 32 +++++- acqui/newordersubscription.pl | 108 ++++++++++++++++++ acqui/orderreceive.pl | 1 + installer/data/mysql/kohastructure.sql | 7 +- installer/data/mysql/updatedatabase.pl | 11 ++ .../en/includes/acquisitions-add-to-basket.inc | 19 ++-- .../prog/en/includes/subscriptions-search.inc | 55 +++++++++ .../prog/en/modules/acqui/neworderempty.tt | 103 ++++++++++------- .../prog/en/modules/acqui/newordersubscription.tt | 120 ++++++++++++++++++++ .../prog/en/modules/acqui/orderreceive.tt | 50 ++++---- .../prog/en/modules/serials/serials-home.tt | 1 + serials/serials-search.pl | 2 +- serials/subscription-detail.pl | 95 +++++++++++----- 18 files changed, 600 insertions(+), 116 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 --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -58,7 +58,7 @@ BEGIN { &SearchOrder &GetHistory &GetRecentAcqui &ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber &GetCancelledOrders - + &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid &NewOrderItem &ModOrderItem &ModItemOrder &GetParcels &GetParcel @@ -1007,6 +1007,67 @@ sub GetOrder { return $data; } +=head3 GetLastOrderNotReceivedFromSubscriptionid + + $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid); + +Returns a reference-to-hash describing the last order not received for a subscription. + +=cut + +sub GetLastOrderNotReceivedFromSubscriptionid { + my ( $subscriptionid ) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT * FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived IS NULL + LIMIT 1 + |; + my $sth = $dbh->prepare( $query ); + $sth->execute( $subscriptionid ); + my $order = $sth->fetchrow_hashref; + return $order; +} + +=head3 GetLastOrderReceivedFromSubscriptionid + + $order = &GetLastOrderReceivedFromSubscriptionid($subscriptionid); + +Returns a reference-to-hash describing the last order received for a subscription. + +=cut + +sub GetLastOrderReceivedFromSubscriptionid { + my ( $subscriptionid ) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT * FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived = + ( + SELECT MAX( aqorders.datereceived ) + FROM aqorders + LEFT JOIN subscription + ON ( aqorders.subscriptionid = subscription.subscriptionid ) + WHERE aqorders.subscriptionid = ? + AND aqorders.datereceived IS NOT NULL + ) + ORDER BY ordernumber DESC + LIMIT 1 + |; + my $sth = $dbh->prepare( $query ); + $sth->execute( $subscriptionid, $subscriptionid ); + my $order = $sth->fetchrow_hashref; + return $order; + +} + + #------------------------------------------------------------# =head3 NewOrder --- a/C4/Budgets.pm +++ a/C4/Budgets.pm @@ -41,6 +41,7 @@ BEGIN { &DelBudget &GetBudgetSpent &GetBudgetOrdered + &GetBudgetName &GetPeriodsCount &GetChildBudgetsSpent @@ -356,6 +357,28 @@ sub GetBudgetOrdered { return $sum; } +=head2 GetBudgetName + + my $budget_name = &GetBudgetName($budget_id); + +get the budget_name for a given budget_id + +=cut + +sub GetBudgetName { + my ( $budget_id ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( + qq| + SELECT budget_name + FROM aqbudgets + WHERE budget_id = ? + |); + + $sth->execute($budget_id); + return $sth->fetchrow_array; +} + # ------------------------------------------------------------------- sub GetBudgetAuthCats { my ($budget_period_id) = shift; --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -55,6 +55,7 @@ BEGIN { &CountIssues HasItems &GetSubscriptionsFromBorrower + &subscriptionCurrentlyOnOrder ); } @@ -1441,7 +1442,7 @@ sub ReNewSubscription { # renew subscription $query = qq| UPDATE subscription - SET startdate=?,numberlength=?,weeklength=?,monthlength=? + SET startdate=?,numberlength=?,weeklength=?,monthlength=?,reneweddate=NOW() WHERE subscriptionid=? |; $sth = $dbh->prepare($query); @@ -2532,6 +2533,27 @@ sub ReopenSubscription { $sth->execute( $subscriptionid ); } +=head2 subscriptionCurrentlyOnOrder + + $bool = subscriptionCurrentlyOnOrder( $subscriptionid ); + +Return 1 if subscription is currently 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; +} + 1; __END__ --- a/acqui/addorder.pl +++ a/acqui/addorder.pl @@ -153,6 +153,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $orderinfo = $input->Vars; $orderinfo->{'list_price'} ||= 0; $orderinfo->{'uncertainprice'} ||= 0; +$orderinfo->{subscriptionid} ||= undef; my $user = $input->remote_user; --- a/acqui/finishreceive.pl +++ a/acqui/finishreceive.pl @@ -52,7 +52,6 @@ my $invoiceno = $invoice->{invoicenumber}; my $datereceived = $invoice->{shipmentdate}; my $booksellerid = $input->param('booksellerid'); my $cnt = 0; -my $error_url_str; my $ecost = $input->param('ecost'); my $rrp = $input->param('rrp'); my $note = $input->param("note"); --- a/acqui/neworderempty.pl +++ a/acqui/neworderempty.pl @@ -97,7 +97,6 @@ my $budget_id = $input->param('budget_id') || 0; my $title = $input->param('title'); my $author = $input->param('author'); my $publicationyear = $input->param('publicationyear'); -my $bookseller = GetBookSellerFromId($booksellerid); # FIXME: else ERROR! my $ordernumber = $input->param('ordernumber') || ''; our $biblionumber = $input->param('biblionumber'); our $basketno = $input->param('basketno'); @@ -105,6 +104,7 @@ my $suggestionid = $input->param('suggestionid'); my $close = $input->param('close'); my $uncertainprice = $input->param('uncertainprice'); my $import_batch_id = $input->param('import_batch_id'); # if this is filled, we come from a staged file, and we will return here after saving the order ! +my $subscriptionid = $input->param('subscriptionid'); my $data; my $new = 'no'; @@ -129,6 +129,9 @@ if(!$basketno) { } our $basket = GetBasket($basketno); +$booksellerid = $basket->{booksellerid} unless $booksellerid; +my $bookseller = GetBookSellerFromId($booksellerid); + my $contract = &GetContract($basket->{contractnumber}); #simple parameters reading (all in one :-) @@ -186,10 +189,8 @@ else { #modify order $biblionumber = $data->{'biblionumber'}; $budget_id = $data->{'budget_id'}; - #get basketno and supplierno. too! - my $data2 = GetBasket( $data->{'basketno'} ); - $basketno = $data2->{'basketno'}; - $booksellerid = $data2->{'booksellerid'}; + $basket = GetBasket( $data->{'basketno'} ); + $basketno = $basket->{'basketno'}; } my $suggestion; @@ -321,6 +322,26 @@ if (C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber) { my @itemtypes; @itemtypes = C4::ItemType->all unless C4::Context->preference('item-level_itypes'); +if ( defined $subscriptionid ) { + my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; + if ( defined $lastOrderReceived ) { + $budget_id = $lastOrderReceived->{budgetid}; + $data->{listprice} = $lastOrderReceived->{listprice}; + $data->{uncertainprice} = $lastOrderReceived->{uncertainprice}; + $data->{gstrate} = $lastOrderReceived->{gstrate}; + $data->{discount} = $lastOrderReceived->{discount}; + $data->{rrp} = $lastOrderReceived->{rrp}; + $data->{ecost} = $lastOrderReceived->{ecost}; + $data->{quantity} = $lastOrderReceived->{quantity}; + $data->{unitprice} = $lastOrderReceived->{unitprice}; + $data->{notes} = $lastOrderReceived->{notes}; + $data->{sort1} = $lastOrderReceived->{sort1}; + $data->{sort2} = $lastOrderReceived->{sort2}; + + $basket = GetBasket( $input->param('basketno') ); + } +} + # Find the items.barcode subfield for barcode validations my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); @@ -393,6 +414,7 @@ $template->param( publishercode => $data->{'publishercode'}, barcode_subfield => $barcode_subfield, import_batch_id => $import_batch_id, + subscriptionid => $subscriptionid, (uc(C4::Context->preference("marcflavour"))) => 1 ); --- a/acqui/newordersubscription.pl +++ a/acqui/newordersubscription.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl + +# Copyright 2012 BibLibre +# +# 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 Modern::Perl; +use CGI; +use C4::Acquisition; +use C4::Auth; +use C4::Bookseller qw/GetBookSellerFromId/; +use C4::Branch; +use C4::Context; +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.tt", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => 'order_manage' }, + } +); + +my $basket = GetBasket($basketno); +$booksellerid = $basket->{booksellerid} unless $booksellerid; +my ($bookseller) = GetBookSellerFromId($booksellerid); + +my @subscriptions; +if ($searched) { + @subscriptions = SearchSubscriptions({ + title => $title, + issn => $ISSN, + ean => $EAN, + publisher => $publisher, + bookseller => $supplier, + branch => $branch + }); +} + +foreach my $sub (@subscriptions) { + $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, + 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}, + dateformat => C4::Context->preference("dateformat"), +); +output_html_with_http_headers $query, $cookie, $template->output; + --- a/acqui/orderreceive.pl +++ a/acqui/orderreceive.pl @@ -199,6 +199,7 @@ $template->param( biblionumber => $order->{'biblionumber'}, ordernumber => $order->{'ordernumber'}, biblioitemnumber => $order->{'biblioitemnumber'}, + subscriptionid => $order->{subscriptionid}, booksellerid => $order->{'booksellerid'}, freight => $freight, name => $bookseller->{'name'}, --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1908,6 +1908,7 @@ CREATE TABLE `subscription` ( `graceperiod` int(11) NOT NULL default '0', `enddate` date default NULL, `closed` INT(1) NOT NULL DEFAULT 0, + `reneweddate` date default NULL, PRIMARY KEY (`subscriptionid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2772,8 +2773,6 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items `notes` mediumtext, -- notes related to this order line `supplierreference` mediumtext, -- not used? always NULL `purchaseordernumber` mediumtext, -- not used? always NULL - `subscription` tinyint(1) default NULL, -- not used? always NULL - `serialid` varchar(30) default NULL, -- not used? always NULL `basketno` int(11) default NULL, -- links this order line to a specific basket (aqbasket.basketno) `biblioitemnumber` int(11) default NULL, -- links this order line the biblioitems table (biblioitems.biblioitemnumber) `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order line was last modified @@ -2791,6 +2790,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, -- links this order line to a subscription (subscription.subscriptionid) parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent PRIMARY KEY (`ordernumber`), KEY `basketno` (`basketno`), @@ -2798,7 +2798,8 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items KEY `budget_id` (`budget_id`), CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -6655,6 +6655,17 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q{ALTER TABLE aqorders DROP COLUMN serialid;}); + $dbh->do(q{ALTER TABLE aqorders DROP COLUMN subscription;}); + $dbh->do(q{ALTER TABLE aqorders ADD COLUMN subscriptionid INT(11) DEFAULT NULL;}); + $dbh->do(q{ALTER TABLE aqorders ADD CONSTRAINT aqorders_subscriptionid FOREIGN KEY (subscriptionid) REFERENCES subscription (subscriptionid) ON DELETE CASCADE ON UPDATE CASCADE;}); + $dbh->do(q{ALTER TABLE subscription ADD COLUMN reneweddate DATE DEFAULT NULL;}); + print "Upgrade to $DBversion done (Bug 5343: table aqorders: DROP serialid and subscription fields and ADD subscriptionid, table subscription: ADD reneweddate)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-add-to-basket.inc @@ -1,17 +1,22 @@
Add order to basket [% IF has_budgets %] -
- - -
[% ELSE %] You can't create any orders unless you first define a budget and a fund. [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc @@ -0,0 +1,55 @@ +
+
+
+ Advanced search + +
+
+
+ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -361,46 +361,48 @@ $(document).ready(function()
[% END %] - [% IF (AcqCreateItemOrdering) %] - - - -
- Item - [% IF ( NoACQframework ) %] -
No ACQ framework, using default. You should create a framework with code ACQ, the items framework would be used
- [% END %] - -
- -
+ [% UNLESS subscriptionid %][% # it is a suggestion, we have not items %] + [% IF (AcqCreateItemOrdering) %] + + + +
+ Item + [% IF ( NoACQframework ) %] +
No ACQ framework, using default. You should create a framework with code ACQ, the items framework would be used
+ [% END %] + +
+ +
+ [% END %][%# UNLESS subscriptionid %] [% END %][%# IF (AcqCreateItemOrdering) %]
Accounting Details @@ -412,9 +414,17 @@ $(document).ready(function() [% ELSE %] [% IF (AcqCreateItemOrdering) %] - + [% IF subscriptionid %] + + [% ELSE %] + + [% END %] [% ELSE %] - + [% IF subscriptionid %] + + [% ELSE %] + + [% END %] [% END %] [% END %] @@ -586,14 +596,19 @@ $(document).ready(function() [% END %] - +
+ [% IF (suggestionid) %] Cancel [% ELSE %] - Cancel + [% IF subscriptionid %] + Cancel + [% ELSE %] + Cancel + [% END %] [% END %]
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersubscription.tt @@ -0,0 +1,120 @@ +[% USE KohaDates %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Serials [% biblionumber %] + +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables-strings.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 sub IN subs_loop %] + + + + + + + + + + [% END %] + +
ISSNTitle Notes LibraryCall numberExpiration date
[% sub.issn %][% IF (sub.title) %][% sub.title |html %][% ELSE %] + --- + [% END %][% IF (sub.unititle) %], [% sub.unititle %][% END %] + [% notes %] + [% IF (sub.internalnotes) %]([% sub.internalnotes %])[% END %] + + [% IF (sub.branchcode) %][% sub.branchcode %][% END %] + + [% IF (sub.callnumber) %][% sub.callnumber %][% END %] + + [% IF (sub.enddate) %][% sub.enddate | $KohaDates %][% END %] + + [% IF (sub.alreadyOnOrder) %] + Outstanding order (only one order per subscription is allowed) + [% ELSE %] + + Order + + [% END %] +
+ [% ELSE %] +

Sorry, there is no result for your search.

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

Use the search form on the left to find subscriptions.

+ [% END %] +
+
+ +
+ [% INCLUDE 'subscriptions-search.inc' %] + [% INCLUDE 'acquisitions-menu.inc' %] +
+
+[% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -218,17 +218,19 @@ function IEEventHandler_KeyDown() {
-
- Item - [% IF ( NoACQframework ) %] -

- No ACQ framework, using default. You should create a - framework with code ACQ, the items framework would be - used -

- [% END %] -
-
+ [% UNLESS subscriptionid %] +
+ Item + [% IF ( NoACQframework ) %] +

+ No ACQ framework, using default. You should create a + framework with code ACQ, the items framework would be + used +

+ [% END %] +
+
+ [% END %] [% ELSIF (AcqCreateItem == 'ordering') %] [% IF (items.size) %]
Items
@@ -294,9 +296,9 @@ function IEEventHandler_KeyDown() {
  • [% bookfund %]
  • [% IF ( memberfirstname and membersurname ) %][% IF ( memberfirstname ) %][% memberfirstname %][% END %] [% membersurname %][% ELSE %]No name[% END %]
  • - [% IF ( edit ) %] + [% IF ( edit and not subscriptionid) %] - [% ELSE %] + [% ELSE%] [% END %]
  • @@ -307,22 +309,22 @@ function IEEventHandler_KeyDown() { [% IF ( quantityreceived ) %] [% IF ( edit ) %] - - [% ELSE %] - [% IF ( items ) %] - + [% ELSE %] - - [% END %] - + [% IF ( items ) %] + + [% ELSE %] + + [% END %] + [% END %] [% ELSE %] - [% IF ( items ) %] - + [% IF ( subscriptionid ) %] + [% ELSE %] - + [% END %] - + [% END %]
    + [% INCLUDE 'subscriptions-search.inc' %] [% INCLUDE 'serials-menu.inc' %]
    --- a/serials/serials-search.pl +++ a/serials/serials-search.pl @@ -106,7 +106,7 @@ my $branches = GetBranches(); my @branches_loop; foreach (sort keys %$branches){ my $selected = 0; - $selected = 1 if( $branch eq $_ ); + $selected = 1 if( defined $branch and $branch eq $_ ); push @branches_loop, { branchcode => $_, branchname => $branches->{$_}->{'branchname'}, --- a/serials/subscription-detail.pl +++ a/serials/subscription-detail.pl @@ -15,10 +15,12 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; +use Modern::Perl; use CGI; +use C4::Acquisition; use C4::Auth; +use C4::Bookseller qw/GetBookSellerFromId/; +use C4::Budgets; use C4::Koha; use C4::Dates qw/format_date/; use C4::Serials; @@ -128,34 +130,33 @@ if (! $subs->{periodicity}) { my $default_bib_view = get_default_view(); my ( $order, $bookseller, $tmpl_infos ); -# FIXME = see http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=5335#c52 -#if ( defined $subscriptionid ) { -# my $lastOrderNotReceived = GetLastOrderNotReceivedFromSubscriptionid $subscriptionid; -# my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; -# if ( defined $lastOrderNotReceived ) { -# my $basket = GetBasket $lastOrderNotReceived->{basketno}; -# my $bookseller = GetBookSellerFromId $basket->{booksellerid}; -# ( $tmpl_infos->{valuegsti_ordered}, $tmpl_infos->{valuegste_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{gstrate}, $bookseller ); -# $tmpl_infos->{valuegsti_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered} ); -# $tmpl_infos->{valuegste_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered} ); -# $tmpl_infos->{budget_name_ordered} = GetBudgetName $lastOrderNotReceived->{budget_id}; -# $tmpl_infos->{basketno} = $lastOrderNotReceived->{basketno}; -# $tmpl_infos->{ordered_exists} = 1; -# } -# if ( defined $lastOrderReceived ) { -# my $basket = GetBasket $lastOrderReceived->{basketno}; -# my $bookseller = GetBookSellerFromId $basket->{booksellerid}; -# ( $tmpl_infos->{valuegsti_spent}, $tmpl_infos->{valuegste_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{gstrate}, $bookseller ); -# $tmpl_infos->{valuegsti_spent} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent} ); -# $tmpl_infos->{valuegste_spent} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent} ); -# $tmpl_infos->{budget_name_spent} = GetBudgetName $lastOrderReceived->{budget_id}; -# $tmpl_infos->{invoicenumber} = $lastOrderReceived->{booksellerinvoicenumber}; -# $tmpl_infos->{spent_exists} = 1; -# } -#} +if ( defined $subscriptionid ) { + my $lastOrderNotReceived = GetLastOrderNotReceivedFromSubscriptionid $subscriptionid; + my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; + if ( defined $lastOrderNotReceived ) { + my $basket = GetBasket $lastOrderNotReceived->{basketno}; + my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + ( $tmpl_infos->{valuegsti_ordered}, $tmpl_infos->{valuegste_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{gstrate}, $bookseller ); + $tmpl_infos->{valuegsti_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered} ); + $tmpl_infos->{valuegste_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered} ); + $tmpl_infos->{budget_name_ordered} = GetBudgetName $lastOrderNotReceived->{budget_id}; + $tmpl_infos->{basketno} = $lastOrderNotReceived->{basketno}; + $tmpl_infos->{ordered_exists} = 1; + } + if ( defined $lastOrderReceived ) { + my $basket = GetBasket $lastOrderReceived->{basketno}; + my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + ( $tmpl_infos->{valuegsti_spent}, $tmpl_infos->{valuegste_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{gstrate}, $bookseller ); + $tmpl_infos->{valuegsti_spent} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent} ); + $tmpl_infos->{valuegste_spent} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent} ); + $tmpl_infos->{budget_name_spent} = GetBudgetName $lastOrderReceived->{budget_id}; + $tmpl_infos->{invoicenumber} = $lastOrderReceived->{booksellerinvoicenumber}; + $tmpl_infos->{spent_exists} = 1; + } +} $template->param( - subscriptionid => $subscriptionid, + subscriptionid => $subscriptionid, serialslist => \@serialslist, hasRouting => $hasRouting, routing => C4::Context->preference("RoutingSerials"), @@ -175,7 +176,9 @@ $template->param( default_bib_view => $default_bib_view, (uc(C4::Context->preference("marcflavour"))) => 1, show_acquisition_details => defined $tmpl_infos->{ordered_exists} || defined $tmpl_infos->{spent_exists} ? 1 : 0, - ); + basketno => $order->{basketno}, + %$tmpl_infos, +); output_html_with_http_headers $query, $cookie, $template->output; @@ -193,3 +196,37 @@ sub get_default_view { } return 'detail'; } + +sub get_value_with_gst_params { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + if ( $bookseller->{listincgst} ) { + return ( $value, $value / ( 1 + $gstrate ) ); + } else { + return ( $value * ( 1 + $gstrate ), $value ); + } +} + +sub get_gste { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + if ( $bookseller->{invoiceincgst} ) { + return $value / ( 1 + $gstrate ); + } else { + return $value; + } +} + +sub get_gst { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + if ( $bookseller->{invoiceincgst} ) { + return $value / ( 1 + $gstrate ) * $gstrate; + } else { + return $value * ( 1 + $gstrate ) - $value; + } +} + --