From 12f62ba1dbefda7ccdaafdc69c168e6658c84468 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 6 Apr 2012 16:57:12 +0200 Subject: [PATCH] Bug 5349: add ability to transfer order lines from one basket to another On basket.pl and parcel.pl there is a 'Transfer' link which allow you to transfer order lines from a basket to another. The link leads to a new page which allow you to search for a bookseller, then display this bookseller's baskets. Then you can pick a basket and the transfer will be done. Signed-off-by: Marc Veron Signed-off-by: Mathieu Saby Signed-off-by: sonia Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- C4/Acquisition.pm | 73 ++++++++- acqui/transferorder.pl | 145 ++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 11 ++ .../prog/en/modules/acqui/basket.tt | 6 + .../prog/en/modules/acqui/parcel.tt | 2 + .../prog/en/modules/acqui/transferorder.tt | 121 +++++++++++++++ 7 files changed, 358 insertions(+), 1 deletion(-) create mode 100755 acqui/transferorder.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/transferorder.tt diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 74aae85f4e..d17c7cf38e 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -57,7 +57,7 @@ BEGIN { &GetLateOrders &GetOrderFromItemnumber &SearchOrder &GetHistory &GetRecentAcqui &ModReceiveOrder &CancelReceipt - &GetCancelledOrders + &GetCancelledOrders &TransferOrder &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid &NewOrderItem &ModItemOrder @@ -1596,6 +1596,77 @@ sub DelOrder { } +=head3 TransferOrder + + my $newordernumber = TransferOrder($ordernumber, $basketno); + +Transfer an order line to a basket. +Mark $ordernumber as cancelled with an internal note 'Cancelled and transfered +to BOOKSELLER on DATE' and create new order with internal note +'Transfered from BOOKSELLER on DATE'. +Move all attached items to the new order. +Received orders cannot be transfered. +Return the ordernumber of created order. + +=cut + +sub TransferOrder { + my ($ordernumber, $basketno) = @_; + + return unless $ordernumber or $basketno; + + my $order = GetOrder( $ordernumber ); + return if $order->{datereceived}; + + my $today = C4::Dates->new()->output("iso"); + my $query = qq{ + SELECT aqbooksellers.name + FROM aqorders + LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno + LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id + WHERE aqorders.ordernumber = ? + }; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($ordernumber); + my ($booksellerfromname) = $sth->fetchrow_array; + + $query = qq{ + SELECT aqbooksellers.name + FROM aqbasket + LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id + WHERE aqbasket.basketno = ? + }; + $sth = $dbh->prepare($query); + $sth->execute($basketno); + my ($booksellertoname) = $sth->fetchrow_array; + + $query = qq{ + UPDATE aqorders + SET datecancellationprinted = CAST(NOW() AS date), + internalnotes = ? + WHERE ordernumber = ? + }; + $sth = $dbh->prepare($query); + $sth->execute("Cancelled and transfered to $booksellertoname on $today", $ordernumber); + + delete $order->{'ordernumber'}; + $order->{'basketno'} = $basketno; + $order->{'internalnotes'} = "Transfered from $booksellerfromname on $today"; + my $newordernumber; + (undef, $newordernumber) = NewOrder($order); + + $query = qq{ + UPDATE aqorders_items + SET ordernumber = ? + WHERE ordernumber = ? + }; + $sth = $dbh->prepare($query); + $sth->execute($newordernumber, $ordernumber); + + return $newordernumber; +} + =head2 FUNCTIONS ABOUT PARCELS =cut diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl new file mode 100755 index 0000000000..27c450955a --- /dev/null +++ b/acqui/transferorder.pl @@ -0,0 +1,145 @@ +#!/usr/bin/perl + +# Script to move an order from a bookseller to another + +# Copyright 2011 BibLibre SARL +# +# 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::Auth; +use C4::Output; +use C4::Context; +use C4::Acquisition; +use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/; +use C4::Members; +use C4::Dates qw/format_date_in_iso/; +use Date::Calc qw/Today/; + +my $input = new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "acqui/transferorder.tmpl", + query => $input, + type => "intranet", + authnotrequired => 1, + flagsrequired => { acquisition => 'order_manage' }, + debug => 1, + } +); + +my $dbh = C4::Context->dbh; + +my $bookselleridfrom = $input->param('bookselleridfrom'); +my $ordernumber = $input->param('ordernumber'); +my $bookselleridto = $input->param('bookselleridto'); +my $basketno = $input->param('basketno'); +my $op = $input->param('op'); +my $query = $input->param('query'); + +my $order = GetOrder($ordernumber); +if($order) { + my $basket = GetBasket($order->{basketno}); + $bookselleridfrom = $basket->{booksellerid} if $basket; +} + +my $booksellerfrom = GetBookSellerFromId($bookselleridfrom); +my $booksellerfromname; +if($booksellerfrom){ + $booksellerfromname = $booksellerfrom->{name}; +} +my $booksellerto = GetBookSellerFromId($bookselleridto); +my $booksellertoname; +if($booksellerto){ + $booksellertoname = $booksellerto->{name}; +} + +if( $basketno && $ordernumber) { + # Transfer order and exit + my $order = GetOrder( $ordernumber ); + my $basket = GetBasket($order->{basketno}); + my $booksellerfrom = GetBookSellerFromId($basket->{booksellerid}); + my $bookselleridfrom = $booksellerfrom->{id}; + + TransferOrder($ordernumber, $basketno); + + my $referrer = $input->param('referrer'); + print $input->redirect($referrer); + exit; +} elsif ( $bookselleridto && $ordernumber) { + # Show open baskets for this bookseller + my $order = GetOrder( $ordernumber ); + my $basketfrom = GetBasket( $order->{basketno} ); + my $booksellerfrom = GetBookSellerFromId( $basketfrom->{booksellerid} ); + $booksellerfromname = $booksellerfrom->{name}; + my $baskets = GetBasketsByBookseller( $bookselleridto ); + my $basketscount = scalar @$baskets; + my @basketsloop = (); + for( my $i = 0 ; $i < $basketscount ; $i++ ){ + my %line; + %line = %{ $baskets->[$i] }; + my $createdby = GetMember(borrowernumber => $line{authorisedby}); + $line{createdby} = "$createdby->{surname}, $createdby->{firstname}"; + push @basketsloop, \%line unless $line{closedate}; + } + $template->param( + show_baskets => 1, + basketsloop => \@basketsloop, + basketfromname => $basketfrom->{basketname}, + ); +} elsif ( $bookselleridfrom && !defined $ordernumber) { + # Show pending orders + my $pendingorders = GetPendingOrders($bookselleridfrom); + my $orderscount = scalar @$pendingorders; + my @ordersloop = (); + for( my $i = 0 ; $i < $orderscount ; $i++ ){ + my %line; + %line = %{ $pendingorders->[$i] }; + push @ordersloop, \%line; + } + $template->param( + ordersloop => \@ordersloop, + ); +} else { + # Search for booksellers to transfer from/to + $op = '' unless $op; + if( $op eq "do_search" ) { + my @booksellers = GetBookSeller($query); + $template->param( + query => $query, + do_search => 1, + booksellersloop => \@booksellers, + ); + } else { + $template->param( + search_form => 1, + ); + } +} + +$template->param( + bookselleridfrom => $bookselleridfrom, + booksellerfromname => $booksellerfromname, + bookselleridto => $bookselleridto, + booksellertoname => $booksellertoname, + ordernumber => $ordernumber, + basketno => $basketno, + referrer => $input->param('referrer') +); + +output_html_with_http_headers $input, $cookie, $template->output; + diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3214ad9670..c885b556b6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2911,6 +2911,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items `cancelledby` varchar(10) default NULL, -- not used? always NULL `datecancellationprinted` date default NULL, -- the date the line item was deleted `notes` mediumtext, -- notes related to this order line + internalnotes mediumtext DEFAULT NULL, -- used by Koha to store some informations, not editable by librarians `supplierreference` mediumtext, -- not used? always NULL `purchaseordernumber` mediumtext, -- not used? always NULL `basketno` int(11) default NULL, -- links this order line to a specific basket (aqbasket.basketno) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ddcc455afe..3d1699fe8a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7104,6 +7104,17 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + ALTER TABLE aqorders + ADD COLUMN internalnotes MEDIUMTEXT DEFAULT NULL AFTER notes + }); + print "Upgrade to $DBversion done (Add internalnotes field in aqorders table)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) 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 ccc97d5ba9..ea7f5d00ff 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -348,6 +348,7 @@ [% ELSE %]

[Add note]

[% END %] +

[% books_loo.internalnotes %]

[% books_loo.rrpgste %] [% books_loo.ecostgste %] @@ -363,6 +364,10 @@ [% UNLESS ( closedate ) %] Modify + [% UNLESS (books_loo.order_received) %] +
+ Transfer + [% END %] [% IF ( books_loo.left_holds_on_order ) %] @@ -435,6 +440,7 @@ [% IF ( order.publicationyear ) %], [% order.publicationyear %][% END %] [% IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement %][% END %]

+

[% order.internalnotes %]

[% order.rrpgste %] [% order.ecostgste %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt index d0c6e274e1..6725948117 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -215,6 +215,8 @@ [% loop_order.budget_name %] Receive +
+ Transfer [% IF ( loop_order.left_holds_on_order ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/transferorder.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/transferorder.tt new file mode 100644 index 0000000000..f694c1f580 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/transferorder.tt @@ -0,0 +1,121 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Acquisitions › Transfer order +[% INCLUDE 'doc-head-close.inc' %] + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'acquisitions-search.inc' %] + + + +
+
+
+
+ [% IF ( show_baskets ) %] +

Baskets for [% booksellertoname %]

+ [% IF ( basketsloop ) %] + + + + + + + + + [% FOREACH basket IN basketsloop %] + + + + + + [% END %] + +
Basket (#)Created byDate 
[% basket.basketname %] (#[% basket.basketno %])[% basket.createdby %][% basket.creationdate %]Choose +
+ [% ELSE %] +

There is no open baskets for this supplier.

+ [% END %] + [% END %] + [% IF ( ordersloop ) %] +

Orders for [% booksellerfromname %]

+ + + + + + + + [% FOREACH ordersloo IN ordersloop %] + + + + + + [% END %] + +
OrderSummary 
[% ordersloo.ordernumber %] + [% ordersloo.title |html %] + [% IF ( ordersloo.author ) %] by [% ordersloo.author %][% END %] + [% IF ( ordersloo.isbn ) %] – [% ordersloo.isbn %][% END %] + [% IF ( ordersloo.publishercode ) %]
Publisher :[% ordersloo.publishercode %][% END %] +
Transfer
+ [% END %] + [% IF ( do_search ) %] + [% IF ( bookselleridfrom ) %] +

Choose a vendor to transfer to

+ [% ELSE %] +

Choose a vendor to transfer from

+ [% END %] + [% IF ( booksellersloop ) %] + + + + + + + [% FOREACH bookseller IN booksellersloop %] + + + + + [% END %] + +
Name 
[% bookseller.name %]Choose
+ [% ELSE %] +

No results found.

+ [% END %] + [% END %] + [% IF ( search_form ) %] + [% IF ( bookselleridfrom ) %] +

Search for a vendor to transfer to

+ [% ELSE %] +

Search for a vendor to transfer from

+ [% END %] +
+ + + [% IF ( ordernumber ) %] + + [% END %] + [% IF ( bookselleridfrom ) %] + + [% END %] + + + +
+ [% END %] +
+
+ +
+ [% INCLUDE 'acquisitions-menu.inc' %] +
+
+
+[% INCLUDE 'intranet-bottom.inc' %] -- 2.39.5