From 5a4ff9cedf127eadce0c24eb133219ae507b7baf Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 13 Jan 2012 16:55:10 +0100 Subject: [PATCH] [SIGNED-OFF] Bug 7175: Allow to choose which items to receive If AcqCreateItem=ordering, when you receive an order, you now have a list of all created items and checkboxes that permit you to choose which items you want to receive. A 'Edit' link open additem.pl page in a popup to allow you edit the items before receiving them (popup is automatically closed after modification, and items table is automatically updated) If quantity is set manually in the text box, the appropriate number of checkbox are checked from top to bottom and a warning shows up if quantity is greater than order quantity Signed-off-by: Nicole C. Engard Tested ordering, receiving in all combinations and the editing and checkboxes options work lovely. --- C4/Acquisition.pm | 41 +++++++- acqui/finishreceive.pl | 9 +- acqui/orderreceive.pl | 48 +++++++- catalogue/getitem-ajax.pl | 73 ++++++++++++ cataloguing/additem.pl | 1 + .../prog/en/modules/acqui/orderreceive.tt | 117 +++++++++++++++++++- .../prog/en/modules/cataloguing/additem.tt | 8 ++ 7 files changed, 283 insertions(+), 14 deletions(-) create mode 100755 catalogue/getitem-ajax.pl diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index e881a16..4518d25 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -57,7 +57,7 @@ BEGIN { &ModReceiveOrder &ModOrderBiblioitemNumber &GetCancelledOrders - &NewOrderItem &ModOrderItem + &NewOrderItem &ModOrderItem &ModItemOrder &GetParcels &GetParcel &GetContracts &GetContract @@ -1053,6 +1053,29 @@ sub ModOrderItem { return 0; } +=head3 ModItemOrder + + ModItemOrder($itemnumber, $ordernumber); + +Modifies the ordernumber of an item in aqorders_items. + +=cut + +sub ModItemOrder { + my ($itemnumber, $ordernumber) = @_; + + return unless ($itemnumber and $ordernumber); + + my $dbh = C4::Context->dbh; + my $query = qq{ + UPDATE aqorders_items + SET ordernumber = ? + WHERE itemnumber = ? + }; + my $sth = $dbh->prepare($query); + return $sth->execute($ordernumber, $itemnumber); +} + #------------------------------------------------------------# @@ -1138,7 +1161,7 @@ C<$ordernumber>. sub ModReceiveOrder { my ( $biblionumber, $ordernumber, $quantrec, $user, $cost, - $invoiceno, $freight, $rrp, $budget_id, $datereceived + $invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items ) = @_; my $dbh = C4::Context->dbh; @@ -1181,7 +1204,19 @@ sub ModReceiveOrder { $order->{'quantity'} -= $quantrec; $order->{'quantityreceived'} = 0; my $newOrder = NewOrder($order); -} else { + # Change ordernumber in aqorders_items for items not received + my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} ); + my $count = scalar @orderitems; + + for (my $i=0; $i<$count; $i++){ + foreach (@$received_items){ + splice (@orderitems, $i, 1) if ($orderitems[$i] == $_); + } + } + foreach (@orderitems) { + ModItemOrder($_, $newOrder); + } + } else { $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, unitprice=?,freight=?,rrp=? diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index d09a40a..84391f5 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -94,9 +94,14 @@ if ($quantityrec > $origquantityrec ) { NewOrderItem($itemnumber, $ordernumber); } } - + + my @received_items = (); + if(C4::Context->preference('AcqCreateItem') eq 'ordering') { + @received_items = $input->param('items_to_receive'); + } + # save the quantity received. - $datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived); + $datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived, \@received_items); } update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber ); diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 430faf8..1ea0bd1 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -112,16 +112,51 @@ my $count = scalar @$results; # prepare the form for receiving if ( $count == 1 ) { my $order = $results->[0]; - if (C4::Context->preference('AcqCreateItem') eq 'receiving') { - # Check if ACQ framework exists - my $marc = GetMarcStructure(1, 'ACQ'); - unless($marc) { - $template->param('NoACQframework' => 1); - } + + # Check if ACQ framework exists + my $acq_fw = GetMarcStructure(1, 'ACQ'); + unless($acq_fw) { + $template->param('NoACQframework' => 1); + } + + my $AcqCreateItem = C4::Context->preference('AcqCreateItem'); + if ($AcqCreateItem eq 'receiving') { $template->param( AcqCreateItemReceiving => 1, UniqueItemFields => C4::Context->preference('UniqueItemFields'), ); + } elsif ($AcqCreateItem eq 'ordering') { + my $fw = ($acq_fw) ? 'ACQ' : ''; + my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber}); + my @items; + foreach (@itemnumbers) { + my $item = GetItem($_); + if($item->{homebranch}) { + $item->{homebranchname} = GetBranchName($item->{homebranch}); + } + if($item->{holdingbranch}) { + $item->{holdingbranchname} = GetBranchName($item->{holdingbranch}); + } + if(my $code = GetAuthValCode("items.notforloan", $fw)) { + $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan}); + } + if(my $code = GetAuthValCode("items.restricted", $fw)) { + $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted}); + } + if(my $code = GetAuthValCode("items.location", $fw)) { + $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location}); + } + if(my $code = GetAuthValCode("items.ccode", $fw)) { + $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode}); + } + if(my $code = GetAuthValCode("items.materials", $fw)) { + $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials}); + } + my $itemtype = getitemtypeinfo($item->{itype}); + $item->{itemtype} = $itemtype->{description}; + push @items, $item; + } + $template->param(items => \@items); } if ( $order->{'unitprice'} == 0 ) { @@ -136,6 +171,7 @@ if ( $count == 1 ) { my $budget = GetBudget( $order->{'budget_id'} ); $template->param( + AcqCreateItem => $AcqCreateItem, count => 1, biblionumber => $order->{'biblionumber'}, ordernumber => $order->{'ordernumber'}, diff --git a/catalogue/getitem-ajax.pl b/catalogue/getitem-ajax.pl new file mode 100755 index 0000000..3bab891 --- /dev/null +++ b/catalogue/getitem-ajax.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +# Copyright BibLibre 2012 +# +# 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 JSON; + +use C4::Biblio; +use C4::Branch; +use C4::Items; +use C4::Koha; +use C4::Output; + +my $cgi = new CGI; +my $item = {}; +my $itemnumber = $cgi->param('itemnumber'); + +if($itemnumber) { + my $acq_fw = GetMarcStructure(1, 'ACQ'); + my $fw = ($acq_fw) ? 'ACQ' : ''; + $item = GetItem($itemnumber); + + if($item->{homebranch}) { + $item->{homebranchname} = GetBranchName($item->{homebranch}); + } + + if($item->{holdingbranch}) { + $item->{holdingbranchname} = GetBranchName($item->{holdingbranch}); + } + + if(my $code = GetAuthValCode("items.notforloan", $fw)) { + $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan}); + } + + if(my $code = GetAuthValCode("items.restricted", $fw)) { + $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted}); + } + + if(my $code = GetAuthValCode("items.location", $fw)) { + $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location}); + } + + if(my $code = GetAuthValCode("items.ccode", $fw)) { + $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode}); + } + + if(my $code = GetAuthValCode("items.materials", $fw)) { + $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials}); + } + + my $itemtype = getitemtypeinfo($item->{itype}); + $item->{itemtype} = $itemtype->{description}; +} + +my $json_text = to_json( $item, { utf8 => 1 } ); + +output_with_http_headers $cgi, undef, $json_text, 'json'; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 9c8120e..f970890 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -724,6 +724,7 @@ $template->param( itemtagsubfield => $itemtagsubfield, op => $nextop, opisadd => ($nextop eq "saveitem") ? 0 : 1, + popup => $input->param('popup') ? 1: 0, C4::Search::enabled_staff_search_views, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 97a7223..821dcd3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -32,9 +32,68 @@ return true; } + [% IF (AcqCreateItem == 'ordering') %] + var items_columns = [null, null, 'barcode', 'homebranchname', + 'holdingbranchname', 'notforloan', 'restricted', 'location', + 'itemcallnumber', 'copynumber', 'stocknumber', 'collection', + 'itemtype', 'materials', 'itemnotes']; + + function PopupEditPage(biblionumber, itemnumber) { + var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=" + + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem"; + var w = window.open(url); + var watchClose = setInterval(function() { + if (w.closed) { + clearTimeout(watchClose); + $.getJSON('/cgi-bin/koha/catalogue/getitem-ajax.pl', + { + 'itemnumber': itemnumber + }, + function(item) { + var tds = $("#item_"+itemnumber+" td"); + for(var i=2; i qtyto) { + $("#qtyrecerror").show(); + } else { + $("#qtyrecerror").hide(); + } + CheckNItems($(this).val()); + }); [% END %] }); //]]> @@ -127,7 +186,55 @@ [% END %]
- [% END %][%# IF (AcqCreateItemReceiving) %] + [% ELSIF (AcqCreateItem == 'ordering') %] + [% IF (items.size) %] +
Items
+
+ + + + + + + + + + + + + + + + + + + + + + [% FOREACH item IN items %] + + + + + + + + + + + + + + + + + + [% END %] + +
Receive? BarcodeHome branchHolding branchNot for loanRestrictedLocationCall numberCopy numberStock numberCollection codeItem typeMaterialsNotes
Edit[% item.barcode %][% item.homebranchname %][% item.holdingbranchname %][% item.notforloan %][% item.restricted %][% item.location %][% item.itemcallnumber %][% item.copynumber %][% item.stocknumber %][% item.collection %][% item.itemtype %][% item.materials %][% item.itemnotes %]
+
+ [% END %] + [% END %] @@ -143,7 +250,7 @@
  • [% datereceived %]
  • [% bookfund %]
  • [% IF ( memberfirstname and membersurname ) %][% IF ( memberfirstname ) %][% memberfirstname %][% END %] [% membersurname %][% ELSE %]No name[% END %]
  • -
  • +
  • [% IF ( edit ) %] [% ELSE %] @@ -168,12 +275,16 @@ [% END %] [% ELSE %] [% IF ( items ) %] - + [% ELSE %] [% END %] [% END %] + [% END %][%# IF (AcqCreateItemReceiving) %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index eabf5a8..296f795 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -4,6 +4,11 @@